パッケージの詳細

npm-graph

clux39MIT0.5.0

Prints a dependency graph of modules that is actually required

npm ls, browserify, dependencies, analysis

readme

npm graph

npm status build status dependency status coverage status

Essentially npm ls with two modifications:

  • only explicitly required dependencies
  • finds cyclical requires

Dependencies are analyzed using parts of the browserify toolchain.

Usage

Install globally and give it a path to a local package or a file:

$ npm install -g npm-graph

no arguments - npm modules only

$ npm-graph node_modules/irc-stream/
irc-stream
 └───irc

If all modules in "dependencies" are used, then this should look like npm ls.

show builtins

$ npm-graph node_modules/irc-stream/ -b
irc-stream
 ├──┬irc
 │  ├───net
 │  ├───tls
 │  └───util
 └───stream

This can give some at a glance information about how browserifiable the module is.

show local files

File by file inclusion:

$ npm-graph node_modules/irc-stream/ -l
irc-stream
 └──┬irc
    ├───./codes
    └───./colors

cycle detection

Cycles are detected and shown in the tree with a after an offender. As an example, readable-stream (tsk tsk) closes a cyclical loop by having Duplex depend on Writable and vice versa (albeit lightly).

$ npm install readable-stream@1.0.27-1
$ npm-graph node_modules/readable-stream/writable.js -l
writable.js
 └─┬./lib/_stream_writable.js
   ├─┬./_stream_duplex ↪ ./_stream_writable
   │ ├─┬./_stream_readable
   │ │ ├──core-util-is
   │ │ ├──inherits
   │ │ ├──isarray
   │ │ └──string_decoder/
   │ ├──core-util-is
   │ └──inherits
   ├──core-util-is
   └──inherits

The mutual file inclusions would normally cause a recursion overflow when generating the tree if we hadn't first found the strongly connected components in the inclusion digraph and manually broken the cycle.

( •_•)
( •_•)>⌐■-■
(⌐■_■)

The cyclical components from Tarjan's algorithm are also available with -c:

$ npm-graph node_modules/readable-stream/writable.js -l -c
[ [ './node_modules/readable-stream/lib/_stream_writable.js',
    './node_modules/readable-stream/lib/_stream_duplex.js' ] ]

In this case, a 2-cycle.

License

MIT-Licensed. See LICENSE file for details.

更新履歴

0.5.0 / 2014-05-15

  • Change CLI library to yargs and unit test the cli bits better
  • Remove colored output from cycle output (-c)
  • module-deps upgraded to 3.7.12 (big change)
  • Can now ignore missing dependencies with --skip #6
    • note that -cov requires are (still) ignored regardless
    • without --skip, first missing entry will halt the process
  • Can now ignore traversing the tree of specific modules with --ignore #8
    • will avoid populating huge dependency trees from specific modules
    • currently slightly inconsistent #9

0.4.0 / 2014-07-18

  • do cycle analysis on the digraph given by module-deps
  • cyclical dependencies now detected and highlighted in the output tree
  • -c flag for raw cycles from Tarjan's algorithm
  • bump dependencies

0.3.3 / 2014-02-09

  • module-deps upgraded to 1.5.0

0.3.2 / 2014-02-09

  • module-deps upgraded to 1.4.2

0.3.1 / 2013-12-26

  • argv.b can be used to additionally show builtins
  • argv.l can be used to additionally show locally required files (always parsed anyway)
  • library usage can set new options with showBuiltins and showLocal as keys

0.3.0 / 2013-12-25

  • output now deterministic (#5)
  • module can now be used as a library as well

0.2.0 / 2013-12-25

  • filter out builtins from the tree
  • fixed missing module dependencies from locally required files (#1)

0.1.0 / 2013-12-24

  • package.json bin property now used properly as a fallback to directory entry

0.0.1 / 2013-12-24

  • first release