mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
87 lines
2.5 KiB
TypeScript
87 lines
2.5 KiB
TypeScript
// Runs tsgo through local heavy-check policy and sparse-checkout guards.
|
|
import { spawnSync } from "node:child_process";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { readFlagValue } from "./lib/arg-utils.mts";
|
|
import {
|
|
acquireLocalHeavyCheckLockSync,
|
|
applyLocalTsgoPolicy,
|
|
ensureRepoToolNodeModulesLink,
|
|
resolveLocalHeavyCheckEnv,
|
|
resolveRepoToolBinPath,
|
|
shouldAcquireLocalHeavyCheckLockForTsgo,
|
|
} from "./lib/local-heavy-check-runtime.mts";
|
|
import { createManagedCommandInvocation } from "./lib/managed-child-process.mts";
|
|
import {
|
|
getSparseTsgoGuardError,
|
|
shouldSkipSparseTsgoGuardError,
|
|
} from "./lib/tsgo-sparse-guard.mts";
|
|
|
|
function main(): void {
|
|
const hostResources = {
|
|
logicalCpuCount:
|
|
typeof os.availableParallelism === "function" ? os.availableParallelism() : os.cpus().length,
|
|
totalMemoryBytes: os.totalmem(),
|
|
};
|
|
const { args: finalArgs, env } = applyLocalTsgoPolicy(
|
|
process.argv.slice(2),
|
|
resolveLocalHeavyCheckEnv(process.env),
|
|
hostResources,
|
|
);
|
|
|
|
const tsgoPath = resolveRepoToolBinPath("tsgo");
|
|
const tsBuildInfoFile = readFlagValue(finalArgs, "--tsBuildInfoFile");
|
|
if (tsBuildInfoFile) {
|
|
fs.mkdirSync(path.dirname(path.resolve(tsBuildInfoFile)), { recursive: true });
|
|
}
|
|
const sparseGuardError = getSparseTsgoGuardError(finalArgs, { cwd: process.cwd() });
|
|
const releaseLock =
|
|
sparseGuardError ||
|
|
env.OPENCLAW_TSGO_HEAVY_CHECK_LOCK_HELD === "1" ||
|
|
!shouldAcquireLocalHeavyCheckLockForTsgo(finalArgs, env)
|
|
? () => {}
|
|
: acquireLocalHeavyCheckLockSync({
|
|
cwd: process.cwd(),
|
|
env,
|
|
toolName: "tsgo",
|
|
});
|
|
|
|
try {
|
|
if (sparseGuardError) {
|
|
console.error(sparseGuardError);
|
|
if (shouldSkipSparseTsgoGuardError(env)) {
|
|
console.error("[tsgo] skipping sparse-missing project because OPENCLAW_TSGO_SPARSE_SKIP=1");
|
|
process.exitCode = 0;
|
|
} else {
|
|
process.exitCode = 1;
|
|
}
|
|
} else {
|
|
ensureRepoToolNodeModulesLink(tsgoPath);
|
|
const tsgo = createManagedCommandInvocation({
|
|
args: finalArgs,
|
|
bin: tsgoPath,
|
|
env,
|
|
});
|
|
const result = spawnSync(tsgo.command, tsgo.args, {
|
|
stdio: "inherit",
|
|
env,
|
|
shell: tsgo.shell,
|
|
windowsVerbatimArguments: tsgo.windowsVerbatimArguments,
|
|
});
|
|
|
|
if (result.error) {
|
|
throw result.error;
|
|
}
|
|
|
|
process.exitCode = result.status ?? 1;
|
|
}
|
|
} finally {
|
|
releaseLock();
|
|
}
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
main();
|
|
}
|