fix(scripts): reap child check processes

This commit is contained in:
Vincent Koc
2026-04-23 08:44:22 -07:00
parent 5071c58346
commit ecefe1c39c
4 changed files with 249 additions and 46 deletions

View File

@@ -1,4 +1,3 @@
import { spawn } from "node:child_process";
import { performance } from "node:perf_hooks";
import {
detectChangedLanes,
@@ -8,6 +7,7 @@ import {
} from "./changed-lanes.mjs";
import { booleanFlag, parseFlagArgs, stringFlag } from "./lib/arg-utils.mjs";
import { printTimingSummary } from "./lib/check-timing-summary.mjs";
import { runManagedCommand } from "./lib/managed-child-process.mjs";
import { resolveChangedTestTargetPlan } from "./test-projects.test-support.mjs";
export function createChangedCheckPlan(result, options = {}) {
@@ -216,31 +216,22 @@ async function runNode(command, timings) {
async function runCommand(command, timings) {
const startedAt = performance.now();
console.error(`\n[check:changed] ${command.name}`);
const child = spawn(command.bin, command.args, {
stdio: "inherit",
shell: process.platform === "win32",
});
let status = 1;
try {
status = await runManagedCommand({
bin: command.bin,
args: command.args,
});
} catch (error) {
console.error(error);
}
return await new Promise((resolve) => {
child.once("error", (error) => {
console.error(error);
timings.push({
name: command.name,
durationMs: performance.now() - startedAt,
status: 1,
});
resolve(1);
});
child.once("close", (status) => {
const resolvedStatus = status ?? 1;
timings.push({
name: command.name,
durationMs: performance.now() - startedAt,
status: resolvedStatus,
});
resolve(resolvedStatus);
});
timings.push({
name: command.name,
durationMs: performance.now() - startedAt,
status,
});
return status;
}
function printSummary(timings, options) {