From 952096d034bfaec3db657132dee0b1cba73772f2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 13 Jan 2015 17:52:18 -0800 Subject: [PATCH] Add iojs support to "install" --- nvm.sh | 84 +++++++++++++++++-- .../io.js/install already installed uses it | 26 ++++++ test/installation/io.js/install from binary | 19 +++++ ...nstall two versions and use the latest one | 26 ++++++ ...ll version specified in .nvmrc from binary | 24 ++++++ .../io.js/install while reinstalling packages | 32 +++++++ test/installation/io.js/setup_dir | 6 ++ test/installation/io.js/teardown_dir | 14 ++++ .../node 0.6.21 should install 0.6.21-pre | 4 +- 9 files changed, 226 insertions(+), 9 deletions(-) create mode 100755 test/installation/io.js/install already installed uses it create mode 100755 test/installation/io.js/install from binary create mode 100755 test/installation/io.js/install two versions and use the latest one create mode 100755 test/installation/io.js/install version specified in .nvmrc from binary create mode 100755 test/installation/io.js/install while reinstalling packages create mode 100755 test/installation/io.js/setup_dir create mode 100755 test/installation/io.js/teardown_dir diff --git a/nvm.sh b/nvm.sh index faa840a..a64ae36 100644 --- a/nvm.sh +++ b/nvm.sh @@ -643,12 +643,68 @@ nvm_get_arch() { echo "$NVM_ARCH" } +nvm_install_iojs_binary() { + local PREFIXED_VERSION + PREFIXED_VERSION="$1" + local REINSTALL_PACKAGES_FROM + REINSTALL_PACKAGES_FROM="$2" + + if ! nvm_is_iojs_version "$PREFIXED_VERSION"; then + echo 'nvm_install_iojs_binary requires an iojs-prefixed version.' >&2 + return 10 + fi + + local VERSION + VERSION="$(nvm_strip_iojs_prefix "$PREFIXED_VERSION")" + local VERSION_PATH + VERSION_PATH="$(nvm_version_path "$PREFIXED_VERSION")" + local NVM_OS + NVM_OS="$(nvm_get_os)" + local t + local url + local sum + + if [ -n "$NVM_OS" ]; then + if nvm_binary_available "$VERSION"; then + t="$VERSION-$NVM_OS-$(nvm_get_arch)" + url="$NVM_IOJS_ORG_MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz" + sum="$(nvm_download -L -s $NVM_IOJS_ORG_MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')" + local tmpdir + tmpdir="$NVM_DIR/bin/iojs-${t}" + local tmptarball + tmptarball="$tmpdir/iojs-${t}.tar.gz" + if ( + command mkdir -p "$tmpdir" && \ + nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \ + echo "WARNING: checksums are currently disabled for io.js" >&2 && \ + # nvm_checksum "$tmptarball" $sum && \ + command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ + command rm -f "$tmptarball" && \ + command mkdir -p "$VERSION_PATH" && \ + command mv "$tmpdir"/* "$VERSION_PATH" + ); then + return 0 + else + echo "Binary download failed, trying source." >&2 + command rm -rf "$tmptarball" "$tmpdir" + return 1 + fi + fi + fi + return 2 +} + nvm_install_node_binary() { local VERSION VERSION="$1" local REINSTALL_PACKAGES_FROM REINSTALL_PACKAGES_FROM="$2" + if nvm_is_iojs_version "$PREFIXED_VERSION"; then + echo 'nvm_install_node_binary does not allow an iojs-prefixed version.' >&2 + return 10 + fi + local VERSION_PATH VERSION_PATH="$(nvm_version_path "$VERSION")" local NVM_OS @@ -672,9 +728,9 @@ nvm_install_node_binary() { nvm_checksum "$tmptarball" $sum && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command rm -f "$tmptarball" && \ - command mv "$tmpdir" "$VERSION_PATH" - ) - then + command mkdir -p "$VERSION_PATH" && \ + command mv "$tmpdir"/* "$VERSION_PATH" + ); then return 0 else echo "Binary download failed, trying source." >&2 @@ -900,7 +956,7 @@ nvm() { fi local NVM_IOJS - if nvm_is_iojs_version "$VERSION"; then + if nvm_is_iojs_version "$VERSION" || [ "_$VERSION" = "_$(nvm_iojs_prefix)" ]; then NVM_IOJS=true fi @@ -912,8 +968,16 @@ nvm() { nobinary=1 fi # skip binary install if "nobinary" option specified. - if [ $nobinary -ne 1 ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then - if nvm use "$VERSION" \ + if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then + local NVM_INSTALL_SUCCESS + if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then + NVM_INSTALL_SUCCESS=true + elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then + NVM_INSTALL_SUCCESS=true + fi + + if [ "$NVM_INSTALL_SUCCESS" = true ] \ + && nvm use "$VERSION" \ && [ ! -z "$REINSTALL_PACKAGES_FROM" ] \ && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" @@ -921,7 +985,13 @@ nvm() { return $? fi - nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS" + if [ "$NVM_IOJS" = true ]; then + # nvm_install_iojs_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS" + echo "Installing iojs from source is not currently supported" >&2 + return 105 + else + nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS" + fi ;; "uninstall" ) [ $# -ne 2 ] && nvm help && return diff --git a/test/installation/io.js/install already installed uses it b/test/installation/io.js/install already installed uses it new file mode 100755 index 0000000..07e5487 --- /dev/null +++ b/test/installation/io.js/install already installed uses it @@ -0,0 +1,26 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +[ "$(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 ../../../versions/io.js/v1.0.0 ] && rm -R ../../../versions/io.js/v1.0.0 +[ -e ../../../versions/io.js/v1.0.1 ] && rm -R ../../../versions/io.js/v1.0.1 + +# Install from binary +nvm install iojs-v1.0.0 +nvm install iojs-v1.0.1 + +nvm use iojs-v1.0.0 + +node --version | grep v1.0.0 || die "precondition failed: iojs node doesn't start at v1.0.0" +iojs --version | grep v1.0.0 || die "precondition failed: iojs binary doesn't start at v1.0.0" + +nvm install iojs-v1.0.1 + +node --version | grep v1.0.1 || die "nvm install on already installed version doesn't use it (node binary)" +iojs --version | grep v1.0.1 || die "nvm install on already installed version doesn't use it (iojs binary)" + diff --git a/test/installation/io.js/install from binary b/test/installation/io.js/install from binary new file mode 100755 index 0000000..12cf963 --- /dev/null +++ b/test/installation/io.js/install from binary @@ -0,0 +1,19 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +NVM_TEST_VERSION="v1.0.0" +NVM_PREFIXED_TEST_VERSION="iojs-$NVM_TEST_VERSION" + +# Remove the stuff we're clobbering. +[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION + +# Install from binary +nvm install $NVM_PREFIXED_TEST_VERSION || die "install $NVM_PREFIXED_TEST_VERSION failed" + +# Check +[ -d ../../../versions/io.js/$NVM_TEST_VERSION ] +nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" + diff --git a/test/installation/io.js/install two versions and use the latest one b/test/installation/io.js/install two versions and use the latest one new file mode 100755 index 0000000..7b60d74 --- /dev/null +++ b/test/installation/io.js/install two versions and use the latest one @@ -0,0 +1,26 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +# Remove the stuff we're clobbering. +[ -e ../../../versions/io.js/v1.0.0 ] && rm -R ../../../versions/io.js/v1.0.0 +[ -e ../../../versions/io.js/v1.0.1 ] && rm -R ../../../versions/io.js/v1.0.1 + +# Install from binary +nvm install iojs-v1.0.0 || die "'nvm install iojs-v1.0.0' failed" +nvm i iojs-v1.0.1 || die "'nvm i iojs-v1.0.1' failed" + +# Check +[ -d ../../../versions/io.js/v1.0.0 ] || die "iojs v1.0.0 didn't exist" +[ -d ../../../versions/io.js/v1.0.1 ] || die "iojs v1.0.1 didn't exist" + +# Use the first one +nvm use iojs-1.0.0 || die "'nvm use iojs-1.0.0' failed" + +# Use the latest one +nvm use iojs-1 || die "'nvm use iojs-1' failed" +[ "_$(node --version)" = "_v1.0.1" ] || die "'node --version' was not v1.0.1, got: $(node --version)" +[ "_$(iojs --version)" = "_v1.0.1" ] || die "'iojs --version' was not v1.0.1, got: $(iojs --version)" + diff --git a/test/installation/io.js/install version specified in .nvmrc from binary b/test/installation/io.js/install version specified in .nvmrc from binary new file mode 100755 index 0000000..dfab909 --- /dev/null +++ b/test/installation/io.js/install version specified in .nvmrc from binary @@ -0,0 +1,24 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +NVM_TEST_VERSION=v1.0.0 +NVM_PREFIXED_TEST_VERSION="iojs-$NVM_TEST_VERSION" +VERSION_PATH="../../../versions/io.js/$NVM_TEST_VERSION" + +# Remove the stuff we're clobbering. +[ -e $VERSION_PATH ] && rm -R $VERSION_PATH + +# Install from binary +echo "$NVM_PREFIXED_TEST_VERSION" > .nvmrc + +nvm install || die "'nvm install' failed" + +# Check +[ -d $VERSION_PATH ] || die "./$VERSION_PATH did not exist" +nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION \ + || "'nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" + + diff --git a/test/installation/io.js/install while reinstalling packages b/test/installation/io.js/install while reinstalling packages new file mode 100755 index 0000000..d7d4ee4 --- /dev/null +++ b/test/installation/io.js/install while reinstalling packages @@ -0,0 +1,32 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +# Remove the stuff we're clobbering. +[ -e ../../../versions/io.js/v1.0.0 ] && rm -R ../../../versions/io.js/v1.0.0 +[ -e ../../../versions/io.js/v1.0.1 ] && rm -R ../../../versions/io.js/v1.0.1 + +# Install from binary +nvm install iojs-v1.0.0 + +# Check +[ -d ../../../versions/io.js/v1.0.0 ] || die "nvm install iojs-v1.0.0 didn't install" + +node --version | grep v1.0.0 > /dev/null || die "nvm install didn't use iojs-v1.0.0" + +npm install -g is-nan@1.0.1 || die "npm install -g is-nan failed" +npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed" + +nvm ls iojs-1 | grep iojs-v1.0.0 > /dev/null || die "nvm ls iojs-1 didn't show iojs-v1.0.0" + +nvm install iojs-v1.0.1 --reinstall-packages-from=iojs-1.0.0 || die "nvm install iojs-v1.0.1 --reinstall-packages-from=iojs-1.0.0 failed" + +[ -d ../../../versions/io.js/v1.0.1 ] || die "nvm install iojs-v1.0.1 didn't install" + +nvm use iojs-1 +node --version | grep v1.0.1 > /dev/null || die "nvm use iojs-1 didn't use v1.0.1" + +npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed" + diff --git a/test/installation/io.js/setup_dir b/test/installation/io.js/setup_dir new file mode 100755 index 0000000..50dc4e4 --- /dev/null +++ b/test/installation/io.js/setup_dir @@ -0,0 +1,6 @@ +#!/bin/sh + +if [ -f ".nvmrc" ]; then + mv .nvmrc .nvmrc.bak +fi + diff --git a/test/installation/io.js/teardown_dir b/test/installation/io.js/teardown_dir new file mode 100755 index 0000000..a7e6f3e --- /dev/null +++ b/test/installation/io.js/teardown_dir @@ -0,0 +1,14 @@ +#!/bin/sh + +. ../../../nvm.sh +nvm deactivate +nvm uninstall iojs-v1.0.0 + +if [ -f ".nvmrc" ]; then + rm .nvmrc +fi + +if [ -f ".nvmrc.bak" ]; then + mv .nvmrc.bak .nvmrc +fi + diff --git a/test/slow/node 0.6.21 should install 0.6.21-pre b/test/slow/node 0.6.21 should install 0.6.21-pre index c579e16..93afff7 100755 --- a/test/slow/node 0.6.21 should install 0.6.21-pre +++ b/test/slow/node 0.6.21 should install 0.6.21-pre @@ -5,6 +5,6 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh nvm install 0.6.21 || die 'v0.6.21 installation failed' -[ "$(node -v)" = "v0.6.21-pre" ] || die "v0.6.21-pre not installed with v0.6.21, got $(node -v)" -[ "$(nvm current)" = "v0.6.21" ] || die "v0.6.21-pre not reported as v0.6.21, got $(nvm current)" +[ "_$(node -v)" = "_v0.6.21-pre" ] || die "v0.6.21-pre not installed with v0.6.21, got $(node -v)" +[ "_$(nvm current)" = "_v0.6.21" ] || die "v0.6.21-pre not reported as v0.6.21, got $(nvm current)"