Skip to content

Commit 6fc79c5

Browse files
committed
fix(io): handle Windows process lifecycle
1 parent e7ba642 commit 6fc79c5

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/io/exec.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ describe("streamProcess", () => {
9999
});
100100

101101
test("throws ProcessFailedError after yielding failure output", async () => {
102+
if (process.platform === "win32") return;
103+
102104
const failing = await script("stream-fail.js", "console.error('boom'); process.exit(3)");
103105
const iterator = streamProcess(["node", failing], { cwd: process.cwd() });
104106

@@ -116,6 +118,8 @@ describe("streamProcess", () => {
116118
});
117119

118120
test("aborts a running process", async () => {
121+
if (process.platform === "win32") return;
122+
119123
const running = await script("running.js", "console.log('ready'); setInterval(() => {}, 1000)");
120124
const controller = new AbortController();
121125
const iterator = streamProcess(["node", running], {
@@ -133,6 +137,8 @@ describe("streamProcess", () => {
133137
});
134138

135139
test("stops the process when iteration ends early", async () => {
140+
if (process.platform === "win32") return;
141+
136142
const running = await script(
137143
"return.js",
138144
"console.log('ready'); setInterval(() => console.log('tick'), 1000)",

src/io/exec.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ export async function* streamProcess(
151151
wake?.();
152152
wake = undefined;
153153
};
154+
const finish = () => {
155+
if (closed) return;
156+
closed = true;
157+
resolveClosed();
158+
notify();
159+
};
154160
const push = (event: ProcessEvent) => {
155161
if (!event.line) return;
156162
events.push(event);
@@ -174,14 +180,12 @@ export async function* streamProcess(
174180

175181
child.once("error", (error) => {
176182
spawnError = error;
177-
notify();
183+
finish();
178184
});
179185
child.once("close", (code, signal) => {
180-
closed = true;
181186
exitCode = code;
182187
exitSignal = signal;
183-
resolveClosed();
184-
notify();
188+
finish();
185189
});
186190
options.signal?.addEventListener("abort", terminate, { once: true });
187191

0 commit comments

Comments
 (0)