Repository navigation
Expand file tree
/
Copy pathreference.html
More file actions
238 lines (238 loc) · 14.9 KB
/
Copy pathreference.html
File metadata and controls
238 lines (238 loc) · 14.9 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Reference | code-inventory</title>
<meta
name="description"
content="Look up command options, file selection rules, and the evidence behind each result."
/>
<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">Guide</a>
<a href="reference.html" aria-current="page">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="#cli">CLI options</a>
<a href="#projects">Project selection</a>
<a href="#counts">Counts and findings</a>
<a href="#snapshot">JSON snapshot</a>
<a href="#boundaries">Analysis limits</a>
</nav>
</aside>
<article>
<h1>Reference</h1>
<p class="intro">Look up command options, file selection rules, and the evidence behind each result.</p>
<h2 id="cli">CLI options</h2>
<pre><code>node dist/cli.js [directory] [options]</code></pre>
<p>
The directory defaults to the current working directory. Quote globs so the scanner receives the pattern
directly.
</p>
<dl>
<dt><code>--project config</code></dt>
<dd>
Select a config relative to the scan root and follow its transitive project references. Repeat to select
multiple configs.
</dd>
<dt><code>--exclude glob</code></dt>
<dd>Omit matching files from the inventory, including imported files. Repeat to combine patterns.</dd>
<dt><code>--test glob</code>, <code>--tooling glob</code>, <code>--production glob</code></dt>
<dd>
Override scope by slash-separated path relative to the root. Each is repeatable. Test takes precedence over
tooling, then production, then the default path conventions.
</dd>
<dt><code>--symbol name-or-id</code></dt>
<dd>Query one declaration by exact unique name or snapshot ID. Supports summary and JSON.</dd>
<dt><code>--changed-since revision</code></dt>
<dd>
Compare a local Git revision directly with the tracked working tree under the scan root, including staged
and unstaged changes. Untracked files enter the diff once staged. The summary groups current references by
caller or test file and shows module exports, including re-exports. Changed lines select overlapping
declarations, including an enclosing declaration when the line also contains its own code. Reads include
callback arguments. Test references identify source sites and do not establish runtime coverage. Removed
lines use base coordinates. Deleted files and the old side of renames have no current declaration to query.
Use this option on its own with summary output.
</dd>
<dt><code>--package-entries</code></dt>
<dd>
Trace module initialization from the root package's exports (or main) and bin targets. All runtime
conditions and array alternatives contribute roots. Type-only branches, declaration files and JSON targets
are skipped. Combine with --entry for framework or implicit roots. For compiled packages select the emitting
--project so the compiler can map outputs to analyzed inputs. Subpath patterns such as
<code>"./features/*": "./dist/*.js"</code> expand against analyzed files and their predicted JavaScript
outputs. An exact subpath or a more specific pattern takes precedence, including private paths blocked with
<code>null</code>. If a target pattern has no matching source or predicted output, select its source
explicitly with <code>--entry</code>. External invocations of exported functions are outside this trace.
</dd>
<dt><code>--entry-symbol name-or-id</code></dt>
<dd>
Assume a function, method or constructor is invoked and trace calls from its body. For example, select
<code>GET</code> when reviewing a route handler. A repeated name requires the snapshot ID shown in the
ambiguity message. Repeat the option for multiple invocations. Add file entries to include module
initialization. The library accepts <code>reachability(inventory, [], { entrySymbols: ['GET'] })</code>. The
report records these assumptions as snapshot IDs in the optional <code>entrySymbols</code> array.
</dd>
<dt><code>--entry-glob glob</code></dt>
<dd>
Trace analyzed files matching a quoted, root-relative pattern such as <code>'src/routes/**/+page.ts'</code>.
Repeat the option or combine it with --entry and --package-entries. Each pattern must match an analyzed
file. Library callers can pass
<code>reachability(inventory, [], { entryGlobs: ['src/routes/**/+page.ts'] })</code>.
</dd>
<dt><code>--entry source-file</code></dt>
<dd>
Trace paths from an analyzed file relative to the scan root. Repeat for multiple entries. Use a separate
query for <code>--symbol</code>.
</dd>
<dt><code>--format summary|json|markdown</code></dt>
<dd>Choose terminal text (default), machine-readable JSON, or a Markdown report.</dd>
<dt><code>--output new-file</code></dt>
<dd>Write the result to a new file. An existing path produces an error.</dd>
<dt><code>--strict</code></dt>
<dd>
Write the report and exit with code 2 for a partial scan. A successful scan otherwise exits with 0. Invalid
arguments and filesystem errors exit with 1.
</dd>
<dt><code>-h</code>, <code>--help</code></dt>
<dd>Print usage and exit.</dd>
</dl>
<h2 id="projects">Project selection</h2>
<pre><code>node dist/cli.js . --project tsconfig.build.json --exclude '**/generated/**' --test 'qa/**'</code></pre>
<p>
The scanner discovers TS, TSX, JS, JSX, MTS, CTS, MJS, and CJS files. By default it reads the root
<code>tsconfig.json</code>, falling back to <code>jsconfig.json</code>, then to discovered source. Configs
supply compiler options, root file selection, and path aliases. A solution config with an empty
<code>files</code> list can select a reference graph. Imported source may enter a program even when excluded
from the config’s root list.
</p>
<p>
Each file is counted once. If multiple configs explicitly include a file, the one with the shortest relative
path to it owns the file. Config path order breaks ties. An imported file outside every root list belongs to
the first importing project in config path order. The file record identifies its owner. Scan projects
separately when a shared file has different alias resolutions.
</p>
<p>
Discovery skips symlinks, declaration files as inventory inputs, and the contents of
<code>node_modules</code>, <code>.git</code>, <code>dist</code>, <code>build</code>, <code>coverage</code>,
<code>.next</code>, <code>.nuxt</code>, and <code>.output</code>. The compiler can still read declarations for
resolution. Discovered files excluded from the inventory carry a reason.
</p>
<p>
When a JavaScript file imports an explicit relative path such as <code>./codec.js</code>, the scanner traces
references into that implementation if it is in scope, even when it has an adjacent declaration file.
TypeScript diagnostics still use the project's declared types.
</p>
<p>
Paths containing <code>test</code>, <code>tests</code>, <code>__tests__</code>, <code>__mocks__</code>, or
<code>fixtures</code> as directory names, and <code>.test</code> or <code>.spec</code> files, receive test
scope. The scanner labels <code>scripts</code>, <code>tools</code>, and <code>*.config.*</code> as tooling.
Other files default to production. The equivalent library options are
<code>scan(root, { projects, exclude, scopes })</code>, where each scope maps to an array of globs.
</p>
<h2 id="counts">Counts and findings</h2>
<p>
<code>usages()</code> groups resolved occurrences into calls, construction, reads, type references, imports,
re-exports, and JSX. An import or re-export alias contributes one reference even if no code uses the binding.
A call inside a loop contributes one direct call site. An explicit constructor and its class each receive a
relationship for the same construction site. Distinct callers count the containing declarations of call and
construction sites, grouping top-level sites by module.
</p>
<p>
<code>findings()</code> separates local declarations without meaningful usage from exports without local
usage. Imports and re-exports alone do not count as meaningful usage. Export visibility includes exports
anywhere in the analyzed source. Review the package’s entry points to determine which exports it exposes.
</p>
<h2 id="snapshot">JSON snapshot</h2>
<dl>
<dt><code>schemaVersion</code>, <code>analyzer</code>, <code>snapshotId</code></dt>
<dd>
Record the format version, analyzer and compiler versions, and report identity. A symbol ID is tied to its
declaration location within the snapshot.
</dd>
<dt><code>config</code>, <code>files</code></dt>
<dd>
Record selected configs, project paths and config input hashes, plus file hashes, status, exclusion reasons
and project ownership. Resolution-only inputs such as installed declarations and package metadata fall
outside the fingerprint.
</dd>
<dt><code>symbols</code>, <code>references</code>, <code>modules</code>, <code>exports</code></dt>
<dd>
Describe declarations and their locations, resolved occurrences, module edges, and exported names. Source
bodies and the absolute root path are omitted. Locations use one-based lines and columns and zero-based
UTF-16 offsets with an exclusive end.
</dd>
<dt><code>completeness</code>, <code>diagnostics</code>, <code>limitations</code></dt>
<dd>
A partial result includes diagnostics. A complete result means the supported analysis emitted none. Read the
limits when interpreting either result.
</dd>
</dl>
<p>
A symbol query returns a <code>usage</code> object with its symbol, counts, and references alongside schema
version, snapshot ID, diagnostics, and completeness. An entry query returns the selected <code>entries</code>,
<code>reached</code> nodes with shortest-path predecessors, and <code>declarations</code> labeled
<code>reachable</code> or <code>no-known-path</code>, along with snapshot ID, completeness, diagnostics, and
limitations.
</p>
<h2>Consuming the 0.x API</h2>
<p>
The package root exports scan, usages, findings, reachability, packageEntries and entryPath. scan reads a
directory synchronously. The other queries operate on its inventory or reachability report, except
packageEntries(directory, inventory), which also reads the matching manifest and build configuration. Pass its
result to reachability. entryPath(report, symbolId) returns the ordered nodes of one shortest path, including
the selected file or invocation root and target, or null for an unreached ID. Select the ID with usages. Each
non-root node carries the edge kind and source location. summary, usageText and markdown render display text.
</p>
<p>
The <a href="report-schema.json">JSON Schema</a> describes all three CLI report shapes. For persisted data
check schemaVersion before reading a full inventory or symbol response. The entry response has the
Reachability shape in the shipped TypeScript declarations. In 0.1.0 it has no schemaVersion. Keep analyzer and
compiler versions from the full snapshot alongside query results. Use snapshot-local IDs for joins. Accept
additional fields and unknown diagnostic codes. Compare counts across upgrades against source examples;
changes in resolution can change a result even when its shape stays compatible. Keep the generating version
for older snapshots. During 0.x the format and API can change.
</p>
<p>
TS-prefixed codes are compiler diagnostics. unresolved-module and dynamic-module identify missing module
edges. unresolved-call, mutable-binding and accessor-dispatch identify uncertainty about invocation targets.
Inspect the diagnostic location alongside the usage or path. Scope is snapshot-wide, so a partial scan can
still contain individually verifiable calls. The inventory summary groups diagnostics by code.
</p>
<h2 id="boundaries">Analysis limits</h2>
<p>
Scanning reads source and configuration without executing modules, tests, or configuration scripts. Parse
errors, unresolved imports or calls, computed module paths, accessors, and mutable function bindings can
produce diagnostics. Implicit getter and setter dispatch, reflection, and framework conventions can hide
usages. The adapter uses Microsoft’s TypeScript 6 compatibility package with compiler engine 6.0.3.
</p>
<p>
Reachability follows direct calls, construction, static imports and re-exports, and literal dynamic imports or
requires in their containing scope. It skips explicit type-only module edges. Emitted JavaScript may omit
other imports too. Conditional branches can contribute paths. Recursion within an isolated group creates
references without making it reachable from an entry. Runtime behavior, test coverage, and safe removal
require additional evidence.
</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>