Add support for `$NPM_CONFIG_PREFIX` to `nvm_die_on_prefix`.

Fixes #606.
Jordan Harband 2015-09-23 06:25:55 -07:00
parent 1458de7293
commit 8ee6f30352
2 changed files with 16 additions and 2 deletions

9
nvm.sh
View File

@ -1274,6 +1274,13 @@ nvm_die_on_prefix() {
return 3
fi
if [ -n "$NPM_CONFIG_PREFIX" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then
nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
echo >&2 "Run \`unset NPM_CONFIG_PREFIX\` to unset it."
return 4
fi
if ! nvm_has 'npm'; then
return
fi
@ -1291,7 +1298,7 @@ nvm_die_on_prefix() {
else
echo >&2 "Run \`$NVM_COMMAND\` to unset it."
fi
return 4
return 10
fi
fi
}

View File

@ -50,6 +50,13 @@ EXIT_CODE="$(PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_3" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 3; got '$EXIT_CODE'"
OUTPUT="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "NPM_CONFIG_PREFIX" environment variable: currently set to "bar"
Run `unset NPM_CONFIG_PREFIX` to unset it.'
EXIT_CODE="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
npm() {
local args
args="$@"
@ -62,6 +69,6 @@ EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: cu
Run \`npm config delete prefix\` or \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_4" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 4 with bad prefix set; got '$EXIT_CODE'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
cleanup