Files
reverse-engineering-anything/scripts/run-typescript.mjs
T
morluto 5a2a08a048 perf(ci): split lazy runtime chunks, cache Windows typecheck, and reuse test analysis workers (#11827)
* perf(runtime): eliminate static imports that defeat lazy provider and workflow chunk splitting

* perf(ci): cache Windows typecheck in Turbo, bound official compiler checkers, and reuse portable build cache in reverse-tools

* perf(package): batch staging file copies and extract packed metadata in one pass

* perf(tests): reuse parked JavaScript analysis workers and eliminate redundant CLI and Node spawns

* fix(tests): retain failed cleanup owners across non-isolated files and settle concurrent verifier copies

* fix(providers): propagate underlying cleanup release claims through DeferredAnalysisClient
2026-11-17 08:28:59 -05:00

75 lines
2.6 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.",
);
const args = process.argv.slice(2);
// Both tsrs and TypeScript 7 (tsgo) accept --checkers; only tsrs accepts
// --maxMemory (TypeScript 7 uses GOMEMLIMIT). Preserve explicit resource
// choices rather than injecting another value.
const defaults = [
["--checkers", String(Math.min(2, availableParallelism()))],
...(compiler.name === "tsrs" ? [["--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();