Skip to content

andriyor/ts-tree

Repository files navigation

ts-tree

Creates a module tree based on a given entrypoint.

Builds on top of ts-morph

Install

npm i @andriyorehov/ts-graph

Usage

import { getTreeByFile } from '@andriyorehov/ts-graph';

const tree = getTreeByFile('filePath.ts');
console.dir(tree, { depth: null });

Comparison table

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

TODO

  • 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,

Tech Debt

  • 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)

About

Creates a module tree based on a given entrypoint.

Resources

Stars

Watchers

Forks