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

package.json: Specify NPM release tag explicitly #3417

Merged
merged 1 commit into from Dec 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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