Compare commits

...

48 Commits

Author SHA1 Message Date
Jordan Harband
e1c84bae37 v0.29.0 2015-10-09 01:52:19 -07:00
Jordan Harband
a928a8f181 nvm exec: don't fall back to .nvmrc when the provided version is not installed. 2015-10-08 17:37:53 -07:00
Jordan Harband
937c29c95a nvm run: use common code path for "ensure version installed"
Better than cb033adc6f
2015-10-08 16:48:17 -07:00
Jordan Harband
a0e94e16de Make sure nvm debug doesn't use an overridden sed 2015-10-08 00:19:53 -07:00
Jordan Harband
7028e5df19 Merge pull request #823 from jbergstroem/feature/prefer-xz
Support `xz` tarballs if available (on io.js >= 2.3.2 and node >= 4)
2015-10-08 00:19:35 -07:00
Johan Bergström
b8e4917646 Use xz tarballs if available
Saves us ~25% bandwidth while downloading the payload. This only applies
to hosts that has the `xz` binary and attempts to use iojs 2.3.2 or newer
(this includes nodejs 4.0+ as well). Older targets are unaffected.
2015-10-08 16:45:26 +11:00
Jordan Harband
cb033adc6f nvm run: use common code path for "ensure version installed" 2015-10-07 18:08:48 -07:00
Jordan Harband
20f4acdd25 [installing] echo the URL that the tarball is being downloaded from. 2015-10-07 20:28:18 -07:00
Jordan Harband
41153e207d Ensure nvm use output shows up *after* prefix check passes. 2015-10-07 14:40:31 -07:00
Jordan Harband
6b3c34313c Fix nvm_ls when $NVM_DIR has spaces in it.
Mostly fixes #861.
2015-10-07 13:57:29 -07:00
Jordan Harband
8541e2e1ee Properly quote some possible variables with spaces. 2015-10-07 13:57:13 -07:00
Jordan Harband
1efc8b4dbe Merge pull request #859 from fresheneesz/patch-1
[docs] Make sure to note "Install OR update"
2015-10-05 16:01:58 -07:00
fresheneesz
49f2c95013 Install OR update 2015-10-05 15:56:41 -07:00
Jordan Harband
06a21284ed Protect against cat clobbering. Fixes #858. 2015-10-04 14:28:38 -07:00
Jordan Harband
ebdcdc4363 v0.28.0 2015-10-02 01:50:44 -07:00
Jordan Harband
b805de80cb Add PREFIX and NPM_CONFIG_PREFIX env vars to nvm debug 2015-10-01 10:05:13 -07:00
Jordan Harband
44f416d58f Create and use nvm_sanitize_path for nvm debug 2015-10-01 09:41:34 -07:00
Jordan Harband
3d1ccfec70 Sort nvm ls results by semver version, so the order goes: "unmerged node", "iojs", "merged node". 2015-09-30 22:05:18 -07:00
Jordan Harband
f73ee40dfe Merge pull request #854 from misterdjules/fix-node-smartos-support
Fix support for installing node on SmartOS
2015-10-01 00:04:13 -07:00
Julien Gilli
2d692d9d78 Fix support for installing node on SmartOS
uname on SmartOS cannot be used to guess if 32 and/or 64 bits binaries
are supported, and its output is different than other uname commands on
other operating systems.

This change uses pkg_info to determine what types of binaries pkgsrc
would install. If pkg_info fails to run or is not present, this change
falls back to using isainfo -n, which determines what the kernel
supports.

It allows users to install node binaries on Solaris derivatives. io.js
can also be installed on Solaris derivatives starting with version
v3.3.1.
2015-09-30 22:10:29 -07:00
Jordan Harband
8aebf86329 v0.27.1 2015-09-27 06:40:29 -07:00
Jordan Harband
39dad845cf Do not exit install.sh on errors (revert part of 0787a559). Fixes #853. 2015-09-27 06:32:00 -07:00
Jordan Harband
838d72688f v0.27.0 2015-09-26 10:13:10 -07:00
Jordan Harband
8ee6f30352 Add support for $NPM_CONFIG_PREFIX to nvm_die_on_prefix.
Fixes #606.
2015-09-23 06:25:55 -07:00
Jordan Harband
1458de7293 Ensure that if npm config get prefix is set to something outside nvm, that nvm use refuses to work.
Fixes #606.
2015-09-21 04:47:37 -07:00
Jordan Harband
a1def71062 Add nvm_die_on_prefix 2015-09-21 04:47:30 -07:00
Jordan Harband
eb81fba8f7 Add support for --silent to nvm run and nvm exec.
Fixes #842.
2015-09-23 05:16:45 -07:00
Jordan Harband
7496a24bd6 Print the npm version when using nvm exec or nvm run. 2015-09-23 05:02:41 -07:00
Jordan Harband
c64a0343af [Docs] Add nvm help documentation for nvm exec 2015-09-23 04:51:55 -07:00
Jordan Harband
643365a948 Allow --silent option to nvm use to be in any position. 2015-09-23 04:51:55 -07:00
Jordan Harband
6e894520ec Use a tighter grep to avoid dnvm.sh conflicts.
Fixes #838.
2015-09-19 22:55:19 +09:00
Jordan Harband
9e389eb9fe Attempt to fix #829. 2015-09-19 13:37:08 +09:00
Jordan Harband
151efc32f5 Merge pull request #827 from lukechilds/master
Revert "Source the nvm.sh file"
2015-09-13 23:57:45 +09:00
Luke Childs
bda1d2ec29 Revert "Source the nvm.sh file"
Fixes #826
This reverts commit b4151e1446.
2015-09-12 23:05:56 +01:00
Jordan Harband
e3528b0d9e Fix nvm_ensure_version_installed iojs to not print an empty string for the version. 2015-09-11 10:42:47 +09:00
Jordan Harband
014a44e154 Minor refactoring to "install from source" logic tree. 2015-09-10 22:37:50 +09:00
Jordan Harband
c9215a127f When no io.js versions are installed, show N/A, not io.js-, as the resolved default alias.
Fixes #822.
2015-09-09 22:37:32 +09:00
Jordan Harband
c92effc6da Don't double-print *default* alias resolutions either. 2015-09-09 22:38:54 +09:00
Jordan Harband
1e2a7a8de4 Sort nvm ls-remote output so the order is: "pre-merged", "iojs", "post-merged". 2015-09-09 22:23:22 +09:00
Jordan Harband
d4caf9fb67 Fix some logic errors in the new "merged node" code path. 2015-09-09 09:46:39 +09:00
Jordan Harband
0ef20199dc Use NVM_VERSION instead of VERSION to be a bit less intrusive.
Fixes #820.
2015-09-07 21:43:21 +09:00
Jordan Harband
0d898b0aa4 When node version is not io.js and is v1.0 or later, on nvm install, run nvm_install_merged_node_binary 2015-08-28 00:51:19 -07:00
Jordan Harband
0181821b51 Add nvm_install_merged_node_binary 2015-08-28 00:51:19 -07:00
Jordan Harband
f34fef96d8 Add nvm_is_merged_node_version 2015-08-28 00:51:18 -07:00
Jordan Harband
26ee4aafc0 v0.26.1 2015-08-22 20:54:31 -07:00
Jordan Harband
8746d63041 Ensure after node v4.0 is released, stable will simply refer to the latest node. 2015-08-22 09:45:49 -07:00
Jordan Harband
b7e2d7d24d Oops, the string passed to awk isn't the same as a shell command.
Fixes #808.
2015-08-16 18:08:50 -07:00
Jordan Harband
58ffa407c2 Prefixing more commands with command to bypass aliases.
Related to #805 and #804.
2015-08-15 23:56:32 -07:00
27 changed files with 832 additions and 115 deletions

View File

@@ -13,13 +13,13 @@ Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creati
### Install script
To install you could use the [install script][2] using cURL:
To install or update nvm, you can use the [install script][2] using cURL:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.26.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/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>
@@ -236,7 +236,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.26.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.29.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com

View File

@@ -1,7 +1,5 @@
#!/bin/bash
set -e
{ # this ensures the entire script is downloaded #
nvm_has() {
@@ -13,7 +11,7 @@ if [ -z "$NVM_DIR" ]; then
fi
nvm_latest_version() {
echo "v0.26.0"
echo "v0.29.0"
}
#
@@ -240,7 +238,7 @@ nvm_do_install() {
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' "$NVM_PROFILE"; then
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
echo "=> Appending source string to $NVM_PROFILE"
printf "$SOURCE_STR\n" >> "$NVM_PROFILE"
else
@@ -250,8 +248,7 @@ nvm_do_install() {
nvm_check_global_modules
. $NVM_DIR/nvm.sh
echo "=> You can now start using nvm"
echo "=> Close and reopen your terminal to start using nvm"
nvm_reset
}

468
nvm.sh
View File

@@ -24,7 +24,7 @@ nvm_get_latest() {
if nvm_has "curl"; then
NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
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 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
>&2 echo 'nvm needs curl or wget to proceed.'
return 1
@@ -33,7 +33,7 @@ nvm_get_latest() {
>&2 echo "http://latest.nvm.sh did not redirect to the latest release on Github"
return 2
else
echo "$NVM_LATEST_URL" | awk -F'/' '{print $NF}'
echo "$NVM_LATEST_URL" | command awk -F'/' '{print $NF}'
fi
}
@@ -78,7 +78,7 @@ if [ -z "$NVM_DIR" ]; then
if [ -n "$BASH_SOURCE" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
fi
export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname "${NVM_SCRIPT_SOURCE:-$0}") > /dev/null && \pwd)
export NVM_DIR="$(cd $NVM_CD_FLAGS $(dirname "${NVM_SCRIPT_SOURCE:-$0}") > /dev/null && \pwd)"
fi
unset NVM_SCRIPT_SOURCE 2> /dev/null
@@ -210,7 +210,9 @@ nvm_ensure_version_installed() {
if [ $? -eq 0 ]; then
echo "N/A: version \"$PROVIDED_VERSION -> $VERSION\" is not yet installed" >&2
else
echo "N/A: version \"$(nvm_ensure_version_prefix "$PROVIDED_VERSION")\" is not yet installed" >&2
local PREFIXED_VERSION
PREFIXED_VERSION="$(nvm_ensure_version_prefix "$PROVIDED_VERSION")"
echo "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed" >&2
fi
return 1
fi
@@ -219,7 +221,7 @@ nvm_ensure_version_installed() {
# Expand a version using the version cache
nvm_version() {
local PATTERN
PATTERN=$1
PATTERN="$1"
local VERSION
# The default version is the current one
if [ -z "$PATTERN" ]; then
@@ -238,7 +240,7 @@ nvm_version() {
PATTERN="stable"
;;
esac
VERSION="$(nvm_ls "$PATTERN" | tail -n1)"
VERSION="$(nvm_ls "$PATTERN" | command tail -n1)"
if [ -z "$VERSION" ] || [ "_$VERSION" = "_N/A" ]; then
echo "N/A"
return 3;
@@ -254,14 +256,14 @@ nvm_remote_version() {
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
case "_$PATTERN" in
"_$(nvm_iojs_prefix)")
VERSION="$(nvm_ls_remote_iojs | tail -n1)"
VERSION="$(nvm_ls_remote_iojs | command tail -n1)"
;;
*)
VERSION="$(nvm_ls_remote "$PATTERN")"
;;
esac
else
VERSION="$(nvm_remote_versions "$PATTERN" | tail -n1)"
VERSION="$(nvm_remote_versions "$PATTERN" | command tail -n1)"
fi
echo "$VERSION"
if [ "_$VERSION" = '_N/A' ]; then
@@ -396,7 +398,7 @@ nvm_alias() {
return 2
fi
cat "$NVM_ALIAS_PATH"
command cat "$NVM_ALIAS_PATH"
}
nvm_ls_current() {
@@ -441,7 +443,7 @@ nvm_resolve_alias() {
fi
if [ -n "$ALIAS_TEMP" ] \
&& printf "$SEEN_ALIASES" | command grep -e "^$ALIAS_TEMP$" > /dev/null; then
&& command printf "$SEEN_ALIASES" | command grep -e "^$ALIAS_TEMP$" > /dev/null; then
ALIAS="∞"
break
fi
@@ -556,6 +558,9 @@ nvm_ls() {
PATTERN=$(nvm_ensure_version_prefix $PATTERN)
;;
esac
if [ "_$PATTERN" = "_N/A" ]; then
return
fi
# If it looks like an explicit version, don't do anything funny
local NVM_PATTERN_STARTS_WITH_V
case $PATTERN in
@@ -587,39 +592,51 @@ nvm_ls() {
setopt shwordsplit
fi
local NVM_DIRS_TO_TEST_AND_SEARCH
local NVM_DIRS_TO_SEARCH
local NVM_DIRS_TO_SEARCH1
NVM_DIRS_TO_SEARCH1=''
local NVM_DIRS_TO_SEARCH2
NVM_DIRS_TO_SEARCH2=''
local NVM_DIRS_TO_SEARCH3
NVM_DIRS_TO_SEARCH3=''
local NVM_ADD_SYSTEM
NVM_ADD_SYSTEM=false
if nvm_is_iojs_version "$PATTERN"; then
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_IOJS"
NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_IOJS"
PATTERN="$(nvm_strip_iojs_prefix "$PATTERN")"
if nvm_has_system_iojs; then
NVM_ADD_SYSTEM=true
fi
elif [ "_$PATTERN" = "_$NVM_NODE_PREFIX-" ]; then
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_OLD $NVM_VERSION_DIR_NEW"
NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_OLD"
NVM_DIRS_TO_SEARCH2="$NVM_VERSION_DIR_NEW"
PATTERN=''
if nvm_has_system_node; then
NVM_ADD_SYSTEM=true
fi
else
NVM_DIRS_TO_TEST_AND_SEARCH="$NVM_VERSION_DIR_OLD $NVM_VERSION_DIR_NEW $NVM_VERSION_DIR_IOJS"
NVM_DIRS_TO_SEARCH1="$NVM_VERSION_DIR_OLD"
NVM_DIRS_TO_SEARCH2="$NVM_VERSION_DIR_NEW"
NVM_DIRS_TO_SEARCH3="$NVM_VERSION_DIR_IOJS"
if nvm_has_system_iojs || nvm_has_system_node; then
NVM_ADD_SYSTEM=true
fi
fi
for NVM_VERSION_DIR in $NVM_DIRS_TO_TEST_AND_SEARCH; do
if [ -d "$NVM_VERSION_DIR" ]; then
NVM_DIRS_TO_SEARCH="$NVM_VERSION_DIR $NVM_DIRS_TO_SEARCH"
if ! [ -d "$NVM_DIRS_TO_SEARCH1" ]; then
NVM_DIRS_TO_SEARCH1=''
fi
if ! [ -d "$NVM_DIRS_TO_SEARCH2" ]; then
NVM_DIRS_TO_SEARCH2="$NVM_DIRS_TO_SEARCH1"
fi
if ! [ -d "$NVM_DIRS_TO_SEARCH3" ]; then
NVM_DIRS_TO_SEARCH3="$NVM_DIRS_TO_SEARCH2"
fi
done
if [ -z "$PATTERN" ]; then
PATTERN='v'
fi
if [ -n "$NVM_DIRS_TO_SEARCH" ]; then
VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \
if [ -n "$NVM_DIRS_TO_SEARCH1$NVM_DIRS_TO_SEARCH2$NVM_DIRS_TO_SEARCH3" ]; then
VERSIONS="$(command find "$NVM_DIRS_TO_SEARCH1" "$NVM_DIRS_TO_SEARCH2" "$NVM_DIRS_TO_SEARCH3" -maxdepth 1 -type d -name "$PATTERN*" \
| command sed "
s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#;
\#$NVM_VERSION_DIR_IOJS# d;
@@ -630,7 +647,6 @@ nvm_ls() {
s#^\($NVM_IOJS_PREFIX\)[-/]v#\1.v#;
s#^\($NVM_NODE_PREFIX\)[-/]v#\1.v#" \
| command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n \
| command sort -s -t- -k1.1,1.1 \
| command sed "
s/^\($NVM_IOJS_PREFIX\)\./\1-/;
s/^$NVM_NODE_PREFIX\.//" \
@@ -665,7 +681,7 @@ nvm_ls_remote() {
local GREP_OPTIONS
GREP_OPTIONS=''
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | tail -n1)"
PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command tail -n1)"
elif [ -n "$PATTERN" ]; then
PATTERN="$(nvm_ensure_version_prefix "$PATTERN")"
else
@@ -674,7 +690,7 @@ nvm_ls_remote() {
VERSIONS=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/ -o - \
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| command grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
| command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
if [ -z "$VERSIONS" ]; then
echo "N/A"
return 3
@@ -757,7 +773,7 @@ nvm_print_versions() {
else
FORMAT='%15s'
fi
printf "$FORMAT\n" $VERSION
command printf "$FORMAT\n" $VERSION
done
}
@@ -814,15 +830,22 @@ nvm_print_implicit_alias() {
fi
local NVM_IOJS_VERSION
NVM_IOJS_VERSION="$($NVM_COMMAND | sed "s/^"$NVM_IMPLICIT"-//" | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq | tail -1)"
local EXIT_CODE
NVM_IOJS_VERSION="$($NVM_COMMAND)"
EXIT_CODE="$?"
if [ "_$EXIT_CODE" = "_0" ]; then
NVM_IOJS_VERSION="$(echo "$NVM_IOJS_VERSION" | sed "s/^"$NVM_IMPLICIT"-//" | command grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq | command tail -1)"
fi
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
if [ "_$NVM_IOJS_VERSION" = "_N/A" ]; then
echo "N/A"
else
echo "$($NVM_ADD_PREFIX_COMMAND "$NVM_IOJS_VERSION")"
fi
return $EXIT_CODE
;;
"$NVM_NODE_PREFIX")
@@ -841,7 +864,7 @@ nvm_print_implicit_alias() {
setopt shwordsplit
fi
LAST_TWO=$($NVM_COMMAND | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
LAST_TWO=$($NVM_COMMAND | command grep -e '^v' | command cut -c2- | command cut -d . -f 1,2 | uniq)
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
@@ -852,6 +875,7 @@ nvm_print_implicit_alias() {
local STABLE
local UNSTABLE
local MOD
local NORMALIZED_VERSION
ZHS_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then
@@ -859,12 +883,17 @@ nvm_print_implicit_alias() {
setopt shwordsplit
fi
for MINOR in $LAST_TWO; do
MOD=$(expr "$(nvm_normalize_version "$MINOR")" \/ 1000000 \% 2)
NORMALIZED_VERSION="$(nvm_normalize_version "$MINOR")"
if [ "_0${NORMALIZED_VERSION#?}" != "_$NORMALIZED_VERSION" ]; then
STABLE="$MINOR"
else
MOD=$(expr "$NORMALIZED_VERSION" \/ 1000000 \% 2)
if [ $MOD -eq 0 ]; then
STABLE="$MINOR"
elif [ $MOD -eq 1 ]; then
UNSTABLE="$MINOR"
fi
fi
done
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
@@ -891,13 +920,30 @@ nvm_get_os() {
}
nvm_get_arch() {
local NVM_UNAME
NVM_UNAME="$(uname -m)"
local HOST_ARCH
local NVM_OS
local EXIT_CODE
NVM_OS="$(nvm_get_os)"
# If the OS is SunOS, first try to use pkgsrc to guess
# the most appropriate arch. If it's not available, use
# isainfo to get the instruction set supported by the
# kernel.
if [ "_$NVM_OS" = "_sunos" ]; then
HOST_ARCH=$(pkg_info -Q MACHINE_ARCH pkg_install)
EXIT_CODE=$?
if [ $EXIT_CODE -ne 0 ]; then
HOST_ARCH=$(isainfo -n)
fi
else
HOST_ARCH="$(uname -m)"
fi
local NVM_ARCH
case "$NVM_UNAME" in
x86_64) NVM_ARCH="x64" ;;
case "$HOST_ARCH" in
x86_64 | amd64) NVM_ARCH="x64" ;;
i*86) NVM_ARCH="x86" ;;
*) NVM_ARCH="$NVM_UNAME" ;;
*) NVM_ARCH="$HOST_ARCH" ;;
esac
echo "$NVM_ARCH"
}
@@ -921,6 +967,84 @@ nvm_ensure_default_set() {
return $EXIT_CODE
}
nvm_is_merged_node_version() {
nvm_version_greater_than_or_equal_to "$1" v4.0.0
}
nvm_install_merged_node_binary() {
local NVM_NODE_TYPE
NVM_NODE_TYPE="$1"
local MIRROR
if [ "_$NVM_NODE_TYPE" = "_std" ]; then
MIRROR="$NVM_NODEJS_ORG_MIRROR"
else
echo "unknown type of node.js release" >&2
return 4
fi
local VERSION
VERSION="$2"
local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$3"
if ! nvm_is_merged_node_version "$VERSION" || nvm_is_iojs_version "$VERSION"; then
echo 'nvm_install_merged_node_binary requires a node version v4.0 or greater.' >&2
return 10
fi
local VERSION_PATH
VERSION_PATH="$(nvm_version_path "$VERSION")"
local NVM_OS
NVM_OS="$(nvm_get_os)"
local t
local url
local sum
local NODE_PREFIX
local compression
compression="gz"
local tar_compression_flag
tar_compression_flag="x"
if nvm_supports_xz "$VERSION"; then
compression="xz"
tar_compression_flag="J"
fi
NODE_PREFIX="$(nvm_node_prefix)"
if [ -n "$NVM_OS" ]; then
t="$VERSION-$NVM_OS-$(nvm_get_arch)"
url="$MIRROR/$VERSION/$NODE_PREFIX-${t}.tar.${compression}"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $NODE_PREFIX-${t}.tar.${compression} | command awk '{print $1}')"
local tmpdir
tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
tmptarball="$tmpdir/node-${t}.tar.${compression}"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
echo "Downloading $url..." && \
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 (
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for node.js v4.0 and later" >&2 && \
# nvm_checksum "$tmptarball" $sum && \
command tar -x${tar_compression_flag}f "$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 >&2 "Binary download failed, trying source." >&2
command rm -rf "$tmptarball" "$tmpdir"
return 1
fi
fi
return 2
}
nvm_install_iojs_binary() {
local NVM_IOJS_TYPE
NVM_IOJS_TYPE="$1"
@@ -950,18 +1074,27 @@ nvm_install_iojs_binary() {
local t
local url
local sum
local compression
compression="gz"
local tar_compression_flag
tar_compression_flag="x"
if nvm_supports_xz "$VERSION"; then
compression="xz"
tar_compression_flag="J"
fi
if [ -n "$NVM_OS" ]; then
if nvm_binary_available "$VERSION"; then
t="$VERSION-$NVM_OS-$(nvm_get_arch)"
url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')"
url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.${compression}"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.${compression} | command awk '{print $1}')"
local tmpdir
tmpdir="$NVM_DIR/bin/iojs-${t}"
local tmptarball
tmptarball="$tmpdir/iojs-${t}.tar.gz"
tmptarball="$tmpdir/iojs-${t}.tar.${compression}"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
echo "Downloading $url..." && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
@@ -972,7 +1105,7 @@ nvm_install_iojs_binary() {
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \
command mv "$tmpdir"/* "$VERSION_PATH"
@@ -1094,6 +1227,7 @@ nvm_install_node_source() {
if (
[ -n "$tarball" ] && \
command mkdir -p "$tmpdir" && \
echo "Downloading $tarball..." && \
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" && \
@@ -1163,6 +1297,116 @@ nvm_npm_global_modules() {
echo "$INSTALLS //// $LINKS"
}
nvm_die_on_prefix() {
local NVM_DELETE_PREFIX
NVM_DELETE_PREFIX="$1"
case "$NVM_DELETE_PREFIX" in
0|1) ;;
*)
echo >&2 'First argument "delete the prefix" must be zero or one'
return 1
;;
esac
local NVM_COMMAND
NVM_COMMAND="$2"
if [ -z "$NVM_COMMAND" ]; then
echo >&2 'Second argument "nvm command" must be nonempty'
return 2
fi
if [ -n "$PREFIX" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$PREFIX" >/dev/null 2>&1); then
nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"$PREFIX\""
echo >&2 "Run \`unset PREFIX\` to unset it."
return 3
fi
if [ -n "$NPM_CONFIG_PREFIX" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then
nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
echo >&2 "Run \`unset NPM_CONFIG_PREFIX\` to unset it."
return 4
fi
if ! nvm_has 'npm'; then
return
fi
local NVM_NPM_PREFIX
NVM_NPM_PREFIX="$(npm config get prefix)"
if ! (nvm_tree_contains_path "$NVM_DIR" "$NVM_NPM_PREFIX" >/dev/null 2>&1); then
if [ "_$NVM_DELETE_PREFIX" = "_1" ]; then
npm config delete prefix
else
nvm deactivate >/dev/null 2>&1
echo >&2 "nvm is not compatible with the npm config \"prefix\" option: currently set to \"$NVM_NPM_PREFIX\""
if nvm_has 'npm'; then
echo >&2 "Run \`npm config delete prefix\` or \`$NVM_COMMAND\` to unset it."
else
echo >&2 "Run \`$NVM_COMMAND\` to unset it."
fi
return 10
fi
fi
}
# Succeeds if $IOJS_VERSION represents an io.js version that has a
# Solaris binary, fails otherwise.
# Currently, only io.js 3.3.1 has a Solaris binary available, and it's the
# latest io.js version available. The expectation is that any potential io.js
# version later than v3.3.1 will also have Solaris binaries.
iojs_version_has_solaris_binary() {
local IOJS_VERSION=$1
local STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix $IOJS_VERSION)"
if [ "_$STRIPPED_IOJS_VERSION" = "$IOJS_VERSION" ]; then
return 1
fi
# io.js started shipping Solaris binaries with io.js v3.3.1
nvm_version_greater_than_or_equal_to "$STRIPPED_IOJS_VERSION" v3.3.1
}
# Succeeds if $NODE_VERSION represents a node version that has a
# Solaris binary, fails otherwise.
# Currently, node versions starting from v0.8.6 have a Solaris binary
# avaliable.
node_version_has_solaris_binary() {
local NODE_VERSION=$1
# Error out if $NODE_VERSION is actually an io.js version
local STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix $NODE_VERSION)"
if [ "_$STRIPPED_IOJS_VERSION" != "_$NODE_VERSION" ]; then
return 1
fi
# node (unmerged) started shipping Solaris binaries with v0.8.6 and
# node versions v1.0.0 or greater are not considered valid "unmerged" node
# versions.
nvm_version_greater_than_or_equal_to "$NODE_VERSION" v0.8.6 &&
! nvm_version_greater_than_or_equal_to "$NODE_VERSION" v1.0.0
}
# Succeeds if $VERSION represents a version (node, io.js or merged) that has a
# Solaris binary, fails otherwise.
nvm_has_solaris_binary() {
local VERSION=$1
if nvm_is_merged_node_version "$VERSION"; then
return 0 # All merged node versions have a Solaris binary
elif nvm_is_iojs_version "$VERSION"; then
iojs_version_has_solaris_binary "$VERSION"
else
node_version_has_solaris_binary "$VERSION"
fi
}
nvm_sanitize_path() {
local SANITIZED_PATH
SANITIZED_PATH="$1"
if [ "_$1" != "_$NVM_DIR" ]; then
SANITIZED_PATH="$(echo "$SANITIZED_PATH" | command sed "s#$NVM_DIR#\$NVM_DIR#g")"
fi
echo "$SANITIZED_PATH" | command sed "s#$HOME#\$HOME#g"
}
nvm() {
if [ $# -lt 1 ]; then
nvm help
@@ -1198,7 +1442,8 @@ nvm() {
echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
echo ' nvm uninstall <version> Uninstall a version'
echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
echo ' nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>'
echo ' nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available'
echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
echo ' nvm current Display currently activated version'
echo ' nvm ls List installed versions'
echo ' nvm ls <version> List versions matching a given description'
@@ -1232,12 +1477,14 @@ nvm() {
setopt shwordsplit
fi
echo >&2 "\$SHELL: $SHELL"
echo >&2 "\$NVM_DIR: $(echo $NVM_DIR | sed "s#$HOME#\$HOME#g")"
echo >&2 "\$NVM_DIR: '$(nvm_sanitize_path "$NVM_DIR")'"
echo >&2 "\$PREFIX: '$(nvm_sanitize_path "$PREFIX")'"
echo >&2 "\$NPM_CONFIG_PREFIX: '$(nvm_sanitize_path "$NPM_CONFIG_PREFIX")'"
local NVM_DEBUG_OUTPUT
for NVM_DEBUG_COMMAND in 'nvm current' 'which node' 'which iojs' 'which npm' 'npm config get prefix' 'npm root -g'
do
NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1 | sed "s#$NVM_DIR#\$NVM_DIR#g")"
echo >&2 "$NVM_DEBUG_COMMAND: $NVM_DEBUG_OUTPUT"
NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1)"
echo >&2 "$NVM_DEBUG_COMMAND: $(nvm_sanitize_path "$NVM_DEBUG_OUTPUT")"
done
if [ "_$ZHS_HAS_SHWORDSPLIT_UNSET" = "_1" ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
@@ -1323,9 +1570,12 @@ nvm() {
return 5
fi
local NVM_NODE_MERGED
local NVM_IOJS
if nvm_is_iojs_version "$VERSION"; then
NVM_IOJS=true
elif nvm_is_merged_node_version "$VERSION"; then
NVM_NODE_MERGED=true
fi
local VERSION_PATH
@@ -1341,26 +1591,36 @@ nvm() {
if [ "_$NVM_OS" = "_freebsd" ]; then
# node.js and io.js do not have a FreeBSD binary
nobinary=1
elif [ "_$NVM_OS" = "_sunos" ] && [ "$NVM_IOJS" = true ]; then
# io.js does not have a SunOS binary
elif [ "_$NVM_OS" = "_sunos" ]; then
# Not all node/io.js versions have a Solaris binary
if ! nvm_has_solaris_binary "$VERSION"; then
nobinary=1
fi
fi
local NVM_INSTALL_SUCCESS
# skip binary install if "nobinary" option specified.
if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then
if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary std "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true
elif [ "$NVM_NODE_MERGED" = true ] && nvm_install_merged_node_binary std "$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
fi
if [ "$NVM_INSTALL_SUCCESS" != true ]; then
if [ "$NVM_IOJS" = true ]; then
if [ "$NVM_IOJS" != true ] && [ "$NVM_NODE_MERGED" != true ]; then
if nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true
fi
elif [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2
return 105
elif nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true
elif [ "$NVM_NODE_MERGED" = true ]; then
# nvm_install_merged_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"
echo "Installing node v1.0 and greater from source is not currently supported" >&2
return 106
fi
fi
@@ -1418,9 +1678,9 @@ nvm() {
fi
# Delete all files related to target version.
command rm -rf "$NVM_DIR/src/$NVM_PREFIX-$VERSION" \
"$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.gz" \
"$NVM_DIR/src/$NVM_PREFIX-$VERSION.tar.*" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.gz" \
"$NVM_DIR/bin/$NVM_PREFIX-${t}.tar.*" \
"$VERSION_PATH" 2>/dev/null
echo "$NVM_SUCCESS_MSG"
@@ -1459,19 +1719,31 @@ nvm() {
local PROVIDED_VERSION
local NVM_USE_SILENT
NVM_USE_SILENT=0
if [ "$2" = '--silent' ]; then
NVM_USE_SILENT=1
shift
fi
local NVM_DELETE_PREFIX
NVM_DELETE_PREFIX=0
if [ $# -eq 1 ]; then
shift # remove "use"
while [ $# -ne 0 ]
do
case "$1" in
--silent) NVM_USE_SILENT=1 ;;
--delete-prefix) NVM_DELETE_PREFIX=1 ;;
*)
if [ -n "$1" ]; then
PROVIDED_VERSION="$1"
fi
;;
esac
shift
done
if [ -z "$PROVIDED_VERSION" ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
PROVIDED_VERSION="$NVM_RC_VERSION"
VERSION="$(nvm_version "$PROVIDED_VERSION")"
fi
else
PROVIDED_VERSION="$2"
VERSION="$(nvm_match_version "$PROVIDED_VERSION")"
fi
@@ -1536,15 +1808,32 @@ nvm() {
if [ "$NVM_SYMLINK_CURRENT" = true ]; then
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
fi
local NVM_USE_OUTPUT
if nvm_is_iojs_version "$VERSION"; then
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
NVM_USE_OUTPUT="Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
fi
else
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using node $VERSION$(nvm_print_npm_version)"
NVM_USE_OUTPUT="Now using node $VERSION$(nvm_print_npm_version)"
fi
fi
if [ "_$VERSION" != "_system" ]; then
local NVM_USE_CMD
NVM_USE_CMD="nvm use --delete-prefix"
if [ -n "$PROVIDED_VERSION" ]; then
NVM_USE_CMD="$NVM_USE_CMD $VERSION"
fi
if [ $NVM_USE_SILENT -eq 1 ]; then
NVM_USE_CMD="$NVM_USE_CMD --silent"
fi
if ! nvm_die_on_prefix "$NVM_DELETE_PREFIX" "$NVM_USE_CMD"; then
return 11
fi
fi
if [ -n "$NVM_USE_OUTPUT" ]; then
echo "$NVM_USE_OUTPUT"
fi
;;
"run" )
local provided_version
@@ -1552,6 +1841,14 @@ nvm() {
has_checked_nvmrc=0
# run given version of node
shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
if [ $# -lt 1 ]; then
nvm_rc_version && has_checked_nvmrc=1
if [ -n "$NVM_RC_VERSION" ]; then
@@ -1565,7 +1862,7 @@ nvm() {
fi
fi
provided_version=$1
provided_version="$1"
if [ -n "$provided_version" ]; then
VERSION="$(nvm_version "$provided_version")"
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then
@@ -1596,8 +1893,8 @@ nvm() {
setopt shwordsplit
fi
if [ "_$VERSION" = "_N/A" ]; then
echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2
EXIT_CODE=1
nvm_ensure_version_installed "$provided_version"
EXIT_CODE=$?
elif [ -z "$ARGS" ]; then
if [ "$NVM_IOJS" = true ]; then
nvm exec "$VERSION" iojs
@@ -1606,11 +1903,11 @@ nvm() {
fi
EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")"
[ $NVM_SILENT -eq 1 ] || echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
EXIT_CODE="$?"
else
echo "Running node $VERSION"
[ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)"
OUTPUT="$(nvm use "$VERSION" >/dev/null && node $ARGS)"
EXIT_CODE="$?"
fi
@@ -1625,11 +1922,18 @@ nvm() {
"exec" )
shift
local NVM_SILENT
NVM_SILENT=0
if [ "_$1" = "_--silent" ]; then
NVM_SILENT=1
shift
fi
local provided_version
provided_version="$1"
if [ -n "$provided_version" ]; then
VERSION="$(nvm_version "$provided_version")"
if [ "_$VERSION" = "_N/A" ]; then
if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then
nvm_rc_version
provided_version="$NVM_RC_VERSION"
VERSION="$(nvm_version "$provided_version")"
@@ -1644,7 +1948,7 @@ nvm() {
return $EXIT_CODE
fi
echo "Running node $VERSION"
[ $NVM_SILENT -eq 1 ] || echo "Running node $VERSION$(nvm_print_npm_version)"
NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
;;
"ls" | "list" )
@@ -1675,10 +1979,16 @@ nvm() {
local NVM_LS_REMOTE_EXIT_CODE
NVM_LS_REMOTE_EXIT_CODE=0
local NVM_LS_REMOTE_OUTPUT
NVM_LS_REMOTE_OUTPUT=''
local NVM_LS_REMOTE_PRE_MERGED_OUTPUT
NVM_LS_REMOTE_PRE_MERGED_OUTPUT=''
local NVM_LS_REMOTE_POST_MERGED_OUTPUT
NVM_LS_REMOTE_POST_MERGED_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$NVM_IOJS_PREFIX" ]; then
local NVM_LS_REMOTE_OUTPUT
NVM_LS_REMOTE_OUTPUT=$(nvm_ls_remote "$PATTERN")
# split output into two
NVM_LS_REMOTE_PRE_MERGED_OUTPUT="${NVM_LS_REMOTE_OUTPUT%%v4\.0\.0*}"
NVM_LS_REMOTE_POST_MERGED_OUTPUT="${NVM_LS_REMOTE_OUTPUT#$NVM_LS_REMOTE_PRE_MERGED_OUTPUT}"
NVM_LS_REMOTE_EXIT_CODE=$?
fi
@@ -1692,8 +2002,9 @@ nvm() {
fi
local NVM_OUTPUT
NVM_OUTPUT="$(echo "$NVM_LS_REMOTE_OUTPUT
$NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
NVM_OUTPUT="$(echo "$NVM_LS_REMOTE_PRE_MERGED_OUTPUT
$NVM_LS_REMOTE_IOJS_OUTPUT
$NVM_LS_REMOTE_POST_MERGED_OUTPUT" | command grep -v "N/A" | command sed '/^$/d')"
if [ -n "$NVM_OUTPUT" ]; then
nvm_print_versions "$NVM_OUTPUT"
return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE
@@ -1777,10 +2088,14 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
DEST="$(nvm_print_implicit_alias local "$ALIAS")"
if [ "_$DEST" != "_" ]; then
VERSION="$(nvm_version "$DEST")"
if [ "_$DEST" = "_$VERSION" ]; then
echo "$ALIAS -> $DEST (default)"
else
echo "$ALIAS -> $DEST (-> $VERSION) (default)"
fi
fi
fi
fi
done
return
fi
@@ -1869,7 +2184,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
nvm_remote_version "$2"
;;
"--version" )
echo "0.26.0"
echo "0.29.0"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum \
@@ -1894,7 +2209,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \
nvm_download nvm_get_latest nvm_has nvm_get_latest \
nvm_supports_source_options > /dev/null 2>&1
nvm_supports_source_options nvm_supports_xz > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
@@ -1908,15 +2223,20 @@ nvm_supports_source_options() {
[ "_$(echo 'echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]
}
VERSION="$(nvm_alias default 2>/dev/null || echo)"
nvm_supports_xz() {
command which xz 2>&1 >/dev/null && \
nvm_version_greater_than_or_equal_to "$1" "2.3.2"
}
NVM_VERSION="$(nvm_alias default 2>/dev/null || echo)"
if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
if [ -n "$VERSION" ]; then
nvm install "$VERSION" >/dev/null
if [ -n "$NVM_VERSION" ]; then
nvm install "$NVM_VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm install >/dev/null
fi
elif [ -n "$VERSION" ]; then
nvm use --silent "$VERSION" >/dev/null
elif [ -n "$NVM_VERSION" ]; then
nvm use --silent "$NVM_VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use --silent >/dev/null
fi

View File

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

13
test/common.sh Normal file
View File

@@ -0,0 +1,13 @@
assert_ok() {
local FUNCTION=$1
shift
$($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'
}
assert_not_ok() {
local FUNCTION=$1
shift
! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'
}

View File

@@ -7,7 +7,7 @@ die () { echo $@ ; exit 1; }
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
. ../../nvm.sh
nvm use v0.2.3 || die "Failed to activate v0.2.3"
nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"
# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable

View File

@@ -23,8 +23,16 @@ EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use foo --silent 2>&1)"
EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use foo --silent' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
EXIT_CODE="$(nvm use foo --silent 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use foo --silent'; got $EXIT_CODE"
cleanup;

View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
. ../../common.sh
assert_not_ok iojs_version_has_solaris_binary ""
assert_not_ok iojs_version_has_solaris_binary "foo"
assert_not_ok iojs_version_has_solaris_binary "v1.1.0"
assert_ok iojs_version_has_solaris_binary "v3.3.1"
assert_ok iojs_version_has_solaris_binary "iojs-v3.3.1"
assert_ok iojs_version_has_solaris_binary "v3.3.2"
assert_ok iojs_version_has_solaris_binary "iojs-v3.3.2"
assert_ok iojs_version_has_solaris_binary "v3.4.1"
assert_ok iojs_version_has_solaris_binary "iojs-v3.4.1"

View File

@@ -0,0 +1,33 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
. ../../common.sh
# Invalid version numbers fail
assert_not_ok node_version_has_solaris_binary ""
assert_not_ok node_version_has_solaris_binary "foo"
# "Invalid" node version numbers fail
assert_not_ok node_version_has_solaris_binary "v1.0.0"
assert_not_ok node_version_has_solaris_binary "v3.3.1"
# Valid io.js version numbers that have a Solaris binary fail
assert_not_ok node_version_has_solaris_binary "iojs-v3.3.1"
# Invvalid io.js version numbers fail
assert_not_ok node_version_has_solaris_binary "iojs-v0.12.7"
# Valid node version numbers that don't have a Solaris binary fail
assert_not_ok node_version_has_solaris_binary "v0.8.5"
# Valid node version numbers that have a Solaris binary succeed
assert_ok node_version_has_solaris_binary "v0.8.6"
assert_ok node_version_has_solaris_binary "v0.10.0"
assert_ok node_version_has_solaris_binary "v0.12.7"
# Valid "merged" version numbers fail, because they're not
# considered node version numbers
assert_not_ok node_version_has_solaris_binary "v4.0.0"
assert_not_ok node_version_has_solaris_binary "v4.1.1"

View File

@@ -0,0 +1,74 @@
#!/bin/sh
cleanup () {
alias nvm_has='\nvm_has'
alias npm='\npm'
unset -f nvm_has npm
}
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
OUTPUT="$(nvm_die_on_prefix 2>&1)"
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
EXIT_CODE="$(nvm_die_on_prefix >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
OUTPUT="$(nvm_die_on_prefix 2 2>&1)"
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
EXIT_CODE="$(nvm_die_on_prefix 2 >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 2' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
OUTPUT="$(nvm_die_on_prefix 0 2>&1)"
EXPECTED_OUTPUT="Second argument \"nvm command\" must be nonempty"
EXIT_CODE="$(nvm_die_on_prefix 0 >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_die_on_prefix 0' did not exit with 2; got '$EXIT_CODE'"
nvm_has() { return 1; } # ie, npm is not installed
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
[ -z "$OUTPUT" ] || die "nvm_die_on_prefix was not a noop when nvm_has returns 1, got '$OUTPUT'"
nvm_has() { return 0; }
npm() {
local args
args="$@"
if [ "_$args" = "_config get prefix" ]; then
echo "$(nvm_version_dir new)/good prefix"
fi
}
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
Run `unset PREFIX` to unset it.'
EXIT_CODE="$(PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_3" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 3; got '$EXIT_CODE'"
OUTPUT="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "NPM_CONFIG_PREFIX" environment variable: currently set to "bar"
Run `unset NPM_CONFIG_PREFIX` to unset it.'
EXIT_CODE="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
npm() {
local args
args="$@"
if [ "_$args" = "_config get prefix" ]; then
echo "./bad prefix"
fi
}
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"
Run \`npm config delete prefix\` or \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
cleanup

View File

@@ -20,4 +20,11 @@ EXIT_CODE=$?
[ "_$OUTPUT" = "_" ] || die "expected 'nvm_ensure_version_installed 0.1' to have no output, got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed 0.1' to exit with 0, got $EXIT_CODE"
# Special case for "iojs"
OUTPUT="$(nvm_ensure_version_installed iojs 2>&1)"
EXIT_CODE=$?
EXPECTED_OUTPUT='N/A: version "iojs" is not yet installed'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT"
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE"
cleanup

View File

@@ -0,0 +1,80 @@
#!/bin/sh
# Save the PATH as it was when the test started to restore it when it
# finishes
ORIG_PATH=$PATH
cleanup() {
# Restore the PATH as it was when the test started
export PATH=ORIG_PATH
}
die () { cleanup; echo $@ ; exit 1; }
. ../../../nvm.sh
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are
# located
MOCKS_DIR=`pwd`/../../mocks
# Sets the PATH for these tests to include the symlinks to the mocked
# binaries
export PATH=.:${PATH}
# Setups mock binaries for a given OS and arch that mimic
# the output of the real binaries used by nvm_get_arch to guess
# the architecture of a given system.
setup_mock_arch() {
local OS=$1
local ARCH=$2
local OPT=$3
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
if [ "_$OPT" != "_no_pkg_info" ]; then
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
fi
fi
ln -sf "${MOCKS_DIR}/uname_${OS}_${ARCH}" ./uname
}
# Cleans up the setup done by setup_mock_arch.
cleanup_mock_arch() {
local OS=$1
local ARCH=$2
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
rm -f ./isainfo
rm -f ./pkg_info
fi
rm -f ./uname
}
# Runs nvm_get_arch for architecture $ARCH and OS $OS, and compares the
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing
# and exits cleanly if they match, dies otherwise.
run_test() {
local ARCH=$1
local OS=$2
local EXPECTED_OUTPUT=$3
local OPT=$4
setup_mock_arch $OS $ARCH $OPT
local OUTPUT="$(nvm_get_arch)"
cleanup_mock_arch $OS $ARCH
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] ||
die "nvm_get_arch for OS \"$OS\" and arch \"$ARCH\" with OPT \"$OPT\" did
not return \"$EXPECTED_OUTPUT\"; got \"$OUTPUT\""
}
run_test x86 smartos x86
run_test x86 smartos x86 no_pkg_info
run_test amd64 smartos x64
run_test amd64 smartos x64 no_pkg_info
run_test x86 osx x86
run_test amd64 osx x64
cleanup

View File

@@ -0,0 +1,32 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
. ../../common.sh
# Invalid version numbers fail
assert_not_ok nvm_has_solaris_binary ""
assert_not_ok nvm_has_solaris_binary "foo"
# "Invalid" node version numbers fail
assert_not_ok nvm_has_solaris_binary "v1.0.0"
assert_not_ok nvm_has_solaris_binary "v3.3.1"
# Valid io.js version numbers that have a Solaris binary succeed
assert_ok nvm_has_solaris_binary "iojs-v3.3.1"
# Invvalid io.js version numbers fail
assert_not_ok nvm_has_solaris_binary "iojs-v0.12.7"
# Valid node version numbers that don't have a Solaris binary fail
assert_not_ok nvm_has_solaris_binary "v0.8.5"
# Valid node version numbers that have a Solaris binary succeed
assert_ok nvm_has_solaris_binary "v0.8.6"
assert_ok nvm_has_solaris_binary "v0.10.0"
assert_ok nvm_has_solaris_binary "v0.12.7"
# Valid "merged" version numbers succeed
assert_ok nvm_has_solaris_binary "v4.0.0"
assert_ok nvm_has_solaris_binary "v4.1.1"

View File

@@ -0,0 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm_is_merged_node_version '4.0' || die '"nvm_is_merged_node_version 4.0 was not true'
nvm_is_merged_node_version '5.1' || die '"nvm_is_merged_node_version 5.1 was not true'
! nvm_is_merged_node_version '3.99' || die '"nvm_is_merged_node_version 3.99 was not false'
! nvm_is_merged_node_version 'v1.0.0' || die '"nvm_is_merged_node_version v1.0.0" was not false'

View File

@@ -8,6 +8,8 @@ cleanup() {
rm -rf ../../../v0.5.7
rm -rf ../../../v0.7.7
rm -rf ../../../versions/io.js/v0.98.0
rm -rf ../../../versions/node/v1.0.0
rm -rf ../../../versions/node/v1.1.0
unset -f nvm_ls_remote nvm_ls_remote_iojs
}
@@ -32,6 +34,17 @@ LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
LATEST_IOJS="$(nvm_print_implicit_alias local iojs)"
[ "_$LATEST_IOJS" = "_iojs-v0.98" ] || die "local iojs is not latest iojs: expected iojs-v0.98, got $LATEST_IOJS"
## node post v1.0/io.js merger ##
mkdir -p ../../../versions/node/v1.0.0
mkdir -p ../../../versions/node/v1.1.0
LATEST_STABLE="$(nvm_print_implicit_alias local stable)"
[ "_$LATEST_STABLE" = "_1.1" ] || die "local stable when post-v1.0 exists is not latest: expected 1.1, got $LATEST_STABLE"
LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest pre-v1.0 odd minor: expected 0.7, got $LATEST_UNSTABLE"
## ** ##
nvm_ls_remote() {
echo "v0.4.3"
echo "v0.5.4"
@@ -65,5 +78,28 @@ LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)"
LATEST_IOJS="$(nvm_print_implicit_alias remote iojs)"
[ "_$LATEST_IOJS" = "_iojs-v0.99" ] || die "remote iojs is not latest: expected iojs-v0.99, got $LATEST_IOJS"
## node post v1.0/io.js merger ##
nvm_ls_remote() {
echo "v0.4.3"
echo "v0.5.4"
echo "v0.6.6"
echo "v0.7.7"
echo "v0.9.7"
echo "v0.4.3"
echo "v0.5.4"
echo "v0.6.6"
echo "v0.7.7"
echo "v0.9.7"
echo "v1.0.0"
echo "v1.1.0"
}
LATEST_STABLE="$(nvm_print_implicit_alias remote stable)"
[ "_$LATEST_STABLE" = "_1.1" ] || die "remote stable when post-v1.0 exists is not latest: expected 1.1, got $LATEST_STABLE"
LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)"
[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd pre-v1.0 minor: expected 0.9, got $LATEST_UNSTABLE"
## ** ##
cleanup

View File

@@ -0,0 +1,36 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
OLDPATH=$PATH
TEST_PATH=../../xz-test
mkdir $TEST_PATH
touch ../../xz-test/xz
chmod +x ../../xz-test/xz
export PATH=$TEST_PATH:$PATH
$(nvm_supports_xz "v2.3.2") || \
die "expected 'nvm_supports_xz v2.3.2' to exit with 0"
$(nvm_supports_xz "v0.12.7") && \
die "expected 'nvm_supports_xz v0.12.7' to exit with 1"
# set up for a failure by having a minimal toolset available
# but remove xz
ln -s /usr/bin/which $TEST_PATH/which
ln -s /usr/bin/command $TEST_PATH/command
ln -s /usr/bin/awk $TEST_PATH/awk
ln -s $(which rm) $TEST_PATH/rm
export PATH=$TEST_PATH
rm $TEST_PATH/xz
$(nvm_supports_xz "v2.3.2") && \
die "expected 'nvm_supports_xz v2.3.2' with a missing xz binary to exit with 1"
export PATH=$OLDPATH

View File

@@ -6,5 +6,5 @@
type setopt >/dev/null 2>&1 && setopt NULL_GLOB
type shopt >/dev/null 2>&1 && shopt -s nullglob
rm -fR v* src alias
rm -fR v* src alias test/test-xz
)

5
test/mocks/isainfo_amd64 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-n" ]; then
echo "amd64"
else
echo "amd64 i386"
fi

5
test/mocks/isainfo_x86 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-n" ]; then
echo "i386"
else
echo "i386"
fi

1
test/mocks/pkg_info_amd64 Executable file
View File

@@ -0,0 +1 @@
echo "x86_64"

1
test/mocks/pkg_info_x86 Executable file
View File

@@ -0,0 +1 @@
echo "i386"

5
test/mocks/uname_osx_amd64 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-m" ]; then
echo "x86_64"
else
echo "Darwin foo.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"
fi

5
test/mocks/uname_osx_x86 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-m" ]; then
echo "i386"
else
echo "Darwin foo.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_I386 i386"
fi

5
test/mocks/uname_smartos_amd64 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-m" ]; then
echo "i86pc"
else
echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"
fi

5
test/mocks/uname_smartos_x86 Executable file
View File

@@ -0,0 +1,5 @@
if [ "_$1" = "_-m" ]; then
echo "i86pc"
else
echo "SunOS dev 5.11 joyent_20150219T102159Z i86pc i386 i86pc Solaris"
fi

View File

@@ -5,5 +5,5 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "$(nvm run 0.2 --version 2>&1)" = "v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly"
[ "$(nvm run iojs-0.2 --version 2>&1)" = "iojs-v0.2 is not installed yet" ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly"
[ "$(nvm run 0.2 --version 2>&1)" = 'N/A: version "v0.2" is not yet installed' ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly"
[ "$(nvm run iojs-0.2 --version 2>&1)" = 'N/A: version "iojs-v0.2" is not yet installed' ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly"

View File

@@ -0,0 +1,22 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
nvm_die_on_prefix() {
echo >&2 "| $1 | $2 |"
return 3
}
OUTPUT="$(nvm use --silent node)"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent node' did not call through to 'nvm_die_on_prefix' and give output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use --silent node >/dev/null 2>&1; echo $?)"
EXPECTED_CODE="11"
[ "_$EXIT_CODE" = "_$EXPECTED_CODE" ] \
|| die "'nvm use --silent node' when 'nvm_die_on_prefix' fails did not return '$EXPECTED_CODE'; got '$EXIT_CODE'"