nvm icon indicating copy to clipboard operation
nvm copied to clipboard

[Request] Command to reinstall latest versions of default_packages

Open Nantris opened this issue 3 years ago • 4 comments

Currently we use nvm install [same version we're already using] - but this is a bit unwieldy and presumably does quite a bit of unnecessary work.

Our use case is to update to the latest version of global dependencies that often introduce/resolve bugs, requiring rather frequent upgrades.

Nantris avatar Jun 06 '22 20:06 Nantris

While there basically shouldn't be any globally installed packages - community guidance/best practices on that has evolved since the feature was added in 2017 - this seems reasonable.

We have nvm reinstall-packages $version already - maybe nvm install-default-packages?

ljharb avatar Jun 06 '22 20:06 ljharb

Another option might be to allow passing this nvm --reinstall-packages-from=default without the need for a command like nvm install.

nvm reinstall-packages latest would be good too, if latest were allowed as a version.

Nantris avatar Jun 06 '22 20:06 Nantris

latest is already a potential user alias, as is default, so i don't think we can leverage reinstall-packages for this.

ljharb avatar Jun 06 '22 20:06 ljharb

Does nvm reinstall-packages * work? I'm not able to check for a while, but that would be a good syntax if there's nothing blocking it.

New commands would also be welcome, of course!

Nantris avatar Jun 06 '22 21:06 Nantris

While there basically shouldn't be any globally installed packages

I somewhat agree, but the reality looks different (i.e. expo-cli has to be installed globally to work or neovim/tree-sitter-cli for LunarVim

I need a dedicated command to just update those global dependencies, because this will fail with permission issues:

	npm_global_packages=($(npm list -g --depth 0 | awk '/ /{print $2}'))
	for val in "${npm_global_packages[@]}"; do
		npm i -g --force $(echo $val | tr "." "\n" | head -1)
	done

My goal is to upgrade node, reinstall all packages form the previous node version and upgrade all default-packages. Manually installed packages could stay on the same version (not like the objective in the code above), so I can locked versions with manual installs while having rolling versions by editing $NVM_DIR/default-packages.

martin-braun avatar Sep 29 '22 10:09 martin-braun

Anything global should work with npx also.

Why will that fail with permissions issues? Anyone running node should have full ownership of npm root -g

ljharb avatar Sep 29 '22 15:09 ljharb

@ljharb Thanks, for some reason I had issue, but I retried today and somehow cannot reproduce. In fact, the code-snippet I shared above is working fine to upgrade all globally installed permissions. Although it's still not what was originally requested, because it will not just upgrade default-packages, but minor versions of all global packages.

npx itself is great, but it does not upgrade without @latest suffix, as you mentioned.

martin-braun avatar Sep 30 '22 16:09 martin-braun

I checked the code - nvm install $(nvm current) doesn't really do much extra work; and if you have an .nvmrc, nvm install would do the same thing.

That said, this is a trivial command to add, so I'll do it.

ljharb avatar Oct 13 '22 21:10 ljharb

But what if a user only needs to update one out of, say, 15 global packages? In that case nvm install is doing a lot of extra work reinstalling all of those, no?

Nantris avatar Oct 13 '22 22:10 Nantris

@Slapbox well sure, but nvm install-default-packages would do that too. If you know which packages you need to update, you'd just run npm install -g $thatPackage.

ljharb avatar Oct 13 '22 22:10 ljharb

Basically, it just does npm install -g a b c d or whatever, and npm figures out what needs to be actually updated. nvm wouldn't do any further optimization than that.

ljharb avatar Oct 13 '22 22:10 ljharb

@Slapbox well sure, but nvm install-default-packages would do that too.

Definitely fair. I'd forgotten that was my original suggestion.

If you know which packages you need to update, you'd just run npm install -g $thatPackage.

I hadn't thought that was safe to run when using nvm. Thanks for the tip!


I personally I think there's no point adding any additional command with your findings in mind - I think the existence of this issue and your comments are sufficient - but I'll leave it to you to decide whether to close this now or later.

Thanks again @ljharb!

Nantris avatar Oct 13 '22 22:10 Nantris

In that case, I'll close it until there's demand in the future.

I did land f062cca, which refactors things so it'll be a two-liner and a test file to add the command if needed in the future.

ljharb avatar Oct 13 '22 23:10 ljharb