Skip to content
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

fix(maker-windows): handle versions with prerelease information #1320

Merged
merged 5 commits into from
Dec 4, 2019
Merged
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
23 changes: 16 additions & 7 deletions packages/api/core/test/slow/api_spec_slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {

const packageJSON = await readRawPackageJson(dir);
packageJSON.name = 'testapp';
packageJSON.version = '1.0.0-beta.1';
packageJSON.productName = 'Test-App';
packageJSON.config.forge.packagerConfig.asar = false;
if (process.platform === 'win32') {
Expand Down Expand Up @@ -340,13 +341,21 @@ describe(`electron-forge API (with installer=${nodeInstaller})`, () => {
return maker.isSupportedOnCurrentPlatform() === good
&& maker.externalBinariesExist() === good;
})
.map((makerPath) => () => ({
name: makerPath,
platforms: [process.platform],
config: {
devCert,
},
}));
.map((makerPath) => () => {
const makerDefinition = {
name: makerPath,
platforms: [process.platform],
config: {
devCert,
},
};

if (process.platform === 'win32') {
(makerDefinition.config as any).makeVersionWinStoreCompatible = true;
}

return makerDefinition;
});
}

const goodMakers = getMakers(true);
Expand Down
5 changes: 2 additions & 3 deletions packages/maker/appx/src/MakerAppX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ export default class MakerAppX extends MakerBase<MakerAppXConfig> {
);
}

if (opts.packageVersion.match(/-/)) {
if (opts.packageVersion.includes('-')) {
if (opts.makeVersionWinStoreCompatible) {
const noBeta = opts.packageVersion.replace(/-.*/, '');
opts.packageVersion = `${noBeta}.0`;
opts.packageVersion = this.normalizeWindowsVersion(opts.packageVersion);
} else {
throw new Error(
"Windows Store version numbers don't support semver beta tags. To "
Expand Down
9 changes: 9 additions & 0 deletions packages/maker/base/src/Maker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,13 @@ export default abstract class Maker<C> implements IForgeMaker {
return false;
}
}

/**
* Normalize the given semver-formatted version to a 4-part dot delimited version number without
* prerelease information for use in Windows apps.
*/
normalizeWindowsVersion(version: string): string {
const noPrerelease = version.replace(/-.*/, '');
return `${noPrerelease}.0`;
}
}
22 changes: 22 additions & 0 deletions packages/maker/base/test/version_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { expect } from 'chai';

import MakerBase from '../src/Maker';

class MakerImpl extends MakerBase<{}> {
name = 'test';

defaultPlatforms = [];
}

describe('normalizeWindowsVersion', () => {
const maker = new MakerImpl({}, []);

it('removes everything after the dash', () => {
for (const version of ['1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-0.3.7', '1.0.0-x.7.z.92']) {
expect(maker.normalizeWindowsVersion(version)).to.equal('1.0.0.0');
}
});
it('does not truncate the version when there is no dash', () => {
expect(maker.normalizeWindowsVersion('2.0.0')).to.equal('2.0.0.0');
});
});
8 changes: 5 additions & 3 deletions packages/maker/squirrel/src/MakerSquirrel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MakerBase, { MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';

import { createWindowsInstaller, Options as ElectronWinstallerOptions } from 'electron-winstaller';
import { convertVersion, createWindowsInstaller, Options as ElectronWinstallerOptions } from 'electron-winstaller';
import fs from 'fs-extra';
import path from 'path';

Expand Down Expand Up @@ -39,12 +39,14 @@ export default class MakerSquirrel extends MakerBase<MakerSquirrelConfig> {

await createWindowsInstaller(winstallerConfig);

const nupkgVersion = convertVersion(packageJSON.version);

const artifacts = [
path.resolve(outPath, 'RELEASES'),
path.resolve(outPath, winstallerConfig.setupExe || `${appName}Setup.exe`),
path.resolve(outPath, `${winstallerConfig.name}-${packageJSON.version}-full.nupkg`),
path.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-full.nupkg`),
];
const deltaPath = path.resolve(outPath, `${winstallerConfig.name}-${packageJSON.version}-delta.nupkg`);
const deltaPath = path.resolve(outPath, `${winstallerConfig.name}-${nupkgVersion}-delta.nupkg`);
if (winstallerConfig.remoteReleases || await fs.pathExists(deltaPath)) {
artifacts.push(deltaPath);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/maker/wix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"dependencies": {
"@electron-forge/maker-base": "6.0.0-beta.45",
"@electron-forge/shared-types": "6.0.0-beta.45",
"colors": "^1.4.0",
"electron-wix-msi": "^2.1.1",
"log-symbols": "^3.0.0",
"parse-author": "^2.0.0"
}
}
}
11 changes: 10 additions & 1 deletion packages/maker/wix/src/MakerWix.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import MakerBase, { MakerOptions } from '@electron-forge/maker-base';
import { ForgePlatform } from '@electron-forge/shared-types';

import 'colors';
import logSymbols from 'log-symbols';
import path from 'path';

import { MSICreator, MSICreatorOptions } from 'electron-wix-msi/lib/creator';
Expand Down Expand Up @@ -28,10 +30,17 @@ export default class MakerWix extends MakerBase<MakerWixConfig> {
const outPath = path.resolve(makeDir, `wix/${targetArch}`);
await this.ensureDirectory(outPath);

let { version } = packageJSON;
if (version.includes('-')) {
// eslint-disable-next-line no-console
console.warn(logSymbols.warning, 'WARNING: WiX distributables do not handle prerelease information in the app version, removing it from the MSI'.yellow);
version = this.normalizeWindowsVersion(version);
}

const creator = new MSICreator(({
description: packageJSON.description,
name: appName,
version: packageJSON.version,
version,
manufacturer: getNameFromAuthor(packageJSON.author),
exe: `${appName}.exe`,
...this.config,
Expand Down