MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / publishPackedPackage

Function publishPackedPackage

apps/cli/src/build.ts:743–773  ·  view source on GitHub ↗
(pkgDir: string, channel: string)

Source from the content-addressed store, hash-verified

741const ALREADY_PUBLISHED_RE = /previously published|cannot publish over|version already exists/i;
742
743const 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".

Callers 1

publishFunction · 0.85

Calls 3

logMethod · 0.80
toStringMethod · 0.80
packageAlreadyPublishedFunction · 0.70

Tested by

no test coverage detected