From 9409877403b4d12a0bed16722356acc9e9546475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Tue, 4 Oct 2022 15:35:25 +0200 Subject: [PATCH] Allow non-semver versions in getVersionInWeirdWindowsForm Fixes #7173 --- packages/app-builder-lib/src/appInfo.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/app-builder-lib/src/appInfo.ts b/packages/app-builder-lib/src/appInfo.ts index e9615015c99..23eb931e9d9 100644 --- a/packages/app-builder-lib/src/appInfo.ts +++ b/packages/app-builder-lib/src/appInfo.ts @@ -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() {