https://github.com/sverweij/dependency-cruiser
これが使いやすいです。
タイトルはTypescriptとしていますが、JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD. で行ける様です。
インストール
READMEの通りですが、
npm install --save-dev dependency-cruiser
複数のプロジェクトで使いたいなら、--global
でも良いと思います。
使ってみる
これもREADMEに書いてますが、
# --save-devでローカルにインストールし、かつパスを通してない場合のコマンド
# プロジェクトルートで実行
./node_modules/.bin/depcruise --exclude "^node_modules" --output-type dot src | dot -T svg > dependencygraph.svg
これでsrc/
配下のモジュール群の依存性グラフが生成されます。
nodeバージョンについて注意
ERROR: Your node version (11.15.0) is not supported. dependency-cruiser
follows the node.js release cycle and runs on these node versions:
^8.10||^10||^12
See https://nodejs.org/en/about/releases/ for details.
こんなのが出ました。8.10, 10, 12じゃないとダメなようです。自分の環境に12.6.0
があったのでそれでやったらできました。