HN 표시: Importree – TypeScript 파일에 대한 종속성 트리 가져오기
hackernews
|
|
🔬 연구
#importree
#review
#typescript
#개발 도구
#의존성 트리
원문 출처: hackernews · Genesis Park에서 요약 및 분석
요약
TypeScript 및 JavaScript 파일의 전체 의존성 트리를 고속으로 구축하는 오픈 소스 라이브러리 ‘Importree’가 공개되었습니다. 이 도구는 무거운 AST 파싱 대신 튜닝된 정규 표현식을 사용하여 대규모 프로젝트에서도 매우 빠르게 동작하며, 특정 파일의 변경 영향을 즉시 파악할 수 있습니다. 이를 통해 테스트 자동화, 캐시 무효화, 리팩토링 시 영향도 분석 등 개발 효율성을 크게 높일 수 있습니다.
본문
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. 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.
Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.
공유