Compare commits

..

21 Commits

Author SHA1 Message Date
Jordan Harband
db8acf11fd v0.7.0 2014-05-08 10:30:52 -07:00
Jordan Harband
a6be718387 Fixing --version output format. 2014-05-08 10:30:34 -07:00
Jordan Harband
e2c4c88136 Updating example node versions. 2014-05-08 10:30:18 -07:00
Jordan Harband
4cd0b078d0 Merge pull request #415 from koenpunt/fix-path-concat
utility method for append path, fixes #414
2014-05-08 10:27:17 -07:00
Koen Punt
f6ba08253b utility method for append path, fixes #414 2014-05-08 10:20:11 +02:00
Jordan Harband
0ecb2879b9 Merge pull request #412 from koenpunt/fix-sed
Use sed -e instead of -E
2014-05-07 10:32:00 -07:00
Koen Punt
e3b84499c2 use regex triplet, add unit test 2014-05-07 10:58:21 +02:00
Koen Punt
b313f62749 Use sed -e instead of -E 2014-05-07 10:58:18 +02:00
Jordan Harband
7f3a794d89 Merge pull request #409 from koenpunt/sed-path-replacement
Use sed for *PATH stripping
2014-05-06 01:37:49 -07:00
Jordan Harband
ba1be9b4ea Making nvm install use the version, even if it's already installed. Fixes #410 2014-05-05 23:32:39 -07:00
Koen Punt
652a9ef9b5 always apply path stripping 2014-05-06 00:00:25 +02:00
Koen Punt
0d81a219ae add quotes 2014-05-05 22:05:02 +02:00
Koen Punt
d6e457354f use nvm_strip_path utility method for path stripping 2014-05-05 22:03:11 +02:00
Koen Punt
6668dc5c47 remove parentheses 2014-05-05 21:50:59 +02:00
Koen Punt
3d9c1d7852 use sed for *PATH stripping 2014-05-05 21:43:22 +02:00
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
8 changed files with 113 additions and 40 deletions

View File

@@ -8,11 +8,11 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
To install you could use the [install script][2] using cURL: To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.5.1/install.sh | sh curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.5.1/install.sh | sh wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.7.0/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:
@@ -133,17 +132,17 @@ nvm alias
default default
$ nvm alias my_alias [tab][tab] $ nvm alias my_alias [tab][tab]
v0.4.11 v0.4.12 v0.6.14 v0.6.21 v0.8.26 v0.10.28
nvm use nvm use
$ nvm use [tab][tab] $ nvm use [tab][tab]
my_alias default v0.4.11 v0.4.12 v0.6.14 my_alias default v0.6.21 v0.8.26 v0.10.28
nvm uninstall nvm uninstall
$ nvm uninstall [tab][tab] $ nvm uninstall [tab][tab]
my_alias default v0.4.11 v0.4.12 v0.6.14 my_alias default v0.6.21 v0.8.26 v0.10.28
## Problems ## Problems
@@ -164,7 +163,7 @@ 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 [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.5.1/install.sh [2]: https://github.com/creationix/nvm/blob/v0.7.0/install.sh
[3]: https://travis-ci.org/creationix/nvm [3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin [Urchin]: https://github.com/scraperwiki/urchin

66
nvm.sh
View File

@@ -97,6 +97,18 @@ nvm_format_version() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g' echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
} }
nvm_strip_path() {
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
}
nvm_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
nvm_binary_available() { nvm_binary_available() {
# binaries started with node 0.8.6 # binaries started with node 0.8.6
local MINIMAL="0.8.6" local MINIMAL="0.8.6"
@@ -306,7 +318,16 @@ nvm() {
shift shift
done done
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return if [ -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION is already installed."
nvm use "$VERSION"
return $?
fi
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
@@ -419,20 +440,20 @@ nvm() {
;; ;;
"deactivate" ) "deactivate" )
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:} export PATH=`nvm_strip_path "$PATH" "/bin"`
hash -r hash -r
echo "$NVM_DIR/*/bin removed from \$PATH" echo "$NVM_DIR/*/bin removed from \$PATH"
else else
echo "Could not find $NVM_DIR/*/bin in \$PATH" echo "Could not find $NVM_DIR/*/bin in \$PATH"
fi fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:} export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH" echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
fi fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then
export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:} export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
else else
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH"
@@ -462,25 +483,21 @@ nvm() {
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet"
return 1 return 1
fi fi
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin"` != 0 ]; then # Strip other version from PATH
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin} PATH=`nvm_strip_path "$PATH" "/bin"`
else # Prepend current version
PATH="$NVM_DIR/$VERSION/bin:$PATH" PATH=`nvm_prepend_path "$PATH" "$NVM_DIR/$VERSION/bin"`
fi
if [ -z "$MANPATH" ]; then if [ -z "$MANPATH" ]; then
MANPATH=$(manpath) MANPATH=$(manpath)
fi fi
MANPATH=${MANPATH#*$NVM_DIR/*/man:} # Strip other version from MANPATH
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man"` != 0 ]; then MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man} # Prepend current version
else MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_DIR/$VERSION/share/man"`
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" # Strip other version from NODE_PATH
fi NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then # Prepend current version
NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
else
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
export PATH export PATH
hash -r hash -r
export MANPATH export MANPATH
@@ -525,11 +542,8 @@ nvm() {
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet"
return; return;
fi fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
RUN_NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules} RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
else
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
echo "Running node $VERSION" echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@" NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;; ;;
@@ -611,7 +625,7 @@ nvm() {
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "nvm v0.5.1" echo "0.7.0"
;; ;;
* ) * )
nvm help nvm help

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.5.1", "version": "0.7.0",
"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

@@ -8,7 +8,7 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
nvm use v0.2.3 && nvm use v0.2.3 &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to activate v0.2.3" [ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` != 0 ] || die "Failed to activate v0.2.3"
nvm deactivate && nvm deactivate &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || die "Failed to deactivate v0.2.3" [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "Failed to deactivate v0.2.3"

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

@@ -0,0 +1,18 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
TEST_PATH=/usr/bin:/usr/local/bin
NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $STRIPPED_PATH "
EMPTY_PATH=
NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $STRIPPED_PATH "

View File

@@ -0,0 +1,11 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "

View File

@@ -0,0 +1,24 @@
#!/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"
# Remove the stuff we're clobbering.
[ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7
[ -e ../../../v0.9.12 ] && rm -R ../../../v0.9.12
# Install from binary
nvm install 0.9.7
nvm install 0.9.12
nvm use 0.9.7
node --version | grep v0.9.7 || die "precondition failed: node doesn't start at 0.9.7"
nvm install 0.9.12
node --version | grep v0.9.12 || die "nvm install on already installed version doesn't use it"