Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
8964cb46d3 | ||
|
|
383f39ab61 | ||
|
|
052743816f | ||
|
|
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.19.0/install.sh | bash
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.22.1/install.sh | bash
|
||||
|
||||
or Wget:
|
||||
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.19.0/install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.22.1/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.19.0/install.sh
|
||||
[2]: https://github.com/creationix/nvm/blob/v0.22.1/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
|
||||
|
||||
|
||||
26
install.sh
26
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.1"
|
||||
}
|
||||
|
||||
#
|
||||
# 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.19.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.19.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 /' \
|
||||
@@ -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"
|
||||
git clone "$(nvm_source git)" "$NVM_DIR"
|
||||
fi
|
||||
cd "$NVM_DIR" && git checkout v0.19.0 && git branch -D master >/dev/null 2>&1
|
||||
cd "$NVM_DIR" && git checkout --quiet $(nvm_latest_version) && 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
|
||||
|
||||
108
nvm.sh
108
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 /' \
|
||||
@@ -183,18 +201,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//' | \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 +227,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() {
|
||||
@@ -253,11 +271,11 @@ nvm_alias() {
|
||||
}
|
||||
|
||||
nvm_ls_current() {
|
||||
local NODE_PATH
|
||||
NODE_PATH="$(which node 2> /dev/null)"
|
||||
local NVM_LS_CURRENT_NODE_PATH
|
||||
NVM_LS_CURRENT_NODE_PATH="$(command which node 2> /dev/null)"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'none'
|
||||
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then
|
||||
elif nvm_tree_contains_path "$NVM_DIR" "$NVM_LS_CURRENT_NODE_PATH"; then
|
||||
local VERSION
|
||||
VERSION=`node -v 2>/dev/null`
|
||||
if [ "$VERSION" = "v0.6.21-pre" ]; then
|
||||
@@ -348,7 +366,7 @@ 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
|
||||
@@ -547,6 +565,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"
|
||||
@@ -790,9 +809,7 @@ nvm() {
|
||||
fi
|
||||
|
||||
NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"
|
||||
if [ "$NODE_PATH" = "$NEWPATH" ]; then
|
||||
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2
|
||||
else
|
||||
if [ "$NODE_PATH" != "$NEWPATH" ]; then
|
||||
export NODE_PATH="$NEWPATH"
|
||||
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
|
||||
fi
|
||||
@@ -850,13 +867,8 @@ nvm() {
|
||||
MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_VERSION_DIR/share/man"`
|
||||
export MANPATH
|
||||
fi
|
||||
# Strip other version from NODE_PATH
|
||||
NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
|
||||
# Prepend current version
|
||||
NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_VERSION_DIR/lib/node_modules"`
|
||||
export PATH
|
||||
hash -r
|
||||
export NODE_PATH
|
||||
export NVM_PATH="$NVM_VERSION_DIR/lib/node"
|
||||
export NVM_BIN="$NVM_VERSION_DIR/bin"
|
||||
if [ "$NVM_SYMLINK_CURRENT" = true ]; then
|
||||
@@ -953,6 +965,49 @@ 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"
|
||||
if [ $# -le 2 ]; then
|
||||
@@ -1044,10 +1099,10 @@ nvm() {
|
||||
nvm_version $2
|
||||
;;
|
||||
"--version" )
|
||||
echo "0.19.0"
|
||||
echo "0.22.1"
|
||||
;;
|
||||
"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
|
||||
;;
|
||||
* )
|
||||
@@ -1056,7 +1111,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.19.0",
|
||||
"version": "0.22.1",
|
||||
"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/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
|
||||
@@ -7,8 +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"
|
||||
|
||||
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
|
||||
|
||||
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