When a file changes, you need to know what else is affected. importree builds the full import dependency tree for any TypeScript or JavaScript entry point — with zero dependencies and zero AST overhead.
Built for CI pipelines, build tools, monorepo task runners, and test selectors.
npm install importree
Copied!
One job, done right. Resolve every import across your entire codebase with a single function call.
Built entirely on Node.js built-ins. No native binaries, no WASM, no transitive dependency tree of its own. Just pure TypeScript.
Regex-based import extraction with concurrent async file traversal. No AST parsing overhead — just the specifiers you need, as fast as reading the file.
Resolve @/components, ~/utils, or any custom alias.
Longest-prefix matching with automatic extension probing and index file resolution.
Someone edits utils.ts — which test suites, which pages, which
build targets need to re-run? The pre-computed reverse graph answers that instantly
with getAffectedFiles().
Compared with excellent tools like madge, dependency-tree, and the TypeScript compiler on a synthetic project with realistic import patterns.
Build the tree. Query it. Done.
import { importree } from 'importree'; const tree = await importree('./src/index.ts', { aliases: { '@': './src' }, }); console.log(tree.files); // ['/abs/src/index.ts', '/abs/src/app.ts', ...] console.log(tree.externals); // ['react', 'lodash', 'node:path'] console.log(tree.graph); // { '/abs/src/index.ts': ['/abs/src/app.ts', ...] }
import { importree, getAffectedFiles } from 'importree'; const tree = await importree('./src/index.ts'); // When utils.ts changes, what needs rebuilding? const affected = getAffectedFiles( tree, './src/utils.ts' ); console.log(affected); // ['/abs/src/app.ts', '/abs/src/index.ts'] // ^ every file that transitively depends on utils.ts
Two functions, five output fields — fully typed with JSDoc. Nothing hidden, nothing undocumented.
Recursively resolves all static imports, dynamic imports,
require() calls, and re-exports starting from the entry file. Returns
the full dependency graph.
BFS traversal of the reverse dependency graph. Returns all files that transitively depend on the changed file — sorted, deterministic, and without the changed file itself.
Absolute path of the entry file.
Sorted absolute paths of all local files in the dependency tree.
Sorted unique bare import specifiers — packages like react,
lodash, node:fs.
Forward adjacency list. Each file maps to its direct local imports.
Reverse adjacency list. Each file maps to files that import it. Pre-computed for fast cache invalidation.