(pkgDir: string, channel: string)
| 719 | const ALREADY_PUBLISHED_RE = /previously published|cannot publish over|version already exists/i; |
| 720 | |
| 721 | const publishPackedPackage = async (pkgDir: string, channel: string) => { |
| 722 | if (await packageAlreadyPublished(pkgDir)) { |
| 723 | console.log(`Skipping ${pkgDir}; package version already exists on npm.`); |
| 724 | return; |
| 725 | } |
| 726 | |
| 727 | await $`bun pm pack`.cwd(pkgDir); |
| 728 | |
| 729 | const provenance = process.env.GITHUB_ACTIONS === "true" ? ["--provenance"] : []; |
| 730 | const result = await $`npm publish *.tgz --access public --tag ${channel} ${provenance}` |
| 731 | .cwd(pkgDir) |
| 732 | .nothrow() |
| 733 | .quiet(); |
| 734 | |
| 735 | const stdout = result.stdout.toString(); |
| 736 | const stderr = result.stderr.toString(); |
| 737 | process.stdout.write(stdout); |
| 738 | process.stderr.write(stderr); |
| 739 | |
| 740 | if (result.exitCode === 0) return; |
| 741 | |
| 742 | // The pre-check via `npm view` has a propagation race — even when an |
| 743 | // earlier publish in this same run committed, `npm view` may 404 for a few |
| 744 | // seconds. Treat "already published" errors as success on retry. |
| 745 | if (ALREADY_PUBLISHED_RE.test(stderr) || ALREADY_PUBLISHED_RE.test(stdout)) { |
| 746 | console.log(`Skipping ${pkgDir}; npm reported version already published.`); |
| 747 | return; |
| 748 | } |
| 749 | |
| 750 | throw new Error(`npm publish failed for ${pkgDir} (exit ${result.exitCode})`); |
| 751 | }; |
| 752 | |
| 753 | /** Extract the platform-tag suffix from a variant version string. |
| 754 | * e.g. "1.4.14-linux-x64" -> "linux-x64". |
no test coverage detected