import { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; import { measureBuild } from "./build-profile.mjs"; // Component witnesses share bindings and usually the same source graph. // Check a bounded batch once when distinct source closures cannot supply // ambient declarations to one another. Otherwise use the original checks. export function checkComponentTypes({ node, tsc, work, witnesses, assets, props, packageRevision }) { const checkTypes = (files, combined = false) => execFileSync( node, [ ...(combined ? [fileURLToPath(new URL("./component-type-batch.mjs", import.meta.url))] : []), tsc, ...(combined ? [String(files.length)] : []), "--noEmit", "--strict", "--skipLibCheck", "false", "--target", "es2024", "--lib", "es2024,dom,dom.iterable,esnext.disposable", "--module", "nodenext", "--moduleResolution", "nodenext", "--jsx", "react-jsx", ...files, assets, props, ], { cwd: work, stdio: combined ? "pipe" : "inherit" }, ); measureBuild("component-typecheck", { package: packageRevision, components: witnesses.length }, () => { for (let start = 0; start < witnesses.length; start += 1000) { const batch = witnesses.slice(start, start + 1000); if (batch.length === 1) checkTypes(batch); else { try { checkTypes(batch, true); } catch (error) { if (!(error.status > 0) && error.code !== "ENOBUFS") throw error; console.error("Component batch requires independent witness checks"); for (const witness of batch) checkTypes([witness]); } } } }); }