Skip to content
Myr

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

6 files+61 added−22 removed

modified:test/sourcing/setup+1 added
7 unmodified lines
8rm -rf ../../v0.9.12910\. ../../nvm.sh11nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'12nvm install 0.10.3 || echo >&2 'nvm install 0.10.3 failed'13nvm unalias default || 'removing default alias failed'14nvm unload || echo >&2 'nvm unload failed'
added:test/sourcing/Sourcing nvm.sh should keep version if one is active+20 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45echo '0.10.1' > ../../alias/default || die "couldn't create default alias"67\. ../../nvm.sh || die 'sourcing returned nonzero exit code'89NVM_TARGET=0.10.310NVM_DEFAULT="$(nvm_resolve_local_alias default)"1112[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET"1314nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed"1516\. ../../nvm.sh || die 'sourcing returned nonzero exit code'1718NVM_CURRENT="$(nvm current)"1920[ "_${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/sh23die () { echo "$@" ; exit 1; }45echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'67\. ../../nvm.sh || die 'sourcing returned nonzero exit code'8\. ../common.sh910NVM_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'"1213# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"1415NVM_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/sh23die () { echo "$@" ; exit 1; }45\. ../common.sh67# 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'11NVM_DIR_CACHED="$NVM_DIR"12nvm unload || die 'unloading returned nonzero exit code'13NVM_DIR="$NVM_DIR_CACHED"1415echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'1617# Now to begin the real test18\. ../../nvm.sh || die 'sourcing returned nonzero exit code'1920NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)"21NVM_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'"2324# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"2526NVM_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 line
23rm -rf ../../alias4rm -rf ../../v0.10.15rm -rf ../../v0.10.26rm -rf ../../v0.10.37rm -f ../../.nvmrc
modified:nvm.sh+11 added-5 removed
3604 unmodified lines
3605 return $?3606}36073608nvm_auto() {3609 local NVM_CURRENT3610 NVM_CURRENT="$(nvm_ls_current)"3611 local NVM_MODE3612 NVM_MODE="${1-}"3613 local VERSION3614 if [ "_$NVM_MODE" = '_install' ]; then
3 unmodified lines
3618 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 1
22 unmodified lines