|
| 1 | +import { type ExecException, execSync } from "node:child_process"; |
| 2 | +import fg from "fast-glob"; |
| 3 | + |
| 4 | +const tsconfigs: string[] = []; |
| 5 | + |
| 6 | +for await (const file of await fg.glob("**/tsconfig.json")) { |
| 7 | + if (file.includes("node_modules")) continue; |
| 8 | + tsconfigs.push(file); |
| 9 | +} |
| 10 | + |
| 11 | +console.log(`Typechecking ${tsconfigs.length} projects...`); |
| 12 | + |
| 13 | +type Result = { |
| 14 | + tsconfig: string; |
| 15 | + success: boolean; |
| 16 | + output: string; |
| 17 | +}; |
| 18 | + |
| 19 | +const results: Result[] = []; |
| 20 | + |
| 21 | +for (const tsconfig of tsconfigs) { |
| 22 | + console.log(`Checking ${tsconfig}...`); |
| 23 | + try { |
| 24 | + const output = execSync(`tsc -p ${tsconfig}`, { |
| 25 | + encoding: "utf-8", |
| 26 | + stdio: ["pipe", "pipe", "pipe"], |
| 27 | + }); |
| 28 | + results.push({ tsconfig, success: true, output }); |
| 29 | + console.log(`✅ ${tsconfig} - OK`); |
| 30 | + } catch (rawError: unknown) { |
| 31 | + const error = rawError as ExecException; |
| 32 | + |
| 33 | + const output = |
| 34 | + error.stdout?.toString() || `${error.stderr?.toString()}` || ""; |
| 35 | + results.push({ tsconfig, success: false, output }); |
| 36 | + console.error(`❌ ${tsconfig} - Failed:`); |
| 37 | + console.error(output); |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +const failed = results.filter((r) => !r.success); |
| 42 | + |
| 43 | +if (failed.length > 0) { |
| 44 | + console.error( |
| 45 | + `\n${failed.length} of ${tsconfigs.length} projects failed to typecheck!` |
| 46 | + ); |
| 47 | + process.exit(1); |
| 48 | +} |
| 49 | + |
| 50 | +console.log("All projects typecheck successfully!"); |
0 commit comments