Compare commits

...

23 Commits

Author SHA1 Message Date
Jordan Harband
29f582611b v0.6.1 2014-05-04 12:40:02 -07:00
Jordan Harband
673cda56c4 Adding a test for nvm install invalid behavior, and correcting the message.
From f00d688c87 (commitcomment-6205164)
2014-05-04 12:03:26 -07:00
Jordan Harband
e562a5645b v0.6.0 2014-05-04 02:20:31 -07:00
Jordan Harband
c0c5e8d7ef Editing README to note improved .nvmrc behavior. 2014-05-04 02:20:24 -07:00
Jordan Harband
f00d688c87 Nicer failure message when trying to install an invalid version. Fixes #285. 2014-05-04 00:59:08 -07:00
Jordan Harband
5aa78f21cf Merge branch 'nvmrc' - Fixes #404 2014-05-04 00:47:16 -07:00
Jordan Harband
4a7275a0c6 Ensuring paths are in quotes, to preserve spaces. 2014-05-04 00:39:46 -07:00
Jordan Harband
c77be55cdc Updating "nvm run" tests. 2014-05-04 00:39:32 -07:00
Jordan Harband
e195fccdb7 Escaping backticks 2014-05-03 23:29:21 -07:00
Jordan Harband
87516039a8 Using portable conditional syntax. 2014-05-02 23:28:42 -07:00
Koen Punt
80e349edb1 locate .nvmrc without find
instead of using find and actually cd'ing into directories
we're now using simple string replacement on the `pwd`
2014-05-02 23:02:34 -07:00
Jordan Harband
038c1f3d0f Find .nvmrc files upwards. 2014-05-02 23:02:34 -07:00
Jordan Harband
66455f7c77 Refactor so "finding .nvmrc" can be done in a bash function. 2014-05-02 23:02:34 -07:00
Jordan Harband
a69eae10e3 Merge pull request #405 from reqshark/master
github raw served from new subdomain
2014-04-26 10:03:41 -07:00
Bent Cardan
13b87449e8 github raw served from new subdomain 2014-04-26 03:48:06 -04:00
Jordan Harband
222250f2d1 v0.5.1 2014-04-25 10:47:59 -07:00
Jordan Harband
77f4490391 Using markdown footnotes. 2014-04-25 10:47:07 -07:00
Jordan Harband
0871131dfd Make sure nvm-exec can use .nvmrc logic. Fixes #402, obviates #403. 2014-04-25 10:38:21 -07:00
Jordan Harband
e6bd207624 When auto-printing "help" on a command other than "help", return a nonzero exit code. 2014-04-25 10:35:52 -07:00
Jordan Harband
bad79e6d77 v0.5.0 2014-04-20 00:36:12 -07:00
Jordan Harband
d07fa2db10 Merge pull request #399 from creationix/run_use_nvmrc
Make sure `nvm run` works without a version argument when .nvmrc specifies a version
2014-04-20 00:35:59 -07:00
Jordan Harband
20953ab04c Make sure nvm run works without a version argument when .nvmrc specifies a version. 2014-04-20 00:28:07 -07:00
Jordan Harband
4cf940153c Use node 0.9 for these testsso that people aren't likely to have it installed 2014-04-19 23:41:36 -07:00
12 changed files with 139 additions and 46 deletions

View File

@@ -2,7 +2,7 @@ language: c # defaults to ruby
install: install:
- sudo apt-get install ksh zsh -y - sudo apt-get install ksh zsh -y
before_script: before_script:
- curl -o /tmp/urchin https://raw.github.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin - curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin
script: script:
- NVM_DIR=$TRAVIS_BUILD_DIR make URCHIN=/tmp/urchin test - NVM_DIR=$TRAVIS_BUILD_DIR make URCHIN=/tmp/urchin test

View File

@@ -1,4 +1,4 @@
# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)](https://travis-ci.org/creationix/nvm) # Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)][3]
## Installation ## Installation
@@ -6,13 +6,13 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
### Install script ### Install script
To install you could use the [install script](https://github.com/creationix/nvm/blob/v0.4.0/install.sh) using cURL: To install you could use the [install script][2] using cURL:
curl https://raw.github.com/creationix/nvm/v0.4.0/install.sh | sh curl https://raw.githubusercontent.com/creationix/nvm/v0.6.1/install.sh | sh
or Wget: or Wget:
wget -qO- https://raw.github.com/creationix/nvm/v0.4.0/install.sh | sh wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.6.1/install.sh | sh
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub> <sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
@@ -37,6 +37,9 @@ Often I also put in a line to use a specific version of node.
## Usage ## 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.
To download, compile, and install the latest v0.10.x release of node, do this: To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.10 nvm install 0.10
@@ -45,13 +48,9 @@ And then in any new shell just use the installed version:
nvm use 0.10 nvm use 0.10
You can create an `.nvmrc` file containing version number in the project root folder; run the following command to switch versions:
nvm use
Or you can just run it: Or you can just run it:
nvm run 0.10 nvm run 0.10 --version
If you want to see what versions are installed: If you want to see what versions are installed:
@@ -90,7 +89,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Running tests ## Running tests
Tests are written in [Urchin](https://github.com/scraperwiki/urchin). Install Urchin (and other dependencies) like so: Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install npm install
@@ -163,3 +162,8 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6 nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.6.1/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -45,7 +45,7 @@ install_from_git() {
install_as_script() { install_as_script() {
if [ -z "$NVM_SOURCE" ]; then if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh"
fi fi
# Downloading to $NVM_DIR # Downloading to $NVM_DIR

View File

@@ -4,12 +4,11 @@ DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/nvm.sh" source "$DIR/nvm.sh"
if [ ! "$NODE_VERSION" ]; then if [ -n "$NODE_VERSION" ]; then
echo 'NODE_VERSION not set' nvm use $NODE_VERSION || (echo "NODE_VERSION not set" && exit 127)
exit 1 else
nvm use || (echo "No .nvmrc file found" && exit 127)
fi fi
nvm use $NODE_VERSION
exec $@ exec $@

79
nvm.sh
View File

@@ -34,11 +34,30 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist" export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
fi fi
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path
path=$PWD
while [ "$path" != "" ] && [ ! -f "$path/$1" ]; do
path=${path%/*}
done
echo "$path"
}
nvm_find_nvmrc() {
local dir="$(nvm_find_up '.nvmrc')"
if [ -e "$dir/.nvmrc" ]; then
echo "$dir/.nvmrc"
fi
}
# Obtain nvm version from rc file # Obtain nvm version from rc file
nvm_rc_version() { nvm_rc_version() {
if [ -e .nvmrc ]; then local NVMRC_PATH="$(nvm_find_nvmrc)"
NVM_RC_VERSION=`cat .nvmrc | head -n 1` if [ -e "$NVMRC_PATH" ]; then
echo "Found .nvmrc files with version <$NVM_RC_VERSION>" NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
fi fi
} }
@@ -208,7 +227,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"
@@ -289,6 +308,11 @@ nvm() {
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return [ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
if [ "$VERSION" = "N/A" ]; then
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions."
return 3
fi
# skip binary install if no binary option specified. # skip binary install if no binary option specified.
if [ $nobinary -ne 1 ]; then if [ $nobinary -ne 1 ]; then
# shortcut - try the binary if possible. # shortcut - try the binary if possible.
@@ -422,7 +446,7 @@ nvm() {
"use" ) "use" )
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
nvm help nvm help
return return 127
fi fi
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
nvm_rc_version nvm_rc_version
@@ -434,7 +458,7 @@ nvm() {
fi fi
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
nvm help nvm help
return return 127
fi fi
if [ -z "$VERSION" ]; then if [ -z "$VERSION" ]; then
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
@@ -471,20 +495,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 127
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 +536,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`"
@@ -547,7 +588,7 @@ nvm() {
;; ;;
"unalias" ) "unalias" )
mkdir -p $NVM_DIR/alias mkdir -p $NVM_DIR/alias
[ $# -ne 2 ] && nvm help && return [ $# -ne 2 ] && nvm help && return 127
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" && return [ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" && return
rm -f $NVM_DIR/alias/$2 rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2" echo "Deleted alias $2"
@@ -555,7 +596,7 @@ nvm() {
"copy-packages" ) "copy-packages" )
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
nvm help nvm help
return return 127
fi fi
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)` local ROOT=`(nvm use $VERSION && npm -g root)`
@@ -575,7 +616,7 @@ nvm() {
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "nvm v0.4.0" echo "nvm v0.6.1"
;; ;;
* ) * )
nvm help nvm help

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.4.0", "version": "0.6.1",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"

View File

@@ -0,0 +1,7 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"

View File

@@ -4,21 +4,21 @@ set -e
. ../../../nvm.sh . ../../../nvm.sh
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
[ -e ../../../v0.10.7 ] && rm -R ../../../v0.10.7 [ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7
[ -e ../../../v0.10.8 ] && rm -R ../../../v0.10.8 [ -e ../../../v0.9.12 ] && rm -R ../../../v0.9.12
# Install from binary # Install from binary
nvm install 0.10.7 nvm install 0.9.7
nvm install 0.10.8 nvm install 0.9.12
# Check # Check
[ -d ../../../v0.10.7 ] [ -d ../../../v0.9.7 ]
[ -d ../../../v0.10.8 ] [ -d ../../../v0.9.12 ]
# Use the first one # Use the first one
nvm use 0.10.7 nvm use 0.9.7
# Use the latest one # Use the latest one
nvm use 0.10 nvm use 0.9
node --version | grep v0.10.8 node --version | grep v0.9.12

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,13 @@
#!/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 '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"

9
test/slow/nvm run/setup_dir Executable file
View File

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

11
test/slow/nvm run/teardown_dir Executable file
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