Closed deepfriedmind closed 3 years ago
No, there's no way to do that out of the box. But what does that flag do exactly?
It migrates global packages from the current install to the new one.
See: https://github.com/nvm-sh/nvm#migrating-global-packages-while-installing
This will do the trick.
set --local pkgs (string split / --fields=10 -- $nvm_data/$nvm_current_version/lib/node_modules/*)
nvm install latest && npm install --global $pkgs
I'm not sure I want to add a flag just to do that. What do you think?
That won't handle linked packages, which nvm does handle, nor will it preserve version numbers (i think).
This will do the trick.
set --local pkgs (string split / --fields=10 -- $nvm_data/$nvm_current_version/lib/node_modules/*) nvm install latest && npm install --global $pkgs
I'm not sure I want to add a flag just to do that. What do you think?
string split
doesn't have a fields
option so the command fails.
I'm currently doing something similar however:
set -l npmPackages (npm list -g --parseable --depth=0 | sed '1d' | awk '{gsub(/\/.*\//,"",$1); print}')
nvm install latest && npm install -g $npmPackages
Unfortunately, this workaround will re-install all packages even if no new node version was installed.
My bad, --fields
is only available in Fish 3.2.
For 3.0 or 3.1 we can use string match
instead:
set --local pkgs (string match --regex -- '[^/]+$' $nvm_data/$nvm_current_version/lib/node_modules/*)
nvm install latest && npm install --global $pkgs
Preserving version numbers is slower since we need to use npm
:
set --local pkgs (npm list --global --depth=0 | string match --regex -- "\w+@[^\s]+\$")
nvm install latest && npm install --global $pkgs
Handling linked packages is much more involved:
$nvm_current_version
to local variablefoobar@1.2.1 -> /home/jb/foobar
nvm install VERSION
set --local pkgs (npm list --global --depth=0 | string match --regex -- "\w+@[^\s]+\$")
That regex breaks on -
. "[\w,-]+@[^\s]+\$"
works.
Anyhoo, it would be nice to have the same functionality as reinstall-packages-from
but I'm fine with working around it. Thanks for your time.
any updates on this? This would be really useful.
Sorry, I won't be working on this so I'm closing. See this comment for a workaround.
Feel free to send me a PR if you have a working solution, but I can't promise that too will get merged. We'll see.
When updating to the latest node in nvm, I'm used to doing
nvm install node --reinstall-packages-from=node
. Is there any way to achieve the same result in nvm.fish?