pahen / madge

Create graphs from your CommonJS, AMD or ES6 module dependencies
MIT License
9.09k stars 318 forks source link

AMD not finding nested depedencies #67

Closed OliverJAsh closed 9 years ago

OliverJAsh commented 9 years ago

Given:

// app.js
define(['a'], function (a) {
    console.log('a');
});
// a.js
define(['b'], function (b) {
    console.log('a');
});
// b.js
define([], function () {
    return {};
});

When I run:

// api.js
var madge = require('madge');
var dependencyObject = madge('app.js', {
    format: 'amd',
    findNestedDependencies: true
});
console.log(dependencyObject.tree);

The output is:

$ node api.js
{ app: [ 'a' ] }

How come madge is not finding the nested AMD dependencies?

mrjoelkemp commented 9 years ago

findNestedDependencies seems to allow dependencies within a module to be found. For example:

define(['dep'], function() {
  // Lazy load a file
  require(['some_file'], function() {});
});

That option would allow some_file to show up in the dependency list. It sounds like you want the entire dependency tree to be traversed. We can likely integrate https://github.com/mrjoelkemp/node-dependency-tree for that purpose.

OliverJAsh commented 9 years ago

It sounds like you want the entire dependency tree to be traversed

Yes, that's right. I would like to see a graph for my entire dependency tree.

OliverJAsh commented 9 years ago

That's what I thought this module did—showed you the whole dependency tree?

OliverJAsh commented 9 years ago

Any thoughts on it? @pahen @mrjoelkemp? I'm quite surprised it only shows one level of dependencies. Is that intentional?

mrjoelkemp commented 9 years ago

The expectation of the api seems to be such that you pass in a directory path if you want a scan of all files to be included in the tree. Your usage only specifies a single file. If you need to specify just that one file, then recursively tracing the tree is one solution. Alternatively, you could look into running madge on the bundled/optimized output using the mainRequireModule setting.

OliverJAsh commented 9 years ago

That helps, thanks!

On Tue, 1 Dec 2015, 12:11 Joel Kemp notifications@github.com wrote:

The expectation of the api seems to be such that you pass in a directory path if you want a scan of all files to be included in the tree. Your usage only specifies a single file. If you need to specify just that one file, then recursively tracing the tree is one solution. Alternatively, you could look into running madge on the bundled/optimized output using the mainRequireModule setting.

— Reply to this email directly or view it on GitHub https://github.com/pahen/madge/issues/67#issuecomment-160949545.

mrjoelkemp commented 9 years ago

No problem! Safe to close this issue? On Dec 1, 2015 8:30 AM, "Oliver Joseph Ash" notifications@github.com wrote:

That helps, thanks!

On Tue, 1 Dec 2015, 12:11 Joel Kemp notifications@github.com wrote:

The expectation of the api seems to be such that you pass in a directory path if you want a scan of all files to be included in the tree. Your usage only specifies a single file. If you need to specify just that one file, then recursively tracing the tree is one solution. Alternatively, you could look into running madge on the bundled/optimized output using the mainRequireModule setting.

— Reply to this email directly or view it on GitHub https://github.com/pahen/madge/issues/67#issuecomment-160949545.

— Reply to this email directly or view it on GitHub https://github.com/pahen/madge/issues/67#issuecomment-160968745.

ainthek commented 8 years ago

this LIMITATION of one level dependencies, shell be clearly stated at the beginning of the readme.

I have also wasted some time for this, trying to use another tool (dependo) which is using your project.