Skip to content

Commit

Permalink
fix: Allow non-semver versions in getVersionInWeirdWindowsForm
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Oct 18, 2022
1 parent f6944a3 commit 83c9d8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 83c9d8b

Please sign in to comment.