Skip to content

Commit

Permalink
install: Pass global-module check in the absence of npm
Browse files Browse the repository at this point in the history
  • Loading branch information
ELLIOTTCABLE committed Feb 3, 2015
1 parent 2a55f69 commit 058ef81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ nvm_detect_profile() {
# Node, and warn them if so.
#
nvm_check_global_modules() {
command -v npm >/dev/null 2>&1 || return 0

local NPM_VERSION
NPM_VERSION="$(npm --version)"
NPM_VERSION="${NPM_VERSION:-0}"
[ "${NPM_VERSION%%[!0-9]*}" -gt 1 ] || return 0

local NPM_GLOBAL_MODULES
NPM_GLOBAL_MODULES=$(npm list -g --depth=0 | sed '/ npm@/d')

Expand Down
16 changes: 15 additions & 1 deletion test/install_script/nvm_check_global_modules
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ cleanup () {
rm -rf "$npm_config_prefix/lib" >/dev/null 2>&1
unset npm_config_prefix

rm -f npm
PATH="$ORIGINAL_PATH"

unset -f setup cleanup die skip
unset message
unset message ORIGINAL_PATH
}
die () { echo $@ ; cleanup ; exit 1; }

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

setup () {
ORIGINAL_PATH="$PATH"

npm_config_prefix="$(pwd)"
export npm_config_prefix
mkdir -p "$npm_config_prefix/lib"
Expand All @@ -37,4 +42,13 @@ JSON
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module"

# Faking the absence of npm
PATH=".:$PATH"
touch npm
chmod +x npm

message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable"


cleanup

0 comments on commit 058ef81

Please sign in to comment.