Respect previously nvm-loaded node version when sourcing
parent
b111436fde
commit
eabd7ab13d
10
nvm.sh
10
nvm.sh
|
@ -3606,6 +3606,8 @@ nvm_supports_xz() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_auto() {
|
nvm_auto() {
|
||||||
|
local NVM_CURRENT
|
||||||
|
NVM_CURRENT="$(nvm_ls_current)"
|
||||||
local NVM_MODE
|
local NVM_MODE
|
||||||
NVM_MODE="${1-}"
|
NVM_MODE="${1-}"
|
||||||
local VERSION
|
local VERSION
|
||||||
|
@ -3617,12 +3619,16 @@ nvm_auto() {
|
||||||
nvm install >/dev/null
|
nvm install >/dev/null
|
||||||
fi
|
fi
|
||||||
elif [ "_$NVM_MODE" = '_use' ]; then
|
elif [ "_$NVM_MODE" = '_use' ]; then
|
||||||
|
if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
|
||||||
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
|
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
|
||||||
if [ -n "$VERSION" ]; then
|
if [ -n "${VERSION}" ]; then
|
||||||
nvm use --silent "$VERSION" >/dev/null
|
nvm use --silent "${VERSION}" >/dev/null
|
||||||
elif nvm_rc_version >/dev/null 2>&1; then
|
elif nvm_rc_version >/dev/null 2>&1; then
|
||||||
nvm use --silent >/dev/null
|
nvm use --silent >/dev/null
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
nvm use --silent "${NVM_CURRENT}" >/dev/null
|
||||||
|
fi
|
||||||
elif [ "_$NVM_MODE" != '_none' ]; then
|
elif [ "_$NVM_MODE" != '_none' ]; then
|
||||||
nvm_err 'Invalid auto mode supplied.'
|
nvm_err 'Invalid auto mode supplied.'
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
echo '0.10.1' > ../../alias/default || die "couldn't create default alias"
|
||||||
|
|
||||||
|
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
||||||
|
|
||||||
|
NVM_TARGET=0.10.3
|
||||||
|
NVM_DEFAULT="$(nvm_resolve_local_alias default)"
|
||||||
|
|
||||||
|
[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET"
|
||||||
|
|
||||||
|
nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed"
|
||||||
|
|
||||||
|
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
||||||
|
|
||||||
|
NVM_CURRENT="$(nvm current)"
|
||||||
|
|
||||||
|
[ "_${NVM_CURRENT#v}" = "_$NVM_TARGET" ] || die "node version not retained after sourcing"
|
|
@ -2,13 +2,24 @@
|
||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'
|
|
||||||
|
|
||||||
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
|
||||||
\. ../common.sh
|
\. ../common.sh
|
||||||
|
|
||||||
|
# We need to unload nvm again first, as by the time this test is run,
|
||||||
|
# despite being unloaded in setup, the inherited PATH still contains
|
||||||
|
# an nvm-installed node version. We have to reset NVM_DIR after the unload.
|
||||||
|
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
||||||
|
NVM_DIR_CACHED="$NVM_DIR"
|
||||||
|
nvm unload || die 'unloading returned nonzero exit code'
|
||||||
|
NVM_DIR="$NVM_DIR_CACHED"
|
||||||
|
|
||||||
|
echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'
|
||||||
|
|
||||||
|
# Now to begin the real test
|
||||||
|
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
||||||
|
|
||||||
|
NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)"
|
||||||
NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"
|
NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"
|
||||||
[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT'"
|
[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'"
|
||||||
|
|
||||||
# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
|
# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
|
||||||
|
|
|
@ -9,5 +9,6 @@ rm -rf ../../v0.9.12
|
||||||
|
|
||||||
\. ../../nvm.sh
|
\. ../../nvm.sh
|
||||||
nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'
|
nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'
|
||||||
|
nvm install 0.10.3 || echo >&2 'nvm install 0.10.3 failed'
|
||||||
nvm unalias default || 'removing default alias failed'
|
nvm unalias default || 'removing default alias failed'
|
||||||
nvm unload || echo >&2 'nvm unload failed'
|
nvm unload || echo >&2 'nvm unload failed'
|
||||||
|
|
|
@ -3,4 +3,5 @@
|
||||||
rm -rf ../../alias
|
rm -rf ../../alias
|
||||||
rm -rf ../../v0.10.1
|
rm -rf ../../v0.10.1
|
||||||
rm -rf ../../v0.10.2
|
rm -rf ../../v0.10.2
|
||||||
|
rm -rf ../../v0.10.3
|
||||||
rm -f ../../.nvmrc
|
rm -f ../../.nvmrc
|
||||||
|
|
Loading…
Reference in New Issue