Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Find where JavaScript and TypeScript declarations are used. The CLI and library

## Run your first scan

Build from a checkout with Node.js 26 or newer. CI uses the version in [.node-version](.node-version).
In a JavaScript or TypeScript project with Node.js 26 or newer:

```sh
npm install --save-dev code-inventory
npx code-inventory .
```

For a checkout of this repository, use the fixture to check how calls are counted. CI uses the version in [.node-version](.node-version).

```sh
npm ci --ignore-scripts --no-audit
Expand Down Expand Up @@ -36,12 +43,13 @@ Check diagnostics before interpreting counts. Call sites measure source occurren

## Use the library

From an ES module in the repository root:
From an ES module in a project with the package installed:

```js
import { scan, usages, reachability } from './dist/index.js';
import { scan, usages, reachability } from 'code-inventory';

const inventory = scan('test/fixtures/basic');
// For a project with an app.ts entry and a normalize declaration:
const inventory = scan('.');
const usage = usages(inventory, 'normalize');
const paths = reachability(inventory, ['app.ts']);
```
Expand Down
32 changes: 32 additions & 0 deletions docs/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ <h2 id="cli">CLI options</h2>
</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>--package-entries</code></dt>
<dd>
Trace module initialization from the root package's explicit 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. Wildcards and unmapped outputs require
explicit source entries instead. External invocations of exported functions are outside this trace.
</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
Expand Down Expand Up @@ -148,6 +156,30 @@ <h2 id="snapshot">JSON snapshot</h2>
<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 module 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
Expand Down
Loading