fix: retry gateway watch after dist rebuild
This commit is contained in:
@@ -22,11 +22,32 @@ const compilerProcess = spawn("pnpm", ["tsdown", '--watch', 'src/'], {
|
|||||||
stdio: "inherit",
|
stdio: "inherit",
|
||||||
});
|
});
|
||||||
|
|
||||||
const nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
|
let nodeProcess = null;
|
||||||
cwd,
|
let restartTimer = null;
|
||||||
env,
|
|
||||||
stdio: "inherit",
|
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;
|
let exiting = false;
|
||||||
|
|
||||||
@@ -35,7 +56,11 @@ function cleanup(code = 0) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
exiting = true;
|
exiting = true;
|
||||||
nodeProcess.kill("SIGTERM");
|
if (restartTimer) {
|
||||||
|
clearTimeout(restartTimer);
|
||||||
|
restartTimer = null;
|
||||||
|
}
|
||||||
|
nodeProcess?.kill("SIGTERM");
|
||||||
compilerProcess.kill("SIGTERM");
|
compilerProcess.kill("SIGTERM");
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
}
|
}
|
||||||
@@ -49,10 +74,3 @@ compilerProcess.on("exit", (code) => {
|
|||||||
}
|
}
|
||||||
cleanup(code ?? 1);
|
cleanup(code ?? 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
nodeProcess.on("exit", (code, signal) => {
|
|
||||||
if (signal || exiting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cleanup(code ?? 1);
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user