Compare commits

...

9 Commits

Author SHA1 Message Date
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
5 changed files with 64 additions and 42 deletions

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: To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh curl https://raw.githubusercontent.com/creationix/nvm/v0.9.0/install.sh | sh
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.9.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>
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> <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 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.8.0/install.sh [2]: https://github.com/creationix/nvm/blob/v0.9.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

View File

@@ -30,14 +30,14 @@ install_from_git() {
if [ -d "$NVM_DIR/.git" ]; then if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update" 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 || { cd "$NVM_DIR" && git pull 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
} }
else else
# Cloning to $NVM_DIR # Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'" echo "=> Downloading nvm from git to '$NVM_DIR'"
echo -e "\r=> \c" printf "\r=> "
mkdir -p "$NVM_DIR" mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR" git clone "$NVM_SOURCE" "$NVM_DIR"
fi fi
@@ -113,12 +113,12 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
fi fi
echo " OR" echo " OR"
echo "=> Append the following lines to the correct file yourself:" echo "=> Append the following lines to the correct file yourself:"
echo -e "$SOURCE_STR" printf "$SOURCE_STR"
echo echo
else else
if ! grep -qc 'nvm.sh' $PROFILE; then if ! grep -qc 'nvm.sh' $PROFILE; then
echo "=> Appending source string to $PROFILE" echo "=> Appending source string to $PROFILE"
echo -e "$SOURCE_STR" >> "$PROFILE" printf "$SOURCE_STR" >> "$PROFILE"
else else
echo "=> Source string already in $PROFILE" echo "=> Source string already in $PROFILE"
fi fi

86
nvm.sh
View File

@@ -46,7 +46,8 @@ nvm_find_up() {
nvm_find_nvmrc() { nvm_find_nvmrc() {
local dir="$(nvm_find_up '.nvmrc')" local dir
dir="$(nvm_find_up '.nvmrc')"
if [ -e "$dir/.nvmrc" ]; then if [ -e "$dir/.nvmrc" ]; then
echo "$dir/.nvmrc" echo "$dir/.nvmrc"
fi fi
@@ -54,7 +55,8 @@ nvm_find_nvmrc() {
# Obtain nvm version from rc file # Obtain nvm version from rc file
nvm_rc_version() { nvm_rc_version() {
local NVMRC_PATH="$(nvm_find_nvmrc)" local NVMRC_PATH
NVMRC_PATH="$(nvm_find_nvmrc)"
if [ -e "$NVMRC_PATH" ]; then if [ -e "$NVMRC_PATH" ]; then
NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1` NVM_RC_VERSION=`cat "$NVMRC_PATH" | head -n 1`
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>" echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
@@ -63,7 +65,8 @@ nvm_rc_version() {
# Expand a version using the version cache # Expand a version using the version cache
nvm_version() { nvm_version() {
local PATTERN=$1 local PATTERN
PATTERN=$1
local VERSION local VERSION
# The default version is the current one # The default version is the current one
if [ -z "$PATTERN" ]; then if [ -z "$PATTERN" ]; then
@@ -74,18 +77,19 @@ nvm_version() {
echo "$VERSION" echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then if [ "$VERSION" = 'N/A' ]; then
return return 3
fi fi
} }
nvm_remote_version() { nvm_remote_version() {
local PATTERN=$1 local PATTERN
PATTERN=$1
local VERSION local VERSION
VERSION=`nvm_ls_remote $PATTERN | tail -n1` VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION" echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then if [ "$VERSION" = 'N/A' ]; then
return return 3
fi fi
} }
@@ -111,14 +115,18 @@ nvm_prepend_path() {
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
local VERSION=$1 MINIMAL="0.8.6"
local VERSION
VERSION=$1
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ] [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
} }
nvm_ls() { nvm_ls() {
local PATTERN=$1 local PATTERN
local VERSIONS='' PATTERN=$1
local VERSIONS
VERSIONS=''
if [ "$PATTERN" = 'current' ]; then if [ "$PATTERN" = 'current' ]; then
echo `node -v 2>/dev/null` echo `node -v 2>/dev/null`
return return
@@ -139,16 +147,18 @@ nvm_ls() {
fi fi
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
echo "N/A" echo "N/A"
return return 3
fi fi
echo "$VERSIONS" echo "$VERSIONS"
return return
} }
nvm_ls_remote() { nvm_ls_remote() {
local PATTERN=$1 local PATTERN
PATTERN=$1
local VERSIONS local VERSIONS
local GREP_OPTIONS='' local GREP_OPTIONS
GREP_OPTIONS=''
if [ -n "$PATTERN" ]; then if [ -n "$PATTERN" ]; then
PATTERN=`nvm_format_version "$PATTERN"` PATTERN=`nvm_format_version "$PATTERN"`
else else
@@ -160,7 +170,7 @@ nvm_ls_remote() {
| 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`
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
echo "N/A" echo "N/A"
return return 3
fi fi
echo "$VERSIONS" echo "$VERSIONS"
return return
@@ -189,9 +199,10 @@ nvm_checksum() {
nvm_print_versions() { nvm_print_versions() {
local VERSION local VERSION
local FORMAT local FORMAT
local CURRENT=`nvm_version current` local NVM_CURRENT
NVM_CURRENT=`nvm_version current`
echo "$1" | while read VERSION; do echo "$1" | while read VERSION; do
if [ "$VERSION" = "$CURRENT" ]; then if [ "$VERSION" = "$NVM_CURRENT" ]; then
FORMAT='\033[0;32m-> %9s\033[0m' FORMAT='\033[0;32m-> %9s\033[0m'
elif [ -d "$NVM_DIR/$VERSION" ]; then elif [ -d "$NVM_DIR/$VERSION" ]; then
FORMAT='\033[0;34m%12s\033[0m' FORMAT='\033[0;34m%12s\033[0m'
@@ -209,10 +220,13 @@ nvm() {
fi fi
# Try to figure out the os and arch for binary fetching # Try to figure out the os and arch for binary fetching
local uname="$(uname -a)" local uname
local os= uname="$(uname -a)"
local arch="$(uname -m)" local os
local GREP_OPTIONS='' local arch
arch="$(uname -m)"
local GREP_OPTIONS
GREP_OPTIONS=''
case "$uname" in case "$uname" in
Linux\ *) os=linux ;; Linux\ *) os=linux ;;
Darwin\ *) os=darwin ;; Darwin\ *) os=darwin ;;
@@ -264,7 +278,7 @@ nvm() {
echo echo
;; ;;
"install" ) "install" | "i" )
# initialize local variables # initialize local variables
local binavail local binavail
local t local t
@@ -272,7 +286,8 @@ nvm() {
local sum local sum
local tarball local tarball
local nobinary local nobinary
local version_not_provided=0 local version_not_provided
version_not_provided=0
local provided_version local provided_version
if ! nvm_has "curl"; then if ! nvm_has "curl"; then
@@ -340,8 +355,10 @@ nvm() {
t="$VERSION-$os-$arch" t="$VERSION-$os-$arch"
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz" 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}'` 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 tmpdir
local tmptarball="$tmpdir/node-${t}.tar.gz" tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz"
if ( if (
mkdir -p "$tmpdir" && \ mkdir -p "$tmpdir" && \
curl -L -C - --progress-bar $url -o "$tmptarball" && \ curl -L -C - --progress-bar $url -o "$tmptarball" && \
@@ -352,7 +369,7 @@ nvm() {
) )
then then
nvm use $VERSION nvm use $VERSION
return; return $?
else else
echo "Binary download failed, trying source." >&2 echo "Binary download failed, trying source." >&2
rm -rf "$tmptarball" "$tmpdir" rm -rf "$tmptarball" "$tmpdir"
@@ -370,8 +387,10 @@ nvm() {
make='gmake' make='gmake'
MAKE_CXX="CXX=c++" MAKE_CXX="CXX=c++"
fi fi
local tmpdir="$NVM_DIR/src" local tmpdir
local tmptarball="$tmpdir/node-$VERSION.tar.gz" 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 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" 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}'` sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
@@ -511,7 +530,8 @@ nvm() {
;; ;;
"run" ) "run" )
local provided_version local provided_version
local has_checked_nvmrc=0 local has_checked_nvmrc
has_checked_nvmrc=0
# run given version of node # run given version of node
shift shift
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
@@ -543,7 +563,7 @@ nvm() {
if [ ! -d "$NVM_DIR/$VERSION" ]; then if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" >&2 echo "$VERSION version is not installed yet" >&2
return; return 1
fi fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"` 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"` RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
@@ -611,8 +631,10 @@ nvm() {
return 127 return 127
fi fi
VERSION=`nvm_version $2` VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)` local ROOT
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) 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 # declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS local INSTALLS
@@ -628,7 +650,7 @@ nvm() {
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.8.0" echo "0.9.0"
;; ;;
"unload" ) "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 -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.8.0", "version": "0.9.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

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