mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-28 12:41:34 +00:00
Ensure that if npm config get prefix
is set to something outside nvm
, that nvm use
refuses to work.
Fixes #606.
This commit is contained in:
@@ -7,7 +7,7 @@ die () { echo $@ ; exit 1; }
|
||||
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
|
||||
|
||||
. ../../nvm.sh
|
||||
nvm use v0.2.3 || die "Failed to activate v0.2.3"
|
||||
nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3"
|
||||
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly"
|
||||
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"
|
||||
# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable
|
||||
|
@@ -43,6 +43,13 @@ npm() {
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
|
||||
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
|
||||
|
||||
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
|
||||
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
|
||||
Run `unset PREFIX` to unset it.'
|
||||
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'"
|
||||
|
||||
npm() {
|
||||
local args
|
||||
args="$@"
|
||||
@@ -55,6 +62,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" = "_3" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 3 with bad prefix set; got '$EXIT_CODE'"
|
||||
[ "_$EXIT_CODE" = "_4" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 4 with bad prefix set; got '$EXIT_CODE'"
|
||||
|
||||
cleanup
|
||||
|
Reference in New Issue
Block a user