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.
This commit is contained in:
Ruslan Lesiutin 2024-09-30 17:07:54 +01:00 committed by GitHub
parent db240980a3
commit 2d16326d9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -82,18 +82,13 @@ async function publishToNPM() {
// If so we might be resuming from a previous run. // If so we might be resuming from a previous run.
// We could infer this by comparing the build-info.json, // We could infer this by comparing the build-info.json,
// But for now the easiest way is just to ask if this is expected. // But for now the easiest way is just to ask if this is expected.
const info = await execRead(`npm view ${npmPackage}@${version}`) const versionListJSON = await execRead(
// Early versions of npm view gives empty response, but newer versions give 404 error. `npm view ${npmPackage} versions --json`
// Catch the error to keep it consistent. );
.catch(childProcessError => { const versionList = JSON.parse(versionListJSON);
if (childProcessError.stderr.startsWith('npm ERR! code E404')) { const versionIsAlreadyPublished = versionList.includes(version);
return null;
}
throw childProcessError; if (versionIsAlreadyPublished) {
});
if (info) {
console.log(''); console.log('');
console.log( console.log(
`${npmPackage} version ${chalk.bold( `${npmPackage} version ${chalk.bold(