From d4eba354b5da6195e4017c0baa3c5664d9db1d1d Mon Sep 17 00:00:00 2001 From: David Moles Date: Mon, 16 Nov 2020 16:49:02 -0800 Subject: [PATCH] [Fix] `install`: Ignore npm command under $NVM_DIR when checking for global modules --- install.sh | 4 +++- test/install_script/nvm_check_global_modules | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 1d2b0a601d..3c33289728 100755 --- a/install.sh +++ b/install.sh @@ -262,7 +262,9 @@ nvm_detect_profile() { # Node, and warn them if so. # nvm_check_global_modules() { - command -v npm >/dev/null 2>&1 || return 0 + local NPM_COMMAND + NPM_COMMAND="$(command -v npm 2>/dev/null)" || return 0 + [ -n "${NVM_DIR}" ] && [ -z "${NPM_COMMAND%%$NVM_DIR/*}" ] && return 0 local NPM_VERSION NPM_VERSION="$(npm --version)" diff --git a/test/install_script/nvm_check_global_modules b/test/install_script/nvm_check_global_modules index 4183b97024..01d6b01ea1 100755 --- a/test/install_script/nvm_check_global_modules +++ b/test/install_script/nvm_check_global_modules @@ -6,9 +6,10 @@ cleanup () { rm -f npm PATH="$ORIGINAL_PATH" + NVM_DIR="$ORIGINAL_NVM_DIR" unset -f setup cleanup die - unset message ORIGINAL_PATH + unset message ORIGINAL_PATH ORIGINAL_NVM_DIR } die () { echo "$@" ; cleanup ; exit 1; } @@ -16,6 +17,10 @@ NVM_ENV=testing \. ../../install.sh setup () { ORIGINAL_PATH="$PATH" + ORIGINAL_NVM_DIR="$NVM_DIR" + + # Pretend we're not using NVM + unset NVM_DIR npm_config_prefix="$(pwd)" export npm_config_prefix @@ -29,6 +34,10 @@ npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested message=$(nvm_check_global_modules) [ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed" +# Admit we're using NVM, just for this one test +message=$(NVM_DIR=$ORIGINAL_NVM_DIR nvm_check_global_modules) +[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm" + npm uninstall -g nop >/dev/null message=$(nvm_check_global_modules) [ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"