From 68ba1afb34ee97b045e02d7a175102182f4210ed Mon Sep 17 00:00:00 2001 From: cpojer Date: Sat, 31 Jan 2026 17:55:49 +0900 Subject: [PATCH] fix: Fix `scripts/watch-node.mjs` and use `tsdown --watch`. --- package.json | 2 +- scripts/watch-node.mjs | 24 +++++++++++------------- tsdown.config.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 tsdown.config.ts diff --git a/package.json b/package.json index 03c3fdfbc..a22a71838 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "docs:bin": "node scripts/build-docs-list.mjs", "docs:dev": "cd docs && mint dev", "docs:build": "cd docs && pnpm dlx --reporter append-only mint broken-links", - "build": "pnpm canvas:a2ui:bundle && tsdown src/index.ts src/entry.ts && node --import tsx scripts/canvas-a2ui-copy.ts && node --import tsx scripts/copy-hook-metadata.ts && node --import tsx scripts/write-build-info.ts", + "build": "pnpm canvas:a2ui:bundle && tsdown && node --import tsx scripts/canvas-a2ui-copy.ts && node --import tsx scripts/copy-hook-metadata.ts && node --import tsx scripts/write-build-info.ts", "plugins:sync": "node --import tsx scripts/sync-plugin-versions.ts", "release:check": "node --import tsx scripts/release-check.ts", "ui:install": "node scripts/ui.js install", diff --git a/scripts/watch-node.mjs b/scripts/watch-node.mjs index 8340e5934..70f54c1a6 100644 --- a/scripts/watch-node.mjs +++ b/scripts/watch-node.mjs @@ -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); }); diff --git a/tsdown.config.ts b/tsdown.config.ts new file mode 100644 index 000000000..09fdaf026 --- /dev/null +++ b/tsdown.config.ts @@ -0,0 +1,12 @@ +import { defineConfig } from 'tsdown' + +export default defineConfig([ + { + entry: 'src/index.ts', + platform: 'node', + }, + { + entry: 'src/entry.ts', + platform: 'node', + }, +])