Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
11 changes: 10 additions & 1 deletion test/install_script/nvm_check_global_modules
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ 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; }

NVM_ENV=testing \. ../../install.sh

setup () {
ORIGINAL_PATH="$PATH"
ORIGINAL_NVM_DIR="$NVM_DIR"

# Pretend we're not using NVM
unset NVM_DIR
ljharb marked this conversation as resolved.
Show resolved Hide resolved

npm_config_prefix="$(pwd)"
export npm_config_prefix
Expand All @@ -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"
Expand Down