[Fix] `install`: Ignore npm command under $NVM_DIR when checking for global modules

David Moles 2020-11-16 16:49:02 -08:00
parent ed321f1df0
commit d4eba354b5
2 changed files with 13 additions and 2 deletions

View File

@ -262,7 +262,9 @@ nvm_detect_profile() {
# Node, and warn them if so. # Node, and warn them if so.
# #
nvm_check_global_modules() { 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 local NPM_VERSION
NPM_VERSION="$(npm --version)" NPM_VERSION="$(npm --version)"

View File

@ -6,9 +6,10 @@ cleanup () {
rm -f npm rm -f npm
PATH="$ORIGINAL_PATH" PATH="$ORIGINAL_PATH"
NVM_DIR="$ORIGINAL_NVM_DIR"
unset -f setup cleanup die unset -f setup cleanup die
unset message ORIGINAL_PATH unset message ORIGINAL_PATH ORIGINAL_NVM_DIR
} }
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
@ -16,6 +17,10 @@ NVM_ENV=testing \. ../../install.sh
setup () { setup () {
ORIGINAL_PATH="$PATH" ORIGINAL_PATH="$PATH"
ORIGINAL_NVM_DIR="$NVM_DIR"
# Pretend we're not using NVM
unset NVM_DIR
npm_config_prefix="$(pwd)" npm_config_prefix="$(pwd)"
export npm_config_prefix 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) message=$(nvm_check_global_modules)
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed" [ ! -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 npm uninstall -g nop >/dev/null
message=$(nvm_check_global_modules) 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" [ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"