pack.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Pack one release family's whole publish set into a single directory, in
  3. * publish order, and record that order for the publish step.
  4. *
  5. * The pack step is the release boundary: it runs without credentials, produces
  6. * every tarball from one commit, and hands the publish step exactly those bytes
  7. * ([rationale](../../.agents/notes/implemented/process/2026-08-10-npm-release-sequences.md)).
  8. */
  9. import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
  10. import { join, resolve } from 'node:path'
  11. import { parseArgs } from 'node:util'
  12. import { releaseFamily, tarballName, type ReleaseFamily, type ReleaseMember } from './families.ts'
  13. import { isEntry, run } from './process.ts'
  14. import { PUBLISH_ORDER_FILE, tarballFiles } from './tarball.ts'
  15. /** Where pack output lands when `--out` is omitted. */
  16. const DEFAULT_OUTPUT = 'dist/npm'
  17. /**
  18. * Pack one member and check what its tarball carries.
  19. * @param family - the release family being packed.
  20. * @param member - the member to pack.
  21. * @param destination - absolute output directory.
  22. * @returns The tarball filename.
  23. */
  24. function packMember(family: ReleaseFamily, member: ReleaseMember, destination: string): string {
  25. run('pnpm', ['--dir', member.directory, 'pack', '--pack-destination', destination])
  26. const filename = tarballName(member)
  27. const tarball = join(destination, filename)
  28. if (!existsSync(tarball)) throw new Error(`${member.name} produced no tarball at ${tarball}`)
  29. family.validatePayload(member, tarballFiles(tarball))
  30. return filename
  31. }
  32. /** Pack the family named by `--family` into `--out`. */
  33. function main(): void {
  34. const { values } = parseArgs({
  35. options: { family: { type: 'string' }, out: { type: 'string' } },
  36. allowPositionals: false,
  37. })
  38. if (values.family === undefined) throw new Error('usage: pack.ts --family <dsh|vendor> [--out dist/npm]')
  39. const family = releaseFamily(values.family)
  40. const root = process.cwd()
  41. const destination = resolve(root, values.out ?? DEFAULT_OUTPUT)
  42. const members = family.publishOrder(family.members(root)).order
  43. family.verifyBuildArtifacts(root)
  44. family.verifyVersions(members)
  45. rmSync(destination, { recursive: true, force: true })
  46. mkdirSync(destination, { recursive: true })
  47. const order: string[] = []
  48. for (const member of members) order.push(packMember(family, member, destination))
  49. writeFileSync(join(destination, PUBLISH_ORDER_FILE), `${order.join('\n')}\n`)
  50. console.log(`release pack: family ${family.id}, ${String(order.length)} tarball(s) in ${values.out ?? DEFAULT_OUTPUT}`)
  51. }
  52. if (isEntry(import.meta.url)) main()