|
1 | 1 | /** |
2 | 2 | * Pipeline step 7 (deploy-cli.md § The pipeline; design-notes.md's "Driving |
3 | | - * Alchemy" call): hand the terminal to the generated stack file. Resolves the |
4 | | - * workspace's own installed `alchemy` bin (walking up `node_modules/.bin` |
5 | | - * from the generated file's package dir) rather than going through |
6 | | - * `bunx`/`npx`, so this works the same under node and bun — the resolved |
7 | | - * bin's own launcher (`alchemy/bin/cli.js`) does its own node/bun dispatch |
8 | | - * from there, driven by the env it inherits. |
| 3 | + * Alchemy" call): hand the terminal to the generated stack file. |
| 4 | + * |
| 5 | + * Resolves the workspace's installed `alchemy` bin. The actual child runner |
| 6 | + * uses Execa, which handles package-manager shims and shebangs on Windows |
| 7 | + * without a shell while preserving argv boundaries. |
9 | 8 | * |
10 | 9 | * This module composes the invocation; it does not decide how the child is |
11 | 10 | * started. Under the CLI the engine starts it (`ctx.spawn`), which is what |
12 | 11 | * makes Ctrl-C reach the child natively and keeps signal policy in one place. |
13 | 12 | * `spawnAlchemy` is the default for programmatic hosts driving |
14 | 13 | * `@prisma/composer/control`, which have no engine to borrow. |
15 | 14 | */ |
16 | | -import { spawn } from 'node:child_process'; |
17 | 15 | import * as fs from 'node:fs'; |
18 | 16 | import * as path from 'node:path'; |
19 | 17 | import { CliStructuredError } from '@internal/foundation/errors'; |
| 18 | +import { execa } from 'execa'; |
20 | 19 |
|
21 | 20 | /** Walks up from `startDir` looking for `node_modules/.bin/alchemy`. */ |
22 | 21 | export function resolveAlchemyBin(startDir: string): string { |
@@ -131,15 +130,15 @@ export function alchemyInvocation(input: AlchemyInvocationInput): AlchemyInvocat |
131 | 130 | */ |
132 | 131 | export const spawnAlchemy: RunAlchemy = async (invocation) => { |
133 | 132 | const line = alchemyCommandLine(invocation); |
134 | | - return new Promise<AlchemyOutcome>((resolve, reject) => { |
135 | | - const child = spawn(line.command, [...line.args], { |
136 | | - cwd: line.cwd, |
137 | | - stdio: 'inherit', |
138 | | - env: { ...process.env, ...line.env }, |
139 | | - }); |
140 | | - child.on('error', reject); |
141 | | - child.on('close', (exitCode, signal) => { |
142 | | - resolve({ exitCode, signal }); |
143 | | - }); |
| 133 | + const result = await execa(line.command, line.args, { |
| 134 | + cwd: line.cwd, |
| 135 | + stdio: 'inherit', |
| 136 | + env: line.env, |
| 137 | + reject: false, |
144 | 138 | }); |
| 139 | + if (result.exitCode === undefined && result.signal === undefined) throw result; |
| 140 | + return { |
| 141 | + exitCode: result.exitCode ?? null, |
| 142 | + signal: result.signal ?? null, |
| 143 | + }; |
145 | 144 | }; |
0 commit comments