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

Function packPackage

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls 5

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

Tested by

no test coverage detected