Files
rea/scripts/run-typescript.mjs
T
gensokyo-dev 905cbaf239 perf(ci): use tsrs and reduce PE acceptance startup (#5795)
Use pinned tsrs on supported development hosts while retaining stable official
TypeScript on Windows and unsupported platforms. Partition compile/typecheck
caches by actual compiler and qualify fallback hosts for compiler inputs and
lifecycle hooks.

Reduce PE acceptance startup through the existing bounded compiled CLI. Retain
upstream named MCP definitions, every fixture/assertion and the original 30s
deadline. Verify that browser transport loss preserves the observed target.

Validation: full qualification and real host lanes in
https://github.com/morluto/rea/actions/runs/39590450889 ; 450 focused regressions
passed with two documented conditional skips. All 1724 production emit files
match SHA-256 and size across both compilers. Current-head Codex/Greptile review
found no actionable issues. Measurements and limitations are in the PR.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
2026-10-21 19:47:52 +08:00

76 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
import { readFileSync } from "node:fs";
import { createRequire } from "node:module";
import { availableParallelism } from "node:os";
import { dirname, resolve } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
/** Use the pinned package's platform inventory; let its launcher select libc. */
export const selectTypeScriptCompiler = (
platform,
arch,
optionalDependencies,
) => {
if (platform === "win32") return "typescript";
const prefix = `@tsrs/${platform}-${arch}`;
return Object.keys(optionalDependencies).some(
(name) => name === prefix || name.startsWith(`${prefix}-`),
)
? "tsrs"
: "typescript";
};
export const resolveTypeScriptCompiler = () => {
const require = createRequire(import.meta.url);
const rustPackagePath = require.resolve("tsrs/package.json");
const rustPackage = JSON.parse(readFileSync(rustPackagePath, "utf8"));
const compiler = selectTypeScriptCompiler(
process.platform,
process.arch,
rustPackage.optionalDependencies,
);
const packagePath =
compiler === "tsrs"
? rustPackagePath
: require.resolve("typescript/package.json");
const metadata =
compiler === "tsrs"
? rustPackage
: JSON.parse(readFileSync(packagePath, "utf8"));
const command = compiler === "tsrs" ? "tsrs" : "tsc";
return {
name: compiler,
identity: `${compiler}@${metadata.version}`,
launcher: resolve(dirname(packagePath), metadata.bin[command]),
};
};
const main = async () => {
const compiler = resolveTypeScriptCompiler();
if (
process.env.TURBO_HASH !== undefined &&
process.env.REA_TYPESCRIPT_COMPILER !== compiler.identity
)
throw new Error(
"Compiler identity is missing or stale. Run Turbo through scripts/run-turbo.mjs.",
);
if (compiler.name === "tsrs") {
const args = process.argv.slice(2);
// Rust consumes --maxMemory once; duplicating it becomes an unknown option.
// Preserve explicit resource choices rather than injecting another value.
const defaults = [
["--checkers", String(Math.min(2, availableParallelism()))],
["--maxMemory", "3G"],
].flatMap(([option, value]) =>
args.includes(option) ? [] : [option, value],
);
process.argv.splice(2, 0, ...defaults);
}
// Delegate execution, diagnostics, status and signals to the package's launcher.
// An unavailable binary on a supported host must fail rather than hide drift.
await import(pathToFileURL(compiler.launcher).href);
};
if (process.argv[1] === fileURLToPath(import.meta.url)) await main();