veoflow 0.5.7 → 0.7.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 +1 -1
- package/dist/checkers.mjs +618 -2
- package/dist/veo.mjs +2342 -180
- package/native/binding.cjs +2 -0
- package/native/veo-extract.darwin-arm64.node +0 -0
- package/native/veo-extract.darwin-x64.node +0 -0
- package/native/veo-extract.linux-arm64-gnu.node +0 -0
- package/native/veo-extract.linux-x64-gnu.node +0 -0
- package/native/veo-extract.win32-x64-msvc.node +0 -0
- package/package.json +3 -2
- package/web/assets/{index-DKA0d0wb.js → index-C3_r4kcv.js} +3 -3
- package/web/index.html +1 -1
package/dist/veo.mjs
CHANGED
|
@@ -98,7 +98,7 @@ function withOrdinals(items, groupKey) {
|
|
|
98
98
|
return [item, n2];
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
var SAFE_SOURCE_ID, ids;
|
|
101
|
+
var SAFE_SOURCE_ID, ids, importStatement;
|
|
102
102
|
var init_ids = __esm({
|
|
103
103
|
"packages/core/src/ids.ts"() {
|
|
104
104
|
"use strict";
|
|
@@ -130,6 +130,7 @@ var init_ids = __esm({
|
|
|
130
130
|
/** A function where a path may start (#305). */
|
|
131
131
|
startCandidate: (functionId2) => `start|${functionId2}`
|
|
132
132
|
};
|
|
133
|
+
importStatement = (e) => `${e.from}\0${e.specifier}\0${e.evidence.span.start.offset}`;
|
|
133
134
|
}
|
|
134
135
|
});
|
|
135
136
|
|
|
@@ -174,6 +175,7 @@ var init_model = __esm({
|
|
|
174
175
|
metaprogramming: "built at run time",
|
|
175
176
|
"dynamic-sql": "SQL built at run time",
|
|
176
177
|
"imported-symbol": "imported, not linked",
|
|
178
|
+
"package-symbol": "in another file of its package",
|
|
177
179
|
"runtime-global": "built-in",
|
|
178
180
|
"builtin-value": "built-in value",
|
|
179
181
|
"template-binding": "awaiting its component",
|
|
@@ -254,8 +256,8 @@ function foldProgress(p, e) {
|
|
|
254
256
|
case "stage.progress": {
|
|
255
257
|
p = joined(p, e.runId);
|
|
256
258
|
const { done: _d, total: _t, unit: _u, ...rest } = p;
|
|
257
|
-
const { type: _type, projectId: _p, runId: _r, stage, ...
|
|
258
|
-
return { ...rest, stage, ...
|
|
259
|
+
const { type: _type, projectId: _p, runId: _r, stage, ...step2 } = e;
|
|
260
|
+
return { ...rest, stage, ...step2 };
|
|
259
261
|
}
|
|
260
262
|
case "stage.completed":
|
|
261
263
|
if (p?.runId !== e.runId) return p;
|
|
@@ -280,8 +282,8 @@ function progressWords(p) {
|
|
|
280
282
|
if (p.phase === "saving results") return { text: `${name}: saving results${of}`, fraction: 1 };
|
|
281
283
|
if (p.phase) {
|
|
282
284
|
const counted = p.total === void 0 ? "" : p.done === void 0 ? ` (${n(p.total)}${p.unit ? ` ${p.unit}` : ""})` : `: ${n(p.done)} of ${n(p.total)}${p.unit && p.unit !== "files" ? ` ${p.unit}` : ""}`;
|
|
283
|
-
const
|
|
284
|
-
what = p.phase === "reading files" ? counted : `: ${p.phase}${counted}${
|
|
285
|
+
const step2 = p.steps && p.steps > 1 ? `, step ${p.step} of ${p.steps}` : "";
|
|
286
|
+
what = p.phase === "reading files" ? counted : `: ${p.phase}${counted}${step2}`;
|
|
285
287
|
if (p.done !== void 0 && p.total) fraction = p.done / p.total;
|
|
286
288
|
else if (p.steps && p.step) fraction = (p.step - 1) / p.steps;
|
|
287
289
|
}
|
|
@@ -504,6 +506,9 @@ var init_classify = __esm({
|
|
|
504
506
|
"tsx",
|
|
505
507
|
"vue",
|
|
506
508
|
"svelte",
|
|
509
|
+
// Python (#415, R3) and Go (#436).
|
|
510
|
+
"python",
|
|
511
|
+
"go",
|
|
507
512
|
"angular-template"
|
|
508
513
|
]);
|
|
509
514
|
UNSUPPORTED = {
|
|
@@ -863,8 +868,8 @@ function readBlobs(top, shas, sizes, batchBytes = BATCH_BYTES) {
|
|
|
863
868
|
let pos = 0;
|
|
864
869
|
while (pos < out.length) {
|
|
865
870
|
const nl = out.indexOf(10, pos);
|
|
866
|
-
const
|
|
867
|
-
const [sha, type, size] =
|
|
871
|
+
const header2 = out.subarray(pos, nl).toString("utf8");
|
|
872
|
+
const [sha, type, size] = header2.split(" ");
|
|
868
873
|
if (type === "missing" || !size) {
|
|
869
874
|
pos = nl + 1;
|
|
870
875
|
continue;
|
|
@@ -1246,7 +1251,7 @@ function unreadNotice(files) {
|
|
|
1246
1251
|
const parts = [...by].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([name, n2]) => `${n2.toLocaleString("en-US")} ${name} ${n2 === 1 ? "file" : "files"}`);
|
|
1247
1252
|
const list = parts.length === 1 ? parts[0] : `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}`;
|
|
1248
1253
|
const total = [...by.values()].reduce((a, b) => a + b, 0);
|
|
1249
|
-
return `${list} ${total === 1 ? "is" : "are"} listed but not analyzed yet: veoflow analyzes JavaScript and TypeScript (with Vue, Svelte and Angular components) today.`;
|
|
1254
|
+
return `${list} ${total === 1 ? "is" : "are"} listed but not analyzed yet: veoflow analyzes JavaScript and TypeScript (with Vue, Svelte and Angular components), Python and Go today.`;
|
|
1250
1255
|
}
|
|
1251
1256
|
function ignoredSourceFolders(root, unpinned) {
|
|
1252
1257
|
const out = [];
|
|
@@ -1869,7 +1874,7 @@ var init_plan = __esm({
|
|
|
1869
1874
|
};
|
|
1870
1875
|
DEFAULT_MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
1871
1876
|
HARD_MAX_FILE_BYTES = 64 * 1024 * 1024;
|
|
1872
|
-
RESOLVER_MANIFEST = /(^|\/)(package\.json|project\.json|nx\.json|(ts|js)config[^/]*\.json|package-lock\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|\.npmrc|\.yarnrc\.yml)$/;
|
|
1877
|
+
RESOLVER_MANIFEST = /(^|\/)(package\.json|project\.json|nx\.json|pyproject\.toml|setup\.cfg|requirements[^/]*\.txt|uv\.lock|poetry\.lock|go\.mod|go\.work|(ts|js)config[^/]*\.json|package-lock\.json|pnpm-lock\.yaml|pnpm-workspace\.yaml|yarn\.lock|\.npmrc|\.yarnrc\.yml)$/;
|
|
1873
1878
|
RESOLVER_INPUT = /\.(json|jsonc|lock|ya?ml|toml|mod|sum)$|(^|\/)(\.npmrc|\.nvmrc|\.babelrc)$/i;
|
|
1874
1879
|
MINIFIED_MIN_BYTES = 2e4;
|
|
1875
1880
|
count = (n2, noun) => `${n2.toLocaleString("en-US")} ${noun}${n2 === 1 ? "" : "s"}`;
|
|
@@ -2621,14 +2626,14 @@ CREATE TABLE IF NOT EXISTS lock (
|
|
|
2621
2626
|
SELECT a.id, a.type, a.file, a.src, 'removed' AS change
|
|
2622
2627
|
FROM a LEFT JOIN b ON b.id = a.id WHERE b.id IS NULL`
|
|
2623
2628
|
).all({ ...pinParams(pa, "a_"), ...pinParams(pb, "b_") });
|
|
2624
|
-
const
|
|
2629
|
+
const cmp12 = (x, y) => x < y ? -1 : x > y ? 1 : 0;
|
|
2625
2630
|
return rows.map((r) => ({
|
|
2626
2631
|
id: r.id,
|
|
2627
2632
|
type: r.type,
|
|
2628
2633
|
change: r.change,
|
|
2629
2634
|
file: r.file,
|
|
2630
2635
|
source: changeSource(r.id, r.file, r.src)
|
|
2631
|
-
})).sort((x, y) =>
|
|
2636
|
+
})).sort((x, y) => cmp12(x.file ?? "", y.file ?? "") || cmp12(x.type, y.type) || cmp12(x.id, y.id));
|
|
2632
2637
|
}
|
|
2633
2638
|
/** How many facts of each type a committed run's graph holds. */
|
|
2634
2639
|
factCounts(run2) {
|
|
@@ -3791,6 +3796,7 @@ var init_src2 = __esm({
|
|
|
3791
3796
|
// packages/extract-client/src/index.ts
|
|
3792
3797
|
var src_exports = {};
|
|
3793
3798
|
__export(src_exports, {
|
|
3799
|
+
SUPPORTED: () => SUPPORTED,
|
|
3794
3800
|
acceptsTestLicenses: () => acceptsTestLicenses,
|
|
3795
3801
|
adapterVersion: () => adapterVersion,
|
|
3796
3802
|
cacheSize: () => cacheSize,
|
|
@@ -3798,6 +3804,9 @@ __export(src_exports, {
|
|
|
3798
3804
|
extract: () => extract,
|
|
3799
3805
|
isAvailable: () => isAvailable,
|
|
3800
3806
|
languageForPath: () => languageForPath,
|
|
3807
|
+
phaseTimings: () => phaseTimings,
|
|
3808
|
+
platformName: () => platformName,
|
|
3809
|
+
resetPhaseTimings: () => resetPhaseTimings,
|
|
3801
3810
|
resolve: () => resolve3,
|
|
3802
3811
|
runQueries: () => runQueries,
|
|
3803
3812
|
verifyLicense: () => verifyLicense
|
|
@@ -3813,12 +3822,17 @@ function native() {
|
|
|
3813
3822
|
return binding;
|
|
3814
3823
|
} catch (e) {
|
|
3815
3824
|
loadError = new Error(
|
|
3816
|
-
|
|
3825
|
+
process.env.VEO_NATIVE_DIR ? `veoflow has no prebuilt engine for ${platformName()}. ${SUPPORTED}` : `The veo-extract native module is not built for ${platformName()}. Run: pnpm --filter @veo/extract-client build:native`,
|
|
3817
3826
|
{ cause: e }
|
|
3818
3827
|
);
|
|
3819
3828
|
throw loadError;
|
|
3820
3829
|
}
|
|
3821
3830
|
}
|
|
3831
|
+
function platformName() {
|
|
3832
|
+
const report = process.report?.getReport();
|
|
3833
|
+
const musl = process.platform === "linux" && !report?.header?.glibcVersionRuntime;
|
|
3834
|
+
return `${process.platform}-${process.arch}${musl ? " (musl)" : ""}`;
|
|
3835
|
+
}
|
|
3822
3836
|
function isAvailable() {
|
|
3823
3837
|
try {
|
|
3824
3838
|
native();
|
|
@@ -3857,10 +3871,17 @@ function languageForPath(path) {
|
|
|
3857
3871
|
const ext = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
3858
3872
|
return LANGUAGES[ext];
|
|
3859
3873
|
}
|
|
3860
|
-
|
|
3874
|
+
function phaseTimings() {
|
|
3875
|
+
return JSON.parse(native().phaseTimings());
|
|
3876
|
+
}
|
|
3877
|
+
function resetPhaseTimings() {
|
|
3878
|
+
native().resetPhaseTimings();
|
|
3879
|
+
}
|
|
3880
|
+
var binding, loadError, SUPPORTED, LANGUAGES;
|
|
3861
3881
|
var init_src3 = __esm({
|
|
3862
3882
|
"packages/extract-client/src/index.ts"() {
|
|
3863
3883
|
"use strict";
|
|
3884
|
+
SUPPORTED = "It runs on macOS (Apple silicon and Intel), Linux with glibc (x64 and arm64) and Windows (x64), with Node.js 22.13 or newer.";
|
|
3864
3885
|
LANGUAGES = {
|
|
3865
3886
|
js: "javascript",
|
|
3866
3887
|
mjs: "javascript",
|
|
@@ -3871,7 +3892,9 @@ var init_src3 = __esm({
|
|
|
3871
3892
|
cts: "typescript",
|
|
3872
3893
|
tsx: "tsx",
|
|
3873
3894
|
vue: "vue",
|
|
3874
|
-
svelte: "svelte"
|
|
3895
|
+
svelte: "svelte",
|
|
3896
|
+
py: "python",
|
|
3897
|
+
go: "go"
|
|
3875
3898
|
};
|
|
3876
3899
|
}
|
|
3877
3900
|
});
|
|
@@ -4576,7 +4599,7 @@ var PROTOCOL_VERSION;
|
|
|
4576
4599
|
var init_protocol = __esm({
|
|
4577
4600
|
"protocol/index.ts"() {
|
|
4578
4601
|
"use strict";
|
|
4579
|
-
PROTOCOL_VERSION = "1.
|
|
4602
|
+
PROTOCOL_VERSION = "1.9.0";
|
|
4580
4603
|
}
|
|
4581
4604
|
});
|
|
4582
4605
|
|
|
@@ -4893,7 +4916,7 @@ var init_stage1 = __esm({
|
|
|
4893
4916
|
byOffset = (a, b) => a.site.start.offset - b.site.start.offset || a.site.end.offset - b.site.end.offset;
|
|
4894
4917
|
BATCH_BYTES2 = 32 << 20;
|
|
4895
4918
|
BATCH_FILES = 200;
|
|
4896
|
-
STAGE1_VERSION =
|
|
4919
|
+
STAGE1_VERSION = 4;
|
|
4897
4920
|
stage1 = {
|
|
4898
4921
|
name: STAGE1,
|
|
4899
4922
|
version: () => `${STAGE1_VERSION}+${adapterVersion()}`,
|
|
@@ -7886,6 +7909,7 @@ function rollUp(out, groupOf, input2, fnFile) {
|
|
|
7886
7909
|
if (!r) roll.set(key, r = { imports: [], calls: [], references: [] });
|
|
7887
7910
|
return r;
|
|
7888
7911
|
};
|
|
7912
|
+
const statements2 = /* @__PURE__ */ new Set();
|
|
7889
7913
|
for (const e of input2.imports) {
|
|
7890
7914
|
const from = groupOf.get(e.from);
|
|
7891
7915
|
if (!from) continue;
|
|
@@ -7895,7 +7919,13 @@ function rollUp(out, groupOf, input2, fnFile) {
|
|
|
7895
7919
|
continue;
|
|
7896
7920
|
}
|
|
7897
7921
|
const to = groupOf.get(e.to);
|
|
7898
|
-
if (to && to !== from)
|
|
7922
|
+
if (to && to !== from) {
|
|
7923
|
+
const statement = `${from}\0${to}\0${e.from}\0${e.specifier}\0${e.evidence.span.start.offset}`;
|
|
7924
|
+
if (!statements2.has(statement)) {
|
|
7925
|
+
statements2.add(statement);
|
|
7926
|
+
rollOf(from, to).imports.push(e);
|
|
7927
|
+
}
|
|
7928
|
+
}
|
|
7899
7929
|
}
|
|
7900
7930
|
for (const c of input2.calls) {
|
|
7901
7931
|
const fromFile = fnFile.get(c.from);
|
|
@@ -9634,7 +9664,11 @@ function getGroup(engine, args, cwd) {
|
|
|
9634
9664
|
for (const f of files) {
|
|
9635
9665
|
const from = nodeOf.get(f.id);
|
|
9636
9666
|
if (!kept.has(from)) continue;
|
|
9667
|
+
const counted = /* @__PURE__ */ new Set();
|
|
9637
9668
|
for (const e of reader.facts("IMPORTS", f.id)) {
|
|
9669
|
+
const key = `${importStatement(e)}\0${members2.has(e.to) ? nodeOf.get(e.to) : e.to}`;
|
|
9670
|
+
if (counted.has(key)) continue;
|
|
9671
|
+
counted.add(key);
|
|
9638
9672
|
if (members2.has(e.to)) {
|
|
9639
9673
|
const to = nodeOf.get(e.to);
|
|
9640
9674
|
if (to !== from) add2(edges, from, to, e.evidence);
|
|
@@ -9766,14 +9800,14 @@ function resolveImports(engine, args, cwd) {
|
|
|
9766
9800
|
evidence: u.evidence
|
|
9767
9801
|
}))
|
|
9768
9802
|
].sort(byEvidence);
|
|
9769
|
-
const
|
|
9803
|
+
const statementKey2 = (id) => id.replace(/^(IMPORTS|unresolved-import)\|/, "");
|
|
9770
9804
|
const namesOf = /* @__PURE__ */ new Map();
|
|
9771
9805
|
for (const n2 of importedNames(reader, file2.id)) {
|
|
9772
9806
|
const key = n2.id.replace(/^IMPORTS_SYMBOL\|/, "").replace(/\|[^|]*$/, "");
|
|
9773
9807
|
namesOf.set(key, [...namesOf.get(key) ?? [], n2]);
|
|
9774
9808
|
}
|
|
9775
9809
|
for (const i of imports) {
|
|
9776
|
-
const names = namesOf.get(
|
|
9810
|
+
const names = namesOf.get(statementKey2(i.id));
|
|
9777
9811
|
if (names) i.names = names;
|
|
9778
9812
|
}
|
|
9779
9813
|
const importers = reader.factsTo("IMPORTS", file2.id).sort(byEvidence);
|
|
@@ -10335,7 +10369,9 @@ function explainImport(reader, e) {
|
|
|
10335
10369
|
};
|
|
10336
10370
|
}
|
|
10337
10371
|
function explainUnresolvedImport(u) {
|
|
10338
|
-
const
|
|
10372
|
+
const language = /\.go$/.test(u.file) ? "go" : /\.pyi?$/.test(u.file) ? "python" : null;
|
|
10373
|
+
const own2 = language ? LANGUAGE_IMPORTS[language]?.[u.reason] : void 0;
|
|
10374
|
+
const why = own2?.[0] ?? IMPORT_REASONS[u.reason] ?? u.reason;
|
|
10339
10375
|
const word = { broken: "is broken", "not-analyzed": "leads to a file not analyzed", pending: "is pending" }[u.outcome];
|
|
10340
10376
|
return {
|
|
10341
10377
|
...base(u, u.file),
|
|
@@ -10344,7 +10380,7 @@ function explainUnresolvedImport(u) {
|
|
|
10344
10380
|
outcome: u.outcome,
|
|
10345
10381
|
summary: `'${u.specifier}' ${word}: ${why}.`,
|
|
10346
10382
|
steps: u.steps,
|
|
10347
|
-
...IMPORT_FIXES[u.reason] ? { toResolve: IMPORT_FIXES[u.reason] } : {}
|
|
10383
|
+
...own2?.[1] ?? IMPORT_FIXES[u.reason] ? { toResolve: own2?.[1] ?? IMPORT_FIXES[u.reason] } : {}
|
|
10348
10384
|
};
|
|
10349
10385
|
}
|
|
10350
10386
|
function mayBeBuiltin(reader, expression, reason) {
|
|
@@ -10585,6 +10621,7 @@ function explain(engine, args, cwd) {
|
|
|
10585
10621
|
)
|
|
10586
10622
|
);
|
|
10587
10623
|
const items = [];
|
|
10624
|
+
const explainedImports = /* @__PURE__ */ new Map();
|
|
10588
10625
|
for (const fact of facts) {
|
|
10589
10626
|
if (!("evidence" in fact) || !onLine(fact.evidence)) continue;
|
|
10590
10627
|
if (fact.type === "SiteResolution") continue;
|
|
@@ -10592,9 +10629,24 @@ function explain(engine, args, cwd) {
|
|
|
10592
10629
|
if (fact.type === "CALLS_CROSS_FILE" && fact.id.startsWith("CALLS_CROSS_FILE|site|")) continue;
|
|
10593
10630
|
if (fact.type === "UnresolvedCallSite" && fact.reason === "template-binding" && !fact.component && linkedBindings.has(fact.evidence.span.start.offset))
|
|
10594
10631
|
continue;
|
|
10632
|
+
if (fact.type === "IMPORTS") {
|
|
10633
|
+
const key = importStatement(fact);
|
|
10634
|
+
if (explainedImports.has(key)) {
|
|
10635
|
+
explainedImports.get(key).push(fact);
|
|
10636
|
+
continue;
|
|
10637
|
+
}
|
|
10638
|
+
explainedImports.set(key, [fact]);
|
|
10639
|
+
}
|
|
10595
10640
|
const item = explainFact(reader, fact, stage22);
|
|
10596
10641
|
if (item) items.push(item);
|
|
10597
10642
|
}
|
|
10643
|
+
for (const item of items) {
|
|
10644
|
+
const group = item.kind === "import" ? [...explainedImports.values()].find((g) => g[0].id === item.id) : void 0;
|
|
10645
|
+
if (group && group.length > 1) {
|
|
10646
|
+
const paths = group.map((e) => pathOf3(e.to));
|
|
10647
|
+
item.summary = `'${group[0].specifier}' resolves to ${group.length} files of its package: ${paths.join(", ")}.`;
|
|
10648
|
+
}
|
|
10649
|
+
}
|
|
10598
10650
|
items.sort(
|
|
10599
10651
|
(a, b) => (
|
|
10600
10652
|
// Every item on a line has evidence (it was matched by it).
|
|
@@ -10610,7 +10662,7 @@ function explain(engine, args, cwd) {
|
|
|
10610
10662
|
...file2.status !== "analyzed" ? { file: { status: file2.status, ...file2.reason ? { reason: file2.reason } : {} } } : {}
|
|
10611
10663
|
};
|
|
10612
10664
|
}
|
|
10613
|
-
var EXPLAIN_MAX, pathOf3, cmp5, IMPORT_REASONS, SITE_REASONS, STATUS_WORDS, base, IMPORT_FIXES, CALL_FIXES, RESOLUTION_WORDS;
|
|
10665
|
+
var EXPLAIN_MAX, pathOf3, cmp5, IMPORT_REASONS, SITE_REASONS, STATUS_WORDS, base, LANGUAGE_IMPORTS, IMPORT_FIXES, CALL_FIXES, RESOLUTION_WORDS;
|
|
10614
10666
|
var init_explain = __esm({
|
|
10615
10667
|
"packages/query-imports/src/explain.ts"() {
|
|
10616
10668
|
"use strict";
|
|
@@ -10640,6 +10692,7 @@ var init_explain = __esm({
|
|
|
10640
10692
|
"computed-member": "the function is picked by a computed key, so which one runs depends on the key's value",
|
|
10641
10693
|
"dynamic-sql": "it runs SQL built at run time",
|
|
10642
10694
|
"imported-symbol": "it calls something imported from another file, which Stage 2 links",
|
|
10695
|
+
"package-symbol": "it calls something another file of its package declares (Go), which Stage 2 links",
|
|
10643
10696
|
"runtime-global": "it is part of the language or runtime (a built-in), outside the code analyzed",
|
|
10644
10697
|
"builtin-value": "the value it is called on is built in (a string, a number, a DOM element, a fetch response), so it runs code of the runtime, outside the code analyzed",
|
|
10645
10698
|
"template-binding": "it is a call in a template file, resolved against the components that declare the template",
|
|
@@ -10661,6 +10714,24 @@ var init_explain = __esm({
|
|
|
10661
10714
|
line: fact.evidence.span.start.line,
|
|
10662
10715
|
evidence: fact.evidence
|
|
10663
10716
|
});
|
|
10717
|
+
LANGUAGE_IMPORTS = {
|
|
10718
|
+
go: {
|
|
10719
|
+
"unknown-package": [
|
|
10720
|
+
"no module of the project provides it and go.mod doesn't require it",
|
|
10721
|
+
"Require its module in go.mod, or add the module to the go.work (use) or a local replace."
|
|
10722
|
+
],
|
|
10723
|
+
"file-not-found": [
|
|
10724
|
+
"the module provides no package in that folder",
|
|
10725
|
+
"Fix the import path, or add the package's folder to the module."
|
|
10726
|
+
]
|
|
10727
|
+
},
|
|
10728
|
+
python: {
|
|
10729
|
+
"unknown-package": [
|
|
10730
|
+
"it isn't in the project, the standard library or a distribution the project declares",
|
|
10731
|
+
"Declare its distribution in pyproject.toml or requirements.txt, or add the source that holds it."
|
|
10732
|
+
]
|
|
10733
|
+
}
|
|
10734
|
+
};
|
|
10664
10735
|
IMPORT_FIXES = {
|
|
10665
10736
|
"file-not-found": "Fix the path, or add the file it names.",
|
|
10666
10737
|
"not-exported": "Import a path the package exports, or export it from the package.",
|
|
@@ -11274,7 +11345,7 @@ async function loadCheckers() {
|
|
|
11274
11345
|
} catch (e) {
|
|
11275
11346
|
throw new VeoError(
|
|
11276
11347
|
"checker-failed",
|
|
11277
|
-
`the
|
|
11348
|
+
`the reference checkers aren't available here (${e.message}); reinstall veoflow with its dependencies`,
|
|
11278
11349
|
{ reason: "unavailable" }
|
|
11279
11350
|
);
|
|
11280
11351
|
}
|
|
@@ -11295,13 +11366,27 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11295
11366
|
const scope2 = relative3(source.root, abs).split(sep6).join("/");
|
|
11296
11367
|
const inScope = (path) => scope2 === "" || path === scope2 || path.startsWith(`${scope2}/`);
|
|
11297
11368
|
const { reader } = engine.readAllStages({ project: projectId });
|
|
11298
|
-
const
|
|
11299
|
-
(f) => f.source === source.id && (f.status === "analyzed" || f.status === "degraded") && f.language !== null &&
|
|
11369
|
+
const checkable = (set2) => reader.facts("File").filter(
|
|
11370
|
+
(f) => f.source === source.id && (f.status === "analyzed" || f.status === "degraded") && f.language !== null && set2.has(f.language) && !f.path.endsWith(".d.ts")
|
|
11300
11371
|
);
|
|
11372
|
+
const script = checkable(CHECKED);
|
|
11373
|
+
const pythonFiles = checkable(CHECKED_PYTHON);
|
|
11374
|
+
const goFiles = checkable(CHECKED_GO);
|
|
11375
|
+
const holds = (fs) => fs.some((f) => inScope(f.path));
|
|
11376
|
+
if (!holds(script) && holds(pythonFiles) && holds(goFiles))
|
|
11377
|
+
throw new VeoError(
|
|
11378
|
+
"invalid-arguments",
|
|
11379
|
+
`${args.path} holds Python and Go files: check a Python folder and a Go folder on their own`,
|
|
11380
|
+
{ fields: ["path"] }
|
|
11381
|
+
);
|
|
11382
|
+
const mode = holds(script) ? "typescript" : holds(pythonFiles) ? "python" : holds(goFiles) ? "go" : "typescript";
|
|
11383
|
+
const python = mode === "python";
|
|
11384
|
+
const go = mode === "go";
|
|
11385
|
+
const analyzed = python ? pythonFiles : go ? goFiles : script;
|
|
11301
11386
|
if (!analyzed.some((f) => inScope(f.path)))
|
|
11302
11387
|
throw new VeoError(
|
|
11303
11388
|
"invalid-arguments",
|
|
11304
|
-
`no analyzed JavaScript or
|
|
11389
|
+
`no analyzed JavaScript, TypeScript, Python or Go files under ${args.path} (the checkers read those; analyze the project first)`,
|
|
11305
11390
|
{ fields: ["path"] }
|
|
11306
11391
|
);
|
|
11307
11392
|
const texts = /* @__PURE__ */ new Map();
|
|
@@ -11324,11 +11409,11 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11324
11409
|
const { extract: extract2 } = await Promise.resolve().then(() => (init_src3(), src_exports));
|
|
11325
11410
|
let index;
|
|
11326
11411
|
try {
|
|
11327
|
-
index = checkers.indexFolder(source.root, { files: [...texts.keys()] });
|
|
11412
|
+
index = python ? checkers.indexPython(source.root, [...texts.keys()]) : go ? checkers.indexGo(source.root, [...texts.keys()]) : checkers.indexFolder(source.root, { files: [...texts.keys()] });
|
|
11328
11413
|
} catch (e) {
|
|
11329
11414
|
throw new VeoError(
|
|
11330
11415
|
"checker-failed",
|
|
11331
|
-
|
|
11416
|
+
`${python ? "scip-python" : go ? "scip-go" : "the TypeScript compiler"} couldn't index ${source.root}: ${e.message}`,
|
|
11332
11417
|
{
|
|
11333
11418
|
reason: "index"
|
|
11334
11419
|
}
|
|
@@ -11342,8 +11427,15 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11342
11427
|
manifests: [],
|
|
11343
11428
|
files
|
|
11344
11429
|
}).files;
|
|
11345
|
-
const { calls, candidates, references } = checkers.translate(index, texts);
|
|
11346
|
-
const
|
|
11430
|
+
const { calls, candidates, references } = python ? { calls: checkers.translatePython(index, adapter, texts), candidates: [], references: 0 } : go ? { calls: checkers.translateGo(index, adapter, texts), candidates: [], references: 0 } : checkers.translate(index, texts);
|
|
11431
|
+
const indexed = go ? new Set(index.map((d) => d.path)) : null;
|
|
11432
|
+
const report = checkers.compare(
|
|
11433
|
+
adapter,
|
|
11434
|
+
calls,
|
|
11435
|
+
references,
|
|
11436
|
+
candidates.length,
|
|
11437
|
+
(p) => inScope(p) && (!indexed || indexed.has(p))
|
|
11438
|
+
);
|
|
11347
11439
|
const fileId = (path) => ids.file(source.id, path);
|
|
11348
11440
|
const adapterFiles = new Map(adapter.map((f) => [f.path, f]));
|
|
11349
11441
|
const stage22 = reader.writtenStages().includes("stage2");
|
|
@@ -11402,7 +11494,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11402
11494
|
if (DISAGREE.has(s.category)) {
|
|
11403
11495
|
const category2 = s.category;
|
|
11404
11496
|
counts.stage1[category2]++;
|
|
11405
|
-
const
|
|
11497
|
+
const narrowed2 = category2 === "checker-only" && stage22 ? candidatesAt(s) : void 0;
|
|
11406
11498
|
sites.push({
|
|
11407
11499
|
stage: "stage1",
|
|
11408
11500
|
category: category2,
|
|
@@ -11413,7 +11505,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11413
11505
|
veoflow: s.adapter,
|
|
11414
11506
|
compiler: s.checker,
|
|
11415
11507
|
...changed.has(s.file) ? { changed: true } : {},
|
|
11416
|
-
...
|
|
11508
|
+
...narrowed2 ? { candidates: narrowed2 } : {}
|
|
11417
11509
|
});
|
|
11418
11510
|
continue;
|
|
11419
11511
|
}
|
|
@@ -11444,6 +11536,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11444
11536
|
const category = !stage22 ? "not-linked-yet" : got.size === 0 ? "checker-only" : got.size === expected.size && [...expected].every((x) => got.has(x)) ? "agree" : "different-callee";
|
|
11445
11537
|
counts.stage2[category]++;
|
|
11446
11538
|
if (category === "agree") continue;
|
|
11539
|
+
const narrowed = category === "checker-only" ? candidatesAt(s) : void 0;
|
|
11447
11540
|
sites.push({
|
|
11448
11541
|
stage: "stage2",
|
|
11449
11542
|
category,
|
|
@@ -11452,7 +11545,8 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11452
11545
|
line: s.line,
|
|
11453
11546
|
column: s.column,
|
|
11454
11547
|
veoflow: got.size ? [...got].join("; ") : stage2Answer(factsOf(fileId(s.file)), s, stage22, reader),
|
|
11455
|
-
compiler: s.checker
|
|
11548
|
+
compiler: s.checker,
|
|
11549
|
+
...narrowed ? { candidates: narrowed } : {}
|
|
11456
11550
|
});
|
|
11457
11551
|
}
|
|
11458
11552
|
sites.sort(
|
|
@@ -11463,7 +11557,7 @@ async function checkCode(engine, args, cwd = process.cwd()) {
|
|
|
11463
11557
|
source: source.id,
|
|
11464
11558
|
root: source.root,
|
|
11465
11559
|
path: scope2,
|
|
11466
|
-
checker: "scip-typescript",
|
|
11560
|
+
checker: python ? "scip-python" : go ? "scip-go" : "scip-typescript",
|
|
11467
11561
|
files: [...texts.keys()].filter(inScope).length,
|
|
11468
11562
|
changed: [...changed].filter(inScope).sort(),
|
|
11469
11563
|
stage2: stage22,
|
|
@@ -11487,7 +11581,7 @@ function stage2Answer(facts, at, stage22, reader) {
|
|
|
11487
11581
|
if (r.importOutcome) return `open: ${reasonWords(r.importOutcome)}`;
|
|
11488
11582
|
return `open: ${reasonWords(r.steps.at(-1)?.kind ?? "unresolved")}`;
|
|
11489
11583
|
}
|
|
11490
|
-
var CHECKED, DISAGREE;
|
|
11584
|
+
var CHECKED, CHECKED_PYTHON, CHECKED_GO, DISAGREE;
|
|
11491
11585
|
var init_check = __esm({
|
|
11492
11586
|
"packages/query-imports/src/check.ts"() {
|
|
11493
11587
|
"use strict";
|
|
@@ -11495,6 +11589,8 @@ var init_check = __esm({
|
|
|
11495
11589
|
init_protocol();
|
|
11496
11590
|
init_src2();
|
|
11497
11591
|
CHECKED = /* @__PURE__ */ new Set(["typescript", "tsx", "javascript", "jsx"]);
|
|
11592
|
+
CHECKED_PYTHON = /* @__PURE__ */ new Set(["python"]);
|
|
11593
|
+
CHECKED_GO = /* @__PURE__ */ new Set(["go"]);
|
|
11498
11594
|
DISAGREE = /* @__PURE__ */ new Set(["different-callee", "adapter-only", "checker-only"]);
|
|
11499
11595
|
}
|
|
11500
11596
|
});
|
|
@@ -11528,9 +11624,13 @@ function fileSummary(engine, args, cwd) {
|
|
|
11528
11624
|
if (!reader.writtenStages().includes("stage2"))
|
|
11529
11625
|
return { ...meta3, file: f.id, path: f.path, alone, acrossFiles: null };
|
|
11530
11626
|
const imports = { files: 0, packages: 0, unresolved: 0 };
|
|
11531
|
-
|
|
11627
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11628
|
+
for (const e of reader.facts("IMPORTS", f.id)) {
|
|
11629
|
+
if (seen.has(importStatement(e))) continue;
|
|
11630
|
+
seen.add(importStatement(e));
|
|
11532
11631
|
if (reader.fact(e.to)?.type === "ExternalPackage") imports.packages++;
|
|
11533
11632
|
else imports.files++;
|
|
11633
|
+
}
|
|
11534
11634
|
imports.unresolved = reader.facts("UnresolvedImport", f.id).filter((u) => u.reason !== "asset").length;
|
|
11535
11635
|
return { ...meta3, file: f.id, path: f.path, alone, acrossFiles: { ...outcomes(reader, f.id), imports } };
|
|
11536
11636
|
}
|
|
@@ -12035,7 +12135,8 @@ function pairOf(reader, end2, from, to, groups2) {
|
|
|
12035
12135
|
callers: new Set(edges.map((e) => e.from)).size,
|
|
12036
12136
|
callees: new Set(edges.map((e) => e.to)).size,
|
|
12037
12137
|
references: references.length,
|
|
12038
|
-
|
|
12138
|
+
// By statement: a Go import is an edge to each file of its package it reaches (#437).
|
|
12139
|
+
imports: new Set(imports.map(importStatement)).size
|
|
12039
12140
|
},
|
|
12040
12141
|
references: references.slice(0, PAIR_LIST_MAX).map((r) => ({
|
|
12041
12142
|
id: r.id,
|
|
@@ -12044,7 +12145,7 @@ function pairOf(reader, end2, from, to, groups2) {
|
|
|
12044
12145
|
context: r.context,
|
|
12045
12146
|
evidence: r.evidence
|
|
12046
12147
|
})),
|
|
12047
|
-
imports: imports.slice(0, PAIR_LIST_MAX).map((e) => ({
|
|
12148
|
+
imports: imports.filter((e, i, all2) => all2.findIndex((x) => importStatement(x) === importStatement(e)) === i).slice(0, PAIR_LIST_MAX).map((e) => ({
|
|
12048
12149
|
id: e.id,
|
|
12049
12150
|
file: e.from,
|
|
12050
12151
|
path: e.from.slice(e.from.indexOf(":") + 1),
|
|
@@ -12894,7 +12995,7 @@ var require_cmp = __commonJS({
|
|
|
12894
12995
|
var gte = require_gte();
|
|
12895
12996
|
var lt = require_lt();
|
|
12896
12997
|
var lte = require_lte();
|
|
12897
|
-
var
|
|
12998
|
+
var cmp12 = (a, op, b, loose) => {
|
|
12898
12999
|
switch (op) {
|
|
12899
13000
|
case "===":
|
|
12900
13001
|
if (typeof a === "object") {
|
|
@@ -12930,7 +13031,7 @@ var require_cmp = __commonJS({
|
|
|
12930
13031
|
throw new TypeError(`Invalid operator: ${op}`);
|
|
12931
13032
|
}
|
|
12932
13033
|
};
|
|
12933
|
-
module.exports =
|
|
13034
|
+
module.exports = cmp12;
|
|
12934
13035
|
}
|
|
12935
13036
|
});
|
|
12936
13037
|
|
|
@@ -13505,7 +13606,7 @@ var require_comparator = __commonJS({
|
|
|
13505
13606
|
return false;
|
|
13506
13607
|
}
|
|
13507
13608
|
}
|
|
13508
|
-
return
|
|
13609
|
+
return cmp12(version3, this.operator, this.semver, this.options);
|
|
13509
13610
|
}
|
|
13510
13611
|
intersects(comp, options2) {
|
|
13511
13612
|
if (!(comp instanceof _Comparator)) {
|
|
@@ -13538,10 +13639,10 @@ var require_comparator = __commonJS({
|
|
|
13538
13639
|
if (this.semver.version === comp.semver.version && this.operator.includes("=") && comp.operator.includes("=")) {
|
|
13539
13640
|
return true;
|
|
13540
13641
|
}
|
|
13541
|
-
if (
|
|
13642
|
+
if (cmp12(this.semver, "<", comp.semver, options2) && this.operator.startsWith(">") && comp.operator.startsWith("<")) {
|
|
13542
13643
|
return true;
|
|
13543
13644
|
}
|
|
13544
|
-
if (
|
|
13645
|
+
if (cmp12(this.semver, ">", comp.semver, options2) && this.operator.startsWith("<") && comp.operator.startsWith(">")) {
|
|
13545
13646
|
return true;
|
|
13546
13647
|
}
|
|
13547
13648
|
return false;
|
|
@@ -13550,7 +13651,7 @@ var require_comparator = __commonJS({
|
|
|
13550
13651
|
module.exports = Comparator;
|
|
13551
13652
|
var parseOptions = require_parse_options();
|
|
13552
13653
|
var { safeRe: re, t } = require_re();
|
|
13553
|
-
var
|
|
13654
|
+
var cmp12 = require_cmp();
|
|
13554
13655
|
var debug = require_debug();
|
|
13555
13656
|
var SemVer = require_semver();
|
|
13556
13657
|
var Range = require_range();
|
|
@@ -14061,7 +14162,7 @@ var require_semver2 = __commonJS({
|
|
|
14061
14162
|
var neq = require_neq();
|
|
14062
14163
|
var gte = require_gte();
|
|
14063
14164
|
var lte = require_lte();
|
|
14064
|
-
var
|
|
14165
|
+
var cmp12 = require_cmp();
|
|
14065
14166
|
var coerce = require_coerce();
|
|
14066
14167
|
var truncate = require_truncate();
|
|
14067
14168
|
var Comparator = require_comparator();
|
|
@@ -14100,7 +14201,7 @@ var require_semver2 = __commonJS({
|
|
|
14100
14201
|
neq,
|
|
14101
14202
|
gte,
|
|
14102
14203
|
lte,
|
|
14103
|
-
cmp:
|
|
14204
|
+
cmp: cmp12,
|
|
14104
14205
|
coerce,
|
|
14105
14206
|
truncate,
|
|
14106
14207
|
Comparator,
|
|
@@ -15781,7 +15882,7 @@ function importFacts(resolved) {
|
|
|
15781
15882
|
if (target2.kind === "package") packages.set(target2.pkg.id, target2.pkg);
|
|
15782
15883
|
edges.push({
|
|
15783
15884
|
type: "IMPORTS",
|
|
15784
|
-
id: ids.importsEdge(s.fileId, s.specifier, s.ordinal),
|
|
15885
|
+
id: ids.importsEdge(s.fileId, s.specifier, s.ordinal) + (target2.kind === "file" && target2.part !== void 0 ? `|${target2.part}` : ""),
|
|
15785
15886
|
from: s.fileId,
|
|
15786
15887
|
to: target2.kind === "file" ? target2.file.id : target2.pkg.id,
|
|
15787
15888
|
specifier: s.specifier,
|
|
@@ -18968,7 +19069,7 @@ function closedWorldResolutions(input2, graph, s, inj = null) {
|
|
|
18968
19069
|
const fns = [...runs.values()];
|
|
18969
19070
|
if (fns.length === 0 || fns.some((f) => f.fn.file === site.file)) continue;
|
|
18970
19071
|
const names = fns.map((f) => `${f.fn.qualifiedName} (${pathOf9(f.fn.file)})`);
|
|
18971
|
-
const
|
|
19072
|
+
const step2 = {
|
|
18972
19073
|
kind: "closed-world",
|
|
18973
19074
|
detail: `the project is analyzed as a closed world (analysis.closedWorld): the values of ${typeName} it makes run ${fns.length === 1 ? names[0] : `one of ${names.join(", ")}`}, and nothing else`
|
|
18974
19075
|
};
|
|
@@ -18984,7 +19085,7 @@ function closedWorldResolutions(input2, graph, s, inj = null) {
|
|
|
18984
19085
|
externalPackage: null,
|
|
18985
19086
|
via: "closed-world",
|
|
18986
19087
|
importOutcome: null,
|
|
18987
|
-
steps: [...r.steps,
|
|
19088
|
+
steps: [...r.steps, step2],
|
|
18988
19089
|
evidence: r.evidence
|
|
18989
19090
|
});
|
|
18990
19091
|
out.edges.push({
|
|
@@ -19004,7 +19105,7 @@ function closedWorldResolutions(input2, graph, s, inj = null) {
|
|
|
19004
19105
|
if (candidates.length !== fns.length) continue;
|
|
19005
19106
|
const { exhaustive: _open, ...rest } = r;
|
|
19006
19107
|
void _open;
|
|
19007
|
-
out.resolutions.push({ ...rest, steps: [...r.steps,
|
|
19108
|
+
out.resolutions.push({ ...rest, steps: [...r.steps, step2], candidates });
|
|
19008
19109
|
continue;
|
|
19009
19110
|
}
|
|
19010
19111
|
return out;
|
|
@@ -20475,8 +20576,976 @@ var init_exits2 = __esm({
|
|
|
20475
20576
|
}
|
|
20476
20577
|
});
|
|
20477
20578
|
|
|
20478
|
-
// packages/stage2/src/
|
|
20579
|
+
// packages/stage2/src/go.ts
|
|
20479
20580
|
import { posix as posix9 } from "node:path";
|
|
20581
|
+
function parseGoMod(text, dir) {
|
|
20582
|
+
const path = /^\s*module\s+("?)([^\s"]+)\1/m.exec(text)?.[2];
|
|
20583
|
+
if (!path) return null;
|
|
20584
|
+
const requires = /* @__PURE__ */ new Map();
|
|
20585
|
+
const replaces = /* @__PURE__ */ new Map();
|
|
20586
|
+
let block = null;
|
|
20587
|
+
for (const raw of text.split("\n")) {
|
|
20588
|
+
const line = raw.replace(/\/\/.*$/, "").trim();
|
|
20589
|
+
if (!line) continue;
|
|
20590
|
+
if (block) {
|
|
20591
|
+
if (line === ")") {
|
|
20592
|
+
block = null;
|
|
20593
|
+
continue;
|
|
20594
|
+
}
|
|
20595
|
+
}
|
|
20596
|
+
const open3 = /^(require|replace)\s*\($/.exec(line);
|
|
20597
|
+
if (open3) {
|
|
20598
|
+
block = open3[1];
|
|
20599
|
+
continue;
|
|
20600
|
+
}
|
|
20601
|
+
const m = /^(require|replace)\s+(.*)$/.exec(line);
|
|
20602
|
+
const [kind, rest] = m ? [m[1], m[2]] : block ? [block, line] : [null, ""];
|
|
20603
|
+
if (kind === "require") {
|
|
20604
|
+
const r = /^("?)([^\s"]+)\1\s+(\S+)/.exec(rest);
|
|
20605
|
+
if (r) requires.set(r[2], r[3]);
|
|
20606
|
+
} else if (kind === "replace") {
|
|
20607
|
+
const r = /^("?)([^\s"]+)\1(?:\s+\S+)?\s*=>\s*("?)([^\s"]+)\3/.exec(rest);
|
|
20608
|
+
if (r && /^\.\.?(\/|$)/.test(r[4])) {
|
|
20609
|
+
const target2 = posix9.normalize(posix9.join(dir, r[4])).replace(/^\.$/, "").replace(/\/$/, "");
|
|
20610
|
+
if (!target2.startsWith("..")) replaces.set(r[2], target2);
|
|
20611
|
+
}
|
|
20612
|
+
}
|
|
20613
|
+
}
|
|
20614
|
+
return { dir, path, requires, replaces };
|
|
20615
|
+
}
|
|
20616
|
+
function parseGoWork(text, dir) {
|
|
20617
|
+
const out = [];
|
|
20618
|
+
let inUse2 = false;
|
|
20619
|
+
for (const raw of text.split("\n")) {
|
|
20620
|
+
const line = raw.replace(/\/\/.*$/, "").trim();
|
|
20621
|
+
if (!line) continue;
|
|
20622
|
+
if (inUse2) {
|
|
20623
|
+
if (line === ")") inUse2 = false;
|
|
20624
|
+
else out.push(line.replace(/^"|"$/g, ""));
|
|
20625
|
+
continue;
|
|
20626
|
+
}
|
|
20627
|
+
if (/^use\s*\($/.test(line)) inUse2 = true;
|
|
20628
|
+
else {
|
|
20629
|
+
const m = /^use\s+("?)([^\s"]+)\1/.exec(line);
|
|
20630
|
+
if (m) out.push(m[2]);
|
|
20631
|
+
}
|
|
20632
|
+
}
|
|
20633
|
+
return out.map((u) => posix9.normalize(posix9.join(dir, u)).replace(/^\.$/, "").replace(/\/$/, ""));
|
|
20634
|
+
}
|
|
20635
|
+
function goModules(plans) {
|
|
20636
|
+
const out = [];
|
|
20637
|
+
for (const plan of plans) {
|
|
20638
|
+
const mods = [];
|
|
20639
|
+
const works = [];
|
|
20640
|
+
for (const m of plan.manifests) {
|
|
20641
|
+
const base2 = posix9.basename(m.path);
|
|
20642
|
+
const dir = posix9.dirname(m.path) === "." ? "" : posix9.dirname(m.path);
|
|
20643
|
+
if (goSkipsDir(m.path)) continue;
|
|
20644
|
+
if (base2 === "go.mod") {
|
|
20645
|
+
const g = parseGoMod(m.content, dir);
|
|
20646
|
+
if (g) mods.push({ ...g, source: plan.sourceId, workspace: [] });
|
|
20647
|
+
} else if (base2 === "go.work") works.push({ dir, uses: parseGoWork(m.content, dir) });
|
|
20648
|
+
}
|
|
20649
|
+
for (const mod of mods) {
|
|
20650
|
+
const work = works.filter(
|
|
20651
|
+
(w) => (w.dir === "" || mod.dir === w.dir || mod.dir.startsWith(`${w.dir}/`)) && w.uses.includes(mod.dir)
|
|
20652
|
+
).sort((a, b) => b.dir.length - a.dir.length)[0];
|
|
20653
|
+
if (work) mod.workspace = work.uses;
|
|
20654
|
+
}
|
|
20655
|
+
out.push(...mods);
|
|
20656
|
+
}
|
|
20657
|
+
return out;
|
|
20658
|
+
}
|
|
20659
|
+
function goResults(plans) {
|
|
20660
|
+
const out = /* @__PURE__ */ new Map();
|
|
20661
|
+
for (const plan of plans) {
|
|
20662
|
+
const files = plan.files.filter((f) => f.language === "go" && f.content !== void 0 && !f.skip);
|
|
20663
|
+
if (!files.length) continue;
|
|
20664
|
+
const response = extract({
|
|
20665
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
20666
|
+
root: plan.root,
|
|
20667
|
+
manifests: [],
|
|
20668
|
+
files: files.map((f) => ({ path: f.path, language: f.language, content: f.content }))
|
|
20669
|
+
});
|
|
20670
|
+
for (const r of response.files) out.set(`${plan.sourceId}\0${r.path}`, r);
|
|
20671
|
+
}
|
|
20672
|
+
return out;
|
|
20673
|
+
}
|
|
20674
|
+
function suffixed(path) {
|
|
20675
|
+
const parts = posix9.basename(path, ".go").replace(/_test$/, "").split("_");
|
|
20676
|
+
const last = parts.at(-1);
|
|
20677
|
+
const prev = parts.at(-2);
|
|
20678
|
+
return parts.length > 1 && (GOOS.includes(last) || GOARCH.includes(last) && (parts.length === 2 || GOOS.includes(prev ?? "") || parts.length > 2));
|
|
20679
|
+
}
|
|
20680
|
+
function header(text) {
|
|
20681
|
+
let build = null;
|
|
20682
|
+
let legacyIgnore = false;
|
|
20683
|
+
const ignored = () => build ? /^\/\/go:build\s+ignore\s*$/.test(build.text) : legacyIgnore;
|
|
20684
|
+
let offset = 0;
|
|
20685
|
+
let line = 1;
|
|
20686
|
+
let inBlock = false;
|
|
20687
|
+
for (const raw of text.split("\n")) {
|
|
20688
|
+
const l = raw.replace(/\r$/, "");
|
|
20689
|
+
const t = l.trim();
|
|
20690
|
+
if (inBlock) {
|
|
20691
|
+
if (t.includes("*/")) inBlock = false;
|
|
20692
|
+
} else if (t.startsWith("/*")) {
|
|
20693
|
+
if (!t.includes("*/")) inBlock = true;
|
|
20694
|
+
} else if (t.startsWith("//go:build")) {
|
|
20695
|
+
build = { text: t, line, col: l.indexOf("//") + 1, offset: offset + l.indexOf("//") };
|
|
20696
|
+
} else if (/^\/\/\s*\+build\b.*\bignore\b/.test(t)) {
|
|
20697
|
+
legacyIgnore = true;
|
|
20698
|
+
} else if (t && !t.startsWith("//")) {
|
|
20699
|
+
const m = /^\uFEFF?package\s+([A-Za-z_]\w*)/.exec(t);
|
|
20700
|
+
return { pkg: m ? m[1] : null, build, ignore: ignored() };
|
|
20701
|
+
}
|
|
20702
|
+
offset += Buffer.byteLength(raw, "utf8") + 1;
|
|
20703
|
+
line++;
|
|
20704
|
+
}
|
|
20705
|
+
return { pkg: null, build, ignore: ignored() };
|
|
20706
|
+
}
|
|
20707
|
+
function goSkipsDir(path) {
|
|
20708
|
+
return posix9.dirname(path).split("/").some((p) => p === "testdata" || p.length > 1 && (p.startsWith("_") || p.startsWith(".")));
|
|
20709
|
+
}
|
|
20710
|
+
function assumedName(path) {
|
|
20711
|
+
const parts = path.split("/");
|
|
20712
|
+
let base2 = parts.pop() ?? path;
|
|
20713
|
+
if (/^v\d+$/.test(base2) && parts.length) base2 = parts.pop();
|
|
20714
|
+
base2 = base2.replace(/^go-/, "");
|
|
20715
|
+
const m = /^[\p{L}\p{N}_]*/u.exec(base2);
|
|
20716
|
+
return m ? m[0] : base2;
|
|
20717
|
+
}
|
|
20718
|
+
function packageVars(text) {
|
|
20719
|
+
const out = /* @__PURE__ */ new Map();
|
|
20720
|
+
let depth = 0;
|
|
20721
|
+
let inBlock = false;
|
|
20722
|
+
let inRaw = false;
|
|
20723
|
+
let inComment = false;
|
|
20724
|
+
let varBlock = false;
|
|
20725
|
+
const entry = (s) => {
|
|
20726
|
+
const m = /^([A-Za-z_]\w*)\s*(.*)$/.exec(s.trim());
|
|
20727
|
+
if (!m || m[1] === "_") return;
|
|
20728
|
+
const rest = m[2].replace(/\/\/.*$/, "").trim();
|
|
20729
|
+
const v = {};
|
|
20730
|
+
const value = /^=\s*([A-Za-z_]\w*)\s*$/.exec(rest);
|
|
20731
|
+
const lit = /^=\s*&?([A-Za-z_][\w.]*)\s*\{/.exec(rest);
|
|
20732
|
+
const typed = /^\*?([A-Za-z_][\w.]*)\s*(?:=|$)/.exec(rest);
|
|
20733
|
+
if (value) v.value = value[1];
|
|
20734
|
+
else if (lit) v.written = lit[1];
|
|
20735
|
+
else if (typed && !rest.startsWith("=")) v.written = typed[1];
|
|
20736
|
+
if (!out.has(m[1])) out.set(m[1], v);
|
|
20737
|
+
};
|
|
20738
|
+
for (const raw of text.split("\n")) {
|
|
20739
|
+
const atStart = depth;
|
|
20740
|
+
const line = raw.replace(/\r$/, "");
|
|
20741
|
+
if (!inBlock && !inRaw && !inComment) {
|
|
20742
|
+
if (atStart === 0 && /^var\s*\($/.test(line.trim())) varBlock = true;
|
|
20743
|
+
else if (atStart === 0 && /^var\s+/.test(line)) entry(line.replace(/^var\s+/, ""));
|
|
20744
|
+
else if (varBlock && atStart === 1 && line.trim() !== ")") entry(line);
|
|
20745
|
+
}
|
|
20746
|
+
for (let i = 0; i < line.length; i++) {
|
|
20747
|
+
const c = line[i];
|
|
20748
|
+
if (inComment) {
|
|
20749
|
+
if (c === "*" && line[i + 1] === "/") {
|
|
20750
|
+
inComment = false;
|
|
20751
|
+
i++;
|
|
20752
|
+
}
|
|
20753
|
+
continue;
|
|
20754
|
+
}
|
|
20755
|
+
if (inRaw) {
|
|
20756
|
+
if (c === "`") inRaw = false;
|
|
20757
|
+
continue;
|
|
20758
|
+
}
|
|
20759
|
+
if (c === "/" && line[i + 1] === "/") break;
|
|
20760
|
+
if (c === "/" && line[i + 1] === "*") {
|
|
20761
|
+
inComment = true;
|
|
20762
|
+
i++;
|
|
20763
|
+
} else if (c === "`") inRaw = true;
|
|
20764
|
+
else if (c === '"' || c === "'") {
|
|
20765
|
+
let j = i + 1;
|
|
20766
|
+
while (j < line.length && line[j] !== c) j += line[j] === "\\" ? 2 : 1;
|
|
20767
|
+
i = j;
|
|
20768
|
+
} else if (c === "(" || c === "[" || c === "{") depth++;
|
|
20769
|
+
else if (c === ")" || c === "]" || c === "}") depth = Math.max(0, depth - 1);
|
|
20770
|
+
}
|
|
20771
|
+
if (varBlock && depth === 0 && atStart >= 1) varBlock = false;
|
|
20772
|
+
inBlock = inComment;
|
|
20773
|
+
}
|
|
20774
|
+
return out;
|
|
20775
|
+
}
|
|
20776
|
+
function linkGo(input2) {
|
|
20777
|
+
const modules = goModules(input2.plans);
|
|
20778
|
+
const text = new Map(
|
|
20779
|
+
input2.plans.flatMap(
|
|
20780
|
+
(p) => p.files.filter((f) => f.language === "go" && f.content !== void 0).map((f) => [ids.file(p.sourceId, f.path), f.content])
|
|
20781
|
+
)
|
|
20782
|
+
);
|
|
20783
|
+
const moduleOf = (source, path) => modules.filter((m) => m.source === source && (m.dir === "" || path.startsWith(`${m.dir}/`))).sort((a, b) => b.dir.length - a.dir.length)[0] ?? null;
|
|
20784
|
+
const goFiles = /* @__PURE__ */ new Map();
|
|
20785
|
+
for (const node2 of input2.files) {
|
|
20786
|
+
if (node2.language !== "go") continue;
|
|
20787
|
+
const result2 = input2.results.get(`${node2.source}\0${node2.path}`);
|
|
20788
|
+
const t = text.get(node2.id);
|
|
20789
|
+
if (!result2 || t === void 0) continue;
|
|
20790
|
+
const h = header(t);
|
|
20791
|
+
const dir = posix9.dirname(node2.path) === "." ? "" : posix9.dirname(node2.path);
|
|
20792
|
+
goFiles.set(node2.id, {
|
|
20793
|
+
node: node2,
|
|
20794
|
+
// Never built, or skipped by the go command: its own imports and calls still resolve, but no
|
|
20795
|
+
// other file sees it (a file without a package clause, unreadable, is on its own too).
|
|
20796
|
+
excluded: h.ignore || goSkipsDir(node2.path) || !h.pkg,
|
|
20797
|
+
dir,
|
|
20798
|
+
pkg: h.pkg ?? "",
|
|
20799
|
+
test: node2.path.endsWith("_test.go"),
|
|
20800
|
+
build: h.build ? {
|
|
20801
|
+
text: h.build.text,
|
|
20802
|
+
span: {
|
|
20803
|
+
start: { line: h.build.line, column: h.build.col, offset: h.build.offset },
|
|
20804
|
+
end: {
|
|
20805
|
+
line: h.build.line,
|
|
20806
|
+
column: h.build.col + [...h.build.text].length,
|
|
20807
|
+
offset: h.build.offset + Buffer.byteLength(h.build.text, "utf8")
|
|
20808
|
+
}
|
|
20809
|
+
}
|
|
20810
|
+
} : null,
|
|
20811
|
+
suffixed: suffixed(node2.path),
|
|
20812
|
+
module: moduleOf(node2.source, node2.path),
|
|
20813
|
+
result: result2
|
|
20814
|
+
});
|
|
20815
|
+
}
|
|
20816
|
+
const keyOf2 = (f) => `${f.node.source}\0${f.dir}\0${f.pkg}`;
|
|
20817
|
+
const packages = /* @__PURE__ */ new Map();
|
|
20818
|
+
const byDir = /* @__PURE__ */ new Map();
|
|
20819
|
+
for (const f of goFiles.values()) {
|
|
20820
|
+
if (f.excluded) continue;
|
|
20821
|
+
const d = `${f.node.source}\0${f.dir}`;
|
|
20822
|
+
byDir.set(d, [...byDir.get(d) ?? [], f]);
|
|
20823
|
+
const k = keyOf2(f);
|
|
20824
|
+
const list = packages.get(k) ?? [];
|
|
20825
|
+
list.push(f);
|
|
20826
|
+
packages.set(k, list);
|
|
20827
|
+
}
|
|
20828
|
+
for (const list of packages.values()) list.sort((a, b) => cmp10(a.node.path, b.node.path));
|
|
20829
|
+
const visible = (f) => {
|
|
20830
|
+
const own2 = (packages.get(keyOf2(f)) ?? []).filter((g) => f.test || !g.test);
|
|
20831
|
+
return f.excluded ? [...own2, f] : own2;
|
|
20832
|
+
};
|
|
20833
|
+
const importable = (source, dir, mod) => {
|
|
20834
|
+
const inDir = (byDir.get(`${source}\0${dir}`) ?? []).filter(
|
|
20835
|
+
(f) => !f.test && !f.pkg.endsWith("_test") && f.module === mod
|
|
20836
|
+
);
|
|
20837
|
+
if (!inDir.length) return [];
|
|
20838
|
+
const counts = /* @__PURE__ */ new Map();
|
|
20839
|
+
for (const f of inDir) counts.set(f.pkg, (counts.get(f.pkg) ?? 0) + 1);
|
|
20840
|
+
const name = [...counts].sort((a, b) => b[1] - a[1] || cmp10(a[0], b[0]))[0][0];
|
|
20841
|
+
return inDir.filter((f) => f.pkg === name).sort((a, b) => cmp10(a.node.path, b.node.path));
|
|
20842
|
+
};
|
|
20843
|
+
const packagesOut = /* @__PURE__ */ new Map();
|
|
20844
|
+
const external = (source, ecosystem, name, version3) => {
|
|
20845
|
+
const id = ids.externalPackage(source, ecosystem, name);
|
|
20846
|
+
let pkg = packagesOut.get(id);
|
|
20847
|
+
if (!pkg) packagesOut.set(id, pkg = { type: "ExternalPackage", id, source, ecosystem, name, version: version3 });
|
|
20848
|
+
return pkg;
|
|
20849
|
+
};
|
|
20850
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
20851
|
+
const resolvePath2 = (from, path) => {
|
|
20852
|
+
const cacheKey = `${from.node.source}\0${from.module?.dir ?? "\0"}\0${path}`;
|
|
20853
|
+
const hit = resolveCache.get(cacheKey);
|
|
20854
|
+
if (hit) return hit;
|
|
20855
|
+
const t = resolveUncached(from, path);
|
|
20856
|
+
resolveCache.set(cacheKey, t);
|
|
20857
|
+
return t;
|
|
20858
|
+
};
|
|
20859
|
+
const resolveUncached = (from, path) => {
|
|
20860
|
+
const source = from.node.source;
|
|
20861
|
+
const mod = from.module;
|
|
20862
|
+
const providers = [];
|
|
20863
|
+
const sourceModules = modules.filter((m) => m.source === source);
|
|
20864
|
+
if (mod) {
|
|
20865
|
+
providers.push({ path: mod.path, local: mod, via: "module" });
|
|
20866
|
+
for (const dir of mod.workspace) {
|
|
20867
|
+
const w = sourceModules.find((m) => m.dir === dir);
|
|
20868
|
+
if (w && w !== mod) providers.push({ path: w.path, local: w, via: "workspace" });
|
|
20869
|
+
}
|
|
20870
|
+
for (const [p, dir] of mod.replaces) {
|
|
20871
|
+
const r = sourceModules.find((m) => m.dir === dir);
|
|
20872
|
+
if (r) providers.push({ path: p, local: r, via: "replace" });
|
|
20873
|
+
}
|
|
20874
|
+
for (const [p, v] of mod.requires)
|
|
20875
|
+
providers.push({ path: p, local: null, via: "dependency", version: v });
|
|
20876
|
+
}
|
|
20877
|
+
const covers2 = (p) => path === p || path.startsWith(`${p}/`);
|
|
20878
|
+
const best = providers.filter((p) => covers2(p.path)).sort((a, b) => b.path.length - a.path.length)[0];
|
|
20879
|
+
if (best?.local) {
|
|
20880
|
+
const rest = path.slice(best.path.length).replace(/^\//, "");
|
|
20881
|
+
const dir = [best.local.dir, rest].filter(Boolean).join("/");
|
|
20882
|
+
const files = importable(source, dir, best.local);
|
|
20883
|
+
const said = best.via === "module" ? `${path} is in this file's module ${best.path} (${best.local.dir || "the source root"})` : best.via === "workspace" ? `${path} is in ${best.path}, a module the go.work uses (${best.local.dir})` : `${path} is in ${best.path}, which go.mod replaces with ${best.local.dir}`;
|
|
20884
|
+
if (!files.length)
|
|
20885
|
+
return {
|
|
20886
|
+
kind: "broken",
|
|
20887
|
+
reason: "file-not-found",
|
|
20888
|
+
steps: [step(best.via, said), step("not-found", `no Go package in ${dir || "the source root"}`)]
|
|
20889
|
+
};
|
|
20890
|
+
return {
|
|
20891
|
+
kind: "package",
|
|
20892
|
+
key: keyOf2(files[0]),
|
|
20893
|
+
files,
|
|
20894
|
+
name: files[0].pkg,
|
|
20895
|
+
via: best.via,
|
|
20896
|
+
steps: [
|
|
20897
|
+
step(best.via, said),
|
|
20898
|
+
step("package", `the package ${files[0].pkg} in ${dir || "the source root"}`)
|
|
20899
|
+
]
|
|
20900
|
+
};
|
|
20901
|
+
}
|
|
20902
|
+
if (best)
|
|
20903
|
+
return {
|
|
20904
|
+
kind: "external",
|
|
20905
|
+
pkg: external(source, "golang", best.path, best.version ?? null),
|
|
20906
|
+
via: "dependency",
|
|
20907
|
+
steps: [
|
|
20908
|
+
step(
|
|
20909
|
+
"dependency",
|
|
20910
|
+
`${path} is in ${best.path} ${best.version ?? ""}, which go.mod requires`.trim()
|
|
20911
|
+
)
|
|
20912
|
+
]
|
|
20913
|
+
};
|
|
20914
|
+
if (!path.split("/")[0].includes("."))
|
|
20915
|
+
return {
|
|
20916
|
+
kind: "external",
|
|
20917
|
+
pkg: external(source, "go", path, null),
|
|
20918
|
+
via: "stdlib",
|
|
20919
|
+
steps: [step("stdlib", `${path} is in Go's standard library`)]
|
|
20920
|
+
};
|
|
20921
|
+
return {
|
|
20922
|
+
kind: "broken",
|
|
20923
|
+
reason: "unknown-package",
|
|
20924
|
+
steps: [step("not-found", `no module of the project provides ${path}, and go.mod doesn't require it`)]
|
|
20925
|
+
};
|
|
20926
|
+
};
|
|
20927
|
+
const resolved = [];
|
|
20928
|
+
const packageImports = [];
|
|
20929
|
+
const importsOf = /* @__PURE__ */ new Map();
|
|
20930
|
+
for (const f of goFiles.values()) {
|
|
20931
|
+
const list = [];
|
|
20932
|
+
for (const s of statements(f.node.source, f.node.path, f.result)) {
|
|
20933
|
+
const target2 = resolvePath2(f, s.specifier);
|
|
20934
|
+
const local = s.bindings[0]?.[1] ?? null;
|
|
20935
|
+
list.push({ path: s.specifier, target: target2, local });
|
|
20936
|
+
if (target2.kind === "package") packageImports.push({ statement: s, target: target2, importer: f.node.id });
|
|
20937
|
+
else if (target2.kind === "external")
|
|
20938
|
+
resolved.push({
|
|
20939
|
+
statement: s,
|
|
20940
|
+
target: { kind: "package", pkg: target2.pkg, via: target2.via, steps: target2.steps }
|
|
20941
|
+
});
|
|
20942
|
+
else
|
|
20943
|
+
resolved.push({
|
|
20944
|
+
statement: s,
|
|
20945
|
+
target: { kind: "unresolved", outcome: "broken", reason: target2.reason, steps: target2.steps }
|
|
20946
|
+
});
|
|
20947
|
+
}
|
|
20948
|
+
importsOf.set(f.node.id, list);
|
|
20949
|
+
}
|
|
20950
|
+
const importByPath = (f, path) => importsOf.get(f.node.id)?.find((i) => i.path === path);
|
|
20951
|
+
const importByName = (f, name) => {
|
|
20952
|
+
for (const i of importsOf.get(f.node.id) ?? []) {
|
|
20953
|
+
if (i.local === null || i.local === ".") continue;
|
|
20954
|
+
const unaliased = i.local === assumedName(i.path);
|
|
20955
|
+
const bound = unaliased && i.target.kind === "package" ? i.target.name : i.local;
|
|
20956
|
+
if (bound === name) return i;
|
|
20957
|
+
}
|
|
20958
|
+
return void 0;
|
|
20959
|
+
};
|
|
20960
|
+
const fnsOf = /* @__PURE__ */ new Map();
|
|
20961
|
+
for (const fn of input2.functions) {
|
|
20962
|
+
if (!goFiles.has(fn.file)) continue;
|
|
20963
|
+
const ok = fn.qualifiedName.includes(".") ? fn.kind === "method" : fn.kind === "function" || fn.kind === "arrow";
|
|
20964
|
+
if (!ok) continue;
|
|
20965
|
+
let byName = fnsOf.get(fn.file);
|
|
20966
|
+
if (!byName) fnsOf.set(fn.file, byName = /* @__PURE__ */ new Map());
|
|
20967
|
+
byName.set(fn.qualifiedName, [...byName.get(fn.qualifiedName) ?? [], fn]);
|
|
20968
|
+
}
|
|
20969
|
+
const declared2 = (files, name) => files.flatMap((g) => fnsOf.get(g.node.id)?.get(name) ?? []);
|
|
20970
|
+
const filesKey = (files) => `${files[0]?.node.id ?? ""}\0${files.length}\0${files.at(-1)?.node.id ?? ""}`;
|
|
20971
|
+
const typeDecl = (files, name) => {
|
|
20972
|
+
for (const g of files) {
|
|
20973
|
+
const decl = g.result.types.find((t) => t.name === name);
|
|
20974
|
+
if (decl) return { decl, file: g };
|
|
20975
|
+
}
|
|
20976
|
+
return null;
|
|
20977
|
+
};
|
|
20978
|
+
const varsCache = /* @__PURE__ */ new Map();
|
|
20979
|
+
const varsOf = (g) => {
|
|
20980
|
+
let v = varsCache.get(g.node.id);
|
|
20981
|
+
if (!v) varsCache.set(g.node.id, v = packageVars(text.get(g.node.id) ?? ""));
|
|
20982
|
+
return v;
|
|
20983
|
+
};
|
|
20984
|
+
const packageVar = (files, name) => {
|
|
20985
|
+
for (const g of files) {
|
|
20986
|
+
const v = varsOf(g).get(name);
|
|
20987
|
+
if (v) return { ...v, file: g };
|
|
20988
|
+
}
|
|
20989
|
+
return null;
|
|
20990
|
+
};
|
|
20991
|
+
const varFunction = (files, name) => packageVar(files, name)?.value ?? null;
|
|
20992
|
+
const typeIn = (f, written2) => {
|
|
20993
|
+
const w = written2.replace(/^\*+/, "").replace(/\[.*\]$/, "").trim();
|
|
20994
|
+
const q = /^([A-Za-z_]\w*)\.([A-Za-z_]\w*)$/.exec(w);
|
|
20995
|
+
if (q) {
|
|
20996
|
+
const imp = importByName(f, q[1]);
|
|
20997
|
+
if (!imp) return { kind: "none" };
|
|
20998
|
+
if (imp.target.kind === "package")
|
|
20999
|
+
return { kind: "local", files: imp.target.files, key: imp.target.key, name: q[2] };
|
|
21000
|
+
if (imp.target.kind === "external") return { kind: "external", pkg: imp.target.pkg };
|
|
21001
|
+
return { kind: "broken", reason: imp.target.reason };
|
|
21002
|
+
}
|
|
21003
|
+
if (GO_BUILTIN_TYPES.has(w)) return { kind: "builtin", name: w };
|
|
21004
|
+
if (/^[A-Za-z_]\w*$/.test(w)) return { kind: "local", files: packageOf(f), key: keyOf2(f), name: w };
|
|
21005
|
+
return { kind: "none" };
|
|
21006
|
+
};
|
|
21007
|
+
const packageOf = (f) => visible(f);
|
|
21008
|
+
const methodCache = /* @__PURE__ */ new Map();
|
|
21009
|
+
const methodOf = (t, m) => {
|
|
21010
|
+
const key = `${filesKey(t.files)}\0${t.name}\0${m}`;
|
|
21011
|
+
let hit = methodCache.get(key);
|
|
21012
|
+
if (!hit) methodCache.set(key, hit = methodUncached(t, m));
|
|
21013
|
+
return hit;
|
|
21014
|
+
};
|
|
21015
|
+
const methodUncached = (t, m) => {
|
|
21016
|
+
const own2 = declared2(t.files, `${t.name}.${m}`);
|
|
21017
|
+
if (own2.length) return { kind: "fns", fns: own2, promoted: false };
|
|
21018
|
+
const d = typeDecl(t.files, t.name);
|
|
21019
|
+
if (!d) return { kind: "none", why: `${t.name} is not a type of its package` };
|
|
21020
|
+
if (d.decl.kind === "interface") return { kind: "interface", files: t.files, name: t.name };
|
|
21021
|
+
if (d.decl.members.some((x) => x.name === m && x.kind === "other"))
|
|
21022
|
+
return {
|
|
21023
|
+
kind: "none",
|
|
21024
|
+
why: `${m} is a field of ${t.name} holding a function: its value isn't followed`,
|
|
21025
|
+
field: true
|
|
21026
|
+
};
|
|
21027
|
+
let level = d.decl.bases.map((b) => ({ ref: typeIn(d.file, b.name) }));
|
|
21028
|
+
const seen = /* @__PURE__ */ new Set([`${d.file.dir}\0${t.name}`]);
|
|
21029
|
+
let externalAbove = null;
|
|
21030
|
+
for (let depth = 0; depth < 8 && level.length; depth++) {
|
|
21031
|
+
const found = [];
|
|
21032
|
+
const next = [];
|
|
21033
|
+
let external2 = null;
|
|
21034
|
+
for (const { ref } of level) {
|
|
21035
|
+
if (ref.kind === "external") {
|
|
21036
|
+
external2 ??= ref.pkg;
|
|
21037
|
+
continue;
|
|
21038
|
+
}
|
|
21039
|
+
if (ref.kind !== "local") continue;
|
|
21040
|
+
const k = `${ref.key}\0${ref.name}`;
|
|
21041
|
+
if (seen.has(k)) continue;
|
|
21042
|
+
seen.add(k);
|
|
21043
|
+
const fns = declared2(ref.files, `${ref.name}.${m}`);
|
|
21044
|
+
if (fns.length) {
|
|
21045
|
+
found.push({ kind: "fns", fns, promoted: true });
|
|
21046
|
+
continue;
|
|
21047
|
+
}
|
|
21048
|
+
const e = typeDecl(ref.files, ref.name);
|
|
21049
|
+
if (!e) continue;
|
|
21050
|
+
if (e.decl.kind === "interface") {
|
|
21051
|
+
if (interfaceMethods(ref.files, ref.name).has(m))
|
|
21052
|
+
found.push({ kind: "interface", files: ref.files, name: ref.name });
|
|
21053
|
+
continue;
|
|
21054
|
+
}
|
|
21055
|
+
next.push(...e.decl.bases.map((b) => ({ ref: typeIn(e.file, b.name) })));
|
|
21056
|
+
}
|
|
21057
|
+
if (found.length === 1)
|
|
21058
|
+
return externalAbove ? {
|
|
21059
|
+
kind: "none",
|
|
21060
|
+
why: `${m} may be ${externalAbove.name}'s, embedded above, or an embedded type's of the project`
|
|
21061
|
+
} : found[0];
|
|
21062
|
+
if (found.length > 1)
|
|
21063
|
+
return { kind: "none", why: `${m} is promoted from several embedded types at the same depth` };
|
|
21064
|
+
externalAbove ??= external2;
|
|
21065
|
+
level = next;
|
|
21066
|
+
}
|
|
21067
|
+
if (externalAbove) return { kind: "external", pkg: externalAbove };
|
|
21068
|
+
return { kind: "none", why: `${t.name} has no method ${m}` };
|
|
21069
|
+
};
|
|
21070
|
+
const ifaceCache = /* @__PURE__ */ new Map();
|
|
21071
|
+
const interfaceMethods = (files, name, depth = 0) => {
|
|
21072
|
+
const key = `${files[0]?.node.id ?? ""}\0${name}`;
|
|
21073
|
+
const hit = ifaceCache.get(key);
|
|
21074
|
+
if (hit) return hit;
|
|
21075
|
+
const out = /* @__PURE__ */ new Set();
|
|
21076
|
+
const d = typeDecl(files, name);
|
|
21077
|
+
if (d && d.decl.kind === "interface" && depth < 8) {
|
|
21078
|
+
for (const mem of d.decl.members) out.add(mem.name);
|
|
21079
|
+
for (const b of d.decl.bases) {
|
|
21080
|
+
const ref = typeIn(d.file, b.name);
|
|
21081
|
+
if (ref.kind === "local")
|
|
21082
|
+
for (const x of interfaceMethods(ref.files, ref.name, depth + 1)) out.add(x);
|
|
21083
|
+
}
|
|
21084
|
+
}
|
|
21085
|
+
ifaceCache.set(key, out);
|
|
21086
|
+
return out;
|
|
21087
|
+
};
|
|
21088
|
+
const allTypes = [];
|
|
21089
|
+
for (const list of packages.values()) {
|
|
21090
|
+
const names = /* @__PURE__ */ new Set();
|
|
21091
|
+
for (const g of list) for (const t of g.result.types) if (t.kind === "class") names.add(t.name);
|
|
21092
|
+
const nonTest = list.filter((g) => !g.test);
|
|
21093
|
+
for (const name of [...names].sort()) allTypes.push({ files: nonTest.length ? nonTest : list, name });
|
|
21094
|
+
}
|
|
21095
|
+
const satisfyCache = /* @__PURE__ */ new Map();
|
|
21096
|
+
const satisfying = (files, iface, m) => {
|
|
21097
|
+
const key = `${filesKey(files)}\0${iface}\0${m}`;
|
|
21098
|
+
let hit = satisfyCache.get(key);
|
|
21099
|
+
if (!hit) satisfyCache.set(key, hit = satisfyingUncached(files, iface, m));
|
|
21100
|
+
return hit;
|
|
21101
|
+
};
|
|
21102
|
+
const satisfyingUncached = (files, iface, m) => {
|
|
21103
|
+
const need = interfaceMethods(files, iface);
|
|
21104
|
+
if (!need.size || !need.has(m)) return [];
|
|
21105
|
+
const out = [];
|
|
21106
|
+
for (const t of allTypes) {
|
|
21107
|
+
let ok = true;
|
|
21108
|
+
let target2 = [];
|
|
21109
|
+
for (const n2 of need) {
|
|
21110
|
+
const found = methodOf(t, n2);
|
|
21111
|
+
if (found.kind !== "fns") {
|
|
21112
|
+
ok = false;
|
|
21113
|
+
break;
|
|
21114
|
+
}
|
|
21115
|
+
if (n2 === m) target2 = found.fns;
|
|
21116
|
+
}
|
|
21117
|
+
if (ok) out.push(...target2);
|
|
21118
|
+
}
|
|
21119
|
+
const uniq = [...new Map(out.map((f) => [f.id, f])).values()];
|
|
21120
|
+
return uniq.sort(
|
|
21121
|
+
(a, b) => cmp10(fileOf(a.file), fileOf(b.file)) || a.evidence.span.start.offset - b.evidence.span.start.offset
|
|
21122
|
+
);
|
|
21123
|
+
};
|
|
21124
|
+
const fileOf = (id) => id.slice(id.indexOf(":") + 1);
|
|
21125
|
+
const rawByFile = /* @__PURE__ */ new Map();
|
|
21126
|
+
const resultsSite = (site) => {
|
|
21127
|
+
let m = rawByFile.get(site.file);
|
|
21128
|
+
if (!m) {
|
|
21129
|
+
m = new Map(
|
|
21130
|
+
(goFiles.get(site.file)?.result.unresolved ?? []).map((u) => [
|
|
21131
|
+
`${u.site.start.offset}\0${u.expression}`,
|
|
21132
|
+
u
|
|
21133
|
+
])
|
|
21134
|
+
);
|
|
21135
|
+
rawByFile.set(site.file, m);
|
|
21136
|
+
}
|
|
21137
|
+
return m.get(`${site.evidence.span.start.offset}\0${site.expression}`);
|
|
21138
|
+
};
|
|
21139
|
+
const evidence = (file2, span) => ({
|
|
21140
|
+
file: file2,
|
|
21141
|
+
span,
|
|
21142
|
+
commit: input2.revisions.get(file2.slice(0, file2.indexOf(":"))) ?? ""
|
|
21143
|
+
});
|
|
21144
|
+
const variantBasis = (fn) => {
|
|
21145
|
+
const g = goFiles.get(fn.file);
|
|
21146
|
+
return g?.build && !g.suffixed ? evidence(fn.file, g.build.span) : fn.evidence;
|
|
21147
|
+
};
|
|
21148
|
+
const onType = (t, m, via, said) => {
|
|
21149
|
+
if (t.kind === "external")
|
|
21150
|
+
return { kind: "external", pkg: t.pkg, steps: [step("external", `${said}, a type of ${t.pkg.name}`)] };
|
|
21151
|
+
if (t.kind === "broken")
|
|
21152
|
+
return {
|
|
21153
|
+
kind: "broken",
|
|
21154
|
+
reason: t.reason,
|
|
21155
|
+
steps: [step("not-found", `${said}: its import is broken`)]
|
|
21156
|
+
};
|
|
21157
|
+
if (t.kind === "builtin")
|
|
21158
|
+
return { kind: "runtime", steps: [step("runtime", `${said}: a method of Go's built-in ${t.name}`)] };
|
|
21159
|
+
if (t.kind === "none")
|
|
21160
|
+
return { kind: "open", steps: [step("untyped", `${said}: not a named type Stage 2 follows`)] };
|
|
21161
|
+
const found = methodOf(t, m);
|
|
21162
|
+
switch (found.kind) {
|
|
21163
|
+
case "fns":
|
|
21164
|
+
return found.fns.length > 1 ? {
|
|
21165
|
+
kind: "fns",
|
|
21166
|
+
fns: found.fns,
|
|
21167
|
+
via,
|
|
21168
|
+
steps: [step("variants", `${t.name}.${m} has a body per build variant`)],
|
|
21169
|
+
variants: true
|
|
21170
|
+
} : {
|
|
21171
|
+
kind: "fns",
|
|
21172
|
+
fns: found.fns,
|
|
21173
|
+
via: found.promoted ? "inherited" : via,
|
|
21174
|
+
steps: [
|
|
21175
|
+
step(
|
|
21176
|
+
found.promoted ? "promoted" : "method",
|
|
21177
|
+
found.promoted ? `${m} is promoted to ${t.name} from an embedded field` : `${said}: ${t.name}.${m}`
|
|
21178
|
+
)
|
|
21179
|
+
]
|
|
21180
|
+
};
|
|
21181
|
+
case "interface": {
|
|
21182
|
+
const fns = satisfying(found.files, found.name, m);
|
|
21183
|
+
return fns.length ? {
|
|
21184
|
+
kind: "candidates",
|
|
21185
|
+
fns,
|
|
21186
|
+
steps: [
|
|
21187
|
+
step(
|
|
21188
|
+
"interface",
|
|
21189
|
+
`${found.name} is an interface: every type of the project that satisfies it`
|
|
21190
|
+
)
|
|
21191
|
+
]
|
|
21192
|
+
} : { kind: "open", steps: [step("interface", `no type of the project satisfies ${found.name}`)] };
|
|
21193
|
+
}
|
|
21194
|
+
case "external":
|
|
21195
|
+
return {
|
|
21196
|
+
kind: "external",
|
|
21197
|
+
pkg: found.pkg,
|
|
21198
|
+
steps: [step("external", `${m} is promoted from ${found.pkg.name}`)]
|
|
21199
|
+
};
|
|
21200
|
+
default:
|
|
21201
|
+
return { kind: "open", steps: [step(found.field ? "field" : "not-found", found.why)] };
|
|
21202
|
+
}
|
|
21203
|
+
};
|
|
21204
|
+
const fieldOf = (t, field) => {
|
|
21205
|
+
let level = [t];
|
|
21206
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21207
|
+
for (let depth = 0; depth < 8 && level.length; depth++) {
|
|
21208
|
+
const found = [];
|
|
21209
|
+
const next = [];
|
|
21210
|
+
for (const ref of level) {
|
|
21211
|
+
if (ref.kind !== "local") continue;
|
|
21212
|
+
const k = `${ref.key}\0${ref.name}`;
|
|
21213
|
+
if (seen.has(k)) continue;
|
|
21214
|
+
seen.add(k);
|
|
21215
|
+
const d = typeDecl(ref.files, ref.name);
|
|
21216
|
+
if (!d) continue;
|
|
21217
|
+
const mem = d.decl.members.find((x) => x.name === field && x.valueType);
|
|
21218
|
+
const base2 = d.decl.bases.find((b) => b.name.replace(/^.*\./, "") === field);
|
|
21219
|
+
if (mem?.valueType) found.push(typeIn(d.file, mem.valueType));
|
|
21220
|
+
else if (base2) found.push(typeIn(d.file, base2.name));
|
|
21221
|
+
else next.push(...d.decl.bases.map((b) => typeIn(d.file, b.name)));
|
|
21222
|
+
}
|
|
21223
|
+
if (found.length === 1) return found[0];
|
|
21224
|
+
if (found.length > 1) return { kind: "none" };
|
|
21225
|
+
level = next;
|
|
21226
|
+
}
|
|
21227
|
+
return { kind: "none" };
|
|
21228
|
+
};
|
|
21229
|
+
const throughFields = (t, fields) => {
|
|
21230
|
+
let cur = t;
|
|
21231
|
+
for (const field of fields) {
|
|
21232
|
+
if (cur.kind !== "local") return cur;
|
|
21233
|
+
cur = fieldOf(cur, field);
|
|
21234
|
+
}
|
|
21235
|
+
return cur;
|
|
21236
|
+
};
|
|
21237
|
+
const resultOf2 = (fn) => {
|
|
21238
|
+
const g = goFiles.get(fn.file);
|
|
21239
|
+
const def = g?.result.definitions.find((d) => d.qualifiedName === fn.qualifiedName);
|
|
21240
|
+
return g && def?.returns ? typeIn(g, def.returns) : { kind: "none" };
|
|
21241
|
+
};
|
|
21242
|
+
const named = (files, name, via, said) => {
|
|
21243
|
+
const fns = declared2(files, name);
|
|
21244
|
+
if (fns.length > 1)
|
|
21245
|
+
return {
|
|
21246
|
+
kind: "fns",
|
|
21247
|
+
fns,
|
|
21248
|
+
via,
|
|
21249
|
+
variants: true,
|
|
21250
|
+
steps: [step("variants", `${name} has a body per build variant`)]
|
|
21251
|
+
};
|
|
21252
|
+
if (fns.length === 1) return { kind: "fns", fns, via, steps: [step(via ?? "package", said)] };
|
|
21253
|
+
const value = varFunction(files, name);
|
|
21254
|
+
if (value) {
|
|
21255
|
+
const target2 = declared2(files, value);
|
|
21256
|
+
if (target2.length === 1)
|
|
21257
|
+
return {
|
|
21258
|
+
kind: "fns",
|
|
21259
|
+
fns: target2,
|
|
21260
|
+
via: "flow",
|
|
21261
|
+
steps: [step("flow", `${name} is a variable holding ${value}`)]
|
|
21262
|
+
};
|
|
21263
|
+
}
|
|
21264
|
+
if (typeDecl(files, name))
|
|
21265
|
+
return {
|
|
21266
|
+
kind: "open",
|
|
21267
|
+
steps: [step("not-a-function", `${name} is a type: ${name}(\u2026) converts to it, calling nothing`)]
|
|
21268
|
+
};
|
|
21269
|
+
return null;
|
|
21270
|
+
};
|
|
21271
|
+
const outcome = (site, raw, f) => {
|
|
21272
|
+
if (site.reason === "dynamic-dispatch") {
|
|
21273
|
+
if (raw.table) {
|
|
21274
|
+
const t = f.result.tables.find((x) => x.name === raw.table);
|
|
21275
|
+
const entries = (t?.entries ?? []).flatMap((e) => {
|
|
21276
|
+
const fn = e.function ? declared2([f], e.function)[0] : void 0;
|
|
21277
|
+
return fn ? [{ fn, basis: evidence(f.node.id, e.span) }] : [];
|
|
21278
|
+
});
|
|
21279
|
+
return entries.length ? {
|
|
21280
|
+
kind: "candidates",
|
|
21281
|
+
fns: entries.map((e) => e.fn),
|
|
21282
|
+
basis: entries.map((e) => e.basis),
|
|
21283
|
+
steps: [step("table", `${raw.table} is a map of functions; the call runs one of its values`)]
|
|
21284
|
+
} : null;
|
|
21285
|
+
}
|
|
21286
|
+
if (raw.receiverType && raw.member)
|
|
21287
|
+
return onType(
|
|
21288
|
+
typeIn(f, raw.receiverType),
|
|
21289
|
+
raw.member,
|
|
21290
|
+
// Another package's type (`helpers.Store`) is reached through its import.
|
|
21291
|
+
raw.receiverType.includes(".") ? "import" : "package",
|
|
21292
|
+
`${site.expression}'s receiver is a ${raw.receiverType}`
|
|
21293
|
+
);
|
|
21294
|
+
return null;
|
|
21295
|
+
}
|
|
21296
|
+
if (site.reason === "package-symbol") {
|
|
21297
|
+
const pkg = packageOf(f);
|
|
21298
|
+
if (raw.receiverType && raw.member) {
|
|
21299
|
+
const t = throughFields(typeIn(f, raw.receiverType), raw.through ?? []);
|
|
21300
|
+
return onType(
|
|
21301
|
+
t,
|
|
21302
|
+
raw.member,
|
|
21303
|
+
"package",
|
|
21304
|
+
`${site.expression} is on a ${raw.receiverType}${raw.through?.length ? `, through ${raw.through.join(".")}` : ""}`
|
|
21305
|
+
);
|
|
21306
|
+
}
|
|
21307
|
+
const name = raw.importedName;
|
|
21308
|
+
if (!name) return null;
|
|
21309
|
+
if (raw.member && raw.receiver === "returned") {
|
|
21310
|
+
const fns = declared2(pkg, name);
|
|
21311
|
+
if (fns.length !== 1)
|
|
21312
|
+
return { kind: "open", steps: [step("not-found", `${name} is not one function of the package`)] };
|
|
21313
|
+
return withVia(
|
|
21314
|
+
onType(
|
|
21315
|
+
throughFields(resultOf2(fns[0]), raw.through ?? []),
|
|
21316
|
+
raw.member,
|
|
21317
|
+
"returned",
|
|
21318
|
+
`${name} returns it`
|
|
21319
|
+
),
|
|
21320
|
+
"returned"
|
|
21321
|
+
);
|
|
21322
|
+
}
|
|
21323
|
+
if (raw.member) {
|
|
21324
|
+
const imp = importByName(f, name);
|
|
21325
|
+
if (imp) return throughImport(imp, raw.member, null, site);
|
|
21326
|
+
const v = packageVar(pkg, name);
|
|
21327
|
+
if (v?.written)
|
|
21328
|
+
return onType(typeIn(v.file, v.written), raw.member, "package", `${name} is a ${v.written}`);
|
|
21329
|
+
if (v)
|
|
21330
|
+
return {
|
|
21331
|
+
kind: "open",
|
|
21332
|
+
steps: [
|
|
21333
|
+
step(
|
|
21334
|
+
"untyped",
|
|
21335
|
+
`${name} is a package variable whose type isn't written: Stage 2 doesn't follow its value`
|
|
21336
|
+
)
|
|
21337
|
+
]
|
|
21338
|
+
};
|
|
21339
|
+
return { kind: "open", steps: [step("not-found", `${name} is not declared by the package`)] };
|
|
21340
|
+
}
|
|
21341
|
+
const own2 = named(pkg, name, "package", `${name} is declared by another file of the package`);
|
|
21342
|
+
if (own2) return own2;
|
|
21343
|
+
for (const imp of importsOf.get(f.node.id) ?? []) {
|
|
21344
|
+
if (imp.local !== "." || imp.target.kind !== "package") continue;
|
|
21345
|
+
const found = named(
|
|
21346
|
+
imp.target.files,
|
|
21347
|
+
name,
|
|
21348
|
+
"import",
|
|
21349
|
+
`${name} comes in with the dot import of ${imp.path}`
|
|
21350
|
+
);
|
|
21351
|
+
if (found) return found;
|
|
21352
|
+
}
|
|
21353
|
+
return { kind: "open", steps: [step("not-found", `no file of the package declares ${name}`)] };
|
|
21354
|
+
}
|
|
21355
|
+
if (site.reason === "imported-symbol" && raw.importSpecifier) {
|
|
21356
|
+
const imp = importByPath(f, raw.importSpecifier);
|
|
21357
|
+
if (!imp) return null;
|
|
21358
|
+
return throughImport(imp, raw.member ?? null, raw, site);
|
|
21359
|
+
}
|
|
21360
|
+
return null;
|
|
21361
|
+
};
|
|
21362
|
+
const withVia = (o, via) => o.kind === "fns" && !o.variants && o.via !== "inherited" ? { ...o, via } : o;
|
|
21363
|
+
const throughImport = (imp, member, raw, site) => {
|
|
21364
|
+
const head = step("import", `${site.expression} goes through the import of ${imp.path}`);
|
|
21365
|
+
const prefix = (o) => ({ ...o, steps: [head, ...o.steps] });
|
|
21366
|
+
if (imp.target.kind === "external")
|
|
21367
|
+
return prefix({ kind: "external", pkg: imp.target.pkg, steps: imp.target.steps });
|
|
21368
|
+
if (imp.target.kind === "broken")
|
|
21369
|
+
return prefix({ kind: "broken", reason: imp.target.reason, steps: imp.target.steps });
|
|
21370
|
+
const importer = goFiles.get(site.file);
|
|
21371
|
+
const files = importer?.test && importer.pkg.endsWith("_test") && imp.target.files[0]?.dir === importer.dir ? [...imp.target.files, ...(packages.get(imp.target.key) ?? []).filter((g) => g.test)] : imp.target.files;
|
|
21372
|
+
const key = imp.target.key;
|
|
21373
|
+
const name = raw?.importedName ?? null;
|
|
21374
|
+
if (!raw || !member || !raw.receiver) {
|
|
21375
|
+
const target2 = raw ? name : member;
|
|
21376
|
+
if (!target2) return prefix({ kind: "open", steps: [] });
|
|
21377
|
+
return prefix(
|
|
21378
|
+
named(files, target2, "import", `${target2} is declared by ${imp.path}`) ?? {
|
|
21379
|
+
kind: "open",
|
|
21380
|
+
steps: [step("not-found", `${imp.path} declares no function ${target2}`)]
|
|
21381
|
+
}
|
|
21382
|
+
);
|
|
21383
|
+
}
|
|
21384
|
+
if (raw.receiver === "returned") {
|
|
21385
|
+
const fns = declared2(files, name ?? "");
|
|
21386
|
+
if (fns.length !== 1)
|
|
21387
|
+
return prefix({
|
|
21388
|
+
kind: "open",
|
|
21389
|
+
steps: [step("not-found", `${imp.path} declares no function ${name}`)]
|
|
21390
|
+
});
|
|
21391
|
+
return prefix(
|
|
21392
|
+
withVia(
|
|
21393
|
+
onType(
|
|
21394
|
+
throughFields(resultOf2(fns[0]), raw.through ?? []),
|
|
21395
|
+
member,
|
|
21396
|
+
"returned",
|
|
21397
|
+
`${name} returns it`
|
|
21398
|
+
),
|
|
21399
|
+
"returned"
|
|
21400
|
+
)
|
|
21401
|
+
);
|
|
21402
|
+
}
|
|
21403
|
+
const t = throughFields({ kind: "local", files, key, name: name ?? "" }, raw.through ?? []);
|
|
21404
|
+
return prefix(onType(t, member, "import", `${site.expression} is on a ${name} of ${imp.path}`));
|
|
21405
|
+
};
|
|
21406
|
+
const resolutions = [];
|
|
21407
|
+
const edges = [];
|
|
21408
|
+
for (const site of input2.sites) {
|
|
21409
|
+
const f = goFiles.get(site.file);
|
|
21410
|
+
const raw = f ? resultsSite(site) : void 0;
|
|
21411
|
+
if (!f || !raw) continue;
|
|
21412
|
+
const o = outcome(site, raw, f);
|
|
21413
|
+
if (!o) continue;
|
|
21414
|
+
const base2 = {
|
|
21415
|
+
type: "SiteResolution",
|
|
21416
|
+
id: ids.resolution(site.id),
|
|
21417
|
+
site: site.id,
|
|
21418
|
+
file: site.file,
|
|
21419
|
+
evidence: site.evidence
|
|
21420
|
+
};
|
|
21421
|
+
if (o.kind === "fns" && o.fns.length === 1 && !o.variants) {
|
|
21422
|
+
const fn = o.fns[0];
|
|
21423
|
+
const via = o.via ?? "package";
|
|
21424
|
+
resolutions.push({
|
|
21425
|
+
...base2,
|
|
21426
|
+
status: "linked",
|
|
21427
|
+
target: fn.id,
|
|
21428
|
+
externalPackage: null,
|
|
21429
|
+
via,
|
|
21430
|
+
importOutcome: null,
|
|
21431
|
+
steps: o.steps
|
|
21432
|
+
});
|
|
21433
|
+
edges.push({
|
|
21434
|
+
type: "CALLS_CROSS_FILE",
|
|
21435
|
+
id: ids.linkedCall(site.id),
|
|
21436
|
+
from: site.enclosingFn,
|
|
21437
|
+
to: fn.id,
|
|
21438
|
+
form: "plain",
|
|
21439
|
+
resolution: "static-exact",
|
|
21440
|
+
confidence: 1,
|
|
21441
|
+
evidence: site.evidence,
|
|
21442
|
+
via: via === "returned" || via === "flow" ? via : via === "package" || via === "inherited" && site.reason === "package-symbol" ? "package" : "import"
|
|
21443
|
+
});
|
|
21444
|
+
} else if (o.kind === "fns" || o.kind === "candidates") {
|
|
21445
|
+
const variants = o.kind === "fns";
|
|
21446
|
+
resolutions.push({
|
|
21447
|
+
...base2,
|
|
21448
|
+
status: "unresolved",
|
|
21449
|
+
target: null,
|
|
21450
|
+
externalPackage: null,
|
|
21451
|
+
importOutcome: null,
|
|
21452
|
+
steps: o.steps,
|
|
21453
|
+
candidates: o.fns.map((fn, i) => ({
|
|
21454
|
+
function: fn.id,
|
|
21455
|
+
basis: variants ? variantBasis(fn) : (o.kind === "candidates" ? o.basis?.[i] : void 0) ?? fn.evidence
|
|
21456
|
+
})),
|
|
21457
|
+
...variants ? {} : { exhaustive: false }
|
|
21458
|
+
});
|
|
21459
|
+
} else if (o.kind === "runtime") {
|
|
21460
|
+
resolutions.push({
|
|
21461
|
+
...base2,
|
|
21462
|
+
status: "external",
|
|
21463
|
+
target: null,
|
|
21464
|
+
externalPackage: null,
|
|
21465
|
+
importOutcome: null,
|
|
21466
|
+
steps: o.steps
|
|
21467
|
+
});
|
|
21468
|
+
} else if (o.kind === "external") {
|
|
21469
|
+
resolutions.push({
|
|
21470
|
+
...base2,
|
|
21471
|
+
status: "external",
|
|
21472
|
+
target: null,
|
|
21473
|
+
externalPackage: o.pkg.id,
|
|
21474
|
+
importOutcome: null,
|
|
21475
|
+
steps: o.steps
|
|
21476
|
+
});
|
|
21477
|
+
} else if (o.kind === "broken") {
|
|
21478
|
+
resolutions.push({
|
|
21479
|
+
...base2,
|
|
21480
|
+
status: "unresolved",
|
|
21481
|
+
target: null,
|
|
21482
|
+
externalPackage: null,
|
|
21483
|
+
importOutcome: "broken",
|
|
21484
|
+
steps: o.steps
|
|
21485
|
+
});
|
|
21486
|
+
} else if (site.reason !== "dynamic-dispatch") {
|
|
21487
|
+
resolutions.push({
|
|
21488
|
+
...base2,
|
|
21489
|
+
status: "unresolved",
|
|
21490
|
+
target: null,
|
|
21491
|
+
externalPackage: null,
|
|
21492
|
+
importOutcome: null,
|
|
21493
|
+
steps: o.steps
|
|
21494
|
+
});
|
|
21495
|
+
}
|
|
21496
|
+
}
|
|
21497
|
+
const fnFile = new Map(input2.functions.map((fn) => [fn.id, fn.file]));
|
|
21498
|
+
const reached = /* @__PURE__ */ new Map();
|
|
21499
|
+
for (const r of resolutions) {
|
|
21500
|
+
const to = [r.target, ...(r.candidates ?? []).map((c) => c.function)].flatMap((id) => {
|
|
21501
|
+
const file2 = id ? fnFile.get(id) : void 0;
|
|
21502
|
+
return file2 ? [file2] : [];
|
|
21503
|
+
});
|
|
21504
|
+
if (!to.length) continue;
|
|
21505
|
+
let set2 = reached.get(r.file);
|
|
21506
|
+
if (!set2) reached.set(r.file, set2 = /* @__PURE__ */ new Set());
|
|
21507
|
+
for (const t of to) set2.add(t);
|
|
21508
|
+
}
|
|
21509
|
+
for (const { statement, target: target2, importer } of packageImports) {
|
|
21510
|
+
const from = goFiles.get(importer);
|
|
21511
|
+
const reachable = from?.test && from.pkg.endsWith("_test") && target2.files[0]?.dir === from.dir ? [...target2.files, ...(packages.get(target2.key) ?? []).filter((g) => g.test)] : target2.files;
|
|
21512
|
+
const used = reachable.filter((t) => reached.get(importer)?.has(t.node.id));
|
|
21513
|
+
for (const t of used.length ? used : target2.files)
|
|
21514
|
+
resolved.push({
|
|
21515
|
+
statement,
|
|
21516
|
+
target: { kind: "file", file: t.node, via: target2.via, steps: target2.steps, part: t.node.path }
|
|
21517
|
+
});
|
|
21518
|
+
}
|
|
21519
|
+
return { resolved, resolutions, edges };
|
|
21520
|
+
}
|
|
21521
|
+
function cmp10(a, b) {
|
|
21522
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
21523
|
+
}
|
|
21524
|
+
var step, GO_BUILTIN_TYPES, GOOS, GOARCH;
|
|
21525
|
+
var init_go = __esm({
|
|
21526
|
+
"packages/stage2/src/go.ts"() {
|
|
21527
|
+
"use strict";
|
|
21528
|
+
init_src();
|
|
21529
|
+
init_src3();
|
|
21530
|
+
init_protocol();
|
|
21531
|
+
init_imports();
|
|
21532
|
+
step = (kind, detail) => ({ kind, detail });
|
|
21533
|
+
GO_BUILTIN_TYPES = new Set(
|
|
21534
|
+
"any bool byte comparable complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8 uint16 uint32 uint64 uintptr".split(
|
|
21535
|
+
" "
|
|
21536
|
+
)
|
|
21537
|
+
);
|
|
21538
|
+
GOOS = "aix android darwin dragonfly freebsd hurd illumos ios js linux nacl netbsd openbsd plan9 solaris wasip1 windows zos".split(
|
|
21539
|
+
" "
|
|
21540
|
+
);
|
|
21541
|
+
GOARCH = "386 amd64 arm arm64 loong64 mips mips64 mips64le mipsle ppc64 ppc64le riscv64 s390x sparc64 wasm".split(
|
|
21542
|
+
" "
|
|
21543
|
+
);
|
|
21544
|
+
}
|
|
21545
|
+
});
|
|
21546
|
+
|
|
21547
|
+
// packages/stage2/src/groups.ts
|
|
21548
|
+
import { posix as posix10 } from "node:path";
|
|
20480
21549
|
function groups(input2) {
|
|
20481
21550
|
const threshold = input2.clusterThreshold ?? DEFAULT_CLUSTER_THRESHOLD;
|
|
20482
21551
|
const fnFile = new Map(input2.functions.map((f) => [f.id, f.file]));
|
|
@@ -20488,25 +21557,34 @@ function groups(input2) {
|
|
|
20488
21557
|
const rootName = manifests.get("package.json")?.name;
|
|
20489
21558
|
const packages = [];
|
|
20490
21559
|
for (const [path, json2] of manifests) {
|
|
20491
|
-
if (
|
|
20492
|
-
const dir =
|
|
21560
|
+
if (posix10.basename(path) !== "package.json" || path === "package.json") continue;
|
|
21561
|
+
const dir = posix10.dirname(path);
|
|
20493
21562
|
const name = json2?.name;
|
|
20494
21563
|
if (typeof name === "string" && name && members2(dir)) packages.push({ dir, name });
|
|
20495
21564
|
}
|
|
20496
21565
|
const holds = (dir) => input2.files.some((f) => f.source === plan.sourceId && f.path.startsWith(`${dir}/`));
|
|
20497
21566
|
if (manifests.has("nx.json"))
|
|
20498
21567
|
for (const [path, json2] of manifests) {
|
|
20499
|
-
if (
|
|
20500
|
-
const dir =
|
|
21568
|
+
if (posix10.basename(path) !== "project.json" || path === "project.json") continue;
|
|
21569
|
+
const dir = posix10.dirname(path);
|
|
20501
21570
|
if (packages.some((p) => p.dir === dir) || !holds(dir)) continue;
|
|
20502
21571
|
const name = json2?.name;
|
|
20503
|
-
packages.push({ dir, name: typeof name === "string" && name ? name :
|
|
21572
|
+
packages.push({ dir, name: typeof name === "string" && name ? name : posix10.basename(dir) });
|
|
20504
21573
|
}
|
|
20505
|
-
|
|
21574
|
+
let goRoot = null;
|
|
21575
|
+
for (const m of plan.manifests) {
|
|
21576
|
+
if (posix10.basename(m.path) !== "go.mod" || goSkipsDir(m.path)) continue;
|
|
21577
|
+
const dir = posix10.dirname(m.path) === "." ? "" : posix10.dirname(m.path);
|
|
21578
|
+
const mod = parseGoMod(m.content, dir);
|
|
21579
|
+
if (!mod) continue;
|
|
21580
|
+
if (dir === "") goRoot = mod.path;
|
|
21581
|
+
else if (!packages.some((p) => p.dir === dir) && holds(dir)) packages.push({ dir, name: mod.path });
|
|
21582
|
+
}
|
|
21583
|
+
packages.sort((a, b) => b.dir.length - a.dir.length || cmp11(a.dir, b.dir));
|
|
20506
21584
|
const named = /* @__PURE__ */ new Map();
|
|
20507
21585
|
for (const p of packages) named.set(p.name, (named.get(p.name) ?? 0) + 1);
|
|
20508
21586
|
for (const p of packages) if (named.get(p.name) > 1) p.name = `${p.name} (${p.dir})`;
|
|
20509
|
-
const files = input2.files.filter((f) => f.source === plan.sourceId).sort((a, b) =>
|
|
21587
|
+
const files = input2.files.filter((f) => f.source === plan.sourceId).sort((a, b) => cmp11(a.path, b.path));
|
|
20510
21588
|
const boundaries = /* @__PURE__ */ new Map();
|
|
20511
21589
|
for (const f of files) {
|
|
20512
21590
|
const pkg = packages.find((p) => f.path.startsWith(`${p.dir}/`));
|
|
@@ -20515,7 +21593,7 @@ function groups(input2) {
|
|
|
20515
21593
|
if (!b) {
|
|
20516
21594
|
b = pkg ? { kind: "workspace-package", name: pkg.name, root: pkg.dir, files: [] } : {
|
|
20517
21595
|
kind: "repository",
|
|
20518
|
-
name: typeof rootName === "string" && rootName ? rootName : plan.sourceId,
|
|
21596
|
+
name: typeof rootName === "string" && rootName ? rootName : goRoot ?? plan.sourceId,
|
|
20519
21597
|
root: "",
|
|
20520
21598
|
files: []
|
|
20521
21599
|
};
|
|
@@ -20560,7 +21638,7 @@ function groups(input2) {
|
|
|
20560
21638
|
});
|
|
20561
21639
|
}
|
|
20562
21640
|
};
|
|
20563
|
-
for (const b of [...boundaries.values()].sort((x, y) =>
|
|
21641
|
+
for (const b of [...boundaries.values()].sort((x, y) => cmp11(x.root, y.root))) {
|
|
20564
21642
|
const units = b.kind === "repository" && packages.length === 0 ? folderUnits(b.files) : null;
|
|
20565
21643
|
const repo = { kind: "repository", name: b.name, root: b.root };
|
|
20566
21644
|
if (units) {
|
|
@@ -20633,7 +21711,7 @@ function folderUnits(files) {
|
|
|
20633
21711
|
list.push(f);
|
|
20634
21712
|
units.set(root, list);
|
|
20635
21713
|
}
|
|
20636
|
-
return [...units].map(([root, list]) => ({ root, files: list })).sort((a, b) =>
|
|
21714
|
+
return [...units].map(([root, list]) => ({ root, files: list })).sort((a, b) => cmp11(a.root, b.root));
|
|
20637
21715
|
}
|
|
20638
21716
|
function folderParts(files, root, threshold) {
|
|
20639
21717
|
if (files.length <= threshold) return [{ root, files }];
|
|
@@ -20650,7 +21728,7 @@ function folderParts(files, root, threshold) {
|
|
|
20650
21728
|
children.set(child, [...children.get(child) ?? [], f]);
|
|
20651
21729
|
}
|
|
20652
21730
|
}
|
|
20653
|
-
const large = [...children].filter(([, list]) => list.length >= min).sort(([a], [b]) =>
|
|
21731
|
+
const large = [...children].filter(([, list]) => list.length >= min).sort(([a], [b]) => cmp11(a, b));
|
|
20654
21732
|
if (large.length === 0) return [{ root, files, connect: true }];
|
|
20655
21733
|
const out = large.flatMap(([child, list]) => folderParts(list, child, threshold));
|
|
20656
21734
|
const big = new Set(large.map(([child]) => child));
|
|
@@ -20683,7 +21761,7 @@ function clusters(files, imports, calls, fnFile) {
|
|
|
20683
21761
|
});
|
|
20684
21762
|
let community = louvain(n2, edges);
|
|
20685
21763
|
const touched = new Set(edges.flatMap((e) => [e.a, e.b]));
|
|
20686
|
-
const dir = (i) =>
|
|
21764
|
+
const dir = (i) => posix10.dirname(files[i].path);
|
|
20687
21765
|
const folderCommunity = /* @__PURE__ */ new Map();
|
|
20688
21766
|
for (let i = 0; i < n2; i++)
|
|
20689
21767
|
if (touched.has(i) && !folderCommunity.has(dir(i))) folderCommunity.set(dir(i), community[i]);
|
|
@@ -20704,16 +21782,17 @@ function clusters(files, imports, calls, fnFile) {
|
|
|
20704
21782
|
});
|
|
20705
21783
|
return [...members2.values()].map(nameCluster).sort(byKey).map(disambiguate());
|
|
20706
21784
|
}
|
|
20707
|
-
var DEFAULT_CLUSTER_THRESHOLD,
|
|
21785
|
+
var DEFAULT_CLUSTER_THRESHOLD, cmp11;
|
|
20708
21786
|
var init_groups = __esm({
|
|
20709
21787
|
"packages/stage2/src/groups.ts"() {
|
|
20710
21788
|
"use strict";
|
|
20711
21789
|
init_src();
|
|
20712
21790
|
init_cluster();
|
|
21791
|
+
init_go();
|
|
20713
21792
|
init_imports();
|
|
20714
21793
|
init_cluster();
|
|
20715
21794
|
DEFAULT_CLUSTER_THRESHOLD = 200;
|
|
20716
|
-
|
|
21795
|
+
cmp11 = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
20717
21796
|
}
|
|
20718
21797
|
});
|
|
20719
21798
|
|
|
@@ -21150,7 +22229,7 @@ function makeLinker(input2, graph = typeGraph(input2)) {
|
|
|
21150
22229
|
kind: "no-import",
|
|
21151
22230
|
steps: [{ kind: "not-found", detail: `no import of ${u.importSpecifier} in this file` }]
|
|
21152
22231
|
};
|
|
21153
|
-
if (u.receiver && u.member) {
|
|
22232
|
+
if (u.receiver && u.receiver !== "returned" && u.member) {
|
|
21154
22233
|
const cls = u.importedName ?? "default";
|
|
21155
22234
|
const found2 = classMember(statement, cls, u.member, u.receiver);
|
|
21156
22235
|
return {
|
|
@@ -22533,6 +23612,1048 @@ var init_together = __esm({
|
|
|
22533
23612
|
}
|
|
22534
23613
|
});
|
|
22535
23614
|
|
|
23615
|
+
// packages/stage2/src/python.ts
|
|
23616
|
+
import { posix as posix11 } from "node:path";
|
|
23617
|
+
function pythonProject(plan, forPath) {
|
|
23618
|
+
const roots = /* @__PURE__ */ new Set();
|
|
23619
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
23620
|
+
const dep = (spec) => {
|
|
23621
|
+
if (/^\s*(git\+|hg\+|svn\+|bzr\+|https?:|file:|\.|\/)/.test(spec)) return;
|
|
23622
|
+
const name = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/.exec(spec)?.[1];
|
|
23623
|
+
if (name) dependencies.add(normalize(name));
|
|
23624
|
+
};
|
|
23625
|
+
for (const m of plan.manifests) {
|
|
23626
|
+
const base2 = posix11.basename(m.path);
|
|
23627
|
+
const dir = posix11.dirname(m.path) === "." ? "" : posix11.dirname(m.path);
|
|
23628
|
+
if (forPath !== void 0 && dir && !forPath.startsWith(`${dir}/`)) continue;
|
|
23629
|
+
const at = (p) => posix11.normalize(posix11.join(dir, p)).replace(/^\.\/?$/, "").replace(/\/$/, "");
|
|
23630
|
+
if (base2 === "pyproject.toml") {
|
|
23631
|
+
roots.add(dir);
|
|
23632
|
+
let section = "";
|
|
23633
|
+
let inArray = null;
|
|
23634
|
+
const add2 = (kind, value) => {
|
|
23635
|
+
if (kind === "deps") for (const s of quoted(value)) dep(s);
|
|
23636
|
+
else if (kind === "roots") for (const s of quoted(value)) roots.add(at(s));
|
|
23637
|
+
else if (kind === "poetry")
|
|
23638
|
+
for (const from of value.matchAll(/from\s*=\s*["']([^"']+)["']/g)) roots.add(at(from[1]));
|
|
23639
|
+
else if (kind === "hatch") for (const s of quoted(value)) roots.add(at(posix11.dirname(s)));
|
|
23640
|
+
};
|
|
23641
|
+
for (const raw of m.content.split("\n")) {
|
|
23642
|
+
const line = raw.replace(/\s+#.*$/, "").trim();
|
|
23643
|
+
if (!line) continue;
|
|
23644
|
+
const header2 = /^\[\[?([^\]]+)\]\]?$/.exec(line);
|
|
23645
|
+
if (header2) {
|
|
23646
|
+
section = header2[1].trim();
|
|
23647
|
+
inArray = null;
|
|
23648
|
+
continue;
|
|
23649
|
+
}
|
|
23650
|
+
if (inArray) {
|
|
23651
|
+
add2(inArray, line);
|
|
23652
|
+
if (closes(line)) inArray = null;
|
|
23653
|
+
continue;
|
|
23654
|
+
}
|
|
23655
|
+
const kv = /^([A-Za-z0-9_.-]+|"[^"]*")\s*=\s*(.*)$/.exec(line);
|
|
23656
|
+
if (!kv) continue;
|
|
23657
|
+
const key = kv[1].replace(/"/g, "");
|
|
23658
|
+
const value = kv[2];
|
|
23659
|
+
const list = (kind) => {
|
|
23660
|
+
add2(kind, value);
|
|
23661
|
+
if (value.startsWith("[") && !closes(value)) inArray = kind;
|
|
23662
|
+
};
|
|
23663
|
+
if (section === "project" && key === "dependencies") list("deps");
|
|
23664
|
+
else if (section === "project.optional-dependencies" || section === "dependency-groups") list("deps");
|
|
23665
|
+
else if (section === "tool.setuptools.packages.find" && key === "where") list("roots");
|
|
23666
|
+
else if (section === "tool.setuptools.package-dir" && key === "")
|
|
23667
|
+
roots.add(at(quoted(value)[0] ?? ""));
|
|
23668
|
+
else if (/^tool\.poetry(\.group\.[^.]+)?\.(dev-)?dependencies$/.test(section) && key !== "python")
|
|
23669
|
+
dependencies.add(normalize(key));
|
|
23670
|
+
else if (section === "tool.poetry" && key === "packages") list("poetry");
|
|
23671
|
+
else if (section === "tool.hatch.build.targets.wheel" && key === "packages") list("hatch");
|
|
23672
|
+
}
|
|
23673
|
+
} else if (base2 === "setup.cfg") {
|
|
23674
|
+
roots.add(dir);
|
|
23675
|
+
let section = "";
|
|
23676
|
+
let key = "";
|
|
23677
|
+
for (const raw of m.content.split("\n")) {
|
|
23678
|
+
const header2 = /^\s*\[([^\]]+)\]/.exec(raw);
|
|
23679
|
+
if (header2) {
|
|
23680
|
+
section = header2[1].trim();
|
|
23681
|
+
key = "";
|
|
23682
|
+
continue;
|
|
23683
|
+
}
|
|
23684
|
+
const kv = /^([A-Za-z0-9_.-]+)\s*=\s*(.*)$/.exec(raw);
|
|
23685
|
+
if (kv) {
|
|
23686
|
+
key = kv[1];
|
|
23687
|
+
if (section === "options" && key === "install_requires") dep(kv[2]);
|
|
23688
|
+
if (section === "options.packages.find" && key === "where" && kv[2].trim())
|
|
23689
|
+
roots.add(at(kv[2].trim()));
|
|
23690
|
+
if (section === "options" && key === "package_dir") {
|
|
23691
|
+
const d = /=\s*(\S+)/.exec(kv[2])?.[1];
|
|
23692
|
+
if (d) roots.add(at(d));
|
|
23693
|
+
}
|
|
23694
|
+
} else if (/^\s+\S/.test(raw) && section === "options" && key === "install_requires") dep(raw.trim());
|
|
23695
|
+
else if (/^\s+=\s*\S/.test(raw) && section === "options" && key === "package_dir")
|
|
23696
|
+
roots.add(at(raw.replace(/^\s+=\s*/, "").trim()));
|
|
23697
|
+
}
|
|
23698
|
+
} else if (base2 === "uv.lock" || base2 === "poetry.lock") {
|
|
23699
|
+
let name = null;
|
|
23700
|
+
let own2 = false;
|
|
23701
|
+
let table = "other";
|
|
23702
|
+
const flush = () => {
|
|
23703
|
+
if (name && !own2) dependencies.add(normalize(name));
|
|
23704
|
+
name = null;
|
|
23705
|
+
own2 = false;
|
|
23706
|
+
};
|
|
23707
|
+
for (const raw of m.content.split("\n")) {
|
|
23708
|
+
const line = raw.trim();
|
|
23709
|
+
if (line === "[[package]]") {
|
|
23710
|
+
flush();
|
|
23711
|
+
table = "package";
|
|
23712
|
+
} else if (line.startsWith("[")) table = line === "[package.source]" ? "source" : "other";
|
|
23713
|
+
else if (table === "package" && name === null && /^name\s*=/.test(line))
|
|
23714
|
+
name = /"([^"]+)"/.exec(line)?.[1] ?? null;
|
|
23715
|
+
else if (table === "package" && /^source\s*=\s*\{\s*(editable|virtual|directory)\s*=/.test(line))
|
|
23716
|
+
own2 = true;
|
|
23717
|
+
else if (table === "source" && /^type\s*=\s*"directory"/.test(line)) own2 = true;
|
|
23718
|
+
}
|
|
23719
|
+
flush();
|
|
23720
|
+
} else if (/^requirements[^/]*\.txt$/.test(base2)) {
|
|
23721
|
+
for (const raw of m.content.split("\n")) {
|
|
23722
|
+
const line = raw.replace(/(^|\s)#.*$/, "").trim();
|
|
23723
|
+
if (line && !line.startsWith("-")) dep(line);
|
|
23724
|
+
}
|
|
23725
|
+
}
|
|
23726
|
+
}
|
|
23727
|
+
roots.add("");
|
|
23728
|
+
return { roots: [...roots].sort((a, b) => b.length - a.length || (a < b ? -1 : 1)), dependencies };
|
|
23729
|
+
}
|
|
23730
|
+
function distribution(top, dependencies) {
|
|
23731
|
+
const plain2 = (d) => d.replace(/-/g, "");
|
|
23732
|
+
const n2 = normalize(top.replace(/^_+/, ""));
|
|
23733
|
+
for (const name of [normalize(DISTRIBUTIONS[top] ?? top), n2, `python-${n2}`])
|
|
23734
|
+
if (dependencies.has(name)) return name;
|
|
23735
|
+
return [...dependencies].find((d) => plain2(d) === plain2(n2)) ?? null;
|
|
23736
|
+
}
|
|
23737
|
+
function distributionByPrefix(top, dependencies) {
|
|
23738
|
+
const n2 = normalize(top);
|
|
23739
|
+
const found = [...dependencies].filter((d) => d.startsWith(`${n2}-`) || d === `${n2}io`).sort((a, b) => a.length - b.length || (a < b ? -1 : 1));
|
|
23740
|
+
return found[0] ?? null;
|
|
23741
|
+
}
|
|
23742
|
+
function moduleIndex(paths) {
|
|
23743
|
+
const files = new Set(paths.filter(isPython));
|
|
23744
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
23745
|
+
for (const p of files)
|
|
23746
|
+
for (let d = posix11.dirname(p); d !== "." && d !== ""; d = posix11.dirname(d)) dirs.add(d);
|
|
23747
|
+
return { files, dirs };
|
|
23748
|
+
}
|
|
23749
|
+
function moduleFile(index, path) {
|
|
23750
|
+
const init = path ? `${path}/__init__.py` : "__init__.py";
|
|
23751
|
+
if (index.files.has(init)) return init;
|
|
23752
|
+
if (path && index.files.has(`${path}.py`)) return `${path}.py`;
|
|
23753
|
+
if (path && index.files.has(`${path}.pyi`)) return `${path}.pyi`;
|
|
23754
|
+
return null;
|
|
23755
|
+
}
|
|
23756
|
+
function moduleVariables(text) {
|
|
23757
|
+
const vars = /* @__PURE__ */ new Map();
|
|
23758
|
+
const code = text.replace(/("""|''')[\s\S]*?\1/g, (m) => m.replace(/[^\n]/g, " "));
|
|
23759
|
+
const set2 = (name, cls) => vars.set(name, vars.has(name) ? "" : cls);
|
|
23760
|
+
let block = null;
|
|
23761
|
+
for (const line of code.split("\n")) {
|
|
23762
|
+
if (!line.trim() || line.trim().startsWith("#")) continue;
|
|
23763
|
+
const indent = /^\s*/.exec(line)[0].length;
|
|
23764
|
+
if (indent === 0) {
|
|
23765
|
+
block = /^(if|elif|else|try|except|finally|with|for|while)\b/.test(line) ? -1 : null;
|
|
23766
|
+
} else if (block === -1) block = indent;
|
|
23767
|
+
const top = indent === 0 || block !== null && block > 0 && indent === block;
|
|
23768
|
+
if (!top) continue;
|
|
23769
|
+
const chain = /^\s*((?:[A-Za-z_]\w*\s*=(?!=)\s*)+)(.*)$/.exec(line);
|
|
23770
|
+
const annotated = /^\s*([A-Za-z_]\w*)\s*:\s*([^=]+?)\s*=(?!=)\s*(.*)$/.exec(line);
|
|
23771
|
+
if (annotated) {
|
|
23772
|
+
const written2 = annotated[2].trim().replace(/^["']|["']$/g, "");
|
|
23773
|
+
set2(annotated[1], indent === 0 && /^[A-Za-z_][\w.]*$/.test(written2) ? written2 : "");
|
|
23774
|
+
} else if (chain) {
|
|
23775
|
+
const names = [...chain[1].matchAll(/([A-Za-z_]\w*)\s*=/g)].map((m) => m[1]);
|
|
23776
|
+
const made = /^([A-Za-z_][\w.]*)\s*\(/.exec(chain[2] ?? "")?.[1];
|
|
23777
|
+
const cls = indent === 0 && made && /^[A-Z]/.test(made.split(".").at(-1)) ? made : "";
|
|
23778
|
+
for (const n2 of names) set2(n2, cls);
|
|
23779
|
+
}
|
|
23780
|
+
}
|
|
23781
|
+
return vars;
|
|
23782
|
+
}
|
|
23783
|
+
function optionalImport(text, line) {
|
|
23784
|
+
const lines = text.split("\n");
|
|
23785
|
+
const indent = (s) => /^\s*/.exec(s)[0].length;
|
|
23786
|
+
let own2 = indent(lines[line - 1] ?? "");
|
|
23787
|
+
for (let i = line - 2; i >= 0 && own2 > 0; i--) {
|
|
23788
|
+
const l = lines[i];
|
|
23789
|
+
if (!l.trim() || l.trim().startsWith("#")) continue;
|
|
23790
|
+
if (indent(l) >= own2) continue;
|
|
23791
|
+
own2 = indent(l);
|
|
23792
|
+
if (/^\s*(def|class|async\s+def)\b/.test(l)) return false;
|
|
23793
|
+
if (!/^\s*try\s*:/.test(l)) continue;
|
|
23794
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
23795
|
+
const k = lines[j];
|
|
23796
|
+
if (!k.trim() || k.trim().startsWith("#")) continue;
|
|
23797
|
+
if (indent(k) < own2) break;
|
|
23798
|
+
if (indent(k) !== own2) continue;
|
|
23799
|
+
if (!/^\s*except\b/.test(k)) {
|
|
23800
|
+
if (/^\s*(else|finally)\s*:/.test(k)) continue;
|
|
23801
|
+
break;
|
|
23802
|
+
}
|
|
23803
|
+
if (/\b(ImportError|ModuleNotFoundError|Exception|BaseException)\b/.test(k) || /^\s*except\s*:/.test(k))
|
|
23804
|
+
return true;
|
|
23805
|
+
}
|
|
23806
|
+
}
|
|
23807
|
+
return false;
|
|
23808
|
+
}
|
|
23809
|
+
function pythonResults(plans) {
|
|
23810
|
+
const out = /* @__PURE__ */ new Map();
|
|
23811
|
+
for (const plan of plans) {
|
|
23812
|
+
const files = plan.files.filter((f) => f.language === "python" && f.content !== void 0 && !f.skip);
|
|
23813
|
+
if (!files.length) continue;
|
|
23814
|
+
const response = extract({
|
|
23815
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
23816
|
+
root: plan.root,
|
|
23817
|
+
manifests: [],
|
|
23818
|
+
files: files.map((f) => ({ path: f.path, language: f.language, content: f.content }))
|
|
23819
|
+
});
|
|
23820
|
+
for (const r of response.files) out.set(`${plan.sourceId}\0${r.path}`, r);
|
|
23821
|
+
}
|
|
23822
|
+
return out;
|
|
23823
|
+
}
|
|
23824
|
+
function resolvePythonImports(plans, files, results) {
|
|
23825
|
+
const resolved = [];
|
|
23826
|
+
const submodules = /* @__PURE__ */ new Set();
|
|
23827
|
+
const folders = /* @__PURE__ */ new Map();
|
|
23828
|
+
const packagesOf = /* @__PURE__ */ new Map();
|
|
23829
|
+
const packages = /* @__PURE__ */ new Map();
|
|
23830
|
+
const external = (source, ecosystem, name) => {
|
|
23831
|
+
const id = ids.externalPackage(source, ecosystem, name);
|
|
23832
|
+
let pkg = packages.get(id);
|
|
23833
|
+
if (!pkg)
|
|
23834
|
+
packages.set(id, pkg = { type: "ExternalPackage", id, source, ecosystem, name, version: null });
|
|
23835
|
+
return pkg;
|
|
23836
|
+
};
|
|
23837
|
+
for (const plan of plans) {
|
|
23838
|
+
const source = plan.sourceId;
|
|
23839
|
+
const fileNodes = files.filter((f) => f.source === source);
|
|
23840
|
+
const byPath = new Map(fileNodes.map((f) => [f.path, f]));
|
|
23841
|
+
const index = moduleIndex(fileNodes.map((f) => f.path));
|
|
23842
|
+
const projects = /* @__PURE__ */ new Map();
|
|
23843
|
+
const manifestDirs = [
|
|
23844
|
+
...new Set(plan.manifests.map((m) => posix11.dirname(m.path) === "." ? "" : posix11.dirname(m.path)))
|
|
23845
|
+
];
|
|
23846
|
+
const projectFor = (path) => {
|
|
23847
|
+
const key = manifestDirs.filter((d) => !d || path.startsWith(`${d}/`)).join("\0");
|
|
23848
|
+
let p = projects.get(key);
|
|
23849
|
+
if (!p) projects.set(key, p = pythonProject(plan, path));
|
|
23850
|
+
return p;
|
|
23851
|
+
};
|
|
23852
|
+
let project2 = projectFor("");
|
|
23853
|
+
const text = new Map(plan.files.filter((f) => f.content !== void 0).map((f) => [f.path, f.content]));
|
|
23854
|
+
const pathIn = (root, dotted) => {
|
|
23855
|
+
const p = posix11.join(root, ...dotted.split("."));
|
|
23856
|
+
return p === "." ? "" : p;
|
|
23857
|
+
};
|
|
23858
|
+
const absoluteFile = (dotted) => {
|
|
23859
|
+
for (const root of project2.roots) {
|
|
23860
|
+
const file2 = moduleFile(index, pathIn(root, dotted));
|
|
23861
|
+
if (file2) return { file: file2, root };
|
|
23862
|
+
}
|
|
23863
|
+
return null;
|
|
23864
|
+
};
|
|
23865
|
+
const absoluteDir = (dotted) => {
|
|
23866
|
+
for (const root of project2.roots) {
|
|
23867
|
+
const dir = pathIn(root, dotted);
|
|
23868
|
+
if (dir && index.dirs.has(dir)) return { dir, root };
|
|
23869
|
+
}
|
|
23870
|
+
return null;
|
|
23871
|
+
};
|
|
23872
|
+
for (const f of fileNodes) {
|
|
23873
|
+
if (f.language !== "python" || f.status === "not_analyzed") continue;
|
|
23874
|
+
const result2 = results.get(`${source}\0${f.path}`);
|
|
23875
|
+
if (!result2) continue;
|
|
23876
|
+
const fileId = f.id;
|
|
23877
|
+
project2 = projectFor(f.path);
|
|
23878
|
+
for (const s of statements(source, f.path, result2)) {
|
|
23879
|
+
let namespaceTarget2 = function(dir) {
|
|
23880
|
+
if (!isFrom) {
|
|
23881
|
+
const local = s.bindings[0]?.[1];
|
|
23882
|
+
if (local) folders.set(`${fileId}\0${local}`, dir);
|
|
23883
|
+
const first = [...index.files].filter((p) => posix11.dirname(p) === dir).sort()[0];
|
|
23884
|
+
return first ? toFile(first, "absolute") : {
|
|
23885
|
+
kind: "unresolved",
|
|
23886
|
+
outcome: "broken",
|
|
23887
|
+
reason: "file-not-found",
|
|
23888
|
+
steps: [
|
|
23889
|
+
...steps,
|
|
23890
|
+
{ kind: "namespace", detail: `${dir} is a namespace package with no module of its own` }
|
|
23891
|
+
]
|
|
23892
|
+
};
|
|
23893
|
+
}
|
|
23894
|
+
return {
|
|
23895
|
+
kind: "unresolved",
|
|
23896
|
+
outcome: "broken",
|
|
23897
|
+
reason: "file-not-found",
|
|
23898
|
+
steps: [
|
|
23899
|
+
...steps,
|
|
23900
|
+
{
|
|
23901
|
+
kind: "namespace",
|
|
23902
|
+
detail: `${dir || "the root"} is a namespace package; ${names.join(", ")} isn't a module in it`
|
|
23903
|
+
}
|
|
23904
|
+
]
|
|
23905
|
+
};
|
|
23906
|
+
};
|
|
23907
|
+
var namespaceTarget = namespaceTarget2;
|
|
23908
|
+
const steps = [];
|
|
23909
|
+
const names = s.bindings.map(([imported]) => imported).filter((n2) => !!n2 && n2 !== "*");
|
|
23910
|
+
const isFrom = s.bindings.some(([imported]) => imported !== "*");
|
|
23911
|
+
const toFile = (path, via) => {
|
|
23912
|
+
const file2 = byPath.get(path);
|
|
23913
|
+
if (file2.status === "not_analyzed")
|
|
23914
|
+
return {
|
|
23915
|
+
kind: "unresolved",
|
|
23916
|
+
outcome: "not-analyzed",
|
|
23917
|
+
reason: file2.reason ?? "not-analyzed",
|
|
23918
|
+
steps: [...steps, { kind: "not-analyzed", detail: `${path} is not analyzed` }]
|
|
23919
|
+
};
|
|
23920
|
+
return { kind: "file", file: file2, via, steps };
|
|
23921
|
+
};
|
|
23922
|
+
const binds = (dir, name) => {
|
|
23923
|
+
const init = results.get(`${source}\0${dir ? `${dir}/` : ""}__init__.py`);
|
|
23924
|
+
return !!init && (init.definitions.some((d) => d.qualifiedName === name) || init.types.some((t) => t.name === name) || init.imports.some(
|
|
23925
|
+
(i) => i.localName === name && !(f.path === `${dir ? `${dir}/` : ""}__init__.py` && i.span.start.offset === s.span.start.offset)
|
|
23926
|
+
));
|
|
23927
|
+
};
|
|
23928
|
+
const subs = (dir, via, namespace) => {
|
|
23929
|
+
if (!names.length || names.length !== s.bindings.length) return null;
|
|
23930
|
+
const found = names.map(
|
|
23931
|
+
(n2) => namespace || !binds(dir, n2) ? moduleFile(index, dir ? `${dir}/${n2}` : n2) : null
|
|
23932
|
+
);
|
|
23933
|
+
if (found.some((x) => x === null)) return null;
|
|
23934
|
+
if (names.length === 1) submodules.add(statementKey(s));
|
|
23935
|
+
else {
|
|
23936
|
+
folders.set(statementKey(s), dir);
|
|
23937
|
+
names.slice(1).forEach((n2, i) => {
|
|
23938
|
+
const spec = s.specifier.endsWith(".") ? `${s.specifier}${n2}` : `${s.specifier}.${n2}`;
|
|
23939
|
+
const file2 = byPath.get(found[i + 1]);
|
|
23940
|
+
resolved.push({
|
|
23941
|
+
statement: { ...s, specifier: spec, bindings: [[n2, s.bindings[i + 1][1]]], ordinal: 0 },
|
|
23942
|
+
target: file2.status === "not_analyzed" ? {
|
|
23943
|
+
kind: "unresolved",
|
|
23944
|
+
outcome: "not-analyzed",
|
|
23945
|
+
reason: file2.reason ?? "not-analyzed",
|
|
23946
|
+
steps: []
|
|
23947
|
+
} : {
|
|
23948
|
+
kind: "file",
|
|
23949
|
+
file: file2,
|
|
23950
|
+
via,
|
|
23951
|
+
steps: [{ kind: via, detail: `${n2} is the submodule ${found[i + 1]}` }]
|
|
23952
|
+
}
|
|
23953
|
+
});
|
|
23954
|
+
});
|
|
23955
|
+
}
|
|
23956
|
+
steps.push({
|
|
23957
|
+
kind: via,
|
|
23958
|
+
detail: `${names.join(", ")} ${names.length === 1 ? "is the submodule" : "are submodules, the first"} ${found[0]}`
|
|
23959
|
+
});
|
|
23960
|
+
return toFile(found[0], via);
|
|
23961
|
+
};
|
|
23962
|
+
const bindPackage = () => {
|
|
23963
|
+
if (isFrom || !s.specifier.includes(".")) return;
|
|
23964
|
+
const local = s.bindings[0]?.[1];
|
|
23965
|
+
const top = s.specifier.split(".")[0];
|
|
23966
|
+
if (local !== top) return;
|
|
23967
|
+
const file2 = absoluteFile(top);
|
|
23968
|
+
if (file2) packagesOf.set(`${fileId}\0${top}`, byPath.get(file2.file));
|
|
23969
|
+
else {
|
|
23970
|
+
const dir = absoluteDir(top);
|
|
23971
|
+
if (dir) folders.set(`${fileId}\0${top}`, dir.dir);
|
|
23972
|
+
}
|
|
23973
|
+
};
|
|
23974
|
+
let target2;
|
|
23975
|
+
if (s.specifier.startsWith(".")) {
|
|
23976
|
+
const level = /^\.+/.exec(s.specifier)[0].length;
|
|
23977
|
+
const rest = s.specifier.slice(level);
|
|
23978
|
+
let dir = posix11.dirname(f.path) === "." ? "" : posix11.dirname(f.path);
|
|
23979
|
+
for (let i = 1; i < level; i++) dir = posix11.dirname(dir) === "." ? "" : posix11.dirname(dir);
|
|
23980
|
+
const path = rest ? posix11.join(dir, ...rest.split(".")) : dir;
|
|
23981
|
+
steps.push({ kind: "relative", detail: `${s.specifier} from ${f.path} is ${path || "the root"}` });
|
|
23982
|
+
const file2 = moduleFile(index, path);
|
|
23983
|
+
if (file2)
|
|
23984
|
+
target2 = isFrom && file2.endsWith("__init__.py") && subs(path, "relative", false) || toFile(file2, "relative");
|
|
23985
|
+
else if (path === "" || index.dirs.has(path))
|
|
23986
|
+
target2 = isFrom && subs(path, "relative", true) || namespaceTarget2(path);
|
|
23987
|
+
else
|
|
23988
|
+
target2 = {
|
|
23989
|
+
kind: "unresolved",
|
|
23990
|
+
outcome: "broken",
|
|
23991
|
+
reason: "file-not-found",
|
|
23992
|
+
steps: [...steps, { kind: "not-found", detail: `no module ${path}` }]
|
|
23993
|
+
};
|
|
23994
|
+
} else {
|
|
23995
|
+
const top = s.specifier.split(".")[0];
|
|
23996
|
+
const found = absoluteFile(s.specifier);
|
|
23997
|
+
const dist = distribution(top, project2.dependencies);
|
|
23998
|
+
if (found) {
|
|
23999
|
+
steps.push({
|
|
24000
|
+
kind: "absolute",
|
|
24001
|
+
detail: `${s.specifier} is ${found.file}${found.root ? ` (under the root ${found.root})` : ""}`
|
|
24002
|
+
});
|
|
24003
|
+
const dir = pathIn(found.root, s.specifier);
|
|
24004
|
+
target2 = isFrom && found.file.endsWith("__init__.py") && subs(dir, "absolute", false) || toFile(found.file, "absolute");
|
|
24005
|
+
bindPackage();
|
|
24006
|
+
} else if (absoluteFile(top) && !absoluteDir(s.specifier)) {
|
|
24007
|
+
target2 = {
|
|
24008
|
+
kind: "unresolved",
|
|
24009
|
+
outcome: "broken",
|
|
24010
|
+
reason: "file-not-found",
|
|
24011
|
+
steps: [{ kind: "not-found", detail: `${top} is the project's, but it has no ${s.specifier}` }]
|
|
24012
|
+
};
|
|
24013
|
+
} else if (PYTHON_STDLIB.has(top)) {
|
|
24014
|
+
target2 = {
|
|
24015
|
+
kind: "package",
|
|
24016
|
+
pkg: external(source, "python", top),
|
|
24017
|
+
via: "stdlib",
|
|
24018
|
+
steps: [{ kind: "builtin", detail: `${top} is Python's standard library` }]
|
|
24019
|
+
};
|
|
24020
|
+
} else if (dist) {
|
|
24021
|
+
target2 = {
|
|
24022
|
+
kind: "package",
|
|
24023
|
+
pkg: external(source, "pypi", dist),
|
|
24024
|
+
via: "dependency",
|
|
24025
|
+
steps: [{ kind: "dependency", detail: `the project declares ${dist}` }]
|
|
24026
|
+
};
|
|
24027
|
+
} else if (absoluteDir(s.specifier)) {
|
|
24028
|
+
const ns = absoluteDir(s.specifier);
|
|
24029
|
+
steps.push({ kind: "absolute", detail: `${s.specifier} is the namespace package ${ns.dir}` });
|
|
24030
|
+
target2 = isFrom && subs(ns.dir, "absolute", true) || namespaceTarget2(ns.dir);
|
|
24031
|
+
bindPackage();
|
|
24032
|
+
} else if (distributionByPrefix(top, project2.dependencies)) {
|
|
24033
|
+
const name = distributionByPrefix(top, project2.dependencies);
|
|
24034
|
+
target2 = {
|
|
24035
|
+
kind: "package",
|
|
24036
|
+
pkg: external(source, "pypi", name),
|
|
24037
|
+
via: "dependency",
|
|
24038
|
+
steps: [{ kind: "dependency", detail: `the project declares ${name}, named after ${top}` }]
|
|
24039
|
+
};
|
|
24040
|
+
} else if (optionalImport(text.get(f.path) ?? "", s.span.start.line)) {
|
|
24041
|
+
const name = normalize(DISTRIBUTIONS[top] ?? top);
|
|
24042
|
+
target2 = {
|
|
24043
|
+
kind: "package",
|
|
24044
|
+
pkg: external(source, "pypi", name),
|
|
24045
|
+
via: "optional",
|
|
24046
|
+
steps: [{ kind: "optional", detail: `imported in a try whose handler catches ImportError` }]
|
|
24047
|
+
};
|
|
24048
|
+
} else
|
|
24049
|
+
target2 = {
|
|
24050
|
+
kind: "unresolved",
|
|
24051
|
+
outcome: "broken",
|
|
24052
|
+
reason: "unknown-package",
|
|
24053
|
+
steps: [{ kind: "not-found", detail: `nothing in the project or its dependencies is ${top}` }]
|
|
24054
|
+
};
|
|
24055
|
+
}
|
|
24056
|
+
if (target2) resolved.push({ statement: s, target: target2 });
|
|
24057
|
+
}
|
|
24058
|
+
}
|
|
24059
|
+
}
|
|
24060
|
+
return { resolved, submodules, folders, packages: packagesOf };
|
|
24061
|
+
}
|
|
24062
|
+
function linkPython(input2) {
|
|
24063
|
+
const fnByName = new Map(input2.functions.map((f) => [`${f.file}\0${f.qualifiedName}`, f]));
|
|
24064
|
+
const pathOf9 = (fileId) => fileId.slice(fileId.indexOf(":") + 1);
|
|
24065
|
+
const sourceOf7 = (fileId) => fileId.slice(0, fileId.indexOf(":"));
|
|
24066
|
+
const resultOf2 = (fileId) => input2.results.get(`${sourceOf7(fileId)}\0${pathOf9(fileId)}`);
|
|
24067
|
+
const statementsOf = /* @__PURE__ */ new Map();
|
|
24068
|
+
for (const r of input2.imports.resolved) {
|
|
24069
|
+
const list = statementsOf.get(r.statement.fileId) ?? [];
|
|
24070
|
+
list.push(r);
|
|
24071
|
+
statementsOf.set(r.statement.fileId, list);
|
|
24072
|
+
}
|
|
24073
|
+
const fileIds = new Set(input2.imports.resolved.map((r) => r.statement.fileId));
|
|
24074
|
+
for (const r of input2.imports.resolved) if (r.target.kind === "file") fileIds.add(r.target.file.id);
|
|
24075
|
+
const allOf = /* @__PURE__ */ new Map();
|
|
24076
|
+
const dunderAll = (fileId) => {
|
|
24077
|
+
if (allOf.has(fileId)) return allOf.get(fileId);
|
|
24078
|
+
const m = /^__all__\s*(?::[^=]+)?=\s*[[(]([^\])]*)[\])]/m.exec(input2.text(fileId) ?? "");
|
|
24079
|
+
const names = m ? [...m[1].matchAll(/["']([^"']+)["']/g)].map((x) => x[1]) : null;
|
|
24080
|
+
allOf.set(fileId, names);
|
|
24081
|
+
return names;
|
|
24082
|
+
};
|
|
24083
|
+
const step2 = (kind, detail) => ({ kind, detail });
|
|
24084
|
+
const missing = (stop, detail, hops = [], steps = []) => ({
|
|
24085
|
+
kind: "missing",
|
|
24086
|
+
stop,
|
|
24087
|
+
hops,
|
|
24088
|
+
steps: [...steps, step2(stop, detail)]
|
|
24089
|
+
});
|
|
24090
|
+
const variables = /* @__PURE__ */ new Map();
|
|
24091
|
+
const variable = (fileId, name) => {
|
|
24092
|
+
let vars = variables.get(fileId);
|
|
24093
|
+
if (!vars) {
|
|
24094
|
+
vars = moduleVariables(input2.text(fileId) ?? "");
|
|
24095
|
+
variables.set(fileId, vars);
|
|
24096
|
+
}
|
|
24097
|
+
return vars.has(name) ? vars.get(name) : null;
|
|
24098
|
+
};
|
|
24099
|
+
const boundName = (fileId, name, hops) => {
|
|
24100
|
+
const key = `${fileId}\0${name}`;
|
|
24101
|
+
const pkg = input2.imports.packages.get(key);
|
|
24102
|
+
if (pkg)
|
|
24103
|
+
return {
|
|
24104
|
+
kind: "module",
|
|
24105
|
+
file: pkg.id,
|
|
24106
|
+
hops,
|
|
24107
|
+
steps: [step2("package", `${name} is the package ${pkg.path}`)]
|
|
24108
|
+
};
|
|
24109
|
+
const dir = input2.imports.folders.get(key);
|
|
24110
|
+
if (dir !== void 0)
|
|
24111
|
+
return {
|
|
24112
|
+
kind: "folder",
|
|
24113
|
+
source: sourceOf7(fileId),
|
|
24114
|
+
dir,
|
|
24115
|
+
hops,
|
|
24116
|
+
steps: [step2("namespace", `${name} is the namespace package ${dir || "at the root"}`)]
|
|
24117
|
+
};
|
|
24118
|
+
return null;
|
|
24119
|
+
};
|
|
24120
|
+
const folderMember = (source, dir, name, hops) => {
|
|
24121
|
+
const base2 = dir ? `${dir}/` : "";
|
|
24122
|
+
for (const candidate of [`${base2}${name}/__init__.py`, `${base2}${name}.py`]) {
|
|
24123
|
+
if (input2.results.has(`${source}\0${candidate}`))
|
|
24124
|
+
return {
|
|
24125
|
+
kind: "module",
|
|
24126
|
+
file: `${source}:${candidate}`,
|
|
24127
|
+
hops,
|
|
24128
|
+
steps: [step2("submodule", `${name} is the submodule ${candidate}`)]
|
|
24129
|
+
};
|
|
24130
|
+
}
|
|
24131
|
+
return missing("not-exported", `${dir || "the root"} has no module ${name}`, hops);
|
|
24132
|
+
};
|
|
24133
|
+
const lookup = (fileId, name, hops, depth, star) => {
|
|
24134
|
+
const path = pathOf9(fileId);
|
|
24135
|
+
if (depth > MAX_DEPTH3) return missing("cycle", `${path} imports ${name} in a cycle`, hops);
|
|
24136
|
+
const result2 = resultOf2(fileId);
|
|
24137
|
+
if (!result2) return missing("not-found", `${path} was not read`, hops);
|
|
24138
|
+
if (star) {
|
|
24139
|
+
const all2 = dunderAll(fileId);
|
|
24140
|
+
if (all2 ? !all2.includes(name) : name.startsWith("_"))
|
|
24141
|
+
return missing(
|
|
24142
|
+
"not-exported",
|
|
24143
|
+
`${path}'s ${all2 ? "__all__" : "public names"} leave out ${name}`,
|
|
24144
|
+
hops
|
|
24145
|
+
);
|
|
24146
|
+
}
|
|
24147
|
+
const fn = fnByName.get(`${fileId}\0${name}`);
|
|
24148
|
+
if (fn)
|
|
24149
|
+
return { kind: "function", fn: fn.id, hops, steps: [step2("definition", `${path} defines ${name}`)] };
|
|
24150
|
+
if (result2.types.some((t) => t.name === name))
|
|
24151
|
+
return {
|
|
24152
|
+
kind: "class",
|
|
24153
|
+
file: fileId,
|
|
24154
|
+
name,
|
|
24155
|
+
hops,
|
|
24156
|
+
steps: [step2("definition", `${path} defines the class ${name}`)]
|
|
24157
|
+
};
|
|
24158
|
+
const value = variable(fileId, name);
|
|
24159
|
+
if (value !== null)
|
|
24160
|
+
return {
|
|
24161
|
+
kind: "value",
|
|
24162
|
+
file: fileId,
|
|
24163
|
+
name,
|
|
24164
|
+
cls: value,
|
|
24165
|
+
hops,
|
|
24166
|
+
steps: [step2("value", `${path} assigns ${name}${value ? ` (${value})` : ""}`)]
|
|
24167
|
+
};
|
|
24168
|
+
if (hops.includes(fileId)) return missing("cycle", `${path} imports ${name} in a cycle`, hops);
|
|
24169
|
+
const statements2 = statementsOf.get(fileId) ?? [];
|
|
24170
|
+
for (const r of statements2) {
|
|
24171
|
+
const binding2 = r.statement.bindings.find(([, local]) => local === name);
|
|
24172
|
+
if (!binding2) continue;
|
|
24173
|
+
const imported = binding2[0];
|
|
24174
|
+
const via = step2("re-export", `${path} imports ${name} from ${r.statement.specifier}`);
|
|
24175
|
+
if (imported === "*") {
|
|
24176
|
+
const ns = bindingAsModule(r);
|
|
24177
|
+
if (ns.kind === "folder") return { ...ns, hops };
|
|
24178
|
+
const t = r.target;
|
|
24179
|
+
if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops, steps: [via, ...t.steps] };
|
|
24180
|
+
if (t.kind === "unresolved")
|
|
24181
|
+
return { kind: "unresolved", outcome: t.outcome, hops, steps: [via, ...t.steps] };
|
|
24182
|
+
return { kind: "module", file: t.file.id, hops: [...hops, fileId], steps: [via] };
|
|
24183
|
+
}
|
|
24184
|
+
const e = bindingOf(r, imported, [...hops, fileId], depth + 1);
|
|
24185
|
+
return { ...e, steps: [via, ...e.steps] };
|
|
24186
|
+
}
|
|
24187
|
+
for (const r of statements2) {
|
|
24188
|
+
if (!r.statement.bindings.some(([imported, local]) => imported === "*" && local === null)) continue;
|
|
24189
|
+
if (r.target.kind !== "file") continue;
|
|
24190
|
+
const e = lookup(r.target.file.id, name, [...hops, fileId], depth + 1, true);
|
|
24191
|
+
if (e.kind !== "missing")
|
|
24192
|
+
return {
|
|
24193
|
+
...e,
|
|
24194
|
+
steps: [step2("re-export", `${path} imports everything from ${r.statement.specifier}`), ...e.steps]
|
|
24195
|
+
};
|
|
24196
|
+
}
|
|
24197
|
+
const bound = boundName(fileId, name, hops);
|
|
24198
|
+
if (bound) return bound;
|
|
24199
|
+
if (path.endsWith("__init__.py")) {
|
|
24200
|
+
const dir = posix11.dirname(path);
|
|
24201
|
+
const base2 = dir === "." ? "" : `${dir}/`;
|
|
24202
|
+
for (const candidate of [`${base2}${name}.py`, `${base2}${name}/__init__.py`]) {
|
|
24203
|
+
const id = `${sourceOf7(fileId)}:${candidate}`;
|
|
24204
|
+
if (fileIds.has(id) || input2.results.has(`${sourceOf7(fileId)}\0${candidate}`))
|
|
24205
|
+
return {
|
|
24206
|
+
kind: "module",
|
|
24207
|
+
file: id,
|
|
24208
|
+
hops,
|
|
24209
|
+
steps: [step2("submodule", `${name} is the submodule ${candidate}`)]
|
|
24210
|
+
};
|
|
24211
|
+
}
|
|
24212
|
+
}
|
|
24213
|
+
return missing("not-exported", `${path} defines or imports no ${name}`, hops);
|
|
24214
|
+
};
|
|
24215
|
+
const bindingOf = (r, imported, hops, depth) => {
|
|
24216
|
+
const t = r.target;
|
|
24217
|
+
if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops, steps: [...t.steps] };
|
|
24218
|
+
if (t.kind === "unresolved") return { kind: "unresolved", outcome: t.outcome, hops, steps: [...t.steps] };
|
|
24219
|
+
if (input2.imports.submodules.has(statementKey(r.statement)))
|
|
24220
|
+
return { kind: "module", file: t.file.id, hops, steps: [...t.steps] };
|
|
24221
|
+
const dir = input2.imports.folders.get(statementKey(r.statement));
|
|
24222
|
+
if (dir !== void 0) return withSteps(folderMember(t.file.source, dir, imported, hops), [...t.steps]);
|
|
24223
|
+
const e = lookup(t.file.id, imported, hops, depth, false);
|
|
24224
|
+
return { ...e, steps: [...t.steps, ...e.steps] };
|
|
24225
|
+
};
|
|
24226
|
+
const classDecl = (c) => resultOf2(c.file)?.types.find((t) => t.name === c.name);
|
|
24227
|
+
const baseMemo = /* @__PURE__ */ new Map();
|
|
24228
|
+
const baseOf2 = (c, base2) => {
|
|
24229
|
+
const key = `${c.file}#${c.name}#${base2}`;
|
|
24230
|
+
let e = baseMemo.get(key);
|
|
24231
|
+
if (!e) baseMemo.set(key, e = baseOfUncached(c, base2));
|
|
24232
|
+
return e;
|
|
24233
|
+
};
|
|
24234
|
+
const baseOfUncached = (c, base2) => {
|
|
24235
|
+
const [head, ...rest] = base2.split(".");
|
|
24236
|
+
if (resultOf2(c.file)?.types.some((t) => t.name === base2))
|
|
24237
|
+
return { kind: "class", file: c.file, name: base2, hops: [], steps: [] };
|
|
24238
|
+
const r = (statementsOf.get(c.file) ?? []).find((s) => s.statement.bindings.some(([, l]) => l === head));
|
|
24239
|
+
let e;
|
|
24240
|
+
if (r) {
|
|
24241
|
+
const imported = r.statement.bindings.find(([, l]) => l === head)[0];
|
|
24242
|
+
e = imported === "*" ? bindingAsModule(r) : bindingOf(r, imported, [], 0);
|
|
24243
|
+
} else
|
|
24244
|
+
e = boundName(c.file, head, []) ?? missing("not-found", `${base2} isn't defined or imported in ${pathOf9(c.file)}`);
|
|
24245
|
+
for (const part of rest) {
|
|
24246
|
+
if (e.kind === "module") e = lookup(e.file, part, [], 0, false);
|
|
24247
|
+
else if (e.kind === "folder") e = folderMember(e.source, e.dir, part, []);
|
|
24248
|
+
else if (e.kind !== "external" && e.kind !== "unresolved")
|
|
24249
|
+
return missing("member", `${base2} can't be followed`);
|
|
24250
|
+
}
|
|
24251
|
+
return e;
|
|
24252
|
+
};
|
|
24253
|
+
const bindingAsModule = (r) => {
|
|
24254
|
+
const local = r.statement.bindings.find(([imported, l]) => imported === "*" && l)?.[1];
|
|
24255
|
+
const ns = local ? input2.imports.folders.get(`${r.statement.fileId}\0${local}`) : void 0;
|
|
24256
|
+
if (ns !== void 0)
|
|
24257
|
+
return {
|
|
24258
|
+
kind: "folder",
|
|
24259
|
+
source: sourceOf7(r.statement.fileId),
|
|
24260
|
+
dir: ns,
|
|
24261
|
+
hops: [],
|
|
24262
|
+
steps: [step2("namespace", `${local} is the namespace package ${ns || "at the root"}`)]
|
|
24263
|
+
};
|
|
24264
|
+
const t = r.target;
|
|
24265
|
+
if (t.kind === "package") return { kind: "external", pkg: t.pkg.id, hops: [], steps: [...t.steps] };
|
|
24266
|
+
if (t.kind === "unresolved")
|
|
24267
|
+
return { kind: "unresolved", outcome: t.outcome, hops: [], steps: [...t.steps] };
|
|
24268
|
+
return { kind: "module", file: t.file.id, hops: [], steps: [...t.steps] };
|
|
24269
|
+
};
|
|
24270
|
+
const methodOf = (c, m, seen = /* @__PURE__ */ new Set()) => {
|
|
24271
|
+
const key = `${c.file}#${c.name}`;
|
|
24272
|
+
if (seen.has(key)) return null;
|
|
24273
|
+
seen.add(key);
|
|
24274
|
+
const decl = classDecl(c);
|
|
24275
|
+
if (!decl) return null;
|
|
24276
|
+
const own2 = [...decl.members, ...decl.statics ?? []].find((x) => x.name === m);
|
|
24277
|
+
if (own2?.function) {
|
|
24278
|
+
const fn = fnByName.get(`${c.file}\0${own2.function}`);
|
|
24279
|
+
if (fn) return { fn, definer: c };
|
|
24280
|
+
}
|
|
24281
|
+
if (m === "__init__") {
|
|
24282
|
+
const fn = fnByName.get(`${c.file}\0${c.name}.__init__`);
|
|
24283
|
+
if (fn && !fn.implicit) return { fn, definer: c };
|
|
24284
|
+
}
|
|
24285
|
+
if (own2) return null;
|
|
24286
|
+
let pkg = null;
|
|
24287
|
+
for (const b of decl.bases) {
|
|
24288
|
+
const e = baseOf2(c, b.name);
|
|
24289
|
+
if (e.kind === "class") {
|
|
24290
|
+
const found = methodOf(e, m, seen);
|
|
24291
|
+
if (found && "fn" in found) return found;
|
|
24292
|
+
if (found && "pkg" in found) pkg ??= found.pkg;
|
|
24293
|
+
} else if (e.kind === "external") pkg ??= e.pkg;
|
|
24294
|
+
}
|
|
24295
|
+
return pkg ? { pkg } : null;
|
|
24296
|
+
};
|
|
24297
|
+
const constructorOf = (c) => {
|
|
24298
|
+
const found = methodOf(c, "__init__");
|
|
24299
|
+
if (found && "fn" in found) return found.fn;
|
|
24300
|
+
return fnByName.get(`${c.file}\0${c.name}.__init__`);
|
|
24301
|
+
};
|
|
24302
|
+
let classes = null;
|
|
24303
|
+
const allClasses = () => {
|
|
24304
|
+
if (classes) return classes;
|
|
24305
|
+
const out = [];
|
|
24306
|
+
for (const [key, result2] of input2.results) {
|
|
24307
|
+
if (result2.language !== "python") continue;
|
|
24308
|
+
const fileId = ids.file(key.slice(0, key.indexOf("\0")), key.slice(key.indexOf("\0") + 1));
|
|
24309
|
+
for (const decl of result2.types) out.push({ file: fileId, decl });
|
|
24310
|
+
}
|
|
24311
|
+
return classes = out.sort(
|
|
24312
|
+
(a, b) => a.file < b.file ? -1 : a.file > b.file ? 1 : a.decl.span.start.offset - b.decl.span.start.offset
|
|
24313
|
+
);
|
|
24314
|
+
};
|
|
24315
|
+
const ancestors2 = /* @__PURE__ */ new Map();
|
|
24316
|
+
const ancestorsOf = (c) => {
|
|
24317
|
+
const key = `${c.file}#${c.name}`;
|
|
24318
|
+
const known = ancestors2.get(key);
|
|
24319
|
+
if (known) return known;
|
|
24320
|
+
const out = /* @__PURE__ */ new Set([key]);
|
|
24321
|
+
ancestors2.set(key, out);
|
|
24322
|
+
for (const b of classDecl(c)?.bases ?? []) {
|
|
24323
|
+
const e = baseOf2(c, b.name);
|
|
24324
|
+
if (e.kind === "class") for (const a of ancestorsOf(e)) out.add(a);
|
|
24325
|
+
}
|
|
24326
|
+
return out;
|
|
24327
|
+
};
|
|
24328
|
+
const reaches = (c, target2) => ancestorsOf(c).has(`${target2.file}#${target2.name}`);
|
|
24329
|
+
const evidence = (file2, span) => ({
|
|
24330
|
+
file: file2,
|
|
24331
|
+
span,
|
|
24332
|
+
commit: input2.revisions.get(sourceOf7(file2)) ?? ""
|
|
24333
|
+
});
|
|
24334
|
+
const baseClause = (file2, decl, base2) => {
|
|
24335
|
+
const b = decl.bases.find((x) => x.name === base2);
|
|
24336
|
+
if (!b) return null;
|
|
24337
|
+
const text = input2.text(file2);
|
|
24338
|
+
if (!text) return b.span;
|
|
24339
|
+
const bytes = Buffer.from(text, "utf8");
|
|
24340
|
+
const open3 = bytes.lastIndexOf(40, b.span.start.offset);
|
|
24341
|
+
const close = bytes.indexOf(41, decl.bases.at(-1).span.end.offset);
|
|
24342
|
+
if (open3 < decl.span.start.offset || close < 0) return b.span;
|
|
24343
|
+
const pos = (offset) => {
|
|
24344
|
+
const before = bytes.subarray(0, offset).toString("utf8");
|
|
24345
|
+
const line = before.split("\n").length;
|
|
24346
|
+
const column = [...before.slice(before.lastIndexOf("\n") + 1)].length + 1;
|
|
24347
|
+
return { line, column, offset };
|
|
24348
|
+
};
|
|
24349
|
+
return { start: pos(open3), end: pos(close + 1) };
|
|
24350
|
+
};
|
|
24351
|
+
const candidateMemo = /* @__PURE__ */ new Map();
|
|
24352
|
+
const typedCandidates = (c, m) => {
|
|
24353
|
+
const key = `${c.file}#${c.name}#${m}`;
|
|
24354
|
+
let found = candidateMemo.get(key);
|
|
24355
|
+
if (!found) candidateMemo.set(key, found = typedCandidatesOf(c, m));
|
|
24356
|
+
return found;
|
|
24357
|
+
};
|
|
24358
|
+
const typedCandidatesOf = (c, m) => {
|
|
24359
|
+
const bodies = /* @__PURE__ */ new Map();
|
|
24360
|
+
for (const { file: file2, decl } of allClasses()) {
|
|
24361
|
+
const cls = { file: file2, name: decl.name };
|
|
24362
|
+
if (!reaches(cls, c)) continue;
|
|
24363
|
+
const body = methodOf(cls, m);
|
|
24364
|
+
if (!body || !("fn" in body) || bodies.has(body.fn.id)) continue;
|
|
24365
|
+
const own2 = body.definer.file === c.file && body.definer.name === c.name;
|
|
24366
|
+
let basis;
|
|
24367
|
+
if (own2) basis = evidence(body.fn.file, body.fn.evidence.span);
|
|
24368
|
+
else {
|
|
24369
|
+
const definerDecl = classDecl(body.definer);
|
|
24370
|
+
const parent = definerDecl.bases.find((b) => {
|
|
24371
|
+
const e = baseOf2(body.definer, b.name);
|
|
24372
|
+
return e.kind === "class" && reaches(e, c);
|
|
24373
|
+
});
|
|
24374
|
+
const span = parent ? baseClause(body.definer.file, definerDecl, parent.name) : null;
|
|
24375
|
+
basis = evidence(body.definer.file, span ?? definerDecl.span);
|
|
24376
|
+
}
|
|
24377
|
+
bodies.set(body.fn.id, { fn: body.fn, basis });
|
|
24378
|
+
}
|
|
24379
|
+
return [...bodies.values()].sort(
|
|
24380
|
+
(a, b) => a.fn.file < b.fn.file ? -1 : a.fn.file > b.fn.file ? 1 : a.fn.evidence.span.start.offset - b.fn.evidence.span.start.offset
|
|
24381
|
+
);
|
|
24382
|
+
};
|
|
24383
|
+
const memberOf = (e, m) => {
|
|
24384
|
+
const found = methodOf(e, m);
|
|
24385
|
+
return found && "fn" in found ? {
|
|
24386
|
+
kind: "function",
|
|
24387
|
+
fn: found.fn.id,
|
|
24388
|
+
hops: e.hops,
|
|
24389
|
+
steps: [...e.steps, step2("instance", `${e.name}'s ${m} is ${found.fn.qualifiedName}`)]
|
|
24390
|
+
} : found && "pkg" in found ? { kind: "external", pkg: found.pkg, hops: e.hops, steps: e.steps } : missing("member", `no class up ${e.name}'s chain declares ${m}`, e.hops, e.steps);
|
|
24391
|
+
};
|
|
24392
|
+
const classNamed = (fileId, name) => {
|
|
24393
|
+
const [head] = name.split(".");
|
|
24394
|
+
if (resultOf2(fileId)?.types.some((t) => t.name === name))
|
|
24395
|
+
return { kind: "class", file: fileId, name, hops: [], steps: [] };
|
|
24396
|
+
const r = (statementsOf.get(fileId) ?? []).find((s) => s.statement.bindings.some(([, l]) => l === head));
|
|
24397
|
+
if (!r) return missing("not-found", `${name} isn't defined or imported here`);
|
|
24398
|
+
return baseOf2({ file: fileId, name: "" }, name);
|
|
24399
|
+
};
|
|
24400
|
+
const resolutions = [];
|
|
24401
|
+
const edges = [];
|
|
24402
|
+
for (const site of input2.sites) {
|
|
24403
|
+
const base2 = {
|
|
24404
|
+
type: "SiteResolution",
|
|
24405
|
+
id: ids.resolution(site.id),
|
|
24406
|
+
site: site.id,
|
|
24407
|
+
file: site.file,
|
|
24408
|
+
evidence: site.evidence
|
|
24409
|
+
};
|
|
24410
|
+
if (site.reason === "dynamic-dispatch") {
|
|
24411
|
+
const table = /^([A-Za-z_]\w*)\[/.exec(site.expression)?.[1];
|
|
24412
|
+
if (table) {
|
|
24413
|
+
const tables = (resultOf2(site.file)?.tables ?? []).filter((t) => t.name === table);
|
|
24414
|
+
if (tables.length === 1) {
|
|
24415
|
+
const t = tables[0];
|
|
24416
|
+
const candidates = t.entries.flatMap((e2) => {
|
|
24417
|
+
const fn = e2.function ? fnByName.get(`${site.file}\0${e2.function}`) : void 0;
|
|
24418
|
+
return fn ? [{ function: fn.id, basis: evidence(site.file, e2.span) }] : [];
|
|
24419
|
+
});
|
|
24420
|
+
if (candidates.length)
|
|
24421
|
+
resolutions.push({
|
|
24422
|
+
...base2,
|
|
24423
|
+
status: "unresolved",
|
|
24424
|
+
target: null,
|
|
24425
|
+
externalPackage: null,
|
|
24426
|
+
importOutcome: null,
|
|
24427
|
+
steps: [step2("table", `${table} is a dict of functions; the call runs one of its values`)],
|
|
24428
|
+
candidates,
|
|
24429
|
+
...t.exhaustive ? {} : { exhaustive: false }
|
|
24430
|
+
});
|
|
24431
|
+
}
|
|
24432
|
+
continue;
|
|
24433
|
+
}
|
|
24434
|
+
const raw = resultOf2(site.file)?.unresolved.find(
|
|
24435
|
+
(u) => u.site.start.offset === site.evidence.span.start.offset && u.expression === site.expression
|
|
24436
|
+
);
|
|
24437
|
+
if (raw?.receiverType && raw.member) {
|
|
24438
|
+
const c = classNamed(site.file, raw.receiverType);
|
|
24439
|
+
if (c.kind !== "class") continue;
|
|
24440
|
+
const found = typedCandidates(c, raw.member);
|
|
24441
|
+
if (found.length)
|
|
24442
|
+
resolutions.push({
|
|
24443
|
+
...base2,
|
|
24444
|
+
status: "unresolved",
|
|
24445
|
+
target: null,
|
|
24446
|
+
externalPackage: null,
|
|
24447
|
+
importOutcome: null,
|
|
24448
|
+
steps: [step2("typed", `${site.expression}'s receiver is annotated ${raw.receiverType}`)],
|
|
24449
|
+
candidates: found.map((x) => ({ function: x.fn.id, basis: x.basis })),
|
|
24450
|
+
exhaustive: false
|
|
24451
|
+
});
|
|
24452
|
+
}
|
|
24453
|
+
continue;
|
|
24454
|
+
}
|
|
24455
|
+
if (site.reason !== "imported-symbol" || !site.importSpecifier) continue;
|
|
24456
|
+
const local = /^[A-Za-z_]\w*/.exec(site.expression)?.[0] ?? "";
|
|
24457
|
+
const inherited = /^(self|cls)\./.test(site.expression) || site.expression.startsWith("super()");
|
|
24458
|
+
const statements2 = (statementsOf.get(site.file) ?? []).filter(
|
|
24459
|
+
(r) => r.statement.specifier === site.importSpecifier
|
|
24460
|
+
);
|
|
24461
|
+
const statement = inherited ? statements2.find(
|
|
24462
|
+
(r) => r.statement.bindings.some(
|
|
24463
|
+
([imported, l]) => (imported ?? l) === site.importedName || l === site.importedName
|
|
24464
|
+
)
|
|
24465
|
+
) ?? statements2.find((r) => r.statement.bindings.some(([imported]) => imported === "*")) : statements2.find((r) => r.statement.bindings.some(([, l]) => l === local)) ?? // A method on an instance of an imported class (`a = A(); a.run()`): the binding of A.
|
|
24466
|
+
statements2.find(
|
|
24467
|
+
(r) => r.statement.bindings.some(
|
|
24468
|
+
([imported, l]) => l === site.importedName || imported === site.importedName
|
|
24469
|
+
)
|
|
24470
|
+
) ?? statements2[0];
|
|
24471
|
+
let e;
|
|
24472
|
+
if (inherited) {
|
|
24473
|
+
const name = site.importedName;
|
|
24474
|
+
const b = statement?.statement.bindings.find(
|
|
24475
|
+
([imported, l]) => (l === name || imported === name) && imported !== "*"
|
|
24476
|
+
);
|
|
24477
|
+
e = !statement ? missing("not-found", `no import of ${site.importSpecifier} in this file`) : b ? bindingOf(statement, b[0], [], 0) : bindingAsModule(statement);
|
|
24478
|
+
if (e.kind === "module") e = withSteps(lookup(e.file, name, e.hops, 0, false), e.steps);
|
|
24479
|
+
else if (e.kind === "folder") e = folderMember(e.source, e.dir, name, e.hops);
|
|
24480
|
+
} else {
|
|
24481
|
+
const dotted = (statementsOf.get(site.file) ?? []).find(
|
|
24482
|
+
(r) => r.statement.specifier.startsWith(`${site.importSpecifier}.`) && r.statement.bindings.some(([imported, l]) => imported === "*" && l === local) && r.target.kind === "package"
|
|
24483
|
+
);
|
|
24484
|
+
if (!statement)
|
|
24485
|
+
e = boundName(site.file, local, []) ?? (dotted ? bindingAsModule(dotted) : missing("not-found", `no import of ${site.importSpecifier} in this file`));
|
|
24486
|
+
else {
|
|
24487
|
+
const binding2 = statement.statement.bindings.find(([, l]) => l === local) ?? statement.statement.bindings.find(
|
|
24488
|
+
([imported, l]) => l === site.importedName || imported === site.importedName
|
|
24489
|
+
) ?? statement.statement.bindings[0];
|
|
24490
|
+
e = binding2[0] === "*" ? bindingAsModule(statement) : bindingOf(statement, binding2[0], [], 0);
|
|
24491
|
+
}
|
|
24492
|
+
if (!statement || statement.statement.bindings.some(([imported, l]) => imported === "*" && l === local)) {
|
|
24493
|
+
if (site.importedName && e.kind === "module")
|
|
24494
|
+
e = withSteps(lookup(e.file, site.importedName, e.hops, 0, false), e.steps);
|
|
24495
|
+
else if (site.importedName && e.kind === "folder")
|
|
24496
|
+
e = folderMember(e.source, e.dir, site.importedName, e.hops);
|
|
24497
|
+
}
|
|
24498
|
+
}
|
|
24499
|
+
let called = !site.member;
|
|
24500
|
+
if (site.member && (e.kind === "module" || e.kind === "folder")) {
|
|
24501
|
+
e = e.kind === "module" ? withSteps(lookup(e.file, site.member, e.hops, 0, false), e.steps) : folderMember(e.source, e.dir, site.member, e.hops);
|
|
24502
|
+
called = true;
|
|
24503
|
+
} else if (site.member && e.kind === "value") {
|
|
24504
|
+
const v = e;
|
|
24505
|
+
const cls = v.cls ? classNamed(v.file, v.cls) : null;
|
|
24506
|
+
e = !cls ? missing(
|
|
24507
|
+
"member",
|
|
24508
|
+
`${v.name} is a variable of ${pathOf9(v.file)}; what it holds isn't followed`,
|
|
24509
|
+
v.hops,
|
|
24510
|
+
v.steps
|
|
24511
|
+
) : cls.kind === "class" || cls.kind === "external" || cls.kind === "unresolved" ? { ...cls, hops: v.hops, steps: [...v.steps, ...cls.steps] } : missing("member", `${v.name} holds a ${v.cls}, which can't be followed`, v.hops, v.steps);
|
|
24512
|
+
if (e.kind === "class") e = memberOf(e, site.member);
|
|
24513
|
+
} else if (site.member && e.kind === "class") e = memberOf(e, site.member);
|
|
24514
|
+
else if (site.member && e.kind === "function")
|
|
24515
|
+
e = missing(
|
|
24516
|
+
"member",
|
|
24517
|
+
`${site.expression} calls a member of what ${local} names, a function`,
|
|
24518
|
+
e.hops,
|
|
24519
|
+
e.steps
|
|
24520
|
+
);
|
|
24521
|
+
if (called) {
|
|
24522
|
+
if (e.kind === "class") {
|
|
24523
|
+
const ctor = constructorOf(e);
|
|
24524
|
+
e = ctor ? {
|
|
24525
|
+
kind: "function",
|
|
24526
|
+
fn: ctor.id,
|
|
24527
|
+
hops: e.hops,
|
|
24528
|
+
steps: [...e.steps, step2("constructor", `calling ${e.name} runs ${ctor.qualifiedName}`)]
|
|
24529
|
+
} : missing("not-a-function", `${e.name} has no constructor Stage 2 can follow`, e.hops, e.steps);
|
|
24530
|
+
} else if (e.kind === "module" || e.kind === "folder")
|
|
24531
|
+
e = missing("not-a-function", `${site.expression} is a module`, e.hops, e.steps);
|
|
24532
|
+
else if (e.kind === "value")
|
|
24533
|
+
e = missing(
|
|
24534
|
+
"not-a-function",
|
|
24535
|
+
`${e.name} is a variable of ${pathOf9(e.file)}, not a function Stage 2 follows`,
|
|
24536
|
+
e.hops,
|
|
24537
|
+
e.steps
|
|
24538
|
+
);
|
|
24539
|
+
}
|
|
24540
|
+
const via = inherited ? "inherited" : "import";
|
|
24541
|
+
e = withSteps(e, [
|
|
24542
|
+
step2(
|
|
24543
|
+
"import",
|
|
24544
|
+
inherited ? `${site.expression} reaches ${site.importedName}, a base imported from ${site.importSpecifier}` : `${site.expression} goes through the import of ${site.importSpecifier}`
|
|
24545
|
+
)
|
|
24546
|
+
]);
|
|
24547
|
+
switch (e.kind) {
|
|
24548
|
+
case "function":
|
|
24549
|
+
resolutions.push({
|
|
24550
|
+
...base2,
|
|
24551
|
+
status: "linked",
|
|
24552
|
+
target: e.fn,
|
|
24553
|
+
externalPackage: null,
|
|
24554
|
+
via,
|
|
24555
|
+
importOutcome: null,
|
|
24556
|
+
steps: e.steps,
|
|
24557
|
+
hops: e.hops
|
|
24558
|
+
});
|
|
24559
|
+
edges.push({
|
|
24560
|
+
type: "CALLS_CROSS_FILE",
|
|
24561
|
+
id: ids.linkedCall(site.id),
|
|
24562
|
+
from: site.enclosingFn,
|
|
24563
|
+
to: e.fn,
|
|
24564
|
+
form: "plain",
|
|
24565
|
+
resolution: "static-exact",
|
|
24566
|
+
confidence: 1,
|
|
24567
|
+
evidence: site.evidence,
|
|
24568
|
+
via: "import"
|
|
24569
|
+
});
|
|
24570
|
+
break;
|
|
24571
|
+
case "external":
|
|
24572
|
+
resolutions.push({
|
|
24573
|
+
...base2,
|
|
24574
|
+
status: "external",
|
|
24575
|
+
target: null,
|
|
24576
|
+
externalPackage: e.pkg,
|
|
24577
|
+
importOutcome: null,
|
|
24578
|
+
steps: e.steps
|
|
24579
|
+
});
|
|
24580
|
+
break;
|
|
24581
|
+
case "unresolved":
|
|
24582
|
+
resolutions.push({
|
|
24583
|
+
...base2,
|
|
24584
|
+
status: "unresolved",
|
|
24585
|
+
target: null,
|
|
24586
|
+
externalPackage: null,
|
|
24587
|
+
importOutcome: e.outcome,
|
|
24588
|
+
steps: e.steps
|
|
24589
|
+
});
|
|
24590
|
+
break;
|
|
24591
|
+
default:
|
|
24592
|
+
resolutions.push({
|
|
24593
|
+
...base2,
|
|
24594
|
+
status: "unresolved",
|
|
24595
|
+
target: null,
|
|
24596
|
+
externalPackage: null,
|
|
24597
|
+
importOutcome: null,
|
|
24598
|
+
steps: e.steps
|
|
24599
|
+
});
|
|
24600
|
+
}
|
|
24601
|
+
}
|
|
24602
|
+
return { resolutions, edges };
|
|
24603
|
+
function withSteps(e, before) {
|
|
24604
|
+
return { ...e, steps: [...before, ...e.steps] };
|
|
24605
|
+
}
|
|
24606
|
+
}
|
|
24607
|
+
var PYTHON_STDLIB, DISTRIBUTIONS, normalize, isPython, quoted, closes, statementKey, MAX_DEPTH3;
|
|
24608
|
+
var init_python = __esm({
|
|
24609
|
+
"packages/stage2/src/python.ts"() {
|
|
24610
|
+
"use strict";
|
|
24611
|
+
init_src();
|
|
24612
|
+
init_src3();
|
|
24613
|
+
init_protocol();
|
|
24614
|
+
init_imports();
|
|
24615
|
+
PYTHON_STDLIB = new Set(
|
|
24616
|
+
"abc aifc argparse array ast asynchat asyncio asyncore atexit audioop base64 bdb binascii bisect builtins bz2 cProfile calendar cgi cgitb chunk cmath cmd code codecs codeop collections colorsys compileall concurrent configparser contextlib contextvars copy copyreg crypt csv ctypes curses dataclasses datetime dbm decimal difflib dis distutils doctest email encodings ensurepip enum errno faulthandler fcntl filecmp fileinput fnmatch fractions ftplib functools gc genericpath getopt getpass gettext glob graphlib grp gzip hashlib heapq hmac html http idlelib imaplib imghdr imp importlib inspect io ipaddress itertools json keyword lib2to3 linecache locale logging lzma mailbox mailcap marshal math mimetypes mmap modulefinder msilib msvcrt multiprocessing netrc nis nntplib ntpath nturl2path numbers opcode operator optparse os ossaudiodev pathlib pdb pickle pickletools pipes pkgutil platform plistlib poplib posix posixpath pprint profile pstats pty pwd py_compile pyclbr pydoc pydoc_data pyexpat queue quopri random re readline reprlib resource rlcompleter runpy sched secrets select selectors shelve shlex shutil signal site smtpd smtplib sndhdr socket socketserver spwd sqlite3 sre_compile sre_constants sre_parse ssl stat statistics string stringprep struct subprocess sunau symtable sys sysconfig syslog tabnanny tarfile telnetlib tempfile termios textwrap this threading time timeit tkinter token tokenize tomllib trace traceback tracemalloc tty turtle turtledemo types typing unicodedata unittest urllib uu uuid venv warnings wave weakref webbrowser winreg winsound wsgiref xdrlib xml xmlrpc zipapp zipfile zipimport zlib zoneinfo __future__ _thread typing_extensions".split(" ")
|
|
24617
|
+
);
|
|
24618
|
+
DISTRIBUTIONS = {
|
|
24619
|
+
yaml: "pyyaml",
|
|
24620
|
+
PIL: "pillow",
|
|
24621
|
+
sklearn: "scikit-learn",
|
|
24622
|
+
bs4: "beautifulsoup4",
|
|
24623
|
+
cv2: "opencv-python",
|
|
24624
|
+
dateutil: "python-dateutil",
|
|
24625
|
+
jwt: "pyjwt",
|
|
24626
|
+
dotenv: "python-dotenv",
|
|
24627
|
+
magic: "python-magic",
|
|
24628
|
+
attr: "attrs",
|
|
24629
|
+
google: "google",
|
|
24630
|
+
jose: "python-jose",
|
|
24631
|
+
multipart: "python-multipart",
|
|
24632
|
+
slugify: "python-slugify",
|
|
24633
|
+
Crypto: "pycryptodome",
|
|
24634
|
+
OpenSSL: "pyopenssl",
|
|
24635
|
+
serial: "pyserial",
|
|
24636
|
+
usb: "pyusb",
|
|
24637
|
+
zmq: "pyzmq",
|
|
24638
|
+
psycopg2: "psycopg2-binary",
|
|
24639
|
+
MySQLdb: "mysqlclient",
|
|
24640
|
+
grpc: "grpcio",
|
|
24641
|
+
qcloud_cos: "cos-python-sdk-v5",
|
|
24642
|
+
baidubce: "bce-python-sdk",
|
|
24643
|
+
obs: "esdk-obs-python",
|
|
24644
|
+
Tea: "alibabacloud-tea",
|
|
24645
|
+
docx: "python-docx",
|
|
24646
|
+
pptx: "python-pptx"
|
|
24647
|
+
};
|
|
24648
|
+
normalize = (name) => name.toLowerCase().replace(/[-_.]+/g, "-");
|
|
24649
|
+
isPython = (path) => path.endsWith(".py") || path.endsWith(".pyi");
|
|
24650
|
+
quoted = (value) => [...value.replace(/\{[^}]*\}/g, "").matchAll(/["']([^"']*)["']/g)].map((m) => m[1]);
|
|
24651
|
+
closes = (line) => line.replace(/"[^"]*"|'[^']*'/g, "").includes("]");
|
|
24652
|
+
statementKey = (s) => `${s.fileId}\0${s.span.start.offset}\0${s.specifier}`;
|
|
24653
|
+
MAX_DEPTH3 = 32;
|
|
24654
|
+
}
|
|
24655
|
+
});
|
|
24656
|
+
|
|
22536
24657
|
// packages/stage2/src/index.ts
|
|
22537
24658
|
function scopeOf2(fact) {
|
|
22538
24659
|
switch (fact.type) {
|
|
@@ -22603,7 +24724,7 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22603
24724
|
if (scope2) scopes.add(scope2);
|
|
22604
24725
|
}
|
|
22605
24726
|
const files = view.facts("File");
|
|
22606
|
-
const
|
|
24727
|
+
const step2 = async (n2, phase, count2, unit) => {
|
|
22607
24728
|
if (!ctx.progress) return;
|
|
22608
24729
|
ctx.progress({ phase, step: n2, steps: STEPS, ...count2 ? { total: count2(), unit } : {} });
|
|
22609
24730
|
await breathe();
|
|
@@ -22617,17 +24738,47 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22617
24738
|
scopes.add(linksScope(f.id));
|
|
22618
24739
|
scopes.add(symbolsScope(f.id));
|
|
22619
24740
|
}
|
|
22620
|
-
await
|
|
24741
|
+
await step2(1, "resolving imports", () => files.length, "files");
|
|
22621
24742
|
const { resolved, results } = resolveImports2(ctx.plans, files);
|
|
22622
|
-
const
|
|
24743
|
+
const pyResults = pythonResults(ctx.plans);
|
|
24744
|
+
const pyImports = resolvePythonImports(ctx.plans, files, pyResults);
|
|
24745
|
+
const pyFiles = new Set(files.filter((f) => f.language === "python").map((f) => f.id));
|
|
24746
|
+
const goFiles = new Set(files.filter((f) => f.language === "go").map((f) => f.id));
|
|
24747
|
+
const allSites = view.facts("UnresolvedCallSite");
|
|
24748
|
+
const goLinked = linkGo({
|
|
24749
|
+
plans: ctx.plans,
|
|
24750
|
+
files,
|
|
24751
|
+
results: goResults(ctx.plans),
|
|
24752
|
+
functions: view.facts("Function"),
|
|
24753
|
+
sites: allSites.filter((s) => goFiles.has(s.file)),
|
|
24754
|
+
revisions: new Map(ctx.plans.map((p) => [p.sourceId, p.revision]))
|
|
24755
|
+
});
|
|
24756
|
+
const { edges, unresolved, packages } = importFacts([
|
|
24757
|
+
...resolved,
|
|
24758
|
+
...pyImports.resolved,
|
|
24759
|
+
...goLinked.resolved
|
|
24760
|
+
]);
|
|
22623
24761
|
const linkInput = {
|
|
22624
24762
|
resolved,
|
|
22625
24763
|
results,
|
|
22626
24764
|
functions: view.facts("Function"),
|
|
22627
|
-
sites:
|
|
24765
|
+
sites: allSites.filter((s) => !pyFiles.has(s.file) && !goFiles.has(s.file)),
|
|
22628
24766
|
revisions: new Map(ctx.plans.map((p) => [p.sourceId, p.revision]))
|
|
22629
24767
|
};
|
|
22630
|
-
|
|
24768
|
+
const pyText = new Map(
|
|
24769
|
+
ctx.plans.flatMap(
|
|
24770
|
+
(p) => p.files.filter((f) => f.content !== void 0 && f.language === "python").map((f) => [ids.file(p.sourceId, f.path), f.content])
|
|
24771
|
+
)
|
|
24772
|
+
);
|
|
24773
|
+
const pyLinked = linkPython({
|
|
24774
|
+
imports: pyImports,
|
|
24775
|
+
results: pyResults,
|
|
24776
|
+
functions: linkInput.functions,
|
|
24777
|
+
sites: allSites.filter((s) => pyFiles.has(s.file)),
|
|
24778
|
+
revisions: linkInput.revisions,
|
|
24779
|
+
text: (id) => pyText.get(id)
|
|
24780
|
+
});
|
|
24781
|
+
await step2(2, "linking calls", () => linkInput.sites.length, "call sites");
|
|
22631
24782
|
const graph = typeGraph(linkInput);
|
|
22632
24783
|
const linked = link(linkInput, graph);
|
|
22633
24784
|
const linker = makeLinker(linkInput, graph);
|
|
@@ -22645,7 +24796,7 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22645
24796
|
templates: view.facts("DeclaredTemplate"),
|
|
22646
24797
|
revisions: new Map(ctx.plans.map((p) => [p.sourceId, p.revision]))
|
|
22647
24798
|
});
|
|
22648
|
-
await
|
|
24799
|
+
await step2(3, "typing calls with the TypeScript checker");
|
|
22649
24800
|
const program = scripts({
|
|
22650
24801
|
files,
|
|
22651
24802
|
text: (f) => ctx.evidence.get(f.contentHash),
|
|
@@ -22725,7 +24876,7 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22725
24876
|
const closedById = new Map(closedOut.resolutions.map((r) => [r.id, r]));
|
|
22726
24877
|
settledNarrowed = settledNarrowed.map((r) => closedById.get(r.id) ?? r);
|
|
22727
24878
|
typed.resolutions = typed.resolutions.map((r) => closedById.get(r.id) ?? r);
|
|
22728
|
-
await
|
|
24879
|
+
await step2(4, "naming where paths leave the project");
|
|
22729
24880
|
const fnIds = new Set(linkInput.functions.map((f) => f.id));
|
|
22730
24881
|
const named = exits(
|
|
22731
24882
|
{
|
|
@@ -22745,7 +24896,7 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22745
24896
|
},
|
|
22746
24897
|
program
|
|
22747
24898
|
);
|
|
22748
|
-
await
|
|
24899
|
+
await step2(5, "grouping files");
|
|
22749
24900
|
const map2 = groups({
|
|
22750
24901
|
plans: ctx.plans,
|
|
22751
24902
|
files,
|
|
@@ -22754,6 +24905,8 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22754
24905
|
// Stage 2's links and R1's template links.
|
|
22755
24906
|
calls: [
|
|
22756
24907
|
...linked.edges,
|
|
24908
|
+
...pyLinked.edges,
|
|
24909
|
+
...goLinked.edges,
|
|
22757
24910
|
...typed.edges,
|
|
22758
24911
|
...injected.edges,
|
|
22759
24912
|
...returned.edges,
|
|
@@ -22781,6 +24934,10 @@ async function runStage2(ctx, options2 = {}) {
|
|
|
22781
24934
|
...packages,
|
|
22782
24935
|
...kept,
|
|
22783
24936
|
...named.resolutions,
|
|
24937
|
+
...pyLinked.resolutions,
|
|
24938
|
+
...pyLinked.edges,
|
|
24939
|
+
...goLinked.resolutions,
|
|
24940
|
+
...goLinked.edges,
|
|
22784
24941
|
...typed.edges,
|
|
22785
24942
|
...injected.edges,
|
|
22786
24943
|
...returned.edges,
|
|
@@ -22826,6 +24983,8 @@ var init_src8 = __esm({
|
|
|
22826
24983
|
init_types();
|
|
22827
24984
|
init_typegraph();
|
|
22828
24985
|
init_together();
|
|
24986
|
+
init_go();
|
|
24987
|
+
init_python();
|
|
22829
24988
|
init_imports();
|
|
22830
24989
|
init_link();
|
|
22831
24990
|
init_candidates();
|
|
@@ -22839,7 +24998,7 @@ var init_src8 = __esm({
|
|
|
22839
24998
|
symbolsScope = (fileId) => `${STAGE23}:symbols:${fileId}`;
|
|
22840
24999
|
groupSource = (groupId) => groupId.split("|")[1];
|
|
22841
25000
|
STEPS = 5;
|
|
22842
|
-
STAGE2_VERSION =
|
|
25001
|
+
STAGE2_VERSION = 12;
|
|
22843
25002
|
stage2 = createStage2();
|
|
22844
25003
|
}
|
|
22845
25004
|
});
|
|
@@ -23430,10 +25589,10 @@ function isValidJWT(jwt2, alg) {
|
|
|
23430
25589
|
if (!jwtRegex.test(jwt2))
|
|
23431
25590
|
return false;
|
|
23432
25591
|
try {
|
|
23433
|
-
const [
|
|
23434
|
-
if (!
|
|
25592
|
+
const [header2] = jwt2.split(".");
|
|
25593
|
+
if (!header2)
|
|
23435
25594
|
return false;
|
|
23436
|
-
const base643 =
|
|
25595
|
+
const base643 = header2.replace(/-/g, "+").replace(/_/g, "/").padEnd(header2.length + (4 - header2.length % 4) % 4, "=");
|
|
23437
25596
|
const decoded = JSON.parse(atob(base643));
|
|
23438
25597
|
if (typeof decoded !== "object" || decoded === null)
|
|
23439
25598
|
return false;
|
|
@@ -23457,12 +25616,12 @@ function isValidCidr(ip, version3) {
|
|
|
23457
25616
|
}
|
|
23458
25617
|
return false;
|
|
23459
25618
|
}
|
|
23460
|
-
function floatSafeRemainder(val,
|
|
25619
|
+
function floatSafeRemainder(val, step2) {
|
|
23461
25620
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
23462
|
-
const stepDecCount = (
|
|
25621
|
+
const stepDecCount = (step2.toString().split(".")[1] || "").length;
|
|
23463
25622
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
23464
25623
|
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
23465
|
-
const stepInt = Number.parseInt(
|
|
25624
|
+
const stepInt = Number.parseInt(step2.toFixed(decCount).replace(".", ""));
|
|
23466
25625
|
return valInt % stepInt / 10 ** decCount;
|
|
23467
25626
|
}
|
|
23468
25627
|
function deepPartialify(schema) {
|
|
@@ -26924,8 +29083,8 @@ function cleanRegex(source) {
|
|
|
26924
29083
|
const end2 = source.endsWith("$") ? source.length - 1 : source.length;
|
|
26925
29084
|
return source.slice(start, end2);
|
|
26926
29085
|
}
|
|
26927
|
-
function floatSafeRemainder2(val,
|
|
26928
|
-
const ratio = val /
|
|
29086
|
+
function floatSafeRemainder2(val, step2) {
|
|
29087
|
+
const ratio = val / step2;
|
|
26929
29088
|
const roundedRatio = Math.round(ratio);
|
|
26930
29089
|
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
26931
29090
|
if (Math.abs(ratio - roundedRatio) < tolerance)
|
|
@@ -29009,10 +31168,10 @@ function isValidJWT2(token, algorithm = null) {
|
|
|
29009
31168
|
const tokensParts = token.split(".");
|
|
29010
31169
|
if (tokensParts.length !== 3)
|
|
29011
31170
|
return false;
|
|
29012
|
-
const [
|
|
29013
|
-
if (!
|
|
31171
|
+
const [header2] = tokensParts;
|
|
31172
|
+
if (!header2)
|
|
29014
31173
|
return false;
|
|
29015
|
-
const parsedHeader = JSON.parse(atob(
|
|
31174
|
+
const parsedHeader = JSON.parse(atob(header2));
|
|
29016
31175
|
if ("typ" in parsedHeader && parsedHeader?.typ !== "JWT")
|
|
29017
31176
|
return false;
|
|
29018
31177
|
if (!parsedHeader.alg)
|
|
@@ -53788,8 +55947,8 @@ var require_resolve = __commonJS({
|
|
|
53788
55947
|
}
|
|
53789
55948
|
return count2;
|
|
53790
55949
|
}
|
|
53791
|
-
function getFullPath(resolver, id = "",
|
|
53792
|
-
if (
|
|
55950
|
+
function getFullPath(resolver, id = "", normalize3) {
|
|
55951
|
+
if (normalize3 !== false)
|
|
53793
55952
|
id = normalizeId(id);
|
|
53794
55953
|
const p = resolver.parse(id);
|
|
53795
55954
|
return _getFullPath(resolver, p);
|
|
@@ -55384,7 +57543,7 @@ var require_fast_uri = __commonJS({
|
|
|
55384
57543
|
}
|
|
55385
57544
|
return decodedScheme;
|
|
55386
57545
|
}
|
|
55387
|
-
function
|
|
57546
|
+
function normalize3(uri, options2) {
|
|
55388
57547
|
if (typeof uri === "string") {
|
|
55389
57548
|
uri = /** @type {T} */
|
|
55390
57549
|
normalizeString(uri, options2);
|
|
@@ -55762,7 +57921,7 @@ var require_fast_uri = __commonJS({
|
|
|
55762
57921
|
}
|
|
55763
57922
|
var fastUri = {
|
|
55764
57923
|
SCHEMES,
|
|
55765
|
-
normalize:
|
|
57924
|
+
normalize: normalize3,
|
|
55766
57925
|
resolve: resolve9,
|
|
55767
57926
|
resolveComponent,
|
|
55768
57927
|
equal,
|
|
@@ -65756,7 +67915,7 @@ var require_send = __commonJS({
|
|
|
65756
67915
|
var { createHttpError } = require_createHttpError();
|
|
65757
67916
|
var extname = path.extname;
|
|
65758
67917
|
var join14 = path.join;
|
|
65759
|
-
var
|
|
67918
|
+
var normalize3 = path.normalize;
|
|
65760
67919
|
var resolve9 = path.resolve;
|
|
65761
67920
|
var sep9 = path.sep;
|
|
65762
67921
|
var Readable = stream.Readable;
|
|
@@ -65835,20 +67994,20 @@ var require_send = __commonJS({
|
|
|
65835
67994
|
let parts;
|
|
65836
67995
|
if (root !== null) {
|
|
65837
67996
|
if (path2) {
|
|
65838
|
-
path2 =
|
|
67997
|
+
path2 = normalize3("." + sep9 + path2);
|
|
65839
67998
|
}
|
|
65840
67999
|
if (UP_PATH_REGEXP.test(path2)) {
|
|
65841
68000
|
debug('malicious path "%s"', path2);
|
|
65842
68001
|
return { statusCode: 403 };
|
|
65843
68002
|
}
|
|
65844
68003
|
parts = path2.split(sep9);
|
|
65845
|
-
path2 =
|
|
68004
|
+
path2 = normalize3(join14(root, path2));
|
|
65846
68005
|
} else {
|
|
65847
68006
|
if (UP_PATH_REGEXP.test(path2)) {
|
|
65848
68007
|
debug('malicious path "%s"', path2);
|
|
65849
68008
|
return { statusCode: 403 };
|
|
65850
68009
|
}
|
|
65851
|
-
parts =
|
|
68010
|
+
parts = normalize3(path2).split(sep9);
|
|
65852
68011
|
path2 = resolve9(path2);
|
|
65853
68012
|
}
|
|
65854
68013
|
return { path: path2, parts };
|
|
@@ -66232,23 +68391,23 @@ var require_accept_negotiator = __commonJS({
|
|
|
66232
68391
|
this.supportedValues = supportedValues;
|
|
66233
68392
|
this.cache = cache;
|
|
66234
68393
|
}
|
|
66235
|
-
Negotiator.prototype.negotiate = function(
|
|
66236
|
-
if (typeof
|
|
68394
|
+
Negotiator.prototype.negotiate = function(header2) {
|
|
68395
|
+
if (typeof header2 !== "string") {
|
|
66237
68396
|
return null;
|
|
66238
68397
|
}
|
|
66239
68398
|
if (!this.cache) {
|
|
66240
|
-
return negotiate(
|
|
68399
|
+
return negotiate(header2, this.supportedValues);
|
|
66241
68400
|
}
|
|
66242
|
-
if (!this.cache.has(
|
|
66243
|
-
this.cache.set(
|
|
68401
|
+
if (!this.cache.has(header2)) {
|
|
68402
|
+
this.cache.set(header2, negotiate(header2, this.supportedValues));
|
|
66244
68403
|
}
|
|
66245
|
-
return this.cache.get(
|
|
68404
|
+
return this.cache.get(header2);
|
|
66246
68405
|
};
|
|
66247
|
-
function negotiate(
|
|
66248
|
-
if (!
|
|
68406
|
+
function negotiate(header2, supportedValues) {
|
|
68407
|
+
if (!header2 || !Array.isArray(supportedValues) || supportedValues.length === 0) {
|
|
66249
68408
|
return null;
|
|
66250
68409
|
}
|
|
66251
|
-
if (
|
|
68410
|
+
if (header2 === "*") {
|
|
66252
68411
|
return supportedValues[0];
|
|
66253
68412
|
}
|
|
66254
68413
|
let preferredEncoding = null;
|
|
@@ -66277,19 +68436,19 @@ var require_accept_negotiator = __commonJS({
|
|
|
66277
68436
|
}
|
|
66278
68437
|
return false;
|
|
66279
68438
|
}
|
|
66280
|
-
parse5(
|
|
68439
|
+
parse5(header2, processMatch);
|
|
66281
68440
|
return preferredEncoding;
|
|
66282
68441
|
}
|
|
66283
68442
|
var BEGIN = 0;
|
|
66284
68443
|
var TOKEN = 1;
|
|
66285
68444
|
var QUALITY = 2;
|
|
66286
68445
|
var END = 3;
|
|
66287
|
-
function parse5(
|
|
68446
|
+
function parse5(header2, processMatch) {
|
|
66288
68447
|
let str3 = "";
|
|
66289
68448
|
let quality;
|
|
66290
68449
|
let state = BEGIN;
|
|
66291
|
-
for (let i = 0, il =
|
|
66292
|
-
const char =
|
|
68450
|
+
for (let i = 0, il = header2.length; i < il; ++i) {
|
|
68451
|
+
const char = header2[i];
|
|
66293
68452
|
if (char === " " || char === " ") {
|
|
66294
68453
|
continue;
|
|
66295
68454
|
} else if (char === ";") {
|
|
@@ -66329,7 +68488,7 @@ var require_accept_negotiator = __commonJS({
|
|
|
66329
68488
|
continue;
|
|
66330
68489
|
}
|
|
66331
68490
|
if (state === TOKEN) {
|
|
66332
|
-
const prevChar =
|
|
68491
|
+
const prevChar = header2[i - 1];
|
|
66333
68492
|
if (prevChar === " " || prevChar === " ") {
|
|
66334
68493
|
str3 = "";
|
|
66335
68494
|
}
|
|
@@ -66371,43 +68530,43 @@ function create(filename, options2) {
|
|
|
66371
68530
|
const parameters = createParameters(filename, options2?.fallback);
|
|
66372
68531
|
return format({ type, parameters }, { extended: false });
|
|
66373
68532
|
}
|
|
66374
|
-
function parse4(
|
|
66375
|
-
const len =
|
|
68533
|
+
function parse4(header2, options2) {
|
|
68534
|
+
const len = header2.length;
|
|
66376
68535
|
const multipart = options2?.multipart === true;
|
|
66377
68536
|
const extended2 = options2?.extended !== false;
|
|
66378
|
-
let index = skipOWS(
|
|
68537
|
+
let index = skipOWS(header2, 0, header2.length);
|
|
66379
68538
|
const typeStart = index;
|
|
66380
|
-
index = parseToken(
|
|
66381
|
-
const typeEnd = trailingOWS(
|
|
66382
|
-
const type =
|
|
68539
|
+
index = parseToken(header2, index, len);
|
|
68540
|
+
const typeEnd = trailingOWS(header2, typeStart, index);
|
|
68541
|
+
const type = header2.slice(typeStart, typeEnd).toLowerCase();
|
|
66383
68542
|
const parameters = new NullObject();
|
|
66384
68543
|
parameter: while (index < len) {
|
|
66385
|
-
index = skipOWS(
|
|
68544
|
+
index = skipOWS(header2, index + 1, len);
|
|
66386
68545
|
const keyStart = index;
|
|
66387
68546
|
while (index < len) {
|
|
66388
|
-
const char =
|
|
68547
|
+
const char = header2.charCodeAt(index);
|
|
66389
68548
|
if (char === SEMI)
|
|
66390
68549
|
continue parameter;
|
|
66391
68550
|
if (char === EQ) {
|
|
66392
|
-
const keyEnd = trailingOWS(
|
|
66393
|
-
const key =
|
|
66394
|
-
index = skipOWS(
|
|
66395
|
-
if (index < len &&
|
|
68551
|
+
const keyEnd = trailingOWS(header2, keyStart, index);
|
|
68552
|
+
const key = header2.slice(keyStart, keyEnd).toLowerCase();
|
|
68553
|
+
index = skipOWS(header2, index + 1, len);
|
|
68554
|
+
if (index < len && header2.charCodeAt(index) === DQUOTE) {
|
|
66396
68555
|
index++;
|
|
66397
68556
|
let value2 = "";
|
|
66398
68557
|
if (multipart) {
|
|
66399
68558
|
while (index < len) {
|
|
66400
|
-
const code =
|
|
68559
|
+
const code = header2.charCodeAt(index++);
|
|
66401
68560
|
if (code === DQUOTE) {
|
|
66402
|
-
index = parseToken(
|
|
68561
|
+
index = parseToken(header2, index, len);
|
|
66403
68562
|
if (parameters[key] === void 0)
|
|
66404
68563
|
parameters[key] = value2;
|
|
66405
68564
|
break;
|
|
66406
68565
|
}
|
|
66407
68566
|
if (code === /* % */
|
|
66408
68567
|
37 && index + 1 < len) {
|
|
66409
|
-
const code2 =
|
|
66410
|
-
const code3 =
|
|
68568
|
+
const code2 = header2.charCodeAt(index);
|
|
68569
|
+
const code3 = header2.charCodeAt(index + 1);
|
|
66411
68570
|
if (code2 === 50 && code3 === 50) {
|
|
66412
68571
|
value2 += '"';
|
|
66413
68572
|
index += 2;
|
|
@@ -66430,15 +68589,15 @@ function parse4(header, options2) {
|
|
|
66430
68589
|
}
|
|
66431
68590
|
} else {
|
|
66432
68591
|
while (index < len) {
|
|
66433
|
-
const code =
|
|
68592
|
+
const code = header2.charCodeAt(index++);
|
|
66434
68593
|
if (code === DQUOTE) {
|
|
66435
|
-
index = parseToken(
|
|
68594
|
+
index = parseToken(header2, index, len);
|
|
66436
68595
|
if (parameters[key] === void 0)
|
|
66437
68596
|
parameters[key] = value2;
|
|
66438
68597
|
break;
|
|
66439
68598
|
}
|
|
66440
68599
|
if (code === BSLASH && index < len) {
|
|
66441
|
-
value2 +=
|
|
68600
|
+
value2 += header2[index++];
|
|
66442
68601
|
continue;
|
|
66443
68602
|
}
|
|
66444
68603
|
value2 += String.fromCharCode(code);
|
|
@@ -66447,9 +68606,9 @@ function parse4(header, options2) {
|
|
|
66447
68606
|
continue parameter;
|
|
66448
68607
|
}
|
|
66449
68608
|
const valueStart = index;
|
|
66450
|
-
index = parseToken(
|
|
66451
|
-
const valueEnd = trailingOWS(
|
|
66452
|
-
const value =
|
|
68609
|
+
index = parseToken(header2, index, len);
|
|
68610
|
+
const valueEnd = trailingOWS(header2, valueStart, index);
|
|
68611
|
+
const value = header2.slice(valueStart, valueEnd);
|
|
66453
68612
|
if (parameters[key] === void 0) {
|
|
66454
68613
|
parameters[key] = value;
|
|
66455
68614
|
if (extended2 && key.charCodeAt(key.length - 1) === ASTERISK) {
|
|
@@ -67855,9 +70014,9 @@ var require_static = __commonJS({
|
|
|
67855
70014
|
}
|
|
67856
70015
|
function getEncodingHeader(headers, checked) {
|
|
67857
70016
|
if (!("accept-encoding" in headers)) return;
|
|
67858
|
-
const
|
|
70017
|
+
const header2 = headers["accept-encoding"].toLowerCase().replace(asteriskRegex, "gzip");
|
|
67859
70018
|
return encodingNegotiator.negotiate(
|
|
67860
|
-
|
|
70019
|
+
header2,
|
|
67861
70020
|
supportedEncodings.filter((enc) => !checked.has(enc))
|
|
67862
70021
|
);
|
|
67863
70022
|
}
|
|
@@ -70074,7 +72233,7 @@ var require_extension = __commonJS({
|
|
|
70074
72233
|
if (dest[name] === void 0) dest[name] = [elem];
|
|
70075
72234
|
else dest[name].push(elem);
|
|
70076
72235
|
}
|
|
70077
|
-
function parse5(
|
|
72236
|
+
function parse5(header2) {
|
|
70078
72237
|
const offers = /* @__PURE__ */ Object.create(null);
|
|
70079
72238
|
let params = /* @__PURE__ */ Object.create(null);
|
|
70080
72239
|
let mustUnescape = false;
|
|
@@ -70086,8 +72245,8 @@ var require_extension = __commonJS({
|
|
|
70086
72245
|
let code = -1;
|
|
70087
72246
|
let end2 = -1;
|
|
70088
72247
|
let i = 0;
|
|
70089
|
-
for (; i <
|
|
70090
|
-
code =
|
|
72248
|
+
for (; i < header2.length; i++) {
|
|
72249
|
+
code = header2.charCodeAt(i);
|
|
70091
72250
|
if (extensionName === void 0) {
|
|
70092
72251
|
if (end2 === -1 && tokenChars[code] === 1) {
|
|
70093
72252
|
if (start === -1) start = i;
|
|
@@ -70098,7 +72257,7 @@ var require_extension = __commonJS({
|
|
|
70098
72257
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
70099
72258
|
}
|
|
70100
72259
|
if (end2 === -1) end2 = i;
|
|
70101
|
-
const name =
|
|
72260
|
+
const name = header2.slice(start, end2);
|
|
70102
72261
|
if (code === 44) {
|
|
70103
72262
|
push(offers, name, params);
|
|
70104
72263
|
params = /* @__PURE__ */ Object.create(null);
|
|
@@ -70119,7 +72278,7 @@ var require_extension = __commonJS({
|
|
|
70119
72278
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
70120
72279
|
}
|
|
70121
72280
|
if (end2 === -1) end2 = i;
|
|
70122
|
-
push(params,
|
|
72281
|
+
push(params, header2.slice(start, end2), true);
|
|
70123
72282
|
if (code === 44) {
|
|
70124
72283
|
push(offers, extensionName, params);
|
|
70125
72284
|
params = /* @__PURE__ */ Object.create(null);
|
|
@@ -70127,7 +72286,7 @@ var require_extension = __commonJS({
|
|
|
70127
72286
|
}
|
|
70128
72287
|
start = end2 = -1;
|
|
70129
72288
|
} else if (code === 61 && start !== -1 && end2 === -1) {
|
|
70130
|
-
paramName =
|
|
72289
|
+
paramName = header2.slice(start, i);
|
|
70131
72290
|
start = end2 = -1;
|
|
70132
72291
|
} else {
|
|
70133
72292
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
@@ -70151,7 +72310,7 @@ var require_extension = __commonJS({
|
|
|
70151
72310
|
} else {
|
|
70152
72311
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
70153
72312
|
}
|
|
70154
|
-
} else if (code === 34 &&
|
|
72313
|
+
} else if (code === 34 && header2.charCodeAt(i - 1) === 61) {
|
|
70155
72314
|
inQuotes = true;
|
|
70156
72315
|
} else if (end2 === -1 && tokenChars[code] === 1) {
|
|
70157
72316
|
if (start === -1) start = i;
|
|
@@ -70162,7 +72321,7 @@ var require_extension = __commonJS({
|
|
|
70162
72321
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
70163
72322
|
}
|
|
70164
72323
|
if (end2 === -1) end2 = i;
|
|
70165
|
-
let value =
|
|
72324
|
+
let value = header2.slice(start, end2);
|
|
70166
72325
|
if (mustUnescape) {
|
|
70167
72326
|
value = value.replace(/\\/g, "");
|
|
70168
72327
|
mustUnescape = false;
|
|
@@ -70184,7 +72343,7 @@ var require_extension = __commonJS({
|
|
|
70184
72343
|
throw new SyntaxError("Unexpected end of input");
|
|
70185
72344
|
}
|
|
70186
72345
|
if (end2 === -1) end2 = i;
|
|
70187
|
-
const token =
|
|
72346
|
+
const token = header2.slice(start, end2);
|
|
70188
72347
|
if (extensionName === void 0) {
|
|
70189
72348
|
push(offers, token, params);
|
|
70190
72349
|
} else {
|
|
@@ -71230,13 +73389,13 @@ var require_subprotocol = __commonJS({
|
|
|
71230
73389
|
"node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/subprotocol.js"(exports, module) {
|
|
71231
73390
|
"use strict";
|
|
71232
73391
|
var { tokenChars } = require_validation2();
|
|
71233
|
-
function parse5(
|
|
73392
|
+
function parse5(header2) {
|
|
71234
73393
|
const protocols = /* @__PURE__ */ new Set();
|
|
71235
73394
|
let start = -1;
|
|
71236
73395
|
let end2 = -1;
|
|
71237
73396
|
let i = 0;
|
|
71238
|
-
for (i; i <
|
|
71239
|
-
const code =
|
|
73397
|
+
for (i; i < header2.length; i++) {
|
|
73398
|
+
const code = header2.charCodeAt(i);
|
|
71240
73399
|
if (end2 === -1 && tokenChars[code] === 1) {
|
|
71241
73400
|
if (start === -1) start = i;
|
|
71242
73401
|
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
@@ -71246,7 +73405,7 @@ var require_subprotocol = __commonJS({
|
|
|
71246
73405
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
71247
73406
|
}
|
|
71248
73407
|
if (end2 === -1) end2 = i;
|
|
71249
|
-
const protocol2 =
|
|
73408
|
+
const protocol2 = header2.slice(start, end2);
|
|
71250
73409
|
if (protocols.has(protocol2)) {
|
|
71251
73410
|
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
71252
73411
|
}
|
|
@@ -71259,7 +73418,7 @@ var require_subprotocol = __commonJS({
|
|
|
71259
73418
|
if (start === -1 || end2 !== -1) {
|
|
71260
73419
|
throw new SyntaxError("Unexpected end of input");
|
|
71261
73420
|
}
|
|
71262
|
-
const protocol =
|
|
73421
|
+
const protocol = header2.slice(start, i);
|
|
71263
73422
|
if (protocols.has(protocol)) {
|
|
71264
73423
|
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
71265
73424
|
}
|
|
@@ -84876,11 +87035,11 @@ var require_pino = __commonJS({
|
|
|
84876
87035
|
depthLimit: 5,
|
|
84877
87036
|
edgeLimit: 100
|
|
84878
87037
|
};
|
|
84879
|
-
var
|
|
87038
|
+
var normalize3 = createArgsNormalizer(defaultOptions2);
|
|
84880
87039
|
var serializers = Object.assign(/* @__PURE__ */ Object.create(null), stdSerializers);
|
|
84881
87040
|
function pino(...args) {
|
|
84882
87041
|
const instance = {};
|
|
84883
|
-
const { opts, stream } =
|
|
87042
|
+
const { opts, stream } = normalize3(instance, caller(), ...args);
|
|
84884
87043
|
if (opts.level && typeof opts.level === "string" && DEFAULT_LEVELS[opts.level.toLowerCase()] !== void 0) opts.level = opts.level.toLowerCase();
|
|
84885
87044
|
const {
|
|
84886
87045
|
redact: redact2,
|
|
@@ -86315,17 +88474,17 @@ var require_reply = __commonJS({
|
|
|
86315
88474
|
const req = reply.request;
|
|
86316
88475
|
if (reply[kReplyTrailers] !== null) {
|
|
86317
88476
|
const trailerHeaders = Object.keys(reply[kReplyTrailers]);
|
|
86318
|
-
let
|
|
88477
|
+
let header2 = "";
|
|
86319
88478
|
for (const trailerName of trailerHeaders) {
|
|
86320
88479
|
if (typeof reply[kReplyTrailers][trailerName] !== "function") continue;
|
|
86321
|
-
|
|
86322
|
-
|
|
88480
|
+
header2 += " ";
|
|
88481
|
+
header2 += trailerName;
|
|
86323
88482
|
}
|
|
86324
|
-
if (
|
|
88483
|
+
if (header2 !== "") {
|
|
86325
88484
|
if (!isHttp2Reply(reply)) {
|
|
86326
88485
|
reply.header("Transfer-Encoding", "chunked");
|
|
86327
88486
|
}
|
|
86328
|
-
reply.header("Trailer",
|
|
88487
|
+
reply.header("Trailer", header2.trim());
|
|
86329
88488
|
} else {
|
|
86330
88489
|
reply[kReplyTrailers] = null;
|
|
86331
88490
|
}
|
|
@@ -86693,35 +88852,35 @@ var require_forwarded = __commonJS({
|
|
|
86693
88852
|
if (!req) {
|
|
86694
88853
|
throw new TypeError("argument req is required");
|
|
86695
88854
|
}
|
|
86696
|
-
const
|
|
88855
|
+
const header2 = req.headers["x-forwarded-for"];
|
|
86697
88856
|
const socketAddr = req.socket.remoteAddress;
|
|
86698
|
-
if (!
|
|
88857
|
+
if (!header2 || typeof header2 !== "string") {
|
|
86699
88858
|
return [socketAddr];
|
|
86700
|
-
} else if (
|
|
86701
|
-
const remote =
|
|
88859
|
+
} else if (header2.indexOf(",") === -1) {
|
|
88860
|
+
const remote = header2.trim();
|
|
86702
88861
|
return remote.length ? [socketAddr, remote] : [socketAddr];
|
|
86703
88862
|
} else {
|
|
86704
|
-
return parse5(
|
|
88863
|
+
return parse5(header2, socketAddr);
|
|
86705
88864
|
}
|
|
86706
88865
|
}
|
|
86707
|
-
function parse5(
|
|
88866
|
+
function parse5(header2, socketAddr) {
|
|
86708
88867
|
const result2 = [socketAddr];
|
|
86709
|
-
let end2 =
|
|
88868
|
+
let end2 = header2.length;
|
|
86710
88869
|
let start = end2;
|
|
86711
88870
|
let char;
|
|
86712
88871
|
let i;
|
|
86713
88872
|
for (i = end2 - 1; i >= 0; --i) {
|
|
86714
|
-
char =
|
|
88873
|
+
char = header2[i];
|
|
86715
88874
|
if (char === " " || char === " ") {
|
|
86716
88875
|
start === end2 && (start = end2 = i);
|
|
86717
88876
|
} else if (char === ",") {
|
|
86718
|
-
start !== end2 && result2.push(
|
|
88877
|
+
start !== end2 && result2.push(header2.slice(start, end2));
|
|
86719
88878
|
start = end2 = i;
|
|
86720
88879
|
} else {
|
|
86721
88880
|
start = i;
|
|
86722
88881
|
}
|
|
86723
88882
|
}
|
|
86724
|
-
start !== end2 && result2.push(
|
|
88883
|
+
start !== end2 && result2.push(header2.substring(start, end2));
|
|
86725
88884
|
return result2;
|
|
86726
88885
|
}
|
|
86727
88886
|
module.exports = forwarded;
|
|
@@ -91316,7 +93475,7 @@ var require_fast_uri2 = __commonJS({
|
|
|
91316
93475
|
}
|
|
91317
93476
|
return decodedScheme;
|
|
91318
93477
|
}
|
|
91319
|
-
function
|
|
93478
|
+
function normalize3(uri, options2) {
|
|
91320
93479
|
if (typeof uri === "string") {
|
|
91321
93480
|
uri = /** @type {T} */
|
|
91322
93481
|
normalizeString(uri, options2);
|
|
@@ -91709,7 +93868,7 @@ var require_fast_uri2 = __commonJS({
|
|
|
91709
93868
|
}
|
|
91710
93869
|
var fastUri = {
|
|
91711
93870
|
SCHEMES,
|
|
91712
|
-
normalize:
|
|
93871
|
+
normalize: normalize3,
|
|
91713
93872
|
resolve: resolve9,
|
|
91714
93873
|
resolveComponent,
|
|
91715
93874
|
equal,
|
|
@@ -99431,13 +101590,13 @@ Content-Disposition: form-data`;
|
|
|
99431
101590
|
yield textEncoder.encode(`${normalizeLinefeeds(value)}\r
|
|
99432
101591
|
`);
|
|
99433
101592
|
} else {
|
|
99434
|
-
let
|
|
99435
|
-
value.name && (
|
|
99436
|
-
|
|
101593
|
+
let header2 = `${prefix}; name="${escape2(normalizeLinefeeds(name))}"`;
|
|
101594
|
+
value.name && (header2 += `; filename="${escape2(value.name)}"`);
|
|
101595
|
+
header2 += `\r
|
|
99437
101596
|
Content-Type: ${value.type || "application/octet-stream"}\r
|
|
99438
101597
|
\r
|
|
99439
101598
|
`;
|
|
99440
|
-
yield textEncoder.encode(
|
|
101599
|
+
yield textEncoder.encode(header2);
|
|
99441
101600
|
if (value.stream) {
|
|
99442
101601
|
yield* value.stream();
|
|
99443
101602
|
} else {
|
|
@@ -99562,8 +101721,8 @@ var require_request2 = __commonJS({
|
|
|
99562
101721
|
if (payload && !payloadResume && !Object.hasOwn(this.headers, "content-length")) {
|
|
99563
101722
|
this.headers["content-length"] = (Buffer.isBuffer(payload) ? payload.length : Buffer.byteLength(payload)).toString();
|
|
99564
101723
|
}
|
|
99565
|
-
for (const
|
|
99566
|
-
this.rawHeaders.push(
|
|
101724
|
+
for (const header2 of Object.keys(this.headers)) {
|
|
101725
|
+
this.rawHeaders.push(header2, this.headers[header2]);
|
|
99567
101726
|
}
|
|
99568
101727
|
this._lightMyRequest = {
|
|
99569
101728
|
payload,
|
|
@@ -102077,7 +104236,7 @@ function unresolvedName(ctx, r, verb) {
|
|
|
102077
104236
|
...r.near.length ? { note: "Functions with similar names are listed." } : {}
|
|
102078
104237
|
};
|
|
102079
104238
|
}
|
|
102080
|
-
function
|
|
104239
|
+
function normalize2(question) {
|
|
102081
104240
|
return question.trim().replace(/\s+/g, " ").replace(/^(?:please\s+|can you\s+|could you\s+)?(?:tell me\s+|show me\s+(?=the\s+))?/i, "").replace(/[?!.\s]+$/, "");
|
|
102082
104241
|
}
|
|
102083
104242
|
function repositoryOf(text, sources) {
|
|
@@ -102091,7 +104250,7 @@ function repositoryOf(text, sources) {
|
|
|
102091
104250
|
return hit ? { source: hit.id, text: m[1] } : null;
|
|
102092
104251
|
}
|
|
102093
104252
|
function answerWithGrammar(engine, project2, question, options2 = {}) {
|
|
102094
|
-
let text =
|
|
104253
|
+
let text = normalize2(question);
|
|
102095
104254
|
let sources = [];
|
|
102096
104255
|
try {
|
|
102097
104256
|
sources = engine.listSources({ project: project2 }).sources;
|
|
@@ -102107,7 +104266,7 @@ function answerWithGrammar(engine, project2, question, options2 = {}) {
|
|
|
102107
104266
|
const name = new Map(sources.map((s) => [s.id, s.name ?? s.id]));
|
|
102108
104267
|
const answer = run2(text, source);
|
|
102109
104268
|
if (answer !== void 0) return answer;
|
|
102110
|
-
return named ? run2(
|
|
104269
|
+
return named ? run2(normalize2(question), scope2) ?? null : null;
|
|
102111
104270
|
function run2(text2, source2) {
|
|
102112
104271
|
for (const intent of INTENTS)
|
|
102113
104272
|
for (const pattern of intent.patterns) {
|
|
@@ -102702,6 +104861,7 @@ var init_grammar = __esm({
|
|
|
102702
104861
|
"dynamic-dispatch": "type unknown",
|
|
102703
104862
|
reflection: "reflection",
|
|
102704
104863
|
"imported-symbol": "imported",
|
|
104864
|
+
"package-symbol": "in its package",
|
|
102705
104865
|
"runtime-global": "built-in",
|
|
102706
104866
|
"builtin-value": "on a built-in value",
|
|
102707
104867
|
"template-binding": "awaiting its component",
|
|
@@ -103334,7 +105494,7 @@ __export(src_exports3, {
|
|
|
103334
105494
|
configPath: () => configPath,
|
|
103335
105495
|
loadSettings: () => loadSettings,
|
|
103336
105496
|
nameRepositories: () => nameRepositories,
|
|
103337
|
-
normalize: () =>
|
|
105497
|
+
normalize: () => normalize2,
|
|
103338
105498
|
publicSettings: () => publicSettings,
|
|
103339
105499
|
repositoryOf: () => repositoryOf,
|
|
103340
105500
|
saveSettings: () => saveSettings,
|
|
@@ -104580,8 +106740,10 @@ Usage:
|
|
|
104580
106740
|
the license in force; install a license key (from a file,
|
|
104581
106741
|
or "-" for stdin); check the installed one again (offline)
|
|
104582
106742
|
veoflow check [<file|folder>] [--json] [--project <id>]
|
|
104583
|
-
|
|
104584
|
-
|
|
106743
|
+
a reference checker's second opinion (the TypeScript compiler;
|
|
106744
|
+
Pyright for Python; go/types for Go, with scip-go installed):
|
|
106745
|
+
each call site where it and veoflow
|
|
106746
|
+
disagree, with both answers
|
|
104585
106747
|
veoflow report <file>:<line> [--include-code] [--out <file>] [--force] [--project <id>]
|
|
104586
106748
|
a bundle to reproduce an analysis bug there (no source code
|
|
104587
106749
|
unless --include-code); review it before sharing it
|
|
@@ -104652,7 +106814,7 @@ function describeCheck(r, cwd, projectFlag) {
|
|
|
104652
106814
|
const disagree1 = s1["different-callee"] + s1["adapter-only"] + s1["checker-only"];
|
|
104653
106815
|
const disagree2 = s2["different-callee"] + s2["checker-only"];
|
|
104654
106816
|
out.push(
|
|
104655
|
-
`checked ${r.source}${r.path ? `:${r.path}` : ""} (${r.files} files) with the TypeScript compiler (scip-typescript)`
|
|
106817
|
+
`checked ${r.source}${r.path ? `:${r.path}` : ""} (${r.files} files) with ${r.checker === "scip-python" ? "Pyright (scip-python)" : r.checker === "scip-go" ? "go/types (scip-go)" : "the TypeScript compiler (scip-typescript)"}`
|
|
104656
106818
|
);
|
|
104657
106819
|
out.push(
|
|
104658
106820
|
` calls within files (Stage 1): ${s1.agree} agree, ${disagree1} disagree; ${s1.outside} resolve outside the source (not compared)`
|
|
@@ -105335,7 +107497,7 @@ try: ${answer.suggestions.join(" \xB7 ")}`);
|
|
|
105335
107497
|
throw new UsageError("usage: veoflow check [<file|folder>] [--json] [--project <id>]");
|
|
105336
107498
|
const project2 = pickProject(engine, values.project, io.cwd);
|
|
105337
107499
|
const path = positionals[0] ?? ".";
|
|
105338
|
-
io.err("running the
|
|
107500
|
+
io.err("running the reference checker over the source (this can take a while)\u2026");
|
|
105339
107501
|
const r = await checkCode(engine, { project: project2, path }, io.cwd);
|
|
105340
107502
|
if (values.json) io.out(JSON.stringify(r, null, 2));
|
|
105341
107503
|
else for (const line of describeCheck(r, io.cwd, values.project)) io.out(line);
|
|
@@ -105429,7 +107591,7 @@ try: ${answer.suggestions.join(" \xB7 ")}`);
|
|
|
105429
107591
|
);
|
|
105430
107592
|
io.out(` ${flat(item.summary)}`);
|
|
105431
107593
|
const steps = item.steps[0]?.detail === item.summary ? item.steps.slice(1) : item.steps;
|
|
105432
|
-
for (const [i,
|
|
107594
|
+
for (const [i, step2] of steps.entries()) io.out(` ${i + 1}. ${flat(step2.detail)}`);
|
|
105433
107595
|
for (const c of item.candidates ?? []) io.out(` could be ${c.name} (${c.path})`);
|
|
105434
107596
|
if (item.toResolve) io.out(` to resolve it: ${flat(item.toResolve, 400)}`);
|
|
105435
107597
|
}
|