who-imports
v0.2.1
Published
Export-level dependency graph tool for TypeScript codebases
Maintainers
Readme
who-imports
Export-level dependency graph tool for TypeScript codebases. Unlike module-level tools (Madge, Skott), this traces dependencies at individual export granularity.
Installation
npm install -g who-importsOr run directly with npx:
npx who-imports -f ./src -o deps.jsonUsage
who-imports -f <folder> [-f <folder>...] [-c <folder>...] -o <output>Options
| Flag | Description |
| ------------------------------ | ------------------------------------------------------------------------------------ |
| -f, --folder <path> | Target folder(s) to analyze exports from. Repeatable. |
| -c, --consumer <path> | Folder(s) to search for consumers. Defaults to -f. Repeatable. |
| -i, --ignore-extension <ext> | File patterns to ignore (e.g., '.test.*'). Quote globs to prevent shell expansion. |
| -d, --declarations | Include .d.ts files (excluded by default). |
| -o, --output <path> | Output file. Extension determines format (.json or .dot). |
Examples
Analyze exports and consumers within the same folder:
who-imports -f ./src/features/auth -o auth-deps.jsonFind consumers of shared types across multiple feature folders:
who-imports \
-f ./src/shared/types \
-c ./src/features/payments \
-c ./src/features/onboarding \
-o types-consumers.jsonOutput Formats
JSON
{
"exports": [
{
"module": "primitiveTypes.ts",
"name": "GroupId",
"consumerCount": 7,
"consumers": [
{ "module": "helpers/csv/operations.ts", "via": ["types.ts"] },
{ "module": "spreadsheet/types.ts" }
]
}
]
}module: Relative path to file where export is originally definedname: Export name (defaultfor default exports)consumerCount: Number of files importing this exportconsumers[].module: Consuming file pathconsumers[].via: Re-export chain if consumer imported through barrel files
DOT (GraphViz)
who-imports -f ./src -o deps.dot
dot -Tsvg deps.dot -o deps.svg # Render with GraphVizFeatures
- Re-export tracing: Follows re-exports to original source
export { X } from './other'export * from './other'import { X } from './other'; export { X };(import-then-export)
- Type exports: Includes
export typeandimport type - Path resolution: Paths relative to folder (single) or common ancestor (multiple folders)
Programmatic API
Use as a library for custom tooling:
import {
parseFiles,
buildExportRegistry,
findConsumers,
buildDependencyOutput,
formatAsJson,
} from 'who-imports';
const { files, basePath } = parseFiles(['./src']);
const registry = buildExportRegistry(files, basePath);
const consumers = findConsumers(files, registry, basePath);
const output = buildDependencyOutput(registry, consumers, files, basePath);
console.log(formatAsJson(output));Exported Functions
| Function | Description |
| ------------------------- | ------------------------------------------------------ |
| parseFiles | Load TypeScript files into a ts-morph Project |
| addFilesToProject | Add additional files to existing project |
| buildExportRegistry | Extract all exports and build re-export map |
| resolveExport | Trace an export to its original source |
| getAllExportsFromModule | Get all exports from a module (including star exports) |
| findConsumers | Find all consumers of exports |
| buildDependencyOutput | Build final dependency output structure |
| formatAsJson | Format output as JSON |
| formatAsDot | Format output as GraphViz DOT |
Exported Types
ExportEntry, ResolvedExport, Consumer, ExportDependencyInfo, DependencyGraphOutput, ExportRegistry, ConsumerMap
How It Works
CLI args
→ parseFiles() # Load .ts/.tsx files into ts-morph Project
→ buildExportRegistry() # Extract exports, build re-export map
→ findConsumers() # Scan imports, trace through re-exports
→ buildDependencyOutput()# Aggregate into final structure
→ formatAsJson/Dot() # SerializeDevelopment
git clone https://github.com/yoavsion/who-imports.git
cd who-imports
yarn install
yarn buildScripts
| Script | Description |
| ------------- | ------------------------------- |
| yarn build | Compile TypeScript to dist/ |
| yarn dev | Run directly via tsx (no build) |
| yarn test | Run tests |
| yarn lint | Run ESLint |
| yarn format | Format with Prettier |
Architecture
src/
├── index.ts # CLI entry point (commander)
├── api.ts # Programmatic API exports
├── types.ts # Shared TypeScript types
├── parser.ts # ts-morph project initialization, file collection
├── exports.ts # Export extraction, re-export chain resolution
├── consumers.ts # Import scanning, consumer mapping
└── output/
├── json.ts # JSON formatter
└── dot.ts # GraphViz DOT formatterContributing
Issues and PRs welcome on GitHub.
Related Tools
- ts-morph - TypeScript compiler API wrapper (powers this tool)
- Madge - Module-level dependency graphs
- Skott - Module-level dependency analysis
License
MIT
