Skip to content

Resolving local/nested node_modules folder  #161

Closed
@walisc

Description

@walisc

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 #162 is a potential fix for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions