Respect previously nvm-loaded node version when sourcing
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Xandor Schiefer · committed by Jordan Harband · parent b111436 · Browse files · 6 files·+61 added−22 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+61 added−22 removed
- tests:+50 added−17 removed
- other:+11 added−5 removed
Provenance
- Commit
eabd7ab- Tree
c5c5f05- Author
Xandor Schiefer <me@xandor.co.za>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
b111436
6 files changed+61 added−22 removed
modified:test/sourcing/setup+1 added
7 unmodified lines8 rm -rf ../../v0.9.129 10 \. ../../nvm.sh11 nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'12+nvm install 0.10.3 || echo >&2 'nvm install 0.10.3 failed'13 nvm unalias default || 'removing default alias failed'14 nvm unload || echo >&2 'nvm unload failed'added:test/sourcing/Sourcing nvm.sh should keep version if one is active+20 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+echo '0.10.1' > ../../alias/default || die "couldn't create default alias"6+7+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'8+9+NVM_TARGET=0.10.310+NVM_DEFAULT="$(nvm_resolve_local_alias default)"11+12+[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET"13+14+nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed"15+16+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'17+18+NVM_CURRENT="$(nvm current)"19+20+[ "_${NVM_CURRENT#v}" = "_$NVM_TARGET" ] || die "node version not retained after sourcing"deleted:test/sourcing/Sourcing nvm.sh should use the default if available-17 removed
1-#!/bin/sh2-3-die () { echo "$@" ; exit 1; }4-5-echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'6-7-\. ../../nvm.sh || die 'sourcing returned nonzero exit code'8-\. ../common.sh9-10-NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"11-[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT'"12-13-# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"14-15-NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"16-[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \17- || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'"added:test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded+28 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+\. ../common.sh6+7+# We need to unload nvm again first, as by the time this test is run,8+# despite being unloaded in setup, the inherited PATH still contains9+# an nvm-installed node version. We have to reset NVM_DIR after the unload.10+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'11+NVM_DIR_CACHED="$NVM_DIR"12+nvm unload || die 'unloading returned nonzero exit code'13+NVM_DIR="$NVM_DIR_CACHED"14+15+echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'16+17+# Now to begin the real test18+\. ../../nvm.sh || die 'sourcing returned nonzero exit code'19+20+NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)"21+NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"22+[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'"23+24+# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"25+26+NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"27+[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \28+ || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'"modified:test/sourcing/teardown+1 added
1 unmodified line2 3 rm -rf ../../alias4 rm -rf ../../v0.10.15 rm -rf ../../v0.10.26+rm -rf ../../v0.10.37 rm -f ../../.nvmrcmodified:nvm.sh+11 added-5 removed
3604 unmodified lines3605 return $?3606 }3607 3608 nvm_auto() {3609+ local NVM_CURRENT3610+ NVM_CURRENT="$(nvm_ls_current)"3611 local NVM_MODE3612 NVM_MODE="${1-}"3613 local VERSION3614 if [ "_$NVM_MODE" = '_install' ]; then3 unmodified lines3618 elif nvm_rc_version >/dev/null 2>&1; then3619 nvm install >/dev/null3620 fi3621 elif [ "_$NVM_MODE" = '_use' ]; then3622+ if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then3620- VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"3621- if [ -n "$VERSION" ]; then3622- nvm use --silent "$VERSION" >/dev/null3623- elif nvm_rc_version >/dev/null 2>&1; then3624- nvm use --silent >/dev/null3623+ VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"3624+ if [ -n "${VERSION}" ]; then3625+ nvm use --silent "${VERSION}" >/dev/null3626+ elif nvm_rc_version >/dev/null 2>&1; then3627+ nvm use --silent >/dev/null3628+ fi3629+ else3630+ nvm use --silent "${NVM_CURRENT}" >/dev/null3631 fi3632 elif [ "_$NVM_MODE" != '_none' ]; then3633 nvm_err 'Invalid auto mode supplied.'3634 return 122 unmodified lines