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