Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions scripts/start-bb.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ function waitForProcess(child) {
}

export async function runBuildProcess(request) {
const child = spawn(request.command, request.args, {
cwd: request.cwd,
detached: supportsProcessGroups(),
env: request.env,
stdio: "inherit",
});
let child;
let stopPromise;
const stopChild = () => {
stopPromise ??= stopProcessGroupLeaderFirst({
Expand All @@ -42,10 +37,18 @@ export async function runBuildProcess(request) {
};
const handleSigint = () => stopChild();
const handleSigterm = () => stopChild();
// Register before spawn so a child that becomes ready immediately cannot
// prompt another process to signal us before the handlers exist.
process.on("SIGINT", handleSigint);
process.on("SIGTERM", handleSigterm);

try {
child = spawn(request.command, request.args, {
cwd: request.cwd,
detached: supportsProcessGroups(),
env: request.env,
stdio: "inherit",
});
const result = await waitForProcess(child);
await stopPromise;
return result;
Expand Down
Loading