fnm
fnm copied to clipboard
Support for reinstall packages from other versions
Please add support for reinstall-packages-from
flag like nvm
๐๐ป
Duplicate of #139 ?
No, these are two distinct features.
@ljharb looks like the issue I linked is all about โreinstalling packages fromโ. Is there a feature of default packages in nvm too?
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".
thanks @ljharb, I read nvm's docs and now I understand. :)
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. ๐
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.
@jschuur that will include npm
as well, which could brick your target node version.
@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?
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
@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.
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 }