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:
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:
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>
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.8.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.9.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
@@ -113,12 +113,12 @@ if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
fi
echo " OR"
echo "=> Append the following lines to the correct file yourself:"
echo -e "$SOURCE_STR"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' $PROFILE; then
echo "=> Appending source string to $PROFILE"
echo -e "$SOURCE_STR" >> "$PROFILE"
printf "$SOURCE_STR" >> "$PROFILE"
else
echo "=> Source string already in $PROFILE"
fi

86
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
@@ -139,16 +147,18 @@ nvm_ls() {
fi
if [ -z "$VERSIONS" ]; then
echo "N/A"
return
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
@@ -160,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
@@ -189,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'
@@ -209,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 ;;
@@ -264,7 +278,7 @@ nvm() {
echo
;;
"install" )
"install" | "i" )
# initialize local variables
local binavail
local t
@@ -272,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
@@ -340,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" && \
@@ -352,7 +369,7 @@ nvm() {
)
then
nvm use $VERSION
return;
return $?
else
echo "Binary download failed, trying source." >&2
rm -rf "$tmptarball" "$tmpdir"
@@ -370,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}'`
@@ -511,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
@@ -543,7 +563,7 @@ nvm() {
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet" >&2
return;
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"`
@@ -611,8 +631,10 @@ nvm() {
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))
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
@@ -628,7 +650,7 @@ nvm() {
nvm_version $2
;;
"--version" )
echo "0.8.0"
echo "0.9.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

View File

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

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 ]