question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

strategies for installing dependencies of local dependencies

See original GitHub issue

Scenario

  • parent-pkg has local dependency: file: ./local-pkg.
  • npm install in parent-pkg.
  • ./local-pkg is copied and installed into parent_package/node_modules, along with the dependencies oflocal-pkg`.
  • post-install, run linklocal.
  • node_modules/local-pkg is now replaced with a relative symlink to ../local-pkg. Dependencies of local-pkg are not installed.
  • Use linklocal list to produce a list of all local dependencies, which we then pass to something like xargs, find -exec or bulk to run npm install --production for us: linklocal list | bulk -c "npm install --production".
  • Local dependencies have now got their dependencies installed.

Issues

  1. Dependencies of local dependencies were installed twice. First when the local dependencies were installed with the regular npm install, second during the bulk npm install in the local dependencies. This can lead to considerable increases in install time if you depend on anything that requires building.
  2. No deduplication occurs between local dependencies. If two local packages depend on the same thing, it will be installed twice.

Some Improvements

Don’t hit remote registry

Disable accessing the remote registry with npm install --cache-min=Infinity for the bulk install. You’ve already just installed everything you need so there’s a good chance everything is already in the cache. This prevents overhead of hitting npm servers over and over for every local dependency. Doesn’t solve rebuilding over and over again though.

Don’t install local dependencies then symlink them away

To avoid the initial install of everything before symlinking it all away, I’ve been doing linklocal in the preinstall script. Of course this requires linklocal and bulk to be installed before starting, so my preinstall (Makefile) looks something like:

preinstall:
    npm install linklocal bulk # this unfortunately ignores the version specified in package.json
    linklocal link -r
    linklocal list -r --unique | bulk -c "npm install --cache-min=Infinity"

but what’s really killing install time is rebuilding dependencies over and over due to lack of deduplication.

cc @hughsk @yoshuawuyts any ideas on what we can do to improve this?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
b-smetscommented, May 11, 2016

Any progress on this issue yet? The install time due to the repeated rebuilding of dependencies is really bad. I don’t think @jbach 's approach works with npm3 as the local package will not have its own node_modules folder when installed (before the linking). You would have to manually resolve all dependencies (and their dependencies and so on) and cherry pick them all into the local package module.

0reactions
jbachcommented, Nov 23, 2015

Old issue, but still: I think the “stealing” approach is the way to go. Considering npm3’s behaviour, node_modules/local-pkg/node_modules should only include module versions that are specific to local-pkg, thus not in the flat hierarch. Copying the node_modules/local-pkg/node_modules folder to ./local-pkg/node_modules before symlinking works, at least in npm3. I’m currently doing exactly that by script but would love to replace it with linklocal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

install-local-dependencies - npm
install -local-dependencies checks your package.json and installs the listed local packages as they were installed from npm . This helps you to ...
Read more >
npm install supports local packages and dependencies
The npm install command supports local development and allows to quickly install and symlink local modules and packages.
Read more >
How to specify local modules as npm package dependencies
run npm i -g install-local; run npx install-local --save <local-path> inside the target repository to install the local dependency. Further reading: ...
Read more >
Strategies for keeping your packages and dependencies ...
For dependencies within dependencies, a good solution is to use the package-lock.json file. Consider using this locking solution for getting ...
Read more >
Learning the Basics - Gradle User Manual
Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found