Skip to content

fix: check for semantic version #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ await msiCreator.compile();
`msi` as well as the intermediate files .`wxs` and `.wixobj`.
* `exe` (string) - The name of the exe.
* `description` (string) - The app's description.
* `version` (string) - The app's version.
* `version` (string) - The app's version. Must be a valid semantic version.
* `name` (string) - The app's name.
* `icon` 🆕 (string, optional) - A path to the Apps icon used for the stub executable.
If not provided a lower quality version will be extracted form the `exe`
Expand Down
3 changes: 2 additions & 1 deletion src/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { createStubExe } from "./utils/rc-edit";
import { replaceInString, replaceToFile } from "./utils/replace";
import {
createInstallInfoFile,
getSemanticVersion,
getWindowsCompliantVersion,
} from "./utils/version-util";
import { getDirectoryStructure } from "./utils/walker";
Expand Down Expand Up @@ -201,7 +202,7 @@ export class MSICreator {
options.shortcutFolderName || options.manufacturer;
this.shortcutName = options.shortcutName || options.name;
this.upgradeCode = options.upgradeCode || randomUUID();
this.semanticVersion = options.version;
this.semanticVersion = getSemanticVersion(options.version);
this.windowsCompliantVersion = getWindowsCompliantVersion(options.version);
this.arch = options.arch || "x86";
this.defaultInstallMode = options.defaultInstallMode || "perMachine";
Expand Down
25 changes: 24 additions & 1 deletion src/utils/version-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,33 @@ export function getWindowsCompliantVersion(input: string): string {
const build = getBuildNumber(parsed);
return `${parsed.major}.${parsed.minor}.${parsed.patch}.${build}`;
} else {
throw new Error("Could not parse semantic version input string");
throw new Error(`Could not parse semantic version input string: ${input}`);
}
}

/**
* Takes a version number and returns a semantic version if possible.
* (1.2.3.4 -> 1.2.3+4)
* @param {string} input
* @returns {string}
*/
export function getSemanticVersion(input: string): string {
if (semver.valid(input)) {
return input;
}

const parsed = input.split(".");
// If build number is different
if (parsed.length === 4) {
const inputWithBuild = `${parsed[0]}.${parsed[1]}.${parsed[2]}+${parsed[3]}`;
if (semver.valid(inputWithBuild)) {
return inputWithBuild;
}
}

throw new Error(`Could not parse semantic version input string: ${input}`);
}

export function createInstallInfoFile(
manufacturer: string,
appName: string,
Expand Down