Skip to content

Commit 01f35ab

Browse files
devversiontinayuangao
authored andcommitted
build: prevent alpha/beta/rc publishing to latest tag (#9711)
* No longer allows publishing versions that include "beta" / "alpha" / "rc" to the "latest" tag on NPM. This safeguard can be still removed temporarily, if there is a real need to publish a beta in the latest tag. Closes #9699.
1 parent 95ffe37 commit 01f35ab

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tools/gulp/tasks/publish.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,30 @@ task(':publish:whoami', execTask('npm', ['whoami'], {
4242
task(':publish:logout', execTask('npm', ['logout']));
4343

4444
task(':publish', async () => {
45-
const label = argv['tag'];
45+
const tag = argv['tag'];
4646
const version = buildConfig.projectVersion;
4747
const currentDir = process.cwd();
4848

4949
console.log('');
50-
if (!label) {
51-
console.log(grey('> You can use a label with --tag=labelName.\n'));
52-
console.log(green(`Publishing version "${version}" using the latest tag...`));
50+
if (!tag) {
51+
console.log(grey('> You can specify the tag by passing --tag=labelName.\n'));
52+
console.log(green(`Publishing version "${version}" to the latest tag...`));
5353
} else {
54-
console.log(yellow(`Publishing version "${version}" using the ${label} tag...`));
54+
console.log(yellow(`Publishing version "${version}" to the ${tag} tag...`));
5555
}
5656
console.log('');
5757

58+
59+
if (version.match(/(alpha|beta|rc)/) && (!tag || tag === 'latest')) {
60+
console.log(red(`Publishing ${version} to the "latest" tag is not allowed.`));
61+
console.log(red(`Alpha, Beta or RC versions shouldn't be published to "latest".`));
62+
console.log();
63+
return;
64+
}
65+
5866
if (releasePackages.length > 1) {
5967
console.warn(red('Warning: Multiple packages will be released if proceeding.'));
60-
console.warn(red('Warning: Packages to be released: ', releasePackages.join(', ')));
68+
console.warn(red('Warning: Packages to be released:', releasePackages.join(', ')));
6169
console.log();
6270
}
6371

@@ -67,13 +75,13 @@ task(':publish', async () => {
6775

6876
// Iterate over every declared release package and publish it on NPM.
6977
for (const packageName of releasePackages) {
70-
await _execNpmPublish(label, packageName);
78+
await _execNpmPublish(tag, packageName);
7179
}
7280

7381
process.chdir(currentDir);
7482
});
7583

76-
function _execNpmPublish(label: string, packageName: string): Promise<{}> | undefined {
84+
function _execNpmPublish(tag: string, packageName: string): Promise<{}> | undefined {
7785
const packageDir = join(buildConfig.outputDir, 'releases', packageName);
7886

7987
if (!statSync(packageDir).isDirectory()) {
@@ -94,8 +102,8 @@ function _execNpmPublish(label: string, packageName: string): Promise<{}> | unde
94102
const command = 'npm';
95103
const args = ['publish', '--access', 'public'];
96104

97-
if (label) {
98-
args.push('--tag', label);
105+
if (tag) {
106+
args.push('--tag', tag);
99107
}
100108

101109
return new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)