Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow non-semver versions in getVersionInWeirdWindowsForm #7174

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chilled-queens-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

Allow non-semver version formats on Windows
18 changes: 15 additions & 3 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmptyOrSpaces, log } from "builder-util"
import { prerelease, SemVer } from "semver"
import { prerelease } from "semver"
import { PlatformSpecificBuildOptions } from "./options/PlatformSpecificBuildOptions"
import { Packager } from "./packager"
import { expandMacro } from "./util/macroExpander"
Expand Down Expand Up @@ -76,13 +76,25 @@ export class AppInfo {
}

getVersionInWeirdWindowsForm(isSetBuildNumber = true): string {
const parsedVersion = new SemVer(this.version)
const [major, maybe_minor, maybe_patch] = this.version.split(".").map(versionPart => parseInt(versionPart))
// The major component must be present. Here it can be either NaN or undefined, which
// both returns true from isNaN.
if (isNaN(major)) {
throw new Error(`Invalid major number in: ${this.version}`)
}
// Allow missing version parts. Minor and patch can be left out and default to zero
const minor = maybe_minor ?? 0
const patch = maybe_patch ?? 0
// ... but reject non-integer version parts. '1.a' is not going to fly
if (isNaN(minor) || isNaN(patch)) {
throw new Error(`Invalid minor or patch number in: ${this.version}`)
}
// https://github.com/electron-userland/electron-builder/issues/2635#issuecomment-371792272
let buildNumber = isSetBuildNumber ? this.buildNumber : null
if (buildNumber == null || !/^\d+$/.test(buildNumber)) {
buildNumber = "0"
}
return `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}.${buildNumber}`
return `${major}.${minor}.${patch}.${buildNumber}`
}

private get notNullDevMetadata() {
Expand Down