diff --git a/.changeset/chilled-queens-think.md b/.changeset/chilled-queens-think.md new file mode 100644 index 00000000000..06fee9820d4 --- /dev/null +++ b/.changeset/chilled-queens-think.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +Allow non-semver version formats on Windows diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index e9615015c99..310f0fcacc0 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -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" @@ -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() {