From 8bff5ff5d7579ed52d2e8a93268b71c23e9a6e4e Mon Sep 17 00:00:00 2001 From: Makisuo Date: Sun, 11 Oct 2026 00:10:01 +0200 Subject: [PATCH] fix(release): tag a version npm rejects as already published npm view can return a stale miss for a package created minutes earlier, so a version published out of band reached npm publish and failed the release with E403. Treat that rejection as already published and only tag it. --- scripts/publish-packages.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/publish-packages.ts b/scripts/publish-packages.ts index e4eb5992a5..a6daf90d2f 100644 --- a/scripts/publish-packages.ts +++ b/scripts/publish-packages.ts @@ -37,7 +37,11 @@ const run = (cmd: ReadonlyArray, cwd = root, quiet = false) => { stdout: quiet ? "pipe" : "inherit", stderr: quiet ? "pipe" : "inherit", }) - return { ok: result.exitCode === 0, stdout: result.stdout?.toString() ?? "" } + return { + ok: result.exitCode === 0, + stdout: result.stdout?.toString() ?? "", + stderr: result.stderr?.toString() ?? "", + } } const fail = (message: string): never => { @@ -130,8 +134,14 @@ for (const { dir, manifest } of ordered) { ) if (!run(["bun", "pm", "pack", "--filename", tarball], dir).ok) fail(`bun pm pack failed for ${tag}`) const publishArgs = ["npm", "publish", tarball, "--access", "public"] - if (!run(dryRun ? [...publishArgs, "--dry-run"] : [...publishArgs, "--provenance"]).ok) { + const publish = run(dryRun ? [...publishArgs, "--dry-run"] : [...publishArgs, "--provenance"], root, true) + process.stdout.write(publish.stdout) + process.stderr.write(publish.stderr) + // `npm view` can serve a stale miss for a package created minutes ago, so a version published + // out of band still lands here; npm rejecting it as a duplicate means it only needs its tag. + if (!publish.ok && !publish.stderr.includes("cannot publish over the previously published versions")) { fail(`npm publish failed for ${tag}`) } + if (!publish.ok) console.log(`${tag} is already on npm, tagging only.`) if (!dryRun) reportRelease(manifest) }