import { readFileSync } from "node:fs"; import { resolve } from "node:path"; import { runBuild } from "./build.ts"; import { runTypecheck } from "./types.ts"; import { assertReachability } from "./reachability.ts"; async function runScript(root: string, name: string): Promise { const child = Bun.spawn(["bun", "run", name], { cwd: root, stdin: "inherit", stdout: "inherit", stderr: "inherit", }); const code = await child.exited; if (code !== 0) throw new Error(`WRN-CHECK: '${name}' failed with exit code ${code}`); } /** Canonical generated-artifact-aware application verification pipeline. */ export async function runCheck(appRoot: string): Promise { const root = resolve(appRoot); const manifest = JSON.parse(readFileSync(resolve(root, "package.json"), "utf8")) as { scripts?: Record; }; assertReachability(root); await runBuild(root); if (manifest.scripts?.typecheck) await runScript(root, "typecheck"); else if (!(await runTypecheck(root))) throw new Error("WRN-CHECK: application typecheck failed"); for (const name of ["lint", "test", "format:check"] as const) { if (manifest.scripts?.[name]) await runScript(root, name); } }