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

Function publishPackage

scripts/publish-packages.ts:276–337  ·  view source on GitHub ↗
(
  pkgDir: string,
  dryRun: boolean,
  publishable: ReadonlySet<string>,
  publishableVersions: ReadonlyMap<string, string>,
)

Source from the content-addressed store, hash-verified

274};
275
276const publishPackage = async (
277 pkgDir: string,
278 dryRun: boolean,
279 publishable: ReadonlySet<string>,
280 publishableVersions: ReadonlyMap<string, string>,
281) => {
282 const { name, version } = await readPackageMeta(pkgDir);
283 const channel = resolveChannel(version);
284
285 if (!existsSync(join(pkgDir, "dist"))) {
286 throw new Error(`Missing dist/ in ${pkgDir}. Did you run 'bun run build:packages'?`);
287 }
288
289 console.log(`[pack] ${name}@${version} (${channel})${dryRun ? " [dry-run]" : ""}`);
290
291 // Clean any stale tarballs from previous runs so our readdir finds exactly
292 // the archive produced by the pack below.
293 const stale = (await readdir(pkgDir)).filter((entry) => entry.endsWith(".tgz"));
294 for (const entry of stale) {
295 await rm(join(pkgDir, entry), { force: true });
296 }
297
298 const restoreWorkspaceVersions = await applyWorkspaceVersions(
299 pkgDir,
300 publishable,
301 publishableVersions,
302 );
303 const restorePublishConfig = await applyPublishConfig(pkgDir);
304 try {
305 await $`bun pm pack`.cwd(pkgDir);
306 } finally {
307 await restorePublishConfig();
308 await restoreWorkspaceVersions();
309 }
310
311 const produced = (await readdir(pkgDir)).filter((entry) => entry.endsWith(".tgz"));
312 if (produced.length !== 1) {
313 throw new Error(
314 `Expected exactly 1 .tgz in ${pkgDir}, found ${produced.length}: ${produced.join(", ")}`,
315 );
316 }
317 const tarball = produced[0]!;
318
319 if (dryRun) {
320 return;
321 }
322
323 // Skip publishing already-shipped versions. The pack still ran above so
324 // smoke tests / pkg-pr-new previews always have a fresh tarball.
325 if (await packageAlreadyPublished(name, version)) {
326 console.log(`[skip] ${name}@${version} already on npm`);
327 return;
328 }
329
330 console.log(`[publish] ${name}@${version} (${channel})`);
331
332 const args = ["publish", tarball, "--access", "public", "--tag", channel];
333 if (process.env.GITHUB_ACTIONS === "true") {

Callers 1

mainFunction · 0.85

Calls 7

readPackageMetaFunction · 0.85
applyWorkspaceVersionsFunction · 0.85
applyPublishConfigFunction · 0.85
logMethod · 0.80
pushMethod · 0.80
resolveChannelFunction · 0.70
packageAlreadyPublishedFunction · 0.70

Tested by

no test coverage detected