build.mjs 796 B

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