Skip to content

Commit 0de804c

Browse files
committed
fix(appkit): forward execArgv so the detached typegen worker runs under tsx
The non-blocking CLI spawned its background worker as `node <argv[1]>` without the parent's node/loader flags. Run from source via tsx, argv[1] is a .ts file that plain node can't parse, so the worker died silently (detached + stdio ignore) and the degraded types never refreshed -- the queries appeared to never run. Forward process.execArgv, which carries tsx's --require/--import loader flags (and is empty for the built bin, so production is unaffected), so the worker runs under the same runtime as the parent. Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
1 parent b698c43 commit 0de804c

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/shared/src/cli/commands/generate-types.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,15 @@ describe("generate-types foreground spawn orchestration", () => {
146146
expect(spawn).toHaveBeenCalledTimes(1);
147147
const [bin, argv, opts] = spawn.mock.calls[0];
148148
expect(bin).toBe(process.execPath);
149-
expect(argv[0]).toBe(process.argv[1]); // CLI entry
150-
expect(argv.slice(1)).toEqual([
149+
// The parent's node/loader flags (process.execArgv — e.g. tsx's
150+
// --require/--import) are forwarded before the CLI entry so a worker spawned
151+
// from a source/tsx run can still execute the .ts. Everything from the entry
152+
// onward is the worker invocation.
153+
const entryIdx = argv.indexOf(process.argv[1]);
154+
expect(entryIdx).toBeGreaterThanOrEqual(0);
155+
expect(argv.slice(0, entryIdx)).toEqual(process.execArgv);
156+
expect(argv.slice(entryIdx)).toEqual([
157+
process.argv[1], // CLI entry
151158
"generate-types",
152159
"--block",
153160
"--worker-lock",

packages/shared/src/cli/commands/generate-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ export function spawnTypegenWorker(
159159
}
160160

161161
const args = [
162+
// Forward the parent's node/loader flags so the worker runs under the same
163+
// runtime. Critically this carries tsx's `--require`/`--import` when the CLI
164+
// is run from source (`tsx index.ts …`); without them the worker would be
165+
// `node index.ts …`, which can't parse TypeScript and dies silently — the
166+
// degraded types would then never refresh. Empty for the built bin (plain
167+
// `node bin/appkit.js`), so production behaviour is unchanged.
168+
...process.execArgv,
162169
cliEntry,
163170
"generate-types",
164171
"--block",

0 commit comments

Comments
 (0)