Merge pull request #398 from creationix/install_use_nvmrc

`nvm install` and `nvm run` use .nvmrc when version not provided
master
Jordan Harband 2014-04-19 22:36:33 -07:00
commit 7976a1343f
3 changed files with 69 additions and 8 deletions

29
nvm.sh
View File

@ -205,7 +205,7 @@ nvm() {
echo "Usage:" echo "Usage:"
echo " nvm help Show this message" echo " nvm help Show this message"
echo " nvm --version Print out the latest released version of nvm" echo " nvm --version Print out the latest released version of nvm"
echo " nvm install [-s] <version> Download and install a <version>, [-s] from source" echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available"
echo " nvm uninstall <version> Uninstall a version" echo " nvm uninstall <version> Uninstall a version"
echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available" echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available"
echo " nvm run <version> [<args>] Run <version> with <args> as arguments" echo " nvm run <version> [<args>] Run <version> with <args> as arguments"
@ -238,6 +238,8 @@ nvm() {
local sum local sum
local tarball local tarball
local nobinary local nobinary
local version_not_provided=0
local provided_version
if ! nvm_has "curl"; then if ! nvm_has "curl"; then
echo 'NVM Needs curl to proceed.' >&2; echo 'NVM Needs curl to proceed.' >&2;
@ -245,9 +247,13 @@ nvm() {
fi fi
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
version_not_provided=1
nvm_rc_version
if [ -z "$NVM_RC_VERSION" ]; then
nvm help nvm help
return return
fi fi
fi
shift shift
@ -261,9 +267,16 @@ nvm() {
nobinary=1 nobinary=1
fi 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='' ADDITIONAL_PARAMETERS=''
shift shift
@ -460,10 +473,18 @@ nvm() {
"run" ) "run" )
# run given version of node # run given version of node
if [ $# -lt 2 ]; then if [ $# -lt 2 ]; then
nvm_rc_version
if [ -z "$NVM_RC_VERSION" ]; then
nvm help nvm help
return return
fi fi
VERSION=`nvm_version $2` fi
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 if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet"
return; return;

View File

@ -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

View File

@ -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