@stll/oxlint-config 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/toolchain-check-cli.cjs +214 -0
- package/dist/toolchain-check-cli.cjs.map +1 -0
- package/dist/toolchain-check-cli.d.cts +1 -0
- package/dist/toolchain-check-cli.d.mts +1 -0
- package/dist/toolchain-check-cli.mjs +191 -0
- package/dist/toolchain-check-cli.mjs.map +1 -0
- package/dist/typecheck-parity-cli.cjs +870 -0
- package/dist/typecheck-parity-cli.cjs.map +1 -0
- package/dist/typecheck-parity-cli.d.cts +1 -0
- package/dist/typecheck-parity-cli.d.mts +1 -0
- package/dist/typecheck-parity-cli.mjs +870 -0
- package/dist/typecheck-parity-cli.mjs.map +1 -0
- package/package.json +10 -4
- package/toolchain.json +32 -0
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { performance } from "node:perf_hooks";
|
|
9
|
+
import { stripVTControlCharacters } from "node:util";
|
|
10
|
+
//#region src/typecheck-parity.ts
|
|
11
|
+
const fixtures = [
|
|
12
|
+
{
|
|
13
|
+
name: "module-detection",
|
|
14
|
+
flags: ["noUnusedLocals"],
|
|
15
|
+
files: { "input.ts": "const unused = 1;" },
|
|
16
|
+
codes: [6133]
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "skip-declaration-check",
|
|
20
|
+
flags: ["skipLibCheck"],
|
|
21
|
+
files: { "input.d.ts": "export declare const value: MissingType;" },
|
|
22
|
+
codes: []
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "json-import",
|
|
26
|
+
flags: ["resolveJsonModule"],
|
|
27
|
+
files: {
|
|
28
|
+
"data.json": "{ \"name\": \"value\" }",
|
|
29
|
+
"input.ts": "import data from \"./data.json\"; export const value: string = data.name;"
|
|
30
|
+
},
|
|
31
|
+
codes: []
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "interop-import",
|
|
35
|
+
flags: ["esModuleInterop"],
|
|
36
|
+
files: {
|
|
37
|
+
"types.d.cts": "declare const value: string; export = value;",
|
|
38
|
+
"input.ts": "import value from \"./types.cjs\"; export const result: string = value;"
|
|
39
|
+
},
|
|
40
|
+
codes: []
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "valid-control",
|
|
44
|
+
flags: [],
|
|
45
|
+
files: { "input.ts": "export const value: string = \"correct\";" },
|
|
46
|
+
codes: []
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: "type-mismatch",
|
|
50
|
+
flags: [],
|
|
51
|
+
files: { "input.ts": "export const value: number = \"wrong\";" },
|
|
52
|
+
codes: [2322]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "missing-property",
|
|
56
|
+
flags: [],
|
|
57
|
+
files: { "input.ts": "export const value: { name: string } = {};" },
|
|
58
|
+
codes: [2741]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "strict-null",
|
|
62
|
+
flags: ["strictNullChecks"],
|
|
63
|
+
files: { "input.ts": "export const value: string = null;" },
|
|
64
|
+
codes: [2322]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: "unchecked-index",
|
|
68
|
+
flags: ["noUncheckedIndexedAccess"],
|
|
69
|
+
files: { "input.ts": "export const value: string = [\"value\"][1];" },
|
|
70
|
+
codes: [2322]
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "unused-local",
|
|
74
|
+
flags: ["noUnusedLocals"],
|
|
75
|
+
files: { "input.ts": "const unused = 1; export {};" },
|
|
76
|
+
codes: [6133]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "unused-parameter",
|
|
80
|
+
flags: ["noUnusedParameters"],
|
|
81
|
+
files: { "input.ts": "export const value = (unused: string) => 1;" },
|
|
82
|
+
codes: [6133]
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "implicit-any",
|
|
86
|
+
flags: ["noImplicitAny"],
|
|
87
|
+
files: { "input.ts": "export const value = (input) => input;" },
|
|
88
|
+
codes: [7006]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "missing-import",
|
|
92
|
+
flags: [],
|
|
93
|
+
files: { "input.ts": "import { value } from \"./missing.js\"; export { value };" },
|
|
94
|
+
codes: [2307]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "side-effect-import",
|
|
98
|
+
flags: ["noUncheckedSideEffectImports"],
|
|
99
|
+
files: { "input.ts": "import \"./missing.js\";" },
|
|
100
|
+
codes: [2882]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "generic-constraint",
|
|
104
|
+
flags: [],
|
|
105
|
+
files: { "input.ts": "type Box<T extends string> = { value: T }; export type Value = Box<number>;" },
|
|
106
|
+
codes: [2344]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "exact-optional",
|
|
110
|
+
flags: ["exactOptionalPropertyTypes"],
|
|
111
|
+
files: { "input.ts": "export const value: { optional?: string } = { optional: undefined };" },
|
|
112
|
+
codes: [2375]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "fallthrough",
|
|
116
|
+
flags: ["noFallthroughCasesInSwitch"],
|
|
117
|
+
files: { "input.ts": "export const run = (value: number) => { switch (value) { case 0: value++; case 1: return value; default: return 0; } };" },
|
|
118
|
+
codes: [7029]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "implicit-override",
|
|
122
|
+
flags: ["noImplicitOverride"],
|
|
123
|
+
files: { "input.ts": "class Base { value = 1; } export class Child extends Base { value = 2; }" },
|
|
124
|
+
codes: [4114]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "implicit-return",
|
|
128
|
+
flags: ["noImplicitReturns"],
|
|
129
|
+
files: { "input.ts": "export const run = (value: boolean) => { if (value) return 1; };" },
|
|
130
|
+
codes: [7030]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "unknown-catch",
|
|
134
|
+
flags: ["useUnknownInCatchVariables"],
|
|
135
|
+
files: { "input.ts": "export const run = () => { try { return 1; } catch (error) { return error.message; } };" },
|
|
136
|
+
codes: [18046]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "index-property",
|
|
140
|
+
flags: ["noPropertyAccessFromIndexSignature"],
|
|
141
|
+
files: { "input.ts": "export const run = (value: Record<string, string>) => value.name;" },
|
|
142
|
+
codes: [4111]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "erasable-syntax",
|
|
146
|
+
flags: ["erasableSyntaxOnly"],
|
|
147
|
+
files: { "input.ts": "export enum Value { First }" },
|
|
148
|
+
codes: [1294]
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "type-only-import",
|
|
152
|
+
flags: ["verbatimModuleSyntax"],
|
|
153
|
+
files: {
|
|
154
|
+
"types.ts": "export type Value = string;",
|
|
155
|
+
"input.ts": "import { Value } from \"./types.js\"; export const value: Value = \"value\";"
|
|
156
|
+
},
|
|
157
|
+
codes: [1484]
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
name: "checked-javascript",
|
|
161
|
+
flags: ["allowJs", "checkJs"],
|
|
162
|
+
files: { "input.js": "/** @type {number} */\nexport const value = \"wrong\";" },
|
|
163
|
+
codes: [2322]
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: "strict-function",
|
|
167
|
+
flags: ["strictFunctionTypes"],
|
|
168
|
+
files: { "input.ts": "export const value: (input: string | number) => void = (input: string) => { input.toUpperCase(); };" },
|
|
169
|
+
codes: [2322]
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: "strict-initialization",
|
|
173
|
+
flags: ["strictPropertyInitialization"],
|
|
174
|
+
files: { "input.ts": "export class Value { name: string; }" },
|
|
175
|
+
codes: [2564]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "strict-bind",
|
|
179
|
+
flags: ["strictBindCallApply"],
|
|
180
|
+
files: { "input.ts": "const value = (input: string) => input; export const result = value.call(undefined, 1);" },
|
|
181
|
+
codes: [2345]
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: "implicit-this",
|
|
185
|
+
flags: ["noImplicitThis"],
|
|
186
|
+
files: { "input.ts": "export function value() { return this.name; }" },
|
|
187
|
+
codes: [2683]
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: "strict-iterator",
|
|
191
|
+
flags: ["strictBuiltinIteratorReturn"],
|
|
192
|
+
files: { "input.ts": "export const value: string = [\"value\"].values().next().value;" },
|
|
193
|
+
codes: [2322]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "always-strict",
|
|
197
|
+
flags: ["alwaysStrict"],
|
|
198
|
+
files: { "input.ts": "export const value = (eval: string) => eval;" },
|
|
199
|
+
codes: [1215]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: "file-casing",
|
|
203
|
+
flags: ["forceConsistentCasingInFileNames"],
|
|
204
|
+
files: {
|
|
205
|
+
"named.ts": "export const name = \"value\";",
|
|
206
|
+
"Named.ts": "export const name = \"value\";",
|
|
207
|
+
"input.ts": "import { name } from \"./named.js\"; import { name as other } from \"./Named.js\"; export const value = name + other;"
|
|
208
|
+
},
|
|
209
|
+
codes: [1149, 1261],
|
|
210
|
+
anyCode: true
|
|
211
|
+
}
|
|
212
|
+
];
|
|
213
|
+
const diagnosticCodes = (text) => [...new Set([...text.matchAll(/(?:TS|(?:error|warning)\s+)(\d{4,5})/g)].map((match) => Number(match.at(1))))].sort((a, b) => a - b);
|
|
214
|
+
const diagnosticParity = ({ expected, match, baseline, candidate }) => {
|
|
215
|
+
const tscCodes = diagnosticCodes(baseline.output);
|
|
216
|
+
const bunCodes = diagnosticCodes(candidate.output);
|
|
217
|
+
const seeded = match === "any" ? expected.some((code) => tscCodes.includes(code)) : expected.every((code) => tscCodes.includes(code));
|
|
218
|
+
const missing = tscCodes.filter((code) => !bunCodes.includes(code));
|
|
219
|
+
const extra = bunCodes.filter((code) => !tscCodes.includes(code));
|
|
220
|
+
const exitsMatch = expected.length === 0 ? baseline.status === 0 && candidate.status === 0 && tscCodes.length === 0 && bunCodes.length === 0 : baseline.status !== null && baseline.status !== 0 && candidate.status !== null && candidate.status !== 0;
|
|
221
|
+
return {
|
|
222
|
+
tscCodes,
|
|
223
|
+
bunCodes,
|
|
224
|
+
missing,
|
|
225
|
+
extra,
|
|
226
|
+
passed: seeded && exitsMatch && baseline.status === candidate.status && missing.length === 0 && extra.length === 0
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const configurationDiagnostics = (output, repo) => diagnosticSet(output, repo).filter((diagnostic) => /^(?:<config>:0:|.*\.json:[0-9]+:)(?:[56][0-9]{3}|1800[23]|2688)(?::|$)/.test(diagnostic) || /:1800[23](?::|$)/.test(diagnostic));
|
|
230
|
+
const fixtureParity = (options) => {
|
|
231
|
+
const result = diagnosticParity(options);
|
|
232
|
+
const { baseline, candidate, expected, match } = options;
|
|
233
|
+
const identityParity = compareDiagnosticSets({
|
|
234
|
+
status: baseline.status,
|
|
235
|
+
diagnostics: diagnosticSet(baseline.output, options.repo ?? process.cwd())
|
|
236
|
+
}, {
|
|
237
|
+
status: candidate.status,
|
|
238
|
+
diagnostics: diagnosticSet(candidate.output, options.repo ?? process.cwd())
|
|
239
|
+
});
|
|
240
|
+
const configDiagnostics = [...configurationDiagnostics(baseline.output, options.repo ?? process.cwd()).map((diagnostic) => `TypeScript: ${diagnostic}`), ...configurationDiagnostics(candidate.output, options.repo ?? process.cwd()).map((diagnostic) => `Bun: ${diagnostic}`)];
|
|
241
|
+
const seedFiles = new Set(options.seedFiles.map((file) => resolve(options.repo ?? process.cwd(), file)));
|
|
242
|
+
const seededCodes = new Set(diagnosticSet(baseline.output, options.repo ?? process.cwd()).flatMap((diagnostic) => {
|
|
243
|
+
const diagnosticMatch = /^(.*):[0-9]+:([0-9]+)$/.exec(diagnostic);
|
|
244
|
+
const file = diagnosticMatch?.at(1);
|
|
245
|
+
const code = diagnosticMatch?.at(2);
|
|
246
|
+
return file !== void 0 && code !== void 0 && seedFiles.has(resolve(options.repo ?? process.cwd(), file)) ? [Number(code)] : [];
|
|
247
|
+
}));
|
|
248
|
+
const active = expected.length > 0 && (match === "any" ? expected.some((code) => seededCodes.has(code)) : expected.every((code) => seededCodes.has(code)));
|
|
249
|
+
const validExits = baseline.status !== null && candidate.status !== null && (result.tscCodes.length === 0 ? baseline.status === 0 : baseline.status !== 0) && (result.bunCodes.length === 0 ? candidate.status === 0 : candidate.status !== 0);
|
|
250
|
+
return {
|
|
251
|
+
...result,
|
|
252
|
+
active,
|
|
253
|
+
configurationDiagnostics: configDiagnostics,
|
|
254
|
+
identityMissing: identityParity.missing,
|
|
255
|
+
identityExtra: identityParity.extra,
|
|
256
|
+
passed: configDiagnostics.length === 0 && identityParity.passed && validExits && baseline.status === candidate.status && result.missing.length === 0 && result.extra.length === 0
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
const fixtureRunPassed = (results) => results.some(({ active }) => active) && results.every(({ passed }) => passed);
|
|
260
|
+
const diagnosticLocation = (file, repo) => {
|
|
261
|
+
const normalized = file.replaceAll("\\", "/");
|
|
262
|
+
const bundled = /^bundled:\/\/\/libs\/(lib\.[^/]+\.d\.ts)$/.exec(normalized);
|
|
263
|
+
const installed = /(?:^|\/)node_modules\/(?:typescript|@typescript\/(?:native|typescript-[^/]+))\/(?:.*\/)?(lib\.[^/]+\.d\.ts)$/.exec(normalized);
|
|
264
|
+
const library = bundled?.at(1) ?? installed?.at(1);
|
|
265
|
+
return library === void 0 ? relative(repo, resolve(repo, file)).replaceAll("\\", "/") : `<lib>/${library}`;
|
|
266
|
+
};
|
|
267
|
+
const globalDiagnosticKey = (code, message) => `<config>:0:${code}:${message.trim().replaceAll(/\s+/g, " ")}`;
|
|
268
|
+
const diagnosticSet = (output, repo) => {
|
|
269
|
+
const clean = stripVTControlCharacters(output);
|
|
270
|
+
const diagnostics = /* @__PURE__ */ new Set();
|
|
271
|
+
for (const block of clean.matchAll(/<error\b([^>]*)>([\s\S]*?)<\/error>/g)) {
|
|
272
|
+
const attributes = new Map([...(block.at(1) ?? "").matchAll(/(\w+)="([^"]*)"/g)].map((match) => [match.at(1), match.at(2)]));
|
|
273
|
+
const file = attributes.get("file");
|
|
274
|
+
const row = attributes.get("line");
|
|
275
|
+
const code = attributes.get("code");
|
|
276
|
+
if (code === void 0 || !/^TS\d+$/.test(code)) continue;
|
|
277
|
+
if (file !== void 0 && row !== void 0 && row !== "0") diagnostics.add(`${diagnosticLocation(file, repo)}:${row}:${code.slice(2)}`);
|
|
278
|
+
else {
|
|
279
|
+
const message = (block.at(2) ?? "").split(/<(?:source|related)\b/).at(0) ?? "";
|
|
280
|
+
diagnostics.add(globalDiagnosticKey(code.slice(2), message));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const line of clean.split("\n")) {
|
|
284
|
+
if (line.startsWith("<error ")) continue;
|
|
285
|
+
const match = /^(.*?)\((\d+),\d+\):\s*(?:error|warning) TS(\d+)/.exec(line) ?? /^(.*?):(\d+):\d+:\s*(?:error|warning) (?:TS)?(\d+)/.exec(line);
|
|
286
|
+
if (match) {
|
|
287
|
+
const [, file = "", row = "", code = ""] = match;
|
|
288
|
+
diagnostics.add(`${diagnosticLocation(file, repo)}:${row}:${code}`);
|
|
289
|
+
} else {
|
|
290
|
+
const global = /^(?:error|warning) TS(\d+):\s*(.*)/.exec(line);
|
|
291
|
+
if (global) diagnostics.add(globalDiagnosticKey(global.at(1) ?? "", global.at(2) ?? ""));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return [...diagnostics].sort();
|
|
295
|
+
};
|
|
296
|
+
const compareDiagnosticSets = (baseline, candidate) => {
|
|
297
|
+
const missing = baseline.diagnostics.filter((item) => !candidate.diagnostics.includes(item));
|
|
298
|
+
const extra = candidate.diagnostics.filter((item) => !baseline.diagnostics.includes(item));
|
|
299
|
+
const valid = (result) => result.status !== null && (result.diagnostics.length === 0 ? result.status === 0 : result.status !== 0);
|
|
300
|
+
return {
|
|
301
|
+
missing,
|
|
302
|
+
extra,
|
|
303
|
+
passed: valid(baseline) && valid(candidate) && baseline.status === candidate.status && missing.length === 0 && extra.length === 0
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
const assertUnshadowedCheck = async (repo) => {
|
|
307
|
+
const manifest = JSON.parse(await readFile(join(repo, "package.json"), "utf8"));
|
|
308
|
+
if (typeof manifest !== "object" || manifest === null) throw new Error("Invalid repository package.json");
|
|
309
|
+
if ("scripts" in manifest && typeof manifest.scripts === "object" && manifest.scripts !== null && "check" in manifest.scripts) throw new Error("Repository package.json must not define a \"check\" script: it shadows Bun typechecking; rename that script before running parity");
|
|
310
|
+
};
|
|
311
|
+
const resolveCompiler = async (repo, policy) => {
|
|
312
|
+
if (typeof policy !== "object" || policy === null || !("typescriptInstallLayouts" in policy) || !Array.isArray(policy.typescriptInstallLayouts)) throw new Error("toolchain.json must define typescriptInstallLayouts");
|
|
313
|
+
const manifest = JSON.parse(await readFile(join(repo, "package.json"), "utf8"));
|
|
314
|
+
if (typeof manifest !== "object" || manifest === null) throw new Error("Invalid repository package.json");
|
|
315
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
316
|
+
for (const key of ["dependencies", "devDependencies"]) {
|
|
317
|
+
if (!(key in manifest)) continue;
|
|
318
|
+
const section = Reflect.get(manifest, key);
|
|
319
|
+
if (typeof section === "object" && section !== null) for (const [name, specifier] of Object.entries(section)) dependencies.set(name, specifier);
|
|
320
|
+
}
|
|
321
|
+
const require = createRequire(join(repo, "package.json"));
|
|
322
|
+
for (const layout of [...policy.typescriptInstallLayouts].reverse()) {
|
|
323
|
+
if (typeof layout !== "object" || layout === null || !("compilerPackage" in layout) || typeof layout.compilerPackage !== "string") throw new Error("Invalid TypeScript install layout");
|
|
324
|
+
if (!dependencies.has(layout.compilerPackage)) continue;
|
|
325
|
+
const packagePath = require.resolve(`${layout.compilerPackage}/package.json`);
|
|
326
|
+
const installed = JSON.parse(await readFile(packagePath, "utf8"));
|
|
327
|
+
if (typeof installed !== "object" || installed === null || !("bin" in installed) || typeof installed.bin !== "object" || installed.bin === null || !("tsc" in installed.bin) || typeof installed.bin.tsc !== "string") throw new Error(`${layout.compilerPackage} must expose a tsc binary`);
|
|
328
|
+
if (!("compilerSpecifier" in layout) || typeof layout.compilerSpecifier !== "string") throw new Error("TypeScript install layout must define compilerSpecifier");
|
|
329
|
+
const expectedVersion = layout.compilerSpecifier.replace(/^npm:typescript@/, "");
|
|
330
|
+
if (!("version" in installed) || installed.version !== expectedVersion) throw new Error(`${layout.compilerPackage} must install TypeScript ${expectedVersion}`);
|
|
331
|
+
return resolve(packagePath, "..", installed.bin.tsc);
|
|
332
|
+
}
|
|
333
|
+
throw new Error("Repository must declare a compiler from typescriptInstallLayouts");
|
|
334
|
+
};
|
|
335
|
+
const assertBunVersion = (bun, policy) => {
|
|
336
|
+
if (typeof policy !== "object" || policy === null || !("bun" in policy) || typeof policy.bun !== "string") throw new Error("toolchain.json must define bun");
|
|
337
|
+
const result = spawnSync(bun, ["--version"], { encoding: "utf8" });
|
|
338
|
+
if (result.error) throw result.error;
|
|
339
|
+
const installed = result.stdout.trim();
|
|
340
|
+
if (result.status !== 0 || installed !== policy.bun) throw new Error(`Bun must be ${policy.bun}; selected runtime reports ${installed || "no version"}`);
|
|
341
|
+
};
|
|
342
|
+
const bunCheckArgs = (project, build = false) => [
|
|
343
|
+
"check",
|
|
344
|
+
"--no-pretty",
|
|
345
|
+
"--all",
|
|
346
|
+
...build ? ["--build"] : [],
|
|
347
|
+
...project === void 0 ? [] : [`--project=${project}`]
|
|
348
|
+
];
|
|
349
|
+
const canonicalOptions = (value) => {
|
|
350
|
+
if (Array.isArray(value)) return `[${value.map(canonicalOptions).join(",")}]`;
|
|
351
|
+
if (typeof value === "object" && value !== null) return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalOptions(Reflect.get(value, key))}`).join(",")}}`;
|
|
352
|
+
if (value !== null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") throw new Error("Invalid effective compiler option");
|
|
353
|
+
return JSON.stringify(value);
|
|
354
|
+
};
|
|
355
|
+
const EMIT_ONLY_OPTIONS = /* @__PURE__ */ new Set([
|
|
356
|
+
"composite",
|
|
357
|
+
"declaration",
|
|
358
|
+
"declarationDir",
|
|
359
|
+
"declarationMap",
|
|
360
|
+
"emitDeclarationOnly",
|
|
361
|
+
"outDir",
|
|
362
|
+
"outFile",
|
|
363
|
+
"rootDir",
|
|
364
|
+
"sourceMap",
|
|
365
|
+
"inlineSourceMap",
|
|
366
|
+
"inlineSources",
|
|
367
|
+
"incremental",
|
|
368
|
+
"tsBuildInfoFile",
|
|
369
|
+
"noEmitOnError",
|
|
370
|
+
"importHelpers",
|
|
371
|
+
"noEmitHelpers",
|
|
372
|
+
"emitBOM",
|
|
373
|
+
"mapRoot",
|
|
374
|
+
"sourceRoot",
|
|
375
|
+
"newLine",
|
|
376
|
+
"preserveConstEnums",
|
|
377
|
+
"removeComments",
|
|
378
|
+
"stripInternal",
|
|
379
|
+
"downlevelIteration",
|
|
380
|
+
"isolatedDeclarations",
|
|
381
|
+
"noEmit"
|
|
382
|
+
]);
|
|
383
|
+
const resolvedCompilerOptions = ({ compilerOptions, configPath }) => {
|
|
384
|
+
if (typeof compilerOptions !== "object" || compilerOptions === null || Array.isArray(compilerOptions)) throw new Error(`Invalid compiler options: ${configPath}`);
|
|
385
|
+
const options = Object.fromEntries(Object.entries(compilerOptions));
|
|
386
|
+
const directory = dirname(configPath);
|
|
387
|
+
const rootDir = options["rootDir"];
|
|
388
|
+
if (rootDir !== void 0 && typeof rootDir !== "string") throw new Error(`Invalid rootDir: ${configPath}`);
|
|
389
|
+
if (typeof rootDir === "string") options["rootDir"] = resolve(directory, rootDir);
|
|
390
|
+
let resolutionDirectory = directory;
|
|
391
|
+
const absolutePaths = (value) => {
|
|
392
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string")) throw new Error(`Invalid compiler path option: ${configPath}`);
|
|
393
|
+
return value.map((entry) => resolve(resolutionDirectory, entry));
|
|
394
|
+
};
|
|
395
|
+
for (const name of ["rootDirs", "typeRoots"]) if (name in options) options[name] = absolutePaths(options[name]);
|
|
396
|
+
if ("baseUrl" in options) {
|
|
397
|
+
const baseUrl = options["baseUrl"];
|
|
398
|
+
if (typeof baseUrl !== "string") throw new Error(`Invalid baseUrl: ${configPath}`);
|
|
399
|
+
resolutionDirectory = resolve(directory, baseUrl);
|
|
400
|
+
options["baseUrl"] = resolutionDirectory;
|
|
401
|
+
}
|
|
402
|
+
if ("paths" in options) {
|
|
403
|
+
const paths = options["paths"];
|
|
404
|
+
if (typeof paths !== "object" || paths === null || Array.isArray(paths)) throw new Error(`Invalid paths: ${configPath}`);
|
|
405
|
+
options["paths"] = Object.fromEntries(Object.entries(paths).map(([key, value]) => [key, absolutePaths(value)]));
|
|
406
|
+
}
|
|
407
|
+
return options;
|
|
408
|
+
};
|
|
409
|
+
const fixtureCompilerOptions = (args) => {
|
|
410
|
+
const options = Object.fromEntries(Object.entries(resolvedCompilerOptions(args)).filter(([name]) => !EMIT_ONLY_OPTIONS.has(name)));
|
|
411
|
+
options["noEmit"] = true;
|
|
412
|
+
return options;
|
|
413
|
+
};
|
|
414
|
+
const fixtureInputs = ({ files, compilerOptions }) => {
|
|
415
|
+
const inputs = files.filter((file) => /\.(?:[cm]?[jt]sx?|json)$/.test(file));
|
|
416
|
+
for (const input of inputs) {
|
|
417
|
+
if (/\.[cm]?jsx?$/.test(input) && compilerOptions["allowJs"] !== true) return {
|
|
418
|
+
status: "inapplicable",
|
|
419
|
+
reason: `${input} requires allowJs`
|
|
420
|
+
};
|
|
421
|
+
if (input.endsWith(".json") && compilerOptions["resolveJsonModule"] !== true) return {
|
|
422
|
+
status: "inapplicable",
|
|
423
|
+
reason: `${input} requires resolveJsonModule`
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
return {
|
|
427
|
+
status: "applicable",
|
|
428
|
+
files: inputs
|
|
429
|
+
};
|
|
430
|
+
};
|
|
431
|
+
const fixturePackageContext = (configPath) => {
|
|
432
|
+
for (let folder = dirname(configPath);; folder = dirname(folder)) {
|
|
433
|
+
try {
|
|
434
|
+
const manifest = JSON.parse(readFileSync(join(folder, "package.json"), "utf8"));
|
|
435
|
+
if (typeof manifest !== "object" || manifest === null) throw new Error(`Invalid package.json: ${folder}`);
|
|
436
|
+
if (!("type" in manifest)) return {};
|
|
437
|
+
if (manifest.type !== "module" && manifest.type !== "commonjs") throw new Error(`Invalid package type: ${folder}`);
|
|
438
|
+
return { type: manifest.type };
|
|
439
|
+
} catch (error) {
|
|
440
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
441
|
+
}
|
|
442
|
+
if (dirname(folder) === folder) return {};
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const groupCompilerConfigs = (configs) => {
|
|
446
|
+
const groups = /* @__PURE__ */ new Map();
|
|
447
|
+
for (const config of configs) {
|
|
448
|
+
const compilerOptions = fixtureCompilerOptions({
|
|
449
|
+
compilerOptions: config.compilerOptions,
|
|
450
|
+
configPath: config.path
|
|
451
|
+
});
|
|
452
|
+
const key = canonicalOptions({
|
|
453
|
+
compilerOptions,
|
|
454
|
+
resolutionContext: "typeRoots" in compilerOptions ? null : dirname(config.path),
|
|
455
|
+
packageContext: config.packageContext ?? {}
|
|
456
|
+
});
|
|
457
|
+
const existing = groups.get(key);
|
|
458
|
+
if (existing) existing.projects.push(config.path);
|
|
459
|
+
else groups.set(key, {
|
|
460
|
+
path: config.path,
|
|
461
|
+
projects: [config.path],
|
|
462
|
+
compilerOptions: config.compilerOptions,
|
|
463
|
+
...config.packageContext === void 0 ? {} : { packageContext: config.packageContext }
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
return [...groups.values()];
|
|
467
|
+
};
|
|
468
|
+
const discoverConfigGroups = ({ repo, compiler }) => {
|
|
469
|
+
const configs = [];
|
|
470
|
+
const visited = /* @__PURE__ */ new Set();
|
|
471
|
+
const projects = [];
|
|
472
|
+
let build = false;
|
|
473
|
+
const visit = (project) => {
|
|
474
|
+
const path = realpathSync(statSync(project).isDirectory() ? join(project, "tsconfig.json") : project);
|
|
475
|
+
if (visited.has(path)) return;
|
|
476
|
+
visited.add(path);
|
|
477
|
+
const result = spawnSync(process.execPath, [
|
|
478
|
+
compiler,
|
|
479
|
+
"--showConfig",
|
|
480
|
+
"--project",
|
|
481
|
+
path
|
|
482
|
+
], {
|
|
483
|
+
cwd: repo,
|
|
484
|
+
encoding: "utf8",
|
|
485
|
+
maxBuffer: 64 * 1024 * 1024
|
|
486
|
+
});
|
|
487
|
+
if (result.error) throw result.error;
|
|
488
|
+
if (result.status !== 0) throw new Error(result.stdout + result.stderr);
|
|
489
|
+
const config = JSON.parse(result.stdout);
|
|
490
|
+
if (typeof config !== "object" || config === null) throw new Error(`Invalid resolved config: ${path}`);
|
|
491
|
+
const references = "references" in config && Array.isArray(config.references) ? config.references : [];
|
|
492
|
+
build ||= references.length > 0;
|
|
493
|
+
const compilerOptions = "compilerOptions" in config ? config.compilerOptions : {};
|
|
494
|
+
if (typeof compilerOptions !== "object" || compilerOptions === null || Array.isArray(compilerOptions)) throw new Error(`Invalid compiler options: ${path}`);
|
|
495
|
+
const rawFiles = "files" in config ? config.files : [];
|
|
496
|
+
if (!Array.isArray(rawFiles)) throw new Error(`Invalid project files: ${path}`);
|
|
497
|
+
const files = rawFiles.map((file) => {
|
|
498
|
+
if (typeof file !== "string") throw new Error(`Invalid project file: ${path}`);
|
|
499
|
+
return resolve(dirname(path), file);
|
|
500
|
+
});
|
|
501
|
+
const referencePaths = [];
|
|
502
|
+
projects.push({
|
|
503
|
+
path,
|
|
504
|
+
compilerOptions,
|
|
505
|
+
files,
|
|
506
|
+
references: referencePaths
|
|
507
|
+
});
|
|
508
|
+
if (files.length > 0 || references.length === 0) configs.push({
|
|
509
|
+
path,
|
|
510
|
+
compilerOptions,
|
|
511
|
+
packageContext: fixturePackageContext(path)
|
|
512
|
+
});
|
|
513
|
+
for (const reference of references) {
|
|
514
|
+
if (typeof reference !== "object" || reference === null || !("path" in reference) || typeof reference.path !== "string") throw new Error(`Invalid project reference: ${path}`);
|
|
515
|
+
const referencedProject = resolve(dirname(path), reference.path);
|
|
516
|
+
const referencePath = realpathSync(statSync(referencedProject).isDirectory() ? join(referencedProject, "tsconfig.json") : referencedProject);
|
|
517
|
+
referencePaths.push(referencePath);
|
|
518
|
+
visit(referencePath);
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
visit(join(repo, "tsconfig.json"));
|
|
522
|
+
const groups = groupCompilerConfigs(configs);
|
|
523
|
+
if (groups.length === 0) throw new Error("No consumer compiler configurations to compare");
|
|
524
|
+
return {
|
|
525
|
+
build,
|
|
526
|
+
groups,
|
|
527
|
+
projects
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
const timedCommand = ({ command, args, repo }) => {
|
|
531
|
+
const started = performance.now();
|
|
532
|
+
const result = spawnSync("/usr/bin/time", [
|
|
533
|
+
process.platform === "darwin" ? "-l" : "-v",
|
|
534
|
+
command,
|
|
535
|
+
...args
|
|
536
|
+
], {
|
|
537
|
+
cwd: repo,
|
|
538
|
+
encoding: "utf8",
|
|
539
|
+
maxBuffer: 64 * 1024 * 1024
|
|
540
|
+
});
|
|
541
|
+
if (result.error) throw result.error;
|
|
542
|
+
const rss = process.platform === "darwin" ? /([0-9]+)\s+maximum resident set size/.exec(result.stderr) : /Maximum resident set size \(kbytes\):\s*([0-9]+)/.exec(result.stderr);
|
|
543
|
+
if (!rss) throw new Error("Cannot measure maximum RSS with /usr/bin/time");
|
|
544
|
+
return {
|
|
545
|
+
status: result.status,
|
|
546
|
+
output: result.stdout + result.stderr,
|
|
547
|
+
wall: (performance.now() - started) / 1e3,
|
|
548
|
+
maxRssKiB: Number(rss[1]) / (process.platform === "darwin" ? 1024 : 1)
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
const NO_WORK_MAX_RSS_KIB = 16 * 1024;
|
|
552
|
+
const NO_WORK_MAX_WALL_SECONDS = .25;
|
|
553
|
+
const sourceDiagnosticSet = ({ output, repo, scratch, configPaths }) => {
|
|
554
|
+
const configs = new Set(configPaths.map((path) => resolve(path)));
|
|
555
|
+
const invalid = new Set(configurationDiagnostics(output, repo));
|
|
556
|
+
return diagnosticSet(output, repo).filter((diagnostic) => {
|
|
557
|
+
if (invalid.has(diagnostic)) return false;
|
|
558
|
+
if (diagnostic.startsWith("<config>:")) return true;
|
|
559
|
+
const file = /^(.*):[0-9]+:[0-9]+$/.exec(diagnostic)?.at(1);
|
|
560
|
+
if (file === void 0) return false;
|
|
561
|
+
const path = resolve(repo, file);
|
|
562
|
+
return !configs.has(path) && path !== scratch && !path.startsWith(scratch + "/");
|
|
563
|
+
});
|
|
564
|
+
};
|
|
565
|
+
const diagnosticExitStatus = ({ status, output, repo }) => status === 2 && configurationDiagnostics(output, repo).length === 0 && diagnosticSet(output, repo).some((diagnostic) => !diagnostic.startsWith("<config>:")) ? 1 : status;
|
|
566
|
+
const repositoryDiagnosticComparison = ({ baseline, candidate, repo, scratch, configPaths }) => {
|
|
567
|
+
const configs = new Set(configPaths.map((path) => resolve(path)));
|
|
568
|
+
const configurationErrors = (output) => [.../* @__PURE__ */ new Set([...configurationDiagnostics(output, repo), ...diagnosticSet(output, repo).filter((diagnostic) => {
|
|
569
|
+
const file = /^(.*):[0-9]+:[0-9]+$/.exec(diagnostic)?.at(1);
|
|
570
|
+
return file !== void 0 && configs.has(resolve(repo, file));
|
|
571
|
+
})])];
|
|
572
|
+
const configurationErrorsFound = [...configurationErrors(baseline.output).map((diagnostic) => `TypeScript: ${diagnostic}`), ...configurationErrors(candidate.output).map((diagnostic) => `Bun: ${diagnostic}`)];
|
|
573
|
+
const diagnostics = (output) => sourceDiagnosticSet({
|
|
574
|
+
output,
|
|
575
|
+
repo,
|
|
576
|
+
scratch,
|
|
577
|
+
configPaths
|
|
578
|
+
});
|
|
579
|
+
const comparison = compareDiagnosticSets({
|
|
580
|
+
status: baseline.status,
|
|
581
|
+
diagnostics: diagnostics(baseline.output)
|
|
582
|
+
}, {
|
|
583
|
+
status: candidate.status,
|
|
584
|
+
diagnostics: diagnostics(candidate.output)
|
|
585
|
+
});
|
|
586
|
+
return {
|
|
587
|
+
...comparison,
|
|
588
|
+
passed: configurationErrorsFound.length === 0 && comparison.passed,
|
|
589
|
+
configurationDiagnostics: configurationErrorsFound
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
const temporaryProjectTree = async ({ scratch, projects }) => {
|
|
593
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
594
|
+
const linkedFolders = /* @__PURE__ */ new Set();
|
|
595
|
+
for (const project of projects) {
|
|
596
|
+
const path = join(scratch, "projects", relative(resolve("/"), project));
|
|
597
|
+
const folder = dirname(path);
|
|
598
|
+
await mkdir(folder, { recursive: true });
|
|
599
|
+
for (let original = dirname(project);; original = dirname(original)) {
|
|
600
|
+
if (!linkedFolders.has(original)) {
|
|
601
|
+
linkedFolders.add(original);
|
|
602
|
+
const modules = join(original, "node_modules");
|
|
603
|
+
try {
|
|
604
|
+
if (statSync(modules).isDirectory()) {
|
|
605
|
+
const destination = join(scratch, "projects", relative(resolve("/"), original));
|
|
606
|
+
await mkdir(destination, { recursive: true });
|
|
607
|
+
await symlink(modules, join(destination, "node_modules"), "dir");
|
|
608
|
+
}
|
|
609
|
+
} catch (error) {
|
|
610
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
if (dirname(original) === original) break;
|
|
614
|
+
}
|
|
615
|
+
contexts.set(project, {
|
|
616
|
+
path,
|
|
617
|
+
folder,
|
|
618
|
+
outputFolder: join(folder, `${basename(path)}.parity-output`)
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
return contexts;
|
|
622
|
+
};
|
|
623
|
+
const compareRepository = async ({ repo, compiler, bun, graph }) => {
|
|
624
|
+
const scratch = await mkdtemp(join(tmpdir(), "parity-repository-"));
|
|
625
|
+
try {
|
|
626
|
+
const contexts = await temporaryProjectTree({
|
|
627
|
+
scratch,
|
|
628
|
+
projects: graph.projects.map(({ path }) => path)
|
|
629
|
+
});
|
|
630
|
+
const configPaths = new Map([...contexts].map(([original, context]) => [original, context.path]));
|
|
631
|
+
const requiredOutputs = new Set(graph.projects.flatMap(({ references }) => references));
|
|
632
|
+
for (const project of graph.projects) {
|
|
633
|
+
const context = contexts.get(project.path);
|
|
634
|
+
if (context === void 0) throw new Error(`Missing temporary project: ${project.path}`);
|
|
635
|
+
const { path: configPath, outputFolder } = context;
|
|
636
|
+
const options = resolvedCompilerOptions({
|
|
637
|
+
configPath: project.path,
|
|
638
|
+
compilerOptions: project.compilerOptions
|
|
639
|
+
});
|
|
640
|
+
const declarationsRequired = graph.build && requiredOutputs.has(project.path) && options["composite"] === true;
|
|
641
|
+
options["noEmit"] = !graph.build || options["noEmit"] === true && !declarationsRequired;
|
|
642
|
+
const relocatesOutput = options["noEmit"] !== true || "outDir" in options || "declarationDir" in options;
|
|
643
|
+
if (!("rootDir" in options) && relocatesOutput) options["rootDir"] = dirname(project.path);
|
|
644
|
+
if (relocatesOutput) options["outDir"] = join(outputFolder, "output");
|
|
645
|
+
const emitsDeclarations = options["declaration"] === true || options["composite"] === true && options["declaration"] !== false;
|
|
646
|
+
if (graph.build && emitsDeclarations || "declarationDir" in options) options["declarationDir"] = join(outputFolder, "declarations");
|
|
647
|
+
if (graph.build || options["incremental"] === true || options["composite"] === true) options["tsBuildInfoFile"] = join(outputFolder, "project.tsbuildinfo");
|
|
648
|
+
if (graph.build) {
|
|
649
|
+
options["declarationMap"] = false;
|
|
650
|
+
if (emitsDeclarations) options["emitDeclarationOnly"] = true;
|
|
651
|
+
options["noEmitOnError"] = false;
|
|
652
|
+
}
|
|
653
|
+
delete options["outFile"];
|
|
654
|
+
await writeFile(configPath, JSON.stringify({
|
|
655
|
+
compilerOptions: options,
|
|
656
|
+
files: project.files,
|
|
657
|
+
include: [],
|
|
658
|
+
references: project.references.map((path) => {
|
|
659
|
+
const temporary = configPaths.get(path);
|
|
660
|
+
if (temporary === void 0) throw new Error(`Missing referenced temporary project: ${path}`);
|
|
661
|
+
return { path: temporary };
|
|
662
|
+
})
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
const root = configPaths.get(realpathSync(join(repo, "tsconfig.json")));
|
|
666
|
+
if (root === void 0) throw new Error("Missing temporary root config");
|
|
667
|
+
const baselineRaw = timedCommand({
|
|
668
|
+
command: process.execPath,
|
|
669
|
+
args: [
|
|
670
|
+
compiler,
|
|
671
|
+
...graph.build ? [
|
|
672
|
+
"--build",
|
|
673
|
+
"--force",
|
|
674
|
+
root
|
|
675
|
+
] : [
|
|
676
|
+
"--noEmit",
|
|
677
|
+
"--project",
|
|
678
|
+
root
|
|
679
|
+
],
|
|
680
|
+
"--pretty",
|
|
681
|
+
"false"
|
|
682
|
+
],
|
|
683
|
+
repo
|
|
684
|
+
});
|
|
685
|
+
const candidate = timedCommand({
|
|
686
|
+
command: bun,
|
|
687
|
+
args: bunCheckArgs(root, graph.build),
|
|
688
|
+
repo
|
|
689
|
+
});
|
|
690
|
+
const sourceDiagnostics = (output) => sourceDiagnosticSet({
|
|
691
|
+
output,
|
|
692
|
+
repo,
|
|
693
|
+
scratch,
|
|
694
|
+
configPaths: graph.projects.map(({ path }) => path)
|
|
695
|
+
});
|
|
696
|
+
const baselineDiagnostics = sourceDiagnostics(baselineRaw.output);
|
|
697
|
+
const baseline = {
|
|
698
|
+
...baselineRaw,
|
|
699
|
+
rawStatus: baselineRaw.status,
|
|
700
|
+
status: diagnosticExitStatus({
|
|
701
|
+
status: baselineRaw.status,
|
|
702
|
+
output: baselineRaw.output,
|
|
703
|
+
repo
|
|
704
|
+
}),
|
|
705
|
+
diagnostics: baselineDiagnostics
|
|
706
|
+
};
|
|
707
|
+
const repository = repositoryDiagnosticComparison({
|
|
708
|
+
baseline,
|
|
709
|
+
candidate,
|
|
710
|
+
repo,
|
|
711
|
+
scratch,
|
|
712
|
+
configPaths: [...graph.projects.map(({ path }) => path), ...configPaths.values()]
|
|
713
|
+
});
|
|
714
|
+
return {
|
|
715
|
+
baseline,
|
|
716
|
+
candidate: {
|
|
717
|
+
...candidate,
|
|
718
|
+
rawStatus: candidate.status,
|
|
719
|
+
diagnostics: sourceDiagnostics(candidate.output)
|
|
720
|
+
},
|
|
721
|
+
repository
|
|
722
|
+
};
|
|
723
|
+
} finally {
|
|
724
|
+
await rm(scratch, {
|
|
725
|
+
recursive: true,
|
|
726
|
+
force: true
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
const runTypecheckParity = async ({ repo, policy, bun = process.versions.bun ? process.execPath : "bun" }) => {
|
|
731
|
+
await assertUnshadowedCheck(repo);
|
|
732
|
+
assertBunVersion(bun, policy);
|
|
733
|
+
const compiler = await resolveCompiler(repo, policy);
|
|
734
|
+
const graph = discoverConfigGroups({
|
|
735
|
+
repo,
|
|
736
|
+
compiler
|
|
737
|
+
});
|
|
738
|
+
const { groups } = graph;
|
|
739
|
+
const { baseline, candidate, repository } = await compareRepository({
|
|
740
|
+
repo,
|
|
741
|
+
compiler,
|
|
742
|
+
bun,
|
|
743
|
+
graph
|
|
744
|
+
});
|
|
745
|
+
console.log("Class | TypeScript diagnostics | Bun diagnostics | Result");
|
|
746
|
+
console.log(`repository | ${baseline.diagnostics.join(",")} | ${candidate.diagnostics.join(",")} | ${repository.passed ? "PASS" : "FAIL"}`);
|
|
747
|
+
console.log(`repository tsc: wall=${baseline.wall.toFixed(3)}s maxRSS=${baseline.maxRssKiB}KiB exit=${baseline.rawStatus}`);
|
|
748
|
+
console.log(`repository bun: wall=${candidate.wall.toFixed(3)}s maxRSS=${candidate.maxRssKiB}KiB exit=${candidate.rawStatus}`);
|
|
749
|
+
for (const diagnostic of repository.configurationDiagnostics) console.error(`FAIL: invalid repository configuration: ${diagnostic}`);
|
|
750
|
+
const scratch = await mkdtemp(join(tmpdir(), "typecheck-parity-"));
|
|
751
|
+
const groupResults = [];
|
|
752
|
+
try {
|
|
753
|
+
for (const [index, group] of groups.entries()) {
|
|
754
|
+
console.log(`Config group ${index + 1}: ${relative(repo, group.path)} (${group.projects.length} projects)`);
|
|
755
|
+
const results = [];
|
|
756
|
+
let tscWall = 0;
|
|
757
|
+
let bunWall = 0;
|
|
758
|
+
let tscRss = 0;
|
|
759
|
+
let bunRss = 0;
|
|
760
|
+
const context = (await temporaryProjectTree({
|
|
761
|
+
scratch: join(scratch, `config-${index + 1}`),
|
|
762
|
+
projects: [group.path]
|
|
763
|
+
})).get(group.path);
|
|
764
|
+
if (context === void 0) throw new Error(`Missing temporary fixture context: ${group.path}`);
|
|
765
|
+
const groupFolder = context.folder;
|
|
766
|
+
const compilerOptions = fixtureCompilerOptions({
|
|
767
|
+
compilerOptions: group.compilerOptions,
|
|
768
|
+
configPath: group.path
|
|
769
|
+
});
|
|
770
|
+
await writeFile(join(groupFolder, "package.json"), JSON.stringify(group.packageContext ?? fixturePackageContext(group.path)));
|
|
771
|
+
for (const fixture of fixtures) {
|
|
772
|
+
const inputs = fixtureInputs({
|
|
773
|
+
files: Object.keys(fixture.files),
|
|
774
|
+
compilerOptions
|
|
775
|
+
});
|
|
776
|
+
if (inputs.status === "inapplicable") {
|
|
777
|
+
console.log(`${fixture.name} (inactive under this config: ${inputs.reason}) | | | INACTIVE`);
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
const folder = join(groupFolder, fixture.name);
|
|
781
|
+
await mkdir(folder);
|
|
782
|
+
await writeFile(join(folder, "tsconfig.json"), JSON.stringify({
|
|
783
|
+
compilerOptions,
|
|
784
|
+
files: inputs.files,
|
|
785
|
+
include: [],
|
|
786
|
+
exclude: []
|
|
787
|
+
}));
|
|
788
|
+
for (const [name, content] of Object.entries(fixture.files)) await writeFile(join(folder, name), content);
|
|
789
|
+
const tsc = timedCommand({
|
|
790
|
+
command: process.execPath,
|
|
791
|
+
args: [
|
|
792
|
+
compiler,
|
|
793
|
+
"--noEmit",
|
|
794
|
+
"--pretty",
|
|
795
|
+
"false",
|
|
796
|
+
"-p",
|
|
797
|
+
folder
|
|
798
|
+
],
|
|
799
|
+
repo: folder
|
|
800
|
+
});
|
|
801
|
+
const checked = timedCommand({
|
|
802
|
+
command: bun,
|
|
803
|
+
args: [...bunCheckArgs(folder), "--threads=1"],
|
|
804
|
+
repo: folder
|
|
805
|
+
});
|
|
806
|
+
const result = fixtureParity({
|
|
807
|
+
seedFiles: inputs.files,
|
|
808
|
+
expected: fixture.codes,
|
|
809
|
+
match: fixture.anyCode ? "any" : "all",
|
|
810
|
+
repo: folder,
|
|
811
|
+
baseline: {
|
|
812
|
+
...tsc,
|
|
813
|
+
status: diagnosticExitStatus({
|
|
814
|
+
status: tsc.status,
|
|
815
|
+
output: tsc.output,
|
|
816
|
+
repo: folder
|
|
817
|
+
})
|
|
818
|
+
},
|
|
819
|
+
candidate: checked
|
|
820
|
+
});
|
|
821
|
+
results.push(result);
|
|
822
|
+
tscWall += tsc.wall;
|
|
823
|
+
bunWall += checked.wall;
|
|
824
|
+
tscRss = Math.max(tscRss, tsc.maxRssKiB);
|
|
825
|
+
bunRss = Math.max(bunRss, checked.maxRssKiB);
|
|
826
|
+
if (result.configurationDiagnostics.length > 0) {
|
|
827
|
+
console.error(`FAIL: invalid fixture configuration for ${fixture.name}: ${result.configurationDiagnostics.join("; ")}`);
|
|
828
|
+
console.log(`${fixture.name} | configuration error | configuration error | FAIL`);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
let outcome = "INACTIVE";
|
|
832
|
+
if (result.active) outcome = result.passed ? "PASS" : "FAIL";
|
|
833
|
+
console.log(`${fixture.name}${result.active ? "" : " (inactive under this config)"} | ${result.tscCodes.join(",")} | ${result.bunCodes.join(",")} | ${outcome}`);
|
|
834
|
+
if (!result.active && !result.passed) console.error(`FAIL: diagnostic comparison differs for inactive class ${fixture.name}: TypeScript exit=${tsc.status}, Bun exit=${checked.status}; missing=${result.identityMissing.join(",")}; extra=${result.identityExtra.join(",")}`);
|
|
835
|
+
if (result.active && result.bunCodes.length === 0) {
|
|
836
|
+
console.error(`FAIL: Bun returned zero diagnostics for active class ${fixture.name} (exit ${checked.status})`);
|
|
837
|
+
if (checked.maxRssKiB <= NO_WORK_MAX_RSS_KIB && checked.wall <= NO_WORK_MAX_WALL_SECONDS) console.error(`Bun measured little checker work: wall=${checked.wall.toFixed(3)}s maxRSS=${checked.maxRssKiB}KiB; verify the checker invocation`);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
console.log(`fixtures tsc: wall=${tscWall.toFixed(3)}s maxRSS=${tscRss}KiB`);
|
|
841
|
+
console.log(`fixtures bun: wall=${bunWall.toFixed(3)}s maxRSS=${bunRss}KiB`);
|
|
842
|
+
if (!results.some(({ active }) => active)) console.error(`FAIL: zero seeded fixture classes active under config group ${index + 1}`);
|
|
843
|
+
groupResults.push(fixtureRunPassed(results));
|
|
844
|
+
}
|
|
845
|
+
} finally {
|
|
846
|
+
await rm(scratch, {
|
|
847
|
+
recursive: true,
|
|
848
|
+
force: true
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
return repository.passed && groupResults.every((passed) => passed);
|
|
852
|
+
};
|
|
853
|
+
//#endregion
|
|
854
|
+
//#region src/typecheck-parity-cli.ts
|
|
855
|
+
const main = async () => {
|
|
856
|
+
if (process.argv.slice(2).length > 0) throw new Error("Usage: stll-typecheck-parity (run from repository root)");
|
|
857
|
+
const policy = JSON.parse(await readFile(new URL("../toolchain.json", import.meta.url), "utf8"));
|
|
858
|
+
if (!await runTypecheckParity({
|
|
859
|
+
repo: process.cwd(),
|
|
860
|
+
policy
|
|
861
|
+
})) process.exitCode = 1;
|
|
862
|
+
};
|
|
863
|
+
main().catch((error) => {
|
|
864
|
+
process.stderr.write(`typecheck-parity: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
865
|
+
process.exitCode = 1;
|
|
866
|
+
});
|
|
867
|
+
//#endregion
|
|
868
|
+
export {};
|
|
869
|
+
|
|
870
|
+
//# sourceMappingURL=typecheck-parity-cli.mjs.map
|