build.mjs 769 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { spawnSync } from 'node:child_process';
  2. const pnpmCommand =
  3. process.env.npm_execpath &&
  4. process.env.npm_execpath.endsWith('.cjs')
  5. ? [process.execPath, process.env.npm_execpath]
  6. : [process.platform === 'win32' ? 'pnpm.cmd' : 'pnpm'];
  7. const steps = [
  8. ['exec', 'tsdown', '--no-dts'],
  9. [
  10. 'exec',
  11. 'tsc',
  12. '-p',
  13. 'tsconfig.build.json',
  14. '--emitDeclarationOnly',
  15. '--declaration',
  16. '--outDir',
  17. 'dist',
  18. ],
  19. ];
  20. for (const args of steps) {
  21. const [command, ...commandArgs] = pnpmCommand;
  22. const result = spawnSync(command, [...commandArgs, ...args], {
  23. shell: false,
  24. stdio: 'inherit',
  25. });
  26. if (result.error) {
  27. throw result.error;
  28. }
  29. if (result.status !== 0) {
  30. process.exit(result.status ?? 1);
  31. }
  32. }