Compare commits

..

71 Commits

Author SHA1 Message Date
Jordan Harband
448bd38a55 v0.22.2 2015-01-14 15:44:40 -08:00
Jordan Harband
0ad5a450fe Put node versions >= 0.12 in versions/node instead of just versions 2015-01-14 12:23:06 -08:00
Jordan Harband
d5e21be164 Add nvm_ensure_version_prefix unit tests. 2015-01-13 23:51:54 -08:00
Jordan Harband
797c5ab70b Move "install node from source" logic into nvm_install_node_source function. 2015-01-13 18:15:42 -08:00
Jordan Harband
0e209ce890 Move "install node binary" logic into nvm_install_node_binary function. 2015-01-13 14:08:56 -08:00
Jordan Harband
9a57a891b9 Refactor OS and architecture detection into separate functions. 2015-01-13 02:41:55 -08:00
Jordan Harband
3d5ded1815 Update the way nvm_ls sorts things. 2015-01-13 00:21:33 -08:00
Jordan Harband
7807a9f09e Consolidate "alias" directory to a method. 2015-01-12 01:27:53 -08:00
Jordan Harband
835c006b5e Better way to search multiple directories in nvm_ls 2015-01-12 01:15:48 -08:00
Jordan Harband
34e51f9f02 Proper quoting and $(…) vs . 2015-01-11 12:13:14 -08:00
Jordan Harband
4b5885d69d Store the version path in a local variable for reuse. 2015-01-11 12:04:26 -08:00
Jordan Harband
bf794ff8da Consistently prefix builtins with command 2015-01-11 11:53:24 -08:00
Jordan Harband
0bd7372c64 Rename this local var in nvm_version_dir 2015-01-11 11:38:55 -08:00
Jordan Harband
0a142b7e7a v0.22.1 2015-01-10 19:43:36 -08:00
Jordan Harband
3fc82d6b2f Use command sed for people who alias sed.
Fixes #493.
2015-01-09 01:50:05 -08:00
Jordan Harband
c6489440dc Add nvm_ls_current test for #605 and zsh. 2015-01-01 23:31:55 -08:00
Jordan Harband
67e8939311 Merge pull request #605 from dhcmrlchtdj/fix_which
Fix which command in zsh (#604).
2015-01-01 22:28:30 -08:00
niris
a26007ec0d fix test suit 2015-01-02 12:51:59 +08:00
niris
3f5ce8b93a Fix which command in zsh (#604). 2015-01-02 10:20:57 +08:00
Jordan Harband
8328741792 Removing an unnecessary return $? 2014-12-28 22:29:26 -08:00
Jordan Harband
8e45afb9f1 Move the version to a single location, nvm_latest_version. 2014-12-28 15:59:06 -08:00
Jordan Harband
fd2fb24b03 Refactor nvm_source a bit. 2014-12-28 15:55:44 -08:00
Jordan Harband
4708cc73ef Update semver 2014-12-27 01:39:48 -08:00
Jordan Harband
c91e8d0ba2 v0.22.0 2014-12-26 16:30:21 -08:00
Jordan Harband
f8b143c594 Merge pull request #602 from ljharb/install_on_source
Support `--install` option on sourcing `nvm.sh`
2014-12-26 14:03:22 -08:00
Jordan Harband
9a4e9060d8 Don't bother testing --install option on source, or supporting it, unless the shell supports passing options upon sourcing. 2014-12-26 13:33:33 -08:00
Jordan Harband
3df0caefa5 Support --install option upon sourcing. 2014-12-26 12:19:35 -08:00
Jordan Harband
274369dc40 Remove trailing whitespace 2014-12-22 23:08:03 -08:00
Jordan Harband
bef3a5ce3a v0.21.0 2014-12-22 12:03:33 -08:00
Jordan Harband
0cb8c9ac2f Merge pull request #599 from ljharb/nvm_get_latest
Add `nvm_get_latest`

This relates to #522, #561, #400.

`nvm_get_latest` uses http://latest.nvm.sh which redirects to https://github.com/creationix/nvm/releases/latest which in turn redirects to the latest release tag.
2014-12-22 11:02:07 -08:00
Jordan Harband
25c61594fe Tests for nvm_get_latest 2014-12-21 18:13:59 -08:00
Jordan Harband
0a739e3fa9 Add nvm_get_latest 2014-12-21 16:33:52 -08:00
Jordan Harband
c0a20f2fa3 Update semver 2014-12-19 17:13:00 -08:00
Jordan Harband
2d78d69d4c Properly outputting the version when nvm_version_path outputs the new "versions" subdirectory. 2014-12-19 17:12:38 -08:00
Jordan Harband
9e17b5059c Return the proper exit code of which directly. 2014-12-19 16:23:27 -08:00
Jordan Harband
0ac2c787be Merge pull request #597 from danielb2/which
Fix `nvm which` to use conventional direct path to program, like system `which`
2014-12-19 13:05:39 -08:00
Daniel Bretoi
99ca0de18f revert echoing path. make tests even better 2014-12-19 11:31:46 -08:00
Daniel Bretoi
f196ace5dd style 2014-12-19 11:10:50 -08:00
Daniel Bretoi
d1a90ca15c work like system which. show system node without changing to use it 2014-12-19 11:10:50 -08:00
Jordan Harband
b3178ca925 Add "--quiet" to git commands post-install.
Mentioned in #595.
2014-12-18 10:37:10 -08:00
Jordan Harband
b9df3fccb4 Remove trailing whitespace. 2014-12-17 01:30:29 -08:00
Jordan Harband
f408d68afc Add nvmrc note to nvm which blurb. 2014-12-17 01:30:23 -08:00
Jordan Harband
fc3a30dd0e Add nvm which to bash_completion 2014-12-17 01:29:38 -08:00
Jordan Harband
74b36b09ff Merge pull request #583 from danielb2/which
Adds `nvm which`
2014-12-17 01:26:50 -08:00
Jordan Harband
080f2149ac Update urchin 2014-12-08 21:51:06 -08:00
Jordan Harband
3bd148056e Fixing deactivate tests.
Fixes #357.
2014-12-03 00:04:43 -08:00
Jordan Harband
5edf013127 Merge pull request #591 from mklement0/fix_make_file
obsolete check for the urchin cross-shell test feature; fix for spurious...
2014-12-02 23:40:24 -08:00
Michael Klement
ae908cbff6 obsolete check for the urchin cross-shell test feature; fix for spurious warnings; improved robustness 2014-12-03 01:47:54 -05:00
Daniel Bretoi
7805492bda merge with master 2014-12-02 13:01:37 -08:00
Daniel Bretoi
a1c0c34088 fix to proper echo of nvm which. Checkin test which had been left out 2014-12-02 12:58:07 -08:00
Daniel Bretoi
234b925c7a style and remove nvm deactivate in nvm which 2014-12-02 12:40:23 -08:00
Jordan Harband
8964cb46d3 v0.20.0 2014-11-29 11:23:16 -08:00
Jordan Harband
383f39ab61 Global modules should not be requireable, and npm root -g should not be in $NODE_PATH.
Fixes #586.
2014-11-29 11:22:10 -08:00
Jordan Harband
052743816f $NODE_PATH is special, so this function shouldn't risk clobbering it. 2014-11-28 11:59:45 -06:00
Jordan Harband
7bbcd3a977 v0.19.0 2014-11-23 14:49:38 -08:00
Jordan Harband
e728577627 Rename nvm copy-packages to nvm reinstall-packages, and --copy-packages-from install option to --reinstall-packages-from
For #341. `nvm copy-packages` and install option `--copy-packages-from` will continue to be supported for for at least a full minor release version.
2014-11-22 13:22:24 -08:00
Jordan Harband
c33074cb54 Tweaking formatting of help output; adding nvm exec example. 2014-11-22 10:48:12 -08:00
Jordan Harband
689c52c90d Install nvm-exec as well when installing via script.
Fixes #553.
2014-11-22 10:34:20 -08:00
Jordan Harband
5904d41b25 Fixing a bug in install_as_script, from 516e553093 2014-11-22 10:29:48 -08:00
Daniel Bretoi
0c33fd2598 change to use default behavior for which 2014-11-22 08:17:15 -08:00
Daniel Bretoi
c9a53fe0c7 include nvm which in documentaiton 2014-11-21 17:55:46 -08:00
Daniel Bretoi
8b25457b74 remove redundant lines from test file 2014-11-21 17:53:08 -08:00
Daniel Bretoi
ee520abf78 adding some tests for nvm which 2014-11-21 17:51:49 -08:00
Daniel Bretoi
b63042bd9f forgot to append bin 2014-11-21 16:59:15 -08:00
Daniel Bretoi
382c3aa85e implements nvm which 2014-11-21 16:54:31 -08:00
Jordan Harband
afba4e08fd Temporarily disable ksh tests, per #574 2014-11-15 11:02:00 -06:00
Jordan Harband
ce82109229 Merge pull request #567 from xcambar/nvm_source
[install script] Refactors NVM_SOURCE
2014-11-15 10:23:40 -06:00
Xavier Cambar
516e553093 Refactors NVM_SOURCE 2014-11-06 22:35:24 +01:00
Jordan Harband
e28a257f23 Merge pull request #573 from mklement0/amend_travis_yml
.travis.yml now obtains latest urchin version from the npm registry
2014-11-05 21:54:53 -08:00
Michael Klement
2d8adac785 .travis.yml now obtains latest urchin version from the npm registry instead of directly from GitHub 2014-11-05 23:22:55 -05:00
Jordan Harband
bf4bf008ac Update urchin 2014-11-05 13:58:30 -08:00
32 changed files with 857 additions and 342 deletions

View File

@@ -1,34 +1,32 @@
language: c # defaults to ruby language: c # defaults to ruby
install: install:
- sudo apt-get install ksh zsh -y - sudo apt-get install zsh -y # ksh
- (mkdir /tmp/urchin && cd /tmp/urchin && curl -s "$(curl -s http://registry.npmjs.org/urchin | grep -Eo '"tarball":\s*"[^"]+"' | tail -n 1 | awk -F\" '{ print $4 }')" -O && tar -x -f urchin*)
- chmod +x /tmp/urchin/package/urchin
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y' - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
before_script:
- '[ -n "$WITHOUT_CURL" ] || curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
- '[ -z "$WITHOUT_CURL" ] || wget -O /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
- chmod +x /tmp/urchin
script: script:
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin test-$SHELL - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL
env: env:
- SHELL=sh TEST_SUITE=install_script - SHELL=sh TEST_SUITE=install_script
- SHELL=dash TEST_SUITE=install_script - SHELL=dash TEST_SUITE=install_script
- SHELL=bash TEST_SUITE=install_script - SHELL=bash TEST_SUITE=install_script
- SHELL=zsh TEST_SUITE=install_script - SHELL=zsh TEST_SUITE=install_script
- SHELL=ksh TEST_SUITE=install_script # - SHELL=ksh TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast - SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast - SHELL=bash TEST_SUITE=fast
- SHELL=zsh TEST_SUITE=fast - SHELL=zsh TEST_SUITE=fast
- SHELL=ksh TEST_SUITE=fast # - SHELL=ksh TEST_SUITE=fast
- SHELL=sh TEST_SUITE=slow - SHELL=sh TEST_SUITE=slow
- SHELL=dash TEST_SUITE=slow - SHELL=dash TEST_SUITE=slow
- SHELL=bash TEST_SUITE=slow - SHELL=bash TEST_SUITE=slow
- SHELL=zsh TEST_SUITE=slow - SHELL=zsh TEST_SUITE=slow
- SHELL=ksh TEST_SUITE=slow # - SHELL=ksh TEST_SUITE=slow
- SHELL=sh TEST_SUITE=sourcing - SHELL=sh TEST_SUITE=sourcing
- SHELL=dash TEST_SUITE=sourcing - SHELL=dash TEST_SUITE=sourcing
- SHELL=bash TEST_SUITE=sourcing - SHELL=bash TEST_SUITE=sourcing
- SHELL=zsh TEST_SUITE=sourcing - SHELL=zsh TEST_SUITE=sourcing
- SHELL=ksh TEST_SUITE=sourcing # - SHELL=ksh TEST_SUITE=sourcing
- SHELL=sh TEST_SUITE=installation - SHELL=sh TEST_SUITE=installation
- SHELL=sh TEST_SUITE=installation WITHOUT_CURL=1 - SHELL=sh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation - SHELL=dash TEST_SUITE=installation
@@ -37,5 +35,5 @@ env:
- SHELL=bash TEST_SUITE=installation WITHOUT_CURL=1 - SHELL=bash TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation - SHELL=zsh TEST_SUITE=installation
- SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1 - SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=ksh TEST_SUITE=installation # - SHELL=ksh TEST_SUITE=installation
- SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1 # - SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1

View File

@@ -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: # Note: With Travis CI:
# - the path to urchin is passed via the command line. # - 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 URCHIN := urchin
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in. 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. # 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`. # The list of all supporting utilities, installed with `npm install`.
UTILS := $(URCHIN) replace semver UTILS := $(URCHIN) replace semver
# Make sure that all required utilities can be located. # Make sure that all required utilities can be located.
@@ -13,13 +17,10 @@ endif
# The files that need updating when incrementing the version number. # The files that need updating when incrementing the version number.
VERSIONED_FILES := nvm.sh install.sh README.markdown package.json VERSIONED_FILES := nvm.sh install.sh README.markdown package.json
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`. # Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
SHELLS := sh bash dash ksh zsh SHELLS := sh bash dash zsh # ksh (#574)
# Generate 'test-<shell>' target names from specified shells. # Generate 'test-<shell>' target names from specified shells.
# The embedded shell names are extracted on demand inside the recipes. # The embedded shell names are extracted on demand inside the recipes.
SHELL_TARGETS := $(addprefix test-,$(SHELLS)) 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>`. # 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 suites are the names of subfolders of './test'.
TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;) TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
@@ -41,9 +42,8 @@ list:
$(SHELL_TARGETS): $(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; } && \ @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"; \ 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; \ [ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
[ "$(HAVE_CROSS_SHELL_TESTS)" = 'yes' ] && targetShellOpt="-s $$shell" || targetShellOpt=; \ for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
for suite in $(TEST_SUITE); do $(URCHIN) -f $$targetShellOpt test/$$suite || exit; done
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS). # All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
.PHONY: test .PHONY: test

View File

@@ -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: To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.18.0/install.sh | bash curl https://raw.githubusercontent.com/creationix/nvm/v0.22.2/install.sh | bash
or Wget: or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.18.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> <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 ## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory). 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: 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 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": In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
nvm install stable nvm install stable
@@ -146,8 +150,9 @@ Put the above sourcing line just below the sourcing line for NVM in your profile
nvm nvm
$ nvm [tab][tab] $ nvm [tab][tab]
alias copy-packages help list run uninstall version alias deactivate install ls run unload
clear-cache deactivate install ls unalias use clear-cache exec list ls-remote unalias use
current help list-remote reinstall-packages uninstall version
nvm alias nvm alias
@@ -186,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 nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.18.0/install.sh [2]: https://github.com/creationix/nvm/blob/v0.22.2/install.sh
[3]: https://travis-ci.org/creationix/nvm [3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin [Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -19,10 +19,10 @@ __nvm_commands ()
COMMANDS='\ COMMANDS='\
help install uninstall use run exec \ help install uninstall use run exec \
alias unalias copy-packages alias unalias reinstall-packages \
current list ls list-remote ls-remote \ current list ls list-remote ls-remote \
clear-cache deactivate unload clear-cache deactivate unload \
version' version which'
if [ ${#COMP_WORDS[@]} == 4 ]; then if [ ${#COMP_WORDS[@]} == 4 ]; then

View File

@@ -4,19 +4,48 @@ set -e
nvm_has() { nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
return $?
} }
if [ -z "$NVM_DIR" ]; then if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm" NVM_DIR="$HOME/.nvm"
fi fi
nvm_latest_version() {
echo "v0.22.2"
}
#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The method used ("script" or "git" in the script, defaults to "git")
# NVM_SOURCE always takes precedence
#
nvm_source() {
local NVM_METHOD
NVM_METHOD="$1"
if [ -z "$NVM_SOURCE" ]; then
local NVM_SOURCE
if [ "_$NVM_METHOD" = "_script" ]; then
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/$(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
}
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # 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/-L //' \
-e 's/-I /--server-response /' \ -e 's/-I /--server-response /' \
-e 's/-s /-q /' \ -e 's/-s /-q /' \
@@ -27,14 +56,10 @@ nvm_download() {
} }
install_nvm_from_git() { install_nvm_from_git() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
fi
if [ -d "$NVM_DIR/.git" ]; then if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update" echo "=> nvm is already installed in $NVM_DIR, trying to update"
printf "\r=> " 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 echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
}) })
else else
@@ -42,16 +67,17 @@ install_nvm_from_git() {
echo "=> Downloading nvm from git to '$NVM_DIR'" echo "=> Downloading nvm from git to '$NVM_DIR'"
printf "\r=> " printf "\r=> "
mkdir -p "$NVM_DIR" mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR" command git clone "$(nvm_source git)" "$NVM_DIR"
fi fi
cd "$NVM_DIR" && git checkout v0.18.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 return
} }
install_nvm_as_script() { install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then local NVM_SOURCE
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.18.0/nvm.sh" NVM_SOURCE=$(nvm_source script)
fi local NVM_EXEC_SOURCE
NVM_EXEC_SOURCE=$(nvm_source script-nvm-exec)
# Downloading to $NVM_DIR # Downloading to $NVM_DIR
mkdir -p "$NVM_DIR" mkdir -p "$NVM_DIR"
@@ -61,9 +87,17 @@ install_nvm_as_script() {
echo "=> Downloading nvm as script to '$NVM_DIR'" echo "=> Downloading nvm as script to '$NVM_DIR'"
fi fi
nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || { nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
echo >&2 "Failed to download '$NVM_SOURCE'.." echo >&2 "Failed to download '$NVM_SOURCE'"
return 1 return 1
} }
nvm_download -s "$NVM_EXEC_SOURCE" -o "$NVM_DIR/nvm-exec" || {
echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2
}
chmod a+x "$NVM_DIR/nvm-exec" || {
echo >&2 "Failed to mark '$NVM_DIR/nvm-exec' as executable"
return 3
}
} }
# #
@@ -144,7 +178,7 @@ nvm_do_install() {
# during the execution of the install script # during the execution of the install script
# #
nvm_reset() { 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 [ "_$NVM_ENV" = "_testing" ] || nvm_do_install

583
nvm.sh
View File

@@ -12,12 +12,30 @@ nvm_has() {
type "$1" > /dev/null 2>&1 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() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # 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/-L //' \
-e 's/-I /--server-response /' \ -e 's/-I /--server-response /' \
-e 's/-s /-q /' \ -e 's/-s /-q /' \
@@ -122,11 +140,11 @@ nvm_version_greater_than_or_equal_to() {
} }
nvm_version_dir() { nvm_version_dir() {
local NVM_USE_NEW_DIR local NVM_WHICH_DIR
NVM_USE_NEW_DIR="$1" NVM_WHICH_DIR="$1"
if [ -z "$NVM_USE_NEW_DIR" ] || [ "$NVM_USE_NEW_DIR" = "new" ]; then if [ -z "$NVM_WHICH_DIR" ] || [ "_$NVM_WHICH_DIR" = "_new" ]; then
echo "$NVM_DIR/versions" echo "$NVM_DIR/versions/node"
elif [ "$NVM_USE_NEW_DIR" = "old" ]; then elif [ "_$NVM_WHICH_DIR" = "_old" ]; then
echo "$NVM_DIR" echo "$NVM_DIR"
else else
echo "unknown version dir" >&2 echo "unknown version dir" >&2
@@ -134,6 +152,10 @@ nvm_version_dir() {
fi fi
} }
nvm_alias_path() {
echo "$(nvm_version_dir old)/alias"
}
nvm_version_path() { nvm_version_path() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
@@ -183,18 +205,18 @@ nvm_remote_version() {
} }
nvm_normalize_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() { 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() { nvm_format_version() {
local VERSION local VERSION
VERSION="$(nvm_ensure_version_prefix "$1")" VERSION="$(nvm_ensure_version_prefix "$1")"
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then 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" nvm_format_version "$VERSION"
else else
echo "$VERSION" echo "$VERSION"
@@ -209,14 +231,14 @@ nvm_num_version_groups() {
return return
fi fi
local NVM_NUM_DOTS 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 local NVM_NUM_GROUPS
NVM_NUM_GROUPS=".$NVM_NUM_DOTS" NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
echo "${#NVM_NUM_GROUPS}" echo "${#NVM_NUM_GROUPS}"
} }
nvm_strip_path() { 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() { nvm_prepend_path() {
@@ -243,7 +265,7 @@ nvm_alias() {
fi fi
local NVM_ALIAS_PATH local NVM_ALIAS_PATH
NVM_ALIAS_PATH="$NVM_DIR/alias/$ALIAS" NVM_ALIAS_PATH="$(nvm_alias_path)/$ALIAS"
if [ ! -f "$NVM_ALIAS_PATH" ]; then if [ ! -f "$NVM_ALIAS_PATH" ]; then
echo >&2 'Alias does not exist.' echo >&2 'Alias does not exist.'
return 2 return 2
@@ -253,13 +275,13 @@ nvm_alias() {
} }
nvm_ls_current() { nvm_ls_current() {
local NODE_PATH local NVM_LS_CURRENT_NODE_PATH
NODE_PATH="$(which node 2> /dev/null)" NVM_LS_CURRENT_NODE_PATH="$(command which node 2> /dev/null)"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo 'none' 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 local VERSION
VERSION=`node -v 2>/dev/null` VERSION="$(node -v 2>/dev/null)"
if [ "$VERSION" = "v0.6.21-pre" ]; then if [ "$VERSION" = "v0.6.21-pre" ]; then
echo "v0.6.21" echo "v0.6.21"
else else
@@ -292,7 +314,7 @@ nvm_resolve_alias() {
fi fi
if [ -n "$ALIAS_TEMP" ] \ 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="∞" ALIAS="∞"
break break
fi fi
@@ -325,7 +347,7 @@ nvm_resolve_alias() {
nvm_ls() { nvm_ls() {
local PATTERN local PATTERN
PATTERN=$1 PATTERN="$1"
local VERSIONS local VERSIONS
VERSIONS='' VERSIONS=''
if [ "$PATTERN" = 'current' ]; then if [ "$PATTERN" = 'current' ]; then
@@ -348,23 +370,47 @@ nvm_ls() {
local NUM_VERSION_GROUPS local NUM_VERSION_GROUPS
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")" NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then 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
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 '{}' ';' \ local ZHS_HAS_SHWORDSPLIT_UNSET
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v' | \grep -v -e '^versions$'` ZHS_HAS_SHWORDSPLIT_UNSET=1
else if nvm_has "setopt"; then
VERSIONS=`find "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \ ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'` 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
fi fi
if nvm_has_system_node; then if nvm_has_system_node; then
if [ -z "$PATTERN" ]; then if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then
VERSIONS="$VERSIONS$(printf '\n%s' 'system')" VERSIONS="$VERSIONS$(command printf '\n%s' 'system')"
elif [ "$PATTERN" = 'system' ]; then elif [ "$PATTERN" = 'system' ]; then
VERSIONS="$(printf '%s' 'system')" VERSIONS="$(command printf '%s' 'system')"
fi fi
fi fi
@@ -374,7 +420,6 @@ nvm_ls() {
fi fi
echo "$VERSIONS" echo "$VERSIONS"
return
} }
nvm_ls_remote() { nvm_ls_remote() {
@@ -392,7 +437,7 @@ nvm_ls_remote() {
fi fi
VERSIONS=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/ -o - \ VERSIONS=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/ -o - \
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ | \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` | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
if [ -z "$VERSIONS" ]; then if [ -z "$VERSIONS" ]; then
echo "N/A" echo "N/A"
@@ -404,11 +449,11 @@ nvm_ls_remote() {
nvm_checksum() { nvm_checksum() {
if nvm_has "sha1sum"; then if nvm_has "sha1sum"; then
checksum="$(sha1sum "$1" | \awk '{print $1}')" checksum="$(sha1sum "$1" | command awk '{print $1}')"
elif nvm_has "sha1"; then elif nvm_has "sha1"; then
checksum="$(sha1 -q "$1")" checksum="$(sha1 -q "$1")"
else else
checksum="$(shasum "$1" | \awk '{print $1}')" checksum="$(shasum "$1" | command awk '{print $1}')"
fi fi
if [ "_$checksum" = "_$2" ]; then if [ "_$checksum" = "_$2" ]; then
@@ -460,9 +505,9 @@ nvm_print_implicit_alias() {
local LAST_TWO local LAST_TWO
if [ "_$1" = "_local" ]; then 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 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 fi
local MINOR local MINOR
local STABLE local STABLE
@@ -472,7 +517,7 @@ nvm_print_implicit_alias() {
local ZHS_HAS_SHWORDSPLIT_UNSET local ZHS_HAS_SHWORDSPLIT_UNSET
ZHS_HAS_SHWORDSPLIT_UNSET=1 ZHS_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then 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 setopt shwordsplit
fi fi
for MINOR in $LAST_TWO; do for MINOR in $LAST_TWO; do
@@ -494,6 +539,152 @@ nvm_print_implicit_alias() {
fi 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() { nvm() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm help nvm help
@@ -501,24 +692,10 @@ nvm() {
fi fi
# Try to figure out the os and arch for binary fetching # Try to figure out the os and arch for binary fetching
local uname
uname="$(uname -a)"
local os local os
local arch local arch
arch="$(uname -m)"
local GREP_OPTIONS local GREP_OPTIONS
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 # initialize local variables
local VERSION local VERSION
@@ -541,18 +718,20 @@ nvm() {
echo " nvm ls List installed versions" echo " nvm ls List installed versions"
echo " nvm ls <version> List versions matching a given description" echo " nvm ls <version> List versions matching a given description"
echo " nvm ls-remote List remote versions available for install" echo " nvm ls-remote List remote versions available for install"
echo " nvm deactivate Undo effects of NVM on current shell" echo " nvm deactivate Undo effects of \`nvm\` on current shell"
echo " nvm alias [<pattern>] Show all aliases beginning with <pattern>" echo " nvm alias [<pattern>] Show all aliases beginning with <pattern>"
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>" echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
echo " nvm unalias <name> Deletes the alias named <name>" echo " nvm unalias <name> Deletes the alias named <name>"
echo " nvm copy-packages <version> Install global NPM packages contained in <version> to current version" echo " nvm reinstall-packages <version> Reinstall global \`npm\` packages contained in <version> to current version"
echo " nvm unload Unload NVM from shell" echo " nvm unload Unload \`nvm\` from shell"
echo " nvm which [<version>] Display path to installed node version. Uses .nvmrc if available"
echo echo
echo "Example:" echo "Example:"
echo " nvm install v0.10.24 Install a specific version number" echo " nvm install v0.10.32 Install a specific version number"
echo " nvm use 0.10 Use the latest available 0.10.x release" echo " nvm use 0.10 Use the latest available 0.10.x release"
echo " nvm run 0.10.24 myApp.js Run myApp.js using node v0.10.24" echo " nvm run 0.10.32 app.js Run app.js using node v0.10.32"
echo " nvm alias default 0.10.24 Set default node version on a shell" echo " nvm exec 0.10.32 node app.js Run \`node app.js\` with the PATH pointing to node v0.10.32"
echo " nvm alias default 0.10.32 Set default node version on a shell"
echo echo
echo "Note:" echo "Note:"
echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders" echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
@@ -560,16 +739,12 @@ nvm() {
;; ;;
"install" | "i" ) "install" | "i" )
# initialize local variables
local binavail
local t
local url
local sum
local tarball
local nobinary local nobinary
local version_not_provided local version_not_provided
version_not_provided=0 version_not_provided=0
local provided_version local provided_version
local NVM_OS
NVM_OS="$(nvm_get_os)"
if ! nvm_has "curl" && ! nvm_has "wget"; then if ! nvm_has "curl" && ! nvm_has "wget"; then
echo 'nvm needs curl or wget to proceed.' >&2; echo 'nvm needs curl or wget to proceed.' >&2;
@@ -588,12 +763,12 @@ nvm() {
shift shift
nobinary=0 nobinary=0
if [ "$1" = "-s" ]; then if [ "_$1" = "_-s" ]; then
nobinary=1 nobinary=1
shift shift
fi fi
if [ "$os" = "freebsd" ]; then if [ "_$NVM_OS" = "_freebsd" ]; then
nobinary=1 nobinary=1
fi fi
@@ -610,166 +785,95 @@ nvm() {
VERSION="$(nvm_remote_version "$provided_version")" VERSION="$(nvm_remote_version "$provided_version")"
ADDITIONAL_PARAMETERS='' ADDITIONAL_PARAMETERS=''
local PROVIDED_COPY_PACKAGES_FROM local PROVIDED_REINSTALL_PACKAGES_FROM
local COPY_PACKAGES_FROM local REINSTALL_PACKAGES_FROM
while [ $# -ne 0 ] while [ $# -ne 0 ]
do do
if [ "_$(echo "$1" | cut -c 1-21)" = "_--copy-packages-from=" ]; then if [ "_$(echo "$1" | command cut -c 1-26)" = "_--reinstall-packages-from=" ]; then
PROVIDED_COPY_PACKAGES_FROM="$(echo "$1" | cut -c 22-)" PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 27-)"
COPY_PACKAGES_FROM="$(nvm_version "$PROVIDED_COPY_PACKAGES_FROM")" REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
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 else
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1" ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
fi fi
shift shift
done done
if [ "_$(nvm_ensure_version_prefix "$PROVIDED_COPY_PACKAGES_FROM")" = "_$VERSION" ]; then if [ "_$(nvm_ensure_version_prefix "$PROVIDED_REINSTALL_PACKAGES_FROM")" = "_$VERSION" ]; then
echo "You can't copy global packages from the same version of node you're installing." >&2 echo "You can't reinstall global packages from the same version of node you're installing." >&2
return 4 return 4
elif [ ! -z "$PROVIDED_COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" = "_N/A" ]; then elif [ ! -z "$PROVIDED_REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" = "_N/A" ]; then
echo "If --copy-packages-from is provided, it must point to an installed version of node." >&2 echo "If --reinstall-packages-from is provided, it must point to an installed version of node." >&2
return 5 return 5
fi 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 echo "$VERSION is already installed." >&2
if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm copy-packages "$COPY_PACKAGES_FROM" nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi fi
return $? return $?
fi 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 echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2
return 3 return 3
fi fi
# skip binary install if no binary option specified. # skip binary install if "nobinary" option specified.
if [ $nobinary -ne 1 ]; then if [ $nobinary -ne 1 ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
# shortcut - try the binary if possible. if nvm use "$VERSION" \
if [ -n "$os" ]; then && [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
if nvm_binary_available "$VERSION"; then && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
t="$VERSION-$os-$arch" nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
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 "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then
nvm copy-packages "$COPY_PACKAGES_FROM"
fi fi
return $? return $?
else
echo "Binary download failed, trying source." >&2
rm -rf "$tmptarball" "$tmpdir"
fi
fi
fi
fi fi
if [ -n "$ADDITIONAL_PARAMETERS" ]; then nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
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 "$COPY_PACKAGES_FROM" ] && [ "_$COPY_PACKAGES_FROM" != "_N/A" ]; then
nvm copy-packages "$COPY_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 $?
;; ;;
"uninstall" ) "uninstall" )
[ $# -ne 2 ] && nvm help && return [ $# -ne 2 ] && nvm help && return
PATTERN=`nvm_ensure_version_prefix $2` PATTERN="$(nvm_ensure_version_prefix "$2")"
if [ "$PATTERN" = `nvm_version` ]; then if [ "_$PATTERN" = "_$(nvm_version)" ]; then
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2 echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
return 1 return 1
fi fi
VERSION=`nvm_version $PATTERN` local VERSION
if [ ! -d "$(nvm_version_path "$VERSION")" ]; then 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 echo "$VERSION version is not installed..." >&2
return; return;
fi fi
t="$VERSION-$os-$arch" t="$VERSION-$(nvm_get_os)-$(nvm_get_arch)"
# Delete all files related to target version. # 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/src/node-$VERSION.tar.gz" \
"$NVM_DIR/bin/node-${t}" \ "$NVM_DIR/bin/node-${t}" \
"$NVM_DIR/bin/node-${t}.tar.gz" \ "$NVM_DIR/bin/node-${t}.tar.gz" \
"$(nvm_version_path "$VERSION")" 2>/dev/null "$VERSION_PATH" 2>/dev/null
echo "Uninstalled node $VERSION" echo "Uninstalled node $VERSION"
# Rm any aliases that point to uninstalled 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 do
nvm unalias `basename $ALIAS` nvm unalias "$(command basename "$ALIAS")"
done done
;; ;;
"deactivate" ) "deactivate" )
local NEWPATH local NEWPATH
NEWPATH="$(nvm_strip_path "$PATH" "/bin")" NEWPATH="$(nvm_strip_path "$PATH" "/bin")"
if [ "$PATH" = "$NEWPATH" ]; then if [ "_$PATH" = "_$NEWPATH" ]; then
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2 echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
else else
export PATH="$NEWPATH" export PATH="$NEWPATH"
@@ -778,7 +882,7 @@ nvm() {
fi fi
NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")" 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 echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
else else
export MANPATH="$NEWPATH" export MANPATH="$NEWPATH"
@@ -786,9 +890,7 @@ nvm() {
fi fi
NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")" NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"
if [ "$NODE_PATH" = "$NEWPATH" ]; then if [ "_$NODE_PATH" != "_$NEWPATH" ]; then
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2
else
export NODE_PATH="$NEWPATH" export NODE_PATH="$NEWPATH"
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH" echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
fi fi
@@ -801,7 +903,7 @@ nvm() {
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
nvm_rc_version nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION` VERSION="$(nvm_version "$NVM_RC_VERSION")"
fi fi
elif [ "_$2" != '_system' ]; then elif [ "_$2" != '_system' ]; then
VERSION="$(nvm_version "$2")" VERSION="$(nvm_version "$2")"
@@ -833,30 +935,25 @@ nvm() {
return 1 return 1
fi fi
# Strip other version from PATH # Strip other version from PATH
PATH=`nvm_strip_path "$PATH" "/bin"` PATH="$(nvm_strip_path "$PATH" "/bin")"
# Prepend current version # 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 nvm_has manpath; then
if [ -z "$MANPATH" ]; then if [ -z "$MANPATH" ]; then
MANPATH=$(manpath) MANPATH=$(manpath)
fi fi
# Strip other version from MANPATH # Strip other version from MANPATH
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"` MANPATH="$(nvm_strip_path "$MANPATH" "/share/man")"
# Prepend current version # 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 export MANPATH
fi 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 export PATH
hash -r hash -r
export NODE_PATH
export NVM_PATH="$NVM_VERSION_DIR/lib/node" export NVM_PATH="$NVM_VERSION_DIR/lib/node"
export NVM_BIN="$NVM_VERSION_DIR/bin" export NVM_BIN="$NVM_VERSION_DIR/bin"
if [ "$NVM_SYMLINK_CURRENT" = true ]; then 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 fi
echo "Now using node $VERSION" echo "Now using node $VERSION"
;; ;;
@@ -869,7 +966,7 @@ nvm() {
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
nvm_rc_version && has_checked_nvmrc=1 nvm_rc_version && has_checked_nvmrc=1
if [ -n "$NVM_RC_VERSION" ]; then if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION` VERSION="$(nvm_version "$NVM_RC_VERSION")"
else else
VERSION='N/A' VERSION='N/A'
fi fi
@@ -881,13 +978,13 @@ nvm() {
provided_version=$1 provided_version=$1
if [ -n "$provided_version" ]; then if [ -n "$provided_version" ]; then
VERSION=`nvm_version $provided_version` VERSION="$(nvm_version "$provided_version")"
if [ "_$VERSION" = "_N/A" ]; then if [ "_$VERSION" = "_N/A" ]; then
provided_version='' provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then if [ $has_checked_nvmrc -ne 1 ]; then
nvm_rc_version && has_checked_nvmrc=1 nvm_rc_version && has_checked_nvmrc=1
fi fi
VERSION=`nvm_version $NVM_RC_VERSION` VERSION="$(nvm_version "$NVM_RC_VERSION")"
else else
shift shift
fi fi
@@ -909,8 +1006,8 @@ nvm() {
local provided_version local provided_version
provided_version="$1" provided_version="$1"
if [ -n "$provided_version" ]; then if [ -n "$provided_version" ]; then
VERSION=`nvm_version $provided_version` VERSION="$(nvm_version "$provided_version")"
if [ $VERSION = "N/A" ]; then if [ "_$VERSION" = "_N/A" ]; then
provided_version='' provided_version=''
nvm_rc_version nvm_rc_version
VERSION="$(nvm_version "$NVM_RC_VERSION")" VERSION="$(nvm_version "$NVM_RC_VERSION")"
@@ -920,13 +1017,13 @@ nvm() {
fi fi
local NVM_VERSION_DIR local NVM_VERSION_DIR
NVM_VERSION_DIR=$(nvm_version_path "$VERSION") NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2 echo "$VERSION version is not installed yet" >&2
return 1 return 1
fi fi
echo "Running node $VERSION" echo "Running node $VERSION"
NODE_VERSION=$VERSION $NVM_DIR/nvm-exec "$@" NODE_VERSION="$VERSION" $NVM_DIR/nvm-exec "$@"
;; ;;
"ls" | "list" ) "ls" | "list" )
local NVM_LS_OUTPUT local NVM_LS_OUTPUT
@@ -949,12 +1046,57 @@ nvm() {
"current" ) "current" )
nvm_version 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" ) "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 if [ $# -le 2 ]; then
local DEST local DEST
for ALIAS_PATH in "$NVM_DIR"/alias/"$2"*; do for ALIAS_PATH in "$NVM_ALIAS_DIR"/"$2"*; do
ALIAS="$(basename "$ALIAS_PATH")" ALIAS="$(command basename "$ALIAS_PATH")"
DEST="$(nvm_alias "$ALIAS" 2> /dev/null)" DEST="$(nvm_alias "$ALIAS" 2> /dev/null)"
if [ -n "$DEST" ]; then if [ -n "$DEST" ]; then
VERSION="$(nvm_version "$DEST")" VERSION="$(nvm_version "$DEST")"
@@ -967,7 +1109,7 @@ nvm() {
done done
for ALIAS in "stable" "unstable"; do 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 if [ $# -lt 2 ] || [ "~$ALIAS" = "~$2" ]; then
DEST="$(nvm_print_implicit_alias local "$ALIAS")" DEST="$(nvm_print_implicit_alias local "$ALIAS")"
if [ "_$DEST" != "_" ]; then if [ "_$DEST" != "_" ]; then
@@ -980,7 +1122,7 @@ nvm() {
return return
fi fi
if [ -z "$3" ]; then if [ -z "$3" ]; then
rm -f "$NVM_DIR/alias/$2" command rm -f "$NVM_ALIAS_DIR/$2"
echo "$2 -> *poof*" echo "$2 -> *poof*"
return return
fi fi
@@ -988,7 +1130,7 @@ nvm() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "! WARNING: Version '$3' does not exist." >&2 echo "! WARNING: Version '$3' does not exist." >&2
fi fi
echo $3 > "$NVM_DIR/alias/$2" echo "$3" > "$NVM_ALIAS_DIR/$2"
if [ ! "_$3" = "_$VERSION" ]; then if [ ! "_$3" = "_$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)" echo "$2 -> $3 (-> $VERSION)"
else else
@@ -996,13 +1138,15 @@ nvm() {
fi fi
;; ;;
"unalias" ) "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 [ $# -ne 2 ] && nvm help && return 127
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return [ ! -f "$NVM_ALIAS_DIR/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
rm -f $NVM_DIR/alias/$2 command rm -f "$NVM_ALIAS_DIR/$2"
echo "Deleted alias $2" echo "Deleted alias $2"
;; ;;
"copy-packages" ) "reinstall-packages" | "copy-packages" )
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
nvm help nvm help
return 127 return 127
@@ -1011,39 +1155,39 @@ nvm() {
local PROVIDED_VERSION local PROVIDED_VERSION
PROVIDED_VERSION="$2" 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 copy packages from the current version of node.' >&2 echo 'Can not reinstall packages from the current version of node.' >&2
return 2 return 2
fi fi
local INSTALLS local INSTALLS
if [ "$PROVIDED_VERSION" = "system" ]; then if [ "_$PROVIDED_VERSION" = "_system" ]; then
if ! nvm_has_system_node; then if ! nvm_has_system_node; then
echo 'No system version of node detected.' >&2 echo 'No system version of node detected.' >&2
return 3 return 3
fi 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 else
local VERSION local VERSION
VERSION="$(nvm_version "$PROVIDED_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 fi
echo "Copying global packages from $VERSION..." echo "Copying global packages from $VERSION..."
echo "$INSTALLS" | xargs npm install -g --quiet echo "$INSTALLS" | command xargs npm install -g --quiet
;; ;;
"clear-cache" ) "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." echo "Cache cleared."
;; ;;
"version" ) "version" )
nvm_version $2 nvm_version $2
;; ;;
"--version" ) "--version" )
echo "0.18.0" echo "0.22.2"
;; ;;
"unload" ) "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 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;; ;;
* ) * )
@@ -1052,7 +1196,18 @@ nvm() {
esac 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 nvm use default >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null nvm use >/dev/null

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.18.0", "version": "0.22.2",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"
@@ -31,7 +31,7 @@
"homepage": "https://github.com/creationix/nvm", "homepage": "https://github.com/creationix/nvm",
"devDependencies": { "devDependencies": {
"replace": "~0.3.0", "replace": "~0.3.0",
"semver": "~4.1.0", "semver": "~4.2.0",
"urchin": "~0.0.2" "urchin": "~0.0.5"
} }
} }

View File

@@ -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'"

View File

@@ -0,0 +1,6 @@
#!/bin/sh
. ../../../nvm.sh
nvm which nonexistent_version
[ "_$?" = "_1" ]

View 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

View File

@@ -2,7 +2,7 @@
mkdir ../../../v0.1.3 mkdir ../../../v0.1.3
mkdir ../../../v0.2.3 mkdir ../../../v0.2.3
mkdir ../../../versions mkdir -p ../../../versions/node
. ../../../nvm.sh . ../../../nvm.sh

View File

@@ -2,7 +2,7 @@
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
mkdir -p ../../../versions/v0.12.1 mkdir -p ../../../versions/node/v0.12.1
mkdir ../../../v0.1.3 mkdir ../../../v0.1.3
. ../../../nvm.sh . ../../../nvm.sh

View File

@@ -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 [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
. ../../nvm.sh . ../../nvm.sh
nvm use v0.2.3 && nvm use v0.2.3 || die "Failed to activate 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" [ `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 && nvm deactivate || die "Failed to deactivate v0.2.3"
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || 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"

View File

@@ -1,31 +0,0 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../v0.10.4
}
mkdir ../../v0.10.4
. ../../nvm.sh
nvm deactivate >/dev/null 2>&1
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.11 2>&1)"
EXPECTED_ERROR_MSG="If --copy-packages-from is provided, it must point to an installed version of node."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --copy-packages" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.11 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~5" ] \
|| die ""nvm install --copy-packages" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE"
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.10.5 2>&1)"
EXPECTED_ERROR_MSG="You can't copy global packages from the same version of node you're installing."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --copy-packages" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~4" ] \
|| die ""nvm install --copy-packages" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"

View File

@@ -0,0 +1,31 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../v0.10.4
}
mkdir ../../v0.10.4
. ../../nvm.sh
nvm deactivate >/dev/null 2>&1
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)"
EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~5" ] \
|| die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE"
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)"
EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~4" ] \
|| die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"

View 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"

View 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"'

View 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

View File

@@ -1,6 +1,10 @@
#!/bin/sh #!/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 . ../../../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"' [ "$(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" rm -rf "$TEST_DIR"
mkdir "$TEST_DIR" mkdir "$TEST_DIR"
ln -s "$(which which)" "$TEST_DIR/which" ln -s "$(command which which)" "$TEST_DIR/which"
ln -s "$(which dirname)" "$TEST_DIR/dirname" 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)" = "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' [ "@$(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' [ "$(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

View File

@@ -4,7 +4,7 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh . ../../../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 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 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' [ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out'

View File

@@ -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 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 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.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'

40
test/install_script/nvm_source Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/sh
cleanup () {
unset -f die cleanup
unset NVM_SOURCE out
}
die () { echo $@ ; cleanup ; exit 1; }
NVM_ENV=testing . ../../install.sh
# nvm_source with no parameter returns the git endpoint
echo $(nvm_source) | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo"
# nvm_source with git parameter returns the location of the nvm repo
echo $(nvm_source "git") | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo"
# nvm_source with script parameter returns the location of nvm.sh
echo $(nvm_source "script") | grep "nvm.sh$" > /dev/null || die "nvm_source \"script\" should return the location of nvm.sh"
# nvm_source with script-nvm-exec parameter returns the location of nvm-exec
echo $(nvm_source "script-nvm-exec") | grep "nvm-exec$" > /dev/null || die "nvm_source \"script-nvm-exec\" should return the location of nvm.sh"
# nvm_source with any other parameter errors out and exits
nvm_source "anything" 2> /dev/null && die "nvm_source with invalid parameter should exit"
out=$(nvm_source "anything" 2>&1 >/dev/null) || : #Saving the process here
[ -z "$out" ] && die "nvm_source with invalid parameter should error out"
#nvm_source should always return NVM_SOURCE no matter the parameters
NVM_SOURCE="my_location"
out=$(nvm_source)
[ "_$out" = "_my_location" ] || die "nvm_source without arguments should have returned \$NVM_SOURCE. Got \"$out\""
out=$(nvm_source "git")
[ "_$out" = "_my_location" ] || die "nvm_source git should have returned \$NVM_SOURCE. Got \"$out\""
out=$(nvm_source "script")
[ "_$out" = "_my_location" ] || die "nvm_source script should have returned \$NVM_SOURCE. Got \"$out\""
out=$(nvm_source "anything")
[ "_$out" = "_my_location" ] || die "nvm_source script should have returned \$NVM_SOURCE. Got \"$out\""
cleanup

View File

@@ -23,7 +23,7 @@ npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed"
nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7" nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7"
nvm install 0.9.12 --copy-packages-from=0.9 || die "nvm install 0.9.12 --copy-packages-from=0.9 failed" nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --reinstall-packages-from=0.9 failed"
[ -d ../../v0.9.12 ] || die "nvm install 0.9.12 didn't install" [ -d ../../v0.9.12 ] || die "nvm install 0.9.12 didn't install"

View 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

View 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

View File

@@ -1,16 +0,0 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm use 0.10.28 > /dev/null
EXPECTED_MSG="Can not copy packages from the current version of node."
ACTUAL_MSG="$(nvm copy-packages 0.10.28 2>&1 > /dev/null)"
[ "~$ACTUAL_MSG" = "~$EXPECTED_MSG" ] || die "'nvm use 0.10.28 && nvm copy-packages 0.10.28' did not fail with the right message: '$ACTUAL_MESSAGE'"
EXPECTED_ERROR_CODE="2"
ACTUAL_ERROR_CODE="$(nvm copy-packages 0.10.28 > /dev/null 2>&1 ; echo $?)"
[ "~$ACTUAL_ERROR_CODE" = "~$EXPECTED_ERROR_CODE" ] || die "'nvm use 0.10.28 && nvm copy-packages 0.10.28' did not fail with the right error code: expected '$EXPECTED_ERROR_CODE', got '$ACTUAL_ERROR_CODE'"

View File

@@ -0,0 +1,16 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm use 0.10.28 > /dev/null
EXPECTED_MSG="Can not reinstall packages from the current version of node."
ACTUAL_MSG="$(nvm reinstall-packages 0.10.28 2>&1 > /dev/null)"
[ "~$ACTUAL_MSG" = "~$EXPECTED_MSG" ] || die "'nvm use 0.10.28 && nvm reinstall-packages 0.10.28' did not fail with the right message: '$ACTUAL_MESSAGE'"
EXPECTED_ERROR_CODE="2"
ACTUAL_ERROR_CODE="$(nvm reinstall-packages 0.10.28 > /dev/null 2>&1 ; echo $?)"
[ "~$ACTUAL_ERROR_CODE" = "~$EXPECTED_ERROR_CODE" ] || die "'nvm use 0.10.28 && nvm reinstall-packages 0.10.28' did not fail with the right error code: expected '$EXPECTED_ERROR_CODE', got '$ACTUAL_ERROR_CODE'"

View File

@@ -13,7 +13,7 @@ echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet
nvm use 0.10.29 nvm use 0.10.29
ORIGINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs) ORIGINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs)
nvm copy-packages 0.10.28 nvm reinstall-packages 0.10.28
FINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs) FINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | sort | uniq | xargs)
[ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)" [ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)"

View 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`"

View 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'"