compilerBinary
uses node:path
The compiler binary: TypeScript 7's own, or tsrs's (TCM_TYPESCRIPT=tsrs: the project's tsrs package, else one
installed alongside tcm), or one named by path.
import { require } from "#codebase/tcmts/core/ts"; import { createRequire } from "node:module"; import path from "node:path"; export function compilerBinary(): string | undefined { const choice = process.env.TCM_TYPESCRIPT; if (!choice || choice === "typescript") return undefined; if (choice !== "tsrs") return choice; let pkg: string | undefined; for (const from of [path.join(process.cwd(), "package.json"), import.meta.filename]) { try { pkg = createRequire(from).resolve("tsrs/package.json"); break; } catch { // not here } } if (!pkg) throw new Error("TCM_TYPESCRIPT=tsrs, but tsrs isn't installed: npm install --save-dev tsrs"); // the binary ships in a per-platform package; tsrs's own helper finds it return (require(path.join(path.dirname(pkg), "lib", "getExePath.js")) as { default: () => string }).default(); }