Skip to content

Commit

Permalink
package.json: Specify NPM release tag explicitly (#3417)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Dec 7, 2021
1 parent 763c149 commit ab52ddc
Show file tree
Hide file tree
Showing 2 changed files with 16 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"
}
}
20 changes: 13 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,17 @@ 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.equal(
versionTag,
publishTag,
'Publish tag and version tag should match!',
);

assert(!packageJSON.publishConfig, 'Can not override "publishConfig".');
packageJSON.publishConfig = { tag: publishTag };
}

return packageJSON;
Expand Down

0 comments on commit ab52ddc

Please sign in to comment.