Compare commits

...

110 Commits

Author SHA1 Message Date
Jordan Harband
49abc9ce02 v0.26.0 2015-08-13 17:10:08 -07:00
Jordan Harband
15876280f7 Remove trailing whitespace. 2015-08-13 17:09:22 -07:00
Jordan Harband
9f653cc196 Merge pull request #802 from Alex7Kom/master
Replace links to nvm-fish and nvm-fish-wrapper with a link to bass
2015-08-13 00:04:07 -07:00
Alexey Komarov
543b86c060 Replace links to nvm-fish and nvm-fish-wrapper with a link to bass 2015-08-13 09:09:51 +03:00
Jordan Harband
ba01993ea6 Merge pull request #799 from hkdobrev/neither
[Docs] Use "neither" in README
2015-08-10 11:09:46 -07:00
Haralan Dobrev
31e7d5b36a Use neither in README
Correct usage of the [neither-nor](https://en.wiktionary.org/wiki/neither) construction.
2015-08-10 20:34:10 +03:00
Jordan Harband
17c68075e8 Use single quotes instead of double quotes for help output. 2015-08-05 23:53:29 -07:00
Jordan Harband
3fcff872af Add explanatory note for <version>
Per https://github.com/creationix/nvm/pull/797#discussion_r36379740
2015-08-05 23:53:17 -07:00
Jordan Harband
c07838fcc0 Merge pull request #797 from Sequoia/patch-1
Add usage string for --reinstall-packages-from
2015-08-05 21:03:30 -07:00
Sequoia McDowell
fe1ed37520 Add usage string for --reinstall-packages-from 2015-08-05 22:26:17 -04:00
Jordan Harband
ae1c488fe1 Merge pull request #795 from reybango/master
Updated readme file to include --reinstall-packages-from
2015-08-04 14:38:38 -07:00
Rey Bango
d9662f138f Updated based on feedback from @ljharb on syntax description and functionality 2015-08-04 17:35:03 -04:00
Jordan Harband
071323847c Add nvm version-remote; document nvm version 2015-08-04 14:03:57 -07:00
Rey Bango
b7a93be02e Updated to added npm to the text 2015-08-04 15:23:07 -04:00
Rey Bango
3543cd5d2f Updated usage instructions to include --reinstall-packages-from syntax and example 2015-08-04 15:19:38 -04:00
Jordan Harband
d7035c5e61 Redirect stderr output from npm ls -g to /dev/null.
Fixes #756.
2015-08-03 16:41:47 -07:00
Jordan Harband
1f679fc055 Merge pull request #765 from CristianCantoro/master
Detect shell type from $SHELL variable instead of .$SHELLrc files
2015-07-21 16:37:03 -07:00
Cristian Consonni
c37dbbecb4 Detect shell type from $SHELL variable instead of .$SHELLrc files 2015-07-19 02:03:15 +02:00
Jordan Harband
f81b6d6b7b Update semver 2015-07-18 12:20:53 -07:00
Jordan Harband
d57f7ea54a Merge pull request #776 from IonicaBizauKitchen/source-nvm.sh
Source the nvm.sh file upon install
2015-07-18 12:02:08 -07:00
Jordan Harband
759f86f946 Tweaking local variable name to avoid pollution under ksh. 2015-07-18 09:31:07 -07:00
Jordan Harband
60c2f3705e Merge pull request #780 from alanmquach/silent-source
Adding --silent option for nvm use, and using it to disable processing certain output to speed up shell startup

Relates to #781.
2015-07-18 09:29:40 -07:00
Alan Quach
657192dd27 Adding unit tests for --silent 2015-07-10 10:27:35 +10:00
Alan Quach
98e40a8da5 Expanding to full if statements because the shorthand results in non-zero exit codes 2015-07-09 18:40:52 +10:00
Alan Quach
2da44f90d2 Silencing error outputs as well (for consistency and following after things like curl) 2015-07-09 18:00:13 +10:00
Alan Quach
88a50780fc Removing global NVM_SILENT and adding/using '--silent' option to nvm use instead 2015-07-09 17:44:09 +10:00
Alan Quach
9419794b19 Guarding npm version printing with NVM_SILENT flag check; when sourcing nvm.sh, a considerable amount of time is spent running npm --version only for that output to be black-holed to /dev/null 2015-07-09 09:56:26 +10:00
Ionică Bizău
b4151e1446 Source the nvm.sh file
Fixes #775. After everything is installed, instead of restarting the terminal, just load the nvm.sh file.
2015-07-06 11:19:48 +03:00
Jordan Harband
f2d31b0458 Some refactoring to clear up the path to io.js release candidate support.
(unblocks #779)
2015-07-04 17:05:24 -07:00
Jordan Harband
0b41352210 Factor out global installs/links into nvm_npm_global_modules function. 2015-07-02 23:47:29 -07:00
Jordan Harband
be5e8de0c8 Fix nvm reinstall-packages for linked packages, broken in 7bce6c6c68 2015-07-02 23:12:06 -07:00
Jordan Harband
3ef937a64e Make nvm_ensure_version_installed slightly more efficient. 2015-06-28 18:15:15 -07:00
Jordan Harband
a21b2e6962 Refactor this nvm use case statement out into an nvm_match_version function. 2015-06-28 18:08:38 -07:00
Jordan Harband
cc090f4476 Speed up nvm_print_npm_version. 2015-06-28 16:23:12 -07:00
Jordan Harband
c31b072145 Fix nvm debug output in zsh. 2015-06-28 17:19:15 -07:00
Jordan Harband
7bce6c6c68 nvm reinstall-packages should install the same version it had before. 2015-06-29 00:04:59 -07:00
Jordan Harband
fb2f1ac627 Merge pull request #778 from williamboman/chore/rewording
nvm.sh: s/copying/reinstalling/
2015-07-02 12:44:37 -07:00
William Boman
bc3840b6f3 nvm.sh: s/copying/reinstalling/ 2015-07-02 21:21:51 +02:00
Jordan Harband
6b8fd19d76 Merge pull request #766 from lukechilds/master
Add --without-snapshot configure flag to ARM devices by default
2015-06-18 13:42:48 -07:00
lukechilds
c1ef31df53 Remove unnecessary nvm use 2015-06-13 19:38:28 +01:00
lukechilds
3b67b3b9bb Use node instead of nvm run and check v8_use_snapshot in node rather than shell 2015-06-13 18:52:54 +01:00
lukechilds
83466446ce Added newline to end of ARM test 2015-06-13 16:10:49 +01:00
lukechilds
3214caa4ec Adding installation test for disabling V8 snapshot on ARM 2015-06-13 15:58:27 +01:00
lukechilds
67f2ee82ca POSIX compatibility 2015-06-13 10:18:58 +01:00
lukechilds
1f13f15620 Add --without-snapshot configure flag to ARM devices 2015-06-12 23:36:02 +01:00
Jordan Harband
fe044c5e3b spawn-sync now dedupes to the top level with this group of packages. 2015-06-07 01:10:55 -07:00
Jordan Harband
3cfa1ed4e1 Remove $NVM_IOJS_ORG_VERSION_LISTING env var. 2015-06-06 22:39:03 -07:00
Jordan Harband
d78722b284 v0.25.4 2015-05-29 11:11:40 -07:00
Jordan Harband
4c475b2767 Use the original ls instead of aliases.
Fixes #755
2015-05-29 11:11:14 -07:00
Jordan Harband
a539cba11e v0.25.3 2015-05-22 15:18:46 -07:00
Jordan Harband
472ba5fc46 Make sure sourcing nvm.sh on shells that don't support source options doesn't exit nonzero.
Fixes #721
2015-05-22 00:15:43 -07:00
Jordan Harband
96c96ec714 v0.25.2 2015-05-19 14:05:43 -07:00
Jordan Harband
475b8bd6b4 Update semver 2015-05-17 21:12:03 -07:00
Jordan Harband
5e805905ca Add undocumented nvm debug to print out helpful debugging info. 2015-05-14 14:56:26 -07:00
Jordan Harband
2dec01da9c nvm reinstall-packages: On systems where npm ls -g --depth=0 does not include npm for some reason, make sure to filter out (empty). 2015-05-08 14:24:51 -07:00
Jordan Harband
63672641a5 Add wrapping curly braces to ensure that the entire scripts are downloaded.
If the closing curly brace isn't present, the script will error out.
2015-05-11 01:46:18 -07:00
Jordan Harband
94bba31de3 Make sure that nvm reinstall-packages system has the right std output. 2015-05-08 14:15:42 -07:00
Jordan Harband
f70530ef18 Fix installation instructions. 2015-05-07 10:43:47 -07:00
Jordan Harband
ec33e8b720 v0.25.1 2015-05-03 15:31:54 -07:00
Jordan Harband
a4f89c6223 Make sure to ignore ~/.curlrc if it exists. 2015-05-01 02:00:49 -07:00
Jordan Harband
517817f1a3 Actually try to install from source when the error message says "binary failed, trying source". 2015-04-27 14:02:45 -07:00
Jordan Harband
a6f5eff0f3 Use uname -m instead of uname -a.
Fixes #744.
2015-04-28 22:56:43 -07:00
Jordan Harband
0aac462b15 Improve the error message when the binary tarball URL 404s.
Fixes #743
2015-04-27 13:48:22 -07:00
Jordan Harband
bb2fe618cb The install script only runs in bash. 2015-04-27 16:55:21 -07:00
Jordan Harband
eb5cecc970 v0.25.0 2015-04-26 12:58:05 -07:00
Jordan Harband
36f933984d Remove trailing whitespace. 2015-04-25 11:21:33 -07:00
Jordan Harband
54d2d70048 Merge pull request #742 from sjasperse/bugfix/rasp-pi-2-arch-detect
adding architecture detection for Raspberry Pi 2
2015-04-26 00:04:00 -07:00
Scott Jasperse
e1009149c9 adding architecture detection for Raspberry Pi 2 2015-04-25 19:10:02 -04:00
Jordan Harband
153ee6887e Merge pull request #741 from phillipsj/master
Adding .gitattributes to force unix line endings.

Fixes #728
2015-04-25 10:58:52 -07:00
Jamie Phillips
295f2b7db4 Adding .gitattributes to force unix line endings.
Hopefully this helps with issue #728
2015-04-25 10:35:22 -04:00
Jordan Harband
356ac7a697 install.sh: Ensure that the --quiet option is available before trying to use it.
Fixes #738, #657.
2015-04-22 00:40:27 -07:00
Jordan Harband
64c88ce62e Merge pull request #735 from madarche/fix-doc
Remove source bashism
2015-04-19 10:32:48 -07:00
Marc-Aurèle DARCHE
4612d8d827 Remove source bashism
Using `.` and not `source`, since it's more portable

cf. #704 and https://wiki.ubuntu.com/DashAsBinSh#source
2015-04-19 16:25:34 +02:00
Jordan Harband
6644f33a77 Update semver, use ^ instead of ~ 2015-04-17 00:24:44 -07:00
Jordan Harband
cbf0f12aac Create nvm_print_npm_version and use that when printing the npm version. 2015-04-12 10:59:17 -07:00
Jordan Harband
de93dc46d0 Merge pull request #726 from SeeThruHead/master
README: Add note about `~/.npmrc` compatibility issues.

Relates to #606.
2015-04-13 13:58:53 -07:00
Shane Keulen
7ea15a7618 Added compatibility issues section
Sections includes warnings for cretain nonstandard path settings and environment variables that conflict with nvm.
2015-04-13 16:54:20 -04:00
Jordan Harband
6a114eddcc Merge pull request #722 from ajcrites/list-npm-version
Include npm version when displaying results of switch.
2015-04-12 10:53:37 -07:00
Andrew Crites
e4149c380b Only print npm version if it exists 2015-04-09 02:31:57 -04:00
Andrew Crites
caa69bc500 npm version: shell compatibility, test update
* Update test string that checks printed node version to pass with additional npm version display
* Remove echo -n for compatibility with shells that do not support it
2015-04-09 02:12:35 -04:00
Andrew Crites
e01bcb740b Include npm version when displaying results of switch.
When running nvm use, successful changing of versions lists the new node version.  The npm version may also be switched, but this is not listed.

This commit updates nvm to display the npm version that was switched to alongside the node version
2015-04-09 01:20:51 -04:00
Jordan Harband
276d55c912 Merge pull request #718 from joliss/performance
Consolidate and avoid sed/cut calls, clean up pattern matches
2015-04-06 21:06:46 -07:00
Jo Liss
0dc177bf9c Consolidate and avoid sed/cut calls, clean up pattern matches
Some patterns contained a no-op `*`; the `*` would match the empty string
because # or % replacement (unlike ## or %%) tries to find the shortest match.
2015-04-06 20:30:38 +00:00
Jordan Harband
c34502ebc2 nvm_num_version_groups should report 0 when given just a v or a . 2015-04-06 11:10:43 -07:00
Jordan Harband
3d764e6833 Add nvm_ensure_default_set 2015-04-05 16:49:29 -07:00
Jordan Harband
a26ef4f1be Consolidate reinstall-packages-from logic to one place nvm install 2015-04-05 16:09:47 -07:00
Jordan Harband
d68f667464 When no arguments are passed to nvm run X, use nvm exec to open a REPL.
Fixes #625. Tests will be in #717.
2015-04-05 15:13:35 -07:00
Jordan Harband
c966204cd6 v0.24.1 2015-04-05 12:55:17 -07:00
Jordan Harband
d72b35b7b8 Remove external calls to sed using parameter filtering.
POSIX-compliant per http://stackoverflow.com/a/25536935/632724

Relates to #709
2015-04-05 02:35:05 -07:00
Jordan Harband
d50a0f46e9 Avoid some external calls by using case statements.
Relates to #709.
2015-04-04 23:59:12 -07:00
Jordan Harband
82393f5b36 Making sure this test passes whether a system node is installed or not. 2015-04-04 23:49:43 -07:00
Jordan Harband
a1a8e5a51b Clean up logic a bit. 2015-04-04 14:53:38 -07:00
Jordan Harband
108f630732 Cache the nvm_node_prefix call. 2015-04-04 14:31:56 -07:00
Jordan Harband
96e73825bd Consolidate faster default alias lookup, and use that explicit version to avoid a second default alias lookup in nvm use default.
Related to #709.
2015-04-04 15:45:40 -07:00
Jordan Harband
9fc20bb14b Merge pull request #710 from joliss/sed
Combine sed and grep commands
2015-04-02 17:00:20 -07:00
Jordan Harband
3401d15a18 Merge pull request #705 from joliss/performance
Improve startup performance. Closes #703
2015-04-02 16:59:38 -07:00
Jo Liss
394e8505d9 Combine sed and grep commands 2015-04-02 16:58:31 +00:00
Jo Liss
fc86834e29 Add comment re nvm_ensure_version_installed performance 2015-04-02 15:30:33 +00:00
Jo Liss
609d9ee4ea Improve startup performance. Closes #703 2015-04-02 15:30:33 +00:00
Jordan Harband
70370a857f No more need for sudo to install ksh and zsh. 2015-03-19 11:05:31 -07:00
Jordan Harband
65a986c633 Merge pull request #693 from hax/reinstall-links
support npm link for reinstall-packages
2015-03-18 22:22:23 -07:00
Jordan Harband
3cc5d6af67 Merge pull request #694 from pfac/pfac-fix-source-nvm-sh-error-message
Fix error message when sourcing nvm.sh
2015-03-18 10:05:22 -07:00
Pedro Costa
999c4111c1 Supresses error message on checking source options 2015-03-18 10:21:11 +00:00
HE Shi-Jun
3d69cf7437 update testcase 2015-03-17 15:54:50 +08:00
HE Shi-Jun
207521d54b support npm link 2015-03-17 14:19:32 +08:00
Jordan Harband
7750253bca Merge pull request #690 from hax/patch-1
Only filter the package `npm`, not any package name that contains 'npm'
2015-03-16 03:10:50 -07:00
HE Shi-Jun
14b23bfa95 fix reinstall-packages test 2015-03-15 06:21:35 +08:00
HE Shi-Jun
bf7bd3e793 Only filter the package npm, not any package name contains 'npm' 2015-03-15 06:21:35 +08:00
Jordan Harband
2b63f37f8d Make nvm_resolve_local_alias not return N/A - that should be done as shallowly as possible. 2015-03-14 10:55:31 -07:00
Jordan Harband
230b479648 Making help error output actually output to stderr consistently. 2015-03-14 10:34:52 -07:00
31 changed files with 706 additions and 232 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
*.sh eol=lf

View File

@@ -1,17 +1,16 @@
language: c # defaults to ruby
addons:
apt_packages:
- zsh
- ksh
install:
- sudo apt-get install zsh -y # ksh
- (mkdir /tmp/urchin && cd /tmp/urchin && curl -s "$(curl -s https://registry.npmjs.com/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'
script:
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL
env:
- SHELL=sh TEST_SUITE=install_script
- SHELL=dash TEST_SUITE=install_script
- SHELL=bash TEST_SUITE=install_script
- SHELL=zsh TEST_SUITE=install_script
# - SHELL=ksh TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast

View File

@@ -4,23 +4,22 @@
First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.
Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/nvm/issues/284)). Two alternatives exist, which are not supported nor developed by us:
Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/nvm/issues/284)). Two alternatives exist, which are neither supported nor developed by us:
- [nvmw](https://github.com/hakobera/nvmw)
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). Two alternatives exist, which are not supported nor developed by us:
- [nvm-fish-wrapper](https://github.com/passcod/nvm-fish-wrapper)
- [nvm-fish](https://github.com/Alex7Kom/nvm-fish) (does not support iojs)
Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). An alternative exists, which is neither supported nor developed by us:
- [bass](https://github.com/edc/bass) allows to use utilities written for Bash in fish shell
### Install script
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.26.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.24.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.26.0/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
@@ -39,7 +38,7 @@ Or if you have `git` installed, then just clone it, and check out the latest ver
To activate nvm, you need to source it from your shell:
source ~/.nvm/nvm.sh
. ~/.nvm/nvm.sh
I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login.
Often I also put in a line to use a specific version of node.
@@ -76,10 +75,27 @@ In place of a version pointer like "0.10", you can use the special default alias
nvm use stable
nvm run unstable --version
If you want to install a new version of Node.js and migrate npm packages from a previous version:
nvm install node --reinstall-packages-from=node
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
You can also install and migrate npm packages from specific versions of Node like this:
nvm install v0.10.40 --reinstall-packages-from=0.10.39
nvm install v0.12.7 --reinstall-packages-from=0.12.6
If you want to install [io.js](https://github.com/iojs/io.js/):
nvm install iojs
If you want to install a new version of io.js and migrate npm packages from a previous version:
nvm install iojs --reinstall-packages-from=iojs
The same guidelines mentioned for migrating npm packages in Node.js are applicable to io.js.
If you want to use the system-installed version of node, you can use the special default alias "system":
nvm use system
@@ -187,6 +203,20 @@ nvm uninstall
$ nvm uninstall [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28
## Compatibility Issues
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606))
The following are known to cause issues:
Inside `~/.npmrc`
```
prefix='some/path'
```
Environment Variables:
```
$NPM_CONFIG_PREFIX
$PREFIX
```
## Problems
If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following:
@@ -206,7 +236,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.24.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.26.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com

View File

@@ -57,7 +57,7 @@ __nvm_aliases ()
declare aliases
aliases=""
if [ -d $NVM_DIR/alias ]; then
aliases="`cd $NVM_DIR/alias && ls`"
aliases="`cd $NVM_DIR/alias && command ls`"
fi
echo "${aliases}"
}

View File

@@ -2,6 +2,8 @@
set -e
{ # this ensures the entire script is downloaded #
nvm_has() {
type "$1" > /dev/null 2>&1
}
@@ -11,7 +13,7 @@ if [ -z "$NVM_DIR" ]; then
fi
nvm_latest_version() {
echo "v0.24.0"
echo "v0.26.0"
}
#
@@ -42,7 +44,7 @@ nvm_source() {
nvm_download() {
if nvm_has "curl"; then
curl $*
curl -q $*
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -71,7 +73,12 @@ install_nvm_from_git() {
fi
cd "$NVM_DIR" && command git checkout --quiet $(nvm_latest_version)
if [ ! -z "$(cd "$NVM_DIR" && git show-ref refs/heads/master)" ]; then
cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&1
if git branch --quiet 2>/dev/null; then
cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&1
else
echo >&2 "Your version of git is out of date. Please update it!"
cd "$NVM_DIR" && command git branch -D master >/dev/null 2>&1
fi
fi
return
}
@@ -110,16 +117,38 @@ install_nvm_as_script() {
# Otherwise, an empty string is returned
#
nvm_detect_profile() {
if [ -f "$PROFILE" ]; then
echo "$PROFILE"
elif [ -f "$HOME/.bashrc" ]; then
echo "$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
echo "$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
echo "$HOME/.zshrc"
elif [ -f "$HOME/.profile" ]; then
echo "$HOME/.profile"
local DETECTED_PROFILE
DETECTED_PROFILE=''
local SHELLTYPE
SHELLTYPE="$(basename /$SHELL)"
if [ $SHELLTYPE = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ $SHELLTYPE = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
if [ -z $DETECTED_PROFILE ]; then
if [ -f "$PROFILE" ]; then
DETECTED_PROFILE="$PROFILE"
elif [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
fi
if [ ! -z $DETECTED_PROFILE ]; then
echo "$DETECTED_PROFILE"
fi
}
@@ -221,7 +250,8 @@ nvm_do_install() {
nvm_check_global_modules
echo "=> Close and reopen your terminal to start using nvm"
. $NVM_DIR/nvm.sh
echo "=> You can now start using nvm"
nvm_reset
}
@@ -236,3 +266,5 @@ nvm_reset() {
}
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
} # this ensures the entire script is downloaded #

View File

@@ -11,4 +11,3 @@ else
fi
exec $@

544
nvm.sh
View File

@@ -6,6 +6,8 @@
# Implemented by Tim Caswell <tim@creationix.com>
# with much bash help from Matthew Ranney
{ # this ensures the entire script is downloaded #
NVM_SCRIPT_SOURCE="$_"
nvm_has() {
@@ -20,7 +22,7 @@ nvm_is_alias() {
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)"
NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
@@ -37,7 +39,7 @@ nvm_get_latest() {
nvm_download() {
if nvm_has "curl"; then
curl $*
curl -q $*
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -58,6 +60,12 @@ nvm_has_system_iojs() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
}
nvm_print_npm_version() {
if nvm_has "npm"; then
echo " (npm v$(npm --version 2>/dev/null))"
fi
}
# Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors
if nvm_has "unsetopt"; then
@@ -83,9 +91,6 @@ fi
if [ -z "$NVM_IOJS_ORG_MIRROR" ]; then
export NVM_IOJS_ORG_MIRROR="https://iojs.org/dist"
fi
if [ -z "$NVM_IOJS_ORG_VERSION_LISTING" ]; then
export NVM_IOJS_ORG_VERSION_LISTING="$NVM_IOJS_ORG_MIRROR/index.tab"
fi
nvm_tree_contains_path() {
local tree
@@ -193,10 +198,14 @@ nvm_ensure_version_installed() {
local PROVIDED_VERSION
PROVIDED_VERSION="$1"
local LOCAL_VERSION
local EXIT_CODE
LOCAL_VERSION="$(nvm_version "$PROVIDED_VERSION")"
EXIT_CODE="$?"
local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$LOCAL_VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
if [ "_$EXIT_CODE" = "_0" ]; then
NVM_VERSION_DIR="$(nvm_version_path "$LOCAL_VERSION")"
fi
if [ "_$EXIT_CODE" != "_0" ] || [ ! -d "$NVM_VERSION_DIR" ]; then
VERSION="$(nvm_resolve_alias "$PROVIDED_VERSION")"
if [ $? -eq 0 ]; then
echo "N/A: version \"$PROVIDED_VERSION -> $VERSION\" is not yet installed" >&2
@@ -222,8 +231,10 @@ nvm_version() {
return $?
fi
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
case "_$PATTERN" in
"_$(nvm_node_prefix)" | "_$(nvm_node_prefix)-")
"_$NVM_NODE_PREFIX" | "_$NVM_NODE_PREFIX-")
PATTERN="stable"
;;
esac
@@ -259,14 +270,12 @@ nvm_remote_version() {
}
nvm_remote_versions() {
local NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local PATTERN
PATTERN="$1"
if [ "_$PATTERN" = "_io.js" ]; then
PATTERN="$NVM_IOJS_PREFIX"
fi
case "_$PATTERN" in
"_$NVM_IOJS_PREFIX")
"_$NVM_IOJS_PREFIX" | "_io.js")
VERSIONS="$(nvm_ls_remote_iojs)"
;;
"_$(nvm_node_prefix)")
@@ -295,7 +304,8 @@ nvm_is_valid_version() {
return 0
fi
case "$1" in
"$(nvm_iojs_prefix)" | "$(nvm_node_prefix)")
"$(nvm_iojs_prefix)" | \
"$(nvm_node_prefix)")
return 0
;;
*)
@@ -307,7 +317,7 @@ nvm_is_valid_version() {
}
nvm_normalize_version() {
echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
echo "${1#v}" | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'
}
nvm_ensure_version_prefix() {
@@ -324,8 +334,7 @@ nvm_format_version() {
local VERSION
VERSION="$(nvm_ensure_version_prefix "$1")"
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
VERSION="$(echo "$VERSION" | command sed -e 's/\.*$/.0/')"
nvm_format_version "$VERSION"
nvm_format_version "${VERSION%.}.0"
else
echo "$VERSION"
fi
@@ -334,14 +343,16 @@ nvm_format_version() {
nvm_num_version_groups() {
local VERSION
VERSION="$1"
VERSION="${VERSION#v}"
VERSION="${VERSION%.}"
if [ -z "$VERSION" ]; then
echo "0"
return
fi
local NVM_NUM_DOTS
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/^v//' | command sed -e 's/\.$//' | command sed -e 's/[^\.]//g')
NVM_NUM_DOTS=$(echo "$VERSION" | command sed -e 's/[^\.]//g')
local NVM_NUM_GROUPS
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
NVM_NUM_GROUPS=".$NVM_NUM_DOTS" # add extra dot, since it's (n - 1) dots at this point
echo "${#NVM_NUM_GROUPS}"
}
@@ -478,7 +489,6 @@ nvm_resolve_local_alias() {
VERSION="$(nvm_resolve_alias "$1")"
EXIT_CODE=$?
if [ -z "$VERSION" ]; then
echo "N/A"
return $EXIT_CODE
fi
if [ "_$VERSION" != "_∞" ]; then
@@ -496,7 +506,8 @@ nvm_node_prefix() {
}
nvm_is_iojs_version() {
[ "_$(echo "$1" | cut -c1-5)" = "_iojs-" ]
case "$1" in iojs-*) return 0 ;; esac
return 1
}
nvm_add_iojs_prefix() {
@@ -509,7 +520,7 @@ nvm_strip_iojs_prefix() {
if [ "_$1" = "_$NVM_IOJS_PREFIX" ]; then
echo
else
echo "$1" | command sed "s/^$NVM_IOJS_PREFIX-//"
echo "${1#"$NVM_IOJS_PREFIX"-}"
fi
}
@@ -528,7 +539,7 @@ nvm_ls() {
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
local NVM_VERSION_DIR_IOJS
NVM_VERSION_DIR_IOJS="$(nvm_version_dir iojs)"
NVM_VERSION_DIR_IOJS="$(nvm_version_dir "$NVM_IOJS_PREFIX")"
local NVM_VERSION_DIR_NEW
NVM_VERSION_DIR_NEW="$(nvm_version_dir new)"
local NVM_VERSION_DIR_OLD
@@ -546,7 +557,12 @@ nvm_ls() {
;;
esac
# If it looks like an explicit version, don't do anything funny
if [ "_$(echo "$PATTERN" | cut -c1-1)" = "_v" ] && [ "_$(nvm_num_version_groups "$PATTERN")" = "_3" ]; then
local NVM_PATTERN_STARTS_WITH_V
case $PATTERN in
v*) NVM_PATTERN_STARTS_WITH_V=true ;;
*) NVM_PATTERN_STARTS_WITH_V=false ;;
esac
if [ $NVM_PATTERN_STARTS_WITH_V = true ] && [ "_$(nvm_num_version_groups "$PATTERN")" = "_3" ]; then
if [ -d "$(nvm_version_path "$PATTERN")" ]; then
VERSIONS="$PATTERN"
elif [ -d "$(nvm_version_path "$(nvm_add_iojs_prefix "$PATTERN")")" ]; then
@@ -559,7 +575,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" | command sed -e 's/\.*$//g')."
PATTERN="${PATTERN%.}."
fi
;;
esac
@@ -604,17 +620,21 @@ nvm_ls() {
fi
if [ -n "$NVM_DIRS_TO_SEARCH" ]; then
VERSIONS="$(command find $NVM_DIRS_TO_SEARCH -maxdepth 1 -type d -name "$PATTERN*" \
| command sed "s#$NVM_VERSION_DIR_IOJS/#"$NVM_IOJS_PREFIX"-#" \
| command grep -v "$NVM_VERSION_DIR_IOJS" \
| command sed "s#^$NVM_DIR/##" \
| command grep -v -e '^versions$' \
| command sed 's#^versions/##' \
| sed -e "s/^v/$NVM_NODE_PREFIX-v/" \
| sed -e "s#^\($NVM_IOJS_PREFIX\)[-/]v#\1.v#" | sed -e "s#^\($NVM_NODE_PREFIX\)[-/]v#\1.v#" \
| command sed "
s#$NVM_VERSION_DIR_IOJS/#$NVM_IOJS_PREFIX-#;
\#$NVM_VERSION_DIR_IOJS# d;
s#^$NVM_DIR/##;
\#^versions\$# d;
s#^versions/##;
s#^v#$NVM_NODE_PREFIX-v#;
s#^\($NVM_IOJS_PREFIX\)[-/]v#\1.v#;
s#^\($NVM_NODE_PREFIX\)[-/]v#\1.v#" \
| command sort -t. -u -k 2.2,2n -k 3,3n -k 4,4n \
| command sort -s -t- -k1.1,1.1 \
| command sed "s/^\($NVM_IOJS_PREFIX\)\./\1-/" \
| command sed "s/^$NVM_NODE_PREFIX\.//")"
| command sed "
s/^\($NVM_IOJS_PREFIX\)\./\1-/;
s/^$NVM_NODE_PREFIX\.//" \
)"
fi
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
@@ -663,18 +683,32 @@ nvm_ls_remote() {
}
nvm_ls_remote_iojs() {
nvm_ls_remote_iojs_org std "$NVM_IOJS_ORG_MIRROR" "$1"
}
nvm_ls_remote_iojs_org() {
local PREFIX
if [ "_$1" = "_std" ]; then
PREFIX="$(nvm_iojs_prefix)"
else
echo "unknown type of io.js release" >&2
return 4
fi
local MIRROR
MIRROR="$2"
local PATTERN
PATTERN="$1"
PATTERN="$3"
local VERSIONS
if [ -n "$PATTERN" ]; then
PATTERN="$(nvm_ensure_version_prefix $(nvm_strip_iojs_prefix "$PATTERN"))"
else
PATTERN=".*"
fi
VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \
| command sed 1d \
| command sed "s/^/$(nvm_iojs_prefix)-/" \
| command cut -f1 \
VERSIONS="$(nvm_download -L -s "$MIRROR/index.tab" -o - \
| command sed "
1d;
s/^/$PREFIX-/;
s/[[:blank:]].*//" \
| command grep -w "$PATTERN" \
| command sort)"
if [ -z "$VERSIONS" ]; then
@@ -750,7 +784,9 @@ nvm_print_implicit_alias() {
return 1
fi
if ! nvm_validate_implicit_alias "$2"; then
local NVM_IMPLICIT
NVM_IMPLICIT="$2"
if ! nvm_validate_implicit_alias "$NVM_IMPLICIT"; then
return 2
fi
@@ -761,12 +797,14 @@ nvm_print_implicit_alias() {
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
local NVM_COMMAND
local NVM_ADD_PREFIX_COMMAND
local LAST_TWO
case "$2" in
"$NVM_IOJS_PREFIX")
case "$NVM_IMPLICIT" in
"$NVM_IOJS_PREFIX" | "$NVM_IOJS_RC_PREFIX")
NVM_COMMAND="nvm_ls_remote_iojs"
NVM_ADD_PREFIX_COMMAND="nvm_add_iojs_prefix"
if [ "_$1" = "_local" ]; then
NVM_COMMAND="nvm_ls iojs"
NVM_COMMAND="nvm_ls "$NVM_IMPLICIT""
fi
ZHS_HAS_SHWORDSPLIT_UNSET=1
@@ -776,7 +814,7 @@ nvm_print_implicit_alias() {
fi
local NVM_IOJS_VERSION
NVM_IOJS_VERSION="$($NVM_COMMAND | sed "s/^"$NVM_IOJS_PREFIX"-//" | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq | tail -1)"
NVM_IOJS_VERSION="$($NVM_COMMAND | sed "s/^"$NVM_IMPLICIT"-//" | command grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq | tail -1)"
local EXIT_CODE
EXIT_CODE="$?"
@@ -784,7 +822,7 @@ nvm_print_implicit_alias() {
unsetopt shwordsplit
fi
echo "$(nvm_add_iojs_prefix "$NVM_IOJS_VERSION")"
echo "$($NVM_ADD_PREFIX_COMMAND "$NVM_IOJS_VERSION")"
return $EXIT_CODE
;;
"$NVM_NODE_PREFIX")
@@ -854,21 +892,49 @@ nvm_get_os() {
nvm_get_arch() {
local NVM_UNAME
NVM_UNAME="$(uname -a)"
NVM_UNAME="$(uname -m)"
local NVM_ARCH
case "$NVM_UNAME" in
*x86_64*) NVM_ARCH=x64 ;;
*i*86*) NVM_ARCH=x86 ;;
*) NVM_ARCH="$(uname -m)" ;;
x86_64) NVM_ARCH="x64" ;;
i*86) NVM_ARCH="x86" ;;
*) NVM_ARCH="$NVM_UNAME" ;;
esac
echo "$NVM_ARCH"
}
nvm_ensure_default_set() {
local VERSION
VERSION="$1"
if [ -z "$VERSION" ]; then
echo 'nvm_ensure_default_set: a version is required' >&2
return 1
fi
if nvm_alias default >/dev/null 2>&1; then
# default already set
return 0
fi
local OUTPUT
OUTPUT="$(nvm alias default "$VERSION")"
local EXIT_CODE
EXIT_CODE="$?"
echo "Creating default alias: $OUTPUT"
return $EXIT_CODE
}
nvm_install_iojs_binary() {
local NVM_IOJS_TYPE
NVM_IOJS_TYPE="$1"
local MIRROR
if [ "_$NVM_IOJS_TYPE" = "_std" ]; then
MIRROR="$NVM_IOJS_ORG_MIRROR"
else
echo "unknown type of io.js release" >&2
return 4
fi
local PREFIXED_VERSION
PREFIXED_VERSION="$1"
PREFIXED_VERSION="$2"
local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2"
REINSTALL_PACKAGES_FROM="$3"
if ! nvm_is_iojs_version "$PREFIXED_VERSION"; then
echo 'nvm_install_iojs_binary requires an iojs-prefixed version.' >&2
@@ -888,15 +954,22 @@ nvm_install_iojs_binary() {
if [ -n "$NVM_OS" ]; then
if nvm_binary_available "$VERSION"; then
t="$VERSION-$NVM_OS-$(nvm_get_arch)"
url="$NVM_IOJS_ORG_MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz"
sum="$(nvm_download -L -s $NVM_IOJS_ORG_MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')"
url="$MIRROR/$VERSION/$(nvm_iojs_prefix)-${t}.tar.gz"
sum="$(nvm_download -L -s $MIRROR/$VERSION/SHASUMS256.txt -o - | command grep $(nvm_iojs_prefix)-${t}.tar.gz | command awk '{print $1}')"
local tmpdir
tmpdir="$NVM_DIR/bin/iojs-${t}"
local tmptarball
tmptarball="$tmpdir/iojs-${t}.tar.gz"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if (
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
[ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
@@ -906,7 +979,7 @@ nvm_install_iojs_binary() {
); then
return 0
else
echo "Binary download failed, trying source." >&2
echo >&2 "Binary download failed, trying source." >&2
command rm -rf "$tmptarball" "$tmpdir"
return 1
fi
@@ -938,7 +1011,7 @@ nvm_install_node_binary() {
if nvm_binary_available "$VERSION"; then
local NVM_ARCH
NVM_ARCH="$(nvm_get_arch)"
if [ $NVM_ARCH = "armv6l" ]; then
if [ $NVM_ARCH = "armv6l" ] || [ $NVM_ARCH = "armv7l" ]; then
NVM_ARCH="arm-pi"
fi
t="$VERSION-$NVM_OS-$NVM_ARCH"
@@ -948,9 +1021,16 @@ nvm_install_node_binary() {
tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
tmptarball="$tmpdir/node-${t}.tar.gz"
local NVM_INSTALL_ERRORED
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" || \
NVM_INSTALL_ERRORED=true
if grep '404 Not Found' "$tmptarball" >/dev/null; then
NVM_INSTALL_ERRORED=true
echo >&2 "HTTP 404 at URL $url";
fi
if (
command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
[ "$NVM_INSTALL_ERRORED" != true ] && \
nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \
@@ -959,7 +1039,7 @@ nvm_install_node_binary() {
); then
return 0
else
echo "Binary download failed, trying source." >&2
echo >&2 "Binary download failed, trying source."
command rm -rf "$tmptarball" "$tmpdir"
return 1
fi
@@ -971,10 +1051,14 @@ nvm_install_node_binary() {
nvm_install_node_source() {
local VERSION
VERSION="$1"
local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2"
local ADDITIONAL_PARAMETERS
ADDITIONAL_PARAMETERS="$3"
ADDITIONAL_PARAMETERS="$2"
local NVM_ARCH
NVM_ARCH="$(nvm_get_arch)"
if [ $NVM_ARCH = "armv6l" ] || [ $NVM_ARCH = "armv7l" ]; then
ADDITIONAL_PARAMETERS="--without-snapshot $ADDITIONAL_PARAMETERS"
fi
if [ -n "$ADDITIONAL_PARAMETERS" ]; then
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
@@ -1020,9 +1104,6 @@ nvm_install_node_source() {
$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
@@ -1045,6 +1126,43 @@ nvm_install_node_source() {
return $?
}
nvm_match_version() {
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local PROVIDED_VERSION
PROVIDED_VERSION="$1"
case "_$PROVIDED_VERSION" in
"_$NVM_IOJS_PREFIX" | "_io.js")
echo "$(nvm_version $NVM_IOJS_PREFIX)"
;;
"_system")
echo "system"
;;
*)
echo "$(nvm_version "$PROVIDED_VERSION")"
;;
esac
}
nvm_npm_global_modules() {
local NPMLIST
local VERSION
VERSION="$1"
if [ "_$VERSION" = "_system" ]; then
NPMLIST=$(nvm use system > /dev/null && npm list -g --depth=0 2> /dev/null | command tail -n +2)
else
NPMLIST=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 2> /dev/null | command tail -n +2)
fi
local INSTALLS
INSTALLS=$(echo "$NPMLIST" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)
local LINKS
LINKS="$(echo "$NPMLIST" | command sed -n 's/.* -> \(.*\)/\1/ p')"
echo "$INSTALLS //// $LINKS"
}
nvm() {
if [ $# -lt 1 ]; then
nvm help
@@ -1061,38 +1179,70 @@ nvm() {
case $1 in
"help" )
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
echo
echo "Node Version Manager"
echo
echo "Usage:"
echo " nvm help Show this message"
echo " nvm --version Print out the latest released version of nvm"
echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available"
echo " nvm uninstall <version> Uninstall a version"
echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available"
echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"
echo " nvm current Display currently activated version"
echo " nvm ls List installed versions"
echo " nvm ls <version> List versions matching a given description"
echo " nvm ls-remote List remote versions available for install"
echo " nvm deactivate Undo effects of \`nvm\` on current shell"
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 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 'Note: <version> refers to any version-like string nvm understands. This includes:'
echo ' - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)'
echo " - default (built-in) aliases: $NVM_NODE_PREFIX, stable, unstable, $NVM_IOJS_PREFIX, system"
echo ' - custom aliases you define with `nvm alias foo`'
echo
echo "Example:"
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 run 0.10.32 app.js Run app.js using node v0.10.32"
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 'Usage:'
echo ' nvm help Show this message'
echo ' nvm --version Print out the latest released version of nvm'
echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available'
echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
echo ' nvm uninstall <version> Uninstall a version'
echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
echo ' nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>'
echo ' nvm current Display currently activated version'
echo ' nvm ls List installed versions'
echo ' nvm ls <version> List versions matching a given description'
echo ' nvm ls-remote List remote versions available for install'
echo ' nvm version <version> Resolve the given description to a single local version'
echo ' nvm version-remote <version> Resolve the given description to a single remote version'
echo ' nvm deactivate Undo effects of `nvm` on current shell'
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 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 "Note:"
echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
echo 'Example:'
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 run 0.10.32 app.js Run app.js using node v0.10.32'
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 'Note:'
echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'
echo
;;
"debug" )
local ZHS_HAS_SHWORDSPLIT_UNSET
if nvm_has "setopt"; then
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | command grep shwordsplit > /dev/null ; echo $?)
setopt shwordsplit
fi
echo >&2 "\$SHELL: $SHELL"
echo >&2 "\$NVM_DIR: $(echo $NVM_DIR | sed "s#$HOME#\$HOME#g")"
local NVM_DEBUG_OUTPUT
for NVM_DEBUG_COMMAND in 'nvm current' 'which node' 'which iojs' 'which npm' 'npm config get prefix' 'npm root -g'
do
NVM_DEBUG_OUTPUT="$($NVM_DEBUG_COMMAND 2>&1 | sed "s#$NVM_DIR#\$NVM_DIR#g")"
echo >&2 "$NVM_DEBUG_COMMAND: $NVM_DEBUG_OUTPUT"
done
if [ "_$ZHS_HAS_SHWORDSPLIT_UNSET" = "_1" ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
return 42
;;
"install" | "i" )
@@ -1112,8 +1262,8 @@ nvm() {
version_not_provided=1
nvm_rc_version
if [ -z "$NVM_RC_VERSION" ]; then
nvm help
return
>&2 nvm help
return 127
fi
fi
@@ -1149,15 +1299,19 @@ nvm() {
while [ $# -ne 0 ]
do
if [ "_$(echo "$1" | command cut -c 1-26)" = "_--reinstall-packages-from=" ]; then
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 27-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
elif [ "_$(echo "$1" | command cut -c 1-21)" = "_--copy-packages-from=" ]; then
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 22-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
else
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
fi
case "$1" in
--reinstall-packages-from=*)
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 27-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
;;
--copy-packages-from=*)
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | command cut -c 22-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
;;
*)
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
;;
esac
shift
done
@@ -1191,34 +1345,38 @@ nvm() {
# io.js does not have a SunOS binary
nobinary=1
fi
local NVM_INSTALL_SUCCESS
# skip binary install if "nobinary" option specified.
if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then
local NVM_INSTALL_SUCCESS
if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary std "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true
elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then
NVM_INSTALL_SUCCESS=true
fi
fi
if [ "$NVM_INSTALL_SUCCESS" != true ]; then
if [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2
return 105
elif nvm_install_node_source "$VERSION" "$ADDITIONAL_PARAMETERS"; then
NVM_INSTALL_SUCCESS=true
fi
fi
if [ "$NVM_INSTALL_SUCCESS" = true ] \
&& nvm use "$VERSION" \
&& [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then
if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
&& [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi
return $?
fi
if [ "$NVM_IOJS" = true ]; then
# nvm_install_iojs_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
echo "Installing iojs from source is not currently supported" >&2
return 105
else
nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS"
fi
return $?
;;
"uninstall" )
[ $# -ne 2 ] && nvm help && return
if [ $# -ne 2 ]; then
>&2 nvm help
return 127
fi
local PATTERN
PATTERN="$2"
@@ -1298,12 +1456,14 @@ nvm() {
fi
;;
"use" )
if [ $# -eq 0 ]; then
nvm help
return 127
local PROVIDED_VERSION
local NVM_USE_SILENT
NVM_USE_SILENT=0
if [ "$2" = '--silent' ]; then
NVM_USE_SILENT=1
shift
fi
local PROVIDED_VERSION
if [ $# -eq 1 ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
@@ -1311,45 +1471,41 @@ nvm() {
VERSION="$(nvm_version "$PROVIDED_VERSION")"
fi
else
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
PROVIDED_VERSION="$2"
case "_$PROVIDED_VERSION" in
"_$NVM_IOJS_PREFIX" | "_io.js")
VERSION="$(nvm_version $NVM_IOJS_PREFIX)"
;;
"_system")
VERSION="system"
;;
*)
VERSION="$(nvm_version "$PROVIDED_VERSION")"
;;
esac
VERSION="$(nvm_match_version "$PROVIDED_VERSION")"
fi
if [ -z "$VERSION" ]; then
nvm help
>&2 nvm help
return 127
fi
if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
echo "Now using system version of node: $(node -v 2>/dev/null)."
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"
fi
return
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then
echo "Now using system version of io.js: $(iojs --version 2>/dev/null)."
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
fi
return
else
echo "System version of node not found." >&2
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "System version of node not found." >&2
fi
return 127
fi
elif [ "_$VERSION" = "_∞" ]; then
echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "The alias \"$PROVIDED_VERSION\" leads to an infinite loop. Aborting." >&2
fi
return 8
fi
# This nvm_ensure_version_installed call can be a performance bottleneck
# on shell startup. Perhaps we can optimize it away or make it faster.
nvm_ensure_version_installed "$PROVIDED_VERSION"
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
@@ -1381,9 +1537,13 @@ nvm() {
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
fi
if nvm_is_iojs_version "$VERSION"; then
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")"
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
fi
else
echo "Now using node $VERSION"
if [ $NVM_USE_SILENT -ne 1 ]; then
echo "Now using node $VERSION$(nvm_print_npm_version)"
fi
fi
;;
"run" )
@@ -1400,7 +1560,7 @@ nvm() {
VERSION='N/A'
fi
if [ $VERSION = "N/A" ]; then
nvm help
>&2 nvm help
return 127
fi
fi
@@ -1438,6 +1598,13 @@ nvm() {
if [ "_$VERSION" = "_N/A" ]; then
echo "$(nvm_ensure_version_prefix "$provided_version") is not installed yet" >&2
EXIT_CODE=1
elif [ -z "$ARGS" ]; then
if [ "$NVM_IOJS" = true ]; then
nvm exec "$VERSION" iojs
else
nvm exec "$VERSION" node
fi
EXIT_CODE="$?"
elif [ "$NVM_IOJS" = true ]; then
echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")"
OUTPUT="$(nvm use "$VERSION" >/dev/null && iojs $ARGS)"
@@ -1494,9 +1661,13 @@ nvm() {
"ls-remote" | "list-remote" )
local PATTERN
PATTERN="$2"
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
NVM_NODE_PREFIX="$(nvm_node_prefix)"
local NVM_FLAVOR
case "_$PATTERN" in
"_$(nvm_iojs_prefix)" | "_$(nvm_node_prefix)" )
"_$NVM_IOJS_PREFIX" | "_$NVM_NODE_PREFIX" )
NVM_FLAVOR="$PATTERN"
PATTERN="$3"
;;
@@ -1506,7 +1677,7 @@ nvm() {
NVM_LS_REMOTE_EXIT_CODE=0
local NVM_LS_REMOTE_OUTPUT
NVM_LS_REMOTE_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$(nvm_iojs_prefix)" ]; then
if [ "_$NVM_FLAVOR" != "_$NVM_IOJS_PREFIX" ]; then
NVM_LS_REMOTE_OUTPUT=$(nvm_ls_remote "$PATTERN")
NVM_LS_REMOTE_EXIT_CODE=$?
fi
@@ -1515,7 +1686,7 @@ nvm() {
NVM_LS_REMOTE_IOJS_EXIT_CODE=0
local NVM_LS_REMOTE_IOJS_OUTPUT
NVM_LS_REMOTE_IOJS_OUTPUT=''
if [ "_$NVM_FLAVOR" != "_$(nvm_node_prefix)" ]; then
if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ]; then
NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$PATTERN")
NVM_LS_REMOTE_IOJS_EXIT_CODE=$?
fi
@@ -1549,7 +1720,7 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
VERSION="$2"
fi
if [ -z "$VERSION" ]; then
nvm help
>&2 nvm help
return 127
fi
@@ -1633,14 +1804,17 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
local NVM_ALIAS_DIR
NVM_ALIAS_DIR="$(nvm_alias_path)"
command mkdir -p "$NVM_ALIAS_DIR"
[ $# -ne 2 ] && nvm help && return 127
if [ $# -ne 2 ]; then
>&2 nvm help
return 127
fi
[ ! -f "$NVM_ALIAS_DIR/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
command rm -f "$NVM_ALIAS_DIR/$2"
echo "Deleted alias $2"
;;
"reinstall-packages" | "copy-packages" )
if [ $# -ne 2 ]; then
nvm help
>&2 nvm help
return 127
fi
@@ -1652,63 +1826,99 @@ $NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"
return 2
fi
local INSTALLS
local VERSION
if [ "_$PROVIDED_VERSION" = "_system" ]; then
if ! nvm_has_system_node && ! nvm_has_system_iojs; then
echo 'No system version of node or io.js detected.' >&2
return 3
fi
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)
VERSION="system"
else
local VERSION
VERSION="$(nvm_version "$PROVIDED_VERSION")"
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | command tail -n +2 | command grep -o -e ' [^@]*' | command cut -c 2- | command grep -v npm | command xargs)
fi
echo "Copying global packages from $VERSION..."
local NPMLIST
NPMLIST="$(nvm_npm_global_modules "$VERSION")"
local INSTALLS
local LINKS
INSTALLS="${NPMLIST%% //// *}"
LINKS="${NPMLIST##* //// }"
echo "Reinstalling global packages from $VERSION..."
echo "$INSTALLS" | command xargs npm install -g --quiet
echo "Linking global packages from $VERSION..."
set -f; IFS='
' # necessary to turn off variable expansion except for newlines
for LINK in $LINKS; do
set +f; unset IFS # restore variable expansion
if [ -n "$LINK" ]; then
(cd "$LINK" && npm link)
fi
done
set +f; unset IFS # restore variable expansion in case $LINKS was empty
;;
"clear-cache" )
command rm -f $NVM_DIR/v* "$(nvm_version_dir)" 2>/dev/null
echo "Cache cleared."
;;
"version" )
nvm_version $2
nvm_version "$2"
;;
"version-remote" )
nvm_remote_version "$2"
;;
"--version" )
echo "0.24.0"
echo "0.26.0"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum \
nvm_iojs_prefix nvm_node_prefix \
nvm_add_iojs_prefix nvm_strip_iojs_prefix \
nvm_is_iojs_version \
nvm_ls_remote nvm_ls nvm_remote_version nvm_remote_versions \
nvm_version nvm_rc_version \
nvm_is_iojs_version nvm_is_alias \
nvm_ls_remote nvm_ls_remote_iojs nvm_ls_remote_iojs_org \
nvm_ls nvm_remote_version nvm_remote_versions \
nvm_install_iojs_binary nvm_install_node_binary \
nvm_install_node_source \
nvm_version nvm_rc_version nvm_match_version \
nvm_ensure_default_set nvm_get_arch nvm_get_os \
nvm_print_implicit_alias nvm_validate_implicit_alias \
nvm_resolve_alias nvm_ls_current nvm_alias \
nvm_binary_available nvm_prepend_path nvm_strip_path \
nvm_num_version_groups nvm_format_version nvm_ensure_version_prefix \
nvm_normalize_version nvm_is_valid_version \
nvm_ensure_version_installed \
nvm_version_path nvm_alias_path nvm_version_dir \
nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \
nvm_version_greater nvm_version_greater_than_or_equal_to \
nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \
nvm_download nvm_get_latest nvm_has nvm_get_latest \
nvm_supports_source_options > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
nvm help
>&2 nvm help
return 127
;;
esac
}
nvm_supports_source_options() {
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
[ "_$(echo 'echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]
}
VERSION="$(nvm_alias default 2>/dev/null || echo)"
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 [ -n "$VERSION" ]; then
nvm use --silent "$VERSION" >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null
nvm use --silent >/dev/null
fi
} # this ensures the entire script is downloaded #

View File

@@ -1,6 +1,6 @@
{
"name": "nvm",
"version": "0.24.0",
"version": "0.26.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
@@ -30,8 +30,8 @@
},
"homepage": "https://github.com/creationix/nvm",
"devDependencies": {
"replace": "~0.3.0",
"semver": "~4.2.0",
"urchin": "~0.0.5"
"replace": "^0.3.0",
"semver": "^5.0.1",
"urchin": "^0.0.5"
}
}

View File

@@ -0,0 +1,18 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm alias default 0.1 >/dev/null || die "'nvm alias default 0.1' failed"
nvm_ensure_default_set 0.3 || die "'nvm_ensure_default_set' with an existing default alias exits 0"
nvm unalias default || die "'nvm unalias default' failed"
OUTPUT="$(nvm_ensure_default_set 0.2)"
EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10)"
EXIT_CODE="$?"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set 0.2' did not output '$EXPECTED_OUTPUT', got '$OUTPUT'"
[ "_$EXIT_CODE" = "_0" ] || die "'nvm_ensure_default_set 0.2' did not exit with 0, got $EXIT_CODE"

View File

@@ -20,7 +20,7 @@ done
OUTPUT="$(nvm_resolve_local_alias nonexistent)"
EXIT_CODE=$(nvm_resolve_local_alias nonexistent > /dev/null 2>&1 ; echo $?)
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_resolve_local_alias nonexistent' did not return 2; got $EXIT_CODE"
[ "_$OUTPUT" = "_N/A" ] || die "'nvm_resolve_local_alias nonexistent' did not output N/A; got $OUTPUT"
[ "_$OUTPUT" = "_" ] || die "'nvm_resolve_local_alias nonexistent' did not have empty output; got $OUTPUT"
STABLE="$(nvm_resolve_local_alias stable)"
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias stable' was not v0.0.10; got $STABLE"

View File

@@ -14,3 +14,4 @@ rm -f "../../../alias/stable"
rm -f "../../../alias/unstable"
rm -f "../../../alias/node"
rm -f "../../../alias/iojs"
rm -f "../../../alias/default"

View File

@@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
OUTPUT="$(nvm use --silent foo 2>&1)"
EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
cleanup;

View File

@@ -18,5 +18,13 @@ EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
OUTPUT="$(nvm use --silent foo 2>&1)"
EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8 from 'nvm use --silent foo'; got $EXIT_CODE"
cleanup;

View File

@@ -5,9 +5,18 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm_has_system_node() { return 0; }
[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node"
nvm_print_npm_version() { return ' (npm v1.2.3)'; }
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"
EXPECTED_OUTPUT=""
[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node or --silent was not silent"
nvm_has_system_node() { return 1; }
[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"
nvm_print_npm_version() { return ''; }
EXPECTED_OUTPUT="System version of node not found."
[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
EXPECTED_OUTPUT=""
[ "$(nvm use --silent system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found or --silent was not silent"
nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent"

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXPECTED_OUTPUT="nvm_ensure_default_set: a version is required"
OUTPUT="$(nvm_ensure_default_set 2>&1 >/dev/null)"
EXIT_CODE="$?"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set' did not output "$EXPECTED_OUTPUT", got "$OUTPUT""
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_ensure_default_set' did not exit with 1, got "$EXIT_CODE""
# see test/fast/Aliases for remaining nvm_ensure_default_set tests

View File

@@ -10,7 +10,12 @@ die () { echo $@ ; cleanup ; exit 1; }
return_zero () { return 0; }
[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'
if nvm_has_system_node || nvm_has_system_iojs; then
EXPECTED_SYSTEM_NODE="system"
else
EXPECTED_SYSTEM_NODE="none"
fi
[ "_$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "_$EXPECTED_SYSTEM_NODE" ] || die "when deactivated, did not return $EXPECTED_SYSTEM_NODE"
rm -rf "$TEST_DIR"
mkdir "$TEST_DIR"

View File

@@ -5,13 +5,17 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0"
[ "~$(nvm_num_version_groups v)" = "~0" ] || die "just "v" should give 0"
[ "~$(nvm_num_version_groups .)" = "~0" ] || die "just "." should give 0"
[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1"
[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1"
[ "~$(nvm_num_version_groups 1.)" = "~1" ] || die "1. should give 1"
[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1"
[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1"
[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2"
[ "~$(nvm_num_version_groups 1.2.)" = "~2" ] || die "1.2. should give 2"
[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2"
[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2"

View File

@@ -0,0 +1,28 @@
#!/bin/sh
cleanup () {
alias nvm_has='\nvm_has'
alias npm='\npm'
unset -f nvm_has npm
}
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm_has() { return 1; }
OUTPUT="$(nvm_print_npm_version)"
[ -z "$OUTPUT" ] || die "nvm_print_npm_version did not return empty when nvm_has returns 1, got '$OUTPUT'"
nvm_has() { return 0; }
npm() {
if [ "_$@" = "_--version" ]; then
echo "1.2.3"
else
echo "error"
fi
}
OUTPUT="$(nvm_print_npm_version)"
EXPECTED_OUTPUT=" (npm v1.2.3)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_npm_version did not provided '$EXPECTED_OUTPUT', got '$OUTPUT'"
cleanup

View File

@@ -22,46 +22,80 @@ HOME="."
setup
#Let's force $SHELL to be bash
SHELL="/bin/bash"
# $SHELL is set to bash and .bashrc is there, it must be detected
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$HOME/.bashrc: _$HOME/.bashrc\n" \
echo "_\$_PROFILE: _$_PROFILE\n" \
die "nvm_detect_profile didn't pick $SHELL and $HOME/.bashrc"
#Let's force $SHELL to be zsh
SHELL="/usr/bin/zsh"
# $SHELL is set to zsh and .zshrc is there, it must be detected
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$HOME/.zshrc: _$HOME/.zshrc\n" \
echo "_\$_PROFILE: _$_PROFILE\n" \
die "nvm_detect_profile didn't pick $SHELL and $HOME/.zshrc"
# if we unset shell it looks for the files
unset SHELL
# $PROFILE points to a valid file, its path must be returned
PROFILE="test_profile"
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$PROFILE" ] || die "nvm_detect_profile didn't pick \$PROFILE"
[ "_$_PROFILE" = "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile didn't pick \$PROFILE"
# $PROFILE doesn't point to a valid file, its path must not be returned
PROFILE="invalid_profile"
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" != "_$PROFILE" ] || die "nvm_detect_profile shouldn't pick \$PROFILE when it's not a valid file"
[ "_$_PROFILE" != "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile shouldn't pick \$PROFILE when it's not a valid file"
# Below are tests for when $PROFILE is undefined
rm test_profile
unset PROFILE
# It should favor .bashrc if file exists
# It should favor .profile if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || die "nvm_detect_profile should have selected .bashrc"
[ "_$_PROFILE" = "_$HOME/.profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile should have selected .profile"
rm .profile
# Otherwise, it should favor .bashrc if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile should have selected .bashrc"
rm .bashrc
# Otherwise, it should favor .bash_profile if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.bash_profile" ] || die "nvm_detect_profile should have selected .bash_profile"
[ "_$_PROFILE" = "_$HOME/.bash_profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile should have selected .bash_profile"
rm .bash_profile
# Otherwise, it should favor .zshrc if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.zshrc" ] || die "nvm_detect_profile should have selected .zshrc"
[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile should have selected .zshrc"
rm .zshrc
# Otherwise, it should favor .profile if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.profile" ] || die "nvm_detect_profile should have selected .profile"
rm .profile
# It should be empty if none is found
_PROFILE=$(nvm_detect_profile)
[ -z "$_PROFILE" ] || die "nvm_detect_profile should have echo'ed an empty value"
[ -z "$_PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \
echo "_\$PROFILE: _$PROFILE\n" \
die "nvm_detect_profile should have echo'ed an empty value"
cleanup

View File

@@ -15,7 +15,7 @@ safe_type() {
safe_type nvm_reset || die 'nvm_reset is not available'
# Apply nvm_reset
nvm_reset
nvm_reset || die 'nvm_reset failed'
# The names should be unset
! safe_type nvm_do_install || die 'nvm_do_install is still available'

View File

@@ -16,8 +16,8 @@ nvm install iojs-v1.0.0
node --version | grep v1.0.0 > /dev/null || die "nvm install didn't use iojs-v1.0.0"
npm install -g is-nan@1.0.1 || die "npm install -g is-nan failed"
npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed"
npm install -g object-is@0.0.0 || die "npm install -g object-is failed"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
nvm ls iojs-1 | grep iojs-v1.0.0 > /dev/null || die "nvm ls iojs-1 didn't show iojs-v1.0.0"
@@ -28,5 +28,5 @@ nvm install iojs-v1.0.1 --reinstall-packages-from=iojs-1.0.0 || die "nvm install
nvm use iojs-1
node --version | grep v1.0.1 > /dev/null || die "nvm use iojs-1 didn't use v1.0.1"
npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"

View File

@@ -0,0 +1,25 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering.
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Fake ARM arch
nvm_get_arch() {
echo "armv7l"
}
# Install from source
nvm install -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
# Check Install
[ -d ../../../$NVM_TEST_VERSION ]
node --version | grep $NVM_TEST_VERSION || "'node --version | grep $NVM_TEST_VERSION' failed"
# Check V8 snapshot isn't compiled
node -p "if(! process.config.variables.v8_use_snapshot) { console.log('no-snapshot'); }" | grep "no-snapshot" || "'node -p \"if(! process.config.variables.v8_use_snapshot) { console.log('no-snapshot'); }\" | grep \"no-snapshot\"' failed"

View File

@@ -18,8 +18,8 @@ nvm use 0.9.7
node --version | grep v0.9.7 > /dev/null || die "nvm use 0.9.7 failed"
npm install -g is-nan@1.0.1 || die "npm install -g is-nan failed"
npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed"
npm install -g object-is@0.0.0 || die "npm install -g object-is failed"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7"
@@ -30,5 +30,5 @@ nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --re
nvm use 0.9
node --version | grep v0.9.12 > /dev/null || die "nvm ls 0.9 didn't use v0.9.12"
npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"

View File

@@ -4,18 +4,27 @@ die () { echo "$@" ; exit 1; }
. ../../../nvm.sh
nvm exec 0.10.28 npm install -g npm@~1.4.11 # this is required because before 1.4.10, npm ls doesn't indicated linked packages
nvm exec 0.10.29 npm install -g npm@~1.4.11 # this is required because before 1.4.10, npm ls doesn't indicated linked packages
nvm use 0.10.28
(cd test-npmlink && npm link)
EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp recursive-blame uglify-js yo"
EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp npmlist recursive-blame spawn-sync test-npmlink uglify-js yo"
echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet
echo "$EXPECTED_PACKAGES" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet
get_packages() {
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
}
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=$(get_packages)
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=$(get_packages)
[ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)"
[ "$ORIGINAL_PACKAGES" != "$FINAL_PACKAGES" ] || die "original packages matched final packages ($ORIGINAL_PACKAGES)"
[ $(test-npmlink) = 'ok' ] || die "failed to run test-npmlink"

View File

@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log('ok')

View File

@@ -0,0 +1,10 @@
{
"name": "test-npmlink",
"version": "0.0.1",
"description": "Stub package for testing npm link",
"bin": {
"test-npmlink": "index.js"
},
"author": "hax",
"license": "ISC"
}

View File

@@ -12,3 +12,9 @@ EXPECTED_OUTPUT="iojs-v1.0.1"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use iojs' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use --silent iojs)"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent iojs' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"

View File

@@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version stable)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use node' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use --silent node)"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent node' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"

View File

@@ -12,3 +12,9 @@ EXPECTED_OUTPUT="$(nvm_version v1.0.0)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use v1.0.0' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use --silent 'v1.0.0')"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent v1.0.0' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"

View File

@@ -10,12 +10,12 @@ cleanup() {
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_CURL_ARGS="-q -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 ($*)"
echo >&2 "expected args ($EXPECTED_CURL_ARGS), got ($*)"
return 1
else
echo $URL
@@ -23,7 +23,7 @@ curl() {
}
wget() {
if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)"
echo >&2 "expected args ($EXPECTED_WGET_ARGS), got ($*)"
return 1
else
local WGET_CONTENTS
@@ -100,7 +100,7 @@ Saving to: /dev/null
"
"$WGET_CONTENTS" | while read line
do
2>& echo "$line"
>&2 echo "$line"
done
fi
}

View File

@@ -0,0 +1,11 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
touch ../../alias/default
rm ../../alias/default || die 'removal of default alias failed'
nvm_alias default && die '"nvm_alias default" did not fail'
set -e # necessary to fail internally with a nonzero code
. ../../nvm.sh || die 'sourcing returned nonzero exit code'