verify-launcher-binary.mjs 1.4 KB

123456789101112131415161718192021222324252627282930
  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. Checks cover ELF/Mach-O format, architecture,
  11. * declared payloads, and Node-API exports. `verify-packed-install.mjs`
  12. * separately pins the installed tarball bytes to the workspace build.
  13. *
  14. * Runs from each platform package's `prepack` hook (pnpm sets the script
  15. * cwd to the package directory). Also callable directly with an explicit
  16. * package directory: `node scripts/verify-launcher-binary.mjs packages/<name>`.
  17. */
  18. import path from 'node:path';
  19. import { root, verifyPlatformBinaries } from './repo.mjs';
  20. const packageDir = process.argv[2] ? path.resolve(root, process.argv[2]) : process.cwd();
  21. try {
  22. const { name, count } = verifyPlatformBinaries(packageDir);
  23. console.log(`verify-launcher-binary: ${name} — ${count} binaries present with the right native format and architecture.`);
  24. } catch (error) {
  25. console.error(`verify-launcher-binary: ${error instanceof Error ? error.message : error}`);
  26. process.exit(1);
  27. }