import { execFile } from "node:child_process" const TYPESCRIPT_PACKAGE = "typescript@^7.0.2" const MAX_COMPILER_OUTPUT_BYTES = 10 * 1024 * 1024 /** * Runs the project's configured TypeScript check with TypeScript 7. * * @param cwd Project directory containing the TypeScript configuration. */ export function typecheckProject(cwd: string) { return new Promise((resolve, reject) => { execFile( "bunx", ["--package", TYPESCRIPT_PACKAGE, "tsc", "--noEmit"], { cwd, encoding: "utf8", maxBuffer: MAX_COMPILER_OUTPUT_BYTES }, (error, stdout, stderr) => { if (!error) { resolve() return } reject( new Error( [stdout, stderr] .map((output) => output.trim()) .filter(Boolean) .join("\n") || "TypeScript typecheck failed.", { cause: error }, ), ) }, ) }) }