fix: Fix scripts/watch-node.mjs and use tsdown --watch.

This commit is contained in:
cpojer
2026-01-31 17:55:49 +09:00
parent 4b7406719c
commit 68ba1afb34
3 changed files with 24 additions and 14 deletions

View File

@@ -5,11 +5,8 @@ import process from "node:process";
const args = process.argv.slice(2);
const env = { ...process.env };
const cwd = process.cwd();
const compilerOverride = env.OPENCLAW_TS_COMPILER ?? env.CLAWDBOT_TS_COMPILER;
const compiler = compilerOverride === "tsc" ? "tsc" : "tsgo";
const projectArgs = ["--project", "tsconfig.json"];
const initialBuild = spawnSync("pnpm", ["exec", compiler, ...projectArgs], {
const initialBuild = spawnSync("pnpm", ["build"], {
cwd,
env,
stdio: "inherit",
@@ -19,12 +16,7 @@ if (initialBuild.status !== 0) {
process.exit(initialBuild.status ?? 1);
}
const watchArgs =
compiler === "tsc"
? [...projectArgs, "--watch", "--preserveWatchOutput"]
: [...projectArgs, "--watch"];
const compilerProcess = spawn("pnpm", ["exec", compiler, ...watchArgs], {
const compilerProcess = spawn("pnpm", ["tsdown", '--watch', 'src/'], {
cwd,
env,
stdio: "inherit",
@@ -39,7 +31,9 @@ const nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args]
let exiting = false;
function cleanup(code = 0) {
if (exiting) return;
if (exiting) {
return;
}
exiting = true;
nodeProcess.kill("SIGTERM");
compilerProcess.kill("SIGTERM");
@@ -50,11 +44,15 @@ process.on("SIGINT", () => cleanup(130));
process.on("SIGTERM", () => cleanup(143));
compilerProcess.on("exit", (code) => {
if (exiting) return;
if (exiting) {
return;
}
cleanup(code ?? 1);
});
nodeProcess.on("exit", (code, signal) => {
if (signal || exiting) return;
if (signal || exiting) {
return;
}
cleanup(code ?? 1);
});