Make sure `nvm run` works without a version argument when .nvmrc specifies a version.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jordan Harband · committed by Jordan Harband · parent 4cf9401 · Browse files · 5 files·+68 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+68 added−10 removed
- tests:+41 added−0 removed
- other:+27 added−10 removed
Provenance
- Commit
20953ab- Tree
c9701eb- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
4cf9401
5 files changed+68 added−10 removed
added:test/slow/nvm run/Running "nvm run 0.x" should work+9 added
1+#!/bin/sh2+3+4+die () { echo $@ ; exit 1; }5+6+. ../../../nvm.sh7+8+[ "$(nvm run 0.10.7 --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the correct version"9+added:test/slow/nvm run/Running "nvm run" should pick up .nvmrc version+12 added
1+#!/bin/sh2+3+4+die () { echo $@ ; exit 1; }5+6+. ../../../nvm.sh7+8+echo "0.10.7" > .nvmrc9+[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the .nvmrc version"10+11+[ "$(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"12+added:test/slow/nvm run/setup_dir+9 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm install 0.10.75+6+if [ -f ".nvmrc" ]; then7+ mv .nvmrc .nvmrc.bak8+fi9+added:test/slow/nvm run/teardown_dir+11 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm uninstall v0.10.75+6+rm .nvmrc7+8+if [ -f ".nvmrc.bak" ]; then9+ mv .nvmrc.bak .nvmrc10+fi11+modified:nvm.sh+27 added-10 removed
206 unmodified lines207 echo " nvm --version Print out the latest released version of nvm"208 echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available"209 echo " nvm uninstall <version> Uninstall a version"210 echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available"211- echo " nvm run <version> [<args>] Run <version> with <args> as arguments"211+ echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"212 echo " nvm current Display currently activated version"213 echo " nvm ls List installed versions"214 echo " nvm ls <version> List versions matching a given description"215 echo " nvm ls-remote List remote versions available for install"254 unmodified lines470 export NVM_BIN="$NVM_DIR/$VERSION/bin"471 echo "Now using node $VERSION"472 ;;473 "run" )474+ local provided_version475+ local has_checked_nvmrc=0476 # run given version of node477+ shift475- if [ $# -lt 2 ]; then476- nvm_rc_version477- if [ -z "$NVM_RC_VERSION" ]; then478+ if [ $# -lt 1 ]; then479+ nvm_rc_version && has_checked_nvmrc=1480+ if [ -n "$NVM_RC_VERSION" ]; then481+ VERSION=`nvm_version $NVM_RC_VERSION`482+ else483+ VERSION='N/A'484+ fi485+ if [ $VERSION = "N/A" ]; then486 nvm help487 return488 fi489 fi482- NVM_PROVIDED_VERSION=`nvm_version $2`483- if [ -z "$NVM_PROVIDED_VERSION" ]; then484- nvm_rc_version485- NVM_PROVIDED_VERSION="$NVM_RC_VERSION"490+491+ provided_version=$1492+ if [ -n "$provided_version" ]; then493+ VERSION=`nvm_version $provided_version`494+ if [ $VERSION = "N/A" ]; then495+ provided_version=''496+ if [ $has_checked_nvmrc -ne 1 ]; then497+ nvm_rc_version && has_checked_nvmrc=1498+ fi499+ VERSION=`nvm_version $NVM_RC_VERSION`500+ else501+ shift502+ fi503 fi487- VERSION="$NVM_PROVIDED_VERSION"504+505 if [ ! -d "$NVM_DIR/$VERSION" ]; then506 echo "$VERSION version is not installed yet"507 return;508 fi2 unmodified lines511 else512 RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"513 fi514 echo "Running node $VERSION"498- NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "${@:3}"515+ NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"516 ;;517 "ls" | "list" )518 nvm_print_versions "`nvm_ls $2`"519 if [ $# -eq 1 ]; then85 unmodified lines