Skip to content

Commit

Permalink
package.json: Specify NPM release tag explicitly
Browse files Browse the repository at this point in the history
It's far from an ideal solution but it least it makes it more explicit
  • Loading branch information
IvanGoncharov committed Dec 7, 2021
1 parent 6e48d16 commit c439809
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -71,5 +71,8 @@
"mocha": "9.1.3",
"prettier": "2.5.0",
"typescript": "4.5.2"
},
"publishConfig": {
"tag": "latest"
}
}
16 changes: 9 additions & 7 deletions resources/build-npm.js
Expand Up @@ -113,6 +113,10 @@ function buildPackageJSON() {
delete packageJSON.scripts;
delete packageJSON.devDependencies;

// TODO: move to integration tests
const publishTag = packageJSON.publishConfig?.tag;
assert(publishTag != null, 'Should have packageJSON.publishConfig defined!');

const { version } = packageJSON;
const versionMatch = /^\d+\.\d+\.\d+-?(?<preReleaseTag>.*)?$/.exec(version);
if (!versionMatch) {
Expand All @@ -124,15 +128,13 @@ function buildPackageJSON() {
if (preReleaseTag != null) {
const splittedTag = preReleaseTag.split('.');
// Note: `experimental-*` take precedence over `alpha`, `beta` or `rc`.
const publishTag = splittedTag[2] ?? splittedTag[0];
const versionTag = splittedTag[2] ?? splittedTag[0];
assert(
['alpha', 'beta', 'rc'].includes(publishTag) ||
publishTag.startsWith('experimental-'),
`"${publishTag}" tag is not supported.`,
['alpha', 'beta', 'rc'].includes(versionTag) ||
versionTag.startsWith('experimental-'),
`"${versionTag}" tag is not supported.`,
);

assert(!packageJSON.publishConfig, 'Can not override "publishConfig".');
packageJSON.publishConfig = { tag: publishTag };
assert.equal(versionTag, publishTag, 'Publish tag and version tag should match!');
}

return packageJSON;
Expand Down

0 comments on commit c439809

Please sign in to comment.