Skip to content

Commit

Permalink
refactor(maker-base): extract Windows-specific version normalization …
Browse files Browse the repository at this point in the history
…to a method on the maker base class
  • Loading branch information
malept committed Dec 4, 2019
1 parent 0aafbf6 commit c3e2361
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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');
});
});

0 comments on commit c3e2361

Please sign in to comment.