Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve all npm dependencies in tree to single version

I am somewhat new to npm and I have been working on converting an existing build process to use grunt with npm package management. We have a number of internal components that we build our apps upon. This results in a dependency tree that can get fairly complex. As a simplified example, consider:

[email protected]
├─┬ [email protected]
│ └── [email protected]
└─┬ [email protected]
  └── [email protected]

In the maven world the module-translation package would be resolved to a single version and the build system then knows which package to include into the app.

In npm, I'm finding that the full tree is created in the node_modules directory, following the method described here, under the section: Cycles, Conflicts, and Folder Parsimony.

  1. Are there any tools out there to resolve to a single version?
    1. I prefer this approach so I can use glob patterns to include all the resolved dependencies into the app.
  2. Is it a bad idea to have the system resolve to a single version in npm?
    1. Of course, this can result in incompatible versions between dependencies, but that beast is there whether the dependencies are resolved to a single version systematically or manually. Are there other potential issues?

There is a related question asked here, but with no answer: npm nested dependency management.

like image 560
Noremac Avatar asked Dec 08 '14 17:12

Noremac


People also ask

How do I remove multiple npm dependencies?

If you want to uninstall all global packages, then you need to name the packages one by one in the npm uninstall -g command. Run the npm list -g --depth=0 command to list the packages installed globally on your computer. That should uninstall all global packages for you.


1 Answers

I'm finding that this question doesn't quite make sense in the world of npm dependency management. Unlike tools such as maven, js can have multiple versions of the same package/artifact used at the same time.

My understanding is that using a tool such as browserify (or requirejs) it can handle the above situation where different versions of "module-translation" are needed. So really, there is no need to flatten the tree. Since flattening the tree could produce versioning conflicts, why do it if browserify can handle the multiple versions anyway?

like image 185
Noremac Avatar answered Nov 15 '22 06:11

Noremac