Skip to content

Commit

Permalink
Force major version number to be present
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Oct 18, 2022
1 parent 1139016 commit a8f44ae
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/app-builder-lib/src/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ export class AppInfo {

getVersionInWeirdWindowsForm(isSetBuildNumber = true): string {
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
// 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
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}`)
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
Expand Down

0 comments on commit a8f44ae

Please sign in to comment.