Use `nvm_ensure_version_installed` to consistently check if a version is installed.

Fixes #675.
master
Jordan Harband 2015-02-21 20:03:28 -08:00
parent 0d9329435c
commit fb853614a7
1 changed files with 23 additions and 16 deletions

39
nvm.sh
View File

@ -1343,12 +1343,15 @@ nvm() {
return 8 return 8
fi fi
nvm_ensure_version_installed "$2"
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
return $EXIT_CODE
fi
local NVM_VERSION_DIR local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")" NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
# Strip other version from PATH # Strip other version from PATH
PATH="$(nvm_strip_path "$PATH" "/bin")" PATH="$(nvm_strip_path "$PATH" "/bin")"
# Prepend current version # Prepend current version
@ -1453,20 +1456,20 @@ nvm() {
if [ -n "$provided_version" ]; then if [ -n "$provided_version" ]; then
VERSION="$(nvm_version "$provided_version")" VERSION="$(nvm_version "$provided_version")"
if [ "_$VERSION" = "_N/A" ]; then if [ "_$VERSION" = "_N/A" ]; then
provided_version=''
nvm_rc_version nvm_rc_version
VERSION="$(nvm_version "$NVM_RC_VERSION")" provided_version="$NVM_RC_VERSION"
VERSION="$(nvm_version "$provided_version")"
else else
shift shift
fi fi
fi fi
local NVM_VERSION_DIR nvm_ensure_version_installed "$provided_version"
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")" EXIT_CODE=$?
if [ ! -d "$NVM_VERSION_DIR" ]; then if [ "$EXIT_CODE" != "0" ]; then
echo "$VERSION version is not installed yet" >&2 return $EXIT_CODE
return 1
fi fi
echo "Running node $VERSION" echo "Running node $VERSION"
NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@" NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
;; ;;
@ -1525,13 +1528,16 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
nvm_version current nvm_version current
;; ;;
"which" ) "which" )
local provided_version
provided_version="$2"
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
nvm_rc_version nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
provided_version="$NVM_RC_VERSION"
VERSION=$(nvm_version "$NVM_RC_VERSION") VERSION=$(nvm_version "$NVM_RC_VERSION")
fi fi
elif [ "_$2" != '_system' ]; then elif [ "_$2" != '_system' ]; then
VERSION="$(nvm_version "$2")" VERSION="$(nvm_version "$provided_version")"
else else
VERSION="$2" VERSION="$2"
fi fi
@ -1559,12 +1565,13 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
return 8 return 8
fi fi
nvm_ensure_version_installed "$provided_version"
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
return $EXIT_CODE
fi
local NVM_VERSION_DIR local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")" NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
echo "$NVM_VERSION_DIR/bin/node" echo "$NVM_VERSION_DIR/bin/node"
;; ;;
"alias" ) "alias" )