Skip to content

Commit c9835c3

Browse files
committed
PR feedback
1 parent 6bfef02 commit c9835c3

4 files changed

Lines changed: 111 additions & 46 deletions

File tree

.ado/jobs/npm-publish.yml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,7 @@ jobs:
4949
yarn nx release --dry-run --verbose
5050
5151
# Show what additional tags would be applied
52-
if [ -n "$(additionalTags)" ]; then
53-
echo ""
54-
echo "=== Additional dist-tags that would be applied ==="
55-
VERSION=$(jq -r '.version' ./packages/react-native/package.json)
56-
IFS=',' read -ra TAGS <<< "$(additionalTags)"
57-
for tag in "${TAGS[@]}"; do
58-
echo " @react-native-macos/virtualized-lists@$VERSION -> $tag"
59-
echo " react-native-macos@$VERSION -> $tag"
60-
done
61-
fi
52+
node .ado/scripts/apply-additional-tags.mjs --tags "$(additionalTags)" --dry-run
6253
displayName: Version and publish packages (dry run)
6354
condition: and(succeeded(), ne(variables['publish_react_native_macos'], '1'))
6455
@@ -96,22 +87,7 @@ jobs:
9687
condition: and(succeeded(), eq(variables['publish_react_native_macos'], '1'))
9788
9889
- script: |
99-
set -eox pipefail
100-
if [[ -z "$(additionalTags)" ]]; then
101-
echo "No additional tags to apply"
102-
exit 0
103-
fi
104-
105-
# Get the version from package.json
106-
VERSION=$(jq -r '.version' ./packages/react-native/package.json)
107-
108-
# Apply additional tags
109-
IFS=',' read -ra TAGS <<< "$(additionalTags)"
110-
for tag in "${TAGS[@]}"; do
111-
echo "Adding dist-tag '$tag' to packages"
112-
npm dist-tag add "@react-native-macos/virtualized-lists@$VERSION" "$tag" --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
113-
npm dist-tag add "react-native-macos@$VERSION" "$tag" --registry https://registry.npmjs.org/ --//registry.npmjs.org/:_authToken=$(npmAuthToken)
114-
done
90+
node .ado/scripts/apply-additional-tags.mjs --tags "$(additionalTags)" --token "$(npmAuthToken)"
11591
displayName: Apply additional dist-tags
11692
condition: and(succeeded(), eq(variables['publish_react_native_macos'], '1'))
11793
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// @ts-check
2+
import { spawnSync } from "node:child_process";
3+
import * as fs from "node:fs";
4+
import * as util from "node:util";
5+
6+
/**
7+
* Apply additional dist-tags to published packages
8+
* Usage: node apply-additional-tags.mjs --tags <tags> --token <token>
9+
* node apply-additional-tags.mjs --tags <tags> --dry-run
10+
* Where tags is a comma-separated list of tags (e.g., "next,v0.79-stable")
11+
*/
12+
13+
const registry = "https://registry.npmjs.org/";
14+
const packages = [
15+
"@react-native-macos/virtualized-lists",
16+
"react-native-macos",
17+
];
18+
19+
/**
20+
* @typedef {{
21+
* tags?: string;
22+
* token?: string;
23+
* "dry-run"?: boolean;
24+
* }} Options;
25+
*/
26+
27+
/**
28+
* @param {Options} options
29+
* @returns {number}
30+
*/
31+
function main({ tags, token, "dry-run": dryRun }) {
32+
if (!tags) {
33+
console.log("No additional tags to apply");
34+
return 0;
35+
}
36+
37+
if (!dryRun && !token) {
38+
console.error("Error: npm auth token is required (use --dry-run to preview)");
39+
return 1;
40+
}
41+
42+
const packageJson = JSON.parse(
43+
fs.readFileSync("./packages/react-native/package.json", "utf-8")
44+
);
45+
const version = packageJson.version;
46+
47+
if (dryRun) {
48+
console.log("");
49+
console.log("=== Additional dist-tags that would be applied ===");
50+
for (const tag of tags.split(",")) {
51+
for (const pkg of packages) {
52+
console.log(` ${pkg}@${version} -> ${tag}`);
53+
}
54+
}
55+
return 0;
56+
}
57+
58+
for (const tag of tags.split(",")) {
59+
for (const pkg of packages) {
60+
console.log(`Adding dist-tag '${tag}' to ${pkg}@${version}`);
61+
const result = spawnSync(
62+
"npm",
63+
[
64+
"dist-tag",
65+
"add",
66+
`${pkg}@${version}`,
67+
tag,
68+
"--registry",
69+
registry,
70+
`--//registry.npmjs.org/:_authToken=${token}`,
71+
],
72+
{ stdio: "inherit", shell: true }
73+
);
74+
75+
if (result.status !== 0) {
76+
console.error(`Failed to add dist-tag '${tag}' to ${pkg}@${version}`);
77+
return 1;
78+
}
79+
}
80+
}
81+
82+
return 0;
83+
}
84+
85+
const { values } = util.parseArgs({
86+
args: process.argv.slice(2),
87+
options: {
88+
tags: {
89+
type: "string",
90+
},
91+
token: {
92+
type: "string",
93+
},
94+
"dry-run": {
95+
type: "boolean",
96+
default: false,
97+
},
98+
},
99+
strict: true,
100+
});
101+
102+
process.exitCode = main(values);

.ado/scripts/prepublish-check.mjs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,14 @@ function getTagsForStableBranch(branch, { tag }, log) {
323323
}
324324

325325
// Publishing a release candidate
326-
if (currentVersion > latestVersion) {
327-
log(`Expected npm tags: ${NPM_TAG_NEXT}`);
326+
// currentVersion > latestVersion
327+
log(`Expected npm tags: ${NPM_TAG_NEXT}`);
328328

329-
if (currentVersion < nextVersion) {
330-
throw new Error(`Current version cannot be a release candidate because it is too old: ${currentVersion} < ${nextVersion}`);
331-
}
332-
333-
return { npmTags: [NPM_TAG_NEXT], prerelease: "rc" };
329+
if (currentVersion < nextVersion) {
330+
throw new Error(`Current version cannot be a release candidate because it is too old: ${currentVersion} < ${nextVersion}`);
334331
}
335332

336-
throw new Error(`Unexpected state: currentVersion=${currentVersion}, latestVersion=${latestVersion}, nextVersion=${nextVersion}, tag=${tag}`);
333+
return { npmTags: [NPM_TAG_NEXT], prerelease: "rc" };
337334
}
338335

339336
/**
@@ -349,8 +346,7 @@ function enablePublishing(config, currentBranch, { npmTags, prerelease }, option
349346
const errors = [];
350347

351348
const { defaultBase, release } = config;
352-
const primaryTag = npmTags[0];
353-
const additionalTags = npmTags.slice(1);
349+
const [primaryTag, ...additionalTags] = npmTags;
354350

355351
// `defaultBase` determines what we diff against when looking for tags or
356352
// released version and must therefore be set to either the main branch or one

.github/workflows/microsoft-pr.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@ jobs:
7777
yarn nx release --dry-run --verbose
7878
7979
# Show what additional tags would be applied
80-
if [ -n "${{ steps.prepublish.outputs.additionalTags }}" ]; then
81-
echo ""
82-
echo "=== Additional dist-tags that would be applied ==="
83-
VERSION=$(jq -r '.version' ./packages/react-native/package.json)
84-
IFS=',' read -ra TAGS <<< "${{ steps.prepublish.outputs.additionalTags }}"
85-
for tag in "${TAGS[@]}"; do
86-
echo " @react-native-macos/virtualized-lists@$VERSION -> $tag"
87-
echo " react-native-macos@$VERSION -> $tag"
88-
done
89-
fi
80+
node .ado/scripts/apply-additional-tags.mjs --tags "${{ steps.prepublish.outputs.additionalTags }}" --dry-run
9081
9182
yarn-constraints:
9283
name: "Check Yarn Constraints"

0 commit comments

Comments
 (0)