diff --git a/nvm.sh b/nvm.sh index cf9695070a..d0e5c00a6e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4559,7 +4559,7 @@ nvm_auto() { case "${NVM_MODE}" in none) return 0 ;; - use | install) + use) local VERSION local NVM_CURRENT NVM_CURRENT="$(nvm_ls_current)" @@ -4567,25 +4567,28 @@ nvm_auto() { VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)" if [ -n "${VERSION}" ]; then if [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then - if [ "_${NVM_MODE}" = '_install' ]; then - nvm install "${VERSION}" >/dev/null - else - nvm use --silent "${VERSION}" >/dev/null - fi + nvm use --silent "${VERSION}" >/dev/null else return 0 fi elif nvm_rc_version >/dev/null 2>&1; then - if [ "_${NVM_MODE}" = '_install' ]; then - nvm install >/dev/null - else - nvm use --silent >/dev/null - fi + nvm use --silent >/dev/null fi else nvm use --silent "${NVM_CURRENT}" >/dev/null fi ;; + install) + local VERSION + VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)" + if [ -n "${VERSION}" ] && [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then + nvm install "${VERSION}" >/dev/null + elif nvm_rc_version >/dev/null 2>&1; then + nvm install >/dev/null + else + return 0 + fi + ;; *) nvm_err 'Invalid auto mode supplied.' return 1 diff --git a/test/sourcing/Sourcing nvm.sh should keep version if one is active b/test/sourcing/Sourcing nvm.sh should keep version if one is active index 4254159d58..28f39c883c 100755 --- a/test/sourcing/Sourcing nvm.sh should keep version if one is active +++ b/test/sourcing/Sourcing nvm.sh should keep version if one is active @@ -9,12 +9,12 @@ echo '0.10.1' > ../../alias/default || die "couldn't create default alias" 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_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 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" +[ "_${NVM_CURRENT#v}" = "_${NVM_TARGET}" ] || die "node version not retained after sourcing" diff --git a/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded index fe837f2664..5ec0cb61fa 100755 --- a/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded +++ b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded @@ -8,21 +8,23 @@ die () { echo "$@" ; exit 1; } # 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_DIR_CACHED="${NVM_DIR}" nvm unload || die 'unloading returned nonzero exit code' -NVM_DIR="$NVM_DIR_CACHED" +NVM_DIR="${NVM_DIR_CACHED}" echo '0.10.1' > ../../alias/default || die 'creation of default alias failed' +which node && die 'node was found in PATH after unloading nvm' + # 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" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'" +[ "_${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_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" -[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \ - || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'" +[ "_${NVM_ALIAS_DEFAULT}" = "_default -> 0.10.1 (-> v0.10.1)" ] \ + || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '${NVM_ALIAS_DEFAULT}'" diff --git a/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it b/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it index 35ed553490..2cd095ca5d 100755 --- a/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it +++ b/test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it @@ -13,15 +13,15 @@ fi echo '0.10.2' > ../../.nvmrc || die 'creation of .nvmrc failed' \. ../../nvm.sh --install -EXIT_CODE="$(echo $?)" +EXIT_CODE="$?" echo 'sourcing complete.' -nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)" +nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: \n$(nvm_ls)" [ "_$(nvm_rc_version | \grep -o -e 'with version .*$')" = "_with version <0.10.2>" ] || die "nvm_rc_version $(nvm_rc_version)" -[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE" +[ "_${EXIT_CODE}" = '_0' ] || die "sourcing returned nonzero exit code: ${EXIT_CODE}" NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)" -[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT' `nvm ls`" +[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got >${NVM_LS_CURRENT}<\n$(nvm_ls)" diff --git a/test/sourcing/Sourcing nvm.sh with --install should install the default b/test/sourcing/Sourcing nvm.sh with --install should install the default index 8791455c2a..0f71d48bcf 100755 --- a/test/sourcing/Sourcing nvm.sh with --install should install the default +++ b/test/sourcing/Sourcing nvm.sh with --install should install the default @@ -16,17 +16,17 @@ echo '0.10.2' > ../../alias/default || die 'creation of default alias failed' echo 'sourcing nvm with --install...' \. ../../nvm.sh --install -EXIT_CODE="$(echo $?)" +EXIT_CODE="$?" echo 'sourcing complete.' -nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)" +nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: \n$(nvm_ls)" -[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE" +[ "_$EXIT_CODE" = '_0' ] || die "sourcing returned nonzero exit code: ${EXIT_CODE}" NVM_LS_CURRENT="$(nvm ls current | strip_colors | command grep -o v0.10.2)" -[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT'" +[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', >${NVM_LS_CURRENT}<\n$(nvm_ls)" NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" [ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \ - || die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got '$NVM_ALIAS_DEFAULT'" + || die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got >${NVM_ALIAS_DEFAULT}<\n$(nvm_ls)"