( pkgDir: string, dryRun: boolean, publishable: ReadonlySet<string>, publishableVersions: ReadonlyMap<string, string>, )
| 274 | }; |
| 275 | |
| 276 | const 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") { |
no test coverage detected