revert: Switch back to tsc for compiling.

This commit is contained in:
cpojer
2026-01-31 18:31:49 +09:00
parent e25fedf932
commit 76361ae3ab
36 changed files with 527 additions and 843 deletions

View File

@@ -1,21 +1,24 @@
#!/usr/bin/env node
import { spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { spawn } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
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 compiler = compilerOverride === 'tsc' ? 'tsc' : 'tsgo';
const projectArgs = ['--project', 'tsconfig.json'];
const distRoot = path.join(cwd, "dist");
const distEntry = path.join(distRoot, "entry.mjs");
const buildStampPath = path.join(distRoot, ".buildstamp");
const srcRoot = path.join(cwd, "src");
const configFiles = [path.join(cwd, "tsconfig.json"), path.join(cwd, "package.json")];
const distRoot = path.join(cwd, 'dist');
const distEntry = path.join(distRoot, '/entry.js');
const buildStampPath = path.join(distRoot, '.buildstamp');
const srcRoot = path.join(cwd, 'src');
const configFiles = [
path.join(cwd, 'tsconfig.json'),
path.join(cwd, 'package.json'),
];
const statMtime = (filePath) => {
try {
@@ -27,10 +30,10 @@ const statMtime = (filePath) => {
const isExcludedSource = (filePath) => {
const relativePath = path.relative(srcRoot, filePath);
if (relativePath.startsWith("..")) return false;
if (relativePath.startsWith('..')) return false;
return (
relativePath.endsWith(".test.ts") ||
relativePath.endsWith(".test.tsx") ||
relativePath.endsWith('.test.ts') ||
relativePath.endsWith('.test.tsx') ||
relativePath.endsWith(`test-helpers.ts`)
);
};
@@ -66,7 +69,7 @@ const findLatestMtime = (dirPath, shouldSkip) => {
};
const shouldBuild = () => {
if (env.OPENCLAW_FORCE_BUILD === "1") return true;
if (env.OPENCLAW_FORCE_BUILD === '1') return true;
const stampMtime = statMtime(buildStampPath);
if (stampMtime == null) return true;
if (statMtime(distEntry) == null) return true;
@@ -82,18 +85,18 @@ const shouldBuild = () => {
};
const logRunner = (message) => {
if (env.OPENCLAW_RUNNER_LOG === "0") return;
if (env.OPENCLAW_RUNNER_LOG === '0') return;
process.stderr.write(`[openclaw] ${message}\n`);
};
const runNode = () => {
const nodeProcess = spawn(process.execPath, ["openclaw.mjs", ...args], {
const nodeProcess = spawn(process.execPath, ['openclaw.mjs', ...args], {
cwd,
env,
stdio: "inherit",
stdio: 'inherit',
});
nodeProcess.on("exit", (exitCode, exitSignal) => {
nodeProcess.on('exit', (exitCode, exitSignal) => {
if (exitSignal) {
process.exit(1);
}
@@ -107,25 +110,29 @@ const writeBuildStamp = () => {
fs.writeFileSync(buildStampPath, `${Date.now()}\n`);
} catch (error) {
// Best-effort stamp; still allow the runner to start.
logRunner(`Failed to write build stamp: ${error?.message ?? "unknown error"}`);
logRunner(
`Failed to write build stamp: ${error?.message ?? 'unknown error'}`,
);
}
};
if (!shouldBuild()) {
runNode();
} else {
logRunner("Building TypeScript (dist is stale).");
const pnpmArgs = ["exec", compiler, ...projectArgs];
const buildCmd = process.platform === "win32" ? "cmd.exe" : "pnpm";
logRunner('Building TypeScript (dist is stale).');
const pnpmArgs = ['exec', compiler, ...projectArgs];
const buildCmd = process.platform === 'win32' ? 'cmd.exe' : 'pnpm';
const buildArgs =
process.platform === "win32" ? ["/d", "/s", "/c", "pnpm", ...pnpmArgs] : pnpmArgs;
process.platform === 'win32'
? ['/d', '/s', '/c', 'pnpm', ...pnpmArgs]
: pnpmArgs;
const build = spawn(buildCmd, buildArgs, {
cwd,
env,
stdio: "inherit",
stdio: 'inherit',
});
build.on("exit", (code, signal) => {
build.on('exit', (code, signal) => {
if (signal) {
process.exit(1);
}