Make sure `nvm run` works without a version argument when .nvmrc specifies a version.
diff --git a/nvm.sh b/nvm.sh
index 5b47806..cc27b23 100644
--- a/nvm.sh
+++ b/nvm.sh
@@ -208,7 +208,7 @@
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 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 ls List installed versions"
echo " nvm ls <version> List versions matching a given description"
@@ -471,20 +471,37 @@
echo "Now using node $VERSION"
;;
"run" )
+ local provided_version
+ local has_checked_nvmrc=0
# run given version of node
- if [ $# -lt 2 ]; then
- nvm_rc_version
- if [ -z "$NVM_RC_VERSION" ]; then
+ shift
+ if [ $# -lt 1 ]; 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
return
fi
fi
- NVM_PROVIDED_VERSION=`nvm_version $2`
- if [ -z "$NVM_PROVIDED_VERSION" ]; then
- nvm_rc_version
- NVM_PROVIDED_VERSION="$NVM_RC_VERSION"
+
+ provided_version=$1
+ if [ -n "$provided_version" ]; then
+ 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
+ VERSION=`nvm_version $NVM_RC_VERSION`
+ else
+ shift
+ fi
fi
- VERSION="$NVM_PROVIDED_VERSION"
+
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet"
return;
@@ -495,7 +512,7 @@
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
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" )
nvm_print_versions "`nvm_ls $2`"
diff --git "a/test/slow/nvm run/Running \"nvm run 0.x\" should work" "b/test/slow/nvm run/Running \"nvm run 0.x\" should work"
new file mode 100755
index 0000000..cc56601
--- /dev/null
+++ "b/test/slow/nvm run/Running \"nvm run 0.x\" should work"
@@ -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"
+
diff --git "a/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version" "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version"
new file mode 100755
index 0000000..181e3fc
--- /dev/null
+++ "b/test/slow/nvm run/Running \"nvm run\" should pick up .nvmrc version"
@@ -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"
+
diff --git a/test/slow/nvm run/setup_dir b/test/slow/nvm run/setup_dir
new file mode 100755
index 0000000..870a22c
--- /dev/null
+++ b/test/slow/nvm run/setup_dir
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. ../../../nvm.sh
+nvm install 0.10.7
+
+if [ -f ".nvmrc" ]; then
+ mv .nvmrc .nvmrc.bak
+fi
+
diff --git a/test/slow/nvm run/teardown_dir b/test/slow/nvm run/teardown_dir
new file mode 100755
index 0000000..120ea83
--- /dev/null
+++ b/test/slow/nvm run/teardown_dir
@@ -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
+