dependents / dependents/node-dependency-tree
npm i --global-style
- Dominant language
- JavaScript
- Stars
- 777
- Forks
- 83
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
Maybe I'm creating an issue in the wrong repository and real problem hides somewhere in dependencies. But I use `dependency-tree` as an entry point, so ... it looks like a good start.
Let's imagine that we have the following directory layout:
```
|
- package.json
- node_modules
| |
| - package1
| |
| - index.js
|
- dist <- dependency-tree `directory` argument
|
- package.json
- src
|
- index.js <- dependency-tree `filename` argument (path.join(..., 'dist', 'src', 'index.js'))
- node_modules
|
- package2
|
- index.js
- node_modules
|
- package1
|
- index.js
```
I invoke dependency-tree with the following arguments:
```
{
directory: path.join(, 'dist'),
filename: path.join(, 'dist/src/index.js')
}
```
And `index.js` requires `package2` module. Which, respectively, requires `package1` module. The folder where `package2` resides was initiated by the following command: `npm i --global-style`, i.e. dependencies of modules from `package.json` are put into local `node_modules` folders of each package. In other words - I want to maintain old-style node_modules directory layout (let's pretend that I like duplicates :) ), where each top-level module holds its modules with itself.
And here is the problem. Top level directory () also contains `node_modules` with `package1`. And when I receive output from **dependency-tree** I have something like this:
```
.../dist/src/index.js
.../dist/node_modules/package2/index.js
.../node_modules/package1/index.js
```
NOT:
```
.../dist/src/index.js
.../dist/node_modules/package2/index.js
.../dist/node_modules/package2/node_modules/package1/index.js
```
If I'm not mistaken [this algorithm](https://nodejs.org/dist/latest/docs/api/modules.html#modules_all_together) assumes the second variant (it starts to look at the nearest `node_modules` folder and traverses to the root of the file system).
Am I wrong or something works not as expected? I have some checks after receiving list from **dependency-tree**. One of them is confirmation that common directory for all imports is `dist` folder. And this check started to fall when I tried to use `npm i` command inside `dist` folder with `--global-style` argument. Without it (when `package1` folder resides at the same level as `package2`) all works as expected.
Can you confirm that I'm wrong :) or help to resolve the issue?
Thanks in advance! CC: @mrjoelkemp
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.