4

Is there an NPM module that can show the dependencies between individual JS files within a module?

Suppose I have 20 JS files in my own NPM module; I'd like to see the dependency tree between my 20 JS files.

6
  • You know you wouldn't be sure there's no other dependency, as the imports are dynamically resolved, right ? (not pretending a graph of the obvious dependencies wouldn't make sense) Commented Mar 24, 2016 at 12:30
  • I'm not sure I follow. A trail through a dependency starts with a require() statement. Simply following them recursively is a relatively trivial problem. I'm also excluding dependencies from package.json, e.g, require('some-module-from-npmjs.org') will be thrown away whereas require('./utils/calculator.js') will be followed. Commented Mar 24, 2016 at 12:33
  • I mean it's legit to do let randomModule = require(names[Math.random()*names.length|0]);. Or something more useful but still dynamic. Of course there are some obvious dependencies, but, but also non obvious ones. Commented Mar 24, 2016 at 12:42
  • Ah, true. I hadn't thought about that. Let's assume that all require() statements are fully "knowable": require('./util/calculator.js'). Commented Mar 24, 2016 at 12:43
  • Then I guess a tool like github.com/pahen/madge would work Commented Mar 24, 2016 at 12:46

1 Answer 1

3

Some tools are available to graph the obvious dependencies (the ones you can guess from a static analysis).

See for example MaDGe - Module Dependency Graph

Sign up to request clarification or add additional context in comments.

1 Comment

I made myself a convenience wrapper around this great tool to quickly open a dependency graph image from the CLI and delete it afterward: gist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.