fix: retry gateway watch after dist rebuild

This commit is contained in:
Peter Steinberger
2026-01-31 09:18:33 +00:00
parent ddc5683c67
commit e25fedf932

View File

@@ -22,11 +22,32 @@ const compilerProcess = spawn("pnpm", ["tsdown", '--watch', 'src/'], {
stdio: "inherit",
});
const nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
cwd,
env,
stdio: "inherit",
});
let nodeProcess = null;
let restartTimer = null;
function spawnNode() {
nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
cwd,
env,
stdio: "inherit",
});
nodeProcess.on("exit", (code, signal) => {
if (signal || exiting) {
return;
}
// If the build is mid-refresh, node can exit on missing modules. Retry.
if (restartTimer) {
clearTimeout(restartTimer);
}
restartTimer = setTimeout(() => {
restartTimer = null;
spawnNode();
}, 250);
});
}
spawnNode();
let exiting = false;
@@ -35,7 +56,11 @@ function cleanup(code = 0) {
return;
}
exiting = true;
nodeProcess.kill("SIGTERM");
if (restartTimer) {
clearTimeout(restartTimer);
restartTimer = null;
}
nodeProcess?.kill("SIGTERM");
compilerProcess.kill("SIGTERM");
process.exit(code);
}
@@ -49,10 +74,3 @@ compilerProcess.on("exit", (code) => {
}
cleanup(code ?? 1);
});
nodeProcess.on("exit", (code, signal) => {
if (signal || exiting) {
return;
}
cleanup(code ?? 1);
});