@snevins/repo-mapper 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/output.js +29 -1
- package/package.json +1 -1
package/dist/output.js
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
import { estimateTokens } from "./tokens.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get files that a given file depends on (outgoing edges).
|
|
4
|
+
* Returns file paths sorted by edge weight descending.
|
|
5
|
+
*/
|
|
6
|
+
function getFileDependencies(file, graph) {
|
|
7
|
+
const edges = graph.edges.get(file);
|
|
8
|
+
if (!edges)
|
|
9
|
+
return [];
|
|
10
|
+
return [...edges.entries()]
|
|
11
|
+
.sort((a, b) => b[1] - a[1])
|
|
12
|
+
.map(([target]) => target);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get files that depend on a given file (incoming edges).
|
|
16
|
+
* Returns file paths sorted by edge weight descending.
|
|
17
|
+
*/
|
|
18
|
+
function getFileDependents(file, graph) {
|
|
19
|
+
const dependents = [];
|
|
20
|
+
for (const [from, toMap] of graph.edges) {
|
|
21
|
+
const weight = toMap.get(file);
|
|
22
|
+
if (weight !== undefined) {
|
|
23
|
+
dependents.push([from, weight]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return dependents.sort((a, b) => b[1] - a[1]).map(([from]) => from);
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* Max definitions per unique name in output to prevent repetition.
|
|
4
30
|
*/
|
|
@@ -195,7 +221,9 @@ export function formatOutput(defs, graph, fileRanks, focusFiles, maxFilesPerModu
|
|
|
195
221
|
if (!fileDefs || fileDefs.length === 0)
|
|
196
222
|
continue;
|
|
197
223
|
const fileRank = fileRanks.get(file) ?? 0;
|
|
198
|
-
|
|
224
|
+
const deps = getFileDependents(file, graph);
|
|
225
|
+
const depsStr = deps.length > 0 ? ` (used-by: ${deps.slice(0, 3).join(", ")}${deps.length > 3 ? ", ..." : ""})` : "";
|
|
226
|
+
lines.push(`${file}: ${formatRankDisplay(fileRank, allRanks)}${depsStr}`);
|
|
199
227
|
// Sort definitions by line ascending
|
|
200
228
|
const sorted = [...fileDefs].sort((a, b) => a.tag.line - b.tag.line);
|
|
201
229
|
for (const def of sorted) {
|