veoflow 0.1.4 → 0.3.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/bin/veoflow.mjs CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import { dirname, join } from "node:path";
3
- import { fileURLToPath } from "node:url";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
4
 
5
5
  const here = dirname(fileURLToPath(import.meta.url));
6
+ process.env.VEO_CHECKERS_MODULE ??= pathToFileURL(join(here, "../dist/checkers.mjs")).href;
6
7
  process.env.VEO_NATIVE_DIR ??= join(here, "../native");
7
8
  process.env.VEO_WEB_ROOT ??= join(here, "../web");
8
- process.env.VEO_VERSION = "0.1.4";
9
+ process.env.VEO_VERSION = "0.3.0";
9
10
  const { main } = await import("../dist/veo.mjs");
10
11
  const code = await main(process.argv.slice(2), {
11
12
  out: (line) => process.stdout.write(line + "\n"),
@@ -0,0 +1,586 @@
1
+ import { createRequire as __veoRequire } from 'node:module'; const require = __veoRequire(import.meta.url);
2
+
3
+ // packages/checkers/src/scip.ts
4
+ import { spawnSync } from "node:child_process";
5
+ import {
6
+ cpSync,
7
+ existsSync,
8
+ mkdirSync,
9
+ mkdtempSync,
10
+ readdirSync,
11
+ readFileSync,
12
+ rmSync,
13
+ writeFileSync
14
+ } from "node:fs";
15
+ import { createRequire } from "node:module";
16
+ import { tmpdir } from "node:os";
17
+ import { dirname, join, relative } from "node:path";
18
+ import ts from "typescript";
19
+ var require2 = createRequire(import.meta.url);
20
+ var MAIN = require2.resolve("@sourcegraph/scip-typescript/dist/src/main.js");
21
+ var DEFINITION = 1;
22
+ var CONFIG = /^(?:[tj]sconfig(?:\..+)?\.json|package\.json)$/;
23
+ function indexFolder(root, options2 = {}) {
24
+ const work = mkdtempSync(join(tmpdir(), "veo-scip-"));
25
+ try {
26
+ const copy = join(work, "src");
27
+ if (options2.files) {
28
+ for (const f of options2.files) {
29
+ mkdirSync(dirname(join(copy, f)), { recursive: true });
30
+ cpSync(join(root, f), join(copy, f));
31
+ }
32
+ copyConfigs(root, copy);
33
+ } else
34
+ cpSync(root, copy, {
35
+ recursive: true,
36
+ // Relative to the root, so a folder that itself sits under node_modules works.
37
+ filter: (p) => !/(^|[\\/])(node_modules|\.git)([\\/]|$)/.test(relative(root, p))
38
+ });
39
+ const own = existsSync(join(copy, "tsconfig.json"));
40
+ const out = join(work, "index.scip");
41
+ const index = (base) => {
42
+ writeFileSync(
43
+ join(copy, "tsconfig.veo.json"),
44
+ JSON.stringify({
45
+ ...base,
46
+ compilerOptions: {
47
+ ...base.compilerOptions ?? {},
48
+ allowJs: true,
49
+ checkJs: false,
50
+ jsx: "preserve",
51
+ target: "es2022",
52
+ module: "esnext",
53
+ moduleResolution: "bundler",
54
+ experimentalDecorators: true,
55
+ noEmit: true,
56
+ skipLibCheck: true
57
+ },
58
+ include: ["**/*"]
59
+ })
60
+ );
61
+ return spawnSync(process.execPath, [MAIN, "index", "tsconfig.veo.json", "--output", out], {
62
+ cwd: copy,
63
+ encoding: "utf8"
64
+ });
65
+ };
66
+ let r = index(own ? { extends: "./tsconfig.json" } : {});
67
+ if (r.status !== 0 && own) r = index({ compilerOptions: ownPaths(join(copy, "tsconfig.json")) });
68
+ if (r.status !== 0)
69
+ throw new Error(`scip-typescript failed: ${r.error?.message ?? ""} ${r.stderr || r.stdout}`.trim());
70
+ return readIndex(out);
71
+ } finally {
72
+ rmSync(work, { recursive: true, force: true });
73
+ }
74
+ }
75
+ function copyConfigs(root, copy, rel = "") {
76
+ let entries;
77
+ try {
78
+ entries = readdirSync(join(root, rel), { withFileTypes: true });
79
+ } catch {
80
+ return;
81
+ }
82
+ for (const e of entries) {
83
+ const path = rel ? `${rel}/${e.name}` : e.name;
84
+ if (e.isDirectory()) {
85
+ if (e.name !== "node_modules" && e.name !== ".git") copyConfigs(root, copy, path);
86
+ } else if (e.isFile() && CONFIG.test(e.name)) {
87
+ mkdirSync(dirname(join(copy, path)), { recursive: true });
88
+ cpSync(join(root, path), join(copy, path));
89
+ }
90
+ }
91
+ }
92
+ function ownPaths(path) {
93
+ try {
94
+ const parsed = ts.parseConfigFileTextToJson(path, readFileSync(path, "utf8")).config;
95
+ const o = parsed?.compilerOptions ?? {};
96
+ return {
97
+ ...typeof o.baseUrl === "string" ? { baseUrl: o.baseUrl } : {},
98
+ ...o.paths && typeof o.paths === "object" ? { paths: o.paths } : {}
99
+ };
100
+ } catch {
101
+ return {};
102
+ }
103
+ }
104
+ function readIndex(path) {
105
+ const { scip } = require2(join(dirname(MAIN), "scip.js"));
106
+ const index = scip.Index.deserializeBinary(readFileSync(path));
107
+ return index.documents.map((d) => ({
108
+ path: d.relative_path,
109
+ occurrences: d.occurrences.map((o) => ({ range: [...o.range], symbol: o.symbol, roles: o.symbol_roles }))
110
+ }));
111
+ }
112
+
113
+ // packages/checkers/src/translate.ts
114
+ import ts2 from "typescript";
115
+ var Source = class {
116
+ constructor(path, text) {
117
+ this.path = path;
118
+ this.bom = text.charCodeAt(0) === 65279;
119
+ this.text = this.bom ? text.slice(1) : text;
120
+ this.sf = ts2.createSourceFile(path, this.text, ts2.ScriptTarget.Latest, true, scriptKind(path));
121
+ }
122
+ path;
123
+ sf;
124
+ /** The file starts with a BOM, which SCIP positions don't count but the adapter's do. */
125
+ bom;
126
+ text;
127
+ /** TS offset of a SCIP (line, UTF-16 character) position. */
128
+ offset(line, char) {
129
+ return this.sf.getPositionOfLineAndCharacter(line, char);
130
+ }
131
+ /** Adapter position (line, column in characters) of a TS offset. */
132
+ pos(offset) {
133
+ const { line, character } = this.sf.getLineAndCharacterOfPosition(offset);
134
+ const lineStart = offset - character;
135
+ let column = [...this.text.slice(lineStart, offset)].length + 1;
136
+ if (this.bom && line === 0) column += 1;
137
+ const bytes = Buffer.byteLength(this.text.slice(0, offset), "utf8") + (this.bom ? 3 : 0);
138
+ return { line: line + 1, column, offset: bytes };
139
+ }
140
+ span(node) {
141
+ const s = this.pos(node.getStart(this.sf));
142
+ const e = this.pos(node.getEnd());
143
+ return {
144
+ start: { line: s.line, column: s.column, offset: s.offset },
145
+ end: { line: e.line, column: e.column, offset: e.offset }
146
+ };
147
+ }
148
+ /** The innermost node at an offset. */
149
+ nodeAt(offset) {
150
+ let found;
151
+ const visit = (node) => {
152
+ if (offset >= node.getStart(this.sf) && offset < node.getEnd()) {
153
+ found = node;
154
+ ts2.forEachChild(node, visit);
155
+ }
156
+ };
157
+ visit(this.sf);
158
+ return found;
159
+ }
160
+ };
161
+ var unwrap = (n) => n.parent && (ts2.isParenthesizedExpression(n.parent) || ts2.isNonNullExpression(n.parent)) ? unwrap(n.parent) : n;
162
+ function callSiteOf(id) {
163
+ if (!id.parent || !(ts2.isIdentifier(id) || ts2.isPrivateIdentifier(id))) return null;
164
+ let target = id;
165
+ if (ts2.isPropertyAccessExpression(id.parent) && id.parent.name === id) target = id.parent;
166
+ target = unwrap(target);
167
+ const parent = target.parent;
168
+ if (!parent) return null;
169
+ if (ts2.isCallExpression(parent) && parent.expression === target) return { site: parent, form: "call" };
170
+ if (ts2.isNewExpression(parent) && parent.expression === target) return { site: parent, form: "new" };
171
+ if (ts2.isTaggedTemplateExpression(parent) && parent.tag === target)
172
+ return { site: parent, form: "tagged-template" };
173
+ if (ts2.isDecorator(parent) && parent.expression === target) return { site: parent, form: "decorator" };
174
+ if ((ts2.isJsxOpeningElement(parent) || ts2.isJsxSelfClosingElement(parent)) && parent.tagName === target)
175
+ return { site: parent, form: "jsx" };
176
+ if (ts2.isPropertyAccessExpression(parent) && parent.expression === target) {
177
+ const method = parent.name.text;
178
+ const call = unwrap(parent).parent;
179
+ if (call && ts2.isCallExpression(call) && call.expression === unwrap(parent)) {
180
+ if (method === "call" || method === "apply") return { site: call, form: "call-apply" };
181
+ if (method === "bind") {
182
+ const outer = unwrap(call).parent;
183
+ if (outer && ts2.isCallExpression(outer) && outer.expression === unwrap(call))
184
+ return { site: outer, form: "bind" };
185
+ }
186
+ }
187
+ }
188
+ return null;
189
+ }
190
+ function callableKind(symbol, definedAs) {
191
+ if (symbol.includes("<get>") || symbol.includes("<set>")) return null;
192
+ const p = definedAs?.parent;
193
+ if (definedAs && (ts2.isConstructorDeclaration(definedAs) || p && ts2.isConstructorDeclaration(p)))
194
+ return "class";
195
+ if (p && (ts2.isMethodSignature(p) || ts2.isMethodDeclaration(p) && !p.body)) return "candidate";
196
+ if (/\(\)\.$/.test(symbol)) return "function";
197
+ if (/#$/.test(symbol) && p && ts2.isClassLike(p)) return "class";
198
+ if (definedAs && p) {
199
+ if (ts2.isFunctionDeclaration(p) || ts2.isFunctionExpression(p) || ts2.isMethodDeclaration(p))
200
+ return "function";
201
+ if (ts2.isClassLike(p)) return "class";
202
+ if (ts2.isVariableDeclaration(p) && p.initializer) {
203
+ const init = ts2.isParenthesizedExpression(p.initializer) ? p.initializer.expression : p.initializer;
204
+ if (ts2.isArrowFunction(init) || ts2.isFunctionExpression(init)) return "function";
205
+ if (ts2.isClassExpression(init)) return "class";
206
+ }
207
+ if (ts2.isPropertyAssignment(p) && (ts2.isArrowFunction(p.initializer) || ts2.isFunctionExpression(p.initializer)))
208
+ return "function";
209
+ if (ts2.isPropertyDeclaration(p) && p.initializer && (ts2.isArrowFunction(p.initializer) || ts2.isFunctionExpression(p.initializer)))
210
+ return "function";
211
+ }
212
+ return null;
213
+ }
214
+ function calleeName(node, sf) {
215
+ const ctor = ts2.isConstructorDeclaration(node) ? node : node.parent && ts2.isConstructorDeclaration(node.parent) ? node.parent : null;
216
+ if (ctor) return ctor.parent.name?.getText(sf) ?? "<class>";
217
+ const fe = node.parent;
218
+ if (fe && ts2.isFunctionExpression(fe) && fe.name === node) {
219
+ const binding = ts2.isParenthesizedExpression(fe.parent) ? fe.parent.parent : fe.parent;
220
+ if (ts2.isVariableDeclaration(binding) && ts2.isIdentifier(binding.name)) return binding.name.text;
221
+ }
222
+ return node.getText(sf);
223
+ }
224
+ function isBookkeeping(id) {
225
+ const p = id.parent;
226
+ return !p || ts2.isImportSpecifier(p) || ts2.isImportClause(p) || ts2.isNamespaceImport(p) || ts2.isExportSpecifier(p) || ts2.isJsxClosingElement(p);
227
+ }
228
+ function translate(docs, texts) {
229
+ const sources = /* @__PURE__ */ new Map();
230
+ const sourceOf = (path) => {
231
+ let s = sources.get(path);
232
+ if (!s && texts.has(path)) {
233
+ s = new Source(path, texts.get(path));
234
+ sources.set(path, s);
235
+ }
236
+ return s;
237
+ };
238
+ const key = (doc, symbol) => symbol.startsWith("local ") ? `${doc}\0${symbol}` : symbol;
239
+ const defs = /* @__PURE__ */ new Map();
240
+ const firstSeen = /* @__PURE__ */ new Map();
241
+ const at = /* @__PURE__ */ new Map();
242
+ for (const d of docs)
243
+ for (const o of d.occurrences) {
244
+ const k = key(d.path, o.symbol);
245
+ const where = { file: d.path, line: o.range[0], char: o.range[1] };
246
+ if (o.roles & DEFINITION && !defs.has(k)) defs.set(k, where);
247
+ if (!firstSeen.has(k)) firstSeen.set(k, where);
248
+ const rk = `${d.path}:${o.range.join(",")}`;
249
+ at.set(rk, [...at.get(rk) ?? [], o]);
250
+ }
251
+ const definitionOf = (doc, symbol) => defs.get(key(doc, symbol)) ?? (symbol.startsWith("local ") ? firstSeen.get(key(doc, symbol)) : void 0);
252
+ const resolveCallee = (doc, symbol, depth = 0) => {
253
+ const def = definitionOf(doc, symbol);
254
+ if (!def) return null;
255
+ const src = sourceOf(def.file);
256
+ if (!src) return null;
257
+ const node = src.nodeAt(src.offset(def.line, def.char));
258
+ if (node?.parent && ts2.isShorthandPropertyAssignment(node.parent) && depth < 3) {
259
+ const value = (at.get(`${def.file}:${[def.line, def.char, def.char + node.getWidth(src.sf)].join(",")}`) ?? []).find((o) => o.symbol !== symbol);
260
+ return value ? resolveCallee(def.file, value.symbol, depth + 1) : void 0;
261
+ }
262
+ const kind = callableKind(symbol, node);
263
+ if (kind === "candidate") return "candidate";
264
+ if (!kind || !node) return void 0;
265
+ return { file: def.file, name: calleeName(node, src.sf), at: src.pos(node.getStart(src.sf)), kind };
266
+ };
267
+ const calls = [];
268
+ const candidates = [];
269
+ let references = 0;
270
+ for (const d of docs) {
271
+ const src = sourceOf(d.path);
272
+ if (!src) continue;
273
+ for (const o of d.occurrences) {
274
+ if (o.roles & DEFINITION) continue;
275
+ const id = src.nodeAt(src.offset(o.range[0], o.range[1]));
276
+ if (!id || isBookkeeping(id)) continue;
277
+ const callee = resolveCallee(d.path, o.symbol);
278
+ if (callee === void 0) continue;
279
+ if (callee === null && ts2.isIdentifier(id) && ["call", "apply", "bind"].includes(id.text) && id.parent && ts2.isPropertyAccessExpression(id.parent) && id.parent.name === id)
280
+ continue;
281
+ const site = callSiteOf(id);
282
+ const isClass = callee !== null && callee !== "candidate" && callee.kind === "class";
283
+ if (!site || isClass && site.form !== "new" && site.form !== "jsx") {
284
+ references++;
285
+ continue;
286
+ }
287
+ const record = {
288
+ file: d.path,
289
+ site: src.span(site.site),
290
+ form: site.form,
291
+ callee: callee === "candidate" ? null : callee,
292
+ symbol: o.symbol
293
+ };
294
+ (callee === "candidate" ? candidates : calls).push(record);
295
+ }
296
+ const occurrenceAt = (node) => {
297
+ const s = src.sf.getLineAndCharacterOfPosition(node.getStart(src.sf));
298
+ return (at.get(`${d.path}:${[s.line, s.character, s.character + node.getWidth(src.sf)].join(",")}`) ?? [])[0];
299
+ };
300
+ const visit = (node) => {
301
+ if (ts2.isCallExpression(node)) {
302
+ let inner = node.expression;
303
+ while (ts2.isParenthesizedExpression(inner)) inner = inner.expression;
304
+ if (node.expression.kind === ts2.SyntaxKind.SuperKeyword) {
305
+ const cls = findAncestor(node, ts2.isClassLike);
306
+ const base = cls?.heritageClauses?.find((h) => h.token === ts2.SyntaxKind.ExtendsKeyword)?.types[0]?.expression;
307
+ const ref = base && occurrenceAt(base);
308
+ const target = ref ? resolveCallee(d.path, ref.symbol) : null;
309
+ calls.push({
310
+ file: d.path,
311
+ site: src.span(node),
312
+ form: "super",
313
+ callee: target && target !== "candidate" ? { ...target, kind: "class" } : null,
314
+ symbol: ref?.symbol ?? "super"
315
+ });
316
+ } else if (ts2.isFunctionExpression(inner) || ts2.isArrowFunction(inner)) {
317
+ calls.push({
318
+ file: d.path,
319
+ site: src.span(node),
320
+ form: "iife",
321
+ callee: {
322
+ file: d.path,
323
+ name: "<iife>",
324
+ at: src.pos(inner.getStart(src.sf)),
325
+ kind: "function",
326
+ exact: true
327
+ },
328
+ symbol: "iife"
329
+ });
330
+ }
331
+ }
332
+ ts2.forEachChild(node, visit);
333
+ };
334
+ visit(src.sf);
335
+ }
336
+ return { calls, candidates, references };
337
+ }
338
+ function findAncestor(node, test) {
339
+ for (let n = node.parent; n; n = n.parent) if (test(n)) return n;
340
+ return void 0;
341
+ }
342
+ function scriptKind(path) {
343
+ if (path.endsWith(".tsx")) return ts2.ScriptKind.TSX;
344
+ if (path.endsWith(".jsx")) return ts2.ScriptKind.JSX;
345
+ if (/\.[mc]?ts$/.test(path)) return ts2.ScriptKind.TS;
346
+ return ts2.ScriptKind.JS;
347
+ }
348
+
349
+ // packages/checkers/src/compare.ts
350
+ var DISAGREEMENTS = ["different-callee", "adapter-only", "checker-only"];
351
+ var siteKey = (file, s) => `${file}\0${s.start.line}:${s.start.column}-${s.end.line}:${s.end.column}`;
352
+ var contains = (s, p) => (s.start.line < p.line || s.start.line === p.line && s.start.column <= p.column) && (s.end.line > p.line || s.end.line === p.line && s.end.column >= p.column);
353
+ var before = (a, s) => a.line < s.start.line || a.line === s.start.line && a.column <= s.start.column;
354
+ var size = (d) => d.span.end.offset - d.span.start.offset;
355
+ function adapterDef(files, call) {
356
+ const callee = call.callee;
357
+ if (!callee) return null;
358
+ const defs = files.get(callee.file)?.definitions ?? [];
359
+ if (callee.exact)
360
+ return defs.find((d) => d.span.start.line === callee.at.line && d.span.start.column === callee.at.column) ?? null;
361
+ if (callee.kind === "class") {
362
+ const names = call.form === "jsx" ? [`${callee.name}.render`, `${callee.name}.constructor`] : [`${callee.name}.constructor`];
363
+ for (const n of names) {
364
+ const d = defs.find((x) => x.qualifiedName === n || x.qualifiedName.endsWith(`.${n}`));
365
+ if (d) return d;
366
+ }
367
+ return null;
368
+ }
369
+ const named = defs.filter((d) => d.name === callee.name);
370
+ const inside = named.filter((d) => contains(d.span, callee.at)).sort((a, b) => size(a) - size(b));
371
+ if (inside[0]) return inside[0];
372
+ return named.filter((d) => before(callee.at, d.span)).sort((a, b) => a.span.start.offset - b.span.start.offset)[0] ?? null;
373
+ }
374
+ function compare(adapter, checker, references = 0, candidates = 0, inScope = () => true) {
375
+ const files = new Map(adapter.map((f) => [f.path, f]));
376
+ const counts = {
377
+ agree: 0,
378
+ "different-callee": 0,
379
+ "adapter-only": 0,
380
+ "checker-only": 0,
381
+ linking: 0,
382
+ outside: 0
383
+ };
384
+ const sites = [];
385
+ const adapterCalls = /* @__PURE__ */ new Map();
386
+ const adapterUnresolved = /* @__PURE__ */ new Map();
387
+ for (const f of adapter) {
388
+ if (!inScope(f.path)) continue;
389
+ for (const c of f.calls) {
390
+ const k = siteKey(f.path, c.site);
391
+ adapterCalls.set(k, [
392
+ ...adapterCalls.get(k) ?? [],
393
+ { file: f.path, site: c.site, callee: c.callee, text: `${c.caller} \u2192 ${c.callee}` }
394
+ ]);
395
+ }
396
+ for (const u of f.unresolved)
397
+ adapterUnresolved.set(siteKey(f.path, u.site), {
398
+ file: f.path,
399
+ site: u.site,
400
+ status: u.status,
401
+ reason: u.reason,
402
+ expression: u.expression
403
+ });
404
+ }
405
+ const checkerBySite = /* @__PURE__ */ new Map();
406
+ for (const c of checker) {
407
+ if (!inScope(c.file)) continue;
408
+ const k = siteKey(c.file, c.site);
409
+ checkerBySite.set(k, [...checkerBySite.get(k) ?? [], c]);
410
+ }
411
+ const record = (category, rec, adapterText, checkerText) => {
412
+ counts[category]++;
413
+ if (category !== "agree")
414
+ sites.push({
415
+ category,
416
+ file: rec.file,
417
+ line: rec.site.start.line,
418
+ column: rec.site.start.column,
419
+ adapter: adapterText,
420
+ checker: checkerText
421
+ });
422
+ };
423
+ for (const [k, cs] of checkerBySite) {
424
+ const rec = { file: cs[0].file, site: cs[0].site };
425
+ const inFolder = cs.filter((c) => c.callee && files.has(c.callee.file));
426
+ const wanted = new Set(inFolder.map((c) => adapterDef(files, c)).map((d) => d?.qualifiedName ?? "?"));
427
+ const checkerText = cs.map(
428
+ (c) => c.callee ? `${c.callee.file}:${c.callee.at.line} ${c.callee.name} (${c.form})` : `outside the folder (${c.form})`
429
+ ).join("; ");
430
+ const a = adapterCalls.get(k);
431
+ if (a) {
432
+ const got = new Set(a.map((x) => x.callee));
433
+ const text = a.map((x) => x.text).join("; ");
434
+ if (inFolder.length === 0) record("adapter-only", rec, text, `no call in the folder (${checkerText})`);
435
+ else if (wanted.size === got.size && [...wanted].every((q) => got.has(q)))
436
+ record("agree", rec, text, checkerText);
437
+ else record("different-callee", rec, text, checkerText);
438
+ continue;
439
+ }
440
+ const u = adapterUnresolved.get(k);
441
+ const unresolvedText = u ? `${u.expression}: ${u.reason} (${u.status})` : "no record";
442
+ if (u && (u.status === "awaiting-link" || u.status === "external"))
443
+ record("linking", rec, unresolvedText, checkerText);
444
+ else if (inFolder.length > 0) record("checker-only", rec, unresolvedText, checkerText);
445
+ else record("outside", rec, unresolvedText, checkerText);
446
+ }
447
+ for (const [k, a] of adapterCalls)
448
+ if (!checkerBySite.has(k)) record("adapter-only", a[0], a.map((x) => x.text).join("; "), "no call");
449
+ sites.sort(
450
+ (x, y) => (x.file < y.file ? -1 : x.file > y.file ? 1 : 0) || x.line - y.line || x.column - y.column
451
+ );
452
+ return { counts, sites, references, candidates };
453
+ }
454
+ function formatReport(report, title = "Reference checker vs adapter") {
455
+ const c = report.counts;
456
+ const lines = [
457
+ `# ${title}`,
458
+ "",
459
+ `Agree: ${c.agree} \xB7 different callee: ${c["different-callee"]} \xB7 adapter only: ${c["adapter-only"]} \xB7 checker only: ${c["checker-only"]}`,
460
+ "",
461
+ `Not disagreements: linking (Stage 2) ${c.linking} \xB7 outside the folder ${c.outside} \xB7 interface/abstract candidates ${report.candidates} \xB7 non-call references ${report.references}`,
462
+ ""
463
+ ];
464
+ const disagreements = report.sites.filter((s) => DISAGREEMENTS.includes(s.category));
465
+ if (disagreements.length === 0) lines.push("No disagreements.");
466
+ else {
467
+ lines.push("| category | site | adapter | checker |", "|---|---|---|---|");
468
+ const cell = (t) => t.replace(/\|/g, "\\|").replace(/\n/g, " ");
469
+ for (const s of disagreements)
470
+ lines.push(
471
+ `| ${s.category} | ${s.file}:${s.line}:${s.column} | ${cell(s.adapter)} | ${cell(s.checker)} |`
472
+ );
473
+ }
474
+ return lines.join("\n") + "\n";
475
+ }
476
+
477
+ // packages/checkers/src/imports.ts
478
+ import { existsSync as existsSync2, readFileSync as readFileSync2, realpathSync, statSync } from "node:fs";
479
+ import { dirname as dirname2, join as join2, relative as relative2, sep } from "node:path";
480
+ import ts3 from "typescript";
481
+ function options(root) {
482
+ const path = join2(root, "tsconfig.json");
483
+ const base = {};
484
+ if (existsSync2(path)) {
485
+ const read = ts3.readConfigFile(path, (p) => ts3.sys.readFile(p));
486
+ Object.assign(base, ts3.parseJsonConfigFileContent(read.config ?? {}, ts3.sys, root).options);
487
+ }
488
+ return {
489
+ ...base,
490
+ module: ts3.ModuleKind.ESNext,
491
+ moduleResolution: ts3.ModuleResolutionKind.Bundler,
492
+ allowJs: true,
493
+ resolveJsonModule: true,
494
+ allowArbitraryExtensions: true
495
+ };
496
+ }
497
+ function resolveWithCompiler(root, queries, packages) {
498
+ const rootReal = realpathSync(root);
499
+ const nm = `${sep}node_modules${sep}`;
500
+ const map = (p) => {
501
+ const i = p.indexOf(nm);
502
+ if (i === -1 || !p.startsWith(rootReal)) return p;
503
+ const rest = p.slice(i + nm.length).split(sep);
504
+ const scoped = rest[0]?.startsWith("@");
505
+ const name = scoped ? `${rest[0]}/${rest[1]}` : rest[0];
506
+ const dir = packages.get(name);
507
+ if (dir === void 0) return p;
508
+ return join2(rootReal, dir, ...rest.slice(scoped ? 2 : 1));
509
+ };
510
+ const host = {
511
+ fileExists: (p) => {
512
+ const m = map(p);
513
+ return existsSync2(m) && statSync(m).isFile();
514
+ },
515
+ readFile: (p) => {
516
+ try {
517
+ return readFileSync2(map(p), "utf8");
518
+ } catch {
519
+ return void 0;
520
+ }
521
+ },
522
+ directoryExists: (p) => {
523
+ const m = map(p);
524
+ if (existsSync2(m)) return statSync(m).isDirectory();
525
+ const prefix = p.endsWith(sep) ? p : p + sep;
526
+ return [...packages.keys()].some((name) => join2(rootReal, "node_modules", name).startsWith(prefix));
527
+ },
528
+ realpath: (p) => map(p),
529
+ getCurrentDirectory: () => rootReal
530
+ };
531
+ const opts = options(rootReal);
532
+ return queries.map((q) => {
533
+ const { resolvedModule } = ts3.resolveModuleName(q.specifier, join2(rootReal, q.from), opts, host);
534
+ if (!resolvedModule) return null;
535
+ const file = map(resolvedModule.resolvedFileName);
536
+ if (file.includes(nm) || !file.startsWith(rootReal)) return null;
537
+ const target = file.replace(/\.d(\.[a-z]+)\.ts$/, "$1");
538
+ return relative2(rootReal, target).split(sep).join("/");
539
+ });
540
+ }
541
+ var IMPORT_DISAGREEMENTS = [
542
+ "different-file",
543
+ "stage2-only",
544
+ "checker-only"
545
+ ];
546
+ function compareImports(root, imports, packages) {
547
+ const checker = resolveWithCompiler(root, imports, packages);
548
+ return imports.map((q, i) => {
549
+ const got = checker[i] ?? null;
550
+ const s = q.stage2;
551
+ const stage2 = s.kind === "file" ? s.file : s.kind === "external" ? "(external)" : `(${s.outcome})`;
552
+ let category;
553
+ if (s.kind === "external" || s.kind === "unresolved" && s.outcome !== "broken") category = "external";
554
+ else if (s.kind === "file" && /\.(vue|svelte)$/.test(s.file) && got === null) category = "unsupported";
555
+ else if (s.kind === "file")
556
+ category = got === null ? "stage2-only" : got === s.file ? "agree" : "different-file";
557
+ else category = got === null ? "agree" : "checker-only";
558
+ return { category, from: q.from, specifier: q.specifier, stage2, checker: got };
559
+ });
560
+ }
561
+ function workspacePackages(root, manifests) {
562
+ const out = /* @__PURE__ */ new Map();
563
+ for (const m of manifests) {
564
+ try {
565
+ const name = JSON.parse(readFileSync2(join2(root, m), "utf8")).name;
566
+ if (typeof name === "string" && !out.has(name)) out.set(name, dirname2(m) === "." ? "" : dirname2(m));
567
+ } catch {
568
+ }
569
+ }
570
+ return out;
571
+ }
572
+ export {
573
+ DEFINITION,
574
+ DISAGREEMENTS,
575
+ IMPORT_DISAGREEMENTS,
576
+ adapterDef,
577
+ callSiteOf,
578
+ compare,
579
+ compareImports,
580
+ formatReport,
581
+ indexFolder,
582
+ readIndex,
583
+ resolveWithCompiler,
584
+ translate,
585
+ workspacePackages
586
+ };