[16.5] Handle npm's 409 'previously staged' error in publish-release retries (#102666)
Backports #102663 (Handle npm's 409 'previously staged' error in
publish-release retries) to `releases/stable/16-5`.
### Why?
The `v16.5.0-rc.3` release run
([build-and-deploy](https://github.com/vercel/next.js/actions/runs/46683925593))
failed to publish `next`. The first workspace publish attempt failed on
`next` after the GitHub OIDC token request timed out. Every retry then
failed on `create-next-app`, which had already been published, because
npm answered `409 Cannot publish over previously staged version`. The
script didn't recognize that message. A rerun then failed on every
native package with the usual 403 "previously published" error, because
pnpm wraps its error output across lines, so neither message ever
matched.
See #102663 for the full explanation and design.
### Verification
- The cherry-pick from #102663 applied cleanly.
`scripts/publish-release.js` matches #102663's version and stays
executable.
- `pnpm exec eslint` and `pnpm exec prettier --check` pass.
- Ran the script with `--dry-run` against a fake `pnpm` on `PATH`. The
403 and 409 fixtures are wrapped pnpm output copied from the failed CI
logs; the ANSI-colored and mixed-case variants are synthetic. 9 of 9
scenarios passed: these "already published/staged" errors are ignored
for single packages, unrelated errors fail, a failed workspace publish
retries and then succeeds, and 4 workspace failures in a row exit 1.
- Not run: a real publish (requires release credentials), and `pnpm
typescript` on this branch.
<!-- NEXT_JS_LLM -->
<!-- fleet 12613d21-0ea5-4338-adaf-b515278f55e1 -->
---------
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>