Something went wrong. Try again.
tsref is a Bun CLI for finding references to exported TypeScript APIs.
Something went wrong. Try again.
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
typescriptcompiler and language service APIs - No CLI parser dependency; args are parsed in
src/cli.ts
CLI Flags #
--project <path>: explicittsconfig.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 entrypointsrc/cli.ts: argument parsing and command flowsrc/project.ts: target/tsconfig resolution, TypeScriptProgram, lazy diagnosticssrc/exportCollector.ts: exported symbols and public memberssrc/referenceCollector.ts: full reference analysis via language servicefindReferencessrc/importReferenceCollector.ts: fast--imports-onlypathsrc/referenceClassifier.ts: reference kind labelssrc/reportRenderer.ts: terminal outputsrc/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-onlyis 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.