compareCompilers
uses node:fs
Hashes don't depend on the compiler (pnpm compare-compilers): every definition in tcm's codebase, rendered and
hashed again with tsrs (TypeScript 7 in Rust, installed into a temporary directory), must be the hash TypeScript 7
gave it (tcm verify), and the golden hashes must pass with tsrs too.
import { codebaseDir, sh } from "#codebase/tcmts/dev"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; export function compareCompilers(): void { const tcm = process.env.TCM_BIN; if (!tcm) throw new Error("run this with `tcm run`, which gives it the codebase's own tcm (TCM_BIN)"); const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "tcm tsrs ")); fs.writeFileSync(path.join(tmp, "package.json"), '{"private":true}\n'); const installed = sh( "npm", ["install", "--no-audit", "--no-fund", "--loglevel=error", "tsrs"], tmp, ); if (!installed.ok) throw new Error(`installing tsrs: ${installed.out}`); const tsrs = sh( process.execPath, [ "--input-type=module", "-e", 'import("./node_modules/tsrs/lib/getExePath.js").then((m) => console.log(m.default()))', ], tmp, ).out.trim(); const same = sh(process.execPath, [tcm, "verify"], codebaseDir(), { TCM_TYPESCRIPT: tsrs }); console.log(`with tsrs: ${same.out.trim().split("\n").at(-1)}`); if (!same.ok) { process.exitCode = 1; return; } const golden = sh( process.execPath, [tcm, "test", "tcmts.core.test", "--definitions", "--fresh"], codebaseDir(), { TCM_TYPESCRIPT: tsrs }, ); console.log(`golden hashes with tsrs: ${golden.out.trim().split("\n").at(-1)}`); process.exitCode = golden.ok ? 0 : 1; }