Make sure `nvm run` works without a version argument when .nvmrc specifies a version.

master
Jordan Harband 2014-04-19 15:09:40 -07:00
parent 4cf940153c
commit 20953ab04c
5 changed files with 68 additions and 10 deletions

37
nvm.sh
View File

@ -208,7 +208,7 @@ nvm() {
echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available" 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. Uses .nvmrc if available for <version>"
echo " nvm current Display currently activated version" echo " nvm current Display currently activated version"
echo " nvm ls List installed versions" echo " nvm ls List installed versions"
echo " nvm ls <version> List versions matching a given description" echo " nvm ls <version> List versions matching a given description"
@ -471,20 +471,37 @@ nvm() {
echo "Now using node $VERSION" echo "Now using node $VERSION"
;; ;;
"run" ) "run" )
local provided_version
local has_checked_nvmrc=0
# run given version of node # run given version of node
if [ $# -lt 2 ]; then shift
nvm_rc_version if [ $# -lt 1 ]; then
if [ -z "$NVM_RC_VERSION" ]; then nvm_rc_version && has_checked_nvmrc=1
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION`
else
VERSION='N/A'
fi
if [ $VERSION = "N/A" ]; then
nvm help nvm help
return return
fi fi
fi fi
NVM_PROVIDED_VERSION=`nvm_version $2`
if [ -z "$NVM_PROVIDED_VERSION" ]; then provided_version=$1
nvm_rc_version if [ -n "$provided_version" ]; then
NVM_PROVIDED_VERSION="$NVM_RC_VERSION" VERSION=`nvm_version $provided_version`
if [ $VERSION = "N/A" ]; then
provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then
nvm_rc_version && has_checked_nvmrc=1
fi fi
VERSION="$NVM_PROVIDED_VERSION" VERSION=`nvm_version $NVM_RC_VERSION`
else
shift
fi
fi
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;
@ -495,7 +512,7 @@ nvm() {
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH" RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi fi
echo "Running node $VERSION" echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "${@:3}" NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;; ;;
"ls" | "list" ) "ls" | "list" )
nvm_print_versions "`nvm_ls $2`" nvm_print_versions "`nvm_ls $2`"

View File

@ -0,0 +1,9 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "$(nvm run 0.10.7 --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the correct version"

View File

@ -0,0 +1,12 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
echo "0.10.7" > .nvmrc
[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the .nvmrc version"
[ "$(nvm run --version | head -1)" = "Found .nvmrc files with version <0.10.7>" ] || die "`nvm run` failed to print out the \"found in .nvmrc\" message"

View File

@ -0,0 +1,9 @@
#!/bin/sh
. ../../../nvm.sh
nvm install 0.10.7
if [ -f ".nvmrc" ]; then
mv .nvmrc .nvmrc.bak
fi

View File

@ -0,0 +1,11 @@
#!/bin/sh
. ../../../nvm.sh
nvm uninstall v0.10.7
rm .nvmrc
if [ -f ".nvmrc.bak" ]; then
mv .nvmrc.bak .nvmrc
fi