From 6a085bc8b4a67cb18bde79e3452883f318f2d497 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 21 Oct 2026 12:47:13 -0700 Subject: [PATCH] [Fix] `nvm reinstall-packages`: don't print `VERSION=''` in zsh `nvm` already declares `VERSION` local, and declaring an existing local again makes zsh print it. --- nvm.sh | 1 - ...install-packages prints no shell variables | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 test/fast/Unit tests/nvm reinstall-packages prints no shell variables diff --git a/nvm.sh b/nvm.sh index 7ca5d6ec..81c61642 100755 --- a/nvm.sh +++ b/nvm.sh @@ -5599,7 +5599,6 @@ nvm() { return 2 fi - local VERSION if [ "_${PROVIDED_VERSION}" = "_system" ]; then if ! nvm_has_system_node && ! nvm_has_system_iojs; then nvm_err 'No system version of node or io.js detected.' diff --git a/test/fast/Unit tests/nvm reinstall-packages prints no shell variables b/test/fast/Unit tests/nvm reinstall-packages prints no shell variables new file mode 100755 index 00000000..92a05adb --- /dev/null +++ b/test/fast/Unit tests/nvm reinstall-packages prints no shell variables @@ -0,0 +1,38 @@ +#!/bin/sh + +ORIG_NVM_DIR="${NVM_DIR}" +TMP_DIR='' + +cleanup () { + case "${TMP_DIR}" in + /*) rm -rf "${TMP_DIR}" ;; + esac + NVM_DIR="${ORIG_NVM_DIR}" + export NVM_DIR + unset -f nvm_npm_global_modules nvm_ls_current +} + +die () { echo "$@" ; cleanup ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +\. ../../common.sh + +TMP_DIR="$(mktemp -d)" +NVM_DIR="${TMP_DIR}/nvm" +export NVM_DIR + +make_fake_node v20.0.0 || die 'fake node v20.0.0 could not be made' +nvm_ls_current() { echo 'v18.0.0'; } +nvm_npm_global_modules() { echo ' //// '; } + +# zsh prints a local that is declared again +OUTPUT="$(nvm reinstall-packages v20.0.0 2>&1)" +EXPECTED='Reinstalling global packages from v20.0.0... +No installed global packages found... +Linking global packages from v20.0.0... +No linked global packages found...' +[ "_${OUTPUT}" = "_${EXPECTED}" ] || die "nvm reinstall-packages printed >${OUTPUT}<, expected >${EXPECTED}<" + +cleanup