verify-entry-lib.mjs 950 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env node
  2. /**
  3. * Prepack gate for entry packages: refuse to pack a tarball whose built
  4. * `lib/` is missing. Entry `files` lists use globs, and a glob matching
  5. * nothing packs a silently JS-less tarball instead of failing — this gate
  6. * turns that into a loud refusal on a checkout that never ran
  7. * `pnpm build:ts`.
  8. *
  9. * Runs from each entry package's `prepack` hook (pnpm sets the script cwd
  10. * to the package directory).
  11. */
  12. import fs from 'node:fs';
  13. import path from 'node:path';
  14. const packageDir = process.cwd();
  15. const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
  16. for (const file of ['lib/index.js', 'lib/index.d.ts']) {
  17. if (!fs.existsSync(path.join(packageDir, file))) {
  18. console.error(`verify-entry-lib: ${manifest.name} has no ${file} — run \`pnpm build:ts\` before packing.`);
  19. process.exit(1);
  20. }
  21. }
  22. console.log(`verify-entry-lib: ${manifest.name} built lib/ present.`);