Skip to content

Commit

Permalink
Allow non-semver versions in getVersionInWeirdWindowsForm
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Oct 4, 2022
1 parent f6944a3 commit 9409877
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ export class AppInfo {
}

getVersionInWeirdWindowsForm(isSetBuildNumber = true): string {
const parsedVersion = new SemVer(this.version)
let [major, minor, patch] = this.version.split('.').map((versionPart) => parseInt(versionPart))
// Allow missing version parts. Version '1.2' gets a patch version of 0
major ??= 0
minor ??= 0
patch ??= 0
// ... but reject non-integer version parts. '1.a' is not going to fly
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
throw new Error(`Invalid version: ${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 9409877

Please sign in to comment.