node-dependency-tree
node-dependency-tree copied to clipboard
Resolving local/nested node_modules folder
There are cases that arise when a node module specifies it's own node_modules folder (for instance when wanting to tie itself to a particular version of a package). Example below:
./
├── app.js
└── node_modules
└── packageA
├── index.js
└── node_modules
└── child_packageA
└── index.js
In the case above, requiring
dependencyTree({
"app.js",
"./",
isListForm: true
});
should return the dependencies
[
"./node_modules/packageA/index.js",
"./node_modules/packageA/node_modules/child_packageA/index.js"
]
which is does not.
Another issue is that if the base node_modules has a version of child_packageA, it will refer to that as a dependency, which is wrong (and can have adverse effects if it is a different version of the package). For instance
./
├── app.js
└── node_modules
├── child_packageA
│ └── index.js
└── packageA
├── index.js
└── node_modules
└── child_packageA
└── index.js
Returns
[
"./node_modules/packageA/index.js",
"./node_modules/child_packageA/index.js"
]
The main issue is related to the directory
used when passing a file to precient
to get the dependencies. When the file is part of node module/package, the directory should be the root of that package (as all files are contained in there)
Pull request https://github.com/dependents/node-dependency-tree/pull/162 is a potential fix for this.