(pkgDir: string, channel: string)
| 741 | const ALREADY_PUBLISHED_RE = /previously published|cannot publish over|version already exists/i; |
| 742 | |
| 743 | const publishPackedPackage = async (pkgDir: string, channel: string) => { |
| 744 | if (await packageAlreadyPublished(pkgDir)) { |
| 745 | console.log(`Skipping ${pkgDir}; package version already exists on npm.`); |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | await $`bun pm pack`.cwd(pkgDir); |
| 750 | |
| 751 | const provenance = process.env.GITHUB_ACTIONS === "true" ? ["--provenance"] : []; |
| 752 | const result = await $`npm publish *.tgz --access public --tag ${channel} ${provenance}` |
| 753 | .cwd(pkgDir) |
| 754 | .nothrow() |
| 755 | .quiet(); |
| 756 | |
| 757 | const stdout = result.stdout.toString(); |
| 758 | const stderr = result.stderr.toString(); |
| 759 | process.stdout.write(stdout); |
| 760 | process.stderr.write(stderr); |
| 761 | |
| 762 | if (result.exitCode === 0) return; |
| 763 | |
| 764 | // The pre-check via `npm view` has a propagation race — even when an |
| 765 | // earlier publish in this same run committed, `npm view` may 404 for a few |
| 766 | // seconds. Treat "already published" errors as success on retry. |
| 767 | if (ALREADY_PUBLISHED_RE.test(stderr) || ALREADY_PUBLISHED_RE.test(stdout)) { |
| 768 | console.log(`Skipping ${pkgDir}; npm reported version already published.`); |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | throw new Error(`npm publish failed for ${pkgDir} (exit ${result.exitCode})`); |
| 773 | }; |
| 774 | |
| 775 | /** Extract the platform-tag suffix from a variant version string. |
| 776 | * e.g. "1.4.14-linux-x64" -> "linux-x64". |
no test coverage detected