From 2d16326d9a3f45260aa80bcae78745ab2f199138 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Mon, 30 Sep 2024 17:07:54 +0100 Subject: [PATCH] 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. --- scripts/devtools/publish-release.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/devtools/publish-release.js b/scripts/devtools/publish-release.js index 495fddefc2..6a2ab4f79d 100755 --- a/scripts/devtools/publish-release.js +++ b/scripts/devtools/publish-release.js @@ -82,18 +82,13 @@ async function publishToNPM() { // If so we might be resuming from a previous run. // We could infer this by comparing the build-info.json, // But for now the easiest way is just to ask if this is expected. - const info = await execRead(`npm view ${npmPackage}@${version}`) - // Early versions of npm view gives empty response, but newer versions give 404 error. - // Catch the error to keep it consistent. - .catch(childProcessError => { - if (childProcessError.stderr.startsWith('npm ERR! code E404')) { - return null; - } + const versionListJSON = await execRead( + `npm view ${npmPackage} versions --json` + ); + const versionList = JSON.parse(versionListJSON); + const versionIsAlreadyPublished = versionList.includes(version); - throw childProcessError; - }); - - if (info) { + if (versionIsAlreadyPublished) { console.log(''); console.log( `${npmPackage} version ${chalk.bold(