Compare commits

...

41 Commits

Author SHA1 Message Date
Jordan Harband
3e5037a1be v0.10.0 2014-06-26 17:06:45 -07:00
Jordan Harband
60fec40613 Merge pull request #444 from creationix/fix_nvm_ls
Make sure `nvm ls foo` returns a nonzero exit code when a version is not found
2014-06-26 17:04:09 -07:00
Jordan Harband
fb215546ee Don't bother trying to return the exit code of nvm alias or nvm_print_versions 2014-06-26 16:52:48 -07:00
Jordan Harband
4b593bcda2 Make sure these vars are local, where supported 2014-06-26 16:52:34 -07:00
Jordan Harband
8349f0ff48 Make sure nvm ls foo returns a nonzero exit code when a version is not found.
Fixes #440.
2014-06-26 10:28:35 -07:00
Jordan Harband
bb250b5730 v0.9.0 2014-06-26 10:28:14 -07:00
Jordan Harband
b6f1c156da Use printf instead of echo -e
Fixes #446
2014-06-26 10:26:57 -07:00
Jordan Harband
4c9a36e9ad Separating variable declaration from first assignment, which should fix some ksh problems. 2014-06-22 15:44:22 -07:00
Jordan Harband
bb01513eba Making sure there's test coverage for nvm i 2014-06-22 09:18:41 -07:00
Jordan Harband
ba7f27dead Silently support nvm i x.x.x. Fixes #443. 2014-06-22 09:16:30 -07:00
Jordan Harband
79ec957ee7 Removing reference to NVM_PROFILE in README. Fixes #442 2014-06-21 17:47:02 -07:00
Jordan Harband
d8b55652a5 Return the exit code of nvm use when nvm install-ing. 2014-06-20 11:49:06 -07:00
Jordan Harband
4c38f507f5 Consistently returning exit code 1 when version is not installed yet. 2014-06-20 11:45:25 -07:00
Jordan Harband
f213167ef0 Returning exit code 3 when no version is found. 2014-06-20 11:45:14 -07:00
Jordan Harband
1da31aa425 v0.8.0 2014-06-20 11:35:18 -07:00
Jordan Harband
519a9481e6 Merge pull request #438 from koenpunt/patch-2
Suppress output of `nvm use`
2014-06-18 00:08:06 -07:00
Koen Punt
b16bf303ca Suppress output of nvm use
+redirect errors to stdout
2014-06-18 08:54:14 +02:00
Jordan Harband
9a28706688 Merge pull request #436 from koenpunt/stderr
redirect output of errors to stderr
2014-06-16 16:37:31 -07:00
Koen Punt
a318ddf9b3 redirect stderr to stdout in test 2014-06-17 01:22:17 +02:00
Koen Punt
8dbbc32905 redirect errors to stderr 2014-06-17 01:22:12 +02:00
Jordan Harband
de03007348 Merge pull request #432 from ajcrites/master
Only list extant explicit version
2014-06-12 11:55:56 -07:00
Andrew Crites
1b22c2e2b1 Including test for specific version listing
This fixes the issue of nvm ls v[:digit:].[:digit:].[:digit:] listing the version even if it isn't available
2014-06-12 14:01:26 -04:00
Andrew Crites
0e1f2408c9 Only list extant explicit version 2014-06-12 10:56:20 -04:00
Jordan Harband
931cc45fc3 Merge pull request #428 from koenpunt/export-nvm-dir-in-profile
export NVM_DIR in profile before sourcing nvm.sh
2014-05-29 16:04:25 -07:00
Jordan Harband
085e314a3f Adding a trailing newline 2014-05-28 20:54:25 -07:00
Jordan Harband
6aa45732d8 Merge pull request #376 from koenpunt/nvm-unload
Feature: nvm unload
2014-05-28 20:53:50 -07:00
Koen Punt
16c0be8314 export NVM_DIR before sourcing nvm.sh 2014-05-28 14:32:01 +02:00
Jordan Harband
578a601b27 Filter out of nvm ls things that start with a dot. Fixes #421, closes #422. 2014-05-20 10:36:12 -07:00
Jordan Harband
896aa7c436 Updating CONTRIBUTING guidelines
Fixes #425
2014-05-19 22:05:13 -07:00
Jordan Harband
2441b00262 Merge pull request #417 from koenpunt/travis_tweaks
Split tests by shell
2014-05-10 10:13:53 -07:00
Koen Punt
88595f09aa remove fast task 2014-05-10 19:03:50 +02:00
Koen Punt
5925bd5e37 make suite for shell task configurable 2014-05-10 18:59:34 +02:00
Koen Punt
24e22dd8bc no need for the extra task, every shell name is already a task 2014-05-10 12:27:11 +02:00
Koen Punt
61de5f9ca3 enable slow test suite for sh 2014-05-10 12:15:19 +02:00
Jordan Harband
4de9eff55c Merge pull request #416 from koenpunt/patch-2
Use correct variables
2014-05-09 10:49:43 -07:00
Koen Punt
7e20a77c89 pass env vars to makefile 2014-05-09 16:42:04 +02:00
Koen Punt
8fbbeb8fc5 ensure correct shell usage 2014-05-09 16:30:04 +02:00
Koen Punt
79203ba5d0 split tests by shell 2014-05-09 16:23:14 +02:00
Koen Punt
2e3e48cc06 Use correct variables 2014-05-09 15:36:44 +02:00
Koen Punt
703acb0514 Added test for nvm unload 2014-03-23 16:44:40 +01:00
Koen Punt
744507b83e added nvm unload method to remove nvm from shell 2014-03-23 16:44:37 +01:00
16 changed files with 174 additions and 100 deletions

View File

@@ -4,5 +4,11 @@ install:
before_script:
- curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin
script:
- NVM_DIR=$TRAVIS_BUILD_DIR make URCHIN=/tmp/urchin test
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL
env:
- SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast
- SHELL=zsh TEST_SUITE=fast
- SHELL=ksh TEST_SUITE=fast
- SHELL=sh TEST_SUITE=slow

View File

@@ -5,7 +5,7 @@ We love pull requests, they're our favorite.
However, before submitting, please review the following:
- Please include tests. Changes with tests will be merged very quickly.
- Please manually confirm that your changes, and all tests, pass in `bash`, `sh`, and `zsh`. We hope to soon automatically run all these tests, but in the meantime, we have to rely on each contributor doing so.
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
- Any time you make a change to your PR, please rebase freshly on top of master. Nobody likes merge commits.

View File

@@ -1,15 +1,14 @@
URCHIN=`which urchin`
SHELLS=sh bash dash ksh zsh
TEST_SUITE=fast
.PHONY: $(SHELLS) test
fast: $(SHELLS)
$(SHELLS):
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
@$@ $(URCHIN) -f test/fast
@$@ $(URCHIN) -f test/$(TEST_SUITE)
test: fast
test: $(SHELLS)
@$(URCHIN) -f test/slow
default: test

View File

@@ -8,15 +8,15 @@ 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:
curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | sh
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.10.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>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `NVM_PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
<sub>*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.*</sub>
@@ -163,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
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.7.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.10.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -30,14 +30,14 @@ install_from_git() {
if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update"
echo -e "\r=> \c"
printf "\r=> "
cd "$NVM_DIR" && git pull 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
}
else
# Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'"
echo -e "\r=> \c"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
fi
@@ -101,7 +101,7 @@ if [ -z "$PROFILE" ]; then
fi
fi
SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm"
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z $PROFILE ]; then
@@ -112,15 +112,13 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
echo "=> Create it (touch $PROFILE) and run this script again"
fi
echo " OR"
echo "=> Append the following line to the correct file yourself:"
echo
echo " $SOURCE_STR"
echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' $PROFILE; then
echo "=> Appending source string to $PROFILE"
echo "" >> "$PROFILE"
echo $SOURCE_STR >> "$PROFILE"
printf "$SOURCE_STR" >> "$PROFILE"
else
echo "=> Source string already in $PROFILE"
fi

View File

@@ -5,9 +5,9 @@ DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/nvm.sh"
if [ -n "$NODE_VERSION" ]; then
nvm use $NODE_VERSION || (echo "NODE_VERSION not set" && exit 127)
nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)
else
nvm use || (echo "No .nvmrc file found" && exit 127)
nvm use > /dev/null || (echo "No .nvmrc file found" >&2 && exit 127)
fi
exec $@

179
nvm.sh
View File

@@ -46,7 +46,8 @@ nvm_find_up() {
nvm_find_nvmrc() {
local dir="$(nvm_find_up '.nvmrc')"
local dir
dir="$(nvm_find_up '.nvmrc')"
if [ -e "$dir/.nvmrc" ]; then
echo "$dir/.nvmrc"
fi
@@ -54,7 +55,8 @@ nvm_find_nvmrc() {
# Obtain nvm version from rc file
nvm_rc_version() {
local NVMRC_PATH="$(nvm_find_nvmrc)"
local NVMRC_PATH
NVMRC_PATH="$(nvm_find_nvmrc)"
if [ -e "$NVMRC_PATH" ]; then
NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
@@ -63,7 +65,8 @@ nvm_rc_version() {
# Expand a version using the version cache
nvm_version() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSION
# The default version is the current one
if [ -z "$PATTERN" ]; then
@@ -74,18 +77,19 @@ nvm_version() {
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
return
return 3
fi
}
nvm_remote_version() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSION
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
return
return 3
fi
}
@@ -111,14 +115,18 @@ nvm_prepend_path() {
nvm_binary_available() {
# binaries started with node 0.8.6
local MINIMAL="0.8.6"
local VERSION=$1
local MINIMAL
MINIMAL="0.8.6"
local VERSION
VERSION=$1
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
}
nvm_ls() {
local PATTERN=$1
local VERSIONS=''
local PATTERN
PATTERN=$1
local VERSIONS
VERSIONS=''
if [ "$PATTERN" = 'current' ]; then
echo `node -v 2>/dev/null`
return
@@ -130,23 +138,27 @@ nvm_ls() {
fi
# If it looks like an explicit version, don't do anything funny
if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
VERSIONS="$PATTERN"
if [ -d "$NVM_DIR/$PATTERN" ]; then
VERSIONS="$PATTERN"
fi
else
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | grep -v '^ *\.'`
fi
if [ -z "$VERSIONS" ]; then
echo "N/A"
return
echo "N/A"
return 3
fi
echo "$VERSIONS"
return
}
nvm_ls_remote() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSIONS
local GREP_OPTIONS=''
local GREP_OPTIONS
GREP_OPTIONS=''
if [ -n "$PATTERN" ]; then
PATTERN=`nvm_format_version "$PATTERN"`
else
@@ -158,7 +170,7 @@ nvm_ls_remote() {
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
if [ -z "$VERSIONS" ]; then
echo "N/A"
return
return 3
fi
echo "$VERSIONS"
return
@@ -179,7 +191,7 @@ nvm_checksum() {
echo 'Checksums empty' #missing in raspberry pi binary
return
else
echo 'Checksums do not match.'
echo 'Checksums do not match.' >&2
return 1
fi
}
@@ -187,9 +199,10 @@ nvm_checksum() {
nvm_print_versions() {
local VERSION
local FORMAT
local CURRENT=`nvm_version current`
local NVM_CURRENT
NVM_CURRENT=`nvm_version current`
echo "$1" | while read VERSION; do
if [ "$VERSION" = "$CURRENT" ]; then
if [ "$VERSION" = "$NVM_CURRENT" ]; then
FORMAT='\033[0;32m-> %9s\033[0m'
elif [ -d "$NVM_DIR/$VERSION" ]; then
FORMAT='\033[0;34m%12s\033[0m'
@@ -207,10 +220,13 @@ nvm() {
fi
# Try to figure out the os and arch for binary fetching
local uname="$(uname -a)"
local os=
local arch="$(uname -m)"
local GREP_OPTIONS=''
local uname
uname="$(uname -a)"
local os
local arch
arch="$(uname -m)"
local GREP_OPTIONS
GREP_OPTIONS=''
case "$uname" in
Linux\ *) os=linux ;;
Darwin\ *) os=darwin ;;
@@ -249,6 +265,7 @@ nvm() {
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
echo " nvm unalias <name> Deletes the alias named <name>"
echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version"
echo " nvm unload Unload NVM from shell"
echo
echo "Example:"
echo " nvm install v0.10.24 Install a specific version number"
@@ -261,7 +278,7 @@ nvm() {
echo
;;
"install" )
"install" | "i" )
# initialize local variables
local binavail
local t
@@ -269,7 +286,8 @@ nvm() {
local sum
local tarball
local nobinary
local version_not_provided=0
local version_not_provided
version_not_provided=0
local provided_version
if ! nvm_has "curl"; then
@@ -305,7 +323,7 @@ nvm() {
fi
provided_version="$NVM_RC_VERSION"
fi
[ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." && return
[ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." >&2 && return
VERSION=`nvm_remote_version $provided_version`
ADDITIONAL_PARAMETERS=''
@@ -319,13 +337,13 @@ nvm() {
done
if [ -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION is already installed."
echo "$VERSION is already installed." >&2
nvm use "$VERSION"
return $?
fi
if [ "$VERSION" = "N/A" ]; then
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions."
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2
return 3
fi
@@ -337,8 +355,10 @@ nvm() {
t="$VERSION-$os-$arch"
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
local tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball="$tmpdir/node-${t}.tar.gz"
local tmpdir
tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz"
if (
mkdir -p "$tmpdir" && \
curl -L -C - --progress-bar $url -o "$tmptarball" && \
@@ -349,7 +369,7 @@ nvm() {
)
then
nvm use $VERSION
return;
return $?
else
echo "Binary download failed, trying source." >&2
rm -rf "$tmptarball" "$tmpdir"
@@ -367,8 +387,10 @@ nvm() {
make='gmake'
MAKE_CXX="CXX=c++"
fi
local tmpdir="$NVM_DIR/src"
local tmptarball="$tmpdir/node-$VERSION.tar.gz"
local tmpdir
tmpdir="$NVM_DIR/src"
local tmptarball
tmptarball="$tmpdir/node-$VERSION.tar.gz"
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
@@ -392,10 +414,10 @@ nvm() {
if ! nvm_has "npm" ; then
echo "Installing npm..."
if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher"
echo "npm requires node v0.2.3 or higher" >&2
elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher"
echo "npm requires node v0.2.3 or higher" >&2
else
curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
fi
@@ -404,7 +426,7 @@ nvm() {
fi
fi
else
echo "nvm: install $VERSION failed!"
echo "nvm: install $VERSION failed!" >&2
return 1
fi
;;
@@ -412,12 +434,12 @@ nvm() {
[ $# -ne 2 ] && nvm help && return
PATTERN=`nvm_format_version $2`
if [ "$PATTERN" = `nvm_version` ]; then
echo "nvm: Cannot uninstall currently-active node version, $PATTERN."
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
return 1
fi
VERSION=`nvm_version $PATTERN`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed..."
echo "$VERSION version is not installed..." >&2
return;
fi
@@ -444,19 +466,19 @@ nvm() {
hash -r
echo "$NVM_DIR/*/bin removed from \$PATH"
else
echo "Could not find $NVM_DIR/*/bin in \$PATH"
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then
export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
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" >&2
fi
;;
"use" )
@@ -467,7 +489,7 @@ nvm() {
if [ $# -eq 1 ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION`
VERSION=`nvm_version $NVM_RC_VERSION`
fi
else
VERSION=`nvm_version $2`
@@ -480,7 +502,7 @@ nvm() {
VERSION=`nvm_version $2`
fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet"
echo "$VERSION version is not installed yet" >&2
return 1
fi
# Strip other version from PATH
@@ -508,7 +530,8 @@ nvm() {
;;
"run" )
local provided_version
local has_checked_nvmrc=0
local has_checked_nvmrc
has_checked_nvmrc=0
# run given version of node
shift
if [ $# -lt 1 ]; then
@@ -539,8 +562,8 @@ nvm() {
fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet"
return;
echo "$VERSION version is not installed yet" >&2
return 1
fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
@@ -548,15 +571,19 @@ nvm() {
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;;
"ls" | "list" )
nvm_print_versions "`nvm_ls $2`"
local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "$2")
NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT"
if [ $# -eq 1 ]; then
nvm alias
fi
return
return $NVM_LS_EXIT_CODE
;;
"ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`"
return
nvm_print_versions "`nvm_ls_remote $2`"
return
;;
"current" )
nvm_version current
@@ -570,18 +597,18 @@ nvm() {
DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then
echo "$(basename $ALIAS) -> $DEST"
echo "$(basename $ALIAS) -> $DEST"
else
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
fi
fi
done
return
fi
if [ -z "$3" ]; then
rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*"
return
rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*"
return
fi
mkdir -p $NVM_DIR/alias
VERSION=`nvm_version $3`
@@ -590,7 +617,7 @@ nvm() {
fi
echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)"
echo "$2 -> $3 (-> $VERSION)"
else
echo "$2 -> $3"
fi
@@ -598,34 +625,40 @@ nvm() {
"unalias" )
mkdir -p $NVM_DIR/alias
[ $# -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!" >&2 && return
rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2"
;;
"copy-packages" )
if [ $# -ne 2 ]; then
nvm help
return 127
fi
VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
if [ $# -ne 2 ]; then
nvm help
return 127
fi
VERSION=`nvm_version $2`
local ROOT
ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH
ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
# declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
# declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
npm install -g ${INSTALLS[@]}
npm install -g ${INSTALLS[@]}
;;
"clear-cache" )
rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared."
rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared."
;;
"version" )
nvm_version $2
nvm_version $2
;;
"--version" )
echo "0.7.0"
echo "0.10.0"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
nvm help

View File

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

View File

@@ -0,0 +1,9 @@
#!/bin/sh
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
. ../../../nvm.sh
[ -z `nvm ls | grep '^ *\.'` ]
# The result should contain only the appropriate version numbers.

View File

@@ -0,0 +1,10 @@
#!/bin/sh
mkdir ../../../v0.1.2
. ../../../nvm.sh
nvm ls v0.1 | grep v0.1.2 &&
nvm ls v0.1.2 | grep v0.1.2 &&
nvm ls v0.1. | grep N/A &&
nvm ls v0.1.1 | grep N/A

View File

@@ -3,5 +3,5 @@
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"
[ "$(nvm install invalid.invalid 2>&1)" = "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,7 @@
#!/bin/sh
. ../../nvm.sh
nvm ls nonexistent_version
[ "$?" = "3" ]

View File

@@ -0,0 +1,12 @@
#!/bin/sh
fail () { echo $@ ; exit 1; }
. ../../nvm.sh
type nvm > /dev/null 2>&1 || fail "NVM not loaded"
nvm unload
type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0

View File

@@ -8,11 +8,11 @@ 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 "
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_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 "
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH "

View File

@@ -4,7 +4,7 @@ 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"
[ "$(nvm install invalid.invalid 2>&1)" = "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

View File

@@ -9,7 +9,7 @@ set -e
# Install from binary
nvm install 0.9.7
nvm install 0.9.12
nvm i 0.9.12
# Check
[ -d ../../../v0.9.7 ]