Compare commits

...

146 Commits

Author SHA1 Message Date
Jordan Harband
1d37af162a v0.12.2 2014-07-29 00:35:27 -07:00
Jordan Harband
781373f7ce Make sure awk is referenced unaliased, per https://github.com/creationix/nvm/issues/162#issuecomment-50284503 2014-07-27 23:02:22 -07:00
Jordan Harband
68574cc7e8 v0.12.1 2014-07-24 14:07:26 -07:00
Jordan Harband
0f3b06320e Merge pull request #481 from johnloy/master
Changes $path var to $node_path. Fixes #482.
2014-07-24 14:07:05 -07:00
John Loy
d181abb628 Changes $path var to $node_path
Avoids obliteration of $path set earlier by Prezto/zsh. Stomping on $path causes dirname to not be in the PATH resulting in an error.
2014-07-24 15:28:33 -04:00
Jordan Harband
f5643dc7ea v0.12.0 2014-07-23 01:15:14 -07:00
Jordan Harband
6bcac7f638 Merge pull request #480 from fjakobs/patch-1
install.sh: make sure to not error out if master branch does not exist
2014-07-23 01:14:41 -07:00
Fabian Jakobs
ad71389dcc master branch might not exist
After a fresh install I was unable to run the installer again. It was breaking with the error

error: branch 'master' not found.

my fix makes sure that the installer continues after that.
2014-07-23 10:08:58 +02:00
Jordan Harband
8cbf149558 Merge pull request #408 from creationix/nvm_system_awareness
Add `system` awareness to `nvm use`, `nvm ls`, and `nvm current`.
2014-07-21 22:55:27 -07:00
Jordan Harband
e7ada80d08 nvm use system should work as expected. 2014-07-21 02:03:18 -07:00
Jordan Harband
9912f7cc46 If nvm is deactivated, display "none" or "system" instead of the system node version 2014-07-21 02:03:18 -07:00
Jordan Harband
6e02e5a54c If nvm_ls is called without a pattern, and node exists, tack on "system". 2014-07-21 02:03:18 -07:00
Jordan Harband
42b010775b Add system support to nvm_print_versions 2014-07-21 02:03:18 -07:00
Jordan Harband
1c50c5c7aa Add nvm_tree_contains_path function 2014-07-21 02:03:04 -07:00
Jordan Harband
200a9aa97e v0.11.2 2014-07-20 23:58:19 -07:00
Jordan Harband
4512337c11 Adding a slow nvm current test, since it needs an installed version of node. 2014-07-20 23:41:11 -07:00
Jordan Harband
55677dba4a Avoid calling "nvm_ls current" and call "nvm_ls_current" directly 2014-07-20 23:40:20 -07:00
Jordan Harband
ca43ca21f5 Fix curl/wget detection. Fixes #478 2014-07-18 13:18:09 -07:00
Jordan Harband
fafbeb8c59 Merge pull request #479 from koenpunt/fix-args-replacement
string replacement turns out not POSIX compliant
2014-07-18 13:15:13 -07:00
Koen Punt
9c2127ce33 string replacement turns out not POSIX compliant 2014-07-18 16:21:20 +02:00
Jordan Harband
5ec0ccec1b Fixing make release to also cover package.json.
Per a3de7f3222 (commitcomment-7057689)
2014-07-18 01:49:57 -07:00
Jordan Harband
7a423b7bb4 v0.11.1 2014-07-18 01:48:46 -07:00
Jordan Harband
a3de7f3222 Fixing make release - amending a tagged commit makes the commit not match the tag. 2014-07-17 00:25:14 -07:00
Jordan Harband
55d892adc8 Fix #476 by making sure to cd into $NVM_DIR before checking out the tag. Also delete the master branch, because we won't be needing that. 2014-07-17 00:20:33 -07:00
Jordan Harband
3b42df8d1d Merge pull request #474 from mzgol/wget-hotfix
Hotfix: correctly map curl's `-C -` to wget
2014-07-16 10:16:18 -07:00
Michał Gołębiowski
21fa84225c Hotfix: correctly map curl's -C - to wget
wget doesn't need or accept the `-` parameter to `-c`. This incorrect
mapping causes `nvm install` to fail on a curlless OS.
2014-07-16 11:00:56 +02:00
Jordan Harband
4895aebf0a v0.11.0 2014-07-15 10:52:30 -07:00
Jordan Harband
8a29122d0a Adding teardown to test/fast/Listing versions/ 2014-07-15 02:01:01 -07:00
Jordan Harband
26ed7a003a Making sure to quote this output, so that paths with spaces don't break the method.
Although tests were passing in Travis for #470, they were failing locally - now they pass in both.
2014-07-15 02:00:48 -07:00
Jordan Harband
00ca5288b0 Merge pull request #470 from creationix/has_system_node
Adding nvm_has_system_node
2014-07-15 00:03:25 -07:00
Jordan Harband
6d2912a2ab Adding nvm_has_system_node 2014-07-14 21:41:26 -07:00
Jordan Harband
1d61584402 Making sure this test cleans up after itself. 2014-07-14 20:43:51 -07:00
Jordan Harband
f6974744cd Moving this nvm ls test inside the "listing versions" test subdir. 2014-07-14 12:36:28 -07:00
Jordan Harband
7171cbed6f Add an nvm_ls_current function. 2014-07-14 11:29:24 -07:00
Jordan Harband
8f66273922 Merge pull request #467 from jsdevel/adding-current-symlink
Adding a symlink in .nvm to the current version.

Fixes #430. Closes #447. Relates to #358. Fixes #355. Closes #313. Fixes #381.
2014-07-13 11:23:27 -07:00
Jordan Harband
1a9ab82e24 Merge pull request #466 from creationix/nvm_ls_minor_versions
nvm_ls minor versions
2014-07-13 11:01:12 -07:00
jsdevel
3fa004293c Adding a symlink in .nvm to the current version. 2014-07-12 12:01:35 -07:00
Jordan Harband
83efa2288d Use [0-9] instead of [[:digit:]] per https://github.com/creationix/nvm/pull/466#discussion_r14853668 - it's simpler (and probably more portable). 2014-07-12 11:02:42 -07:00
Jordan Harband
4cfe62d3d1 Fixing nvm ls 0.x to only include 0.x.* instead of 0.x*.* 2014-07-12 11:02:42 -07:00
Jordan Harband
802f064178 Adding a failing test. 2014-07-12 11:02:14 -07:00
Jordan Harband
c49cb68575 Merge pull request #468 from egilkh/master
Should escape grep in nvm_ls
2014-07-12 11:02:09 -07:00
egilkh
0534872e0f Should escape grep in nvm_ls 2014-07-12 19:33:28 +02:00
Olivier Mengué
f1b8cf8fd6 Use 'read' built-in instead of $(cat ... | head -n1) 2014-07-10 12:15:27 -07:00
Jordan Harband
78ff9a2215 Merge pull request #464 from koenpunt/release-task
add makefile release task
2014-07-10 12:14:23 -07:00
Koen Punt
b952be6f56 add makefile release task 2014-07-10 13:28:26 +02:00
Jordan Harband
638ae5c6fa Hardcode latest version number into the install script.
Fixes #462.
2014-07-10 01:24:12 -07:00
Jordan Harband
a7b6495172 Removing unnecessary line, per #461 2014-07-10 01:24:12 -07:00
Jordan Harband
703e43cc2b Merge pull request #463 from mzgol/bash
Use bash, not sh for install scritps - followup to #450
2014-07-10 01:22:39 -07:00
Michał Gołębiowski
03636878d1 Use bash, not sh for install scritps - followup to #450 2014-07-10 10:21:03 +02:00
Jordan Harband
2ee4b6f414 Correcting nvm.sh comment wrt bash 2014-07-09 18:30:52 -07:00
Jordan Harband
10305f0791 Merge pull request #460 from koenpunt/patch-1
Finalize fix for #458
2014-07-08 10:26:24 -07:00
Koen Punt
276c031c60 Finalize fix for #458 2014-07-08 14:49:24 +02:00
Jordan Harband
63f72b37df Followup per https://github.com/creationix/nvm/pull/452#issuecomment-48151847 2014-07-07 15:40:59 -07:00
Jordan Harband
cf5bfecec4 Merge pull request #452 from creationix/curl_wget_handling
Better combo curl/wget handling
2014-07-07 15:03:31 -07:00
Jordan Harband
77c3f20956 Merge pull request #459 from koenpunt/curl_wget_handling
fix nvm_curl arguments for stdout
2014-07-07 14:28:37 -07:00
Jordan Harband
e4ada9fa43 Revert part of the change from e0537ce3df, fixes #458 2014-07-07 14:22:49 -07:00
Koen Punt
a0de15d0f7 fix nvm_curl arguments for stdout 2014-07-07 23:16:20 +02:00
Jordan Harband
df4689fbd2 Removing an extra "echo" 2014-07-07 13:59:58 -07:00
Jordan Harband
018e47bec0 Make sure both wget and curl work. 2014-07-07 13:32:10 -07:00
Jordan Harband
74cc1eb022 Make nvm_curl do a runtime check if curl is available. 2014-07-07 13:32:10 -07:00
Jordan Harband
eda8ffbcc4 Add some more curl → wget argument munging 2014-07-07 13:32:10 -07:00
Jordan Harband
b9383c9016 Use nvm_curl instead of curl directly, which has a wget fallback. 2014-07-07 13:32:10 -07:00
Jordan Harband
25c0be1e20 Using an nvm_curl function instead of curl/wget directly. 2014-07-07 13:32:10 -07:00
Jordan Harband
a8233eb68c Merge pull request #457 from koenpunt/patch-1
Add newline to printf command
2014-07-07 13:02:23 -07:00
Koen Punt
ea198c9a19 add newline to printf 2014-07-07 14:43:02 +02:00
Jordan Harband
e0537ce3df Shellcheck recommendations. 2014-07-05 13:48:23 -07:00
Jordan Harband
cce5df35ba Naming install.sh functions more explicitly as being for nvm. 2014-07-05 13:44:00 -07:00
Jordan Harband
7e269961c3 In install.sh, rename has to nvm_has for consistency with nvm.sh. 2014-07-05 13:42:44 -07:00
Jordan Harband
f214ffaf1f Oxford comma 2014-07-05 11:07:14 -07:00
Jordan Harband
d016fe010a Merge pull request #450 from mzgol/install-script
Use bash, not sh for install scritps
2014-07-03 00:50:31 -07:00
Michał Gołębiowski
fb5a51b1b7 Use bash, not sh for install scritps
Install scripts don't work in pure sh; they may work on some systems where
the /bin/sh binary actually implements more than the pure Bourne Shell but
fail on other ones (e.g. Ubuntu).

Just using bash works.
2014-07-02 14:58:56 +02:00
Jordan Harband
3e5037a1be v0.10.0 2014-06-26 17:06:45 -07:00
Jordan Harband
60fec40613 Merge pull request #444 from creationix/fix_nvm_ls
Make sure `nvm ls foo` returns a nonzero exit code when a version is not found
2014-06-26 17:04:09 -07:00
Jordan Harband
fb215546ee Don't bother trying to return the exit code of nvm alias or nvm_print_versions 2014-06-26 16:52:48 -07:00
Jordan Harband
4b593bcda2 Make sure these vars are local, where supported 2014-06-26 16:52:34 -07:00
Jordan Harband
8349f0ff48 Make sure nvm ls foo returns a nonzero exit code when a version is not found.
Fixes #440.
2014-06-26 10:28:35 -07:00
Jordan Harband
bb250b5730 v0.9.0 2014-06-26 10:28:14 -07:00
Jordan Harband
b6f1c156da Use printf instead of echo -e
Fixes #446
2014-06-26 10:26:57 -07:00
Jordan Harband
4c9a36e9ad Separating variable declaration from first assignment, which should fix some ksh problems. 2014-06-22 15:44:22 -07:00
Jordan Harband
bb01513eba Making sure there's test coverage for nvm i 2014-06-22 09:18:41 -07:00
Jordan Harband
ba7f27dead Silently support nvm i x.x.x. Fixes #443. 2014-06-22 09:16:30 -07:00
Jordan Harband
79ec957ee7 Removing reference to NVM_PROFILE in README. Fixes #442 2014-06-21 17:47:02 -07:00
Jordan Harband
d8b55652a5 Return the exit code of nvm use when nvm install-ing. 2014-06-20 11:49:06 -07:00
Jordan Harband
4c38f507f5 Consistently returning exit code 1 when version is not installed yet. 2014-06-20 11:45:25 -07:00
Jordan Harband
f213167ef0 Returning exit code 3 when no version is found. 2014-06-20 11:45:14 -07:00
Jordan Harband
1da31aa425 v0.8.0 2014-06-20 11:35:18 -07:00
Jordan Harband
519a9481e6 Merge pull request #438 from koenpunt/patch-2
Suppress output of `nvm use`
2014-06-18 00:08:06 -07:00
Koen Punt
b16bf303ca Suppress output of nvm use
+redirect errors to stdout
2014-06-18 08:54:14 +02:00
Jordan Harband
9a28706688 Merge pull request #436 from koenpunt/stderr
redirect output of errors to stderr
2014-06-16 16:37:31 -07:00
Koen Punt
a318ddf9b3 redirect stderr to stdout in test 2014-06-17 01:22:17 +02:00
Koen Punt
8dbbc32905 redirect errors to stderr 2014-06-17 01:22:12 +02:00
Jordan Harband
de03007348 Merge pull request #432 from ajcrites/master
Only list extant explicit version
2014-06-12 11:55:56 -07:00
Andrew Crites
1b22c2e2b1 Including test for specific version listing
This fixes the issue of nvm ls v[:digit:].[:digit:].[:digit:] listing the version even if it isn't available
2014-06-12 14:01:26 -04:00
Andrew Crites
0e1f2408c9 Only list extant explicit version 2014-06-12 10:56:20 -04:00
Jordan Harband
931cc45fc3 Merge pull request #428 from koenpunt/export-nvm-dir-in-profile
export NVM_DIR in profile before sourcing nvm.sh
2014-05-29 16:04:25 -07:00
Jordan Harband
085e314a3f Adding a trailing newline 2014-05-28 20:54:25 -07:00
Jordan Harband
6aa45732d8 Merge pull request #376 from koenpunt/nvm-unload
Feature: nvm unload
2014-05-28 20:53:50 -07:00
Koen Punt
16c0be8314 export NVM_DIR before sourcing nvm.sh 2014-05-28 14:32:01 +02:00
Jordan Harband
578a601b27 Filter out of nvm ls things that start with a dot. Fixes #421, closes #422. 2014-05-20 10:36:12 -07:00
Jordan Harband
896aa7c436 Updating CONTRIBUTING guidelines
Fixes #425
2014-05-19 22:05:13 -07:00
Jordan Harband
2441b00262 Merge pull request #417 from koenpunt/travis_tweaks
Split tests by shell
2014-05-10 10:13:53 -07:00
Koen Punt
88595f09aa remove fast task 2014-05-10 19:03:50 +02:00
Koen Punt
5925bd5e37 make suite for shell task configurable 2014-05-10 18:59:34 +02:00
Koen Punt
24e22dd8bc no need for the extra task, every shell name is already a task 2014-05-10 12:27:11 +02:00
Koen Punt
61de5f9ca3 enable slow test suite for sh 2014-05-10 12:15:19 +02:00
Jordan Harband
4de9eff55c Merge pull request #416 from koenpunt/patch-2
Use correct variables
2014-05-09 10:49:43 -07:00
Koen Punt
7e20a77c89 pass env vars to makefile 2014-05-09 16:42:04 +02:00
Koen Punt
8fbbeb8fc5 ensure correct shell usage 2014-05-09 16:30:04 +02:00
Koen Punt
79203ba5d0 split tests by shell 2014-05-09 16:23:14 +02:00
Koen Punt
2e3e48cc06 Use correct variables 2014-05-09 15:36:44 +02:00
Jordan Harband
db8acf11fd v0.7.0 2014-05-08 10:30:52 -07:00
Jordan Harband
a6be718387 Fixing --version output format. 2014-05-08 10:30:34 -07:00
Jordan Harband
e2c4c88136 Updating example node versions. 2014-05-08 10:30:18 -07:00
Jordan Harband
4cd0b078d0 Merge pull request #415 from koenpunt/fix-path-concat
utility method for append path, fixes #414
2014-05-08 10:27:17 -07:00
Koen Punt
f6ba08253b utility method for append path, fixes #414 2014-05-08 10:20:11 +02:00
Jordan Harband
0ecb2879b9 Merge pull request #412 from koenpunt/fix-sed
Use sed -e instead of -E
2014-05-07 10:32:00 -07:00
Koen Punt
e3b84499c2 use regex triplet, add unit test 2014-05-07 10:58:21 +02:00
Koen Punt
b313f62749 Use sed -e instead of -E 2014-05-07 10:58:18 +02:00
Jordan Harband
7f3a794d89 Merge pull request #409 from koenpunt/sed-path-replacement
Use sed for *PATH stripping
2014-05-06 01:37:49 -07:00
Jordan Harband
ba1be9b4ea Making nvm install use the version, even if it's already installed. Fixes #410 2014-05-05 23:32:39 -07:00
Koen Punt
652a9ef9b5 always apply path stripping 2014-05-06 00:00:25 +02:00
Koen Punt
0d81a219ae add quotes 2014-05-05 22:05:02 +02:00
Koen Punt
d6e457354f use nvm_strip_path utility method for path stripping 2014-05-05 22:03:11 +02:00
Koen Punt
6668dc5c47 remove parentheses 2014-05-05 21:50:59 +02:00
Koen Punt
3d9c1d7852 use sed for *PATH stripping 2014-05-05 21:43:22 +02:00
Jordan Harband
29f582611b v0.6.1 2014-05-04 12:40:02 -07:00
Jordan Harband
673cda56c4 Adding a test for nvm install invalid behavior, and correcting the message.
From f00d688c87 (commitcomment-6205164)
2014-05-04 12:03:26 -07:00
Jordan Harband
e562a5645b v0.6.0 2014-05-04 02:20:31 -07:00
Jordan Harband
c0c5e8d7ef Editing README to note improved .nvmrc behavior. 2014-05-04 02:20:24 -07:00
Jordan Harband
f00d688c87 Nicer failure message when trying to install an invalid version. Fixes #285. 2014-05-04 00:59:08 -07:00
Jordan Harband
5aa78f21cf Merge branch 'nvmrc' - Fixes #404 2014-05-04 00:47:16 -07:00
Jordan Harband
4a7275a0c6 Ensuring paths are in quotes, to preserve spaces. 2014-05-04 00:39:46 -07:00
Jordan Harband
c77be55cdc Updating "nvm run" tests. 2014-05-04 00:39:32 -07:00
Jordan Harband
e195fccdb7 Escaping backticks 2014-05-03 23:29:21 -07:00
Jordan Harband
87516039a8 Using portable conditional syntax. 2014-05-02 23:28:42 -07:00
Koen Punt
80e349edb1 locate .nvmrc without find
instead of using find and actually cd'ing into directories
we're now using simple string replacement on the `pwd`
2014-05-02 23:02:34 -07:00
Jordan Harband
038c1f3d0f Find .nvmrc files upwards. 2014-05-02 23:02:34 -07:00
Jordan Harband
66455f7c77 Refactor so "finding .nvmrc" can be done in a bash function. 2014-05-02 23:02:34 -07:00
Jordan Harband
a69eae10e3 Merge pull request #405 from reqshark/master
github raw served from new subdomain
2014-04-26 10:03:41 -07:00
Bent Cardan
13b87449e8 github raw served from new subdomain 2014-04-26 03:48:06 -04:00
Jordan Harband
222250f2d1 v0.5.1 2014-04-25 10:47:59 -07:00
Jordan Harband
77f4490391 Using markdown footnotes. 2014-04-25 10:47:07 -07:00
Jordan Harband
0871131dfd Make sure nvm-exec can use .nvmrc logic. Fixes #402, obviates #403. 2014-04-25 10:38:21 -07:00
Jordan Harband
e6bd207624 When auto-printing "help" on a command other than "help", return a nonzero exit code. 2014-04-25 10:35:52 -07:00
Koen Punt
703acb0514 Added test for nvm unload 2014-03-23 16:44:40 +01:00
Koen Punt
744507b83e added nvm unload method to remove nvm from shell 2014-03-23 16:44:37 +01:00
29 changed files with 633 additions and 202 deletions

2
.gitignore vendored
View File

@@ -11,4 +11,4 @@ test/bak
node_modules/
.DS_Store
current

View File

@@ -2,7 +2,13 @@ language: c # defaults to ruby
install:
- sudo apt-get install ksh zsh -y
before_script:
- curl -o /tmp/urchin https://raw.github.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin
- curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin
script:
- NVM_DIR=$TRAVIS_BUILD_DIR make URCHIN=/tmp/urchin test
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL
env:
- SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast
- SHELL=zsh TEST_SUITE=fast
- SHELL=ksh TEST_SUITE=fast
- SHELL=sh TEST_SUITE=slow

View File

@@ -5,7 +5,7 @@ We love pull requests, they're our favorite.
However, before submitting, please review the following:
- Please include tests. Changes with tests will be merged very quickly.
- Please manually confirm that your changes, and all tests, pass in `bash`, `sh`, and `zsh`. We hope to soon automatically run all these tests, but in the meantime, we have to rely on each contributor doing so.
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
- Any time you make a change to your PR, please rebase freshly on top of master. Nobody likes merge commits.

View File

@@ -1,16 +1,26 @@
URCHIN=`which urchin`
SHELLS=sh bash dash ksh zsh
TEST_SUITE=fast
.PHONY: $(SHELLS) test
fast: $(SHELLS)
.PHONY: $(SHELLS) test verify-tag release
$(SHELLS):
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
@$@ $(URCHIN) -f test/fast
@$@ $(URCHIN) -f test/$(TEST_SUITE)
test: fast
test: $(SHELLS)
@$(URCHIN) -f test/slow
default: test
verify-tag:
ifndef TAG
$(error TAG is undefined)
endif
release: verify-tag
@ OLD_TAG=`git describe --abbrev=0 --tags` && \
replace "$${OLD_TAG/v/}" "$(TAG)" -- nvm.sh install.sh README.markdown package.json && \
git commit -m "v$(TAG)" nvm.sh install.sh README.markdown package.json && \
git tag "v$(TAG)"

View File

@@ -1,4 +1,4 @@
# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)](https://travis-ci.org/creationix/nvm)
# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)][3]
## Installation
@@ -6,19 +6,19 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
### Install script
To install you could use the [install script](https://github.com/creationix/nvm/blob/v0.5.0/install.sh) using cURL:
To install you could use the [install script][2] using cURL:
curl https://raw.github.com/creationix/nvm/v0.5.0/install.sh | sh
curl https://raw.githubusercontent.com/creationix/nvm/v0.12.2/install.sh | bash
or Wget:
wget -qO- https://raw.github.com/creationix/nvm/v0.5.0/install.sh | sh
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.12.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>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `NVM_PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install.
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
<sub>*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.*</sub>
<sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
### Manual install
@@ -37,6 +37,9 @@ Often I also put in a line to use a specific version of node.
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
`nvm use`, `nvm install`, and `nvm run` will all respect an `.nvmrc` file.
To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.10
@@ -45,13 +48,9 @@ And then in any new shell just use the installed version:
nvm use 0.10
You can create an `.nvmrc` file containing version number in the project root folder; run the following command to switch versions:
nvm use
Or you can just run it:
nvm run 0.10
nvm run 0.10 --version
If you want to see what versions are installed:
@@ -90,7 +89,7 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Running tests
Tests are written in [Urchin](https://github.com/scraperwiki/urchin). Install Urchin (and other dependencies) like so:
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install
@@ -133,17 +132,17 @@ nvm alias
default
$ nvm alias my_alias [tab][tab]
v0.4.11 v0.4.12 v0.6.14
v0.6.21 v0.8.26 v0.10.28
nvm use
$ nvm use [tab][tab]
my_alias default v0.4.11 v0.4.12 v0.6.14
my_alias default v0.6.21 v0.8.26 v0.10.28
nvm uninstall
$ nvm uninstall [tab][tab]
my_alias default v0.4.11 v0.4.12 v0.6.14
my_alias default v0.6.21 v0.8.26 v0.10.28
## Problems
@@ -163,3 +162,8 @@ 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.12.2/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -2,7 +2,7 @@
set -e
has() {
nvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
@@ -11,41 +11,45 @@ if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
if ! has "curl"; then
if has "wget"; then
nvm_download() {
if nvm_has "curl"; then
curl $*
elif nvm_has "wget"; then
# Emulate curl with wget
curl() {
ARGS="$* "
ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-o /-O }
wget $ARGS
}
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I //' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
fi
}
install_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
echo "=> nvm is already installed in $NVM_DIR, trying to update"
echo -e "\r=> \c"
cd "$NVM_DIR" && git pull 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
}
printf "\r=> "
cd "$NVM_DIR" && (git fetch 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
})
else
# Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'"
echo -e "\r=> \c"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
fi
cd $NVM_DIR && git checkout v0.12.2 && git branch -D master || true
}
install_as_script() {
install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh"
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.12.2/nvm.sh"
fi
# Downloading to $NVM_DIR
@@ -55,7 +59,7 @@ install_as_script() {
else
echo "=> Downloading nvm as script to '$NVM_DIR'"
fi
curl -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'.."
return 1
}
@@ -63,28 +67,28 @@ install_as_script() {
if [ -z "$METHOD" ]; then
# Autodetect install method
if has "git"; then
install_from_git
elif has "curl"; then
install_as_script
if nvm_has "git"; then
install_nvm_from_git
elif nvm_has "nvm_download"; then
install_nvm_as_script
else
echo >&2 "You need git, curl or wget to install nvm"
echo >&2 "You need git, curl, or wget to install nvm"
exit 1
fi
else
if [ "$METHOD" = "git" ]; then
if ! has "git"; then
if ! nvm_has "git"; then
echo >&2 "You need git to install nvm"
exit 1
fi
install_from_git
install_nvm_from_git
fi
if [ "$METHOD" = "script" ]; then
if ! has "curl"; then
if ! nvm_has "nvm_download"; then
echo >&2 "You need curl or wget to install nvm"
exit 1
fi
install_as_script
install_nvm_as_script
fi
fi
@@ -101,30 +105,27 @@ if [ -z "$PROFILE" ]; then
fi
fi
SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm"
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z $PROFILE ]; then
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
if [ -z "$PROFILE" ]; then
echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again"
else
echo "=> Profile $PROFILE not found"
echo "=> Create it (touch $PROFILE) and run this script again"
fi
echo " OR"
echo "=> Append the following line to the correct file yourself:"
echo
echo " $SOURCE_STR"
echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' $PROFILE; then
if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $PROFILE"
echo "" >> "$PROFILE"
echo $SOURCE_STR >> "$PROFILE"
printf "$SOURCE_STR\n" >> "$PROFILE"
else
echo "=> Source string already in $PROFILE"
fi
fi
echo "=> Close and reopen your terminal to start using nvm"

View File

@@ -4,12 +4,11 @@ DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/nvm.sh"
if [ ! "$NODE_VERSION" ]; then
echo 'NODE_VERSION not set'
exit 1
if [ -n "$NODE_VERSION" ]; then
nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)
else
nvm use > /dev/null || (echo "No .nvmrc file found" >&2 && exit 127)
fi
nvm use $NODE_VERSION
exec $@

381
nvm.sh
View File

@@ -1,5 +1,6 @@
# Node Version Manager
# Implemented as a bash function
# Implemented as a POSIX-compliant function
# Should work on sh, dash, bash, ksh, zsh
# To use source this file from your bash profile
#
# Implemented by Tim Caswell <tim@creationix.com>
@@ -9,7 +10,25 @@ NVM_SCRIPT_SOURCE="$_"
nvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
nvm_download() {
if nvm_has "curl"; then
curl $*
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I //' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
}
nvm_has_system_node() {
[ "$(nvm deactivate 2> /dev/null && command -v node)" != '' ]
}
# Make zsh glob matching behave same as bash
@@ -34,62 +53,131 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
fi
nvm_tree_contains_path() {
local tree
tree="$1"
local node_path
node_path="$2"
local pathdir
pathdir=$(dirname "$node_path")
while [ "$pathdir" != "" ] && [ "$pathdir" != "." ] && [ "$pathdir" != "/" ] && [ "$pathdir" != "$tree" ]; do
pathdir=$(dirname "$pathdir")
done
[ "$pathdir" = "$tree" ]
}
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path
path=$PWD
while [ "$path" != "" ] && [ ! -f "$path/$1" ]; do
path=${path%/*}
done
echo "$path"
}
nvm_find_nvmrc() {
local dir
dir="$(nvm_find_up '.nvmrc')"
if [ -e "$dir/.nvmrc" ]; then
echo "$dir/.nvmrc"
fi
}
# Obtain nvm version from rc file
nvm_rc_version() {
if [ -e .nvmrc ]; then
NVM_RC_VERSION=`cat .nvmrc | head -n 1`
echo "Found .nvmrc files with version <$NVM_RC_VERSION>"
local NVMRC_PATH
NVMRC_PATH="$(nvm_find_nvmrc)"
if [ -e "$NVMRC_PATH" ]; then
read NVM_RC_VERSION < "$NVMRC_PATH"
echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>"
fi
}
# Expand a version using the version cache
nvm_version() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSION
# The default version is the current one
if [ -z "$PATTERN" ]; then
PATTERN='current'
fi
if [ "$PATTERN" = "current" ]; then
nvm_ls_current
return $?
fi
VERSION=`nvm_ls $PATTERN | tail -n1`
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
return
return 3
fi
}
nvm_remote_version() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSION
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
return
return 3
fi
}
nvm_normalize_version() {
echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'
echo "$1" | sed -e 's/^v//' | \awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'
}
nvm_format_version() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
}
nvm_strip_path() {
echo "$1" | sed -e "s#$NVM_DIR/[^/]*$2[^:]*:##g" -e "s#:$NVM_DIR/[^/]*$2[^:]*##g" -e "s#$NVM_DIR/[^/]*$2[^:]*##g"
}
nvm_prepend_path() {
if [ -z "$1" ]; then
echo "$2"
else
echo "$2:$1"
fi
}
nvm_binary_available() {
# binaries started with node 0.8.6
local MINIMAL="0.8.6"
local VERSION=$1
local MINIMAL
MINIMAL="0.8.6"
local VERSION
VERSION=$1
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
}
nvm_ls() {
local PATTERN=$1
local VERSIONS=''
if [ "$PATTERN" = 'current' ]; then
nvm_ls_current() {
local NODE_PATH
NODE_PATH="$(which node)"
if [ $? -ne 0 ]; then
echo 'none'
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then
echo `node -v 2>/dev/null`
else
echo 'system'
fi
}
nvm_ls() {
local PATTERN
PATTERN=$1
local VERSIONS
VERSIONS=''
if [ "$PATTERN" = 'current' ]; then
nvm_ls_current
return
fi
@@ -98,36 +186,47 @@ nvm_ls() {
return
fi
# If it looks like an explicit version, don't do anything funny
if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then
VERSIONS="$PATTERN"
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*\.[0-9]*$"` != 0 ]; then
if [ -d "$NVM_DIR/$PATTERN" ]; then
VERSIONS="$PATTERN"
fi
else
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
PATTERN=$(nvm_format_version $PATTERN)
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
PATTERN="$PATTERN."
fi
VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.'`
fi
if [ -z "$VERSIONS" ]; then
echo "N/A"
return
echo "N/A"
return 3
fi
if [ -z "$PATTERN" ] && nvm_has_system_node; then
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
fi
echo "$VERSIONS"
return
}
nvm_ls_remote() {
local PATTERN=$1
local PATTERN
PATTERN=$1
local VERSIONS
local GREP_OPTIONS=''
local GREP_OPTIONS
GREP_OPTIONS=''
if [ -n "$PATTERN" ]; then
PATTERN=`nvm_format_version "$PATTERN"`
else
PATTERN=".*"
fi
VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
VERSIONS=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/ -o - \
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| \grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
if [ -z "$VERSIONS" ]; then
echo "N/A"
return
return 3
fi
echo "$VERSIONS"
return
@@ -135,11 +234,11 @@ nvm_ls_remote() {
nvm_checksum() {
if nvm_has "shasum"; then
checksum=$(shasum $1 | awk '{print $1}')
checksum=$(shasum $1 | \awk '{print $1}')
elif nvm_has "sha1"; then
checksum=$(sha1 -q $1)
else
checksum=$(sha1sum $1 | awk '{print $1}')
checksum=$(sha1sum $1 | \awk '{print $1}')
fi
if [ "$checksum" = "$2" ]; then
@@ -148,7 +247,7 @@ nvm_checksum() {
echo 'Checksums empty' #missing in raspberry pi binary
return
else
echo 'Checksums do not match.'
echo 'Checksums do not match.' >&2
return 1
fi
}
@@ -156,12 +255,15 @@ nvm_checksum() {
nvm_print_versions() {
local VERSION
local FORMAT
local CURRENT=`nvm_version current`
local NVM_CURRENT
NVM_CURRENT=$(nvm_ls_current)
echo "$1" | while read VERSION; do
if [ "$VERSION" = "$CURRENT" ]; then
if [ "$VERSION" = "$NVM_CURRENT" ]; then
FORMAT='\033[0;32m-> %9s\033[0m'
elif [ -d "$NVM_DIR/$VERSION" ]; then
FORMAT='\033[0;34m%12s\033[0m'
elif [ "$VERSION" = "system" ]; then
FORMAT='\033[0;33m%12s\033[0m'
else
FORMAT='%12s'
fi
@@ -176,10 +278,13 @@ nvm() {
fi
# Try to figure out the os and arch for binary fetching
local uname="$(uname -a)"
local os=
local arch="$(uname -m)"
local GREP_OPTIONS=''
local uname
uname="$(uname -a)"
local os
local arch
arch="$(uname -m)"
local GREP_OPTIONS
GREP_OPTIONS=''
case "$uname" in
Linux\ *) os=linux ;;
Darwin\ *) os=darwin ;;
@@ -218,6 +323,7 @@ nvm() {
echo " nvm alias <name> <version> Set an alias named <name> pointing to <version>"
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 unload Unload NVM from shell"
echo
echo "Example:"
echo " nvm install v0.10.24 Install a specific version number"
@@ -226,11 +332,11 @@ nvm() {
echo " nvm alias default 0.10.24 Set default node version on a shell"
echo
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"
echo
;;
"install" )
"install" | "i" )
# initialize local variables
local binavail
local t
@@ -238,11 +344,12 @@ nvm() {
local sum
local tarball
local nobinary
local version_not_provided=0
local version_not_provided
version_not_provided=0
local provided_version
if ! nvm_has "curl"; then
echo 'NVM Needs curl to proceed.' >&2;
if ! nvm_has "curl" && ! nvm_has "wget"; then
echo 'nvm needs curl or wget to proceed.' >&2;
return 1
fi
@@ -274,7 +381,7 @@ nvm() {
fi
provided_version="$NVM_RC_VERSION"
fi
[ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." && return
[ -d "$NVM_DIR/$provided_version" ] && echo "$provided_version is already installed." >&2 && return
VERSION=`nvm_remote_version $provided_version`
ADDITIONAL_PARAMETERS=''
@@ -287,7 +394,16 @@ nvm() {
shift
done
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
if [ -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION is already installed." >&2
nvm use "$VERSION"
return $?
fi
if [ "$VERSION" = "N/A" ]; then
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2
return 3
fi
# skip binary install if no binary option specified.
if [ $nobinary -ne 1 ]; then
@@ -296,12 +412,14 @@ nvm() {
if nvm_binary_available "$VERSION"; then
t="$VERSION-$os-$arch"
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
local tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball="$tmpdir/node-${t}.tar.gz"
sum=`nvm_download -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" && \
curl -L -C - --progress-bar $url -o "$tmptarball" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \
tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
rm -f "$tmptarball" && \
@@ -309,7 +427,7 @@ nvm() {
)
then
nvm use $VERSION
return;
return $?
else
echo "Binary download failed, trying source." >&2
rm -rf "$tmptarball" "$tmpdir"
@@ -327,18 +445,20 @@ nvm() {
make='gmake'
MAKE_CXX="CXX=c++"
fi
local tmpdir="$NVM_DIR/src"
local tmptarball="$tmpdir/node-$VERSION.tar.gz"
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
local tmpdir
tmpdir="$NVM_DIR/src"
local tmptarball
tmptarball="$tmpdir/node-$VERSION.tar.gz"
if [ "`nvm_download -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - | \grep '200 OK'`" != '' ]; then
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
elif [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
sum=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-$VERSION.tar.gz | \awk '{print $1}'`
elif [ "`nvm_download -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" && \
curl -L --progress-bar $tarball -o "$tmptarball" && \
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \
tar -xzf "$tmptarball" -C "$tmpdir" && \
cd "$tmpdir/node-$VERSION" && \
@@ -352,19 +472,19 @@ nvm() {
if ! nvm_has "npm" ; then
echo "Installing npm..."
if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher"
echo "npm requires node v0.2.3 or higher" >&2
elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
echo "npm requires node v0.2.3 or higher"
echo "npm requires node v0.2.3 or higher" >&2
else
curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
nvm_download https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
fi
else
curl https://npmjs.org/install.sh | clean=yes sh
nvm_download https://npmjs.org/install.sh -o - | clean=yes sh
fi
fi
else
echo "nvm: install $VERSION failed!"
echo "nvm: install $VERSION failed!" >&2
return 1
fi
;;
@@ -372,12 +492,12 @@ nvm() {
[ $# -ne 2 ] && nvm help && return
PATTERN=`nvm_format_version $2`
if [ "$PATTERN" = `nvm_version` ]; then
echo "nvm: Cannot uninstall currently-active node version, $PATTERN."
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
return 1
fi
VERSION=`nvm_version $PATTERN`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed..."
echo "$VERSION version is not installed..." >&2
return;
fi
@@ -400,79 +520,87 @@ nvm() {
;;
"deactivate" )
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then
export PATH=${PATH%$NVM_DIR/*/bin*}${PATH#*$NVM_DIR/*/bin:}
export PATH=`nvm_strip_path "$PATH" "/bin"`
hash -r
echo "$NVM_DIR/*/bin removed from \$PATH"
else
echo "Could not find $NVM_DIR/*/bin in \$PATH"
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=${MANPATH%$NVM_DIR/*/share/man*}${MANPATH#*$NVM_DIR/*/share/man:}
export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then
export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:}
export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
else
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH"
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2
fi
;;
"use" )
if [ $# -eq 0 ]; then
nvm help
return
return 127
fi
if [ $# -eq 1 ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION`
VERSION=`nvm_version $NVM_RC_VERSION`
fi
else
VERSION=`nvm_version $2`
if [ $2 = 'system' ]; then
if nvm_has_system_node && nvm deactivate; then
echo "Now using system version of node: $(node -v 2>/dev/null)."
return
else
echo "System version of node not found." >&2
return 127
fi
else
VERSION=`nvm_version $2`
fi
fi
if [ -z "$VERSION" ]; then
nvm help
return
return 127
fi
if [ -z "$VERSION" ]; then
VERSION=`nvm_version $2`
fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet"
echo "$VERSION version is not installed yet" >&2
return 1
fi
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin"` != 0 ]; then
PATH=${PATH%$NVM_DIR/*/bin*}$NVM_DIR/$VERSION/bin${PATH#*$NVM_DIR/*/bin}
else
PATH="$NVM_DIR/$VERSION/bin:$PATH"
fi
# Strip other version from PATH
PATH=`nvm_strip_path "$PATH" "/bin"`
# Prepend current version
PATH=`nvm_prepend_path "$PATH" "$NVM_DIR/$VERSION/bin"`
if [ -z "$MANPATH" ]; then
MANPATH=$(manpath)
fi
MANPATH=${MANPATH#*$NVM_DIR/*/man:}
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man"` != 0 ]; then
MANPATH=${MANPATH%$NVM_DIR/*/share/man*}$NVM_DIR/$VERSION/share/man${MANPATH#*$NVM_DIR/*/share/man}
else
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH"
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then
NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
# Strip other version from MANPATH
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
# Prepend current version
MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_DIR/$VERSION/share/man"`
# 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_DIR/$VERSION/lib/node_modules"`
export PATH
hash -r
export MANPATH
export NODE_PATH
export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
export NVM_BIN="$NVM_DIR/$VERSION/bin"
rm -f "$NVM_DIR/current" && ln -s "$NVM_DIR/$VERSION" "$NVM_DIR/current"
echo "Now using node $VERSION"
;;
"run" )
local provided_version
local has_checked_nvmrc=0
local has_checked_nvmrc
has_checked_nvmrc=0
# run given version of node
shift
if [ $# -lt 1 ]; then
@@ -484,7 +612,7 @@ nvm() {
fi
if [ $VERSION = "N/A" ]; then
nvm help
return
return 127
fi
fi
@@ -503,27 +631,28 @@ nvm() {
fi
if [ ! -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION version is not installed yet"
return;
fi
if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ]; then
RUN_NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
RUN_NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
echo "$VERSION version is not installed yet" >&2
return 1
fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_DIR/$VERSION/lib/node_modules"`
echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_DIR/$VERSION/bin/node "$@"
;;
"ls" | "list" )
nvm_print_versions "`nvm_ls $2`"
local NVM_LS_OUTPUT
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls "$2")
NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT"
if [ $# -eq 1 ]; then
nvm alias
fi
return
return $NVM_LS_EXIT_CODE
;;
"ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`"
return
nvm_print_versions "`nvm_ls_remote $2`"
return
;;
"current" )
nvm_version current
@@ -537,18 +666,18 @@ nvm() {
DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then
echo "$(basename $ALIAS) -> $DEST"
echo "$(basename $ALIAS) -> $DEST"
else
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
fi
fi
done
return
fi
if [ -z "$3" ]; then
rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*"
return
rm -f $NVM_DIR/alias/$2
echo "$2 -> *poof*"
return
fi
mkdir -p $NVM_DIR/alias
VERSION=`nvm_version $3`
@@ -557,42 +686,48 @@ nvm() {
fi
echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)"
echo "$2 -> $3 (-> $VERSION)"
else
echo "$2 -> $3"
fi
;;
"unalias" )
mkdir -p $NVM_DIR/alias
[ $# -ne 2 ] && nvm help && return
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" && return
[ $# -ne 2 ] && nvm help && return 127
[ ! -f "$NVM_DIR/alias/$2" ] && echo "Alias $2 doesn't exist!" >&2 && return
rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2"
;;
"copy-packages" )
if [ $# -ne 2 ]; then
nvm help
return
fi
VERSION=`nvm_version $2`
local ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
if [ $# -ne 2 ]; then
nvm help
return 127
fi
VERSION=`nvm_version $2`
local ROOT
ROOT=`(nvm use $VERSION && npm -g root)`
local ROOTDEPTH
ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
# declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
# declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS
INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "`
npm install -g ${INSTALLS[@]}
npm install -g ${INSTALLS[@]}
;;
"clear-cache" )
rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared."
rm -f $NVM_DIR/v* 2>/dev/null
echo "Cache cleared."
;;
"version" )
nvm_version $2
nvm_version $2
;;
"--version" )
echo "nvm v0.5.0"
echo "0.12.2"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
nvm help

View File

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

View File

@@ -2,11 +2,40 @@
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
mkdir ../../../v0.20.3
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers.
nvm ls 0.2 | grep v0.2.3 &&
nvm ls 0.1 | grep -v v0.2.3 &&
nvm ls 0.1 | grep v0.1.3 &&
nvm ls v0.2 | grep v0.2.3
nvm ls 0.1 | grep 'v0.2.3' > /dev/null
if [ $? -eq 0 ]; then
echo '"nvm ls 0.1" contained v0.2.3'
fi
nvm ls 0.1 | grep 'v0.20.3' > /dev/null
if [ $? -eq 0 ]; then
die '"nvm ls 0.1" contained v0.20.3'
fi
nvm ls 0.1 | grep 'v0.1.3' > /dev/null
if [ $? -ne 0 ]; then
die '"nvm ls 0.1" did not contain v0.1.3'
fi
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
if [ $? -ne 0 ]; then
die '"nvm ls 0.2" did not contain v0.2.3'
fi
nvm ls 0.2 | grep 'v0.20.3' > /dev/null
if [ $? -eq 0 ]; then
die '"nvm ls 0.2" contained v0.20.3'
fi
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
if [ $? -ne 0 ]; then
die '"nvm ls 0.2" did not contain v0.2.3'
fi

View File

@@ -0,0 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
nvm ls nonexistent_version
[ "$?" = "3" ]

View File

@@ -0,0 +1,9 @@
#!/bin/sh
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
. ../../../nvm.sh
[ -z `nvm ls | grep '^ *\.'` ]
# The result should contain only the appropriate version numbers.

View File

@@ -0,0 +1,21 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
mkdir -p ../../../v0.0.1
mkdir -p ../../../v0.0.3
mkdir -p ../../../v0.0.9
mkdir -p ../../../v0.3.1
mkdir -p ../../../v0.3.3
mkdir -p ../../../v0.3.9
nvm_has_system_node() { return 0; }
nvm ls | grep system 2>&1 > /dev/null
[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present'
nvm_has_system_node() { return 1; }
nvm ls | grep system 2>&1 > /dev/null
[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'

View File

@@ -0,0 +1,11 @@
#!/bin/sh
mkdir ../../../v0.1.2
. ../../../nvm.sh
nvm ls v0.1 | grep v0.1.2 &&
nvm ls v0.1.2 | grep v0.1.2 &&
nvm ls v0.1. | grep N/A &&
nvm ls v0.1.1 | grep N/A

View File

@@ -0,0 +1,11 @@
rmdir ../../../v0.0.1
rmdir ../../../v0.0.3
rmdir ../../../v0.0.9
rmdir ../../../v0.1.2
rmdir ../../../v0.1.3
rmdir ../../../v0.2.3
rmdir ../../../v0.3.1
rmdir ../../../v0.3.3
rmdir ../../../v0.3.9
unalias nvm_has_system_node

View File

@@ -3,4 +3,8 @@
die () { echo $@ ; exit 1; }
. ../../nvm.sh
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version"
nvm deactivate 2>&1
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'

View File

@@ -8,7 +8,7 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm use v0.2.3 &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || 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"
nvm deactivate &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || 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"

View File

@@ -0,0 +1,7 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"

View File

@@ -0,0 +1,12 @@
#!/bin/sh
fail () { echo $@ ; exit 1; }
. ../../nvm.sh
type nvm > /dev/null 2>&1 || fail "NVM not loaded"
nvm unload
type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0

View File

@@ -0,0 +1,13 @@
#!/bin/sh
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_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 use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"

View File

@@ -0,0 +1,32 @@
#!/bin/bash
. ../../nvm.sh
rm -rf ../../v0.10.29
mkdir ../../v0.10.29
nvm use 0.10.29
rmdir ../../v0.10.29
if [ ! -L ../../current ];then
echo "Expected 'current' symlink to be created!"
exit 1
fi
oldLink="$(readlink ../../current)"
if [ "$(basename $oldLink)" != 'v0.10.29' ];then
echo "Expected 'current' to point to v0.10.29 but was $oldLink"
exit 1
fi
rm -rf ../../v0.11.13
mkdir ../../v0.11.13
nvm use 0.11.13
rmdir ../../v0.11.13
newLink="$(readlink ../../current)"
if [ "$(basename $newLink)" != 'v0.11.13' ];then
echo "Expected 'current' to point to v0.11.13 but was $newLink"
exit 1
fi

View File

@@ -0,0 +1,29 @@
#!/bin/sh
cleanup () {
rm ../../../v0.1.2/node
rmdir ../../../v0.1.2
}
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
mkdir ../../../v0.1.2
touch ../../../v0.1.2/node
nvm use 0.1.2
if command -v node; then
nvm_has_system_node
else
! nvm_has_system_node
fi
nvm deactivate /dev/null 2>&1
if command -v node; then
nvm_has_system_node
else
! nvm_has_system_node
fi

View File

@@ -0,0 +1,18 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
TEST_PATH=/usr/bin:/usr/local/bin
NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_PATH "
EMPTY_PATH=
NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"`
[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH "

View File

@@ -0,0 +1,11 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin
STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"`
[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH "

View File

@@ -0,0 +1,27 @@
#!/bin/sh
cleanup () {
rm tmp/node
rmdir tmp
rm tmp2/node
rmdir tmp2
}
die () { echo $@ ; cleanup; exit 1; }
. ../../../nvm.sh
mkdir -p tmp
touch -p tmp/node
mkdir -p tmp2
touch -p tmp2/node
nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"'
nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"'
nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
cleanup

View File

@@ -0,0 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm install 0.10
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version: got \"$(nvm current)\", expected \"$(node -v)\""

View File

@@ -0,0 +1,24 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"
# Remove the stuff we're clobbering.
[ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7
[ -e ../../../v0.9.12 ] && rm -R ../../../v0.9.12
# Install from binary
nvm install 0.9.7
nvm install 0.9.12
nvm use 0.9.7
node --version | grep v0.9.7 || die "precondition failed: node doesn't start at 0.9.7"
nvm install 0.9.12
node --version | grep v0.9.12 || die "nvm install on already installed version doesn't use it"

View File

@@ -9,7 +9,7 @@ set -e
# Install from binary
nvm install 0.9.7
nvm install 0.9.12
nvm i 0.9.12
# Check
[ -d ../../../v0.9.7 ]

View File

@@ -6,7 +6,8 @@ die () { echo $@ ; exit 1; }
. ../../../nvm.sh
echo "0.10.7" > .nvmrc
[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "`nvm run` failed to run with the .nvmrc version"
[ "$(nvm run --version | head -1)" = "Found .nvmrc files with version <0.10.7>" ] || die "`nvm run` failed to print out the \"found in .nvmrc\" message"
[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version"
[ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message"