(pkgDir: string, channel: string)
| 790 | const ALREADY_PUBLISHED_RE = /previously published|cannot publish over|version already exists/i; |
| 791 | |
| 792 | const publishPackedPackage = async (pkgDir: string, channel: string) => { |
| 793 | if (await packageAlreadyPublished(pkgDir)) { |
| 794 | console.log(`Skipping ${pkgDir}; package version already exists on npm.`); |
| 795 | return; |
| 796 | } |
| 797 | |
| 798 | await $`bun pm pack`.cwd(pkgDir); |
| 799 | |
| 800 | const provenance = process.env.GITHUB_ACTIONS === "true" ? ["--provenance"] : []; |
| 801 | const result = await $`npm publish *.tgz --access public --tag ${channel} ${provenance}` |
| 802 | .cwd(pkgDir) |
| 803 | .nothrow() |
| 804 | .quiet(); |
| 805 | |
| 806 | const stdout = result.stdout.toString(); |
| 807 | const stderr = result.stderr.toString(); |
| 808 | process.stdout.write(stdout); |
| 809 | process.stderr.write(stderr); |
| 810 | |
| 811 | if (result.exitCode === 0) return; |
| 812 | |
| 813 | // The pre-check via `npm view` has a propagation race — even when an |
| 814 | // earlier publish in this same run committed, `npm view` may 404 for a few |
| 815 | // seconds. Treat "already published" errors as success on retry. |
| 816 | if (ALREADY_PUBLISHED_RE.test(stderr) || ALREADY_PUBLISHED_RE.test(stdout)) { |
| 817 | console.log(`Skipping ${pkgDir}; npm reported version already published.`); |
| 818 | return; |
| 819 | } |
| 820 | |
| 821 | throw new Error(`npm publish failed for ${pkgDir} (exit ${result.exitCode})`); |
| 822 | }; |
| 823 | |
| 824 | /** Extract the platform-tag suffix from a variant version string. |
| 825 | * e.g. "1.4.14-linux-x64" -> "linux-x64". |
no test coverage detected