| 60 | } |
| 61 | |
| 62 | function run(msg: Msg) { |
| 63 | return new Promise<{ code: number; stdout: Buffer; stderr: Buffer }>((resolve) => { |
| 64 | const proc = spawn(process.execPath, [worker, JSON.stringify(msg)], { |
| 65 | cwd: root, |
| 66 | }) |
| 67 | |
| 68 | const stdout: Buffer[] = [] |
| 69 | const stderr: Buffer[] = [] |
| 70 | |
| 71 | proc.stdout?.on("data", (data) => stdout.push(Buffer.from(data))) |
| 72 | proc.stderr?.on("data", (data) => stderr.push(Buffer.from(data))) |
| 73 | |
| 74 | proc.on("close", (code) => { |
| 75 | resolve({ |
| 76 | code: code ?? 1, |
| 77 | stdout: Buffer.concat(stdout), |
| 78 | stderr: Buffer.concat(stderr), |
| 79 | }) |
| 80 | }) |
| 81 | }) |
| 82 | } |
| 83 | |
| 84 | function spawnWorker(msg: Msg) { |
| 85 | return spawn(process.execPath, [worker, JSON.stringify(msg)], { |