verify-launcher-binary.mjs 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env node
  2. /**
  3. * Prepack gate for platform packages: refuse to pack a tarball whose
  4. * declared binaries are missing or built for the wrong architecture.
  5. *
  6. * Without it, `pnpm pack` on a checkout that never ran
  7. * `pnpm run build:native` would ship an EMPTY platform package — the
  8. * binary's absence surfacing only at runtime as a failed probe on every
  9. * consumer — and a binary copied across packages would advertise an
  10. * architecture it cannot execute. The check is presence + ELF `e_machine`
  11. * against the package's declared `cpu`; byte provenance is
  12. * `verify-packed-install.mjs`'s concern (it pins the installed tarball
  13. * against the workspace build).
  14. *
  15. * Runs from each platform package's `prepack` hook (pnpm sets the script
  16. * cwd to the package directory). Also callable directly with an explicit
  17. * package directory: `node scripts/verify-launcher-binary.mjs packages/<name>`.
  18. */
  19. import path from 'node:path';
  20. import { root, verifyPlatformBinaries } from './repo.mjs';
  21. const packageDir = process.argv[2] ? path.resolve(root, process.argv[2]) : process.cwd();
  22. try {
  23. const { name, count } = verifyPlatformBinaries(packageDir);
  24. console.log(`verify-launcher-binary: ${name} — ${count} binaries present with the right ELF architecture.`);
  25. } catch (error) {
  26. console.error(`verify-launcher-binary: ${error instanceof Error ? error.message : error}`);
  27. process.exit(1);
  28. }