Schniz / fnm

🚀 Fast and simple Node.js version manager, built in Rust
https://fnm.vercel.app
GNU General Public License v3.0
17.69k stars 449 forks source link

Question: migrate global npm packages #481

Open bfulop opened 3 years ago

bfulop commented 3 years ago

Hello,

Thank you for this great tool!

I was wondering, what's the "recommended" way to migrate globally installed npm packages when moving from one version to another?

Thanks again!

istevkovski commented 2 years ago

I second this, can we push for this to happen?

samhwang commented 2 years ago

I believe the nvm way of doing this was to:

I'd love to see fnm having this capability as well! <3

ljharb commented 2 years ago

It’s nvm reinstall-packages Y since that’s a more accurate name :-) (and nvm install X --reinstall-packages-from=Y)

It will reinstall packages as well as copy over symlinks (from npm link).

kraftwerk28 commented 1 year ago

I use this for migrating global packages (assuming we are currently on the newer version):

fnm_upgrade () {
  fnm exec --using=$1 npm ls --global --json \
    | jq -r '.dependencies | to_entries[] | .key+"@"+.value.version' \
    | xargs npm i -g
}

# Usage:
$ fnm_upgrade 18.4
its-monotype commented 10 months ago

Has anyone managed to create a script for windows PS?

jryom commented 10 months ago

I switched to pnpm for global packages, which sort of solved this issue for me as pnpm keeps packages in a global folder, not tied to a particular version of node. Might be helpful for someone else as well.

ljharb commented 10 months ago

That’s surprising since global packages must be tied to a particular version of node, since installed and compiled packages can differ based on the node version.

atwright147 commented 10 months ago

Is this a dupe of https://github.com/Schniz/fnm/issues/139?

I made a suggestion to add a hooks system, which I think could be used to implement this in https://github.com/Schniz/fnm/issues/1060

romantech commented 3 months ago

I created a simple script and uploaded it to GitHub Gist. Running the command below will install the LTS version of Node.js and reinstall the global packages that are installed in the current Node.js version. You can also specify the Node.js version you want to install using the -v option.

curl -fsSL https://gist.githubusercontent.com/romantech/83ac87cea4e9a6d7a0985f610df329e5/raw/decd27fb4fb3c0aa6563a74e000dc00974f6f1e9/update-node-lts.sh | bash -s -- -v <version>