Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist global npm installs #364

Closed
wants to merge 5 commits into from

Conversation

Jonnymcc
Copy link

Sometimes I need a different version of npm than the one installed with a version. Every time I switch node versions with n it wipes out my global node modules since it is a fresh copy from that installed version. This change backs up the global node modules so that the next time you switch to a previous version you were using the global node modules you installed will still be there.

run ./run_tests.sh to demonstrate that this change fixes the problem.

@qw3rtman
Copy link
Collaborator

qw3rtman commented Aug 5, 2016

I think this is a great addition; however, it is extremely slow to copy every single global module installed. For this reason, I think persisting a global module should be opt-in. For example:

n 0.11.1 # install v0.11.1
npm install --global [email protected]
yo --version # 1.1.0
n persist yo # persist the current `yo` version for this version of Node

n latest # install v6.3.1
npm update --global yo
yo --version # 1.8.4
n persist yo # persist the current `yo` version for this version of Node

n 0.11.1 # switch back to v0.11.1
yo --version # 1.1.0

There could be a similar command to unpersist.

What do you think about this?

@Jonnymcc
Copy link
Author

Jonnymcc commented Aug 8, 2016

I think making it opt in is fine. I feel that adding a command to persist once or to toggle is a bit much. Instead I'm thinking setting an environment variable that if set persists global modules is a good solution. For people that want to persist their global installs I believe that they would want this to apply to all versions managed by n and not have to worry about running a command. In most cases I would imagine that globally installed modules would be light, I'm thinking npm, grunt, bower?.. and that the bulk of installed modules would be installed locally to a project.

Does adding an environment variable sound sufficient?

@JamesChevalier
Copy link

I just switched from homebrew's node to having n manage my node installs. So, I'm brand new to n & my background is mostly in ruby. This probably skews my opinions quite a bit, so my perspective might not fall in line with the node community.

Just in case it's helpful... I expected that each version of node that n installed would have its own "global" view of npm & its packages.
I thought that n 6.6.0 && npm -g list and n 4.5.0 && npm -g list would produce two different lists of packages. I think my mindset here is coming from gemsets/bundler.

I don't know if this is a completely ridiculous suggestion. I just wanted to share my point of view as a relative newcomer, in case it's useful.

Thanks for all your hard work!

@qw3rtman
Copy link
Collaborator

qw3rtman commented Oct 1, 2016

@JamesChevalier I think isolating npm for each Node version is important. At the same time, I think it should be implemented to accommodate n's ease-of-use. There are some users of n (myself included) who don't want to manually manage packages for each Node version. There are also some users who would benefit from that kind of flexibility.

As such, my main concern is that a solution compensating for both user's needs would be

  1. too automatic (makes many assumptions) for power users, or
  2. too error-prone (configuration can become a mess) for more relaxed users.

If we are able to come up with a solution that serves both types of users, I would be all for implementing it! If not, making this isolated npm an optional mode may be best.

Thanks for sharing your thoughts! Community input is what makes good open-source software great. 😄

@Kikobeats
Copy link

what about that?

@sam3d
Copy link

sam3d commented Jun 5, 2017

What about what, @Kikobeats?

@Jonnymcc Jonnymcc force-pushed the persist-global-npm-installs branch from 30e5cc2 to b0ecf57 Compare June 27, 2018 18:35
@amosbird
Copy link

amosbird commented Nov 2, 2018

Hmm, what's the state of this pr?

@shadowspawn
Copy link
Collaborator

This is interesting, but I do not think adding more files to the install is a good fit for n. See especially this comment: #364 (comment)

I think a lighter weight approach to achieve the separation would be to symlink into nvh/versions from the install destination instead of copying, but that isn't something I plan to do either.

Feel free to open a new issue if this comes up again, with new information and renewed interest.

Thank you for your contributions.

@shadowspawn
Copy link
Collaborator

I have added support for preserving npm in nvh if any readers would like to give it a try. (It was made possible by switching to rsync for the install and so can't be brought back to n.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants