devlensio 1.1.0 → 1.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/extractors/runner.js +1 -0
- package/dist/extractors/types.d.ts +2 -1
- package/dist/graph/buildLookup.d.ts +30 -0
- package/dist/graph/buildLookup.js +36 -1
- package/dist/graph/edges/aliasChain.d.ts +7 -0
- package/dist/graph/edges/aliasChain.js +63 -0
- package/dist/graph/edges/aliasResolution.test.d.ts +1 -0
- package/dist/graph/edges/aliasResolution.test.js +351 -0
- package/dist/graph/edges/callEdges.js +101 -15
- package/dist/graph/edges/callEdges.test.js +119 -0
- package/dist/graph/edges/importEdges.js +124 -0
- package/dist/parser/declarationIds.d.ts +23 -0
- package/dist/parser/declarationIds.js +123 -0
- package/dist/parser/exportsMap.d.ts +9 -0
- package/dist/parser/exportsMap.js +260 -0
- package/dist/parser/exportsMap.test.d.ts +1 -0
- package/dist/parser/exportsMap.test.js +324 -0
- package/dist/parser/extractors/functions.d.ts +11 -0
- package/dist/parser/extractors/functions.js +69 -59
- package/dist/parser/extractors/moduleScope.d.ts +8 -0
- package/dist/parser/extractors/moduleScope.js +80 -0
- package/dist/parser/index.d.ts +2 -1
- package/dist/parser/index.js +45 -0
- package/dist/parser/moduleScope.test.d.ts +1 -0
- package/dist/parser/moduleScope.test.js +174 -0
- package/dist/pipeline/index.d.ts +2 -1
- package/dist/pipeline/index.js +1 -0
- package/dist/storage/fileStorage.d.ts +2 -1
- package/dist/storage/fileStorage.js +5 -1
- package/dist/storage/fileStorage.test.d.ts +1 -0
- package/dist/storage/fileStorage.test.js +112 -0
- package/dist/types.d.ts +4 -0
- package/extractors/go/bin/darwin-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/darwin-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-amd64/devlens_go_extractor +0 -0
- package/extractors/go/bin/linux-arm64/devlens_go_extractor +0 -0
- package/extractors/go/bin/windows-amd64/devlens_go_extractor.exe +0 -0
- package/extractors/go/calls.go +45 -3
- package/extractors/go/parser.go +81 -36
- package/extractors/java/devlens_java_extractor.jar +0 -0
- package/extractors/java/src/devlens/extractor/Extractor.java +16 -2
- package/extractors/java/src/devlens/extractor/LookupMaps.java +2 -0
- package/extractors/java/src/devlens/extractor/Parser.java +33 -1
- package/extractors/java/src/devlens/extractor/edges/Calls.java +44 -0
- package/extractors/python/devlens_extractors_python/edges/calls.py +173 -33
- package/extractors/python/devlens_extractors_python/edges/imports.py +21 -1
- package/extractors/python/devlens_extractors_python/lookup.py +9 -0
- package/extractors/python/devlens_extractors_python/parser/__init__.py +10 -1
- package/extractors/rust/bin/darwin-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/darwin-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-amd64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/linux-arm64/devlens_rust_extractor +0 -0
- package/extractors/rust/bin/windows-amd64/devlens_rust_extractor.exe +0 -0
- package/extractors/rust/src/calls.rs +32 -0
- package/extractors/rust/src/lookup.rs +66 -0
- package/package.json +1 -1
|
@@ -43,77 +43,87 @@ function inferArgType(arg) {
|
|
|
43
43
|
// classifier below.
|
|
44
44
|
const API_HOOK_FAMILIES = new Set(["useQuery", "useMutation", "useInfiniteQuery", "useSuspenseQuery", "useSWR", "useSWRMutation"]);
|
|
45
45
|
const AXIOS_METHODS = new Set(["axios.get", "axios.post", "axios.put", "axios.delete", "axios.patch", "axios"]);
|
|
46
|
+
export function createCallAccumulator() {
|
|
47
|
+
return {
|
|
48
|
+
sites: [],
|
|
49
|
+
hookCalls: [],
|
|
50
|
+
apiCalls: [],
|
|
51
|
+
dependencyNames: [],
|
|
52
|
+
contextRefs: [],
|
|
53
|
+
seenSites: new Set(),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
46
56
|
// SINGLE traversal over all call expressions producing every call-derived
|
|
47
57
|
// output at once: structured call sites + legacy bare names, custom hook
|
|
48
58
|
// calls, and API-call strings. The per-aspect extractors used to walk the
|
|
49
59
|
// same descendants tree four times per function-like; whole-repo cost is now
|
|
50
60
|
// one walk.
|
|
51
|
-
export function
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (/^use[A-Z]/.test(name) && !hookCalls.includes(name))
|
|
65
|
-
hookCalls.push(name);
|
|
66
|
-
if (!dependencyNames.includes(name))
|
|
67
|
-
dependencyNames.push(name);
|
|
68
|
-
if (name === "useContext") {
|
|
69
|
-
const ctxArg = call.getArguments()[0];
|
|
70
|
-
if (ctxArg && !contextRefs.includes(ctxArg.getText()))
|
|
71
|
-
contextRefs.push(ctxArg.getText());
|
|
72
|
-
}
|
|
61
|
+
export function classifyCall(call, acc) {
|
|
62
|
+
const name = call.getExpression().getText();
|
|
63
|
+
// use* family: custom hooks (^use[A-Z]) plus ALL use* names (incl.
|
|
64
|
+
// built-ins like useState) for hook dependency tracking
|
|
65
|
+
if (name.startsWith("use")) {
|
|
66
|
+
if (/^use[A-Z]/.test(name) && !acc.hookCalls.includes(name))
|
|
67
|
+
acc.hookCalls.push(name);
|
|
68
|
+
if (!acc.dependencyNames.includes(name))
|
|
69
|
+
acc.dependencyNames.push(name);
|
|
70
|
+
if (name === "useContext") {
|
|
71
|
+
const ctxArg = call.getArguments()[0];
|
|
72
|
+
if (ctxArg && !acc.contextRefs.includes(ctxArg.getText()))
|
|
73
|
+
acc.contextRefs.push(ctxArg.getText());
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (args.length > 0)
|
|
78
|
-
apiCalls.push(`${name}(${args[0].getText()})`);
|
|
79
|
-
}
|
|
80
|
-
// Plain calls/sites skip hooks and builtin noise
|
|
81
|
-
if (name.startsWith("use"))
|
|
82
|
-
continue;
|
|
83
|
-
const rootName = name.split(".")[0];
|
|
84
|
-
if (JS_BUILTINS.has(rootName))
|
|
85
|
-
continue;
|
|
75
|
+
}
|
|
76
|
+
// API-call families: fetch / axios.* / React Query / SWR
|
|
77
|
+
if (name === "fetch" || AXIOS_METHODS.has(name) || API_HOOK_FAMILIES.has(name)) {
|
|
86
78
|
const args = call.getArguments();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
if (args.length > 0)
|
|
80
|
+
acc.apiCalls.push(`${name}(${args[0].getText()})`);
|
|
81
|
+
}
|
|
82
|
+
// Plain calls/sites skip hooks and builtin noise
|
|
83
|
+
if (name.startsWith("use"))
|
|
84
|
+
return;
|
|
85
|
+
const rootName = name.split(".")[0];
|
|
86
|
+
if (JS_BUILTINS.has(rootName))
|
|
87
|
+
return;
|
|
88
|
+
const args = call.getArguments();
|
|
89
|
+
let hasSpread = false;
|
|
90
|
+
const argTypes = [];
|
|
91
|
+
for (const arg of args) {
|
|
92
|
+
if (arg.getKind?.() === SyntaxKind.SpreadElement) {
|
|
93
|
+
hasSpread = true;
|
|
94
|
+
argTypes.push("unknown");
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
argTypes.push(inferArgType(arg) ?? "unknown");
|
|
97
98
|
}
|
|
98
|
-
// One record per (name, arity, argTypes) triple — two calls to the same
|
|
99
|
-
// name with different arg counts OR arg type shapes are both overload
|
|
100
|
-
// signals (same arity + different literal types can hit different
|
|
101
|
-
// overloads, and each deserves its own edge).
|
|
102
|
-
const key = `${name}/${args.length}/${argTypes.join(",")}`;
|
|
103
|
-
if (seenSites.has(key))
|
|
104
|
-
continue;
|
|
105
|
-
seenSites.add(key);
|
|
106
|
-
sites.push({ name, argCount: args.length, argTypes, ...(hasSpread && { hasSpread: true }) });
|
|
107
99
|
}
|
|
100
|
+
// One record per (name, arity, argTypes) triple — two calls to the same
|
|
101
|
+
// name with different arg counts OR arg type shapes are both overload
|
|
102
|
+
// signals (same arity + different literal types can hit different
|
|
103
|
+
// overloads, and each deserves its own edge).
|
|
104
|
+
const key = `${name}/${args.length}/${argTypes.join(",")}`;
|
|
105
|
+
if (acc.seenSites.has(key))
|
|
106
|
+
return;
|
|
107
|
+
acc.seenSites.add(key);
|
|
108
|
+
acc.sites.push({ name, argCount: args.length, argTypes, ...(hasSpread && { hasSpread: true }) });
|
|
109
|
+
}
|
|
110
|
+
export function finishCalls(acc) {
|
|
108
111
|
return {
|
|
109
|
-
calls: [...new Set(sites.map((cs) => cs.name))],
|
|
110
|
-
callSites: sites,
|
|
111
|
-
hookCalls,
|
|
112
|
-
apiCalls,
|
|
113
|
-
dependencyNames,
|
|
114
|
-
contextRefs,
|
|
112
|
+
calls: [...new Set(acc.sites.map((cs) => cs.name))],
|
|
113
|
+
callSites: acc.sites,
|
|
114
|
+
hookCalls: acc.hookCalls,
|
|
115
|
+
apiCalls: acc.apiCalls,
|
|
116
|
+
dependencyNames: acc.dependencyNames,
|
|
117
|
+
contextRefs: acc.contextRefs,
|
|
115
118
|
};
|
|
116
119
|
}
|
|
120
|
+
export function extractCallsWithSites(node) {
|
|
121
|
+
const acc = createCallAccumulator();
|
|
122
|
+
for (const call of node.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
123
|
+
classifyCall(call, acc);
|
|
124
|
+
}
|
|
125
|
+
return finishCalls(acc);
|
|
126
|
+
}
|
|
117
127
|
export function extractFunctionCalls(node) {
|
|
118
128
|
return extractCallsWithSites(node).calls;
|
|
119
129
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SourceFile } from "ts-morph";
|
|
2
|
+
import { type ExtractedCallData } from "./functions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Collect every call executed at module scope, classified exactly like calls
|
|
5
|
+
* inside a function (same builtin filtering, hook/api tracking, call sites).
|
|
6
|
+
* Returns EMPTY data for files with no module-scope calls.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractModuleScopeCalls(file: SourceFile): ExtractedCallData;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { SyntaxKind } from "ts-morph";
|
|
2
|
+
import { classifyCall, createCallAccumulator, finishCalls, } from "./functions.js";
|
|
3
|
+
// ─── Module-scope call extraction ─────────────────────────────────────────────
|
|
4
|
+
//
|
|
5
|
+
// A FILE node represents the module itself. Calls executed at module scope
|
|
6
|
+
// (`const cleanup = startAll()`, `const app = express()`, top-level `if`
|
|
7
|
+
// blocks) belong to that FILE node, not to any child function. Entry files
|
|
8
|
+
// (main.ts, server.ts, workers.ts) do most of their work here, so without this
|
|
9
|
+
// pass the graph shows them importing things but never calling anything.
|
|
10
|
+
//
|
|
11
|
+
// Scope rule: a call is module scope iff its nearest function-like/class
|
|
12
|
+
// ancestor is absent. Everything nested in a function body, arrow initializer,
|
|
13
|
+
// class field, or static block belongs to that owner and is extracted by the
|
|
14
|
+
// regular per-declaration extractors.
|
|
15
|
+
const NON_MODULE_ANCESTORS = new Set([
|
|
16
|
+
SyntaxKind.FunctionDeclaration,
|
|
17
|
+
SyntaxKind.FunctionExpression,
|
|
18
|
+
SyntaxKind.ArrowFunction,
|
|
19
|
+
SyntaxKind.MethodDeclaration,
|
|
20
|
+
SyntaxKind.Constructor,
|
|
21
|
+
SyntaxKind.GetAccessor,
|
|
22
|
+
SyntaxKind.SetAccessor,
|
|
23
|
+
SyntaxKind.ClassDeclaration,
|
|
24
|
+
SyntaxKind.ClassExpression,
|
|
25
|
+
SyntaxKind.ClassStaticBlockDeclaration,
|
|
26
|
+
]);
|
|
27
|
+
// Top-level statements that cannot contain module-scope calls. Skipping them
|
|
28
|
+
// before descending is the perf win: a 3k-line file of function declarations
|
|
29
|
+
// costs nothing here (correctness is still guaranteed by the ancestor guard).
|
|
30
|
+
const SKIP_TOP_LEVEL = new Set([
|
|
31
|
+
SyntaxKind.FunctionDeclaration,
|
|
32
|
+
SyntaxKind.ClassDeclaration,
|
|
33
|
+
SyntaxKind.InterfaceDeclaration,
|
|
34
|
+
SyntaxKind.TypeAliasDeclaration,
|
|
35
|
+
SyntaxKind.EnumDeclaration,
|
|
36
|
+
SyntaxKind.ModuleDeclaration,
|
|
37
|
+
SyntaxKind.ImportDeclaration,
|
|
38
|
+
SyntaxKind.ImportEqualsDeclaration,
|
|
39
|
+
SyntaxKind.ExportDeclaration,
|
|
40
|
+
]);
|
|
41
|
+
/**
|
|
42
|
+
* Collect every call executed at module scope, classified exactly like calls
|
|
43
|
+
* inside a function (same builtin filtering, hook/api tracking, call sites).
|
|
44
|
+
* Returns EMPTY data for files with no module-scope calls.
|
|
45
|
+
*/
|
|
46
|
+
export function extractModuleScopeCalls(file) {
|
|
47
|
+
const acc = createCallAccumulator();
|
|
48
|
+
for (const stmt of file.getStatements()) {
|
|
49
|
+
if (SKIP_TOP_LEVEL.has(stmt.getKind()))
|
|
50
|
+
continue;
|
|
51
|
+
for (const call of stmt.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
52
|
+
if (isOwnedByDeclaration(call))
|
|
53
|
+
continue;
|
|
54
|
+
// Dynamic import() is a CallExpression whose callee is ImportKeyword —
|
|
55
|
+
// not a function call; recording it as `import(...)` is pure noise.
|
|
56
|
+
if (call.getExpression().getKind() === SyntaxKind.ImportKeyword)
|
|
57
|
+
continue;
|
|
58
|
+
// IIFE: the callee is an inline function expression, so the "name" would
|
|
59
|
+
// be the whole function body text. Its body is already excluded by the
|
|
60
|
+
// ancestor rule; the call itself carries no resolvable name.
|
|
61
|
+
if (isIifeCallee(call.getExpression()))
|
|
62
|
+
continue;
|
|
63
|
+
classifyCall(call, acc);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return finishCalls(acc);
|
|
67
|
+
}
|
|
68
|
+
function isOwnedByDeclaration(call) {
|
|
69
|
+
return Boolean(call.getFirstAncestor((ancestor) => NON_MODULE_ANCESTORS.has(ancestor.getKind())));
|
|
70
|
+
}
|
|
71
|
+
// `(async () => { ... })()` / `(function () { ... })()` — unwrap parentheses
|
|
72
|
+
// and detect a function-expression callee.
|
|
73
|
+
function isIifeCallee(callee) {
|
|
74
|
+
let expr = callee;
|
|
75
|
+
while (expr.getKind() === SyntaxKind.ParenthesizedExpression) {
|
|
76
|
+
expr = expr.getExpression();
|
|
77
|
+
}
|
|
78
|
+
return (expr.getKind() === SyntaxKind.ArrowFunction ||
|
|
79
|
+
expr.getKind() === SyntaxKind.FunctionExpression);
|
|
80
|
+
}
|
package/dist/parser/index.d.ts
CHANGED
package/dist/parser/index.js
CHANGED
|
@@ -7,8 +7,10 @@ import { extractFunctions } from "./extractors/functions.js";
|
|
|
7
7
|
import { extractStores } from "./extractors/stores.js";
|
|
8
8
|
import { extractObjectMethods } from "./extractors/objectMethods.js";
|
|
9
9
|
import { extractClasses } from "./extractors/classes.js";
|
|
10
|
+
import { extractModuleScopeCalls } from "./extractors/moduleScope.js";
|
|
10
11
|
import { detectFileDirective } from "./directives.js";
|
|
11
12
|
import { applyOverloadDisambiguation } from "./overloads.js";
|
|
13
|
+
import { buildExportsMap, validateExportsMap, exportsMapStats } from "./exportsMap.js";
|
|
12
14
|
import { createHash } from "crypto";
|
|
13
15
|
// Directories to skip entirely while walking
|
|
14
16
|
const IGNORE_DIRS = [
|
|
@@ -106,6 +108,9 @@ export function parseRepo(repoPath) {
|
|
|
106
108
|
},
|
|
107
109
|
};
|
|
108
110
|
const fileDirective = detectFileDirective(file);
|
|
111
|
+
// Module scope — calls executed at file load belong to the FILE node.
|
|
112
|
+
// TEST/STORY files are leaves and never carry them (same rule as children).
|
|
113
|
+
const moduleScope = fileType === "FILE" ? extractModuleScopeCalls(file) : undefined;
|
|
109
114
|
const components = extractComponents(file, fileDirective);
|
|
110
115
|
const hooks = extractHooks(file, fileDirective);
|
|
111
116
|
const functions = extractFunctions(file, fileDirective);
|
|
@@ -144,6 +149,14 @@ export function parseRepo(repoPath) {
|
|
|
144
149
|
else {
|
|
145
150
|
fileNode.metadata.nodeCount = overloads.length;
|
|
146
151
|
fileNode.metadata.childNodeIds = overloads.map(n => n.id);
|
|
152
|
+
// Module-scope call facts — only when non-empty so files with no
|
|
153
|
+
// top-level work don't gain four meaningless metadata keys.
|
|
154
|
+
if (moduleScope && moduleScope.callSites.length > 0) {
|
|
155
|
+
fileNode.metadata.calls = moduleScope.calls;
|
|
156
|
+
fileNode.metadata.callSites = moduleScope.callSites;
|
|
157
|
+
fileNode.metadata.hookCalls = moduleScope.hookCalls;
|
|
158
|
+
fileNode.metadata.apiCalls = moduleScope.apiCalls;
|
|
159
|
+
}
|
|
147
160
|
// File node hash — based on all child code combined
|
|
148
161
|
const fileRawCode = overloads.map(n => n.rawCode ?? "").join("\n");
|
|
149
162
|
if (fileRawCode.trim()) {
|
|
@@ -164,8 +177,40 @@ export function parseRepo(repoPath) {
|
|
|
164
177
|
const storeCount = allNodes.filter((n) => n.type === "STATE_STORE").length;
|
|
165
178
|
const classCount = allNodes.filter((n) => n.type === "CLASS").length;
|
|
166
179
|
const methodCount = allNodes.filter((n) => n.type === "METHOD").length;
|
|
180
|
+
let exports;
|
|
181
|
+
try {
|
|
182
|
+
const built = buildExportsMap(project, repoPath, allNodes);
|
|
183
|
+
if (built) {
|
|
184
|
+
const dangling = validateExportsMap(built, new Set(allNodes.map((n) => n.id)));
|
|
185
|
+
if (dangling.length > 0) {
|
|
186
|
+
console.warn(`Exports map: dropping ${dangling.length} dangling nodeId references`);
|
|
187
|
+
for (const perPath of Object.values(built.exports)) {
|
|
188
|
+
for (const [name, ids] of Object.entries(perPath)) {
|
|
189
|
+
const filtered = ids.filter((id) => !dangling.includes(id));
|
|
190
|
+
if (filtered.length > 0)
|
|
191
|
+
perPath[name] = filtered;
|
|
192
|
+
else
|
|
193
|
+
delete perPath[name];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const [subpath, perPath] of Object.entries(built.exports)) {
|
|
197
|
+
if (Object.keys(perPath).length === 0)
|
|
198
|
+
delete built.exports[subpath];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (Object.keys(built.exports).length > 0) {
|
|
202
|
+
exports = built;
|
|
203
|
+
const s = exportsMapStats(built);
|
|
204
|
+
console.log(` Exports map: ${s.names} names across ${s.subpaths} subpath(s), ${s.ambiguous} ambiguous`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
console.warn(`Exports map build failed — continuing without it: ${err}`);
|
|
210
|
+
}
|
|
167
211
|
return {
|
|
168
212
|
nodes: allNodes,
|
|
213
|
+
exports,
|
|
169
214
|
stats: {
|
|
170
215
|
totalFiles: sourceFiles.length,
|
|
171
216
|
totalNodes: allNodes.length,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import os from "os";
|
|
4
|
+
import { Project } from "ts-morph";
|
|
5
|
+
import { extractModuleScopeCalls } from "./extractors/moduleScope.js";
|
|
6
|
+
import { parseRepo } from "./index.js";
|
|
7
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
8
|
+
function parse(source) {
|
|
9
|
+
const project = new Project({ useInMemoryFileSystem: true });
|
|
10
|
+
const file = project.createSourceFile("main.ts", source);
|
|
11
|
+
return extractModuleScopeCalls(file);
|
|
12
|
+
}
|
|
13
|
+
function createFakeRepo(files) {
|
|
14
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "devlens-module-scope-test-"));
|
|
15
|
+
for (const [filePath, content] of Object.entries(files)) {
|
|
16
|
+
const fullPath = path.join(tmpDir, filePath);
|
|
17
|
+
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
18
|
+
fs.writeFileSync(fullPath, content);
|
|
19
|
+
}
|
|
20
|
+
return tmpDir;
|
|
21
|
+
}
|
|
22
|
+
function deleteFakeRepo(repoPath) {
|
|
23
|
+
fs.rmSync(repoPath, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
// ─── Scope rule ───────────────────────────────────────────────────────────────
|
|
26
|
+
describe("extractModuleScopeCalls — scope rule", () => {
|
|
27
|
+
it("collects a call in a top-level variable initializer", () => {
|
|
28
|
+
const data = parse(`
|
|
29
|
+
import { startAll } from "./lib/startAll";
|
|
30
|
+
const cleanup = startAll();
|
|
31
|
+
`);
|
|
32
|
+
expect(data.calls).toEqual(["startAll"]);
|
|
33
|
+
expect(data.callSites).toEqual([{ name: "startAll", argCount: 0, argTypes: [] }]);
|
|
34
|
+
});
|
|
35
|
+
it("collects calls inside a top-level if block", () => {
|
|
36
|
+
const data = parse(`
|
|
37
|
+
if (process.env.NODE_ENV === "production") {
|
|
38
|
+
startAll();
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
expect(data.calls).toEqual(["startAll"]);
|
|
42
|
+
});
|
|
43
|
+
it("collects exported top-level initializers", () => {
|
|
44
|
+
const data = parse(`export const app = createApp();`);
|
|
45
|
+
expect(data.calls).toEqual(["createApp"]);
|
|
46
|
+
});
|
|
47
|
+
it("does NOT collect calls inside a function body", () => {
|
|
48
|
+
const data = parse(`
|
|
49
|
+
function boot() {
|
|
50
|
+
startAll();
|
|
51
|
+
}
|
|
52
|
+
`);
|
|
53
|
+
expect(data.calls).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
it("does NOT collect calls inside an arrow-function initializer", () => {
|
|
56
|
+
const data = parse(`const boot = () => startAll();`);
|
|
57
|
+
expect(data.calls).toEqual([]);
|
|
58
|
+
});
|
|
59
|
+
it("does NOT collect calls inside a class method", () => {
|
|
60
|
+
const data = parse(`
|
|
61
|
+
class Boot {
|
|
62
|
+
run() { startAll(); }
|
|
63
|
+
}
|
|
64
|
+
`);
|
|
65
|
+
expect(data.calls).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
it("does NOT collect calls inside a class field initializer", () => {
|
|
68
|
+
const data = parse(`
|
|
69
|
+
class Boot {
|
|
70
|
+
cleanup = startAll();
|
|
71
|
+
}
|
|
72
|
+
`);
|
|
73
|
+
expect(data.calls).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
it("does NOT collect calls inside a class static block", () => {
|
|
76
|
+
const data = parse(`
|
|
77
|
+
class Boot {
|
|
78
|
+
static { startAll(); }
|
|
79
|
+
}
|
|
80
|
+
`);
|
|
81
|
+
expect(data.calls).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
it("does NOT collect an IIFE body (the IIFE is a function scope)", () => {
|
|
84
|
+
const data = parse(`
|
|
85
|
+
(async () => { startAll(); })();
|
|
86
|
+
`);
|
|
87
|
+
expect(data.calls).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
it("does NOT collect dynamic import()", () => {
|
|
90
|
+
const data = parse(`const mod = await import("./lib/startAll");`);
|
|
91
|
+
expect(data.calls).toEqual([]);
|
|
92
|
+
});
|
|
93
|
+
it("returns empty data for a file with only declarations", () => {
|
|
94
|
+
const data = parse(`export function a() {} export class B {}`);
|
|
95
|
+
expect(data.calls).toEqual([]);
|
|
96
|
+
expect(data.callSites).toEqual([]);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
// ─── Builtin noise (same rule as function bodies) ─────────────────────────────
|
|
100
|
+
describe("extractModuleScopeCalls — builtin filtering", () => {
|
|
101
|
+
it("drops console.* and Math.* at module scope", () => {
|
|
102
|
+
const data = parse(`
|
|
103
|
+
console.log("booting");
|
|
104
|
+
const n = Math.min(1, 2);
|
|
105
|
+
startAll();
|
|
106
|
+
`);
|
|
107
|
+
expect(data.calls).toEqual(["startAll"]);
|
|
108
|
+
});
|
|
109
|
+
it("drops builtin member calls but keeps user calls with the same shape", () => {
|
|
110
|
+
const data = parse(`
|
|
111
|
+
Object.keys({});
|
|
112
|
+
JSON.stringify({});
|
|
113
|
+
app.listen(3000);
|
|
114
|
+
`);
|
|
115
|
+
expect(data.calls).toEqual(["app.listen"]);
|
|
116
|
+
});
|
|
117
|
+
it("keeps use* names in hookCalls but not in calls (hook rule)", () => {
|
|
118
|
+
const data = parse(`
|
|
119
|
+
const theme = useTheme();
|
|
120
|
+
startAll();
|
|
121
|
+
`);
|
|
122
|
+
expect(data.calls).toEqual(["startAll"]);
|
|
123
|
+
expect(data.hookCalls).toEqual(["useTheme"]);
|
|
124
|
+
});
|
|
125
|
+
it("captures fetch at module scope as an api call", () => {
|
|
126
|
+
const data = parse(`const cfg = fetch("/config");`);
|
|
127
|
+
expect(data.apiCalls).toEqual(['fetch("/config")']);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
// ─── parseRepo wiring ─────────────────────────────────────────────────────────
|
|
131
|
+
describe("parseRepo — module-scope metadata on FILE nodes", () => {
|
|
132
|
+
it("attaches calls/callSites to the FILE node", () => {
|
|
133
|
+
const repo = createFakeRepo({
|
|
134
|
+
"lib/startAll.ts": `export function startAll() { return () => {}; }`,
|
|
135
|
+
"main.ts": `
|
|
136
|
+
import { startAll } from "./lib/startAll";
|
|
137
|
+
const cleanup = startAll();
|
|
138
|
+
process.on("SIGTERM", cleanup);
|
|
139
|
+
`,
|
|
140
|
+
});
|
|
141
|
+
const { nodes } = parseRepo(repo);
|
|
142
|
+
const file = nodes.find((n) => n.id === "file::main.ts");
|
|
143
|
+
expect(file.type).toBe("FILE");
|
|
144
|
+
expect(file.metadata.calls).toEqual(["startAll", "process.on"]);
|
|
145
|
+
expect(file.metadata.callSites).toEqual([
|
|
146
|
+
{ name: "startAll", argCount: 0, argTypes: [] },
|
|
147
|
+
{ name: "process.on", argCount: 2, argTypes: ["string", "unknown"] },
|
|
148
|
+
]);
|
|
149
|
+
deleteFakeRepo(repo);
|
|
150
|
+
});
|
|
151
|
+
it("does not attach module-scope keys to files with no top-level calls", () => {
|
|
152
|
+
const repo = createFakeRepo({
|
|
153
|
+
"lib/startAll.ts": `export function startAll() { return 1; }`,
|
|
154
|
+
});
|
|
155
|
+
const { nodes } = parseRepo(repo);
|
|
156
|
+
const file = nodes.find((n) => n.id === "file::lib/startAll.ts");
|
|
157
|
+
expect(file.metadata.calls).toBeUndefined();
|
|
158
|
+
expect(file.metadata.callSites).toBeUndefined();
|
|
159
|
+
deleteFakeRepo(repo);
|
|
160
|
+
});
|
|
161
|
+
it("does not attach module-scope facts to TEST file nodes", () => {
|
|
162
|
+
const repo = createFakeRepo({
|
|
163
|
+
"main.test.ts": `
|
|
164
|
+
import { startAll } from "./lib/startAll";
|
|
165
|
+
const cleanup = startAll();
|
|
166
|
+
`,
|
|
167
|
+
});
|
|
168
|
+
const { nodes } = parseRepo(repo);
|
|
169
|
+
const file = nodes.find((n) => n.id === "file::main.test.ts");
|
|
170
|
+
expect(file.type).toBe("TEST");
|
|
171
|
+
expect(file.metadata.calls).toBeUndefined();
|
|
172
|
+
deleteFakeRepo(repo);
|
|
173
|
+
});
|
|
174
|
+
});
|
package/dist/pipeline/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FilterThresholds } from "../scoring/noiseFilter.js";
|
|
2
|
-
import type { CodeNode, CodeEdge, ProjectFingerprint, RouteNode, BackendRouteNode } from "../types.js";
|
|
2
|
+
import type { CodeNode, CodeEdge, ProjectFingerprint, RouteNode, BackendRouteNode, GraphExports } from "../types.js";
|
|
3
3
|
export type { FilterThresholds };
|
|
4
4
|
export interface GitInfo {
|
|
5
5
|
commitHash: string;
|
|
@@ -37,6 +37,7 @@ export interface PipelineResult {
|
|
|
37
37
|
analyzedAt: string;
|
|
38
38
|
fingerprint: ProjectFingerprint;
|
|
39
39
|
routes: (RouteNode | BackendRouteNode)[];
|
|
40
|
+
exports?: GraphExports;
|
|
40
41
|
nodes: CodeNode[];
|
|
41
42
|
edges: CodeEdge[];
|
|
42
43
|
allNodes: CodeNode[];
|
package/dist/pipeline/index.js
CHANGED
|
@@ -251,6 +251,7 @@ export async function analyzePipeline(repoPath, isGithubRepo, options) {
|
|
|
251
251
|
analyzedAt,
|
|
252
252
|
fingerprint: extractorResult.fingerprint,
|
|
253
253
|
routes: extractorResult.routes ?? [],
|
|
254
|
+
exports: extractorResult.exports,
|
|
254
255
|
nodes: scoringResult.filteredNodes,
|
|
255
256
|
edges: scoringResult.filteredEdges,
|
|
256
257
|
allNodes,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PipelineResult, PipelineStats } from "../pipeline/index.js";
|
|
2
|
-
import type { CodeNode, CodeEdge } from "../types.js";
|
|
2
|
+
import type { CodeNode, CodeEdge, GraphExports } from "../types.js";
|
|
3
3
|
import type { GraphStorage } from "./interface.js";
|
|
4
4
|
export interface GraphIndexEntry {
|
|
5
5
|
graphId: string;
|
|
@@ -44,6 +44,7 @@ export interface CommitData {
|
|
|
44
44
|
allEdges: CodeEdge[];
|
|
45
45
|
nodeScores: Record<string, number>;
|
|
46
46
|
stats: PipelineStats;
|
|
47
|
+
exports?: GraphExports;
|
|
47
48
|
}
|
|
48
49
|
export interface NodeDiff {
|
|
49
50
|
added: DiffNode[];
|
|
@@ -14,7 +14,9 @@ import { simpleGit } from "simple-git";
|
|
|
14
14
|
//
|
|
15
15
|
// Diffs are computed on demand — not stored.
|
|
16
16
|
// GitHub scope is reserved in meta.json for future cloud repo support.
|
|
17
|
-
const STORAGE_DIR =
|
|
17
|
+
const STORAGE_DIR = process.env.DEVLENS_STORAGE_DIR
|
|
18
|
+
? path.resolve(process.env.DEVLENS_STORAGE_DIR)
|
|
19
|
+
: path.join(os.homedir(), ".devlens");
|
|
18
20
|
const GRAPHS_DIR = path.join(STORAGE_DIR, "graphs");
|
|
19
21
|
const INDEX_FILE = path.join(STORAGE_DIR, "index.json");
|
|
20
22
|
const SCHEMA_VERSION = "1.0";
|
|
@@ -118,6 +120,7 @@ function buildCommitData(result) {
|
|
|
118
120
|
allEdges: result.allEdges,
|
|
119
121
|
nodeScores: result.nodeScores,
|
|
120
122
|
stats: result.stats,
|
|
123
|
+
exports: result.exports,
|
|
121
124
|
};
|
|
122
125
|
}
|
|
123
126
|
// ─── Public API ───────────────────────────────────────────────────────────────
|
|
@@ -239,6 +242,7 @@ export function getGraph(graphId, commitHash // defaults to latest commit
|
|
|
239
242
|
allEdges: data.allEdges,
|
|
240
243
|
nodeScores: data.nodeScores,
|
|
241
244
|
stats: data.stats,
|
|
245
|
+
exports: data.exports,
|
|
242
246
|
isGithubRepo: meta.isGithubRepo,
|
|
243
247
|
gitInfo: {
|
|
244
248
|
commitHash: data.commitHash,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|