Skip to content
Myr

[New] support `--no-use` on sourcing, in supported shells.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #972.

authored by Jordan Harband · committed by Jordan Harband · parent e76fe61 · Browse files · 3 files+68 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+68 added−12 removed

  • tests:+32 added−0 removed
  • other:+36 added−12 removed

3 files+68 added−12 removed

added:test/sourcing/Sourcing nvm.sh with --no-use should not use anything+32 added
1#!/bin/sh23die () { echo $@ ; exit 1; }4supports_source_options () {5 [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]6}78if ! supports_source_options; then9 echo 'this shell does not support passing options on sourcing'10 exit 0;11fi1213. ../../nvm.sh14nvm install 4.1.0 || die 'install of v4.1.0 failed'15nvm_version 4.1.0 >/dev/null 2>&1 || die "v4.1.0 not installed: $(nvm ls)"16nvm deactivate || die 'nvm deactivate failed'1718NVM_CURRENT="$(nvm current)"19[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"2021nvm unload || die 'nvm unload failed'2223. ../../nvm.sh --no-use24EXIT_CODE="$(echo $?)"2526echo 'sourcing complete.'2728[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"2930NVM_CURRENT="$(nvm current)"31[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"32
modified:nvm-exec+1 added-1 removed
1#!/bin/bash23DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"45source "$DIR/nvm.sh"5. "$DIR/nvm.sh" --no-use67if [ -n "$NODE_VERSION" ]; then8 nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)9else
4 unmodified lines
modified:nvm.sh+35 added-11 removed
2323 unmodified lines
2324 nvm_version_greater nvm_version_greater_than_or_equal_to \2325 nvm_print_npm_version nvm_npm_global_modules \2326 nvm_has_system_node nvm_has_system_iojs \2327 nvm_download nvm_get_latest nvm_has nvm_get_latest \2328 nvm_supports_source_options nvm_supports_xz > /dev/null 2>&12328 nvm_supports_source_options nvm_auto nvm_supports_xz > /dev/null 2>&12329 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&12330 ;;2331 * )2332 >&2 nvm help
9 unmodified lines
2342nvm_supports_xz() {2343 command which xz >/dev/null 2>&1 && nvm_version_greater_than_or_equal_to "$1" "2.3.2"2344}23452346nvm_auto() {2347 local NVM_MODE2348 NVM_MODE="${1-}"2349 local VERSION2346NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)"2347if nvm_supports_source_options && [ "$#" -gt 0 ] && [ "_$1" = "_--install" ]; then2348 if [ -n "$NVM_VERSION" ]; then2349 nvm install "$NVM_VERSION" >/dev/null2350 elif nvm_rc_version >/dev/null 2>&1; then2351 nvm install >/dev/null2350 if [ "_$NVM_MODE" = '_install' ]; then2351 VERSION="$(nvm_alias default 2>/dev/null || echo)"2352 if [ -n "$VERSION" ]; then2353 nvm install "$VERSION" >/dev/null2354 elif nvm_rc_version >/dev/null 2>&1; then2355 nvm install >/dev/null2356 fi2357 elif [ "_$NVM_MODE" = '_use' ]; then2358 VERSION="$(nvm_alias default 2>/dev/null || echo)"2359 if [ -n "$VERSION" ]; then2360 nvm use --silent "$VERSION" >/dev/null2361 elif nvm_rc_version >/dev/null 2>&1; then2362 nvm use --silent >/dev/null2363 fi2364 elif [ "_$NVM_MODE" != '_none' ]; then2365 echo >&2 'Invalid auto mode supplied.'2366 return 12367 fi2353elif [ -n "$NVM_VERSION" ]; then2354 nvm use --silent "$NVM_VERSION" >/dev/null2355elif nvm_rc_version >/dev/null 2>&1; then2356 nvm use --silent >/dev/null2368}23692370NVM_AUTO_MODE='use'2371if nvm_supports_source_options; then2372 while [ $# -ne 0 ]2373 do2374 case "$1" in2375 --install) NVM_AUTO_MODE='install' ;;2376 --no-use) NVM_AUTO_MODE='none' ;;2377 esac2378 shift2379 done2380fi2381nvm_auto "$NVM_AUTO_MODE"23822383} # this ensures the entire script is downloaded #