cartotree 0.2.0 → 0.2.1
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/.claude-plugin/marketplace.json +11 -11
- package/.claude-plugin/plugin.json +12 -12
- package/LICENSE +20 -20
- package/README.md +270 -246
- package/bin/cartotree.js +162 -162
- package/hooks/hooks.json +14 -14
- package/package.json +45 -45
- package/skills/cartotree/SKILL.md +32 -32
- package/src/ai.js +112 -112
- package/src/atlas/cache.js +46 -46
- package/src/atlas/files.js +56 -56
- package/src/atlas/git.js +65 -65
- package/src/atlas/init.js +114 -114
- package/src/atlas/links.js +87 -87
- package/src/atlas/locate.js +218 -218
- package/src/atlas/mcp.js +106 -106
- package/src/atlas/peek.js +24 -24
- package/src/atlas/symbols.js +41 -41
- package/src/clipboard.js +10 -10
- package/src/config.js +25 -25
- package/src/exports.js +73 -73
- package/src/ignore.js +30 -30
- package/src/sync.js +29 -29
- package/src/tree.js +96 -96
package/src/atlas/init.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cartotree init — set up a project so AI agents use cartotree automatically.
|
|
3
|
-
* Only runs when the user calls it (never from npm postinstall). Shows every change; --dry-run writes nothing.
|
|
4
|
-
*
|
|
5
|
-
* Claude Code:
|
|
6
|
-
* .claude/skills/cartotree/SKILL.md how and when to use the tools
|
|
7
|
-
* .mcp.json registers the cartotree MCP server
|
|
8
|
-
* .claude/settings.json SessionStart hook with a one-line reminder (skip with --no-hook)
|
|
9
|
-
* .gitignore ignores .cartotree/ (index cache)
|
|
10
|
-
* Other agents (Cursor, Codex, ...): writes the skill under their skills folder when it exists.
|
|
11
|
-
*/
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
|
|
15
|
-
const SKILL_SRC = path.join(__dirname, '..', '..', 'skills', 'cartotree', 'SKILL.md');
|
|
16
|
-
const HOOK_CMD = "echo 'cartotree is available: to find where code lives, call cartotree_locate first (then cartotree_peek to confirm) before grep or reading whole files.'";
|
|
17
|
-
const MCP_ENTRY = { command: 'npx', args: ['-y', 'cartotree@latest', 'mcp'] };
|
|
18
|
-
|
|
19
|
-
const AGENT_SKILL_DIRS = {
|
|
20
|
-
'claude-code': '.claude/skills',
|
|
21
|
-
cursor: '.cursor/skills',
|
|
22
|
-
codex: '.codex/skills',
|
|
23
|
-
windsurf: '.windsurf/skills',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function readJson(file, fallback) {
|
|
27
|
-
try {
|
|
28
|
-
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
29
|
-
} catch {
|
|
30
|
-
return fallback;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function detectAgents(root) {
|
|
35
|
-
const found = Object.keys(AGENT_SKILL_DIRS).filter(a => fs.existsSync(path.join(root, AGENT_SKILL_DIRS[a].split('/')[0])));
|
|
36
|
-
return found.length ? found : ['claude-code'];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function plan(root, { agents, hook = true } = {}) {
|
|
40
|
-
const steps = [];
|
|
41
|
-
const list = agents && agents.length ? agents : detectAgents(root);
|
|
42
|
-
const skill = fs.readFileSync(SKILL_SRC, 'utf-8');
|
|
43
|
-
|
|
44
|
-
for (const a of list) {
|
|
45
|
-
const dir = AGENT_SKILL_DIRS[a];
|
|
46
|
-
if (!dir) continue;
|
|
47
|
-
steps.push({ file: path.join(dir, 'cartotree', 'SKILL.md'), why: `skill for ${a}`, write: () => skill });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (list.includes('claude-code')) {
|
|
51
|
-
steps.push({
|
|
52
|
-
file: '.mcp.json',
|
|
53
|
-
why: 'register cartotree MCP server',
|
|
54
|
-
write: prev => {
|
|
55
|
-
const j = prev ? JSON.parse(prev) : {};
|
|
56
|
-
j.mcpServers = { ...(j.mcpServers || {}), cartotree: MCP_ENTRY };
|
|
57
|
-
return JSON.stringify(j, null, 2) + '\n';
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
if (hook) {
|
|
61
|
-
steps.push({
|
|
62
|
-
file: '.claude/settings.json',
|
|
63
|
-
why: 'SessionStart reminder to use cartotree',
|
|
64
|
-
write: prev => {
|
|
65
|
-
const j = prev ? JSON.parse(prev) : {};
|
|
66
|
-
j.hooks = j.hooks || {};
|
|
67
|
-
const ss = (j.hooks.SessionStart = j.hooks.SessionStart || []);
|
|
68
|
-
const exists = ss.some(g => (g.hooks || []).some(h => h.command === HOOK_CMD));
|
|
69
|
-
if (!exists) ss.push({ hooks: [{ type: 'command', command: HOOK_CMD }] });
|
|
70
|
-
return JSON.stringify(j, null, 2) + '\n';
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
steps.push({
|
|
77
|
-
file: '.gitignore',
|
|
78
|
-
why: 'ignore index cache',
|
|
79
|
-
write: prev => {
|
|
80
|
-
const body = prev || '';
|
|
81
|
-
if (body.split('\n').some(l => l.trim() === '.cartotree/')) return body;
|
|
82
|
-
return body + (body && !body.endsWith('\n') ? '\n' : '') + '.cartotree/\n';
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
return { agents: list, steps };
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function runInit(root, { agents, hook = true, dryRun = false } = {}) {
|
|
89
|
-
const { agents: list, steps } = plan(root, { agents, hook });
|
|
90
|
-
const report = [];
|
|
91
|
-
for (const s of steps) {
|
|
92
|
-
const abs = path.join(root, s.file);
|
|
93
|
-
const prev = fs.existsSync(abs) ? fs.readFileSync(abs, 'utf-8') : null;
|
|
94
|
-
if (prev !== null && s.file.endsWith('.json')) {
|
|
95
|
-
if (readJson(abs, null) === null) {
|
|
96
|
-
report.push(`skip ${s.file} (not valid JSON — edit it by hand)`);
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const next = s.write(prev);
|
|
101
|
-
if (prev === next) {
|
|
102
|
-
report.push(`ok ${s.file} (already set up)`);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
report.push(`${prev === null ? 'create' : 'update'} ${s.file} — ${s.why}`);
|
|
106
|
-
if (!dryRun) {
|
|
107
|
-
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
108
|
-
fs.writeFileSync(abs, next);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return { agents: list, report };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
module.exports = { runInit, plan, MCP_ENTRY };
|
|
1
|
+
/**
|
|
2
|
+
* cartotree init — set up a project so AI agents use cartotree automatically.
|
|
3
|
+
* Only runs when the user calls it (never from npm postinstall). Shows every change; --dry-run writes nothing.
|
|
4
|
+
*
|
|
5
|
+
* Claude Code:
|
|
6
|
+
* .claude/skills/cartotree/SKILL.md how and when to use the tools
|
|
7
|
+
* .mcp.json registers the cartotree MCP server
|
|
8
|
+
* .claude/settings.json SessionStart hook with a one-line reminder (skip with --no-hook)
|
|
9
|
+
* .gitignore ignores .cartotree/ (index cache)
|
|
10
|
+
* Other agents (Cursor, Codex, ...): writes the skill under their skills folder when it exists.
|
|
11
|
+
*/
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
|
|
15
|
+
const SKILL_SRC = path.join(__dirname, '..', '..', 'skills', 'cartotree', 'SKILL.md');
|
|
16
|
+
const HOOK_CMD = "echo 'cartotree is available: to find where code lives, call cartotree_locate first (then cartotree_peek to confirm) before grep or reading whole files.'";
|
|
17
|
+
const MCP_ENTRY = { command: 'npx', args: ['-y', 'cartotree@latest', 'mcp'] };
|
|
18
|
+
|
|
19
|
+
const AGENT_SKILL_DIRS = {
|
|
20
|
+
'claude-code': '.claude/skills',
|
|
21
|
+
cursor: '.cursor/skills',
|
|
22
|
+
codex: '.codex/skills',
|
|
23
|
+
windsurf: '.windsurf/skills',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function readJson(file, fallback) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
29
|
+
} catch {
|
|
30
|
+
return fallback;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function detectAgents(root) {
|
|
35
|
+
const found = Object.keys(AGENT_SKILL_DIRS).filter(a => fs.existsSync(path.join(root, AGENT_SKILL_DIRS[a].split('/')[0])));
|
|
36
|
+
return found.length ? found : ['claude-code'];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function plan(root, { agents, hook = true } = {}) {
|
|
40
|
+
const steps = [];
|
|
41
|
+
const list = agents && agents.length ? agents : detectAgents(root);
|
|
42
|
+
const skill = fs.readFileSync(SKILL_SRC, 'utf-8');
|
|
43
|
+
|
|
44
|
+
for (const a of list) {
|
|
45
|
+
const dir = AGENT_SKILL_DIRS[a];
|
|
46
|
+
if (!dir) continue;
|
|
47
|
+
steps.push({ file: path.join(dir, 'cartotree', 'SKILL.md'), why: `skill for ${a}`, write: () => skill });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (list.includes('claude-code')) {
|
|
51
|
+
steps.push({
|
|
52
|
+
file: '.mcp.json',
|
|
53
|
+
why: 'register cartotree MCP server',
|
|
54
|
+
write: prev => {
|
|
55
|
+
const j = prev ? JSON.parse(prev) : {};
|
|
56
|
+
j.mcpServers = { ...(j.mcpServers || {}), cartotree: MCP_ENTRY };
|
|
57
|
+
return JSON.stringify(j, null, 2) + '\n';
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (hook) {
|
|
61
|
+
steps.push({
|
|
62
|
+
file: '.claude/settings.json',
|
|
63
|
+
why: 'SessionStart reminder to use cartotree',
|
|
64
|
+
write: prev => {
|
|
65
|
+
const j = prev ? JSON.parse(prev) : {};
|
|
66
|
+
j.hooks = j.hooks || {};
|
|
67
|
+
const ss = (j.hooks.SessionStart = j.hooks.SessionStart || []);
|
|
68
|
+
const exists = ss.some(g => (g.hooks || []).some(h => h.command === HOOK_CMD));
|
|
69
|
+
if (!exists) ss.push({ hooks: [{ type: 'command', command: HOOK_CMD }] });
|
|
70
|
+
return JSON.stringify(j, null, 2) + '\n';
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
steps.push({
|
|
77
|
+
file: '.gitignore',
|
|
78
|
+
why: 'ignore index cache',
|
|
79
|
+
write: prev => {
|
|
80
|
+
const body = prev || '';
|
|
81
|
+
if (body.split('\n').some(l => l.trim() === '.cartotree/')) return body;
|
|
82
|
+
return body + (body && !body.endsWith('\n') ? '\n' : '') + '.cartotree/\n';
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
return { agents: list, steps };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function runInit(root, { agents, hook = true, dryRun = false } = {}) {
|
|
89
|
+
const { agents: list, steps } = plan(root, { agents, hook });
|
|
90
|
+
const report = [];
|
|
91
|
+
for (const s of steps) {
|
|
92
|
+
const abs = path.join(root, s.file);
|
|
93
|
+
const prev = fs.existsSync(abs) ? fs.readFileSync(abs, 'utf-8') : null;
|
|
94
|
+
if (prev !== null && s.file.endsWith('.json')) {
|
|
95
|
+
if (readJson(abs, null) === null) {
|
|
96
|
+
report.push(`skip ${s.file} (not valid JSON — edit it by hand)`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const next = s.write(prev);
|
|
101
|
+
if (prev === next) {
|
|
102
|
+
report.push(`ok ${s.file} (already set up)`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
report.push(`${prev === null ? 'create' : 'update'} ${s.file} — ${s.why}`);
|
|
106
|
+
if (!dryRun) {
|
|
107
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
108
|
+
fs.writeFileSync(abs, next);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { agents: list, report };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { runInit, plan, MCP_ENTRY };
|
package/src/atlas/links.js
CHANGED
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* atlas links — a compact "connection map" for a file or symbol, so an agent
|
|
3
|
-
* can follow a call chain without reading whole files.
|
|
4
|
-
*/
|
|
5
|
-
const { listSourceFiles, readSafe } = require('./files');
|
|
6
|
-
const { parseExportsFromText, parseImports } = require('./symbols');
|
|
7
|
-
const { readHistory, coChanges, recentChanges } = require('./git');
|
|
8
|
-
|
|
9
|
-
function buildGraph(root) {
|
|
10
|
-
const files = listSourceFiles(root, { includeTests: true });
|
|
11
|
-
const set = new Set(files);
|
|
12
|
-
const imports = new Map();
|
|
13
|
-
const importers = new Map();
|
|
14
|
-
const exportsOf = new Map();
|
|
15
|
-
for (const f of files) {
|
|
16
|
-
const t = readSafe(root, f);
|
|
17
|
-
exportsOf.set(f, parseExportsFromText(t));
|
|
18
|
-
const im = parseImports(t, f, set);
|
|
19
|
-
imports.set(f, im);
|
|
20
|
-
for (const g of im) {
|
|
21
|
-
if (!importers.has(g)) importers.set(g, []);
|
|
22
|
-
importers.get(g).push(f);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return { files, set, imports, importers, exportsOf };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function lineOf(text, idx) {
|
|
29
|
-
return text.slice(0, idx).split('\n').length;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Where a symbol is defined and where it is called (file:line + trimmed code). */
|
|
33
|
-
function candidateFiles(root, graph, name) {
|
|
34
|
-
try {
|
|
35
|
-
const out = require('child_process').execSync(`git grep -l -w -- ${JSON.stringify(name)}`, { cwd: root, maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
|
|
36
|
-
return out.split('\n').filter(f => graph.set.has(f));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
return e.status === 1 ? [] : graph.files; // 1 = no match; otherwise not git -> scan all
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function symbolLinks(graph, name, { maxUses = 12, root = process.cwd() } = {}) {
|
|
43
|
-
const defs = [];
|
|
44
|
-
const uses = [];
|
|
45
|
-
const defRe = new RegExp(`(?:function\\*?|class|const|let|var|type|interface|enum)\\s+${name}\\b`);
|
|
46
|
-
const useRe = new RegExp(`\\b${name}\\s*[(<.]`, 'g');
|
|
47
|
-
for (const f of candidateFiles(root, graph, name)) {
|
|
48
|
-
const t = readSafe(root, f);
|
|
49
|
-
if (!t.includes(name)) continue;
|
|
50
|
-
const d = defRe.exec(t);
|
|
51
|
-
if (d) defs.push({ file: f, line: lineOf(t, d.index), exported: graph.exportsOf.get(f).includes(name) });
|
|
52
|
-
let m;
|
|
53
|
-
while ((m = useRe.exec(t)) && uses.length < maxUses * 4) {
|
|
54
|
-
if (d && m.index >= d.index && m.index <= d.index + d[0].length + 2) continue;
|
|
55
|
-
const ln = lineOf(t, m.index);
|
|
56
|
-
const code = t.split('\n')[ln - 1].trim().slice(0, 90);
|
|
57
|
-
uses.push({ file: f, line: ln, code });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const byFile = new Map();
|
|
61
|
-
for (const u of uses) {
|
|
62
|
-
if (!byFile.has(u.file)) byFile.set(u.file, []);
|
|
63
|
-
byFile.get(u.file).push(u);
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
symbol: name,
|
|
67
|
-
definedIn: defs,
|
|
68
|
-
usedIn: [...byFile.entries()].slice(0, maxUses).map(([file, us]) => ({ file, count: us.length, first: `${us[0].line}: ${us[0].code}` })),
|
|
69
|
-
moreFiles: Math.max(0, byFile.size - maxUses),
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** What a file pulls in, who depends on it, and how it tends to change. */
|
|
74
|
-
function fileLinks(graph, root, file, { history = null } = {}) {
|
|
75
|
-
const hist = history || readHistory(root);
|
|
76
|
-
return {
|
|
77
|
-
file,
|
|
78
|
-
exports: graph.exportsOf.get(file) || [],
|
|
79
|
-
imports: graph.imports.get(file) || [],
|
|
80
|
-
importedBy: (graph.importers.get(file) || []).slice(0, 15),
|
|
81
|
-
importedByCount: (graph.importers.get(file) || []).length,
|
|
82
|
-
changedWith: coChanges(hist, file),
|
|
83
|
-
recent: recentChanges(hist, file),
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
module.exports = { buildGraph, symbolLinks, fileLinks };
|
|
1
|
+
/**
|
|
2
|
+
* atlas links — a compact "connection map" for a file or symbol, so an agent
|
|
3
|
+
* can follow a call chain without reading whole files.
|
|
4
|
+
*/
|
|
5
|
+
const { listSourceFiles, readSafe } = require('./files');
|
|
6
|
+
const { parseExportsFromText, parseImports } = require('./symbols');
|
|
7
|
+
const { readHistory, coChanges, recentChanges } = require('./git');
|
|
8
|
+
|
|
9
|
+
function buildGraph(root) {
|
|
10
|
+
const files = listSourceFiles(root, { includeTests: true });
|
|
11
|
+
const set = new Set(files);
|
|
12
|
+
const imports = new Map();
|
|
13
|
+
const importers = new Map();
|
|
14
|
+
const exportsOf = new Map();
|
|
15
|
+
for (const f of files) {
|
|
16
|
+
const t = readSafe(root, f);
|
|
17
|
+
exportsOf.set(f, parseExportsFromText(t));
|
|
18
|
+
const im = parseImports(t, f, set);
|
|
19
|
+
imports.set(f, im);
|
|
20
|
+
for (const g of im) {
|
|
21
|
+
if (!importers.has(g)) importers.set(g, []);
|
|
22
|
+
importers.get(g).push(f);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { files, set, imports, importers, exportsOf };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function lineOf(text, idx) {
|
|
29
|
+
return text.slice(0, idx).split('\n').length;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Where a symbol is defined and where it is called (file:line + trimmed code). */
|
|
33
|
+
function candidateFiles(root, graph, name) {
|
|
34
|
+
try {
|
|
35
|
+
const out = require('child_process').execSync(`git grep -l -w -- ${JSON.stringify(name)}`, { cwd: root, maxBuffer: 1 << 26, stdio: ['ignore', 'pipe', 'ignore'] }).toString();
|
|
36
|
+
return out.split('\n').filter(f => graph.set.has(f));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return e.status === 1 ? [] : graph.files; // 1 = no match; otherwise not git -> scan all
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function symbolLinks(graph, name, { maxUses = 12, root = process.cwd() } = {}) {
|
|
43
|
+
const defs = [];
|
|
44
|
+
const uses = [];
|
|
45
|
+
const defRe = new RegExp(`(?:function\\*?|class|const|let|var|type|interface|enum)\\s+${name}\\b`);
|
|
46
|
+
const useRe = new RegExp(`\\b${name}\\s*[(<.]`, 'g');
|
|
47
|
+
for (const f of candidateFiles(root, graph, name)) {
|
|
48
|
+
const t = readSafe(root, f);
|
|
49
|
+
if (!t.includes(name)) continue;
|
|
50
|
+
const d = defRe.exec(t);
|
|
51
|
+
if (d) defs.push({ file: f, line: lineOf(t, d.index), exported: graph.exportsOf.get(f).includes(name) });
|
|
52
|
+
let m;
|
|
53
|
+
while ((m = useRe.exec(t)) && uses.length < maxUses * 4) {
|
|
54
|
+
if (d && m.index >= d.index && m.index <= d.index + d[0].length + 2) continue;
|
|
55
|
+
const ln = lineOf(t, m.index);
|
|
56
|
+
const code = t.split('\n')[ln - 1].trim().slice(0, 90);
|
|
57
|
+
uses.push({ file: f, line: ln, code });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const byFile = new Map();
|
|
61
|
+
for (const u of uses) {
|
|
62
|
+
if (!byFile.has(u.file)) byFile.set(u.file, []);
|
|
63
|
+
byFile.get(u.file).push(u);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
symbol: name,
|
|
67
|
+
definedIn: defs,
|
|
68
|
+
usedIn: [...byFile.entries()].slice(0, maxUses).map(([file, us]) => ({ file, count: us.length, first: `${us[0].line}: ${us[0].code}` })),
|
|
69
|
+
moreFiles: Math.max(0, byFile.size - maxUses),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** What a file pulls in, who depends on it, and how it tends to change. */
|
|
74
|
+
function fileLinks(graph, root, file, { history = null } = {}) {
|
|
75
|
+
const hist = history || readHistory(root);
|
|
76
|
+
return {
|
|
77
|
+
file,
|
|
78
|
+
exports: graph.exportsOf.get(file) || [],
|
|
79
|
+
imports: graph.imports.get(file) || [],
|
|
80
|
+
importedBy: (graph.importers.get(file) || []).slice(0, 15),
|
|
81
|
+
importedByCount: (graph.importers.get(file) || []).length,
|
|
82
|
+
changedWith: coChanges(hist, file),
|
|
83
|
+
recent: recentChanges(hist, file),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = { buildGraph, symbolLinks, fileLinks };
|