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

Function publishPackedPackage

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

Source from the content-addressed store, hash-verified

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

Callers 1

publishFunction · 0.85

Calls 3

logMethod · 0.80
toStringMethod · 0.80
packageAlreadyPublishedFunction · 0.70

Tested by

no test coverage detected