Repository navigation
Expand file tree
/
Copy pathguide.html
More file actions
141 lines (140 loc) · 7.26 KB
/
Copy pathguide.html
File metadata and controls
141 lines (140 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Your first scan | code-inventory</title>
<meta
name="description"
content="Build the CLI from a checkout, then use the included TypeScript fixture to investigate a declaration and trace its callers."
/>
<link rel="icon" href="assets/mark.svg" type="image/svg+xml" />
<link rel="stylesheet" href="assets/site.css" />
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
<header>
<div class="wrap">
<a class="brand" href="index.html"><img src="assets/mark.svg" width="34" height="34" alt="" />code-inventory</a>
<nav aria-label="Primary">
<a href="guide.html" aria-current="page">Guide</a>
<a href="reference.html">Reference</a>
<a href="https://github.com/Huldoser/code-inventory">GitHub</a>
</nav>
</div>
</header>
<main id="main" class="wrap layout">
<aside>
<strong>On this page</strong>
<nav aria-label="On this page">
<a href="#build">Build from source</a>
<a href="#scan">Scan the fixture</a>
<a href="#references">Inspect a symbol</a>
<a href="#paths">Trace an entry point</a>
<a href="#self-scan">Read a partial scan</a>
<a href="#library">Use the library</a>
</nav>
</aside>
<article>
<h1>Your first scan</h1>
<p class="intro">
Build the CLI from a checkout, then use the included TypeScript fixture to investigate a declaration and trace
its callers.
</p>
<h2 id="build">Build from source</h2>
<p>
Clone the <a href="https://github.com/Huldoser/code-inventory">code-inventory repository</a> and open its root
directory. The examples use the compiled files in your checkout. Use Node.js 26 or newer. CI pins 26.13.1.
</p>
<pre><code>npm ci --ignore-scripts --no-audit
npm run build</code></pre>
<h2 id="scan">Scan the fixture</h2>
<p>
The basic fixture has a function named <code>normalize</code>, a module that re-exports it as
<code>clean</code>, and two files that use it. Scan the directory to see the totals across all declarations.
</p>
<pre><code>node dist/cli.js test/fixtures/basic</code></pre>
<pre><code>Code inventory: 4 analyzed files, 10 symbols
16 references, 7 direct call sites
2 symbols with no references found
2 exports without local usage
Analysis: complete; 0 diagnostics
Static evidence only; no-reference findings are not proof of dead code.</code></pre>
<p>
To review individual records or share a report, select an output format. Each output path must be new. The CLI
writes to standard output when you omit <code>--output</code>.
</p>
<pre><code>node dist/cli.js test/fixtures/basic --format json --output inventory.json
node dist/cli.js test/fixtures/basic --format markdown --output inventory.md</code></pre>
<h2 id="references">Inspect a symbol</h2>
<pre><code>node dist/cli.js test/fixtures/basic --symbol normalize</code></pre>
<p>
The report starts with the declaration ID and counts. Each subsequent reference names its file, line, column,
kind, and scope.
</p>
<pre><code>normalize (definitions.ts:0:function)
9 references; 4 direct call sites; 3 distinct callers</code></pre>
<p>
In <code>app.ts</code>, <code>clean(' first ')</code> on line 6 and <code>alias(' second ')</code> on line 8
both resolve to <code>normalize</code>. Passing <code>clean</code> to <code>.map()</code> on line 9
contributes a read. The scanner cannot infer how often the callback runs. When several declarations share a
name, use an exact ID from the snapshot or ambiguity error.
</p>
<h2 id="paths">Trace an entry point</h2>
<pre><code>node dist/cli.js test/fixtures/basic --entry app.ts --format markdown</code></pre>
<p>
The scan finds four reachable declarations and five with no known path from <code>app.ts</code>. The
production entry calls <code>main()</code>, which calls <code>normalize</code> through its alias. The separate
test function also references <code>normalize</code>, but has no incoming path from the selected entry. Repeat
<code>--entry</code> to combine roots.
</p>
<p>
In JSON, start at a reached node and follow <code>via.from</code> until you reach an entry. Each step gives
the edge kind and its location. Consider other entry points, callbacks, framework dispatch, and external
consumers before removing a declaration.
</p>
<h2 id="self-scan">Read a partial scan</h2>
<p>After building from source, scan the CLI itself from the repository root.</p>
<pre><code>node dist/cli.js . --project tsconfig.build.json --entry src/cli.ts --format markdown</code></pre>
<pre><code>42 reachable declarations, 63 with no known path
Analysis: partial; 3 diagnostics</code></pre>
<p>
In the paths section, follow the call from the entry module to <code>main()</code> at
<code>src/cli.ts:71</code>, then from <code>main()</code> to <code>scan()</code> at
<code>src/cli.ts:36</code>. The line numbers point to the calls that establish each step.
</p>
<p>
Run the same query with <code>--format json</code> to inspect <code>diagnostics</code>. The three
<code>unresolved-call</code> entries point to two calls through <code>rules.excluded</code> and one through
<code>addCompilerDiagnostic</code>. The scanner could not tie those calls to concrete project declarations.
Adding <code>--strict</code> still emits the report and sets exit code 2.
</p>
<p>
The callback passed to <code>.map()</code> at <code>src/report.ts:49</code> appears under declarations with no
known path. That status describes the path the scanner could establish from this entry. The scanner does not
model the runtime call that <code>.map()</code> makes to the callback.
</p>
<h2 id="library">Use the library</h2>
<p>From the repository root, run the same queries against one in-memory snapshot. All calls are synchronous.</p>
<p>
Save this example as <code>inspect.mjs</code> in the repository root and run <code>node inspect.mjs</code>.
</p>
<pre><code>import { scan, usages, reachability, findings, markdown } from './dist/index.js';
const inventory = scan('test/fixtures/basic');
console.log(usages(inventory, 'normalize').counts);
console.log(reachability(inventory, ['app.ts']).declarations);
console.log(findings(inventory));
console.log(markdown(inventory));</code></pre>
<p>
See the <a href="reference.html#projects">project selection rules</a> before scanning a workspace with several
TypeScript configs.
</p>
</article>
</main>
<footer>
<div class="wrap">
code-inventory · <a href="https://github.com/Huldoser/code-inventory/blob/main/LICENSE">MIT license</a>
</div>
</footer>
</body>
</html>