Repository navigation
Expand file tree
/
Copy pathreference.html
More file actions
316 lines (316 loc) · 20.2 KB
/
Copy pathreference.html
File metadata and controls
316 lines (316 loc) · 20.2 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!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="#exit-codes">Exit codes</a>
<a href="#projects">Project selection</a>
<a href="#counts">Counts and findings</a>
<a href="#snapshot">JSON snapshot</a>
<a href="#compatibility">Saved reports and upgrades</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. Globs match slash-separated paths relative to the scan root, case-sensitively on every platform.
<code>*</code> and <code>**</code> skip dot files and folders unless the pattern names them, as in
<code>.config/**</code>. Braces such as <code>{a,b}</code>, extglobs such as <code>@(a|b)</code> and character
classes work; other parentheses are literal, so <code>'app/(marketing)/**'</code> selects a Next.js route
group.
</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.
Each candidate test has one shortest chain of resolved calls or constructions to the changed declaration.
Paths start at a site in a test file. An unexecuted helper in a test file may supply such a site. Use
summary or JSON output. The JSON report has kind <code>change-impact</code>, schemaVersion 1, baseTree,
snapshotId, diagnostics, changes and diff notes. Within each change, tests[].path lists located references
from the test toward the declaration.
</dd>
<dt><code>--workspace-entries</code></dt>
<dd>
Read the root and member manifests matched by the root npm workspaces array, selecting member folders as npm
does: <code>*</code> and <code>**</code> skip dot folders unless a pattern names them, and a pattern
starting with <code>!</code> excludes the folders it matches. Each entry origin lists the manifest, field
and analyzed file. Use --project for any required compiler output mapping.
</dd>
<dt><code>--next-routes</code></dt>
<dd>
Select route.js and route.ts files under app or src/app in the scan root, excluding private folders. Model
both module initialization and invocation of exported HTTP methods identified in each route file.
</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>Signal a partial scan after writing its report. See <a href="#exit-codes">exit codes</a>.</dd>
<dt><code>-h</code>, <code>--help</code></dt>
<dd>Print usage and exit.</dd>
</dl>
<h2 id="exit-codes">Exit codes</h2>
<dl>
<dt><code>0</code> · Success</dt>
<dd>
The CLI printed help or produced the requested report. Without <code>--strict</code>, both complete and
partial scans succeed. Check the JSON <code>completeness</code> field when the distinction matters.
</dd>
<dt><code>1</code> · Command failed</dt>
<dd>
An invalid option, failed query, or read or write error sends an explanation to stderr. Stop before
consuming output. In particular, an existing <code>--output</code> file may be from an earlier run.
</dd>
<dt><code>2</code> · Strict scan produced a partial report</dt>
<dd>
Read the report from stdout or the new file named by <code>--output</code>. Inspect its diagnostics before
using the results. A complete scan with <code>--strict</code> exits with 0.
</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.
workspaceEntries(directory, inventory) returns manifest origins. nextRouteEntries(inventory) returns route
files and handler IDs. changeImpact(directory, base, inventory) queries Git against the current matching scan
and returns the structured change report. Pass the packageEntries 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>
<h2 id="compatibility">Saved reports and 0.x upgrades</h2>
<p>
Use <code>--format json</code> for scripts. The packaged <a href="report-schema.json">JSON Schema</a> lists
the required properties, types, allowed values and nullable fields for each report. Summary, Markdown,
diagnostic messages and limitation text are for display.
</p>
<dl>
<dt>Full inventory</dt>
<dd>
Require <code>schemaVersion === 1</code> for the layout above. Save the full inventory to run new
<code>usages</code> or <code>reachability</code> queries later. Use <code>analyzer.version</code> and
<code>analyzer.compilerVersion</code> to identify the producer.
</dd>
<dt>Symbol query</dt>
<dd>
Require <code>schemaVersion === 1</code> and read <code>usage.symbol</code>,
<code>usage.references</code> and <code>usage.counts</code>. The CLI puts snapshot-wide diagnostics
alongside <code>usage</code>.
</dd>
<dt>Entry query</dt>
<dd>
In 0.3.0 this report has no <code>schemaVersion</code>. Validate it against the schema’s
<code>entryReport</code> definition. File roots appear in <code>entries</code>. The optional
<code>entrySymbols</code> lists explicitly invoked declarations. Use <code>reached</code> to reconstruct
paths and <code>declarations</code> to look up reachability status.
</dd>
</dl>
<p>
All three shapes carry <code>snapshotId</code>, <code>completeness</code> and <code>diagnostics</code>. Keep
the matching inventory or its producer metadata with a saved query. Treat IDs as opaque and join records only
within the same snapshot. A fresh scan with an improved resolver can produce different IDs, counts, paths or
diagnostics for the same source.
</p>
<p>
Within schema version 1, readers can rely on required fields and their documented meanings. Producers may add
optional fields and diagnostic codes. Ignore unfamiliar properties, handle unfamiliar codes, and allow
optional fields such as <code>files[].project</code> to be absent. A required field with a nullable type, such
as <code>references[].callerId</code>, is present even when its value is <code>null</code>.
</p>
<p>
During 0.x, a change that invalidates existing reports or breaks a reader following these rules belongs in a
new minor release with migration instructions. An incompatible JSON shape also needs a new schema version,
including an explicit version on a replacement for the unversioned entry report. A change to the documented
exit codes is likewise a breaking CLI change. Before moving to another minor release, validate a saved report
with the target schema and replay a representative query. For an unsupported version, retain the original
report and use its generating release until you migrate.
</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>