有什么方法可以获取项目的依赖图?

laz*_*dmx 6 typescript

实际上,我正在寻找诸如-M键入的内容,gcc但对于tsc

Pas*_*ius 8

我创建了ts-dependency-graph,因为我的相当大的项目的依赖巡洋舰从未完成。它包含一些处理大型依赖图的选项。

npm i ts_dependency_graph -g

ts_dependency_graph --start src/index.ts
Run Code Online (Sandbox Code Playgroud)

将输出复制到例如https://dreampuf.github.io/GraphvizOnline/

 ts_dependency_graph --help
Options:
  --help                        Show help                              [boolean]
  --version                     Show version number                    [boolean]
  --start                       the starting file, for the analysis     [string]
  --aggregate_by_folder, --agg  create graph on folder level
                                                      [boolean] [default: false]
  --max_depth                                           [number] [default: 1000]
  --filter                      filters files containing the provided strings
                                                           [array] [default: []]
  --verbose, -v                 prints information about ignored files
                                                      [boolean] [default: false]
  --hotspots, -h                identify hotspots, by analyzing number of
                                incoming and outgoing edges
                                                      [boolean] [default: false]
  --base_path                   calculates path relatives to the base path
   [string] [default: "/currentpath"]
Run Code Online (Sandbox Code Playgroud)

  • 效果非常好!谢谢!你帮助我调试了一个烦人的依赖关系,否则这将花费很长时间 (2认同)

Mic*_*amm 6

依赖巡洋舰可以生成依赖图:

通过npm以下方式安装后:

npm install --save-dev dependency-cruiser
Run Code Online (Sandbox Code Playgroud)

您应该先运行:

node_modules/.bin/depcruise --info
Run Code Online (Sandbox Code Playgroud)

确保TypeScript支持有效。

用命令

node_modules/.bin/depcruise --exclude "^node_modules" --output-type json <your_entry_point.ts> > dependencies.json
Run Code Online (Sandbox Code Playgroud)

您可以创建一个包含TypeScript文件之间的依赖关系的JSON文件。

如果还安装了该dot实用程序(graphviz大多数Linux发行版的软件包中都提供),则可以执行以下操作:

node_modules/.bin/depcruise --exclude "^node_modules" --output-type dot <your_entry_point.ts> | dot -T svg > dependency_graph.svg
Run Code Online (Sandbox Code Playgroud)

生成依赖关系图作为SVG图像。