Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
448bd38a55 | ||
|
|
0ad5a450fe | ||
|
|
d5e21be164 | ||
|
|
797c5ab70b | ||
|
|
0e209ce890 | ||
|
|
9a57a891b9 | ||
|
|
3d5ded1815 | ||
|
|
7807a9f09e | ||
|
|
835c006b5e | ||
|
|
34e51f9f02 | ||
|
|
4b5885d69d | ||
|
|
bf794ff8da | ||
|
|
0bd7372c64 | ||
|
|
0a142b7e7a | ||
|
|
3fc82d6b2f | ||
|
|
c6489440dc | ||
|
|
67e8939311 | ||
|
|
a26007ec0d | ||
|
|
3f5ce8b93a | ||
|
|
8328741792 | ||
|
|
8e45afb9f1 | ||
|
|
fd2fb24b03 | ||
|
|
4708cc73ef | ||
|
|
c91e8d0ba2 | ||
|
|
f8b143c594 | ||
|
|
9a4e9060d8 | ||
|
|
3df0caefa5 | ||
|
|
274369dc40 | ||
|
|
bef3a5ce3a | ||
|
|
0cb8c9ac2f | ||
|
|
25c61594fe | ||
|
|
0a739e3fa9 | ||
|
|
c0a20f2fa3 | ||
|
|
2d78d69d4c | ||
|
|
9e17b5059c | ||
|
|
0ac2c787be | ||
|
|
99ca0de18f | ||
|
|
f196ace5dd | ||
|
|
d1a90ca15c | ||
|
|
b3178ca925 | ||
|
|
b9df3fccb4 | ||
|
|
f408d68afc | ||
|
|
fc3a30dd0e | ||
|
|
74b36b09ff | ||
|
|
080f2149ac | ||
|
|
3bd148056e | ||
|
|
5edf013127 | ||
|
|
ae908cbff6 | ||
|
|
7805492bda | ||
|
|
a1c0c34088 | ||
|
|
234b925c7a | ||
|
|
0c33fd2598 | ||
|
|
c9a53fe0c7 | ||
|
|
8b25457b74 | ||
|
|
ee520abf78 | ||
|
|
b63042bd9f | ||
|
|
382c3aa85e |
16
Makefile
16
Makefile
@@ -1,10 +1,14 @@
|
||||
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
|
||||
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
|
||||
# Note: With Travis CI:
|
||||
# - the path to urchin is passed via the command line.
|
||||
# - the other utilties are NOT needed, so we skip the test for their existence.
|
||||
# - the other utilities are NOT needed, so we skip the test for their existence.
|
||||
URCHIN := urchin
|
||||
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
|
||||
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
|
||||
export PATH := $(shell printf '%s' "$$(npm bin):$$PATH")
|
||||
# Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
|
||||
# where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
|
||||
export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
|
||||
# The list of all supporting utilities, installed with `npm install`.
|
||||
UTILS := $(URCHIN) replace semver
|
||||
# Make sure that all required utilities can be located.
|
||||
@@ -17,9 +21,6 @@ SHELLS := sh bash dash zsh # ksh (#574)
|
||||
# Generate 'test-<shell>' target names from specified shells.
|
||||
# The embedded shell names are extracted on demand inside the recipes.
|
||||
SHELL_TARGETS := $(addprefix test-,$(SHELLS))
|
||||
# Determine if the installed Urchin version supports cross-shell testing, based on whether its usage information mentions the -s option.
|
||||
HAVE_CROSS_SHELL_TESTS := $(shell PATH="$(PATH)" $(URCHIN) -h | grep -qE '(^|\s)-s\s' && echo 'yes')
|
||||
NO_CROSS_SHELL_TESTS_WARNING := $(if $(HAVE_CROSS_SHELL_TESTS),,$(warning WARNING: This version of Urchin does not support cross-shell tests. All tests will run with 'sh'.))
|
||||
# Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
|
||||
# Test suites are the names of subfolders of './test'.
|
||||
TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
|
||||
@@ -41,9 +42,8 @@ list:
|
||||
$(SHELL_TARGETS):
|
||||
@shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
|
||||
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
|
||||
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(export -p | awk -F'[ =]' '$$2 ~ "^NVM_" { print $$2 }'); do unset $$v; done && unset v; \
|
||||
[ "$(HAVE_CROSS_SHELL_TESTS)" = 'yes' ] && targetShellOpt="-s $$shell" || targetShellOpt=; \
|
||||
for suite in $(TEST_SUITE); do $(URCHIN) -f $$targetShellOpt test/$$suite || exit; done
|
||||
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
|
||||
for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
|
||||
|
||||
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
||||
.PHONY: test
|
||||
|
||||
@@ -12,11 +12,11 @@ Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/n
|
||||
|
||||
To install you could use the [install script][2] using cURL:
|
||||
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.22.2/install.sh | bash
|
||||
|
||||
or Wget:
|
||||
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.20.0/install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.22.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>
|
||||
|
||||
@@ -43,7 +43,7 @@ Often I also put in a line to use a specific version of node.
|
||||
## Usage
|
||||
|
||||
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
|
||||
`nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file.
|
||||
`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied.
|
||||
|
||||
To download, compile, and install the latest v0.10.x release of node, do this:
|
||||
|
||||
@@ -61,6 +61,10 @@ Or, you can run any arbitrary command in a subshell with the desired version of
|
||||
|
||||
nvm exec 0.10 node --version
|
||||
|
||||
You can also get the path to the executable to where it was installed:
|
||||
|
||||
nvm which 0.10
|
||||
|
||||
In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
|
||||
|
||||
nvm install stable
|
||||
@@ -187,7 +191,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.20.0/install.sh
|
||||
[2]: https://github.com/creationix/nvm/blob/v0.22.2/install.sh
|
||||
[3]: https://travis-ci.org/creationix/nvm
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ __nvm_commands ()
|
||||
alias unalias reinstall-packages \
|
||||
current list ls list-remote ls-remote \
|
||||
clear-cache deactivate unload \
|
||||
version'
|
||||
version which'
|
||||
|
||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||
|
||||
|
||||
28
install.sh
28
install.sh
@@ -4,13 +4,16 @@ set -e
|
||||
|
||||
nvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
if [ -z "$NVM_DIR" ]; then
|
||||
NVM_DIR="$HOME/.nvm"
|
||||
fi
|
||||
|
||||
nvm_latest_version() {
|
||||
echo "v0.22.2"
|
||||
}
|
||||
|
||||
#
|
||||
# Outputs the location to NVM depending on:
|
||||
# * The availability of $NVM_SOURCE
|
||||
@@ -22,20 +25,17 @@ nvm_source() {
|
||||
NVM_METHOD="$1"
|
||||
if [ -z "$NVM_SOURCE" ]; then
|
||||
local NVM_SOURCE
|
||||
else
|
||||
echo "$NVM_SOURCE"
|
||||
return 0
|
||||
fi
|
||||
if [ "_$NVM_METHOD" = "_script" ]; then
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.20.0/nvm.sh"
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm.sh"
|
||||
elif [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.20.0/nvm-exec"
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm-exec"
|
||||
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
|
||||
NVM_SOURCE="https://github.com/creationix/nvm.git"
|
||||
else
|
||||
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
echo "$NVM_SOURCE"
|
||||
return 0
|
||||
}
|
||||
@@ -45,7 +45,7 @@ nvm_download() {
|
||||
curl $*
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
|
||||
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/-L //' \
|
||||
-e 's/-I /--server-response /' \
|
||||
-e 's/-s /-q /' \
|
||||
@@ -59,7 +59,7 @@ install_nvm_from_git() {
|
||||
if [ -d "$NVM_DIR/.git" ]; then
|
||||
echo "=> nvm is already installed in $NVM_DIR, trying to update"
|
||||
printf "\r=> "
|
||||
cd "$NVM_DIR" && (git fetch 2> /dev/null || {
|
||||
cd "$NVM_DIR" && (command git fetch 2> /dev/null || {
|
||||
echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
|
||||
})
|
||||
else
|
||||
@@ -67,17 +67,17 @@ install_nvm_from_git() {
|
||||
echo "=> Downloading nvm from git to '$NVM_DIR'"
|
||||
printf "\r=> "
|
||||
mkdir -p "$NVM_DIR"
|
||||
git clone "$(nvm_source "git")" "$NVM_DIR"
|
||||
command git clone "$(nvm_source git)" "$NVM_DIR"
|
||||
fi
|
||||
cd "$NVM_DIR" && git checkout v0.20.0 && git branch -D master >/dev/null 2>&1
|
||||
cd "$NVM_DIR" && command git checkout --quiet $(nvm_latest_version) && command git branch --quiet -D master >/dev/null 2>&1
|
||||
return
|
||||
}
|
||||
|
||||
install_nvm_as_script() {
|
||||
local NVM_SOURCE
|
||||
NVM_SOURCE=$(nvm_source "script")
|
||||
NVM_SOURCE=$(nvm_source script)
|
||||
local NVM_EXEC_SOURCE
|
||||
NVM_EXEC_SOURCE=$(nvm_source "script-nvm-exec")
|
||||
NVM_EXEC_SOURCE=$(nvm_source script-nvm-exec)
|
||||
|
||||
# Downloading to $NVM_DIR
|
||||
mkdir -p "$NVM_DIR"
|
||||
@@ -178,7 +178,7 @@ nvm_do_install() {
|
||||
# during the execution of the install script
|
||||
#
|
||||
nvm_reset() {
|
||||
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset nvm_detect_profile
|
||||
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset nvm_detect_profile nvm_latest_version
|
||||
}
|
||||
|
||||
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
|
||||
|
||||
536
nvm.sh
536
nvm.sh
@@ -12,12 +12,30 @@ nvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
nvm_get_latest() {
|
||||
local NVM_LATEST_URL
|
||||
if nvm_has "curl"; then
|
||||
NVM_LATEST_URL="$(curl -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 }')"
|
||||
else
|
||||
>&2 echo 'nvm needs curl or wget to proceed.'
|
||||
return 1
|
||||
fi
|
||||
if [ "_$NVM_LATEST_URL" = "_" ]; then
|
||||
>&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}'
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_download() {
|
||||
if nvm_has "curl"; then
|
||||
curl $*
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
|
||||
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/-L //' \
|
||||
-e 's/-I /--server-response /' \
|
||||
-e 's/-s /-q /' \
|
||||
@@ -122,11 +140,11 @@ nvm_version_greater_than_or_equal_to() {
|
||||
}
|
||||
|
||||
nvm_version_dir() {
|
||||
local NVM_USE_NEW_DIR
|
||||
NVM_USE_NEW_DIR="$1"
|
||||
if [ -z "$NVM_USE_NEW_DIR" ] || [ "$NVM_USE_NEW_DIR" = "new" ]; then
|
||||
echo "$NVM_DIR/versions"
|
||||
elif [ "$NVM_USE_NEW_DIR" = "old" ]; then
|
||||
local NVM_WHICH_DIR
|
||||
NVM_WHICH_DIR="$1"
|
||||
if [ -z "$NVM_WHICH_DIR" ] || [ "_$NVM_WHICH_DIR" = "_new" ]; then
|
||||
echo "$NVM_DIR/versions/node"
|
||||
elif [ "_$NVM_WHICH_DIR" = "_old" ]; then
|
||||
echo "$NVM_DIR"
|
||||
else
|
||||
echo "unknown version dir" >&2
|
||||
@@ -134,6 +152,10 @@ nvm_version_dir() {
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_alias_path() {
|
||||
echo "$(nvm_version_dir old)/alias"
|
||||
}
|
||||
|
||||
nvm_version_path() {
|
||||
local VERSION
|
||||
VERSION="$1"
|
||||
@@ -183,18 +205,18 @@ nvm_remote_version() {
|
||||
}
|
||||
|
||||
nvm_normalize_version() {
|
||||
echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
||||
echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
|
||||
}
|
||||
|
||||
nvm_ensure_version_prefix() {
|
||||
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
|
||||
echo "$1" | command sed -e 's/^\([0-9]\)/v\1/g'
|
||||
}
|
||||
|
||||
nvm_format_version() {
|
||||
local VERSION
|
||||
VERSION="$(nvm_ensure_version_prefix "$1")"
|
||||
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
|
||||
VERSION="$(echo "$VERSION" | sed -e 's/\.*$/.0/')"
|
||||
VERSION="$(echo "$VERSION" | command sed -e 's/\.*$/.0/')"
|
||||
nvm_format_version "$VERSION"
|
||||
else
|
||||
echo "$VERSION"
|
||||
@@ -209,14 +231,14 @@ nvm_num_version_groups() {
|
||||
return
|
||||
fi
|
||||
local NVM_NUM_DOTS
|
||||
NVM_NUM_DOTS=$(echo "$VERSION" | sed -e 's/^v//' | sed -e 's/\.$//' | sed -e 's/[^\.]//g')
|
||||
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/^v//' | command sed -e 's/\.$//' | command sed -e 's/[^\.]//g')
|
||||
local NVM_NUM_GROUPS
|
||||
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
|
||||
echo "${#NVM_NUM_GROUPS}"
|
||||
}
|
||||
|
||||
nvm_strip_path() {
|
||||
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
|
||||
echo "$1" | command sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
|
||||
}
|
||||
|
||||
nvm_prepend_path() {
|
||||
@@ -243,7 +265,7 @@ nvm_alias() {
|
||||
fi
|
||||
|
||||
local NVM_ALIAS_PATH
|
||||
NVM_ALIAS_PATH="$NVM_DIR/alias/$ALIAS"
|
||||
NVM_ALIAS_PATH="$(nvm_alias_path)/$ALIAS"
|
||||
if [ ! -f "$NVM_ALIAS_PATH" ]; then
|
||||
echo >&2 'Alias does not exist.'
|
||||
return 2
|
||||
@@ -254,12 +276,12 @@ nvm_alias() {
|
||||
|
||||
nvm_ls_current() {
|
||||
local NVM_LS_CURRENT_NODE_PATH
|
||||
NVM_LS_CURRENT_NODE_PATH="$(which node 2> /dev/null)"
|
||||
NVM_LS_CURRENT_NODE_PATH="$(command which node 2> /dev/null)"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'none'
|
||||
elif nvm_tree_contains_path "$NVM_DIR" "$NVM_LS_CURRENT_NODE_PATH"; then
|
||||
local VERSION
|
||||
VERSION=`node -v 2>/dev/null`
|
||||
VERSION="$(node -v 2>/dev/null)"
|
||||
if [ "$VERSION" = "v0.6.21-pre" ]; then
|
||||
echo "v0.6.21"
|
||||
else
|
||||
@@ -292,7 +314,7 @@ nvm_resolve_alias() {
|
||||
fi
|
||||
|
||||
if [ -n "$ALIAS_TEMP" ] \
|
||||
&& printf "$SEEN_ALIASES" | \grep -e "^$ALIAS_TEMP$" > /dev/null; then
|
||||
&& printf "$SEEN_ALIASES" | command grep -e "^$ALIAS_TEMP$" > /dev/null; then
|
||||
ALIAS="∞"
|
||||
break
|
||||
fi
|
||||
@@ -325,7 +347,7 @@ nvm_resolve_alias() {
|
||||
|
||||
nvm_ls() {
|
||||
local PATTERN
|
||||
PATTERN=$1
|
||||
PATTERN="$1"
|
||||
local VERSIONS
|
||||
VERSIONS=''
|
||||
if [ "$PATTERN" = 'current' ]; then
|
||||
@@ -348,23 +370,47 @@ nvm_ls() {
|
||||
local NUM_VERSION_GROUPS
|
||||
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
|
||||
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
|
||||
PATTERN="$(echo "$PATTERN" | sed -e 's/\.*$//g')."
|
||||
PATTERN="$(echo "$PATTERN" | command sed -e 's/\.*$//g')."
|
||||
fi
|
||||
fi
|
||||
if [ -d "$(nvm_version_dir new)" ]; then
|
||||
VERSIONS=`find "$(nvm_version_dir new)/" "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v' | \grep -v -e '^versions$'`
|
||||
else
|
||||
VERSIONS=`find "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
|
||||
|
||||
local ZHS_HAS_SHWORDSPLIT_UNSET
|
||||
ZHS_HAS_SHWORDSPLIT_UNSET=1
|
||||
if nvm_has "setopt"; then
|
||||
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
|
||||
setopt shwordsplit
|
||||
fi
|
||||
|
||||
local NVM_DIRS_TO_TEST_AND_SEARCH
|
||||
local NVM_DIRS_TO_SEARCH
|
||||
NVM_DIRS_TO_TEST_AND_SEARCH="$(nvm_version_dir old) $(nvm_version_dir new)"
|
||||
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"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$PATTERN" ]; then
|
||||
PATTERN='v'
|
||||
fi
|
||||
VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \
|
||||
| command sed "s#^$NVM_DIR/##" \
|
||||
| command grep -v -e '^versions$' \
|
||||
| sed -e 's/^v/node-v/' \
|
||||
| command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n \
|
||||
| command sort -s -t- -k1.1,1.1 \
|
||||
| command sed 's/^node-//')"
|
||||
|
||||
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
|
||||
unsetopt shwordsplit
|
||||
fi
|
||||
fi
|
||||
|
||||
if nvm_has_system_node; then
|
||||
if [ -z "$PATTERN" ]; then
|
||||
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
|
||||
if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then
|
||||
VERSIONS="$VERSIONS$(command printf '\n%s' 'system')"
|
||||
elif [ "$PATTERN" = 'system' ]; then
|
||||
VERSIONS="$(printf '%s' 'system')"
|
||||
VERSIONS="$(command printf '%s' 'system')"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -374,7 +420,6 @@ nvm_ls() {
|
||||
fi
|
||||
|
||||
echo "$VERSIONS"
|
||||
return
|
||||
}
|
||||
|
||||
nvm_ls_remote() {
|
||||
@@ -392,7 +437,7 @@ nvm_ls_remote() {
|
||||
fi
|
||||
VERSIONS=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/ -o - \
|
||||
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| \grep -w "${PATTERN}" \
|
||||
| command grep -w "${PATTERN}" \
|
||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
|
||||
if [ -z "$VERSIONS" ]; then
|
||||
echo "N/A"
|
||||
@@ -404,11 +449,11 @@ nvm_ls_remote() {
|
||||
|
||||
nvm_checksum() {
|
||||
if nvm_has "sha1sum"; then
|
||||
checksum="$(sha1sum "$1" | \awk '{print $1}')"
|
||||
checksum="$(sha1sum "$1" | command awk '{print $1}')"
|
||||
elif nvm_has "sha1"; then
|
||||
checksum="$(sha1 -q "$1")"
|
||||
else
|
||||
checksum="$(shasum "$1" | \awk '{print $1}')"
|
||||
checksum="$(shasum "$1" | command awk '{print $1}')"
|
||||
fi
|
||||
|
||||
if [ "_$checksum" = "_$2" ]; then
|
||||
@@ -460,9 +505,9 @@ nvm_print_implicit_alias() {
|
||||
|
||||
local LAST_TWO
|
||||
if [ "_$1" = "_local" ]; then
|
||||
LAST_TWO=$(nvm_ls | \grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
|
||||
LAST_TWO=$(nvm_ls | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
|
||||
else
|
||||
LAST_TWO=$(nvm_ls_remote | \grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
|
||||
LAST_TWO=$(nvm_ls_remote | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
|
||||
fi
|
||||
local MINOR
|
||||
local STABLE
|
||||
@@ -472,7 +517,7 @@ nvm_print_implicit_alias() {
|
||||
local ZHS_HAS_SHWORDSPLIT_UNSET
|
||||
ZHS_HAS_SHWORDSPLIT_UNSET=1
|
||||
if nvm_has "setopt"; then
|
||||
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | \grep shwordsplit > /dev/null ; echo $?)
|
||||
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
|
||||
setopt shwordsplit
|
||||
fi
|
||||
for MINOR in $LAST_TWO; do
|
||||
@@ -494,6 +539,152 @@ nvm_print_implicit_alias() {
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_get_os() {
|
||||
local NVM_UNAME
|
||||
NVM_UNAME="$(uname -a)"
|
||||
local NVM_OS
|
||||
case "$NVM_UNAME" in
|
||||
Linux\ *) NVM_OS=linux ;;
|
||||
Darwin\ *) NVM_OS=darwin ;;
|
||||
SunOS\ *) NVM_OS=sunos ;;
|
||||
FreeBSD\ *) NVM_OS=freebsd ;;
|
||||
esac
|
||||
echo "$NVM_OS"
|
||||
}
|
||||
|
||||
nvm_get_arch() {
|
||||
local NVM_UNAME
|
||||
NVM_UNAME="$(uname -a)"
|
||||
local NVM_ARCH
|
||||
case "$NVM_UNAME" in
|
||||
*x86_64*) NVM_ARCH=x64 ;;
|
||||
*i*86*) NVM_ARCH=x86 ;;
|
||||
*armv6l*) NVM_ARCH=arm-pi ;;
|
||||
*) NVM_ARCH="$(uname -m)" ;;
|
||||
esac
|
||||
echo "$NVM_ARCH"
|
||||
}
|
||||
|
||||
nvm_install_node_binary() {
|
||||
local VERSION
|
||||
VERSION="$1"
|
||||
local REINSTALL_PACKAGES_FROM
|
||||
REINSTALL_PACKAGES_FROM="$2"
|
||||
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "$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_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
||||
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | command grep node-${t}.tar.gz | command awk '{print $1}'`
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/bin/node-${t}"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||
if (
|
||||
command mkdir -p "$tmpdir" && \
|
||||
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
|
||||
command rm -f "$tmptarball" && \
|
||||
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_source() {
|
||||
local VERSION
|
||||
VERSION="$1"
|
||||
local REINSTALL_PACKAGES_FROM
|
||||
REINSTALL_PACKAGES_FROM="$2"
|
||||
local ADDITIONAL_PARAMETERS
|
||||
ADDITIONAL_PARAMETERS="$3"
|
||||
|
||||
if [ -n "$ADDITIONAL_PARAMETERS" ]; then
|
||||
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
|
||||
fi
|
||||
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "$VERSION")"
|
||||
local NVM_OS
|
||||
NVM_OS="$(nvm_get_os)"
|
||||
|
||||
local tarball
|
||||
tarball=''
|
||||
local sum
|
||||
sum=''
|
||||
local make
|
||||
make='make'
|
||||
if [ "_$NVM_OS" = "_freebsd" ]; then
|
||||
make='gmake'
|
||||
MAKE_CXX="CXX=c++"
|
||||
fi
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/src"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||
|
||||
if [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - 2>&1 | command grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
||||
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | command grep "node-$VERSION.tar.gz" | command awk '{print $1}'`
|
||||
elif [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | command grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
|
||||
fi
|
||||
|
||||
if (
|
||||
[ -n "$tarball" ] && \
|
||||
command mkdir -p "$tmpdir" && \
|
||||
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
command tar -xzf "$tmptarball" -C "$tmpdir" && \
|
||||
cd "$tmpdir/node-$VERSION" && \
|
||||
./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \
|
||||
$make $MAKE_CXX && \
|
||||
command rm -f "$VERSION_PATH" 2>/dev/null && \
|
||||
$make $MAKE_CXX install
|
||||
)
|
||||
then
|
||||
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
|
||||
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
|
||||
fi
|
||||
if ! nvm_has "npm" ; then
|
||||
echo "Installing npm..."
|
||||
if nvm_version_greater 0.2.0 "$VERSION"; then
|
||||
echo "npm requires node v0.2.3 or higher" >&2
|
||||
elif nvm_version_greater_than_or_equal_to "$VERSION" 0.2.0; then
|
||||
if nvm_version_greater 0.2.3 "$VERSION"; then
|
||||
echo "npm requires node v0.2.3 or higher" >&2
|
||||
else
|
||||
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
|
||||
fi
|
||||
else
|
||||
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes sh
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "nvm: install $VERSION failed!" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
return $?
|
||||
}
|
||||
|
||||
nvm() {
|
||||
if [ $# -lt 1 ]; then
|
||||
nvm help
|
||||
@@ -501,24 +692,10 @@ nvm() {
|
||||
fi
|
||||
|
||||
# Try to figure out the os and arch for binary fetching
|
||||
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 ;;
|
||||
SunOS\ *) os=sunos ;;
|
||||
FreeBSD\ *) os=freebsd ;;
|
||||
esac
|
||||
case "$uname" in
|
||||
*x86_64*) arch=x64 ;;
|
||||
*i*86*) arch=x86 ;;
|
||||
*armv6l*) arch=arm-pi ;;
|
||||
esac
|
||||
|
||||
# initialize local variables
|
||||
local VERSION
|
||||
@@ -547,6 +724,7 @@ nvm() {
|
||||
echo " nvm unalias <name> Deletes the alias named <name>"
|
||||
echo " nvm reinstall-packages <version> Reinstall global \`npm\` packages contained in <version> to current version"
|
||||
echo " nvm unload Unload \`nvm\` from shell"
|
||||
echo " nvm which [<version>] Display path to installed node version. Uses .nvmrc if available"
|
||||
echo
|
||||
echo "Example:"
|
||||
echo " nvm install v0.10.32 Install a specific version number"
|
||||
@@ -561,16 +739,12 @@ nvm() {
|
||||
;;
|
||||
|
||||
"install" | "i" )
|
||||
# initialize local variables
|
||||
local binavail
|
||||
local t
|
||||
local url
|
||||
local sum
|
||||
local tarball
|
||||
local nobinary
|
||||
local version_not_provided
|
||||
version_not_provided=0
|
||||
local provided_version
|
||||
local NVM_OS
|
||||
NVM_OS="$(nvm_get_os)"
|
||||
|
||||
if ! nvm_has "curl" && ! nvm_has "wget"; then
|
||||
echo 'nvm needs curl or wget to proceed.' >&2;
|
||||
@@ -589,12 +763,12 @@ nvm() {
|
||||
shift
|
||||
|
||||
nobinary=0
|
||||
if [ "$1" = "-s" ]; then
|
||||
if [ "_$1" = "_-s" ]; then
|
||||
nobinary=1
|
||||
shift
|
||||
fi
|
||||
|
||||
if [ "$os" = "freebsd" ]; then
|
||||
if [ "_$NVM_OS" = "_freebsd" ]; then
|
||||
nobinary=1
|
||||
fi
|
||||
|
||||
@@ -616,11 +790,11 @@ nvm() {
|
||||
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
if [ "_$(echo "$1" | cut -c 1-26)" = "_--reinstall-packages-from=" ]; then
|
||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 27-)"
|
||||
if [ "_$(echo "$1" | command cut -c 1-26)" = "_--reinstall-packages-from=" ]; then
|
||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 27-)"
|
||||
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
|
||||
elif [ "_$(echo "$1" | cut -c 1-21)" = "_--copy-packages-from=" ]; then
|
||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 22-)"
|
||||
elif [ "_$(echo "$1" | command cut -c 1-21)" = "_--copy-packages-from=" ]; then
|
||||
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 22-)"
|
||||
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
|
||||
else
|
||||
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
|
||||
@@ -636,7 +810,9 @@ nvm() {
|
||||
return 5
|
||||
fi
|
||||
|
||||
if [ -d "$(nvm_version_path "$VERSION")" ]; then
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "$VERSION")"
|
||||
if [ -d "$VERSION_PATH" ]; then
|
||||
echo "$VERSION is already installed." >&2
|
||||
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
|
||||
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
|
||||
@@ -644,136 +820,60 @@ nvm() {
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$VERSION" = "N/A" ]; then
|
||||
if [ "_$VERSION" = "_N/A" ]; then
|
||||
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2
|
||||
return 3
|
||||
fi
|
||||
|
||||
# skip binary install if no binary option specified.
|
||||
if [ $nobinary -ne 1 ]; then
|
||||
# shortcut - try the binary if possible.
|
||||
if [ -n "$os" ]; then
|
||||
if nvm_binary_available "$VERSION"; then
|
||||
t="$VERSION-$os-$arch"
|
||||
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
||||
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-${t}.tar.gz | \awk '{print $1}'`
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/bin/node-${t}"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||
if (
|
||||
mkdir -p "$tmpdir" && \
|
||||
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
|
||||
rm -f "$tmptarball" && \
|
||||
mv "$tmpdir" "$(nvm_version_path "$VERSION")"
|
||||
)
|
||||
then
|
||||
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
|
||||
# skip binary install if "nobinary" option specified.
|
||||
if [ $nobinary -ne 1 ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
|
||||
if nvm use "$VERSION" \
|
||||
&& [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
|
||||
&& [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
|
||||
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
|
||||
fi
|
||||
return $?
|
||||
else
|
||||
echo "Binary download failed, trying source." >&2
|
||||
rm -rf "$tmptarball" "$tmpdir"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$ADDITIONAL_PARAMETERS" ]; then
|
||||
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
|
||||
fi
|
||||
|
||||
tarball=''
|
||||
sum=''
|
||||
make='make'
|
||||
if [ "$os" = "freebsd" ]; then
|
||||
make='gmake'
|
||||
MAKE_CXX="CXX=c++"
|
||||
fi
|
||||
local tmpdir
|
||||
tmpdir="$NVM_DIR/src"
|
||||
local tmptarball
|
||||
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||
if [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - 2>&1 | \grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
||||
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-$VERSION.tar.gz | \awk '{print $1}'`
|
||||
elif [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | \grep '200 OK'`" != '' ]; then
|
||||
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
|
||||
fi
|
||||
if (
|
||||
[ -n "$tarball" ] && \
|
||||
mkdir -p "$tmpdir" && \
|
||||
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \
|
||||
nvm_checksum "$tmptarball" $sum && \
|
||||
tar -xzf "$tmptarball" -C "$tmpdir" && \
|
||||
cd "$tmpdir/node-$VERSION" && \
|
||||
./configure --prefix="$(nvm_version_path "$VERSION")" $ADDITIONAL_PARAMETERS && \
|
||||
$make $MAKE_CXX && \
|
||||
rm -f "$(nvm_version_path "$VERSION")" 2>/dev/null && \
|
||||
$make $MAKE_CXX install
|
||||
)
|
||||
then
|
||||
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
|
||||
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
|
||||
fi
|
||||
if ! nvm_has "npm" ; then
|
||||
echo "Installing npm..."
|
||||
if nvm_version_greater 0.2.0 "$VERSION"; then
|
||||
echo "npm requires node v0.2.3 or higher" >&2
|
||||
elif nvm_version_greater_than_or_equal_to "$VERSION" 0.2.0; then
|
||||
if nvm_version_greater 0.2.3 "$VERSION"; then
|
||||
echo "npm requires node v0.2.3 or higher" >&2
|
||||
else
|
||||
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
|
||||
fi
|
||||
else
|
||||
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes sh
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "nvm: install $VERSION failed!" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
return $?
|
||||
nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
|
||||
;;
|
||||
"uninstall" )
|
||||
[ $# -ne 2 ] && nvm help && return
|
||||
PATTERN=`nvm_ensure_version_prefix $2`
|
||||
if [ "$PATTERN" = `nvm_version` ]; then
|
||||
PATTERN="$(nvm_ensure_version_prefix "$2")"
|
||||
if [ "_$PATTERN" = "_$(nvm_version)" ]; then
|
||||
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
|
||||
return 1
|
||||
fi
|
||||
VERSION=`nvm_version $PATTERN`
|
||||
if [ ! -d "$(nvm_version_path "$VERSION")" ]; then
|
||||
local VERSION
|
||||
VERSION="$(nvm_version "$PATTERN")"
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "$VERSION")"
|
||||
if [ ! -d "$VERSION_PATH" ]; then
|
||||
echo "$VERSION version is not installed..." >&2
|
||||
return;
|
||||
fi
|
||||
|
||||
t="$VERSION-$os-$arch"
|
||||
t="$VERSION-$(nvm_get_os)-$(nvm_get_arch)"
|
||||
|
||||
# Delete all files related to target version.
|
||||
rm -rf "$NVM_DIR/src/node-$VERSION" \
|
||||
command rm -rf "$NVM_DIR/src/node-$VERSION" \
|
||||
"$NVM_DIR/src/node-$VERSION.tar.gz" \
|
||||
"$NVM_DIR/bin/node-${t}" \
|
||||
"$NVM_DIR/bin/node-${t}.tar.gz" \
|
||||
"$(nvm_version_path "$VERSION")" 2>/dev/null
|
||||
"$VERSION_PATH" 2>/dev/null
|
||||
echo "Uninstalled node $VERSION"
|
||||
|
||||
# Rm any aliases that point to uninstalled version.
|
||||
for ALIAS in `\grep -l $VERSION $NVM_DIR/alias/* 2>/dev/null`
|
||||
for ALIAS in `command grep -l $VERSION "$(nvm_alias_path)/*" 2>/dev/null`
|
||||
do
|
||||
nvm unalias `basename $ALIAS`
|
||||
nvm unalias "$(command basename "$ALIAS")"
|
||||
done
|
||||
|
||||
;;
|
||||
"deactivate" )
|
||||
local NEWPATH
|
||||
NEWPATH="$(nvm_strip_path "$PATH" "/bin")"
|
||||
if [ "$PATH" = "$NEWPATH" ]; then
|
||||
if [ "_$PATH" = "_$NEWPATH" ]; then
|
||||
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
|
||||
else
|
||||
export PATH="$NEWPATH"
|
||||
@@ -782,7 +882,7 @@ nvm() {
|
||||
fi
|
||||
|
||||
NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")"
|
||||
if [ "$MANPATH" = "$NEWPATH" ]; then
|
||||
if [ "_$MANPATH" = "_$NEWPATH" ]; then
|
||||
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
|
||||
else
|
||||
export MANPATH="$NEWPATH"
|
||||
@@ -790,7 +890,7 @@ nvm() {
|
||||
fi
|
||||
|
||||
NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"
|
||||
if [ "$NODE_PATH" != "$NEWPATH" ]; then
|
||||
if [ "_$NODE_PATH" != "_$NEWPATH" ]; then
|
||||
export NODE_PATH="$NEWPATH"
|
||||
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
|
||||
fi
|
||||
@@ -803,7 +903,7 @@ nvm() {
|
||||
if [ $# -eq 1 ]; then
|
||||
nvm_rc_version
|
||||
if [ -n "$NVM_RC_VERSION" ]; then
|
||||
VERSION=`nvm_version $NVM_RC_VERSION`
|
||||
VERSION="$(nvm_version "$NVM_RC_VERSION")"
|
||||
fi
|
||||
elif [ "_$2" != '_system' ]; then
|
||||
VERSION="$(nvm_version "$2")"
|
||||
@@ -835,17 +935,17 @@ nvm() {
|
||||
return 1
|
||||
fi
|
||||
# Strip other version from PATH
|
||||
PATH=`nvm_strip_path "$PATH" "/bin"`
|
||||
PATH="$(nvm_strip_path "$PATH" "/bin")"
|
||||
# Prepend current version
|
||||
PATH=`nvm_prepend_path "$PATH" "$NVM_VERSION_DIR/bin"`
|
||||
PATH="$(nvm_prepend_path "$PATH" "$NVM_VERSION_DIR/bin")"
|
||||
if nvm_has manpath; then
|
||||
if [ -z "$MANPATH" ]; then
|
||||
MANPATH=$(manpath)
|
||||
fi
|
||||
# Strip other version from MANPATH
|
||||
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
|
||||
MANPATH="$(nvm_strip_path "$MANPATH" "/share/man")"
|
||||
# Prepend current version
|
||||
MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_VERSION_DIR/share/man"`
|
||||
MANPATH="$(nvm_prepend_path "$MANPATH" "$NVM_VERSION_DIR/share/man")"
|
||||
export MANPATH
|
||||
fi
|
||||
export PATH
|
||||
@@ -853,7 +953,7 @@ nvm() {
|
||||
export NVM_PATH="$NVM_VERSION_DIR/lib/node"
|
||||
export NVM_BIN="$NVM_VERSION_DIR/bin"
|
||||
if [ "$NVM_SYMLINK_CURRENT" = true ]; then
|
||||
rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
|
||||
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
|
||||
fi
|
||||
echo "Now using node $VERSION"
|
||||
;;
|
||||
@@ -866,7 +966,7 @@ nvm() {
|
||||
if [ $# -lt 1 ]; then
|
||||
nvm_rc_version && has_checked_nvmrc=1
|
||||
if [ -n "$NVM_RC_VERSION" ]; then
|
||||
VERSION=`nvm_version $NVM_RC_VERSION`
|
||||
VERSION="$(nvm_version "$NVM_RC_VERSION")"
|
||||
else
|
||||
VERSION='N/A'
|
||||
fi
|
||||
@@ -878,13 +978,13 @@ nvm() {
|
||||
|
||||
provided_version=$1
|
||||
if [ -n "$provided_version" ]; then
|
||||
VERSION=`nvm_version $provided_version`
|
||||
VERSION="$(nvm_version "$provided_version")"
|
||||
if [ "_$VERSION" = "_N/A" ]; then
|
||||
provided_version=''
|
||||
if [ $has_checked_nvmrc -ne 1 ]; then
|
||||
nvm_rc_version && has_checked_nvmrc=1
|
||||
fi
|
||||
VERSION=`nvm_version $NVM_RC_VERSION`
|
||||
VERSION="$(nvm_version "$NVM_RC_VERSION")"
|
||||
else
|
||||
shift
|
||||
fi
|
||||
@@ -906,8 +1006,8 @@ nvm() {
|
||||
local provided_version
|
||||
provided_version="$1"
|
||||
if [ -n "$provided_version" ]; then
|
||||
VERSION=`nvm_version $provided_version`
|
||||
if [ $VERSION = "N/A" ]; then
|
||||
VERSION="$(nvm_version "$provided_version")"
|
||||
if [ "_$VERSION" = "_N/A" ]; then
|
||||
provided_version=''
|
||||
nvm_rc_version
|
||||
VERSION="$(nvm_version "$NVM_RC_VERSION")"
|
||||
@@ -917,13 +1017,13 @@ nvm() {
|
||||
fi
|
||||
|
||||
local NVM_VERSION_DIR
|
||||
NVM_VERSION_DIR=$(nvm_version_path "$VERSION")
|
||||
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
|
||||
if [ ! -d "$NVM_VERSION_DIR" ]; then
|
||||
echo "$VERSION version is not installed yet" >&2
|
||||
return 1
|
||||
fi
|
||||
echo "Running node $VERSION"
|
||||
NODE_VERSION=$VERSION $NVM_DIR/nvm-exec "$@"
|
||||
NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
|
||||
;;
|
||||
"ls" | "list" )
|
||||
local NVM_LS_OUTPUT
|
||||
@@ -946,12 +1046,57 @@ nvm() {
|
||||
"current" )
|
||||
nvm_version current
|
||||
;;
|
||||
"which" )
|
||||
if [ $# -eq 1 ]; then
|
||||
nvm_rc_version
|
||||
if [ -n "$NVM_RC_VERSION" ]; then
|
||||
VERSION=$(nvm_version "$NVM_RC_VERSION")
|
||||
fi
|
||||
elif [ "_$2" != '_system' ]; then
|
||||
VERSION="$(nvm_version "$2")"
|
||||
else
|
||||
VERSION="$2"
|
||||
fi
|
||||
if [ -z "$VERSION" ]; then
|
||||
nvm help
|
||||
return 127
|
||||
fi
|
||||
|
||||
if [ "_$VERSION" = '_system' ]; then
|
||||
if nvm_has_system_node >/dev/null 2>&1; then
|
||||
local NVM_BIN
|
||||
NVM_BIN="$(nvm use system >/dev/null 2>&1 && command which node)"
|
||||
if [ -n "$NVM_BIN" ]; then
|
||||
echo "$NVM_BIN"
|
||||
return
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "System version of node not found." >&2
|
||||
return 127
|
||||
fi
|
||||
elif [ "_$VERSION" = "_∞" ]; then
|
||||
echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2
|
||||
return 8
|
||||
fi
|
||||
|
||||
local NVM_VERSION_DIR
|
||||
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
|
||||
if [ ! -d "$NVM_VERSION_DIR" ]; then
|
||||
echo "$VERSION version is not installed yet" >&2
|
||||
return 1
|
||||
fi
|
||||
echo "$NVM_VERSION_DIR/bin/node"
|
||||
;;
|
||||
"alias" )
|
||||
mkdir -p "$NVM_DIR/alias"
|
||||
local NVM_ALIAS_DIR
|
||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||
command mkdir -p "$NVM_ALIAS_DIR"
|
||||
if [ $# -le 2 ]; then
|
||||
local DEST
|
||||
for ALIAS_PATH in "$NVM_DIR"/alias/"$2"*; do
|
||||
ALIAS="$(basename "$ALIAS_PATH")"
|
||||
for ALIAS_PATH in "$NVM_ALIAS_DIR"/"$2"*; do
|
||||
ALIAS="$(command basename "$ALIAS_PATH")"
|
||||
DEST="$(nvm_alias "$ALIAS" 2> /dev/null)"
|
||||
if [ -n "$DEST" ]; then
|
||||
VERSION="$(nvm_version "$DEST")"
|
||||
@@ -964,7 +1109,7 @@ nvm() {
|
||||
done
|
||||
|
||||
for ALIAS in "stable" "unstable"; do
|
||||
if [ ! -f "$NVM_DIR/alias/$ALIAS" ]; then
|
||||
if [ ! -f "$NVM_ALIAS_DIR/$ALIAS" ]; then
|
||||
if [ $# -lt 2 ] || [ "~$ALIAS" = "~$2" ]; then
|
||||
DEST="$(nvm_print_implicit_alias local "$ALIAS")"
|
||||
if [ "_$DEST" != "_" ]; then
|
||||
@@ -977,7 +1122,7 @@ nvm() {
|
||||
return
|
||||
fi
|
||||
if [ -z "$3" ]; then
|
||||
rm -f "$NVM_DIR/alias/$2"
|
||||
command rm -f "$NVM_ALIAS_DIR/$2"
|
||||
echo "$2 -> *poof*"
|
||||
return
|
||||
fi
|
||||
@@ -985,7 +1130,7 @@ nvm() {
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "! WARNING: Version '$3' does not exist." >&2
|
||||
fi
|
||||
echo $3 > "$NVM_DIR/alias/$2"
|
||||
echo "$3" > "$NVM_ALIAS_DIR/$2"
|
||||
if [ ! "_$3" = "_$VERSION" ]; then
|
||||
echo "$2 -> $3 (-> $VERSION)"
|
||||
else
|
||||
@@ -993,10 +1138,12 @@ nvm() {
|
||||
fi
|
||||
;;
|
||||
"unalias" )
|
||||
mkdir -p $NVM_DIR/alias
|
||||
local NVM_ALIAS_DIR
|
||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||
command mkdir -p "$NVM_ALIAS_DIR"
|
||||
[ $# -ne 2 ] && nvm help && return 127
|
||||
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
|
||||
rm -f $NVM_DIR/alias/$2
|
||||
[ ! -f "$NVM_ALIAS_DIR/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
|
||||
command rm -f "$NVM_ALIAS_DIR/$2"
|
||||
echo "Deleted alias $2"
|
||||
;;
|
||||
"reinstall-packages" | "copy-packages" )
|
||||
@@ -1008,39 +1155,39 @@ nvm() {
|
||||
local PROVIDED_VERSION
|
||||
PROVIDED_VERSION="$2"
|
||||
|
||||
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version $PROVIDED_VERSION)" = "$(nvm_ls_current)" ]; then
|
||||
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version "$PROVIDED_VERSION")" = "$(nvm_ls_current)" ]; then
|
||||
echo 'Can not reinstall packages from the current version of node.' >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
local INSTALLS
|
||||
if [ "$PROVIDED_VERSION" = "system" ]; then
|
||||
if [ "_$PROVIDED_VERSION" = "_system" ]; then
|
||||
if ! nvm_has_system_node; then
|
||||
echo 'No system version of node detected.' >&2
|
||||
return 3
|
||||
fi
|
||||
INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||
INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2 | command grep -o -e ' [^@]*' | command cut -c 2- | command grep -v npm | command xargs)
|
||||
else
|
||||
local VERSION
|
||||
VERSION="$(nvm_version "$PROVIDED_VERSION")"
|
||||
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2 | command grep -o -e ' [^@]*' | command cut -c 2- | command grep -v npm | command xargs)
|
||||
fi
|
||||
|
||||
echo "Copying global packages from $VERSION..."
|
||||
echo "$INSTALLS" | xargs npm install -g --quiet
|
||||
echo "$INSTALLS" | command xargs npm install -g --quiet
|
||||
;;
|
||||
"clear-cache" )
|
||||
rm -f $NVM_DIR/v* "$(nvm_version_dir)" 2>/dev/null
|
||||
command rm -f $NVM_DIR/v* "$(nvm_version_dir)" 2>/dev/null
|
||||
echo "Cache cleared."
|
||||
;;
|
||||
"version" )
|
||||
nvm_version $2
|
||||
;;
|
||||
"--version" )
|
||||
echo "0.20.0"
|
||||
echo "0.22.2"
|
||||
;;
|
||||
"unload" )
|
||||
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to > /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 nvm_version_greater nvm_version_greater_than_or_equal_to nvm_supports_source_options > /dev/null 2>&1
|
||||
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
|
||||
;;
|
||||
* )
|
||||
@@ -1049,7 +1196,18 @@ nvm() {
|
||||
esac
|
||||
}
|
||||
|
||||
if nvm ls default >/dev/null; then
|
||||
nvm_supports_source_options() {
|
||||
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||
}
|
||||
|
||||
if nvm_supports_source_options && [ "_$1" = "_--install" ]; then
|
||||
VERSION="$(nvm_alias default 2>/dev/null)"
|
||||
if [ -n "$VERSION" ]; then
|
||||
nvm install "$VERSION" >/dev/null
|
||||
elif nvm_rc_version >/dev/null 2>&1; then
|
||||
nvm install >/dev/null
|
||||
fi
|
||||
elif nvm ls default >/dev/null; then
|
||||
nvm use default >/dev/null
|
||||
elif nvm_rc_version >/dev/null 2>&1; then
|
||||
nvm use >/dev/null
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.20.0",
|
||||
"version": "0.22.2",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
@@ -31,7 +31,7 @@
|
||||
"homepage": "https://github.com/creationix/nvm",
|
||||
"devDependencies": {
|
||||
"replace": "~0.3.0",
|
||||
"semver": "~4.1.0",
|
||||
"urchin": "~0.0.4"
|
||||
"semver": "~4.2.0",
|
||||
"urchin": "~0.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir -p ../../../v0.0.2
|
||||
mkdir -p ../../../v0.0.20
|
||||
mkdir -p ../../../versions/node/v0.12.0
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
|
||||
nvm which 0.0.2 || die "v0.0.2 not found"
|
||||
NVM_BIN="$(nvm which 0.0.2)"
|
||||
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.2)/bin/node" ] \
|
||||
|| die "'nvm which 0.0.2' did not contain the correct path: got '$NVM_BIN'"
|
||||
|
||||
nvm which 0.0.20 || die "v0.0.20 not found"
|
||||
NVM_BIN="$(nvm which 0.0.20)"
|
||||
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.20)/bin/node" ] \
|
||||
|| die "'nvm which 0.20.0' did not contain the correct path: got '$NVM_BIN'"
|
||||
|
||||
nvm which 0.12.0 || die "v0.0.20 not found"
|
||||
NVM_BIN="$(nvm which 0.12.0)"
|
||||
[ "_$NVM_BIN" = "_$(nvm_version_path v0.12.0)/bin/node" ] \
|
||||
|| die "'nvm which 0.12.0' did not contain the correct path: got '$NVM_BIN'"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
nvm which nonexistent_version
|
||||
[ "_$?" = "_1" ]
|
||||
3
test/fast/Listing paths/teardown
Executable file
3
test/fast/Listing paths/teardown
Executable file
@@ -0,0 +1,3 @@
|
||||
rmdir ../../../v0.0.2 >/dev/null 2>&1
|
||||
rmdir ../../../v0.0.20 >/dev/null 2>&1
|
||||
rmdir ../../../v0.12.0 >/dev/null 2>&1
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
mkdir ../../../v0.1.3
|
||||
mkdir ../../../v0.2.3
|
||||
mkdir ../../../versions
|
||||
mkdir -p ../../../versions/node
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
mkdir -p ../../../versions/v0.12.1
|
||||
mkdir -p ../../../versions/node/v0.12.1
|
||||
mkdir ../../../v0.1.3
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
@@ -7,9 +7,11 @@ 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 &&
|
||||
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "Failed to activate v0.2.3"
|
||||
nvm use 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
|
||||
|
||||
nvm deactivate &&
|
||||
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "Failed to deactivate v0.2.3"
|
||||
nvm deactivate || die "Failed to deactivate v0.2.3"
|
||||
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly"
|
||||
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly"
|
||||
|
||||
8
test/fast/Unit tests/nvm_alias_path
Executable file
8
test/fast/Unit tests/nvm_alias_path
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
[ "_$(nvm_alias_path)" = "_$NVM_DIR/alias" ] || die "nvm_alias_path did not requrn correct location"
|
||||
|
||||
9
test/fast/Unit tests/nvm_ensure_version_prefix
Executable file
9
test/fast/Unit tests/nvm_ensure_version_prefix
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
[ "_$(nvm_ensure_version_prefix 1)" = "_v1" ] || die '"nvm_ensure_version_prefix 1" did not return "v1"'
|
||||
[ "_$(nvm_ensure_version_prefix v1)" = "_v1" ] || die '"nvm_ensure_version_prefix v1" did not return "v1"'
|
||||
[ "_$(nvm_ensure_version_prefix foo)" = "_foo" ] || die '"nvm_ensure_version_prefix foo" did not return "foo"'
|
||||
20
test/fast/Unit tests/nvm_get_latest missing curl or wget
Executable file
20
test/fast/Unit tests/nvm_get_latest missing curl or wget
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
unset -f nvm_has
|
||||
}
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
nvm_has() { return 1 ; }
|
||||
|
||||
OUTPUT="$(nvm_get_latest 2>&1)"
|
||||
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_nvm needs curl or wget to proceed." ] \
|
||||
|| die "no curl/wget did not report correct error message, got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_1" ] \
|
||||
|| die "no curl/wget did not exit with code 1, got $EXIT_CODE"
|
||||
|
||||
cleanup
|
||||
@@ -1,6 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
TEST_PWD=$(pwd)
|
||||
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"
|
||||
|
||||
cleanup() { rm -rf "$TEST_DIR"; unset -f return_zero; unalias node; }
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
@@ -8,12 +12,10 @@ return_zero () { return 0; }
|
||||
|
||||
[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'
|
||||
|
||||
TEST_PWD=$(pwd)
|
||||
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"
|
||||
rm -rf "$TEST_DIR"
|
||||
mkdir "$TEST_DIR"
|
||||
ln -s "$(which which)" "$TEST_DIR/which"
|
||||
ln -s "$(which dirname)" "$TEST_DIR/dirname"
|
||||
ln -s "$(command which which)" "$TEST_DIR/which"
|
||||
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
|
||||
|
||||
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"'
|
||||
[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'
|
||||
@@ -24,5 +26,7 @@ chmod a+x "$TEST_DIR/node"
|
||||
|
||||
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
|
||||
|
||||
rm -rf "$TEST_DIR"
|
||||
alias node='node --harmony'
|
||||
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
|
||||
|
||||
cleanup
|
||||
|
||||
@@ -4,7 +4,7 @@ die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path'
|
||||
[ "$(nvm_version_dir)" = "$NVM_DIR/versions/node" ] || die '"nvm_version_dir" did not return new dir path'
|
||||
[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path'
|
||||
[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path'
|
||||
[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out'
|
||||
|
||||
@@ -7,5 +7,5 @@ die () { echo $@ ; exit 1; }
|
||||
[ "$(nvm_version_path foo)" = "$NVM_DIR/foo" ] || die '"nvm_version_path foo" did not return correct location'
|
||||
[ "$(nvm_version_path 2>&1)" = "version is required" ] || die '"nvm_version_path" did not error out'
|
||||
[ "$(nvm_version_path v0.11.0)" = "$NVM_DIR/v0.11.0" ] || die 'old version has the wrong path'
|
||||
[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/v0.12.0" ] || die 'new version has the wrong path'
|
||||
[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/node/v0.12.0" ] || die 'new version has the wrong path'
|
||||
|
||||
|
||||
117
test/installation/nvm_get_latest/nvm_get_latest
Executable file
117
test/installation/nvm_get_latest/nvm_get_latest
Executable file
@@ -0,0 +1,117 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
unset -f curl wget nvm_has
|
||||
}
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
EXPECTED_VERSION="v12.3.456"
|
||||
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_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"
|
||||
|
||||
curl() {
|
||||
if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then
|
||||
echo 2>& "expected args ($EXPECTED_CURL_ARGS), got ($*)"
|
||||
return 1
|
||||
else
|
||||
echo $URL
|
||||
fi
|
||||
}
|
||||
wget() {
|
||||
if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then
|
||||
echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)"
|
||||
return 1
|
||||
else
|
||||
local WGET_CONTENTS
|
||||
WGET_CONTENTS="
|
||||
--2014-12-21 18:11:14-- http://latest.nvm.sh/
|
||||
Resolving latest.nvm.sh... 50.31.209.229
|
||||
Connecting to latest.nvm.sh|50.31.209.229|:80... connected.
|
||||
HTTP request sent, awaiting response...
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
Location: https://github.com/creationix/nvm/releases/latest
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Content-Length: 84
|
||||
Date: Mon, 22 Dec 2014 02:11:15 GMT
|
||||
Location: https://github.com/creationix/nvm/releases/latest [following]
|
||||
--2014-12-21 18:11:15-- https://github.com/creationix/nvm/releases/latest
|
||||
Resolving github.com... 192.30.252.130
|
||||
Connecting to github.com|192.30.252.130|:443... connected.
|
||||
HTTP request sent, awaiting response...
|
||||
HTTP/1.1 302 Found
|
||||
Server: GitHub.com
|
||||
Date: Mon, 22 Dec 2014 02:11:15 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Transfer-Encoding: chunked
|
||||
Status: 302 Found
|
||||
X-XSS-Protection: 1; mode=block
|
||||
X-Frame-Options: deny
|
||||
Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com
|
||||
Cache-Control: no-cache
|
||||
Vary: X-PJAX
|
||||
Location: $URL
|
||||
X-UA-Compatible: IE=Edge,chrome=1
|
||||
Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Fri, 22-Dec-2034 02:11:15 GMT; secure; HttpOnly
|
||||
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzV9--e2fa4cf5305d61aa58c0e0bf21fdb335a9660dcf; path=/; secure; HttpOnly
|
||||
X-Request-Id: 4b99bf200157dd845f76ab83e4093acc
|
||||
X-Runtime: 0.030872
|
||||
X-Rack-Cache: miss
|
||||
X-GitHub-Request-Id: 45B56780:3913:880EF6:54977DC3
|
||||
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
|
||||
X-Content-Type-Options: nosniff
|
||||
Vary: Accept-Encoding
|
||||
X-Served-By: ef97014f01ea59c1ef337fe51a4d0331
|
||||
Location: $URL [following]
|
||||
--2014-12-21 18:11:15-- $URL
|
||||
Reusing existing connection to github.com:443.
|
||||
HTTP request sent, awaiting response...
|
||||
HTTP/1.1 200 OK
|
||||
Server: GitHub.com
|
||||
Date: Mon, 22 Dec 2014 02:11:15 GMT
|
||||
Content-Type: text/html; charset=utf-8
|
||||
Transfer-Encoding: chunked
|
||||
Status: 200 OK
|
||||
X-XSS-Protection: 1; mode=block
|
||||
X-Frame-Options: deny
|
||||
Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com
|
||||
Cache-Control: no-cache, private
|
||||
Vary: X-PJAX
|
||||
X-UA-Compatible: IE=Edge,chrome=1
|
||||
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzUsIl9jc3JmX3Rva2VuIjoiemZTVDNIRGo0QzF0dzkyNXp6NFBRdGJVbTl4NSsxTGo1cngwVFQ3NDVwdz0ifQ%3D%3D--b72bfd5241907dcf557b226e74351ff39f0e9ede; path=/; secure; HttpOnly
|
||||
X-Request-Id: 305b0d158bf8c0b3fa488a33d7687091
|
||||
X-Runtime: 0.038544
|
||||
X-Rack-Cache: miss
|
||||
X-GitHub-Request-Id: 45B56780:3913:880F19:54977DC3
|
||||
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
|
||||
X-Content-Type-Options: nosniff
|
||||
Vary: Accept-Encoding
|
||||
X-Served-By: 926b734ea1992f8ee1f88ab967a93dac
|
||||
Length: unspecified [text/html]
|
||||
Saving to: ‘/dev/null’
|
||||
|
||||
0K .......... ......... 225K=0.09s
|
||||
|
||||
2014-12-21 18:11:15 (225 KB/s) - ‘/dev/null’ saved [20298]
|
||||
|
||||
"
|
||||
"$WGET_CONTENTS" | while read line
|
||||
do
|
||||
2>& echo "$line"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
OUTPUT="$(nvm_get_latest)"
|
||||
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_VERSION" ] \
|
||||
|| die "success path did not return version '$EXPECTED_VERSION', got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_0" ] \
|
||||
|| die "success path did not exit with code 0, got $EXIT_CODE"
|
||||
|
||||
|
||||
cleanup
|
||||
|
||||
26
test/installation/nvm_get_latest/nvm_get_latest failed redirect
Executable file
26
test/installation/nvm_get_latest/nvm_get_latest failed redirect
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
unset -f curl wget
|
||||
}
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
curl() {
|
||||
return 1
|
||||
}
|
||||
wget() {
|
||||
return 1
|
||||
}
|
||||
|
||||
OUTPUT="$(nvm_get_latest 2>&1)"
|
||||
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
|
||||
[ "_$OUTPUT" = "_http://latest.nvm.sh did not redirect to the latest release on Github" ] \
|
||||
|| die "failed redirect did not report correct error message, got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_2" ] \
|
||||
|| die "failed redirect did not exit with code 2, got $EXIT_CODE"
|
||||
|
||||
cleanup
|
||||
|
||||
28
test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it
Executable file
28
test/sourcing/Sourcing nvm.sh with --install and .nvmrc should install it
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
supports_source_options () {
|
||||
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||
}
|
||||
|
||||
if ! supports_source_options; then
|
||||
echo 'this shell does not support passing options on sourcing'
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo '0.10.2' > ../../.nvmrc || die 'creation of .nvmrc failed'
|
||||
|
||||
. ../../nvm.sh --install
|
||||
EXIT_CODE="$(echo $?)"
|
||||
|
||||
echo 'sourcing complete.'
|
||||
|
||||
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)"
|
||||
|
||||
[ "_$(nvm_rc_version | \grep -o -e 'with version .*$')" = "_with version <0.10.2>" ] || die "nvm_rc_version $(nvm_rc_version)"
|
||||
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
|
||||
|
||||
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)"
|
||||
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT' `nvm ls`"
|
||||
|
||||
32
test/sourcing/Sourcing nvm.sh with --install should install the default
Executable file
32
test/sourcing/Sourcing nvm.sh with --install should install the default
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
supports_source_options () {
|
||||
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||
}
|
||||
|
||||
if ! supports_source_options; then
|
||||
echo 'this shell does not support passing options on sourcing'
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
echo '0.10.2' > ../../alias/default || die 'creation of default alias failed'
|
||||
|
||||
echo 'sourcing nvm with --install...'
|
||||
|
||||
. ../../nvm.sh --install
|
||||
EXIT_CODE="$(echo $?)"
|
||||
|
||||
echo 'sourcing complete.'
|
||||
|
||||
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)"
|
||||
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE"
|
||||
|
||||
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)"
|
||||
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT'"
|
||||
|
||||
NVM_ALIAS_DEFAULT="$(nvm alias default)"
|
||||
[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \
|
||||
|| die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got '$NVM_ALIAS_DEFAULT'"
|
||||
|
||||
Reference in New Issue
Block a user