tsref is a Bun CLI for finding references to exported TypeScript APIs.
tsref-cli AGENTS.md
2.3 kB · 66 lines
Markdown
at main

AGENTS.md #

Project #

tsref is a Bun + TypeScript CLI that analyzes one module file and reports references to its public exports.

Do not commit or push unless explicitly asked.

Commands #

bun install
bun test
bun run typecheck
bun src/index.ts test/fixtures/basic/api.ts --project test/fixtures/basic/tsconfig.json

Linked CLI usage:

tsref src/file.ts --project tsconfig.json

Stack #

  • Bun runtime and test runner
  • TypeScript ESM
  • Official typescript compiler and language service APIs
  • No CLI parser dependency; args are parsed in src/cli.ts

CLI Flags #

  • --project <path>: explicit tsconfig.json
  • --summary-only: table only, count-oriented path
  • --unused: show exports with zero external references
  • --no-imports: exclude import declarations from counts/details
  • --imports-only: fast syntax-level import/re-export count
  • --diagnostics: include TypeScript diagnostic count

Architecture #

  • src/index.ts: executable entrypoint
  • src/cli.ts: argument parsing and command flow
  • src/project.ts: target/tsconfig resolution, TypeScript Program, lazy diagnostics
  • src/exportCollector.ts: exported symbols and public members
  • src/referenceCollector.ts: full reference analysis via language service findReferences
  • src/importReferenceCollector.ts: fast --imports-only path
  • src/referenceClassifier.ts: reference kind labels
  • src/reportRenderer.ts: terminal output
  • src/types.ts: shared report types

Behavior Notes #

  • The target file is treated as the public API surface.
  • External refs are outside the target file; internal refs are inside it.
  • Declarations are shown as declared ... and are not counted as references.
  • Editor "find all references" often includes declarations, so editor counts can be one higher per symbol.
  • Default mode prioritizes TypeScript language-service accuracy.
  • --imports-only is intentionally less complete but much faster.
  • Avoid eager ts.getPreEmitDiagnostics(program) in default mode; diagnostics are lazy behind --diagnostics.

Testing #

Tests live in test/; fixtures live in test/fixtures/.

When changing reference behavior, add or update a small fixture test. Prefer real TypeScript fixtures over mocking compiler internals.