[New] support `--no-use` on sourcing, in supported shells.
Fixes #972.
parent
e76fe61d95
commit
4fcf37fa29
2
nvm-exec
2
nvm-exec
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
source "$DIR/nvm.sh"
|
. "$DIR/nvm.sh" --no-use
|
||||||
|
|
||||||
if [ -n "$NODE_VERSION" ]; then
|
if [ -n "$NODE_VERSION" ]; then
|
||||||
nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)
|
nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)
|
||||||
|
|
38
nvm.sh
38
nvm.sh
|
@ -2325,7 +2325,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d'
|
||||||
nvm_print_npm_version nvm_npm_global_modules \
|
nvm_print_npm_version nvm_npm_global_modules \
|
||||||
nvm_has_system_node nvm_has_system_iojs \
|
nvm_has_system_node nvm_has_system_iojs \
|
||||||
nvm_download nvm_get_latest nvm_has nvm_get_latest \
|
nvm_download nvm_get_latest nvm_has nvm_get_latest \
|
||||||
nvm_supports_source_options nvm_supports_xz > /dev/null 2>&1
|
nvm_supports_source_options nvm_auto nvm_supports_xz > /dev/null 2>&1
|
||||||
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
|
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
|
@ -2343,17 +2343,41 @@ nvm_supports_xz() {
|
||||||
command which xz >/dev/null 2>&1 && nvm_version_greater_than_or_equal_to "$1" "2.3.2"
|
command which xz >/dev/null 2>&1 && nvm_version_greater_than_or_equal_to "$1" "2.3.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)"
|
nvm_auto() {
|
||||||
if nvm_supports_source_options && [ "$#" -gt 0 ] && [ "_$1" = "_--install" ]; then
|
local NVM_MODE
|
||||||
if [ -n "$NVM_VERSION" ]; then
|
NVM_MODE="${1-}"
|
||||||
nvm install "$NVM_VERSION" >/dev/null
|
local VERSION
|
||||||
|
if [ "_$NVM_MODE" = '_install' ]; then
|
||||||
|
VERSION="$(nvm_alias default 2>/dev/null || echo)"
|
||||||
|
if [ -n "$VERSION" ]; then
|
||||||
|
nvm install "$VERSION" >/dev/null
|
||||||
elif nvm_rc_version >/dev/null 2>&1; then
|
elif nvm_rc_version >/dev/null 2>&1; then
|
||||||
nvm install >/dev/null
|
nvm install >/dev/null
|
||||||
fi
|
fi
|
||||||
elif [ -n "$NVM_VERSION" ]; then
|
elif [ "_$NVM_MODE" = '_use' ]; then
|
||||||
nvm use --silent "$NVM_VERSION" >/dev/null
|
VERSION="$(nvm_alias default 2>/dev/null || echo)"
|
||||||
|
if [ -n "$VERSION" ]; then
|
||||||
|
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
|
||||||
|
elif [ "_$NVM_MODE" != '_none' ]; then
|
||||||
|
echo >&2 'Invalid auto mode supplied.'
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
NVM_AUTO_MODE='use'
|
||||||
|
if nvm_supports_source_options; then
|
||||||
|
while [ $# -ne 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
--install) NVM_AUTO_MODE='install' ;;
|
||||||
|
--no-use) NVM_AUTO_MODE='none' ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
nvm_auto "$NVM_AUTO_MODE"
|
||||||
|
|
||||||
} # this ensures the entire script is downloaded #
|
} # this ensures the entire script is downloaded #
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
supports_source_options () {
|
||||||
|
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! supports_source_options; then
|
||||||
|
echo 'this shell does not support passing options on sourcing'
|
||||||
|
exit 0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
. ../../nvm.sh
|
||||||
|
nvm install 4.1.0 || die 'install of v4.1.0 failed'
|
||||||
|
nvm_version 4.1.0 >/dev/null 2>&1 || die "v4.1.0 not installed: $(nvm ls)"
|
||||||
|
nvm deactivate || die 'nvm deactivate failed'
|
||||||
|
|
||||||
|
NVM_CURRENT="$(nvm current)"
|
||||||
|
[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"
|
||||||
|
|
||||||
|
nvm unload || die 'nvm unload failed'
|
||||||
|
|
||||||
|
. ../../nvm.sh --no-use
|
||||||
|
EXIT_CODE="$(echo $?)"
|
||||||
|
|
||||||
|
echo 'sourcing complete.'
|
||||||
|
|
||||||
|
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
|
||||||
|
|
||||||
|
NVM_CURRENT="$(nvm current)"
|
||||||
|
[ "_$NVM_CURRENT" = '_none' ] || [ "_$NVM_CURRENT" = '_system' ] || die "'nvm current' did not return 'none' or 'system', got '$NVM_CURRENT' `nvm ls`"
|
||||||
|
|
Loading…
Reference in New Issue