Compare commits

..

13 Commits

Author SHA1 Message Date
Jordan Harband
96c96ec714 v0.25.2 2015-05-19 14:05:43 -07:00
Jordan Harband
475b8bd6b4 Update semver 2015-05-17 21:12:03 -07:00
Jordan Harband
5e805905ca Add undocumented nvm debug to print out helpful debugging info. 2015-05-14 14:56:26 -07:00
Jordan Harband
2dec01da9c nvm reinstall-packages: On systems where npm ls -g --depth=0 does not include npm for some reason, make sure to filter out (empty). 2015-05-08 14:24:51 -07:00
Jordan Harband
63672641a5 Add wrapping curly braces to ensure that the entire scripts are downloaded.
If the closing curly brace isn't present, the script will error out.
2015-05-11 01:46:18 -07:00
Jordan Harband
94bba31de3 Make sure that nvm reinstall-packages system has the right std output. 2015-05-08 14:15:42 -07:00
Jordan Harband
f70530ef18 Fix installation instructions. 2015-05-07 10:43:47 -07:00
Jordan Harband
ec33e8b720 v0.25.1 2015-05-03 15:31:54 -07:00
Jordan Harband
a4f89c6223 Make sure to ignore ~/.curlrc if it exists. 2015-05-01 02:00:49 -07:00
Jordan Harband
517817f1a3 Actually try to install from source when the error message says "binary failed, trying source". 2015-04-27 14:02:45 -07:00
Jordan Harband
a6f5eff0f3 Use uname -m instead of uname -a.
Fixes #744.
2015-04-28 22:56:43 -07:00
Jordan Harband
0aac462b15 Improve the error message when the binary tarball URL 404s.
Fixes #743
2015-04-27 13:48:22 -07:00
Jordan Harband
bb2fe618cb The install script only runs in bash. 2015-04-27 16:55:21 -07:00
7 changed files with 70 additions and 37 deletions

View File

@@ -10,11 +10,7 @@ install:
script: script:
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL
env: env:
- SHELL=sh TEST_SUITE=install_script
- SHELL=dash TEST_SUITE=install_script
- SHELL=bash TEST_SUITE=install_script - SHELL=bash TEST_SUITE=install_script
- SHELL=zsh TEST_SUITE=install_script
# - SHELL=ksh TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast - SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast - SHELL=bash TEST_SUITE=fast

View File

@@ -16,11 +16,11 @@ Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creati
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.25.0/install.sh | bash curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.0/install.sh | bash wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.2/install.sh | bash
<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>
@@ -220,7 +220,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.25.0/install.sh [2]: https://github.com/creationix/nvm/blob/v0.25.2/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
[Fish]: http://fishshell.com [Fish]: http://fishshell.com

View File

@@ -2,6 +2,8 @@
set -e set -e
{ # this ensures the entire script is downloaded #
nvm_has() { nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
@@ -11,7 +13,7 @@ if [ -z "$NVM_DIR" ]; then
fi fi
nvm_latest_version() { nvm_latest_version() {
echo "v0.25.0" echo "v0.25.2"
} }
# #
@@ -42,7 +44,7 @@ nvm_source() {
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl -q $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -241,3 +243,5 @@ nvm_reset() {
} }
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install [ "_$NVM_ENV" = "_testing" ] || nvm_do_install
} # this ensures the entire script is downloaded #

75
nvm.sh
View File

@@ -6,6 +6,8 @@
# Implemented by Tim Caswell <tim@creationix.com> # Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney # with much bash help from Matthew Ranney
{ # this ensures the entire script is downloaded #
NVM_SCRIPT_SOURCE="$_" NVM_SCRIPT_SOURCE="$_"
nvm_has() { nvm_has() {
@@ -20,7 +22,7 @@ nvm_is_alias() {
nvm_get_latest() { nvm_get_latest() {
local NVM_LATEST_URL local NVM_LATEST_URL
if nvm_has "curl"; then if nvm_has "curl"; then
NVM_LATEST_URL="$(curl -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)" NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')" NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else else
@@ -37,7 +39,7 @@ nvm_get_latest() {
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl -q $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -870,12 +872,12 @@ nvm_get_os() {
nvm_get_arch() { nvm_get_arch() {
local NVM_UNAME local NVM_UNAME
NVM_UNAME="$(uname -a)" NVM_UNAME="$(uname -m)"
local NVM_ARCH local NVM_ARCH
case "$NVM_UNAME" in case "$NVM_UNAME" in
*x86_64*) NVM_ARCH=x64 ;; x86_64) NVM_ARCH="x64" ;;
*i*86*) NVM_ARCH=x86 ;; i*86) NVM_ARCH="x86" ;;
*) NVM_ARCH="$(uname -m)" ;; *) NVM_ARCH="$NVM_UNAME" ;;
esac esac
echo "$NVM_ARCH" echo "$NVM_ARCH"
} }
@@ -929,9 +931,16 @@ nvm_install_iojs_binary() {
tmpdir="$NVM_DIR/bin/iojs-${t}" tmpdir="$NVM_DIR/bin/iojs-${t}"
local tmptarball local tmptarball
tmptarball="$tmpdir/iojs-${t}.tar.gz" tmptarball="$tmpdir/iojs-${t}.tar.gz"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if ( if (
command mkdir -p "$tmpdir" && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \ echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \ # nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
@@ -941,7 +950,7 @@ nvm_install_iojs_binary() {
); then ); then
return 0 return 0
else else
echo "Binary download failed, trying source." >&2 echo >&2 "Binary download failed, trying source." >&2
command rm -rf "$tmptarball" "$tmpdir" command rm -rf "$tmptarball" "$tmpdir"
return 1 return 1
fi fi
@@ -983,9 +992,16 @@ nvm_install_node_binary() {
tmpdir="$NVM_DIR/bin/node-${t}" tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz" tmptarball="$tmpdir/node-${t}.tar.gz"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if ( if (
command mkdir -p "$tmpdir" && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \ nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
@@ -994,7 +1010,7 @@ nvm_install_node_binary() {
); then ); then
return 0 return 0
else else
echo "Binary download failed, trying source." >&2 echo >&2 "Binary download failed, trying source."
command rm -rf "$tmptarball" "$tmpdir" command rm -rf "$tmptarball" "$tmpdir"
return 1 return 1
fi fi
@@ -1125,6 +1141,17 @@ nvm() {
echo echo
;; ;;
"debug" )
echo >&2 "\$SHELL: $SHELL"
echo >&2 "\$NVM_DIR: $(echo $NVM_DIR | sed "s#$HOME#\$HOME#g")"
for NVM_DEBUG_COMMAND in 'nvm current' 'which node' 'which iojs' 'which npm' 'npm config get prefix' 'npm root -g'
do
local NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND | sed "s#$NVM_DIR#\$NVM_DIR#g")"
echo >&2 "$NVM_DEBUG_COMMAND: ${NVM_DEBUG_OUTPUT}"
done
return 42
;;
"install" | "i" ) "install" | "i" )
local nobinary local nobinary
local version_not_provided local version_not_provided
@@ -1233,12 +1260,15 @@ nvm() {
elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
fi fi
elif [ "$NVM_IOJS" = true ]; then fi
# nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS" if [ "$NVM_INSTALL_SUCCESS" != true ]; then
echo "Installing iojs from source is not currently supported" >&2 if [ "$NVM_IOJS" = true ]; then
return 105 # nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS"
elif nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then echo "Installing iojs from source is not currently supported" >&2
NVM_INSTALL_SUCCESS=true return 105
elif nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true
fi
fi fi
if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then
@@ -1695,20 +1725,21 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
fi fi
local NPMLIST local NPMLIST
local VERSION
if [ "_$PROVIDED_VERSION" = "_system" ]; then if [ "_$PROVIDED_VERSION" = "_system" ]; then
if ! nvm_has_system_node && ! nvm_has_system_iojs; then if ! nvm_has_system_node && ! nvm_has_system_iojs; then
echo 'No system version of node or io.js detected.' >&2 echo 'No system version of node or io.js detected.' >&2
return 3 return 3
fi fi
VERSION="system"
NPMLIST=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2) NPMLIST=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2)
else else
local VERSION
VERSION="$(nvm_version "$PROVIDED_VERSION")" VERSION="$(nvm_version "$PROVIDED_VERSION")"
NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2) NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2)
fi fi
local INSTALLS local INSTALLS
INSTALLS=$(echo "$NPMLIST" | command sed -e '/ -> / d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | command xargs) INSTALLS=$(echo "$NPMLIST" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | command xargs)
echo "Copying global packages from $VERSION..." echo "Copying global packages from $VERSION..."
echo "$INSTALLS" | command xargs npm install -g --quiet echo "$INSTALLS" | command xargs npm install -g --quiet
@@ -1729,7 +1760,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.25.0" echo "0.25.2"
;; ;;
"unload" ) "unload" )
unset -f nvm nvm_print_versions nvm_checksum \ unset -f nvm nvm_print_versions nvm_checksum \
@@ -1765,3 +1796,5 @@ elif [ -n "$VERSION" ]; then
elif nvm_rc_version >/dev/null 2>&1; then elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null nvm use >/dev/null
fi fi
} # this ensures the entire script is downloaded #

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.25.0", "version": "0.25.2",
"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"
@@ -31,7 +31,7 @@
"homepage": "https://github.com/creationix/nvm", "homepage": "https://github.com/creationix/nvm",
"devDependencies": { "devDependencies": {
"replace": "^0.3.0", "replace": "^0.3.0",
"semver": "^4.3.3", "semver": "^4.3.4",
"urchin": "^0.0.5" "urchin": "^0.0.5"
} }
} }

View File

@@ -15,7 +15,7 @@ safe_type() {
safe_type nvm_reset || die 'nvm_reset is not available' safe_type nvm_reset || die 'nvm_reset is not available'
# Apply nvm_reset # Apply nvm_reset
nvm_reset nvm_reset || die 'nvm_reset failed'
# The names should be unset # The names should be unset
! safe_type nvm_do_install || die 'nvm_do_install is still available' ! safe_type nvm_do_install || die 'nvm_do_install is still available'

View File

@@ -10,12 +10,12 @@ cleanup() {
EXPECTED_VERSION="v12.3.456" EXPECTED_VERSION="v12.3.456"
URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION" URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION"
EXPECTED_CURL_ARGS="-w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null" EXPECTED_CURL_ARGS="-q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"
EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null" EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"
curl() { curl() {
if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_CURL_ARGS), got ($*)" echo >&2 "expected args ($EXPECTED_CURL_ARGS), got ($*)"
return 1 return 1
else else
echo $URL echo $URL
@@ -23,7 +23,7 @@ curl() {
} }
wget() { wget() {
if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)" echo >&2 "expected args ($EXPECTED_WGET_ARGS), got ($*)"
return 1 return 1
else else
local WGET_CONTENTS local WGET_CONTENTS
@@ -100,7 +100,7 @@ Saving to: /dev/null
" "
"$WGET_CONTENTS" | while read line "$WGET_CONTENTS" | while read line
do do
2>& echo "$line" >&2 echo "$line"
done done
fi fi
} }