Skip to content

Commit a1c0864

Browse files
authored
Support untagged releases (facebook#19509)
1 parent 5d271fc commit a1c0864

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

scripts/release/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ Once this step is complete, you're ready to publish the release:
8787

8888
```sh
8989
scripts/release/publish.js --tags latest
90+
91+
# Or, if you want to bump "next" as well:
92+
scripts/release/publish.js --tags latest next
9093
```
9194

9295
If the OTP code expires while publishing, re-run this command and answer "y" to the questions about whether it was expected for already published packages.
@@ -172,5 +175,5 @@ Upon completion, this script provides instructions for tagging the Git commit th
172175
#### Example usage
173176
To publish a release to NPM as both `next` and `latest`:
174177
```sh
175-
scripts/release/publish.js --tags latest
178+
scripts/release/publish.js --tags latest next
176179
```

scripts/release/publish-commands/confirm-version-and-tags.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ const run = async ({cwd, packages, tags}) => {
1212
clear();
1313

1414
if (tags.length === 0) {
15-
console.log(
16-
theme`{spinnerSuccess ✓} You are about the publish the following packages without any tags:`
17-
);
15+
console.error('Expected at least one tag.');
16+
process.exit(1);
1817
} else if (tags.length === 1) {
1918
console.log(
2019
theme`{spinnerSuccess ✓} You are about the publish the following packages under the tag {tag ${tags}}:`

scripts/release/publish-commands/parse-params.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const paramDefinitions = [
1717
type: String,
1818
multiple: true,
1919
description: 'NPM tags to point to the new release.',
20+
defaultValue: ['untagged'],
2021
},
2122
{
2223
name: 'skipPackages',
@@ -29,10 +30,20 @@ const paramDefinitions = [
2930

3031
module.exports = () => {
3132
const params = commandLineArgs(paramDefinitions);
32-
if (!params.tags || !params.tags.length) {
33-
params.tags = [];
34-
}
3533
splitCommaParams(params.skipPackages);
3634
splitCommaParams(params.tags);
35+
params.tags.forEach(tag => {
36+
switch (tag) {
37+
case 'latest':
38+
case 'next':
39+
case 'experimental':
40+
case 'untagged':
41+
break;
42+
default:
43+
console.error('Unknown tag: "' + params.tag + '"');
44+
process.exit(1);
45+
break;
46+
}
47+
});
3748
return params;
3849
};

scripts/release/publish-commands/publish-to-npm.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ const run = async ({cwd, dry, packages, tags}, otp) => {
5454
)
5555
);
5656
}
57+
58+
if (tags.includes('untagged')) {
59+
// npm doesn't let us publish without a tag at all,
60+
// so for one-off publishes we clean it up ourselves.
61+
if (!dry) {
62+
await exec(`npm dist-tag rm ${packageName}@untagged --otp=${otp}`);
63+
}
64+
console.log(
65+
theme.command(`npm dist-tag rm ${packageName}@untagged --otp=${otp}`)
66+
);
67+
}
5768
}
5869
}
5970
};

scripts/release/publish-commands/validate-tags.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,42 @@ const run = async ({cwd, packages, tags}) => {
1818
'package.json'
1919
);
2020
const {version} = await readJson(packageJSONPath);
21+
const isExperimentalVersion = version.indexOf('experimental') !== -1;
2122
if (version.indexOf('0.0.0') === 0) {
2223
if (tags.includes('latest')) {
24+
if (isExperimentalVersion) {
25+
console.log(
26+
theme`{error Experimental release} {version ${version}} {error cannot be tagged as} {tag latest}`
27+
);
28+
} else {
29+
console.log(
30+
theme`{error Next release} {version ${version}} {error cannot be tagged as} {tag latest}`
31+
);
32+
}
33+
process.exit(1);
34+
}
35+
if (tags.includes('next') && isExperimentalVersion) {
36+
console.log(
37+
theme`{error Experimental release} {version ${version}} {error cannot be tagged as} {tag next}`
38+
);
39+
process.exit(1);
40+
}
41+
if (tags.includes('experimental') && !isExperimentalVersion) {
2342
console.log(
24-
theme`{error Next release} {version ${version}} {error cannot be tagged as} {tag latest}`
43+
theme`{error Next release} {version ${version}} {error cannot be tagged as} {tag experimental}`
2544
);
2645
process.exit(1);
2746
}
2847
} else {
29-
if (tags.includes('next')) {
48+
if (!tags.includes('latest')) {
49+
console.log(
50+
theme`{error Stable release} {version ${version}} {error must always be tagged as} {tag latest}`
51+
);
52+
process.exit(1);
53+
}
54+
if (tags.includes('experimental')) {
3055
console.log(
31-
theme`{error Stable release} {version ${version}} {error cannot be tagged as} {tag next}`
56+
theme`{error Stable release} {version ${version}} {error cannot be tagged as} {tag experimental}`
3257
);
3358
process.exit(1);
3459
}

0 commit comments

Comments
 (0)