fix[scripts/devtools/publish-release]: parse version list instead of handling 404 (#31087)
Discovered yesterday while was publishing a new release. NPM `10.x.x` changed the text for 404 errors, so this check was failing. Instead of handling 404 as a signal, I think its better to just parse the whole list of versions and check if the new one is already there.
Ruslan Lesiutin committed
Sep 30, 2024 at 17:07 UTC
2d16326d9a3f45260aa80bcae78745ab2f199138
1 file changed
+6
-11
scripts/devtools/publish-release.js
+6
-11
@@ -82,18 +82,13 @@ async function publishToNPM() {
82
// If so we might be resuming from a previous run.
83
// We could infer this by comparing the build-info.json,
84
// But for now the easiest way is just to ask if this is expected.
85
- const info = await execRead(`npm view ${npmPackage}@${version}`)
86
- // Early versions of npm view gives empty response, but newer versions give 404 error.
87
- // Catch the error to keep it consistent.
88
- .catch(childProcessError => {
89
- if (childProcessError.stderr.startsWith('npm ERR! code E404')) {
90
- return null;
91
- }
92
-
93
- throw childProcessError;
94
- });
85
+ const versionListJSON = await execRead(
86
+ `npm view ${npmPackage} versions --json`
87
+ );
88
+ const versionList = JSON.parse(versionListJSON);
89
+ const versionIsAlreadyPublished = versionList.includes(version);
90
96
- if (info) {
91
+ if (versionIsAlreadyPublished) {
92
console.log('');
93
console.log(
94
`${npmPackage} version ${chalk.bold(