From 33fda56d2a8fbc4576cb95cb070b075de3d31aa2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 14 Mar 2026 14:34:06 -0700 Subject: [PATCH] [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 https://github.com/nvm-sh/nvm/commit/7807a9f09e54a14f9b493c6eeda0022489cda496. --- nvm.sh | 2 +- ...up aliases pointing to uninstalled version | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 test/fast/Running 'nvm uninstall' should clean up aliases pointing to uninstalled version diff --git a/nvm.sh b/nvm.sh index b1cf64c..0a656da 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3906,7 +3906,7 @@ nvm() { nvm_echo "${NVM_SUCCESS_MSG}" # 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}")" done ;; diff --git a/test/fast/Running 'nvm uninstall' should clean up aliases pointing to uninstalled version b/test/fast/Running 'nvm uninstall' should clean up aliases pointing to uninstalled version new file mode 100755 index 0000000..58f23bd --- /dev/null +++ b/test/fast/Running 'nvm uninstall' should clean up aliases pointing to uninstalled version @@ -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"