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

Support for reinstall packages from other versions #620

Open
gperdomor opened this issue Jan 2, 2022 · 12 comments
Open

Support for reinstall packages from other versions #620

gperdomor opened this issue Jan 2, 2022 · 12 comments

Comments

@gperdomor
Copy link

Please add support for reinstall-packages-from flag like nvm 🙏🏻

@Schniz
Copy link
Owner

Schniz commented Jan 2, 2022

Duplicate of #139 ?

@ljharb
Copy link

ljharb commented Jan 2, 2022

No, these are two distinct features.

@Schniz
Copy link
Owner

Schniz commented Jan 2, 2022

@ljharb looks like the issue I linked is all about “reinstalling packages from”. Is there a feature of default packages in nvm too?

@ljharb
Copy link

ljharb commented Jan 2, 2022

The one you linked's title and OP suggest it's about "installing packages by default with a newly installed node version", which is a feature of nvm.

This one is about nvm reinstall-packages X and nvm install X --reinstall-packages-from Y which are for "on-demand, install the global packages from one node version into the current/new one".

@Schniz
Copy link
Owner

Schniz commented Jan 3, 2022

thanks @ljharb, I read nvm's docs and now I understand. :)

@ooloth
Copy link

ooloth commented Dec 16, 2022

fnm install X --reinstall-packages-from Y would be handy for ensuring packages I install with npm i -g automatically follow me as I change versions. 🙏

@jschuur
Copy link

jschuur commented Apr 18, 2023

I'd love to see this supported too, but in the mean time, this little shell command makes it a little easier to get a list of your installed global modules

npm list -g --json | jq -r '.dependencies | keys | join(" ")'

This assumed you have jq installed. It'll format all the installed modules in a single line that you can copy and paste (or redirect to your clipboard by adding | pbcopy on a Mac) into a new npm command to manually reinstall modules from a previous install.

Run this in the old version, of course. If you're adventurous, you could try something to install them automatically, but you'd need to redirect the output from an older node version to the new one. Somehow.

@ljharb
Copy link

ljharb commented Apr 18, 2023

@jschuur that will include npm as well, which could brick your target node version.

@jschuur
Copy link

jschuur commented Apr 19, 2023

@jschuur that will include npm as well, which could brick your target node version.

Are you suggesting if I run npm install -g npm (by copying it from a list of installed modules and accidentally including it) that it could brick my node version? How so?

Is this an fnm specific issue or a general possibility?

@aforty
Copy link

aforty commented Dec 8, 2023

I made a little shell script to help me with this. Just add it to your bashrc/zshrc. Hope this helps some people.

fnm-reinstall-packages-from () { npm install -g $(fnm exec --using=$1 npm list -g | grep "├──\|└──" | awk '{gsub(/@[0-9.]+/, "", $2); print $2}' | tr '\n' ' ' | sed 's/ $//') }

Example Usage:

$ node --version
v18.12.0
$ fnm install v18.19.0
$ fnm use v18.19.0
$ fnm-reinstall-packages-from v18.12.0

@ljharb
Copy link

ljharb commented Dec 8, 2023

@jschuur yes, you can, because newer versions of npm don't necessarily work on older node versions, and once a broken one is installed, you're screwed.

@Southclaws
Copy link

Here's a Nushell version:

npm list -g -json
| from json
| get dependencies
| items {|key, value| { name: $key, version: $value.version } }
| format "{name}@{version}"
| each { |r| npm install $r }

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

No branches or pull requests

7 participants