Merge pull request #491 from creationix/nvm_exec
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add `nvm exec` command.
authored by Jordan Harband · committed by Jordan Harband · parents 6dc602b, a703d35 · Browse files · 6 files·+80 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+80 added−1 removed
- tests:+52 added−0 removed
- other:+28 added−1 removed
Provenance
- Commit
1a8479e- Tree
9a93ccf- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
6dc602b- Parent 2
a703d35
6 files changed+80 added−1 removed
added:test/slow/nvm exec/Running "nvm exec 0.x" should work+13 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+7+nvm use 0.108+NPM_VERSION_TEN="$(npm --version)"9+10+nvm use 0.11.7 && [ "$(node --version)" = "v0.11.7" ] || die "\`nvm use\` failed!"11+12+[ "$(nvm exec 0.10 npm --version | tail -1)" = "$NPM_VERSION_TEN" ] || die "`nvm exec` failed to run with the correct version"13+added:test/slow/nvm exec/Running "nvm exec" should pick up .nvmrc version+17 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+7+nvm use 0.10.78+NPM_VERSION_TEN="$(npm --version)"9+10+nvm use 0.11.7 && [ "$(node --version)" = "v0.11.7" ] || die "\`nvm use\` failed!"11+12+echo "0.10.7" > .nvmrc13+14+[ "$(nvm exec npm --version | tail -1)" = "$NPM_VERSION_TEN" ] || die "\`nvm exec\` failed to run with the .nvmrc version"15+16+[ "$(nvm exec npm --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm exec\` failed to print out the \"found in .nvmrc\" message"17+added:test/slow/nvm exec/setup_dir+10 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm install 0.10.75+nvm install 0.11.76+7+if [ -f ".nvmrc" ]; then8+ mv .nvmrc .nvmrc.bak9+fi10+added:test/slow/nvm exec/teardown_dir+12 added
1+#!/bin/sh2+3+. ../../../nvm.sh4+nvm uninstall v0.10.75+nvm uninstall v0.11.76+7+rm .nvmrc8+9+if [ -f ".nvmrc.bak" ]; then10+ mv .nvmrc.bak .nvmrc11+fi12+modified:nvm.sh+23 added
637 unmodified lines638 RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`639 echo "Running node $VERSION"640 NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"641 ;;642+ "exec" )643+ shift644+645+ local provided_version646+ provided_version=$1647+ if [ -n "$provided_version" ]; then648+ VERSION=`nvm_version $provided_version`649+ if [ $VERSION = "N/A" ]; then650+ provided_version=''651+ nvm_rc_version652+ VERSION=`nvm_version $NVM_RC_VERSION`653+ else654+ shift655+ fi656+ fi657+658+ if [ ! -d "$NVM_DIR/$VERSION" ]; then659+ echo "$VERSION version is not installed yet" >&2660+ return 1661+ fi662+ echo "Running node $VERSION"663+ NODE_VERSION=$VERSION $NVM_DIR/nvm-exec "$@"664+ ;;665 "ls" | "list" )666 local NVM_LS_OUTPUT667 local NVM_LS_EXIT_CODE668 NVM_LS_OUTPUT=$(nvm_ls "$2")94 unmodified linesmodified:README.markdown+5 added-1 removed
36 unmodified lines373839404141424344455 unmodified lines515253545556575859606162111 unmodified linesExpand all36 unmodified lines
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).`nvm use`, `nvm install`, and `nvm run` will all respect an `.nvmrc` file.`nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file.
To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.105 unmodified linesOr you can just run it:
nvm run 0.10 --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
If you want to see what versions are installed:
nvm ls
111 unmodified linesExpand all