diff --git a/nvm.sh b/nvm.sh index 84a87c3..5b47806 100644 --- a/nvm.sh +++ b/nvm.sh @@ -205,7 +205,7 @@ nvm() { echo "Usage:" echo " nvm help Show this message" echo " nvm --version Print out the latest released version of nvm" - echo " nvm install [-s] Download and install a , [-s] from source" + echo " nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available" echo " nvm uninstall Uninstall a version" echo " nvm use Modify PATH to use . Uses .nvmrc if available" echo " nvm run [] Run with as arguments" @@ -238,6 +238,8 @@ nvm() { local sum local tarball local nobinary + local version_not_provided=0 + local provided_version if ! nvm_has "curl"; then echo 'NVM Needs curl to proceed.' >&2; @@ -245,8 +247,12 @@ nvm() { fi if [ $# -lt 2 ]; then - nvm help - return + version_not_provided=1 + nvm_rc_version + if [ -z "$NVM_RC_VERSION" ]; then + nvm help + return + fi fi shift @@ -261,9 +267,16 @@ nvm() { nobinary=1 fi - [ -d "$NVM_DIR/$1" ] && echo "$1 is already installed." && return + provided_version=$1 + if [ -z "$provided_version" ]; then + if [ $version_not_provided -ne 1 ]; then + nvm_rc_version + fi + provided_version="$NVM_RC_VERSION" + fi + [ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." && return - VERSION=`nvm_remote_version $1` + VERSION=`nvm_remote_version $provided_version` ADDITIONAL_PARAMETERS='' shift @@ -460,10 +473,18 @@ nvm() { "run" ) # run given version of node if [ $# -lt 2 ]; then - nvm help - return + nvm_rc_version + if [ -z "$NVM_RC_VERSION" ]; then + nvm help + return + fi fi - VERSION=`nvm_version $2` + NVM_PROVIDED_VERSION=`nvm_version $2` + if [ -z "$NVM_PROVIDED_VERSION" ]; then + nvm_rc_version + NVM_PROVIDED_VERSION="$NVM_RC_VERSION" + fi + VERSION="$NVM_PROVIDED_VERSION" if [ ! -d "$NVM_DIR/$VERSION" ]; then echo "$VERSION version is not installed yet" return; diff --git a/test/slow/nvm install/install version specified in .nvmrc from binary b/test/slow/nvm install/install version specified in .nvmrc from binary new file mode 100644 index 0000000..dec2fe1 --- /dev/null +++ b/test/slow/nvm install/install version specified in .nvmrc from binary @@ -0,0 +1,20 @@ +#!/bin/sh + +set -e +. ../../../nvm.sh + +NVM_TEST_VERSION=v0.10.7 + +# Remove the stuff we're clobbering. +[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION + +# Install from binary +cat "$NVM_TEST_VERSION" > .nvmrc + +nvm install + +# Check +[ -d ../../../$NVM_TEST_VERSION ] +nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION + + diff --git a/test/slow/nvm install/install version specified in .nvmrc from source b/test/slow/nvm install/install version specified in .nvmrc from source new file mode 100644 index 0000000..6910228 --- /dev/null +++ b/test/slow/nvm install/install version specified in .nvmrc from source @@ -0,0 +1,20 @@ +#!/bin/sh + +set -e +. ../../../nvm.sh + +NVM_TEST_VERSION=v0.10.7 + +# Remove the stuff we're clobbering. +[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION + +# Install from binary +cat "$NVM_TEST_VERSION" > .nvmrc + +nvm install -s + +# Check +[ -d ../../../$NVM_TEST_VERSION ] +nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION + +