archtracker-mcp 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +627 -98
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +626 -96
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.js +656 -120
- package/dist/mcp/index.js.map +1 -1
- package/package.json +12 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/types/schema.ts
|
|
2
9
|
var SCHEMA_VERSION = "1.0";
|
|
3
10
|
|
|
4
11
|
// src/analyzer/analyze.ts
|
|
12
|
+
import { resolve as resolve4 } from "path";
|
|
13
|
+
|
|
14
|
+
// src/analyzer/engines/dependency-cruiser.ts
|
|
5
15
|
import { resolve } from "path";
|
|
6
16
|
import { cruise } from "dependency-cruiser";
|
|
7
17
|
var DEFAULT_EXCLUDE = [
|
|
@@ -12,110 +22,630 @@ var DEFAULT_EXCLUDE = [
|
|
|
12
22
|
"coverage",
|
|
13
23
|
"\\.archtracker"
|
|
14
24
|
];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
var DependencyCruiserEngine = class {
|
|
26
|
+
async analyze(rootDir, options = {}) {
|
|
27
|
+
const {
|
|
28
|
+
exclude = [],
|
|
29
|
+
maxDepth = 0,
|
|
30
|
+
tsConfigPath,
|
|
31
|
+
includeTypeOnly = true
|
|
32
|
+
} = options;
|
|
33
|
+
const absRootDir = resolve(rootDir);
|
|
34
|
+
const allExclude = [...DEFAULT_EXCLUDE, ...exclude];
|
|
35
|
+
const excludePattern = allExclude.join("|");
|
|
36
|
+
const cruiseOptions = {
|
|
37
|
+
baseDir: absRootDir,
|
|
38
|
+
exclude: { path: excludePattern },
|
|
39
|
+
doNotFollow: { path: "node_modules" },
|
|
40
|
+
maxDepth,
|
|
41
|
+
tsPreCompilationDeps: includeTypeOnly ? true : false,
|
|
42
|
+
combinedDependencies: false
|
|
43
|
+
};
|
|
44
|
+
if (tsConfigPath) {
|
|
45
|
+
cruiseOptions.tsConfig = { fileName: tsConfigPath };
|
|
46
|
+
}
|
|
47
|
+
let result;
|
|
48
|
+
try {
|
|
49
|
+
result = await cruise(["."], cruiseOptions);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
52
|
+
throw new Error(`dependency-cruiser failed: ${message}`, {
|
|
53
|
+
cause: error
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (result.exitCode !== 0 && !result.output) {
|
|
57
|
+
throw new Error(`Analysis exited with code ${result.exitCode}`);
|
|
58
|
+
}
|
|
59
|
+
const cruiseResult = result.output;
|
|
60
|
+
return this.buildGraph(absRootDir, cruiseResult);
|
|
35
61
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
62
|
+
buildGraph(rootDir, cruiseResult) {
|
|
63
|
+
const files = {};
|
|
64
|
+
const edges = [];
|
|
65
|
+
const circularSet = /* @__PURE__ */ new Set();
|
|
66
|
+
const circularDependencies = [];
|
|
67
|
+
for (const mod of cruiseResult.modules) {
|
|
68
|
+
if (this.isExternalModule(mod)) continue;
|
|
69
|
+
files[mod.source] = {
|
|
70
|
+
path: mod.source,
|
|
71
|
+
exists: !mod.couldNotResolve,
|
|
72
|
+
dependencies: [],
|
|
73
|
+
dependents: []
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
for (const mod of cruiseResult.modules) {
|
|
77
|
+
for (const dep of mod.dependencies) {
|
|
78
|
+
if (dep.couldNotResolve || dep.coreModule) continue;
|
|
79
|
+
if (!files[mod.source] || this.isExternalDep(dep)) continue;
|
|
80
|
+
const edgeType = dep.typeOnly ? "type-only" : dep.dynamic ? "dynamic" : "static";
|
|
81
|
+
edges.push({ source: mod.source, target: dep.resolved, type: edgeType });
|
|
82
|
+
if (files[mod.source]) {
|
|
83
|
+
files[mod.source].dependencies.push(dep.resolved);
|
|
84
|
+
}
|
|
85
|
+
if (files[dep.resolved]) {
|
|
86
|
+
files[dep.resolved].dependents.push(mod.source);
|
|
87
|
+
}
|
|
88
|
+
if (dep.circular && dep.cycle) {
|
|
89
|
+
const cyclePath = dep.cycle.map((c) => c.name);
|
|
90
|
+
const cycleKey = [...cyclePath].sort().join("\u2192");
|
|
91
|
+
if (!circularSet.has(cycleKey)) {
|
|
92
|
+
circularSet.add(cycleKey);
|
|
93
|
+
circularDependencies.push({ cycle: cyclePath });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
rootDir,
|
|
100
|
+
files,
|
|
101
|
+
edges,
|
|
102
|
+
circularDependencies,
|
|
103
|
+
totalFiles: Object.keys(files).length,
|
|
104
|
+
totalEdges: edges.length
|
|
105
|
+
};
|
|
45
106
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
107
|
+
isExternalModule(mod) {
|
|
108
|
+
if (mod.coreModule) return true;
|
|
109
|
+
const depTypes = mod.dependencyTypes ?? [];
|
|
110
|
+
if (depTypes.some((t2) => t2.startsWith("npm") || t2 === "core")) return true;
|
|
111
|
+
return isExternalPath(mod.source);
|
|
112
|
+
}
|
|
113
|
+
isExternalDep(dep) {
|
|
114
|
+
if (dep.coreModule) return true;
|
|
115
|
+
if (dep.dependencyTypes.some((t2) => t2.startsWith("npm") || t2 === "core"))
|
|
116
|
+
return true;
|
|
117
|
+
return isExternalPath(dep.resolved);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
function isExternalPath(source) {
|
|
121
|
+
if (source.startsWith("@")) return true;
|
|
122
|
+
if (!source.includes("/") && !source.includes("\\") && !source.includes("."))
|
|
123
|
+
return true;
|
|
124
|
+
if (source.startsWith("node:")) return true;
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/analyzer/engines/regex-engine.ts
|
|
129
|
+
import { readdir, readFile } from "fs/promises";
|
|
130
|
+
import { join, relative, resolve as resolve2 } from "path";
|
|
131
|
+
|
|
132
|
+
// src/analyzer/engines/cycle.ts
|
|
133
|
+
function detectCycles(edges) {
|
|
134
|
+
const adj = /* @__PURE__ */ new Map();
|
|
135
|
+
for (const edge of edges) {
|
|
136
|
+
if (!adj.has(edge.source)) adj.set(edge.source, []);
|
|
137
|
+
adj.get(edge.source).push(edge.target);
|
|
138
|
+
}
|
|
139
|
+
const visited = /* @__PURE__ */ new Set();
|
|
140
|
+
const inStack = /* @__PURE__ */ new Set();
|
|
141
|
+
const cycles = [];
|
|
142
|
+
const cycleKeys = /* @__PURE__ */ new Set();
|
|
143
|
+
function dfs(node, path) {
|
|
144
|
+
if (inStack.has(node)) {
|
|
145
|
+
const cycleStart = path.indexOf(node);
|
|
146
|
+
if (cycleStart !== -1) {
|
|
147
|
+
const cycle = path.slice(cycleStart);
|
|
148
|
+
const key = [...cycle].sort().join("\u2192");
|
|
149
|
+
if (!cycleKeys.has(key)) {
|
|
150
|
+
cycleKeys.add(key);
|
|
151
|
+
cycles.push({ cycle });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (visited.has(node)) return;
|
|
157
|
+
visited.add(node);
|
|
158
|
+
inStack.add(node);
|
|
159
|
+
path.push(node);
|
|
160
|
+
for (const neighbor of adj.get(node) ?? []) {
|
|
161
|
+
dfs(neighbor, path);
|
|
162
|
+
}
|
|
163
|
+
path.pop();
|
|
164
|
+
inStack.delete(node);
|
|
50
165
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
166
|
+
for (const node of adj.keys()) {
|
|
167
|
+
if (!visited.has(node)) {
|
|
168
|
+
dfs(node, []);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return cycles;
|
|
53
172
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
173
|
+
|
|
174
|
+
// src/analyzer/engines/regex-engine.ts
|
|
175
|
+
var RegexEngine = class {
|
|
176
|
+
constructor(config) {
|
|
177
|
+
this.config = config;
|
|
178
|
+
}
|
|
179
|
+
async analyze(rootDir, options = {}) {
|
|
180
|
+
const absRootDir = resolve2(rootDir);
|
|
181
|
+
const excludePatterns = [
|
|
182
|
+
...this.config.defaultExclude ?? [],
|
|
183
|
+
...options.exclude ?? [],
|
|
184
|
+
"\\.archtracker"
|
|
185
|
+
].map((p) => new RegExp(p));
|
|
186
|
+
const projectFiles = await this.collectFiles(
|
|
187
|
+
absRootDir,
|
|
188
|
+
excludePatterns,
|
|
189
|
+
options.maxDepth ?? 0
|
|
190
|
+
);
|
|
191
|
+
const projectFileSet = new Set(projectFiles);
|
|
192
|
+
const files = {};
|
|
193
|
+
const edges = [];
|
|
194
|
+
for (const filePath of projectFiles) {
|
|
195
|
+
const relPath = relative(absRootDir, filePath);
|
|
196
|
+
files[relPath] = {
|
|
197
|
+
path: relPath,
|
|
198
|
+
exists: true,
|
|
199
|
+
dependencies: [],
|
|
200
|
+
dependents: []
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
for (const filePath of projectFiles) {
|
|
204
|
+
const relSource = relative(absRootDir, filePath);
|
|
205
|
+
let content;
|
|
206
|
+
try {
|
|
207
|
+
content = await readFile(filePath, "utf-8");
|
|
208
|
+
} catch {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
const imports = this.extractImports(content);
|
|
212
|
+
for (const importPath of imports) {
|
|
213
|
+
const resolved = this.config.resolveImport(
|
|
214
|
+
importPath,
|
|
215
|
+
filePath,
|
|
216
|
+
absRootDir,
|
|
217
|
+
projectFileSet
|
|
218
|
+
);
|
|
219
|
+
if (!resolved) continue;
|
|
220
|
+
const relTarget = relative(absRootDir, resolved);
|
|
221
|
+
if (!files[relTarget]) continue;
|
|
222
|
+
edges.push({
|
|
223
|
+
source: relSource,
|
|
224
|
+
target: relTarget,
|
|
225
|
+
type: "static"
|
|
226
|
+
});
|
|
227
|
+
files[relSource].dependencies.push(relTarget);
|
|
228
|
+
files[relTarget].dependents.push(relSource);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const circularDependencies = detectCycles(edges);
|
|
232
|
+
return {
|
|
233
|
+
rootDir: absRootDir,
|
|
234
|
+
files,
|
|
235
|
+
edges,
|
|
236
|
+
circularDependencies,
|
|
237
|
+
totalFiles: Object.keys(files).length,
|
|
238
|
+
totalEdges: edges.length
|
|
66
239
|
};
|
|
67
240
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
if (files[mod.source]) {
|
|
79
|
-
files[mod.source].dependencies.push(dep.resolved);
|
|
241
|
+
extractImports(content) {
|
|
242
|
+
const imports = [];
|
|
243
|
+
for (const pattern of this.config.importPatterns) {
|
|
244
|
+
const regex = new RegExp(pattern.regex.source, pattern.regex.flags);
|
|
245
|
+
let match;
|
|
246
|
+
while ((match = regex.exec(content)) !== null) {
|
|
247
|
+
if (match[1]) {
|
|
248
|
+
imports.push(match[1]);
|
|
249
|
+
}
|
|
80
250
|
}
|
|
81
|
-
|
|
82
|
-
|
|
251
|
+
}
|
|
252
|
+
return imports;
|
|
253
|
+
}
|
|
254
|
+
async collectFiles(dir, excludePatterns, maxDepth, currentDepth = 0) {
|
|
255
|
+
if (maxDepth > 0 && currentDepth >= maxDepth) return [];
|
|
256
|
+
const results = [];
|
|
257
|
+
let entries;
|
|
258
|
+
try {
|
|
259
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
260
|
+
} catch {
|
|
261
|
+
return results;
|
|
262
|
+
}
|
|
263
|
+
for (const entry of entries) {
|
|
264
|
+
const fullPath = join(dir, entry.name);
|
|
265
|
+
const relPath = relative(dir, fullPath);
|
|
266
|
+
if (excludePatterns.some(
|
|
267
|
+
(p) => p.test(entry.name) || p.test(relPath) || p.test(fullPath)
|
|
268
|
+
)) {
|
|
269
|
+
continue;
|
|
83
270
|
}
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
271
|
+
if (entry.isDirectory()) {
|
|
272
|
+
if (entry.name.startsWith(".")) continue;
|
|
273
|
+
const sub = await this.collectFiles(
|
|
274
|
+
fullPath,
|
|
275
|
+
excludePatterns,
|
|
276
|
+
maxDepth,
|
|
277
|
+
currentDepth + 1
|
|
278
|
+
);
|
|
279
|
+
results.push(...sub);
|
|
280
|
+
} else if (entry.isFile()) {
|
|
281
|
+
const dotIdx = entry.name.lastIndexOf(".");
|
|
282
|
+
if (dotIdx > 0) {
|
|
283
|
+
const ext = entry.name.slice(dotIdx);
|
|
284
|
+
if (this.config.extensions.includes(ext)) {
|
|
285
|
+
results.push(fullPath);
|
|
286
|
+
}
|
|
90
287
|
}
|
|
91
288
|
}
|
|
92
289
|
}
|
|
290
|
+
return results;
|
|
93
291
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/analyzer/engines/detect.ts
|
|
295
|
+
import { readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
296
|
+
import { join as join2 } from "path";
|
|
297
|
+
var MARKERS = [
|
|
298
|
+
{ file: "Cargo.toml", language: "rust" },
|
|
299
|
+
{ file: "go.mod", language: "go" },
|
|
300
|
+
{ file: "pyproject.toml", language: "python" },
|
|
301
|
+
{ file: "setup.py", language: "python" },
|
|
302
|
+
{ file: "requirements.txt", language: "python" },
|
|
303
|
+
{ file: "Pipfile", language: "python" },
|
|
304
|
+
{ file: "pom.xml", language: "java" },
|
|
305
|
+
{ file: "build.gradle", language: "java" },
|
|
306
|
+
{ file: "build.gradle.kts", language: "kotlin" },
|
|
307
|
+
{ file: "Package.swift", language: "swift" },
|
|
308
|
+
{ file: "Gemfile", language: "ruby" },
|
|
309
|
+
{ file: "composer.json", language: "php" },
|
|
310
|
+
{ file: "CMakeLists.txt", language: "c-cpp" },
|
|
311
|
+
{ file: "Makefile", language: "c-cpp" },
|
|
312
|
+
{ file: "package.json", language: "javascript" },
|
|
313
|
+
{ file: "tsconfig.json", language: "javascript" }
|
|
314
|
+
];
|
|
315
|
+
var EXT_MAP = {
|
|
316
|
+
".ts": "javascript",
|
|
317
|
+
".tsx": "javascript",
|
|
318
|
+
".js": "javascript",
|
|
319
|
+
".jsx": "javascript",
|
|
320
|
+
".mjs": "javascript",
|
|
321
|
+
".cjs": "javascript",
|
|
322
|
+
".py": "python",
|
|
323
|
+
".rs": "rust",
|
|
324
|
+
".go": "go",
|
|
325
|
+
".java": "java",
|
|
326
|
+
".c": "c-cpp",
|
|
327
|
+
".cpp": "c-cpp",
|
|
328
|
+
".cc": "c-cpp",
|
|
329
|
+
".cxx": "c-cpp",
|
|
330
|
+
".h": "c-cpp",
|
|
331
|
+
".hpp": "c-cpp",
|
|
332
|
+
".rb": "ruby",
|
|
333
|
+
".php": "php",
|
|
334
|
+
".swift": "swift",
|
|
335
|
+
".kt": "kotlin",
|
|
336
|
+
".kts": "kotlin"
|
|
337
|
+
};
|
|
338
|
+
async function detectLanguage(rootDir) {
|
|
339
|
+
for (const marker of MARKERS) {
|
|
340
|
+
try {
|
|
341
|
+
const s = await stat2(join2(rootDir, marker.file));
|
|
342
|
+
if (s.isFile() || s.isDirectory()) {
|
|
343
|
+
return marker.language;
|
|
344
|
+
}
|
|
345
|
+
} catch {
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const counts = /* @__PURE__ */ new Map();
|
|
349
|
+
try {
|
|
350
|
+
await scanExtensions(rootDir, counts, 2, 0);
|
|
351
|
+
} catch {
|
|
352
|
+
}
|
|
353
|
+
if (counts.size > 0) {
|
|
354
|
+
let maxLang = "javascript";
|
|
355
|
+
let maxCount = 0;
|
|
356
|
+
for (const [lang, count] of counts) {
|
|
357
|
+
if (count > maxCount) {
|
|
358
|
+
maxCount = count;
|
|
359
|
+
maxLang = lang;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return maxLang;
|
|
363
|
+
}
|
|
364
|
+
return "javascript";
|
|
102
365
|
}
|
|
103
|
-
function
|
|
104
|
-
if (
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
366
|
+
async function scanExtensions(dir, counts, maxDepth, currentDepth) {
|
|
367
|
+
if (currentDepth >= maxDepth) return;
|
|
368
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
369
|
+
for (const entry of entries) {
|
|
370
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
371
|
+
if (entry.isDirectory() && currentDepth < maxDepth - 1) {
|
|
372
|
+
await scanExtensions(
|
|
373
|
+
join2(dir, entry.name),
|
|
374
|
+
counts,
|
|
375
|
+
maxDepth,
|
|
376
|
+
currentDepth + 1
|
|
377
|
+
);
|
|
378
|
+
} else if (entry.isFile()) {
|
|
379
|
+
const dotIdx = entry.name.lastIndexOf(".");
|
|
380
|
+
if (dotIdx > 0) {
|
|
381
|
+
const ext = entry.name.slice(dotIdx);
|
|
382
|
+
const lang = EXT_MAP[ext];
|
|
383
|
+
if (lang) {
|
|
384
|
+
counts.set(lang, (counts.get(lang) ?? 0) + 1);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
108
389
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
390
|
+
|
|
391
|
+
// src/analyzer/engines/languages.ts
|
|
392
|
+
import { join as join3, dirname, resolve as resolve3 } from "path";
|
|
393
|
+
var python = {
|
|
394
|
+
id: "python",
|
|
395
|
+
extensions: [".py"],
|
|
396
|
+
importPatterns: [
|
|
397
|
+
// from package.module import something
|
|
398
|
+
{ regex: /^from\s+(\.[\w.]*|\w[\w.]*)\s+import\b/gm },
|
|
399
|
+
// import package.module
|
|
400
|
+
{ regex: /^import\s+([\w.]+)/gm }
|
|
401
|
+
],
|
|
402
|
+
resolveImport(importPath, sourceFile, rootDir, projectFiles) {
|
|
403
|
+
if (importPath.startsWith(".")) {
|
|
404
|
+
const dots = importPath.match(/^\.+/)?.[0].length ?? 1;
|
|
405
|
+
let base = dirname(sourceFile);
|
|
406
|
+
for (let i = 1; i < dots; i++) base = dirname(base);
|
|
407
|
+
const rest = importPath.slice(dots).replace(/\./g, "/");
|
|
408
|
+
return tryPythonResolve(join3(base, rest), projectFiles);
|
|
409
|
+
}
|
|
410
|
+
const parts = importPath.replace(/\./g, "/");
|
|
411
|
+
return tryPythonResolve(join3(rootDir, parts), projectFiles);
|
|
412
|
+
},
|
|
413
|
+
defaultExclude: ["__pycache__", "\\.venv", "venv", "\\.egg-info", "dist", "build"]
|
|
414
|
+
};
|
|
415
|
+
function tryPythonResolve(base, projectFiles) {
|
|
416
|
+
if (projectFiles.has(base + ".py")) return base + ".py";
|
|
417
|
+
if (projectFiles.has(join3(base, "__init__.py"))) return join3(base, "__init__.py");
|
|
418
|
+
return null;
|
|
113
419
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
420
|
+
var rust = {
|
|
421
|
+
id: "rust",
|
|
422
|
+
extensions: [".rs"],
|
|
423
|
+
importPatterns: [
|
|
424
|
+
// use crate::module::item;
|
|
425
|
+
{ regex: /\buse\s+crate::(\w[\w:]*)/gm },
|
|
426
|
+
// mod child;
|
|
427
|
+
{ regex: /\bmod\s+(\w+)\s*;/gm }
|
|
428
|
+
],
|
|
429
|
+
resolveImport(importPath, sourceFile, rootDir, projectFiles) {
|
|
430
|
+
const srcDir = join3(rootDir, "src");
|
|
431
|
+
if (!importPath.includes("::")) {
|
|
432
|
+
const parentDir = dirname(sourceFile);
|
|
433
|
+
const asFile = join3(parentDir, importPath + ".rs");
|
|
434
|
+
if (projectFiles.has(asFile)) return asFile;
|
|
435
|
+
const asDir = join3(parentDir, importPath, "mod.rs");
|
|
436
|
+
if (projectFiles.has(asDir)) return asDir;
|
|
437
|
+
return null;
|
|
438
|
+
}
|
|
439
|
+
const segments = importPath.split("::");
|
|
440
|
+
for (let i = segments.length; i > 0; i--) {
|
|
441
|
+
const path = segments.slice(0, i).join("/");
|
|
442
|
+
const asFile = join3(srcDir, path + ".rs");
|
|
443
|
+
if (projectFiles.has(asFile)) return asFile;
|
|
444
|
+
const asDir = join3(srcDir, path, "mod.rs");
|
|
445
|
+
if (projectFiles.has(asDir)) return asDir;
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
},
|
|
449
|
+
defaultExclude: ["target"]
|
|
450
|
+
};
|
|
451
|
+
var go = {
|
|
452
|
+
id: "go",
|
|
453
|
+
extensions: [".go"],
|
|
454
|
+
importPatterns: [
|
|
455
|
+
// import "path" or import ( "path" )
|
|
456
|
+
{ regex: /\bimport\s+(?:\w+\s+)?"([^"]+)"/gm },
|
|
457
|
+
// import block entries
|
|
458
|
+
{ regex: /^\s+(?:\w+\s+)?"([^"]+)"/gm }
|
|
459
|
+
],
|
|
460
|
+
resolveImport(importPath, _sourceFile, rootDir, projectFiles) {
|
|
461
|
+
const modPrefix = goModulePrefix(rootDir);
|
|
462
|
+
if (!modPrefix || !importPath.startsWith(modPrefix)) return null;
|
|
463
|
+
const relPath = importPath.slice(modPrefix.length + 1);
|
|
464
|
+
const pkgDir = join3(rootDir, relPath);
|
|
465
|
+
for (const f of projectFiles) {
|
|
466
|
+
if (f.startsWith(pkgDir + "/") && f.endsWith(".go")) return f;
|
|
467
|
+
}
|
|
468
|
+
return null;
|
|
469
|
+
},
|
|
470
|
+
defaultExclude: ["vendor"]
|
|
471
|
+
};
|
|
472
|
+
var goModCache = /* @__PURE__ */ new Map();
|
|
473
|
+
function goModulePrefix(rootDir) {
|
|
474
|
+
if (goModCache.has(rootDir)) return goModCache.get(rootDir);
|
|
475
|
+
try {
|
|
476
|
+
const fs = __require("fs");
|
|
477
|
+
const content = fs.readFileSync(join3(rootDir, "go.mod"), "utf-8");
|
|
478
|
+
const match = content.match(/^module\s+(.+)$/m);
|
|
479
|
+
const prefix = match ? match[1].trim() : null;
|
|
480
|
+
goModCache.set(rootDir, prefix);
|
|
481
|
+
return prefix;
|
|
482
|
+
} catch {
|
|
483
|
+
goModCache.set(rootDir, null);
|
|
484
|
+
return null;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
var java = {
|
|
488
|
+
id: "java",
|
|
489
|
+
extensions: [".java"],
|
|
490
|
+
importPatterns: [
|
|
491
|
+
// import com.example.ClassName;
|
|
492
|
+
{ regex: /^import\s+(?:static\s+)?([\w.]+);/gm }
|
|
493
|
+
],
|
|
494
|
+
resolveImport(importPath, _sourceFile, rootDir, projectFiles) {
|
|
495
|
+
const filePath = importPath.replace(/\./g, "/") + ".java";
|
|
496
|
+
for (const srcRoot of ["", "src/main/java/", "src/", "app/src/main/java/"]) {
|
|
497
|
+
const full = join3(rootDir, srcRoot, filePath);
|
|
498
|
+
if (projectFiles.has(full)) return full;
|
|
499
|
+
}
|
|
500
|
+
return null;
|
|
501
|
+
},
|
|
502
|
+
defaultExclude: ["build", "target", "\\.gradle", "\\.idea"]
|
|
503
|
+
};
|
|
504
|
+
var cCpp = {
|
|
505
|
+
id: "c-cpp",
|
|
506
|
+
extensions: [".c", ".cpp", ".cc", ".cxx", ".h", ".hpp"],
|
|
507
|
+
importPatterns: [
|
|
508
|
+
// #include "file.h" (skip <system> includes)
|
|
509
|
+
{ regex: /^#include\s+"([^"]+)"/gm }
|
|
510
|
+
],
|
|
511
|
+
resolveImport(importPath, sourceFile, rootDir, projectFiles) {
|
|
512
|
+
const fromSource = resolve3(dirname(sourceFile), importPath);
|
|
513
|
+
if (projectFiles.has(fromSource)) return fromSource;
|
|
514
|
+
const fromRoot = join3(rootDir, importPath);
|
|
515
|
+
if (projectFiles.has(fromRoot)) return fromRoot;
|
|
516
|
+
for (const incDir of ["include", "src"]) {
|
|
517
|
+
const full = join3(rootDir, incDir, importPath);
|
|
518
|
+
if (projectFiles.has(full)) return full;
|
|
519
|
+
}
|
|
520
|
+
return null;
|
|
521
|
+
},
|
|
522
|
+
defaultExclude: ["build", "cmake-build", "\\.o$", "\\.obj$"]
|
|
523
|
+
};
|
|
524
|
+
var ruby = {
|
|
525
|
+
id: "ruby",
|
|
526
|
+
extensions: [".rb"],
|
|
527
|
+
importPatterns: [
|
|
528
|
+
// require_relative 'path'
|
|
529
|
+
{ regex: /\brequire_relative\s+['"]([^'"]+)['"]/gm },
|
|
530
|
+
// require 'path' (for project-internal requires)
|
|
531
|
+
{ regex: /\brequire\s+['"]([^'"]+)['"]/gm }
|
|
532
|
+
],
|
|
533
|
+
resolveImport(importPath, sourceFile, rootDir, projectFiles) {
|
|
534
|
+
const withExt = importPath.endsWith(".rb") ? importPath : importPath + ".rb";
|
|
535
|
+
const fromSource = resolve3(dirname(sourceFile), withExt);
|
|
536
|
+
if (projectFiles.has(fromSource)) return fromSource;
|
|
537
|
+
const fromRoot = join3(rootDir, withExt);
|
|
538
|
+
if (projectFiles.has(fromRoot)) return fromRoot;
|
|
539
|
+
const fromLib = join3(rootDir, "lib", withExt);
|
|
540
|
+
if (projectFiles.has(fromLib)) return fromLib;
|
|
541
|
+
return null;
|
|
542
|
+
},
|
|
543
|
+
defaultExclude: ["vendor", "\\.bundle"]
|
|
544
|
+
};
|
|
545
|
+
var php = {
|
|
546
|
+
id: "php",
|
|
547
|
+
extensions: [".php"],
|
|
548
|
+
importPatterns: [
|
|
549
|
+
// require/include/require_once/include_once 'path'
|
|
550
|
+
{ regex: /\b(?:require|include)(?:_once)?\s+['"]([^'"]+)['"]/gm },
|
|
551
|
+
// use Namespace\Class (PSR-4 style)
|
|
552
|
+
{ regex: /^use\s+([\w\\]+)/gm }
|
|
553
|
+
],
|
|
554
|
+
resolveImport(importPath, sourceFile, rootDir, projectFiles) {
|
|
555
|
+
if (importPath.includes("/") || importPath.endsWith(".php")) {
|
|
556
|
+
const withExt = importPath.endsWith(".php") ? importPath : importPath + ".php";
|
|
557
|
+
const fromSource = resolve3(dirname(sourceFile), withExt);
|
|
558
|
+
if (projectFiles.has(fromSource)) return fromSource;
|
|
559
|
+
const fromRoot2 = join3(rootDir, withExt);
|
|
560
|
+
if (projectFiles.has(fromRoot2)) return fromRoot2;
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
const filePath = importPath.replace(/\\/g, "/") + ".php";
|
|
564
|
+
const fromRoot = join3(rootDir, filePath);
|
|
565
|
+
if (projectFiles.has(fromRoot)) return fromRoot;
|
|
566
|
+
const fromSrc = join3(rootDir, "src", filePath);
|
|
567
|
+
if (projectFiles.has(fromSrc)) return fromSrc;
|
|
568
|
+
return null;
|
|
569
|
+
},
|
|
570
|
+
defaultExclude: ["vendor"]
|
|
571
|
+
};
|
|
572
|
+
var swift = {
|
|
573
|
+
id: "swift",
|
|
574
|
+
extensions: [".swift"],
|
|
575
|
+
importPatterns: [
|
|
576
|
+
// import ModuleName
|
|
577
|
+
{ regex: /^import\s+(?:class|struct|enum|protocol|func|var|let|typealias)?\s*(\w+)/gm }
|
|
578
|
+
],
|
|
579
|
+
resolveImport(importPath, _sourceFile, rootDir, projectFiles) {
|
|
580
|
+
const spmDir = join3(rootDir, "Sources", importPath);
|
|
581
|
+
for (const f of projectFiles) {
|
|
582
|
+
if (f.startsWith(spmDir + "/") && f.endsWith(".swift")) return f;
|
|
583
|
+
}
|
|
584
|
+
return null;
|
|
585
|
+
},
|
|
586
|
+
defaultExclude: ["\\.build", "DerivedData"]
|
|
587
|
+
};
|
|
588
|
+
var kotlin = {
|
|
589
|
+
id: "kotlin",
|
|
590
|
+
extensions: [".kt", ".kts"],
|
|
591
|
+
importPatterns: [
|
|
592
|
+
// import com.example.ClassName
|
|
593
|
+
{ regex: /^import\s+([\w.]+)/gm }
|
|
594
|
+
],
|
|
595
|
+
resolveImport(importPath, _sourceFile, rootDir, projectFiles) {
|
|
596
|
+
const filePath = importPath.replace(/\./g, "/");
|
|
597
|
+
for (const ext of [".kt", ".kts"]) {
|
|
598
|
+
for (const srcRoot of [
|
|
599
|
+
"",
|
|
600
|
+
"src/main/kotlin/",
|
|
601
|
+
"src/main/java/",
|
|
602
|
+
"src/",
|
|
603
|
+
"app/src/main/kotlin/",
|
|
604
|
+
"app/src/main/java/"
|
|
605
|
+
]) {
|
|
606
|
+
const full = join3(rootDir, srcRoot, filePath + ext);
|
|
607
|
+
if (projectFiles.has(full)) return full;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
return null;
|
|
611
|
+
},
|
|
612
|
+
defaultExclude: ["build", "\\.gradle", "\\.idea"]
|
|
613
|
+
};
|
|
614
|
+
var LANGUAGE_CONFIGS = {
|
|
615
|
+
javascript: null,
|
|
616
|
+
// handled by DependencyCruiserEngine
|
|
617
|
+
python,
|
|
618
|
+
rust,
|
|
619
|
+
go,
|
|
620
|
+
java,
|
|
621
|
+
"c-cpp": cCpp,
|
|
622
|
+
ruby,
|
|
623
|
+
php,
|
|
624
|
+
swift,
|
|
625
|
+
kotlin
|
|
626
|
+
};
|
|
627
|
+
function getLanguageConfig(id) {
|
|
628
|
+
return LANGUAGE_CONFIGS[id] ?? null;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/analyzer/analyze.ts
|
|
632
|
+
async function analyzeProject(rootDir, options = {}) {
|
|
633
|
+
const absRootDir = resolve4(rootDir);
|
|
634
|
+
const language = options.language ?? await detectLanguage(absRootDir);
|
|
635
|
+
try {
|
|
636
|
+
if (language === "javascript") {
|
|
637
|
+
return await new DependencyCruiserEngine().analyze(absRootDir, options);
|
|
638
|
+
}
|
|
639
|
+
const config = getLanguageConfig(language);
|
|
640
|
+
if (!config) {
|
|
641
|
+
throw new AnalyzerError(`No analyzer config for language: ${language}`);
|
|
642
|
+
}
|
|
643
|
+
return await new RegexEngine(config).analyze(absRootDir, options);
|
|
644
|
+
} catch (error) {
|
|
645
|
+
if (error instanceof AnalyzerError) throw error;
|
|
646
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
647
|
+
throw new AnalyzerError(message, { cause: error });
|
|
648
|
+
}
|
|
119
649
|
}
|
|
120
650
|
var AnalyzerError = class extends Error {
|
|
121
651
|
constructor(message, options) {
|
|
@@ -382,8 +912,8 @@ function formatAnalysisReport(graph, options = {}) {
|
|
|
382
912
|
}
|
|
383
913
|
|
|
384
914
|
// src/storage/snapshot.ts
|
|
385
|
-
import { mkdir, writeFile, readFile, access } from "fs/promises";
|
|
386
|
-
import { join } from "path";
|
|
915
|
+
import { mkdir, writeFile, readFile as readFile2, access } from "fs/promises";
|
|
916
|
+
import { join as join4 } from "path";
|
|
387
917
|
import { z } from "zod";
|
|
388
918
|
var ARCHTRACKER_DIR = ".archtracker";
|
|
389
919
|
var SNAPSHOT_FILE = "snapshot.json";
|
|
@@ -412,8 +942,8 @@ var SnapshotSchema = z.object({
|
|
|
412
942
|
graph: DependencyGraphSchema
|
|
413
943
|
});
|
|
414
944
|
async function saveSnapshot(projectRoot, graph) {
|
|
415
|
-
const dirPath =
|
|
416
|
-
const filePath =
|
|
945
|
+
const dirPath = join4(projectRoot, ARCHTRACKER_DIR);
|
|
946
|
+
const filePath = join4(dirPath, SNAPSHOT_FILE);
|
|
417
947
|
const snapshot = {
|
|
418
948
|
version: SCHEMA_VERSION,
|
|
419
949
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -425,10 +955,10 @@ async function saveSnapshot(projectRoot, graph) {
|
|
|
425
955
|
return snapshot;
|
|
426
956
|
}
|
|
427
957
|
async function loadSnapshot(projectRoot) {
|
|
428
|
-
const filePath =
|
|
958
|
+
const filePath = join4(projectRoot, ARCHTRACKER_DIR, SNAPSHOT_FILE);
|
|
429
959
|
let raw;
|
|
430
960
|
try {
|
|
431
|
-
raw = await
|
|
961
|
+
raw = await readFile2(filePath, "utf-8");
|
|
432
962
|
} catch (error) {
|
|
433
963
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
434
964
|
return null;
|
|
@@ -457,7 +987,7 @@ async function loadSnapshot(projectRoot) {
|
|
|
457
987
|
}
|
|
458
988
|
async function hasArchtrackerDir(projectRoot) {
|
|
459
989
|
try {
|
|
460
|
-
await access(
|
|
990
|
+
await access(join4(projectRoot, ARCHTRACKER_DIR));
|
|
461
991
|
return true;
|
|
462
992
|
} catch {
|
|
463
993
|
return false;
|