-
Notifications
You must be signed in to change notification settings - Fork 451
Expand file tree
/
Copy pathtypecheck.ts
More file actions
75 lines (62 loc) · 1.86 KB
/
typecheck.ts
File metadata and controls
75 lines (62 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { exec } from "node:child_process";
import { promisify } from "node:util";
import fg from "fast-glob";
import os from "node:os";
const execAsync = promisify(exec);
const tsconfigs: string[] = [];
for await (const file of await fg.glob("**/tsconfig.json")) {
if (file.includes("node_modules")) continue;
tsconfigs.push(file);
}
const concurrency = Math.max(os.cpus().length, 2);
console.log(
`Typechecking ${tsconfigs.length} projects (${concurrency} concurrent)...`
);
type Result = {
tsconfig: string;
success: boolean;
output: string;
};
async function checkProject(tsconfig: string): Promise<Result> {
try {
await execAsync(`tsc -p ${tsconfig}`);
return { tsconfig, success: true, output: "" };
} catch (rawError: unknown) {
const error = rawError as { stdout?: string; stderr?: string };
const output = error.stdout || error.stderr || "";
return { tsconfig, success: false, output };
}
}
// Run with concurrency limit
const results: Result[] = [];
const queue = [...tsconfigs];
const active: Promise<void>[] = [];
async function runNext(): Promise<void> {
while (queue.length > 0) {
const tsconfig = queue.shift()!;
const result = await checkProject(tsconfig);
results.push(result);
if (result.success) {
console.log(` ✅ ${result.tsconfig}`);
} else {
console.error(` ❌ ${result.tsconfig}`);
}
}
}
for (let i = 0; i < concurrency; i++) {
active.push(runNext());
}
await Promise.all(active);
const failed = results.filter((r) => !r.success);
if (failed.length > 0) {
console.error(
`\n${failed.length} of ${tsconfigs.length} projects failed to typecheck:\n`
);
for (const f of failed) {
console.error(`--- ${f.tsconfig} ---`);
console.error(f.output);
console.error("");
}
process.exit(1);
}
console.log(`\nAll ${tsconfigs.length} projects typecheck successfully!`);