@aryam/fixmap-core 0.9.1 → 0.9.2
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/README.md +51 -1
- package/dist/annotation-store.d.ts +5 -0
- package/dist/annotation-store.js +117 -0
- package/dist/annotation-store.js.map +1 -0
- package/dist/annotations.d.ts +57 -0
- package/dist/annotations.js +221 -0
- package/dist/annotations.js.map +1 -0
- package/dist/architecture-history.d.ts +33 -0
- package/dist/architecture-history.js +234 -0
- package/dist/architecture-history.js.map +1 -0
- package/dist/architecture.d.ts +124 -0
- package/dist/architecture.js +348 -0
- package/dist/architecture.js.map +1 -0
- package/dist/artifacts.d.ts +9 -0
- package/dist/artifacts.js +82 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/ask.d.ts +48 -0
- package/dist/ask.js +182 -0
- package/dist/ask.js.map +1 -0
- package/dist/browser.d.ts +66 -3
- package/dist/browser.js +34 -2
- package/dist/browser.js.map +1 -1
- package/dist/capabilities.d.ts +39 -0
- package/dist/capabilities.js +172 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/capability-history.d.ts +49 -0
- package/dist/capability-history.js +176 -0
- package/dist/capability-history.js.map +1 -0
- package/dist/change-conflicts.d.ts +34 -0
- package/dist/change-conflicts.js +140 -0
- package/dist/change-conflicts.js.map +1 -0
- package/dist/change-scope.d.ts +81 -0
- package/dist/change-scope.js +316 -0
- package/dist/change-scope.js.map +1 -0
- package/dist/characterization.d.ts +61 -0
- package/dist/characterization.js +169 -0
- package/dist/characterization.js.map +1 -0
- package/dist/ci-matrix.d.ts +53 -0
- package/dist/ci-matrix.js +170 -0
- package/dist/ci-matrix.js.map +1 -0
- package/dist/compare.js +2 -2
- package/dist/compare.js.map +1 -1
- package/dist/composer-projects.d.ts +32 -0
- package/dist/composer-projects.js +246 -0
- package/dist/composer-projects.js.map +1 -0
- package/dist/context.d.ts +1 -1
- package/dist/context.js +26 -4
- package/dist/context.js.map +1 -1
- package/dist/contracts.d.ts +75 -0
- package/dist/contracts.js +526 -0
- package/dist/contracts.js.map +1 -0
- package/dist/custom-language-context.d.ts +43 -0
- package/dist/custom-language-context.js +89 -0
- package/dist/custom-language-context.js.map +1 -0
- package/dist/decisions.d.ts +64 -0
- package/dist/decisions.js +338 -0
- package/dist/decisions.js.map +1 -0
- package/dist/dossier.d.ts +63 -0
- package/dist/dossier.js +176 -0
- package/dist/dossier.js.map +1 -0
- package/dist/dotnet-projects.d.ts +26 -0
- package/dist/dotnet-projects.js +171 -0
- package/dist/dotnet-projects.js.map +1 -0
- package/dist/editor-loader.d.ts +9 -0
- package/dist/editor-loader.js +18 -0
- package/dist/editor-loader.js.map +1 -0
- package/dist/editor-protocol.d.ts +35 -0
- package/dist/editor-protocol.js +200 -0
- package/dist/editor-protocol.js.map +1 -0
- package/dist/editor-session.d.ts +15 -0
- package/dist/editor-session.js +27 -0
- package/dist/editor-session.js.map +1 -0
- package/dist/editor-transport.d.ts +10 -0
- package/dist/editor-transport.js +75 -0
- package/dist/editor-transport.js.map +1 -0
- package/dist/enterprise-policy.d.ts +82 -0
- package/dist/enterprise-policy.js +170 -0
- package/dist/enterprise-policy.js.map +1 -0
- package/dist/evidence-bundle.d.ts +13 -0
- package/dist/evidence-bundle.js +105 -0
- package/dist/evidence-bundle.js.map +1 -0
- package/dist/evidence.d.ts +125 -0
- package/dist/evidence.js +252 -0
- package/dist/evidence.js.map +1 -0
- package/dist/explain.js +7 -0
- package/dist/explain.js.map +1 -1
- package/dist/go-projects.d.ts +22 -0
- package/dist/go-projects.js +146 -0
- package/dist/go-projects.js.map +1 -0
- package/dist/graph.js +9 -0
- package/dist/graph.js.map +1 -1
- package/dist/grounding.d.ts +4 -1
- package/dist/grounding.js +70 -13
- package/dist/grounding.js.map +1 -1
- package/dist/identity-graph.d.ts +106 -0
- package/dist/identity-graph.js +353 -0
- package/dist/identity-graph.js.map +1 -0
- package/dist/impact.d.ts +2 -1
- package/dist/impact.js +12 -4
- package/dist/impact.js.map +1 -1
- package/dist/import-graph.d.ts +7 -1
- package/dist/import-graph.js +616 -34
- package/dist/import-graph.js.map +1 -1
- package/dist/incident.d.ts +74 -0
- package/dist/incident.js +212 -0
- package/dist/incident.js.map +1 -0
- package/dist/index.d.ts +91 -4
- package/dist/index.js +47 -3
- package/dist/index.js.map +1 -1
- package/dist/language-adapters.d.ts +33 -0
- package/dist/language-adapters.js +390 -0
- package/dist/language-adapters.js.map +1 -0
- package/dist/language-registry.d.ts +26 -0
- package/dist/language-registry.js +57 -0
- package/dist/language-registry.js.map +1 -0
- package/dist/languages.d.ts +20 -5
- package/dist/languages.js +197 -19
- package/dist/languages.js.map +1 -1
- package/dist/markdown.d.ts +1 -0
- package/dist/markdown.js +7 -1
- package/dist/markdown.js.map +1 -1
- package/dist/migration.d.ts +56 -0
- package/dist/migration.js +154 -0
- package/dist/migration.js.map +1 -0
- package/dist/outcomes.d.ts +57 -0
- package/dist/outcomes.js +146 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/ownership.d.ts +29 -0
- package/dist/ownership.js +189 -0
- package/dist/ownership.js.map +1 -0
- package/dist/plan-alternatives.d.ts +74 -0
- package/dist/plan-alternatives.js +205 -0
- package/dist/plan-alternatives.js.map +1 -0
- package/dist/plan.d.ts +7 -0
- package/dist/plan.js +41 -8
- package/dist/plan.js.map +1 -1
- package/dist/rank.d.ts +64 -1
- package/dist/rank.js +278 -26
- package/dist/rank.js.map +1 -1
- package/dist/repo-scan.d.ts +8 -1
- package/dist/repo-scan.js +341 -97
- package/dist/repo-scan.js.map +1 -1
- package/dist/report.d.ts +16 -0
- package/dist/report.js +298 -33
- package/dist/report.js.map +1 -1
- package/dist/retrieval.d.ts +37 -0
- package/dist/retrieval.js +150 -21
- package/dist/retrieval.js.map +1 -1
- package/dist/reverse-docs.d.ts +46 -0
- package/dist/reverse-docs.js +179 -0
- package/dist/reverse-docs.js.map +1 -0
- package/dist/ruby-projects.d.ts +20 -0
- package/dist/ruby-projects.js +114 -0
- package/dist/ruby-projects.js.map +1 -0
- package/dist/runtime-evidence.d.ts +90 -0
- package/dist/runtime-evidence.js +186 -0
- package/dist/runtime-evidence.js.map +1 -0
- package/dist/rust-projects.d.ts +17 -0
- package/dist/rust-projects.js +125 -0
- package/dist/rust-projects.js.map +1 -0
- package/dist/sandbox.d.ts +59 -0
- package/dist/sandbox.js +202 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/semantic-cache.d.ts +8 -0
- package/dist/semantic-cache.js +149 -0
- package/dist/semantic-cache.js.map +1 -0
- package/dist/semantic.d.ts +78 -0
- package/dist/semantic.js +237 -0
- package/dist/semantic.js.map +1 -0
- package/dist/sensitive-data.d.ts +8 -0
- package/dist/sensitive-data.js +157 -0
- package/dist/sensitive-data.js.map +1 -0
- package/dist/signals.js +1 -1
- package/dist/signals.js.map +1 -1
- package/dist/supply-chain.d.ts +38 -0
- package/dist/supply-chain.js +206 -0
- package/dist/supply-chain.js.map +1 -0
- package/dist/test-reliability.d.ts +56 -0
- package/dist/test-reliability.js +191 -0
- package/dist/test-reliability.js.map +1 -0
- package/dist/text.js +8 -1
- package/dist/text.js.map +1 -1
- package/dist/transformers-embedding.d.ts +16 -0
- package/dist/transformers-embedding.js +127 -0
- package/dist/transformers-embedding.js.map +1 -0
- package/dist/types.d.ts +79 -2
- package/dist/validate.js +172 -0
- package/dist/validate.js.map +1 -1
- package/dist/verify.js +136 -2
- package/dist/verify.js.map +1 -1
- package/dist/workspace.d.ts +86 -0
- package/dist/workspace.js +557 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +1 -1
package/dist/import-graph.js
CHANGED
|
@@ -1,52 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { extractLanguageDefinitions, extractLanguageImports, languageAdapterForFile } from "./language-adapters.js";
|
|
2
|
+
import { buildComposerProjects, composerDependencyClosure, resolveComposerSymbol } from "./composer-projects.js";
|
|
3
|
+
import { buildDotnetProjects, dotnetReferenceClosure } from "./dotnet-projects.js";
|
|
4
|
+
import { buildRustProjects, rustPathDependency, rustProjectForPath } from "./rust-projects.js";
|
|
5
|
+
import { buildGoModules, buildGoWorkspaces, goModuleForPath, goReplacementForImport, goWorkspaceForModules } from "./go-projects.js";
|
|
6
|
+
import { buildRubyProjects, rubyProjectForPath } from "./ruby-projects.js";
|
|
5
7
|
const RESOLVE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs", ".vue", ".svelte"];
|
|
6
8
|
const COMPILED_TO_SOURCE = {
|
|
7
9
|
".js": [".ts", ".tsx"],
|
|
8
10
|
".mjs": [".mts"],
|
|
9
11
|
".cjs": [".cts"]
|
|
10
12
|
};
|
|
11
|
-
const SPECIFIER_PATTERNS = [
|
|
12
|
-
/\bimport\s+[^'"()]*?from\s*["']([^"'\n]+)["']/g,
|
|
13
|
-
/\bimport\s*["']([^"'\n]+)["']/g,
|
|
14
|
-
/\bexport\s+[^'"()]*?from\s*["']([^"'\n]+)["']/g,
|
|
15
|
-
/\brequire\s*\(\s*["']([^"'\n]+)["']\s*\)/g,
|
|
16
|
-
/\bimport\s*\(\s*["']([^"'\n]+)["']\s*\)/g
|
|
17
|
-
];
|
|
18
13
|
const MAX_GRAPH_FILES = 5_000;
|
|
19
14
|
const MAX_EDGES_PER_FILE = 200;
|
|
20
|
-
export function buildImportGraph(files) {
|
|
21
|
-
const allParseable = files.filter((file) =>
|
|
15
|
+
export function buildImportGraph(files, custom) {
|
|
16
|
+
const allParseable = files.filter((file) => (languageAdapterForFile(file) || custom?.supports(file.extension)) && file.textSample.length > 0);
|
|
22
17
|
const parseable = allParseable.slice(0, MAX_GRAPH_FILES);
|
|
23
|
-
const
|
|
18
|
+
const dotnetProjects = buildDotnetProjects(files);
|
|
19
|
+
const composerProjects = buildComposerProjects(files);
|
|
20
|
+
const rustProjects = buildRustProjects(files);
|
|
21
|
+
const hasRailsGem = files.some((file) => file.path.split("/").pop()?.toLowerCase() === "gemfile" &&
|
|
22
|
+
/^\s*gem\s*(?:\(|\s)\s*["']rails["']/im.test(file.textSample));
|
|
23
|
+
const hasRailsApplication = files.some((file) => /(?:^|\/)config\/application\.rb$/i.test(file.path) &&
|
|
24
|
+
/\bclass\s+Application\s*<\s*Rails::Application\b/.test(file.textSample));
|
|
25
|
+
const rubyProjects = hasRailsGem && hasRailsApplication ? buildRubyProjects(files) : [];
|
|
26
|
+
const goModules = buildGoModules(files);
|
|
27
|
+
const goWorkspaces = buildGoWorkspaces(files, goModules);
|
|
28
|
+
const resolverIndex = buildResolverIndex(files, dotnetProjects, composerProjects, rustProjects, rubyProjects, goModules, goWorkspaces);
|
|
24
29
|
const aliases = buildAliases(files);
|
|
25
30
|
const workspacePackages = buildWorkspacePackages(files);
|
|
26
31
|
const imports = new Map();
|
|
27
32
|
const importedBy = new Map();
|
|
28
33
|
let truncatedEdges = 0;
|
|
34
|
+
const customDiagnostics = [];
|
|
35
|
+
const candidatePaths = files.map((file) => file.path);
|
|
36
|
+
function* targetGroups(file) {
|
|
37
|
+
if (custom?.supports(file.extension)) {
|
|
38
|
+
const extraction = custom.extract(file);
|
|
39
|
+
if (extraction.status === "failed") {
|
|
40
|
+
if (customDiagnostics.length < MAX_GRAPH_FILES)
|
|
41
|
+
customDiagnostics.push({ path: file.path, adapter: extraction.adapter, code: extraction.code });
|
|
42
|
+
}
|
|
43
|
+
else if (extraction.status === "ok") {
|
|
44
|
+
for (const imported of extraction.facts.imports) {
|
|
45
|
+
const resolved = custom.resolve(file.extension, file.path, imported, candidatePaths);
|
|
46
|
+
if (resolved.status === "failed") {
|
|
47
|
+
if (customDiagnostics.length < MAX_GRAPH_FILES)
|
|
48
|
+
customDiagnostics.push({ path: file.path, adapter: resolved.adapter, code: resolved.code });
|
|
49
|
+
}
|
|
50
|
+
else if (resolved.status === "ok")
|
|
51
|
+
yield resolved.targets;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
for (const imported of extractLanguageImports(file)) {
|
|
57
|
+
yield resolveLanguageImport(file.path, imported, resolverIndex, aliases, workspacePackages);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
29
60
|
for (const file of parseable) {
|
|
30
61
|
let edges = 0;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
62
|
+
let edgeTruncated = false;
|
|
63
|
+
importsLoop: for (const targets of targetGroups(file)) {
|
|
64
|
+
for (const target of targets) {
|
|
65
|
+
if (edges >= MAX_EDGES_PER_FILE) {
|
|
66
|
+
truncatedEdges += 1;
|
|
67
|
+
edgeTruncated = true;
|
|
68
|
+
break importsLoop;
|
|
69
|
+
}
|
|
70
|
+
if (target === file.path || imports.get(file.path)?.has(target))
|
|
71
|
+
continue;
|
|
72
|
+
addEdge(imports, file.path, target);
|
|
73
|
+
addEdge(importedBy, target, file.path);
|
|
74
|
+
edges += 1;
|
|
35
75
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
76
|
+
}
|
|
77
|
+
const dotnetProject = resolverIndex.dotnetProjectByFile.get(file.path);
|
|
78
|
+
if (!edgeTruncated && dotnetProject && file.path.toLowerCase().endsWith(".cs")) {
|
|
79
|
+
const identifiers = new Set(file.textSample.match(/\b[A-Za-z_][A-Za-z0-9_]*\b/g) ?? []);
|
|
80
|
+
const targetsBySymbol = resolverIndex.dotnetGlobalTargetsByProject.get(dotnetProject.path);
|
|
81
|
+
for (const identifier of identifiers) {
|
|
82
|
+
for (const target of targetsBySymbol?.get(identifier) ?? []) {
|
|
83
|
+
if (edges >= MAX_EDGES_PER_FILE) {
|
|
84
|
+
truncatedEdges += 1;
|
|
85
|
+
edgeTruncated = true;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (target === file.path || imports.get(file.path)?.has(target))
|
|
89
|
+
continue;
|
|
90
|
+
addEdge(imports, file.path, target);
|
|
91
|
+
addEdge(importedBy, target, file.path);
|
|
92
|
+
edges += 1;
|
|
93
|
+
}
|
|
94
|
+
if (edges >= MAX_EDGES_PER_FILE)
|
|
95
|
+
break;
|
|
39
96
|
}
|
|
40
|
-
addEdge(imports, file.path, target);
|
|
41
|
-
addEdge(importedBy, target, file.path);
|
|
42
|
-
edges += 1;
|
|
43
97
|
}
|
|
98
|
+
const rubyProject = resolverIndex.rubyProjectByFile.get(file.path);
|
|
99
|
+
if (!edgeTruncated && rubyProject && file.path.toLowerCase().endsWith(".rb")) {
|
|
100
|
+
const targetsBySymbol = resolverIndex.rubyAutoloadTargetsByProject.get(rubyProject.path);
|
|
101
|
+
for (const identifier of rubyConstantIdentifiers(file.textSample)) {
|
|
102
|
+
for (const target of targetsBySymbol?.get(identifier) ?? []) {
|
|
103
|
+
if (edges >= MAX_EDGES_PER_FILE) {
|
|
104
|
+
truncatedEdges += 1;
|
|
105
|
+
edgeTruncated = true;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (target === file.path || imports.get(file.path)?.has(target))
|
|
109
|
+
continue;
|
|
110
|
+
addEdge(imports, file.path, target);
|
|
111
|
+
addEdge(importedBy, target, file.path);
|
|
112
|
+
edges += 1;
|
|
113
|
+
}
|
|
114
|
+
if (edges >= MAX_EDGES_PER_FILE)
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
for (const project of dotnetProjects) {
|
|
120
|
+
for (const reference of project.references.slice(0, MAX_EDGES_PER_FILE)) {
|
|
121
|
+
addEdge(imports, project.path, reference);
|
|
122
|
+
addEdge(importedBy, reference, project.path);
|
|
123
|
+
}
|
|
124
|
+
truncatedEdges += Math.max(0, project.references.length - MAX_EDGES_PER_FILE);
|
|
125
|
+
}
|
|
126
|
+
for (const project of composerProjects) {
|
|
127
|
+
for (const dependency of project.pathDependencies.slice(0, MAX_EDGES_PER_FILE)) {
|
|
128
|
+
addEdge(imports, project.path, dependency.projectPath);
|
|
129
|
+
addEdge(importedBy, dependency.projectPath, project.path);
|
|
130
|
+
}
|
|
131
|
+
truncatedEdges += Math.max(0, project.pathDependencies.length - MAX_EDGES_PER_FILE);
|
|
44
132
|
}
|
|
45
133
|
return {
|
|
46
134
|
imports,
|
|
47
135
|
importedBy,
|
|
48
136
|
truncatedFiles: Math.max(0, allParseable.length - parseable.length),
|
|
49
|
-
truncatedEdges
|
|
137
|
+
truncatedEdges,
|
|
138
|
+
...(custom ? { customDiagnostics } : {})
|
|
50
139
|
};
|
|
51
140
|
}
|
|
52
141
|
export function findImportProximity(graph, seedPaths) {
|
|
@@ -81,17 +170,509 @@ function neighborsOf(graph, path) {
|
|
|
81
170
|
}
|
|
82
171
|
return neighbors;
|
|
83
172
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
173
|
+
function resolveLanguageImport(fromPath, imported, resolverIndex, aliases, workspacePackages) {
|
|
174
|
+
if (imported.adapter === "python") {
|
|
175
|
+
return resolvePythonImport(fromPath, imported, resolverIndex);
|
|
176
|
+
}
|
|
177
|
+
if (imported.adapter === "java") {
|
|
178
|
+
return resolveJavaImport(imported, resolverIndex);
|
|
179
|
+
}
|
|
180
|
+
if (imported.adapter === "go") {
|
|
181
|
+
return resolveGoImport(fromPath, imported, resolverIndex);
|
|
182
|
+
}
|
|
183
|
+
if (imported.adapter === "rust") {
|
|
184
|
+
return resolveRustImport(fromPath, imported, resolverIndex);
|
|
185
|
+
}
|
|
186
|
+
if (imported.adapter === "ruby") {
|
|
187
|
+
return resolveRubyImport(fromPath, imported, resolverIndex);
|
|
188
|
+
}
|
|
189
|
+
if (imported.adapter === "php") {
|
|
190
|
+
return resolvePhpImport(fromPath, imported, resolverIndex);
|
|
191
|
+
}
|
|
192
|
+
if (imported.adapter === "dotnet") {
|
|
193
|
+
return resolveDotnetImport(fromPath, imported, resolverIndex);
|
|
194
|
+
}
|
|
195
|
+
const target = resolveSpecifier(fromPath, imported.specifier, resolverIndex.repoPaths, aliases, workspacePackages);
|
|
196
|
+
return target ? [target] : [];
|
|
197
|
+
}
|
|
198
|
+
function resolvePythonImport(fromPath, imported, resolverIndex) {
|
|
199
|
+
const relativeMatch = /^(\.+)(.*)$/.exec(imported.specifier);
|
|
200
|
+
let roots;
|
|
201
|
+
if (relativeMatch?.[1] !== undefined) {
|
|
202
|
+
const base = fromPath.split("/").slice(0, -1);
|
|
203
|
+
const parentLevels = Math.max(0, relativeMatch[1].length - 1);
|
|
204
|
+
if (parentLevels > base.length)
|
|
205
|
+
return [];
|
|
206
|
+
const packageRoot = base.slice(0, base.length - parentLevels);
|
|
207
|
+
const moduleSegments = (relativeMatch[2] ?? "").split(".").filter(Boolean);
|
|
208
|
+
roots = [[...packageRoot, ...moduleSegments].join("/")];
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
const modulePath = imported.specifier.replace(/\./g, "/");
|
|
212
|
+
roots = [modulePath, `src/${modulePath}`];
|
|
213
|
+
}
|
|
214
|
+
const memberRoots = imported.importedNames
|
|
215
|
+
.filter((name) => name !== "*")
|
|
216
|
+
.flatMap((name) => roots.map((root) => root ? `${root}/${name}` : name));
|
|
217
|
+
const targets = new Set();
|
|
218
|
+
for (const root of [...memberRoots, ...roots]) {
|
|
219
|
+
for (const candidate of pythonCandidates(root, resolverIndex, !relativeMatch)) {
|
|
220
|
+
targets.add(candidate);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return [...targets].sort((a, b) => a.localeCompare(b));
|
|
224
|
+
}
|
|
225
|
+
function pythonCandidates(root, resolverIndex, allowSuffix) {
|
|
226
|
+
if (!root)
|
|
227
|
+
return [];
|
|
228
|
+
const suffixes = [`${root}.py`, `${root}.pyi`, `${root}/__init__.py`, `${root}/__init__.pyi`];
|
|
229
|
+
const exact = suffixes.filter((candidate) => resolverIndex.repoPaths.has(candidate));
|
|
230
|
+
if (exact.length > 0 || !allowSuffix)
|
|
231
|
+
return exact;
|
|
232
|
+
return [...new Set(suffixes.flatMap((suffix) => resolverIndex.suffixPaths.get(suffix) ?? []))]
|
|
233
|
+
.sort(shortestPathFirst)
|
|
234
|
+
.slice(0, 8);
|
|
235
|
+
}
|
|
236
|
+
function resolveJavaImport(imported, resolverIndex) {
|
|
237
|
+
const modulePath = imported.specifier.replace(/\./g, "/");
|
|
238
|
+
if (imported.wildcard) {
|
|
239
|
+
return [...(resolverIndex.javaPackagePaths.get(modulePath) ?? [])].sort(shortestPathFirst);
|
|
240
|
+
}
|
|
241
|
+
const suffix = `${modulePath}.java`;
|
|
242
|
+
const exact = resolverIndex.repoPaths.has(suffix) ? [suffix] : [];
|
|
243
|
+
return [...exact, ...(resolverIndex.suffixPaths.get(suffix) ?? [])]
|
|
244
|
+
.sort(shortestPathFirst)
|
|
245
|
+
.slice(0, 1);
|
|
246
|
+
}
|
|
247
|
+
function resolveGoImport(fromPath, imported, resolverIndex) {
|
|
248
|
+
const sourceModule = goModuleForPath(resolverIndex.goModules, fromPath);
|
|
249
|
+
const replacement = sourceModule ? goReplacementForImport(sourceModule, imported.specifier) : undefined;
|
|
250
|
+
if (replacement) {
|
|
251
|
+
const suffix = imported.specifier === replacement.module ? "" : imported.specifier.slice(replacement.module.length + 1);
|
|
252
|
+
const directory = [replacement.targetRoot, suffix].filter(Boolean).join("/");
|
|
253
|
+
return (resolverIndex.directoryPaths.get(directory) ?? [])
|
|
254
|
+
.filter((path) => path.endsWith(".go") && !path.endsWith("_test.go"))
|
|
255
|
+
.sort(shortestPathFirst)
|
|
256
|
+
.slice(0, 20);
|
|
257
|
+
}
|
|
258
|
+
const candidates = resolverIndex.goModules
|
|
259
|
+
.filter((entry) => imported.specifier === entry.name || imported.specifier.startsWith(`${entry.name}/`))
|
|
260
|
+
.sort((left, right) => right.name.length - left.name.length || left.path.localeCompare(right.path));
|
|
261
|
+
const longest = candidates[0]?.name.length;
|
|
262
|
+
const equallySpecific = candidates.filter((candidate) => candidate.name.length === longest);
|
|
263
|
+
const reachable = sourceModule
|
|
264
|
+
? equallySpecific.filter((candidate) => candidate.path === sourceModule.path ||
|
|
265
|
+
goWorkspaceForModules(resolverIndex.goWorkspaces, sourceModule.root, candidate.root) !== undefined)
|
|
266
|
+
: equallySpecific;
|
|
267
|
+
const module = reachable.length === 1 ? reachable[0] : undefined;
|
|
268
|
+
if (!module)
|
|
269
|
+
return [];
|
|
270
|
+
const suffix = imported.specifier === module.name ? "" : imported.specifier.slice(module.name.length + 1);
|
|
271
|
+
const directory = [module.root, suffix].filter(Boolean).join("/");
|
|
272
|
+
return (resolverIndex.directoryPaths.get(directory) ?? [])
|
|
273
|
+
.filter((path) => path.endsWith(".go") && !path.endsWith("_test.go"))
|
|
274
|
+
.sort(shortestPathFirst)
|
|
275
|
+
.slice(0, 20);
|
|
276
|
+
}
|
|
277
|
+
function resolveRustImport(fromPath, imported, resolverIndex) {
|
|
278
|
+
if (imported.specifier.startsWith("file:")) {
|
|
279
|
+
const raw = imported.specifier.slice("file:".length);
|
|
280
|
+
const target = normalizeSegments(`${fromPath.split("/").slice(0, -1).join("/")}/${raw}`);
|
|
281
|
+
if (!target)
|
|
282
|
+
return [];
|
|
283
|
+
return resolverIndex.repoPaths.has(target) ? [target] : resolverIndex.repoPaths.has(`${target}.rs`) ? [`${target}.rs`] : [];
|
|
284
|
+
}
|
|
285
|
+
const cargoRoot = nearestManifestDirectory(fromPath, "Cargo.toml", resolverIndex.repoPaths);
|
|
286
|
+
const sourceRoot = cargoRoot ? `${cargoRoot}/src`.replace(/^\//, "") : fromPath.startsWith("src/") ? "src" : "";
|
|
287
|
+
const segments = imported.specifier.replace(/::\*$/, "").split("::").filter(Boolean);
|
|
288
|
+
const head = segments.shift();
|
|
289
|
+
let base;
|
|
290
|
+
let externalRoot;
|
|
291
|
+
if (head === "crate") {
|
|
292
|
+
base = sourceRoot;
|
|
293
|
+
}
|
|
294
|
+
else if (head === "self" || head === "super") {
|
|
295
|
+
const pathSegments = fromPath.split("/");
|
|
296
|
+
const fileName = pathSegments.pop() ?? "";
|
|
297
|
+
const stem = fileName.replace(/\.rs$/i, "");
|
|
298
|
+
const isRootModule = ["lib", "main", "mod"].includes(stem);
|
|
299
|
+
const moduleSegments = isRootModule ? pathSegments : [...pathSegments, stem];
|
|
300
|
+
if (head === "super")
|
|
301
|
+
moduleSegments.pop();
|
|
302
|
+
base = moduleSegments.join("/");
|
|
303
|
+
}
|
|
304
|
+
else if (head) {
|
|
305
|
+
const project = rustProjectForPath(resolverIndex.rustProjects, fromPath);
|
|
306
|
+
const dependency = project ? rustPathDependency(project, head) : undefined;
|
|
307
|
+
if (!dependency)
|
|
308
|
+
return [];
|
|
309
|
+
base = [dependency.root, "src"].filter(Boolean).join("/");
|
|
310
|
+
externalRoot = [`${base}/lib.rs`, `${base}/main.rs`, `${base}/mod.rs`]
|
|
311
|
+
.find((candidate) => resolverIndex.repoPaths.has(candidate));
|
|
312
|
+
if (segments.length === 0) {
|
|
313
|
+
return externalRoot ? [externalRoot] : [];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
return [];
|
|
318
|
+
}
|
|
319
|
+
for (let length = segments.length; length >= 1; length -= 1) {
|
|
320
|
+
const root = [base, ...segments.slice(0, length)].filter(Boolean).join("/");
|
|
321
|
+
const match = [`${root}.rs`, `${root}/mod.rs`].find((candidate) => resolverIndex.repoPaths.has(candidate));
|
|
322
|
+
if (match)
|
|
323
|
+
return [match];
|
|
324
|
+
}
|
|
325
|
+
return externalRoot ? [externalRoot] : [];
|
|
326
|
+
}
|
|
327
|
+
function resolveRubyImport(fromPath, imported, resolverIndex) {
|
|
328
|
+
const separator = imported.specifier.indexOf(":");
|
|
329
|
+
const mode = separator === -1 ? "" : imported.specifier.slice(0, separator);
|
|
330
|
+
const raw = separator === -1 ? imported.specifier : imported.specifier.slice(separator + 1);
|
|
331
|
+
const normalized = raw.replace(/\.rb$/i, "");
|
|
332
|
+
const roots = mode === "relative"
|
|
333
|
+
? [normalizeSegments(`${fromPath.split("/").slice(0, -1).join("/")}/${normalized}`)].filter((value) => Boolean(value))
|
|
334
|
+
: [normalized, `lib/${normalized}`, `app/${normalized}`];
|
|
335
|
+
for (const root of roots) {
|
|
336
|
+
const match = [`${root}.rb`, `${root}/init.rb`].find((candidate) => resolverIndex.repoPaths.has(candidate));
|
|
337
|
+
if (match)
|
|
338
|
+
return [match];
|
|
339
|
+
}
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
342
|
+
function resolvePhpImport(fromPath, imported, resolverIndex) {
|
|
343
|
+
if (imported.specifier.startsWith("file:")) {
|
|
344
|
+
const raw = imported.specifier.slice("file:".length);
|
|
345
|
+
const root = normalizeSegments(`${fromPath.split("/").slice(0, -1).join("/")}/${raw}`);
|
|
346
|
+
if (!root)
|
|
347
|
+
return [];
|
|
348
|
+
return resolverIndex.repoPaths.has(root) ? [root] : resolverIndex.repoPaths.has(`${root}.php`) ? [`${root}.php`] : [];
|
|
349
|
+
}
|
|
350
|
+
const symbol = imported.specifier.replace(/^\\+/, "").toLowerCase();
|
|
351
|
+
const exact = resolverIndex.phpSymbols.get(symbol);
|
|
352
|
+
const sourceProject = resolverIndex.composerProjectByFile.get(fromPath);
|
|
353
|
+
if (exact?.length) {
|
|
354
|
+
if (!sourceProject)
|
|
355
|
+
return [...exact].sort(shortestPathFirst).slice(0, 1);
|
|
356
|
+
const own = exact.filter((path) => resolverIndex.composerProjectByFile.get(path)?.path === sourceProject.path);
|
|
357
|
+
if (own.length > 0)
|
|
358
|
+
return [...own].sort(shortestPathFirst).slice(0, 1);
|
|
359
|
+
const reachable = composerReachableProjects(resolverIndex, sourceProject);
|
|
360
|
+
const dependencyExact = exact.filter((path) => {
|
|
361
|
+
const owner = resolverIndex.composerProjectByFile.get(path);
|
|
362
|
+
return owner !== undefined && owner.path !== sourceProject.path && reachable.has(owner.path);
|
|
363
|
+
});
|
|
364
|
+
if (dependencyExact.length === 1)
|
|
365
|
+
return dependencyExact;
|
|
366
|
+
if (dependencyExact.length > 1)
|
|
367
|
+
return [];
|
|
368
|
+
}
|
|
369
|
+
if (sourceProject) {
|
|
370
|
+
const mapped = resolveComposerSymbol(sourceProject, imported.specifier.replace(/^\\+/, ""), resolverIndex.repoPaths, resolverIndex.suffixPaths);
|
|
371
|
+
if (mapped.length > 0)
|
|
372
|
+
return mapped;
|
|
373
|
+
const dependencyMapped = new Set();
|
|
374
|
+
for (const projectPath of [...composerReachableProjects(resolverIndex, sourceProject)].sort()) {
|
|
375
|
+
if (projectPath === sourceProject.path)
|
|
376
|
+
continue;
|
|
377
|
+
const dependency = resolverIndex.composerProjectsByPath.get(projectPath);
|
|
378
|
+
if (!dependency)
|
|
379
|
+
continue;
|
|
380
|
+
for (const path of resolveComposerSymbol(dependency, imported.specifier.replace(/^\\+/, ""), resolverIndex.repoPaths, resolverIndex.suffixPaths)) {
|
|
381
|
+
dependencyMapped.add(path);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (dependencyMapped.size === 1)
|
|
385
|
+
return [...dependencyMapped];
|
|
386
|
+
if (dependencyMapped.size > 1)
|
|
387
|
+
return [];
|
|
388
|
+
}
|
|
389
|
+
const namespace = symbol.split("\\").slice(0, -1).join("\\");
|
|
390
|
+
const namespacePaths = resolverIndex.phpNamespaces.get(namespace) ?? [];
|
|
391
|
+
return (sourceProject
|
|
392
|
+
? namespacePaths.filter((path) => {
|
|
393
|
+
const owner = resolverIndex.composerProjectByFile.get(path);
|
|
394
|
+
return owner !== undefined && composerReachableProjects(resolverIndex, sourceProject).has(owner.path);
|
|
395
|
+
})
|
|
396
|
+
: namespacePaths)
|
|
397
|
+
.sort(shortestPathFirst)
|
|
398
|
+
.slice(0, 20);
|
|
399
|
+
}
|
|
400
|
+
function resolveDotnetImport(fromPath, imported, resolverIndex) {
|
|
401
|
+
const namespace = imported.specifier.toLowerCase();
|
|
402
|
+
const exact = resolverIndex.dotnetNamespaces.get(namespace) ?? [];
|
|
403
|
+
// C# namespace names are dotted but not hierarchical imports: `using A.B`
|
|
404
|
+
// does not make symbols declared in `A.B.C` available. Exact lookup is both
|
|
405
|
+
// the correct model and avoids scanning every namespace for every using.
|
|
406
|
+
const sourceProject = resolverIndex.dotnetProjectByFile.get(fromPath);
|
|
407
|
+
if (!sourceProject)
|
|
408
|
+
return exact.slice(0, 20);
|
|
409
|
+
let reachableProjects = resolverIndex.dotnetReferenceClosures.get(sourceProject.path);
|
|
410
|
+
if (!reachableProjects) {
|
|
411
|
+
reachableProjects = dotnetReferenceClosure(resolverIndex.dotnetProjects, sourceProject.path);
|
|
412
|
+
resolverIndex.dotnetReferenceClosures.set(sourceProject.path, reachableProjects);
|
|
413
|
+
}
|
|
414
|
+
return exact
|
|
415
|
+
.filter((path) => {
|
|
416
|
+
const targetProject = resolverIndex.dotnetProjectByFile.get(path);
|
|
417
|
+
return targetProject !== undefined && reachableProjects.has(targetProject.path);
|
|
418
|
+
})
|
|
419
|
+
.slice(0, 20);
|
|
420
|
+
}
|
|
421
|
+
/** Build once per graph instead of walking every repository path for every Python or Java
|
|
422
|
+
* import. Each source path contributes its directory suffixes, preserving the old
|
|
423
|
+
* path.endsWith() resolution semantics while changing repeated lookup from O(files) to O(1). */
|
|
424
|
+
function buildResolverIndex(files, dotnetProjects, composerProjects, rustProjects, rubyProjects, goModules, goWorkspaces) {
|
|
425
|
+
const repoPaths = new Set(files.map((file) => file.path));
|
|
426
|
+
const suffixPaths = new Map();
|
|
427
|
+
const javaPackagePaths = new Map();
|
|
428
|
+
const directoryPaths = new Map();
|
|
429
|
+
const phpSymbols = new Map();
|
|
430
|
+
const phpNamespaces = new Map();
|
|
431
|
+
const dotnetNamespaces = new Map();
|
|
432
|
+
const dotnetSymbolsByFile = new Map();
|
|
433
|
+
const dotnetProjectByFile = new Map();
|
|
434
|
+
const rubyProjectByFile = new Map();
|
|
435
|
+
const composerProjectByFile = new Map();
|
|
436
|
+
const composerProjectsByPath = new Map(composerProjects.map((project) => [project.path, project]));
|
|
437
|
+
const composerDependencyClosures = new Map();
|
|
438
|
+
const dotnetProjectsByPath = new Map(dotnetProjects.map((project) => [project.path, project]));
|
|
439
|
+
const dotnetProjectsByRoot = new Map();
|
|
440
|
+
for (const project of dotnetProjects) {
|
|
441
|
+
const existing = dotnetProjectsByRoot.get(project.root);
|
|
442
|
+
if (existing)
|
|
443
|
+
existing.push(project);
|
|
444
|
+
else
|
|
445
|
+
dotnetProjectsByRoot.set(project.root, [project]);
|
|
446
|
+
}
|
|
447
|
+
const composerProjectsByRoot = new Map();
|
|
448
|
+
for (const project of composerProjects) {
|
|
449
|
+
const existing = composerProjectsByRoot.get(project.root);
|
|
450
|
+
if (existing)
|
|
451
|
+
existing.push(project);
|
|
452
|
+
else
|
|
453
|
+
composerProjectsByRoot.set(project.root, [project]);
|
|
454
|
+
}
|
|
455
|
+
for (const file of files) {
|
|
456
|
+
const segments = file.path.split("/");
|
|
457
|
+
addIndexedPath(directoryPaths, segments.slice(0, -1).join("/"), file.path);
|
|
458
|
+
if (/\.(?:py|pyi|java|php)$/i.test(file.path)) {
|
|
459
|
+
for (let start = 1; start < segments.length; start += 1) {
|
|
460
|
+
addIndexedPath(suffixPaths, segments.slice(start).join("/"), file.path);
|
|
91
461
|
}
|
|
92
462
|
}
|
|
463
|
+
if (file.path.toLowerCase().endsWith(".java")) {
|
|
464
|
+
const directories = segments.slice(0, -1);
|
|
465
|
+
for (let start = 0; start < directories.length; start += 1) {
|
|
466
|
+
addIndexedPath(javaPackagePaths, directories.slice(start).join("/"), file.path);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (file.path.toLowerCase().endsWith(".php")) {
|
|
470
|
+
const owner = projectForSourcePath(file.path, composerProjectsByRoot);
|
|
471
|
+
if (owner)
|
|
472
|
+
composerProjectByFile.set(file.path, owner);
|
|
473
|
+
const namespace = /^\s*namespace\s+([^;{\n]+)\s*[;{]/m.exec(file.textSample)?.[1]?.trim().replace(/^\\+|\\+$/g, "");
|
|
474
|
+
if (namespace) {
|
|
475
|
+
const normalizedNamespace = namespace.toLowerCase();
|
|
476
|
+
addIndexedPath(phpNamespaces, normalizedNamespace, file.path);
|
|
477
|
+
for (const definition of extractLanguageDefinitions(file)) {
|
|
478
|
+
if (["class", "interface", "type"].includes(definition.kind)) {
|
|
479
|
+
addIndexedPath(phpSymbols, `${normalizedNamespace}\\${definition.name.toLowerCase()}`, file.path);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (file.path.toLowerCase().endsWith(".cs")) {
|
|
485
|
+
const namespace = /\bnamespace\s+([A-Za-z_][A-Za-z0-9_.]*)\s*(?:;|\{)/m.exec(file.textSample)?.[1]?.toLowerCase();
|
|
486
|
+
if (namespace)
|
|
487
|
+
addIndexedPath(dotnetNamespaces, namespace, file.path);
|
|
488
|
+
const symbols = [...new Set(extractLanguageDefinitions(file)
|
|
489
|
+
.filter((definition) => definition.kind !== "method")
|
|
490
|
+
.map((definition) => definition.name))];
|
|
491
|
+
if (symbols.length > 0)
|
|
492
|
+
dotnetSymbolsByFile.set(file.path, symbols);
|
|
493
|
+
const owner = projectForSourcePath(file.path, dotnetProjectsByRoot);
|
|
494
|
+
if (owner)
|
|
495
|
+
dotnetProjectByFile.set(file.path, owner);
|
|
496
|
+
}
|
|
497
|
+
if (file.path.toLowerCase().endsWith(".rb")) {
|
|
498
|
+
const owner = rubyProjectForPath(rubyProjects, file.path);
|
|
499
|
+
if (owner)
|
|
500
|
+
rubyProjectByFile.set(file.path, owner);
|
|
501
|
+
}
|
|
93
502
|
}
|
|
94
|
-
|
|
503
|
+
goModules.sort((a, b) => b.name.length - a.name.length || a.name.localeCompare(b.name));
|
|
504
|
+
// A large namespace such as `System` can be referenced by thousands of C# files.
|
|
505
|
+
// Sort each namespace once instead of sorting the same candidate list per `using`.
|
|
506
|
+
for (const paths of dotnetNamespaces.values())
|
|
507
|
+
paths.sort(shortestPathFirst);
|
|
508
|
+
const dotnetReferenceClosures = new Map();
|
|
509
|
+
const dotnetGlobalTargetsByProject = new Map();
|
|
510
|
+
for (const project of dotnetProjects) {
|
|
511
|
+
if (project.globalUsings.length === 0)
|
|
512
|
+
continue;
|
|
513
|
+
const reachable = dotnetReferenceClosureFromIndex(dotnetProjectsByPath, project.path);
|
|
514
|
+
dotnetReferenceClosures.set(project.path, reachable);
|
|
515
|
+
const targetsBySymbol = new Map();
|
|
516
|
+
for (const namespace of project.globalUsings) {
|
|
517
|
+
for (const path of dotnetNamespaces.get(namespace.toLowerCase()) ?? []) {
|
|
518
|
+
const owner = dotnetProjectByFile.get(path);
|
|
519
|
+
const symbols = dotnetSymbolsByFile.get(path) ?? [];
|
|
520
|
+
if (!owner || !reachable.has(owner.path))
|
|
521
|
+
continue;
|
|
522
|
+
for (const symbol of symbols) {
|
|
523
|
+
const targets = targetsBySymbol.get(symbol);
|
|
524
|
+
if (targets)
|
|
525
|
+
targets.add(path);
|
|
526
|
+
else
|
|
527
|
+
targetsBySymbol.set(symbol, new Set([path]));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
dotnetGlobalTargetsByProject.set(project.path, new Map([...targetsBySymbol.entries()]
|
|
532
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
533
|
+
.map(([symbol, targets]) => [symbol, [...targets].sort(shortestPathFirst)])));
|
|
534
|
+
}
|
|
535
|
+
const rubyAutoloadTargetsByProject = new Map();
|
|
536
|
+
const filesByPath = new Map(files.map((file) => [file.path, file]));
|
|
537
|
+
for (const project of rubyProjects) {
|
|
538
|
+
if (project.autoloadFiles.length === 0)
|
|
539
|
+
continue;
|
|
540
|
+
const targetsBySymbol = new Map();
|
|
541
|
+
for (const path of project.autoloadFiles) {
|
|
542
|
+
const target = filesByPath.get(path);
|
|
543
|
+
if (!target)
|
|
544
|
+
continue;
|
|
545
|
+
for (const definition of extractLanguageDefinitions(target)) {
|
|
546
|
+
if (definition.kind === "method")
|
|
547
|
+
continue;
|
|
548
|
+
const paths = targetsBySymbol.get(definition.name);
|
|
549
|
+
if (paths)
|
|
550
|
+
paths.add(path);
|
|
551
|
+
else
|
|
552
|
+
targetsBySymbol.set(definition.name, new Set([path]));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
rubyAutoloadTargetsByProject.set(project.path, new Map([...targetsBySymbol.entries()]
|
|
556
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
557
|
+
.map(([symbol, targets]) => [symbol, [...targets].sort(shortestPathFirst)])));
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
repoPaths,
|
|
561
|
+
suffixPaths,
|
|
562
|
+
javaPackagePaths,
|
|
563
|
+
directoryPaths,
|
|
564
|
+
goModules,
|
|
565
|
+
goWorkspaces,
|
|
566
|
+
rustProjects,
|
|
567
|
+
rubyProjectByFile,
|
|
568
|
+
rubyAutoloadTargetsByProject,
|
|
569
|
+
phpSymbols,
|
|
570
|
+
phpNamespaces,
|
|
571
|
+
dotnetNamespaces,
|
|
572
|
+
dotnetProjects,
|
|
573
|
+
dotnetProjectByFile,
|
|
574
|
+
dotnetReferenceClosures,
|
|
575
|
+
dotnetGlobalTargetsByProject,
|
|
576
|
+
composerProjectByFile,
|
|
577
|
+
composerProjectsByPath,
|
|
578
|
+
composerDependencyClosures
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function composerReachableProjects(resolverIndex, project) {
|
|
582
|
+
let reachable = resolverIndex.composerDependencyClosures.get(project.path);
|
|
583
|
+
if (!reachable) {
|
|
584
|
+
reachable = composerDependencyClosure([...resolverIndex.composerProjectsByPath.values()], project.path);
|
|
585
|
+
resolverIndex.composerDependencyClosures.set(project.path, reachable);
|
|
586
|
+
}
|
|
587
|
+
return reachable;
|
|
588
|
+
}
|
|
589
|
+
function rubyConstantIdentifiers(text) {
|
|
590
|
+
const identifiers = new Set();
|
|
591
|
+
let heredocEnd;
|
|
592
|
+
for (const line of text.split(/\r?\n/)) {
|
|
593
|
+
if (heredocEnd) {
|
|
594
|
+
if (line.trim() === heredocEnd)
|
|
595
|
+
heredocEnd = undefined;
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
let scrubbed = "";
|
|
599
|
+
let quote = "";
|
|
600
|
+
let escaped = false;
|
|
601
|
+
for (const character of line) {
|
|
602
|
+
if (escaped) {
|
|
603
|
+
escaped = false;
|
|
604
|
+
scrubbed += " ";
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
if (quote && character === "\\") {
|
|
608
|
+
escaped = true;
|
|
609
|
+
scrubbed += " ";
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (character === '"' || character === "'") {
|
|
613
|
+
quote = quote === character ? "" : quote ? quote : character;
|
|
614
|
+
scrubbed += " ";
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (!quote && character === "#")
|
|
618
|
+
break;
|
|
619
|
+
scrubbed += quote ? " " : character;
|
|
620
|
+
}
|
|
621
|
+
const heredoc = /<<[-~]?\s*(?:["']([A-Za-z_][A-Za-z0-9_]*)["']|([A-Za-z_][A-Za-z0-9_]*))/.exec(line);
|
|
622
|
+
if (heredoc)
|
|
623
|
+
heredocEnd = heredoc[1] ?? heredoc[2];
|
|
624
|
+
const searchable = heredoc ? scrubbed.slice(0, heredoc.index) : scrubbed;
|
|
625
|
+
for (const match of searchable.matchAll(/\b[A-Z][A-Za-z0-9_]*\b/g)) {
|
|
626
|
+
if (match[0])
|
|
627
|
+
identifiers.add(match[0]);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return identifiers;
|
|
631
|
+
}
|
|
632
|
+
function dotnetReferenceClosureFromIndex(projectsByPath, projectPath) {
|
|
633
|
+
const reachable = new Set();
|
|
634
|
+
const pending = [projectPath];
|
|
635
|
+
while (pending.length > 0) {
|
|
636
|
+
const current = pending.shift();
|
|
637
|
+
if (reachable.has(current))
|
|
638
|
+
continue;
|
|
639
|
+
reachable.add(current);
|
|
640
|
+
for (const reference of projectsByPath.get(current)?.references ?? []) {
|
|
641
|
+
if (!reachable.has(reference))
|
|
642
|
+
pending.push(reference);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return reachable;
|
|
646
|
+
}
|
|
647
|
+
function projectForSourcePath(path, projectsByRoot) {
|
|
648
|
+
const directories = path.split("/").slice(0, -1);
|
|
649
|
+
for (let length = directories.length; length >= 0; length -= 1) {
|
|
650
|
+
const root = directories.slice(0, length).join("/");
|
|
651
|
+
const projects = projectsByRoot.get(root) ?? [];
|
|
652
|
+
if (projects.length > 0)
|
|
653
|
+
return projects.length === 1 ? projects[0] : undefined;
|
|
654
|
+
}
|
|
655
|
+
return undefined;
|
|
656
|
+
}
|
|
657
|
+
function nearestManifestDirectory(fromPath, manifest, repoPaths) {
|
|
658
|
+
const directories = fromPath.split("/").slice(0, -1);
|
|
659
|
+
for (let length = directories.length; length >= 0; length -= 1) {
|
|
660
|
+
const directory = directories.slice(0, length).join("/");
|
|
661
|
+
const candidate = directory ? `${directory}/${manifest}` : manifest;
|
|
662
|
+
if (repoPaths.has(candidate))
|
|
663
|
+
return directory;
|
|
664
|
+
}
|
|
665
|
+
return undefined;
|
|
666
|
+
}
|
|
667
|
+
function addIndexedPath(index, key, path) {
|
|
668
|
+
const existing = index.get(key);
|
|
669
|
+
if (existing)
|
|
670
|
+
existing.push(path);
|
|
671
|
+
else
|
|
672
|
+
index.set(key, [path]);
|
|
673
|
+
}
|
|
674
|
+
function shortestPathFirst(left, right) {
|
|
675
|
+
return left.split("/").length - right.split("/").length || left.localeCompare(right);
|
|
95
676
|
}
|
|
96
677
|
function resolveSpecifier(fromPath, specifier, repoPaths, aliases, workspacePackages) {
|
|
97
678
|
const baseDir = fromPath.split("/").slice(0, -1).join("/");
|
|
@@ -106,7 +687,8 @@ function resolveSpecifier(fromPath, specifier, repoPaths, aliases, workspacePack
|
|
|
106
687
|
for (const alias of aliases) {
|
|
107
688
|
if (!specifier.startsWith(alias.prefix) || !specifier.endsWith(alias.suffix))
|
|
108
689
|
continue;
|
|
109
|
-
const
|
|
690
|
+
const end = alias.suffix.length === 0 ? specifier.length : specifier.length - alias.suffix.length;
|
|
691
|
+
const middle = specifier.slice(alias.prefix.length, end);
|
|
110
692
|
roots.push(...alias.targets.map((target) => target.replace("*", middle)));
|
|
111
693
|
}
|
|
112
694
|
}
|