[Fix] nvm uninstall: fix alias cleanup glob expansion

The `*` glob was inside double quotes, preventing shell expansion. `nvm_grep -l` received a literal `*` filename instead of the list of alias files, so aliases pointing to uninstalled versions were never cleaned up.

Bug introduced in 7807a9f09e.
This commit is contained in:
Jordan Harband
2026-03-14 14:34:06 -07:00
parent 32863e1052
commit 33fda56d2a
2 changed files with 25 additions and 1 deletions

2
nvm.sh
View File

@@ -3906,7 +3906,7 @@ nvm() {
nvm_echo "${NVM_SUCCESS_MSG}" nvm_echo "${NVM_SUCCESS_MSG}"
# rm any aliases that point to uninstalled version. # rm any aliases that point to uninstalled version.
for ALIAS in $(nvm_grep -l "${VERSION}" "$(nvm_alias_path)/*" 2>/dev/null); do for ALIAS in $(nvm_grep -l "${VERSION}" "$(nvm_alias_path)"/* 2>/dev/null); do
nvm unalias "$(command basename "${ALIAS}")" nvm unalias "$(command basename "${ALIAS}")"
done done
;; ;;

View File

@@ -0,0 +1,24 @@
#!/bin/sh
die() { echo "$@" >&2; exit 1; }
set -ex
: nvm.sh
\. ../../nvm.sh
\. ../common.sh
make_fake_node v0.0.1
nvm alias test_alias v0.0.1
# Verify alias was created
[ -f "$(nvm_alias_path)/test_alias" ] || die "alias file should exist before uninstall"
nvm uninstall v0.0.1
# Verify the version directory was removed
[ ! -d "$(nvm_version_path v0.0.1)" ] || die "version directory should be removed"
# Verify the alias was cleaned up
[ ! -f "$(nvm_alias_path)/test_alias" ] || die "alias file should be removed after uninstalling the version it points to"