fix: Update CONTRIBUTING.md + adjust watch-node.mjs again to be faster with tsc.

This commit is contained in:
cpojer 2026-01-31 19:36:07 +09:00
parent 76361ae3ab
commit dae00fe184
No known key found for this signature in database
GPG key ID: C29F94A3201118AF
2 changed files with 24 additions and 34 deletions

View file

@ -25,7 +25,7 @@ Welcome to the lobster tank! 🦞
## Before You PR ## Before You PR
- Test locally with your OpenClaw instance - Test locally with your OpenClaw instance
- Run linter: `npm run lint` - Run tests: `pnpm tsgo && pnpm format && pnpm lint && pnpm build && pnpm test`
- Keep PRs focused (one thing per PR) - Keep PRs focused (one thing per PR)
- Describe what & why - Describe what & why

View file

@ -5,8 +5,11 @@ import process from "node:process";
const args = process.argv.slice(2); const args = process.argv.slice(2);
const env = { ...process.env }; const env = { ...process.env };
const cwd = process.cwd(); 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", ["build"], { const initialBuild = spawnSync("pnpm", ["exec", compiler, ...projectArgs], {
cwd, cwd,
env, env,
stdio: "inherit", stdio: "inherit",
@ -16,38 +19,22 @@ if (initialBuild.status !== 0) {
process.exit(initialBuild.status ?? 1); process.exit(initialBuild.status ?? 1);
} }
const compilerProcess = spawn("pnpm", ["tsc", '-p', 'tsconfig.json', '--noEmit', 'false', '--watch'], { const watchArgs =
compiler === "tsc"
? [...projectArgs, "--watch", "--preserveWatchOutput"]
: [...projectArgs, "--watch"];
const compilerProcess = spawn("pnpm", ["exec", compiler, ...watchArgs], {
cwd, cwd,
env, env,
stdio: "inherit", stdio: "inherit",
}); });
let nodeProcess = null; const nodeProcess = spawn(process.execPath, ["--watch", "openclaw.mjs", ...args], {
let restartTimer = null; cwd,
env,
function spawnNode() { stdio: "inherit",
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;
@ -56,11 +43,7 @@ function cleanup(code = 0) {
return; return;
} }
exiting = true; exiting = true;
if (restartTimer) { nodeProcess.kill("SIGTERM");
clearTimeout(restartTimer);
restartTimer = null;
}
nodeProcess?.kill("SIGTERM");
compilerProcess.kill("SIGTERM"); compilerProcess.kill("SIGTERM");
process.exit(code); process.exit(code);
} }
@ -74,3 +57,10 @@ compilerProcess.on("exit", (code) => {
} }
cleanup(code ?? 1); cleanup(code ?? 1);
}); });
nodeProcess.on("exit", (code, signal) => {
if (signal || exiting) {
return;
}
cleanup(code ?? 1);
});