Creates a module tree based on a given entrypoint.
Builds on top of ts-morph
npm i @andriyorehov/ts-graph
Per file
import { getTreeByFile } from '@andriyorehov/ts-graph';
const tree = getTreeByFile('filePath.ts');
console.dir(tree, { depth: null });
Per folder
import { getTreeByFolder } from '@andriyorehov/ts-graph';
const tree = getTreeByFolder('filePath.ts');
console.dir(tree, { depth: null });
Feature/Name | ts-tree | module-graph | node-dependency-tree |
---|---|---|---|
ts support | ✅ TypeScript (via typescript) | ✅ es-module-lexer | ✅ |
ts alias support | ✅ | ✅ | ❌ issue |
jsx support | ✅ | ❌ issue | ✅ |
not ts project support | ❌ | ✅ | ✅ |
circular dependencies handling | ❌ use dpdm | ✅ |
- tree by folder dependencies
- tree by file dependencies
- ignore third-party dependencies
- alias handling
- ignore types/interface/enum/
as const
dependencies from file tree - ignore types/interface/enum/
as const
dependencies from folder tree - ignore object which used only in types for folder tree
- handle
ExportDeclaration
with moduleSpecifier - exclude barrel files from file tree
- exclude barrel files from folder tree
- guarantee id uniqueness of file tree
- guarantee id uniqueness of folder tree
- pass meta info about files to file tree
- pass meta info about files to folder tree
- arg parser for file tree
- include used export by parent
- check named imports from same file on different lines for file tree
- check named imports from same file on different lines for folder tree
- handle default import for file tree
- handle default import for folder tree
- build package
- use tsconfig related to passed file path to allow running not from project root directory
- publish to npm
- handle files outside of folder tree
- return flat list to simplify processing
- create separate method with flat structure and use getReferencingSourceFiles, include types, barrel files, styles
- check barrel files handling for default import
- circular dependencies handling?
- how to get file deps with skipAddingFilesFromTsConfig: false, skipFileDependencyResolution: false,
- depth number
- flat tree for folder
- parent in flat tree
- try https://github.com/thepassle/module-graph
- reuse code between file and folder tree builder
- cache file tree builder? (don't need since id need to be unique for each node)
- improve performance
- use getReferencingSourceFiles instead own resolution implementation? in such case I will not able to ignore types/interface/enum/
as const
and barrel files - fix eslint
- add test for folder tree id uniqueness
- upgrade
find-up
to latest version with ESM - try find-up-simple (ESM)
npm run test
tsx test/prepare-mocks.ts
npmr run bench