[Fix] nvm_install_latest_npm: avoid unbound variable

Fixes #3447
This commit is contained in:
Jordan Harband 2024-10-22 22:02:01 -07:00
parent 5dc31ac51b
commit 6b70c40f15
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56

5
nvm.sh
View File

@ -196,6 +196,9 @@ nvm_install_latest_npm() {
nvm_echo 'Attempting to upgrade to the latest working version of npm...' nvm_echo 'Attempting to upgrade to the latest working version of npm...'
local NODE_VERSION local NODE_VERSION
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")" NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ "${NODE_VERSION}" = 'system' ]; then if [ "${NODE_VERSION}" = 'system' ]; then
NODE_VERSION="$(node --version)" NODE_VERSION="$(node --version)"
elif [ "${NODE_VERSION}" = 'none' ]; then elif [ "${NODE_VERSION}" = 'none' ]; then
@ -206,8 +209,6 @@ nvm_install_latest_npm() {
nvm_err 'Unable to obtain node version.' nvm_err 'Unable to obtain node version.'
return 1 return 1
fi fi
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ -z "${NPM_VERSION}" ]; then if [ -z "${NPM_VERSION}" ]; then
nvm_err 'Unable to obtain npm version.' nvm_err 'Unable to obtain npm version.'
return 2 return 2