Compare commits

...

169 Commits

Author SHA1 Message Date
Jordan Harband
bef3a5ce3a v0.21.0 2014-12-22 12:03:33 -08:00
Jordan Harband
0cb8c9ac2f Merge pull request #599 from ljharb/nvm_get_latest
Add `nvm_get_latest`

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

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

Also, the shell command that determines the set of available test suites is now POSIX-compliant.
2014-11-01 02:18:10 -04:00
Jordan Harband
6ec62fcc79 Merge pull request #564 from xcambar/nvm_detect_profile
Tests for PROFILE detection
2014-10-30 10:24:53 -07:00
Jordan Harband
fc17aaafb1 Merge pull request #541 from mklement0/fix_make_file
Makefile enhanced to error out with instructions if invoked without a target.
2014-10-30 10:23:37 -07:00
Michael Klement
ac912afc4c Many makefile enhancements (support for direct invocation, instructions if invoked without target, release mechanism improved), package.json scripts now invoke the makefile.
- Using `npm test` and `npm run …` scripts defined in package.json now invokes the makefile and runs the test with the same shell that npm was invoked from.
- The makefile can now be invoked directly - supporting utilities from locally installed npm packages are automatically discovered.
- Invoking the makefile without a target errors out with a hint.
- Shell-specific test targets are now named 'test-<shell>'.
- Both 'test-<shell>' targets and the all-shells 'test' target now run all test suites by default.
- On `make TAG=<new-version> release` there must be no uncommitted changes. '<new-version>' can now also be one of the following increment specifiers: 'patch', 'minor', 'major'.
- It is ensure that <new-version>, if not an increment specifier, is a valid semver version number that is higher than the previous release's.
- The previous release tag is now located with a pattern so as to exclude tags that aren't version numbers.
- Switched from lightweight to annotated tags for releases.
2014-10-30 00:13:22 -04:00
Xavier Cambar
b9f15b0ab0 Tests for PROFILE detection 2014-10-29 18:50:04 +01:00
Jordan Harband
d30c0fe146 Cleaning up install_script tests. 2014-10-28 13:47:21 -07:00
Jordan Harband
21534ec0c9 Merge pull request #556 from xcambar/install_function_for_testing
Add install_script test suite; wrap installation in a function, for testing.
2014-10-28 13:42:59 -07:00
Xavier Cambar
3cdec8e875 Testable install script
* wraps main code into a function
* EnvVar-based install start
* Clean environment after install
2014-10-28 11:44:01 +01:00
Jordan Harband
cec1c38a84 Move sourcing tests to a separate test suite. 2014-10-26 23:40:32 -07:00
Jordan Harband
ad0a5cd8c7 Merge pull request #560 from brock/pwd
use `command -p pwd` to use the system default pwd
2014-10-26 01:23:41 -07:00
Brock Angelo
1c9a5ba2d8 use slash pwd instead of command 2014-10-25 22:19:27 -05:00
Brock Angelo
fd1f2cdf66 use command -p pwd to use the system default pwd 2014-10-25 13:55:20 -05:00
Jordan Harband
2d529cc8b7 Prevent attempts to nvm use a circular reference. 2014-10-22 18:15:21 -07:00
Jordan Harband
9b91734f0b Show "∞" when there's a circular alias reference. 2014-10-22 18:15:21 -07:00
Jordan Harband
0f5997f754 Clean up from some more tests 2014-10-22 18:15:21 -07:00
Jordan Harband
7a339bdd3c Adding nvm_resolve_alias 2014-10-22 01:30:40 -07:00
Jordan Harband
08aa09e664 Prevent test pollution. 2014-10-22 01:26:39 -07:00
Jordan Harband
8284cd0f81 Ensuring that there's a stable and unstable version "available" for this test. 2014-10-21 01:02:59 -07:00
Jordan Harband
e421a0dc5f Ensure nvm follows redirects to nodejs.org 2014-10-20 16:02:46 -07:00
Jordan Harband
601490ac1d Merge tag 'v0.17.3' 2014-10-20 15:50:47 -07:00
Jordan Harband
4748b3a236 v0.17.3 2014-10-20 15:48:49 -07:00
Jordan Harband
2a61569881 http://nodejs.org/dist now redirects to https://nodejs.org/dist 2014-10-20 15:48:35 -07:00
Jordan Harband
a7b1f93592 README cleanup: Use the Oxford comma, properly lowercase commands 2014-10-19 19:26:17 -07:00
Jordan Harband
ca89cceb99 Default $NVM_SYMLINK_CURRENT to off (create a "current" symlink on use).
Fixes #499.
2014-10-14 18:14:12 -07:00
Jordan Harband
7b6e06e556 Add tests for "nvm use default on source" behavior. 2014-10-13 23:55:58 -07:00
Jordan Harband
370dfcab7c Merge pull request #548 from BanzaiMan/ha-bug-npm-update
Fix npm update code
2014-10-12 16:35:13 -07:00
Hiro Asari
44d5776110 Fix npm update code
https://npmjs.org/install.sh redirects to https://www.npmjs.org/install.sh
so this code would fail if it ever npm was absent when we get here.
2014-10-12 12:28:38 -04:00
Jordan Harband
d49443e1fb Properly handle nvm_print_implicit_alias splitting in zsh.
Hopefully fixes #546.
2014-10-11 00:41:16 -04:00
Jordan Harband
e99645f402 Don't list uninstalled implicit aliases 2014-10-10 23:46:25 -04:00
Jordan Harband
8f76b35370 Fix nvm alias tests to have both stable and unstable mocks. 2014-10-10 23:46:25 -04:00
Jordan Harband
a2633e5980 Fixing "nvm alias" output redirection. 2014-10-09 00:19:14 -07:00
Jordan Harband
6c89e96f67 Ensure that we don't try to uninstall the current version of node in test teardowns. 2014-10-09 00:19:14 -07:00
Jordan Harband
1ee708b79b Fix an output redirection error. 2014-10-06 16:18:21 -07:00
Jordan Harband
035334fd34 Merge pull request #544 from coreybutler/patch-1
Fixed links
2014-10-05 12:02:30 -07:00
Corey Butler
2edc86d574 Fixed links
The links were relative to github.com/creationix/nvm/master instead of the intended sites.
2014-10-05 10:15:10 -05:00
Jordan Harband
9d23f609ad Add note about Windows options. Related to #284. 2014-10-04 16:42:29 -07:00
Jordan Harband
9d9cfdc2c8 Two spaces after a period is incorrect. 2014-10-04 16:38:56 -07:00
Jordan Harband
1931f7f3f8 Remove '-e' option from installation tests, in favor of explicit failures. 2014-10-03 03:03:48 -07:00
Jordan Harband
2f2c6f0727 Use nvm_alias in nvm_ls. 2014-10-02 17:19:21 -07:00
Jordan Harband
0eef553a88 Use -f instead of -e in nvm_alias. 2014-10-02 16:06:09 -07:00
Jordan Harband
5135577a3c Ensure nvm run has the same semantics as nvm use 2014-10-01 01:46:46 -07:00
Jordan Harband
5bc6e289ce Silencing nvm_version_path error output in nvm_print_versions 2014-10-01 01:46:35 -07:00
Jordan Harband
d0c6b87b2e Use nvm_alias in nvm alias 2014-09-30 00:24:37 -07:00
Jordan Harband
66b214651f Add nvm_alias and unit tests. 2014-09-30 00:23:37 -07:00
Jordan Harband
acfc459bc5 Adding notes to the README for "stable", "unstable", and "system". 2014-09-29 21:43:58 -07:00
Jordan Harband
fc16d20766 Merge pull request #537 from ljharb/add_stable_unstable_aliases
Add stable & unstable aliases.

Fixes #336.

With these changes, the following `nvm` commands will now support "stable" and "unstable" default/implicit aliases:
 - `ls`/`list`
 - `use`
 - `alias`
 - `run`
 - `exec`
 - `uninstall`
 - `copy-packages`

For these, "stable" will be the latest even minor version that's locally installed; "unstable" will be the latest odd minor version that's locally installed.

In addition, `nvm ls-remote` and `nvm install` will accept the same implicit aliases, however, these will actually call nodejs.org and output the latest even and odd minor versions available for installation.

`nvm alias stable foo` and `nvm alias unstable foo` will *override* the default/implicit aliases. `nvm alias` output will reflect this by showing "(default)" when the alias is not user-defined.
2014-09-29 21:35:44 -07:00
Jordan Harband
f0471acbf5 v0.17.2 2014-09-29 14:32:44 -07:00
Jordan Harband
fda05fb64b Remove trailing whitespace. 2014-09-29 14:26:19 -07:00
Jordan Harband
2737a95645 Create nvm_ensure_version_prefix, and make nvm_format_version actually format the version. 2014-09-29 01:36:02 -07:00
Jordan Harband
5706aef3d0 nvm_format_version: add unit tests. 2014-09-29 01:34:50 -07:00
Jordan Harband
4cdf356cdc Support nvm ls-remote stable and nvm ls-remote unstable 2014-09-29 00:10:06 -07:00
Jordan Harband
c918e570b6 Add support for nvm ls stable and nvm ls unstable 2014-09-29 00:09:48 -07:00
Jordan Harband
5dc7af6285 Make nvm alias list implicit "stable" and "unstable" aliases when they're not already aliases. 2014-09-29 00:09:17 -07:00
Jordan Harband
f9565ff675 Adding nvm_print_implicit_alias success tests 2014-09-29 00:08:55 -07:00
Jordan Harband
cea0e88489 Adding nvm_print_implicit_alias error tests. 2014-09-28 22:43:46 -07:00
Jordan Harband
5aad535d53 Adding nvm_print_implicit_alias 2014-09-28 22:40:17 -07:00
Jordan Harband
fcdd1ef431 Add nvm_validate_implicit_alias 2014-09-28 22:36:02 -07:00
Jordan Harband
cd4fc8fb2c Adding unit tests for nvm_ls_remote
`nvm_download` is stubbed, to avoid making network calls.
2014-09-28 22:00:20 -07:00
Jordan Harband
050a2ee9d3 nvm_remote_version: add unit tests
`nvm_ls_remote` is stubbed out to avoid making network calls here.
2014-09-28 18:12:25 -07:00
Jordan Harband
ff92ba7f43 Silence more secondary "deactivate" output. 2014-09-28 16:50:50 -07:00
Jordan Harband
804f2759f8 Ensure that nvm use works when .nvmrc contains "system" 2014-09-28 16:50:50 -07:00
Jordan Harband
d5fe657382 Ensure nvm_rc_version always modifies $NVM_RC_VERSION, rather than retaining its value from previous runs. 2014-09-28 16:50:50 -07:00
Jordan Harband
3e4613fd66 Don't output nvm deactivate output when running nvm use system 2014-09-28 16:50:50 -07:00
Jordan Harband
9aec19a692 Update bash completion commands for nvm 2014-09-28 16:50:49 -07:00
Jordan Harband
b707d8b072 nvm_ls: format the version immediately, so that nvm ls 0.0.1 doesn't return nvm ls 0.0.10 2014-09-28 10:14:27 -07:00
Jordan Harband
be605cb12b Adding a failing test: nvm ls 0.0.x includes v0.0.xy 2014-09-28 10:18:00 -07:00
Jordan Harband
3c66c20570 Improving "nvm alias" tests to test for all cases. 2014-09-28 10:07:50 -07:00
Jordan Harband
59bfdb9863 Making sure fast alias tests do their own teardown. 2014-09-28 09:54:35 -07:00
Jordan Harband
25bd2bb018 Make nvm ls-remote return nvm_ls_remote's exit code. 2014-09-28 09:41:02 -07:00
Jordan Harband
4a8a5a1180 Shell-quoting some more things. 2014-09-27 17:30:09 -07:00
Jordan Harband
145da7eef8 v0.17.1 2014-09-26 23:22:56 -07:00
Jordan Harband
4cf56ae186 Remove unnecessary local var declaration. Fixes #535 2014-09-26 23:22:38 -07:00
Jordan Harband
5ad00f13fa Suppress error messages in case there's no master branch.
Fixes #533.
2014-09-25 22:10:48 -07:00
Jordan Harband
53f9841c6c v0.17.0 2014-09-24 14:58:07 -07:00
Jordan Harband
444efdb08b Adding some more quotes and $() 2014-09-23 23:51:02 -07:00
Jordan Harband
6fde379707 Use _ instead of ~ as a sentinel 2014-09-23 23:50:12 -07:00
Jordan Harband
ce69c8413e More shellcheck recommendations 2014-09-23 23:49:51 -07:00
Jordan Harband
51f6109f8d Use $() instead of backticks; add quotes 2014-09-23 23:49:10 -07:00
Jordan Harband
4f081ce4be Collapsing some if/else conditions with elif 2014-09-23 23:48:31 -07:00
Jordan Harband
db0051753a Compare shell variable contents with a sentinel. 2014-09-23 23:47:17 -07:00
Jordan Harband
cf1110ecea Quote $NVM_DIR in commands 2014-09-23 23:46:23 -07:00
Jordan Harband
34b97bf76d Adding shell var quotes in nvm alias 2014-09-23 17:23:37 -07:00
Jordan Harband
b962a590a2 Removing an extra mkdir -p 2014-09-23 17:23:09 -07:00
Jordan Harband
ddb25ed5a3 Merge pull request #530 from creationix/copy_packages_from_on_install
nvm install: Add --copy-packages-from option
2014-09-21 18:57:04 -07:00
Jordan Harband
486d14f5f8 Copy packages when applicable, whenever nvm install would normally nvm use and exit. 2014-09-21 18:25:15 -07:00
Jordan Harband
622fdd2cd0 Error out early if the --copy-packages-from version is invalid. 2014-09-21 18:03:11 -07:00
Jordan Harband
eddbe15ee8 Extract --copy-packages-from argument. 2014-09-21 18:03:11 -07:00
Jordan Harband
2e161fe414 nvm install: Remove this redundant "already installed" check. 2014-09-21 11:22:05 -07:00
Jordan Harband
a42b90d215 Adding some helpful output to nvm copy-packages 2014-09-21 11:02:03 -07:00
Jordan Harband
6bae6c07f2 Merge pull request #528 from creationix/remove_last_expr
Remove last usages of `expr`
2014-09-19 12:37:33 -07:00
Jordan Harband
7fd6d05426 Instead of using expr to check if paths need cleaning, compare cleaned paths to original paths and export appropriately. 2014-09-19 10:10:53 -07:00
Jordan Harband
5ef092b2c8 Using nvm_version_greater and nvm_version_greater_than_or_equal_to instead of expr in nvm install. 2014-09-19 10:10:37 -07:00
Jordan Harband
cb6456fd85 Using nvm_version_greater_than_or_equal_to instead of nvm_version_greater where it increases readability. 2014-09-19 10:10:01 -07:00
Jordan Harband
991fb85047 Adding nvm_version_greater_than_or_equal_to 2014-09-19 10:09:45 -07:00
Jordan Harband
edf36a8ea7 Merge pull request #526 from creationix/add_nvm_num_version_groups
Replace `expr` with `nvm_num_version_groups`
2014-09-16 10:13:57 -07:00
Jordan Harband
35466187f2 Noting the changed behavior of nvm ls vx.y. to return something useful. 2014-09-16 09:03:48 -07:00
Jordan Harband
c992b1766c Use nvm_num_version_groups in nvm_ls 2014-09-16 09:03:47 -07:00
Jordan Harband
4b2bc0be08 Adding nvm_num_version_groups 2014-09-16 09:03:47 -07:00
Jordan Harband
15b3e7b6a8 Removing unnecessary cleanup in "Listing Versions" tests. 2014-09-16 09:03:47 -07:00
Jordan Harband
8d05ab63f1 Silencing error output in the "Listing Versions" teardown script. 2014-09-16 09:03:47 -07:00
Jordan Harband
da693eaea1 Tweaking nvm_ls_current tests. 2014-09-16 09:03:47 -07:00
Jordan Harband
5363ff8916 Merge pull request #525 from creationix/add_unit_tests
Add unit tests
2014-09-15 20:46:31 -07:00
Jordan Harband
e186fa27a7 Use nvm_version_greater in nvm_binary_available 2014-09-15 09:20:47 -07:00
Jordan Harband
f6e0104685 Use nvm_normalize_version in nvm_version_greater 2014-09-15 09:17:41 -07:00
Jordan Harband
97d4e2f88f Unit tests: add nvm_find_up 2014-09-15 09:09:56 -07:00
Jordan Harband
e0a22ccf4a Unit tests: add nvm_has 2014-09-15 09:09:51 -07:00
Jordan Harband
d5d66c34d9 If there's no "default" specified, fall back to an .nvmrc file. 2014-09-15 07:54:30 -07:00
Jordan Harband
152904e3fb Return a nonzero exit code from nvm_rc_version when no .nvmrc found 2014-09-15 07:51:00 -07:00
Jordan Harband
64de890d07 v0.16.1 2014-09-14 22:24:18 -07:00
Jordan Harband
a4da8a48ef Merge pull request #524 from creationix/run_installation_tests_separately
Run installation tests separately
2014-09-14 22:21:02 -07:00
Jordan Harband
354be52672 Correct installation test paths 2014-09-14 18:01:55 -07:00
Jordan Harband
ad604cc068 Only run the "installation" tests both with and without curl. 2014-09-14 17:25:17 -07:00
Jordan Harband
ba08fa31d8 Moving actual installation tests to their own suite. 2014-09-14 17:24:30 -07:00
Jordan Harband
13aadbcf31 Run slow tests in ksh too 2014-09-14 16:42:23 -07:00
Jordan Harband
7bb6e9c915 Merge pull request #523 from creationix/run_slow_nvmrc_tests_too
Actually run all tests; fix some bugs
2014-09-14 16:38:12 -07:00
Jordan Harband
3d3145f2e0 install: don't output "additional options" when there are none. 2014-09-14 16:04:51 -07:00
Jordan Harband
4c948cf422 install: Ensure that if a version is not provided, we don't try to shift a nonexistent argument. 2014-09-14 16:04:37 -07:00
Jordan Harband
f8054d5cae copy-packages: ensure that nvm_version is also applied to compare the provided version to the current one. 2014-09-14 16:04:25 -07:00
Jordan Harband
ad2713b13a &> is a bash-specific extension for redirecting both stdout and stderr. 2014-09-14 16:04:13 -07:00
Jordan Harband
243fc04164 Fixing these test files that have never been run 2014-09-14 16:04:04 -07:00
Jordan Harband
a80f958a1e All 4 of these test files should be executable. 2014-09-14 16:03:55 -07:00
Jordan Harband
f6fef75f36 Use git in manual install instructions to determine the latest release tag, rather than hardcoding it.
Per 199ba53340
2014-09-13 11:37:19 -07:00
Jordan Harband
199ba53340 Fixing manual install instructions to use the version tag. Relates to #520 2014-09-13 00:59:09 -07:00
75 changed files with 2294 additions and 419 deletions

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@ test/bak
.urchin_stdout
node_modules/
npm-debug.log
.DS_Store
current

View File

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

View File

@@ -1,26 +1,77 @@
URCHIN=`which urchin`
SHELLS=sh bash dash ksh zsh
TEST_SUITE=fast
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
# Note: With Travis CI:
# - the path to urchin is passed via the command line.
# - the other utilities are NOT needed, so we skip the test for their existence.
URCHIN := urchin
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
# Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
# where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
# The list of all supporting utilities, installed with `npm install`.
UTILS := $(URCHIN) replace semver
# Make sure that all required utilities can be located.
UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
endif
# The files that need updating when incrementing the version number.
VERSIONED_FILES := nvm.sh install.sh README.markdown package.json
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
SHELLS := sh bash dash zsh # ksh (#574)
# Generate 'test-<shell>' target names from specified shells.
# The embedded shell names are extracted on demand inside the recipes.
SHELL_TARGETS := $(addprefix test-,$(SHELLS))
# Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
# Test suites are the names of subfolders of './test'.
TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
.PHONY: $(SHELLS) test verify-tag release
$(SHELLS):
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
@$@ $(URCHIN) -f test/$(TEST_SUITE)
# Default target (by virtue of being the first non '.'-prefixed in the file).
.PHONY: _no-target-specified
_no-target-specified:
$(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests)
test: $(SHELLS)
@$(URCHIN) -f test/slow
# Lists all targets defined in this makefile.
.PHONY: list
list:
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
default: test
# Set of test-<shell> targets; each runs the specified test suites for a single shell.
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
.PHONY: $(SHELL_TARGETS)
$(SHELL_TARGETS):
@shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
verify-tag:
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
.PHONY: test
test: $(SHELL_TARGETS)
.PHONY: _ensure-tag
_ensure-tag:
ifndef TAG
$(error TAG is undefined)
$(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
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)"
# Ensures that the git workspace is clean.
.PHONY: _ensure-clean
_ensure-clean:
@[ -z "$$(git status --porcelain --untracked-files=no || echo err)" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
.PHONY: release
release: _ensure-tag _ensure-clean
@old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
if printf "$$new_ver" | grep -q '^[0-9]'; then \
semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
else \
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
fi; \
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
git tag -a -m "v$$new_ver" "v$$new_ver"

View File

@@ -2,31 +2,36 @@
## Installation
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.
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:
- [nvmw](http://github.com/hakobera/nvmw)
- [nvm-windows](http://github.com/coreybutler/nvm-windows)
### Install script
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.0/install.sh | bash
curl https://raw.githubusercontent.com/creationix/nvm/v0.21.0/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.16.0/install.sh | bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.21.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>
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.
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
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
Or if you have `git` installed, then just clone it:
Or if you have `git` installed, then just clone it, and check out the latest version:
git clone https://github.com/creationix/nvm.git ~/.nvm
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
To activate nvm, you need to source it from your shell:
@@ -38,7 +43,7 @@ Often I also put in a line to use a specific version of node.
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
`nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file.
`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied.
To download, compile, and install the latest v0.10.x release of node, do this:
@@ -56,6 +61,22 @@ Or, you can run any arbitrary command in a subshell with the desired version of
nvm exec 0.10 node --version
You can also get the path to the executable to where it was installed:
nvm which 0.10
In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
nvm install stable
nvm install unstable
nvm use stable
nvm run unstable --version
If you want to use the system-installed version of node, you can use the special default alias "system":
nvm use system
nvm run system --version
If you want to see what versions are installed:
nvm ls
@@ -70,7 +91,7 @@ To restore your PATH, you can deactivate it.
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default 0.10
nvm alias default stable
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
@@ -79,7 +100,7 @@ To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10
`nvm use` will, by defaut, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to any value other than "true" to disable this behavior.
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs.
## License
@@ -129,8 +150,9 @@ Put the above sourcing line just below the sourcing line for NVM in your profile
nvm
$ nvm [tab][tab]
alias copy-packages help list run uninstall version
clear-cache deactivate install ls unalias use
alias deactivate install ls run unload
clear-cache exec list ls-remote unalias use
current help list-remote reinstall-packages uninstall version
nvm alias
@@ -169,7 +191,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.16.0/install.sh
[2]: https://github.com/creationix/nvm/blob/v0.21.0/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

View File

@@ -18,9 +18,11 @@ __nvm_commands ()
current_word="${COMP_WORDS[COMP_CWORD]}"
COMMANDS='\
help install uninstall use run\
ls ls-remote list list-remote deactivate\
alias unalias copy-packages clear-cache version'
help install uninstall use run exec \
alias unalias reinstall-packages \
current list ls list-remote ls-remote \
clear-cache deactivate unload \
version which'
if [ ${#COMP_WORDS[@]} == 4 ]; then
@@ -79,8 +81,8 @@ __nvm ()
return 0
}
# complete is a bash builtin, but recent versions of ZSH come with a function
# called bashcompinit that will create a complete in ZSH. If the user is in
# complete is a bash builtin, but recent versions of ZSH come with a function
# called bashcompinit that will create a complete in ZSH. If the user is in
# ZSH, load and run bashcompinit before calling the complete function.
if [[ -n ${ZSH_VERSION-} ]]; then
autoload -U +X bashcompinit && bashcompinit

View File

@@ -11,6 +11,35 @@ if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The method used ("script" or "git" in the script, defaults to "git")
# NVM_SOURCE always takes precedence
#
nvm_source() {
local NVM_METHOD
NVM_METHOD="$1"
if [ -z "$NVM_SOURCE" ]; then
local NVM_SOURCE
else
echo "$NVM_SOURCE"
return 0
fi
if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.21.0/nvm.sh"
elif [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.21.0/nvm-exec"
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
else
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
fi
echo "$NVM_SOURCE"
return 0
}
nvm_download() {
if nvm_has "curl"; then
curl $*
@@ -27,10 +56,6 @@ nvm_download() {
}
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"
printf "\r=> "
@@ -42,15 +67,17 @@ install_nvm_from_git() {
echo "=> Downloading nvm from git to '$NVM_DIR'"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
git clone "$(nvm_source "git")" "$NVM_DIR"
fi
cd $NVM_DIR && git checkout v0.16.0 && git branch -D master || true
cd "$NVM_DIR" && git checkout --quiet v0.21.0 && git branch --quiet -D master >/dev/null 2>&1
return
}
install_nvm_as_script() {
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.16.0/nvm.sh"
fi
local NVM_SOURCE
NVM_SOURCE=$(nvm_source "script")
local NVM_EXEC_SOURCE
NVM_EXEC_SOURCE=$(nvm_source "script-nvm-exec")
# Downloading to $NVM_DIR
mkdir -p "$NVM_DIR"
@@ -60,74 +87,98 @@ install_nvm_as_script() {
echo "=> Downloading nvm as script to '$NVM_DIR'"
fi
nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
echo >&2 "Failed to download '$NVM_SOURCE'.."
echo >&2 "Failed to download '$NVM_SOURCE'"
return 1
}
nvm_download -s "$NVM_EXEC_SOURCE" -o "$NVM_DIR/nvm-exec" || {
echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2
}
chmod a+x "$NVM_DIR/nvm-exec" || {
echo >&2 "Failed to mark '$NVM_DIR/nvm-exec' as executable"
return 3
}
}
if [ -z "$METHOD" ]; then
# Autodetect install method
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"
exit 1
#
# Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile)
# The echo'ed path is guaranteed to be an existing file
# 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"
fi
else
if [ "$METHOD" = "git" ]; then
}
nvm_do_install() {
if [ -z "$METHOD" ]; then
# Autodetect install method
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"
exit 1
fi
elif [ "~$METHOD" = "~git" ]; then
if ! nvm_has "git"; then
echo >&2 "You need git to install nvm"
exit 1
fi
install_nvm_from_git
fi
if [ "$METHOD" = "script" ]; then
elif [ "~$METHOD" = "~script" ]; then
if ! nvm_has "nvm_download"; then
echo >&2 "You need curl or wget to install nvm"
exit 1
fi
install_nvm_as_script
fi
fi
echo
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
if [ -z "$PROFILE" ]; then
if [ -f "$HOME/.bashrc" ]; then
PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.profile" ]; then
PROFILE="$HOME/.profile"
fi
fi
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 ~/.bashrc, ~/.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 lines to the correct file yourself:"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $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"
local NVM_PROFILE
NVM_PROFILE=$(nvm_detect_profile)
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
if [ -z "$NVM_PROFILE" ] ; then
echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again"
echo "=> Create it (touch $NVM_PROFILE) and run this script again"
echo " OR"
echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' "$NVM_PROFILE"; then
echo "=> Appending source string to $NVM_PROFILE"
printf "$SOURCE_STR\n" >> "$NVM_PROFILE"
else
echo "=> Source string already in $NVM_PROFILE"
fi
fi
echo "=> Close and reopen your terminal to start using nvm"
nvm_reset
}
#
# Unsets the various functions defined
# during the execution of the install script
#
nvm_reset() {
unset -f nvm_do_install nvm_has nvm_download install_nvm_as_script install_nvm_from_git nvm_reset nvm_detect_profile
}
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install

571
nvm.sh
View File

@@ -12,6 +12,24 @@ nvm_has() {
type "$1" > /dev/null 2>&1
}
nvm_get_latest() {
local NVM_LATEST_URL
if nvm_has "curl"; then
NVM_LATEST_URL="$(curl -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
>&2 echo 'nvm needs curl or wget to proceed.'
return 1
fi
if [ "_$NVM_LATEST_URL" = "_" ]; then
>&2 echo "http://latest.nvm.sh did not redirect to the latest release on Github"
return 2
else
echo "$NVM_LATEST_URL" | awk -F'/' '{print $NF}'
fi
}
nvm_download() {
if nvm_has "curl"; then
curl $*
@@ -28,7 +46,7 @@ nvm_download() {
}
nvm_has_system_node() {
[ "$(nvm deactivate 2> /dev/null && command -v node)" != '' ]
[ "$(nvm deactivate >/dev/null 2>&1 && command -v node)" != '' ]
}
# Make zsh glob matching behave same as bash
@@ -43,14 +61,14 @@ if [ -z "$NVM_DIR" ]; then
if [ -n "$BASH_SOURCE" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
fi
export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname "${NVM_SCRIPT_SOURCE:-$0}") > /dev/null && pwd)
export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname "${NVM_SCRIPT_SOURCE:-$0}") > /dev/null && \pwd)
fi
unset NVM_SCRIPT_SOURCE 2> /dev/null
# Setup mirror location if not already set
if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"
export NVM_NODEJS_ORG_MIRROR="https://nodejs.org/dist"
fi
nvm_tree_contains_path() {
@@ -93,22 +111,34 @@ nvm_find_nvmrc() {
# Obtain nvm version from rc file
nvm_rc_version() {
export 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>"
else
>&2 echo "No .nvmrc file found"
return 1
fi
}
nvm_version_greater() {
local LHS
LHS=$(echo "$1" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')
LHS=$(nvm_normalize_version "$1")
local RHS
RHS=$(echo "$2" | awk -F. '{for (i=1;i<=NF;++i) printf "%010d",$i}')
RHS=$(nvm_normalize_version "$2")
[ $LHS -gt $RHS ];
}
nvm_version_greater_than_or_equal_to() {
local LHS
LHS=$(nvm_normalize_version "$1")
local RHS
RHS=$(nvm_normalize_version "$2")
[ $LHS -ge $RHS ];
}
nvm_version_dir() {
local NVM_USE_NEW_DIR
NVM_USE_NEW_DIR="$1"
@@ -150,7 +180,7 @@ nvm_version() {
return $?
fi
VERSION=`nvm_ls $PATTERN | tail -n1`
VERSION="$(nvm_ls "$PATTERN" | tail -n1)"
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
@@ -160,22 +190,47 @@ nvm_version() {
nvm_remote_version() {
local PATTERN
PATTERN=$1
PATTERN="$1"
local VERSION
VERSION=`nvm_ls_remote $PATTERN | tail -n1`
VERSION="$(nvm_ls_remote "$PATTERN" | tail -n1)"
echo "$VERSION"
if [ "$VERSION" = 'N/A' ]; then
if [ "_$VERSION" = '_N/A' ]; then
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%06d%06d\n", $1,$2,$3); }'
}
nvm_ensure_version_prefix() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
}
nvm_format_version() {
echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
local VERSION
VERSION="$(nvm_ensure_version_prefix "$1")"
if [ "_$(nvm_num_version_groups "$VERSION")" != "_3" ]; then
VERSION="$(echo "$VERSION" | sed -e 's/\.*$/.0/')"
nvm_format_version "$VERSION"
else
echo "$VERSION"
fi
}
nvm_num_version_groups() {
local VERSION
VERSION="$1"
if [ -z "$VERSION" ]; then
echo "0"
return
fi
local NVM_NUM_DOTS
NVM_NUM_DOTS=$(echo "$VERSION" | sed -e 's/^v//' | sed -e 's/\.$//' | sed -e 's/[^\.]//g')
local NVM_NUM_GROUPS
NVM_NUM_GROUPS=".$NVM_NUM_DOTS"
echo "${#NVM_NUM_GROUPS}"
}
nvm_strip_path() {
@@ -192,19 +247,35 @@ nvm_prepend_path() {
nvm_binary_available() {
# binaries started with node 0.8.6
local MINIMAL
MINIMAL="0.8.6"
local VERSION
VERSION=$1
[ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]
local FIRST_VERSION_WITH_BINARY
FIRST_VERSION_WITH_BINARY="0.8.6"
nvm_version_greater_than_or_equal_to "$1" "$FIRST_VERSION_WITH_BINARY"
}
nvm_alias() {
local ALIAS
ALIAS="$1"
if [ -z "$ALIAS" ]; then
echo >&2 'An alias is required.'
return 1
fi
local NVM_ALIAS_PATH
NVM_ALIAS_PATH="$NVM_DIR/alias/$ALIAS"
if [ ! -f "$NVM_ALIAS_PATH" ]; then
echo >&2 'Alias does not exist.'
return 2
fi
cat "$NVM_ALIAS_PATH"
}
nvm_ls_current() {
local NODE_PATH
NODE_PATH="$(which node 2> /dev/null)"
local NVM_LS_CURRENT_NODE_PATH
NVM_LS_CURRENT_NODE_PATH="$(which node 2> /dev/null)"
if [ $? -ne 0 ]; then
echo 'none'
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then
elif nvm_tree_contains_path "$NVM_DIR" "$NVM_LS_CURRENT_NODE_PATH"; then
local VERSION
VERSION=`node -v 2>/dev/null`
if [ "$VERSION" = "v0.6.21-pre" ]; then
@@ -217,6 +288,59 @@ nvm_ls_current() {
fi
}
nvm_resolve_alias() {
if [ -z "$1" ]; then
return 1
fi
local PATTERN
PATTERN="$1"
local ALIAS
ALIAS="$PATTERN"
local ALIAS_TEMP
local SEEN_ALIASES
SEEN_ALIASES="$ALIAS"
while true; do
ALIAS_TEMP="$(nvm_alias "$ALIAS" 2> /dev/null)"
if [ -z "$ALIAS_TEMP" ]; then
break
fi
if [ -n "$ALIAS_TEMP" ] \
&& printf "$SEEN_ALIASES" | \grep -e "^$ALIAS_TEMP$" > /dev/null; then
ALIAS="∞"
break
fi
SEEN_ALIASES="$SEEN_ALIASES\n$ALIAS_TEMP"
ALIAS="$ALIAS_TEMP"
done
if [ -n "$ALIAS" ] && [ "_$ALIAS" != "_$PATTERN" ]; then
if [ "_$ALIAS" = "_∞" ]; then
echo "$ALIAS"
else
nvm_version "$ALIAS"
fi
return 0
fi
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
local IMPLICIT
IMPLICIT="$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)"
if [ -n "$IMPLICIT" ]; then
nvm_version "$IMPLICIT"
return $?
fi
return 3
fi
return 2
}
nvm_ls() {
local PATTERN
PATTERN=$1
@@ -227,19 +351,23 @@ nvm_ls() {
return
fi
if [ -f "$NVM_DIR/alias/$PATTERN" ]; then
nvm_version `cat $NVM_DIR/alias/$PATTERN`
if nvm_resolve_alias "$PATTERN"; then
return
fi
# If it looks like an explicit version, don't do anything funny
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*\.[0-9]*$"` != 0 ]; then
PATTERN=$(nvm_ensure_version_prefix $PATTERN)
if [ "_$(echo "$PATTERN" | cut -c1-1)" = "_v" ] && [ "_$(nvm_num_version_groups "$PATTERN")" = "_3" ]; then
if [ -d "$(nvm_version_path "$PATTERN")" ]; then
VERSIONS="$PATTERN"
fi
else
PATTERN=$(nvm_format_version $PATTERN)
if [ `expr "$PATTERN" : "v[0-9]*\.[0-9]*$"` != 0 ]; then
PATTERN="$PATTERN."
if [ "_$PATTERN" != "_system" ]; then
local NUM_VERSION_GROUPS
NUM_VERSION_GROUPS="$(nvm_num_version_groups "$PATTERN")"
if [ "_$NUM_VERSION_GROUPS" = "_2" ] || [ "_$NUM_VERSION_GROUPS" = "_1" ]; then
PATTERN="$(echo "$PATTERN" | sed -e 's/\.*$//g')."
fi
fi
if [ -d "$(nvm_version_dir new)" ]; then
VERSIONS=`find "$(nvm_version_dir new)/" "$(nvm_version_dir old)/" -maxdepth 1 -type d -name "$PATTERN*" -exec basename '{}' ';' \
@@ -269,16 +397,18 @@ nvm_ls() {
nvm_ls_remote() {
local PATTERN
PATTERN=$1
PATTERN="$1"
local VERSIONS
local GREP_OPTIONS
GREP_OPTIONS=''
if [ -n "$PATTERN" ]; then
PATTERN=`nvm_format_version "$PATTERN"`
if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then
PATTERN="$(nvm_remote_version "$(nvm_print_implicit_alias remote "$PATTERN")")"
elif [ -n "$PATTERN" ]; then
PATTERN="$(nvm_ensure_version_prefix "$PATTERN")"
else
PATTERN=".*"
fi
VERSIONS=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/ -o - \
VERSIONS=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/ -o - \
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| \grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
@@ -292,14 +422,14 @@ nvm_ls_remote() {
nvm_checksum() {
if nvm_has "sha1sum"; then
checksum=$(sha1sum $1 | \awk '{print $1}')
checksum="$(sha1sum "$1" | \awk '{print $1}')"
elif nvm_has "sha1"; then
checksum=$(sha1 -q $1)
checksum="$(sha1 -q "$1")"
else
checksum=$(shasum $1 | \awk '{print $1}')
checksum="$(shasum "$1" | \awk '{print $1}')"
fi
if [ "$checksum" = "$2" ]; then
if [ "_$checksum" = "_$2" ]; then
return
elif [ -z "$2" ]; then
echo 'Checksums empty' #missing in raspberry pi binary
@@ -318,7 +448,7 @@ nvm_print_versions() {
echo "$1" | while read VERSION; do
if [ "$VERSION" = "$NVM_CURRENT" ]; then
FORMAT='\033[0;32m-> %9s\033[0m'
elif [ -d "$(nvm_version_path "$VERSION")" ]; then
elif [ -d "$(nvm_version_path "$VERSION" 2> /dev/null)" ]; then
FORMAT='\033[0;34m%12s\033[0m'
elif [ "$VERSION" = "system" ]; then
FORMAT='\033[0;33m%12s\033[0m'
@@ -329,6 +459,59 @@ nvm_print_versions() {
done
}
nvm_validate_implicit_alias() {
if [ "_$1" != "_stable" ] && [ "_$1" != "_unstable" ]; then
echo "Only implicit aliases 'stable' and 'unstable' are supported." >&2
return 1
fi
}
nvm_print_implicit_alias() {
if [ "_$1" != "_local" ] && [ "_$1" != "_remote" ]; then
echo "nvm_print_implicit_alias must be specified with local or remote as the first argument." >&2
return 1
fi
if ! nvm_validate_implicit_alias "$2"; then
return 2
fi
local LAST_TWO
if [ "_$1" = "_local" ]; then
LAST_TWO=$(nvm_ls | \grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
else
LAST_TWO=$(nvm_ls_remote | \grep -e '^v' | cut -c2- | cut -d . -f 1,2 | uniq)
fi
local MINOR
local STABLE
local UNSTABLE
local MOD
local ZHS_HAS_SHWORDSPLIT_UNSET
ZHS_HAS_SHWORDSPLIT_UNSET=1
if nvm_has "setopt"; then
ZHS_HAS_SHWORDSPLIT_UNSET=$(setopt | \grep shwordsplit > /dev/null ; echo $?)
setopt shwordsplit
fi
for MINOR in $LAST_TWO; do
MOD=$(expr "$(nvm_normalize_version "$MINOR")" \/ 1000000 \% 2)
if [ $MOD -eq 0 ]; then
STABLE="$MINOR"
elif [ $MOD -eq 1 ]; then
UNSTABLE="$MINOR"
fi
done
if [ $ZHS_HAS_SHWORDSPLIT_UNSET -eq 1 ] && nvm_has "unsetopt"; then
unsetopt shwordsplit
fi
if [ "_$2" = "_stable" ]; then
echo $STABLE
elif [ "_$2" = "_unstable" ]; then
echo $UNSTABLE
fi
}
nvm() {
if [ $# -lt 1 ]; then
nvm help
@@ -366,31 +549,33 @@ nvm() {
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 copy-packages <version> Install global NPM packages contained in <version> to current version"
echo " nvm unload Unload NVM from shell"
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
echo "Example:"
echo " nvm install v0.10.24 Install a specific version number"
echo " nvm use 0.10 Use the latest available 0.10.x release"
echo " nvm run 0.10.24 myApp.js Run myApp.js using node v0.10.24"
echo " nvm alias default 0.10.24 Set default node version on a shell"
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 ~/.nvm, ~/.npm, and ~/.bower folders"
echo " to remove, delete, or uninstall nvm - just remove ~/.nvm, ~/.npm, and ~/.bower folders"
echo
;;
@@ -432,29 +617,49 @@ nvm() {
nobinary=1
fi
provided_version=$1
provided_version="$1"
if [ -z "$provided_version" ]; then
if [ $version_not_provided -ne 1 ]; then
nvm_rc_version
fi
provided_version="$NVM_RC_VERSION"
else
shift
fi
[ -d "$(nvm_version_path "$provided_version")" ] && echo "$provided_version is already installed." >&2 && return
VERSION=`nvm_remote_version $provided_version`
VERSION="$(nvm_remote_version "$provided_version")"
ADDITIONAL_PARAMETERS=''
shift
local PROVIDED_REINSTALL_PACKAGES_FROM
local REINSTALL_PACKAGES_FROM
while [ $# -ne 0 ]
do
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
if [ "_$(echo "$1" | cut -c 1-26)" = "_--reinstall-packages-from=" ]; then
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 27-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
elif [ "_$(echo "$1" | cut -c 1-21)" = "_--copy-packages-from=" ]; then
PROVIDED_REINSTALL_PACKAGES_FROM="$(echo "$1" | cut -c 22-)"
REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")"
else
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
fi
shift
done
if [ "_$(nvm_ensure_version_prefix "$PROVIDED_REINSTALL_PACKAGES_FROM")" = "_$VERSION" ]; then
echo "You can't reinstall global packages from the same version of node you're installing." >&2
return 4
elif [ ! -z "$PROVIDED_REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" = "_N/A" ]; then
echo "If --reinstall-packages-from is provided, it must point to an installed version of node." >&2
return 5
fi
if [ -d "$(nvm_version_path "$VERSION")" ]; then
echo "$VERSION is already installed." >&2
nvm use "$VERSION"
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi
return $?
fi
@@ -470,7 +675,7 @@ nvm() {
if nvm_binary_available "$VERSION"; then
t="$VERSION-$os-$arch"
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
sum=`nvm_download -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-${t}.tar.gz | \awk '{print $1}'`
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-${t}.tar.gz | \awk '{print $1}'`
local tmpdir
tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball
@@ -484,7 +689,9 @@ nvm() {
mv "$tmpdir" "$(nvm_version_path "$VERSION")"
)
then
nvm use $VERSION
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi
return $?
else
echo "Binary download failed, trying source." >&2
@@ -494,7 +701,9 @@ nvm() {
fi
fi
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
if [ -n "$ADDITIONAL_PARAMETERS" ]; then
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
fi
tarball=''
sum=''
@@ -507,10 +716,10 @@ nvm() {
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 - 2>&1 | \grep '200 OK'`" != '' ]; then
if [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - 2>&1 | \grep '200 OK'`" != '' ]; then
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
sum=`nvm_download -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
sum=`nvm_download -L -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt -o - | \grep node-$VERSION.tar.gz | \awk '{print $1}'`
elif [ "`nvm_download -L -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | \grep '200 OK'`" != '' ]; then
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
fi
if (
@@ -526,29 +735,33 @@ nvm() {
$make $MAKE_CXX install
)
then
nvm use $VERSION
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 [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then
if nvm_version_greater 0.2.0 "$VERSION"; then
echo "npm requires node v0.2.3 or higher" >&2
elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
elif nvm_version_greater_than_or_equal_to "$VERSION" 0.2.0; then
if nvm_version_greater 0.2.3 "$VERSION"; then
echo "npm requires node v0.2.3 or higher" >&2
else
nvm_download https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
fi
else
nvm_download https://npmjs.org/install.sh -o - | clean=yes sh
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes sh
fi
fi
else
echo "nvm: install $VERSION failed!" >&2
return 1
fi
return $?
;;
"uninstall" )
[ $# -ne 2 ] && nvm help && return
PATTERN=`nvm_format_version $2`
PATTERN=`nvm_ensure_version_prefix $2`
if [ "$PATTERN" = `nvm_version` ]; then
echo "nvm: Cannot uninstall currently-active node version, $PATTERN." >&2
return 1
@@ -577,24 +790,28 @@ nvm() {
;;
"deactivate" )
if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then
export PATH=`nvm_strip_path "$PATH" "/bin"`
local NEWPATH
NEWPATH="$(nvm_strip_path "$PATH" "/bin")"
if [ "$PATH" = "$NEWPATH" ]; then
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
else
export PATH="$NEWPATH"
hash -r
echo "$NVM_DIR/*/bin removed from \$PATH"
else
echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2
fi
if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then
export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
else
NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")"
if [ "$MANPATH" = "$NEWPATH" ]; then
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=`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" >&2
export MANPATH="$NEWPATH"
echo "$NVM_DIR/*/share/man removed from \$MANPATH"
fi
NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"
if [ "$NODE_PATH" != "$NEWPATH" ]; then
export NODE_PATH="$NEWPATH"
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
fi
;;
"use" )
@@ -607,26 +824,29 @@ nvm() {
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=`nvm_version $NVM_RC_VERSION`
fi
elif [ "_$2" != '_system' ]; then
VERSION="$(nvm_version "$2")"
else
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
VERSION="$2"
fi
if [ -z "$VERSION" ]; then
nvm help
return 127
fi
if [ -z "$VERSION" ]; then
VERSION=`nvm_version $2`
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)."
return
else
echo "System version of node not found." >&2
return 127
fi
elif [ "_$VERSION" = "_∞" ]; then
echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2
return 8
fi
local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
@@ -637,24 +857,21 @@ nvm() {
PATH=`nvm_strip_path "$PATH" "/bin"`
# Prepend current version
PATH=`nvm_prepend_path "$PATH" "$NVM_VERSION_DIR/bin"`
if [ -z "$MANPATH" ]; then
MANPATH=$(manpath)
if nvm_has manpath; then
if [ -z "$MANPATH" ]; then
MANPATH=$(manpath)
fi
# Strip other version from MANPATH
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
# Prepend current version
MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_VERSION_DIR/share/man"`
export MANPATH
fi
# Strip other version from MANPATH
MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`
# Prepend current version
MANPATH=`nvm_prepend_path "$MANPATH" "$NVM_VERSION_DIR/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_VERSION_DIR/lib/node_modules"`
export PATH
hash -r
export MANPATH
export NODE_PATH
export NVM_PATH="$NVM_VERSION_DIR/lib/node"
export NVM_BIN="$NVM_VERSION_DIR/bin"
if [ "$NVM_SYMLINK_CURRENT" = true ] || [ -z "$NVM_SYMLINK_CURRENT" ]; then
if [ "$NVM_SYMLINK_CURRENT" = true ]; then
rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
fi
echo "Now using node $VERSION"
@@ -681,7 +898,7 @@ nvm() {
provided_version=$1
if [ -n "$provided_version" ]; then
VERSION=`nvm_version $provided_version`
if [ $VERSION = "N/A" ]; then
if [ "_$VERSION" = "_N/A" ]; then
provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then
nvm_rc_version && has_checked_nvmrc=1
@@ -692,28 +909,27 @@ nvm() {
fi
fi
local NVM_VERSION_DIR
NVM_VERSION_DIR=$(nvm_version_path "$VERSION")
if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
RUN_NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`
RUN_NODE_PATH=`nvm_prepend_path "$NODE_PATH" "$NVM_VERSION_DIR/lib/node_modules"`
echo "Running node $VERSION"
NODE_PATH=$RUN_NODE_PATH $NVM_VERSION_DIR/bin/node "$@"
local ARGS
ARGS="$@"
local OUTPUT
OUTPUT="$(nvm use "$VERSION" >/dev/null && node "$ARGS")"
local EXIT_CODE
EXIT_CODE="$?"
echo "$OUTPUT"
return $EXIT_CODE
;;
"exec" )
shift
local provided_version
provided_version=$1
provided_version="$1"
if [ -n "$provided_version" ]; then
VERSION=`nvm_version $provided_version`
if [ $VERSION = "N/A" ]; then
provided_version=''
nvm_rc_version
VERSION=`nvm_version $NVM_RC_VERSION`
VERSION="$(nvm_version "$NVM_RC_VERSION")"
else
shift
fi
@@ -740,41 +956,99 @@ nvm() {
return $NVM_LS_EXIT_CODE
;;
"ls-remote" | "list-remote" )
nvm_print_versions "`nvm_ls_remote $2`"
return
local NVM_LS_EXIT_CODE
NVM_LS_OUTPUT=$(nvm_ls_remote "$2")
NVM_LS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_OUTPUT"
return $NVM_LS_EXIT_CODE
;;
"current" )
nvm_version current
;;
"which" )
if [ $# -eq 1 ]; then
nvm_rc_version
if [ -n "$NVM_RC_VERSION" ]; then
VERSION=$(nvm_version $NVM_RC_VERSION)
fi
elif [ "_$2" != '_system' ]; then
VERSION="$(nvm_version "$2")"
else
VERSION="$2"
fi
if [ -z "$VERSION" ]; then
nvm help
return 127
fi
if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node >/dev/null 2>&1; then
local NVM_BIN
NVM_BIN="$(nvm use system >/dev/null 2>&1 && which node)"
if [ -n "$NVM_BIN" ]; then
echo "$NVM_BIN"
return
else
return 1
fi
else
echo "System version of node not found." >&2
return 127
fi
elif [ "_$VERSION" = "_∞" ]; then
echo "The alias \"$2\" leads to an infinite loop. Aborting." >&2
return 8
fi
local NVM_VERSION_DIR
NVM_VERSION_DIR="$(nvm_version_path "$VERSION")"
if [ ! -d "$NVM_VERSION_DIR" ]; then
echo "$VERSION version is not installed yet" >&2
return 1
fi
echo "$NVM_VERSION_DIR/bin/node"
;;
"alias" )
mkdir -p $NVM_DIR/alias
mkdir -p "$NVM_DIR/alias"
if [ $# -le 2 ]; then
local DEST
for ALIAS in $NVM_DIR/alias/$2*; do
if [ -e "$ALIAS" ]; then
DEST=`cat $ALIAS`
VERSION=`nvm_version $DEST`
if [ "$DEST" = "$VERSION" ]; then
echo "$(basename $ALIAS) -> $DEST"
for ALIAS_PATH in "$NVM_DIR"/alias/"$2"*; do
ALIAS="$(basename "$ALIAS_PATH")"
DEST="$(nvm_alias "$ALIAS" 2> /dev/null)"
if [ -n "$DEST" ]; then
VERSION="$(nvm_version "$DEST")"
if [ "_$DEST" = "_$VERSION" ]; then
echo "$ALIAS -> $DEST"
else
echo "$(basename $ALIAS) -> $DEST (-> $VERSION)"
echo "$ALIAS -> $DEST (-> $VERSION)"
fi
fi
done
for ALIAS in "stable" "unstable"; do
if [ ! -f "$NVM_DIR/alias/$ALIAS" ]; then
if [ $# -lt 2 ] || [ "~$ALIAS" = "~$2" ]; then
DEST="$(nvm_print_implicit_alias local "$ALIAS")"
if [ "_$DEST" != "_" ]; then
VERSION="$(nvm_version "$DEST")"
echo "$ALIAS -> $DEST (-> $VERSION) (default)"
fi
fi
fi
done
return
fi
if [ -z "$3" ]; then
rm -f $NVM_DIR/alias/$2
rm -f "$NVM_DIR/alias/$2"
echo "$2 -> *poof*"
return
fi
mkdir -p $NVM_DIR/alias
VERSION=`nvm_version $3`
VERSION="$(nvm_version "$3")"
if [ $? -ne 0 ]; then
echo "! WARNING: Version '$3' does not exist." >&2
fi
echo $3 > "$NVM_DIR/alias/$2"
if [ ! "$3" = "$VERSION" ]; then
if [ ! "_$3" = "_$VERSION" ]; then
echo "$2 -> $3 (-> $VERSION)"
else
echo "$2 -> $3"
@@ -787,7 +1061,7 @@ nvm() {
rm -f $NVM_DIR/alias/$2
echo "Deleted alias $2"
;;
"copy-packages" )
"reinstall-packages" | "copy-packages" )
if [ $# -ne 2 ]; then
nvm help
return 127
@@ -796,8 +1070,8 @@ nvm() {
local PROVIDED_VERSION
PROVIDED_VERSION="$2"
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ]; then
echo 'Can not copy packages from the current version of node.' >&2
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ] || [ "$(nvm_version $PROVIDED_VERSION)" = "$(nvm_ls_current)" ]; then
echo 'Can not reinstall packages from the current version of node.' >&2
return 2
fi
@@ -814,6 +1088,7 @@ nvm() {
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
fi
echo "Copying global packages from $VERSION..."
echo "$INSTALLS" | xargs npm install -g --quiet
;;
"clear-cache" )
@@ -824,10 +1099,10 @@ nvm() {
nvm_version $2
;;
"--version" )
echo "0.16.0"
echo "0.21.0"
;;
"unload" )
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to > /dev/null 2>&1
unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1
;;
* )
@@ -836,5 +1111,9 @@ nvm() {
esac
}
nvm ls default >/dev/null && nvm use default >/dev/null || true
if nvm ls default >/dev/null; then
nvm use default >/dev/null
elif nvm_rc_version >/dev/null 2>&1; then
nvm use >/dev/null
fi

View File

@@ -1,14 +1,17 @@
{
"name": "nvm",
"version": "0.16.0",
"version": "0.21.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
},
"scripts": {
"test": "urchin test",
"test/fast": "urchin -f test/fast",
"test/slow": "urchin -f test/slow"
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
"test/installation": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation test-$shell",
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell"
},
"repository": {
"type": "git",
@@ -27,7 +30,8 @@
},
"homepage": "https://github.com/creationix/nvm",
"devDependencies": {
"urchin": "~0.0.2"
"replace": "~0.3.0",
"semver": "~4.1.1",
"urchin": "~0.0.5"
}
}

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. ../../../nvm.sh
[ $(nvm alias test1 | wc -l) = '2' ]
[ $(nvm alias test-stable-1 | wc -l) = '2' ]

View File

@@ -0,0 +1,18 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias)
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \
|| die "nvm alias did not contain the default local stable node version"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \
|| die "nvm alias did not contain the default local unstable node version"

View File

@@ -0,0 +1,37 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../../alias/stable
rm -rf ../../../alias/unstable
rm -rf ../../../v0.8.1
rm -rf ../../../v0.9.1
}
mkdir ../../../v0.8.1
mkdir ../../../v0.9.1
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \
|| die "stable and unstable versions are the same!"
nvm alias stable "$EXPECTED_UNSTABLE"
nvm alias unstable "$EXPECTED_STABLE"
NVM_ALIAS_OUTPUT=$(nvm alias)
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'stable' alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'unstable' alias"
cleanup

View File

@@ -1,4 +1,48 @@
#!/bin/sh
. ../../../nvm.sh
[ $(nvm alias | wc -l) = '10' ]
die () { echo $@ ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias)
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \
|| die "did not find test-stable-1 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \
|| die "did not find test-stable-2 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \
|| die "did not find test-stable-3 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \
|| die "did not find test-stable-4 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \
|| die "did not find test-stable-5 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \
|| die "did not find test-stable-6 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \
|| die "did not find test-stable-7 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \
|| die "did not find test-stable-8 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \
|| die "did not find test-stable-9 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \
|| die "did not find test-stable-10 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \
|| die "did not find test-unstable-1 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \
|| die "did not find test-unstable-2 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \
|| die "did not find test-unstable-3 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \
|| die "did not find test-unstable-4 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \
|| die "did not find test-unstable-5 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \
|| die "did not find test-unstable-6 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \
|| die "did not find test-unstable-7 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \
|| die "did not find test-unstable-8 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \
|| die "did not find test-unstable-9 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \
|| die "did not find test-unstable-10 alias"

View File

@@ -0,0 +1,36 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../../nvm.sh
ALIAS="$(nvm_resolve_alias loopback)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias loopback was not ∞; got $ALIAS"
OUTPUT="$(nvm alias loopback)"
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias one)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias one was not ∞; got $ALIAS"
OUTPUT="$(nvm alias one)"
EXPECTED_OUTPUT="one -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias two)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias two was not ∞; got $ALIAS"
OUTPUT="$(nvm alias two)"
EXPECTED_OUTPUT="two -> three (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias three)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias three was not ∞; got $ALIAS"
OUTPUT="$(nvm alias three)"
EXPECTED_OUTPUT="three -> one (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias four)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias four was not ∞; got $ALIAS"
OUTPUT="$(nvm alias four)"
EXPECTED_OUTPUT="four -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"

View File

@@ -0,0 +1,10 @@
#!/bin/sh
echo loopback > ../../../../alias/loopback
echo two > ../../../../alias/one
echo three > ../../../../alias/two
echo one > ../../../../alias/three
echo two > ../../../../alias/four

View File

@@ -0,0 +1,10 @@
#!/bin/sh
rm -f ../../../../alias/loopback
rm -f ../../../../alias/one
rm -f ../../../../alias/two
rm -f ../../../../alias/three
rm -f ../../../../alias/four

View File

@@ -0,0 +1,28 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"
for i in $(seq 1 10)
do
STABLE_ALIAS="$(nvm_resolve_alias test-stable-$i)"
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|| die "'nvm_resolve_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
UNSTABLE_ALIAS="$(nvm_resolve_alias test-unstable-$i)"
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|| die "'nvm_resolve_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
done
EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?)
[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE"
STABLE="$(nvm_resolve_alias stable)"
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_alias stable' was not v0.0.10; got $STABLE"
UNSTABLE="$(nvm_resolve_alias unstable)"
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE"

9
test/fast/Aliases/setup Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/sh
for i in $(seq 1 10)
do
echo 0.0.$i > ../../../alias/test-stable-$i
mkdir -p ../../../v0.0.$i
echo 0.1.$i > ../../../alias/test-unstable-$i
mkdir -p ../../../v0.1.$i
done

View File

@@ -1,6 +0,0 @@
#!/bin/sh
for i in $(seq 1 10)
do
echo v0.0.$i > ../../../alias/test$i
done

13
test/fast/Aliases/teardown Executable file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
for i in $(seq 1 10)
do
rm -f "../../../alias/test-stable-$i"
rm -rf "../../../v0.0.$i"
rm -f "../../../alias/test-unstable-$i"
rm -rf "../../../v0.1.$i"
done
rm -f "../../../alias/stable"
rm -f "../../../alias/unstable"

View File

@@ -0,0 +1,27 @@
#!/bin/sh
mkdir -p ../../../v0.0.2
mkdir -p ../../../v0.0.20
mkdir -p ../../../versions/v0.12.0
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers.
nvm which 0.0.2 || die "v0.0.2 not found"
NVM_BIN="$(nvm which 0.0.2)"
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.2)/bin/node" ] \
|| die "'nvm which 0.0.2' did not contain the correct path: got '$NVM_BIN'"
nvm which 0.0.20 || die "v0.0.20 not found"
NVM_BIN="$(nvm which 0.0.20)"
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.20)/bin/node" ] \
|| die "'nvm which 0.20.0' did not contain the correct path: got '$NVM_BIN'"
nvm which 0.12.0 || die "v0.0.20 not found"
NVM_BIN="$(nvm which 0.12.0)"
[ "_$NVM_BIN" = "_$(nvm_version_path v0.12.0)/bin/node" ] \
|| die "'nvm which 0.12.0' did not contain the correct path: got '$NVM_BIN'"

View File

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

View File

@@ -0,0 +1,3 @@
rmdir ../../../v0.0.2 >/dev/null 2>&1
rmdir ../../../v0.0.20 >/dev/null 2>&1
rmdir ../../../v0.12.0 >/dev/null 2>&1

View File

@@ -0,0 +1,21 @@
#!/bin/sh
mkdir ../../../v0.0.2
mkdir ../../../v0.0.20
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers.
nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null
if [ $? -eq 0 ]; then
echo '"nvm ls 0.0.2" contained v0.0.2'
fi
nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null
if [ $? -eq 0 ]; then
die '"nvm ls 0.0.2" contained v0.0.20'
fi

View File

@@ -0,0 +1,29 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
mkdir ../../../v0.2.3
mkdir ../../../v0.3.3
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \
|| die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)"
nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \
|| die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)"
mkdir ../../../v0.1.2
nvm alias stable 0.1
nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \
|| die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2"
nvm ls stable | \grep v0.1.2 >/dev/null \
|| die "'nvm ls stable' did not contain v0.1.2"

View File

@@ -1,7 +1,6 @@
#!/bin/sh
cleanup () { unset -f nvm_has_system_node; }
die () { cleanup ; echo $@ ; exit 1; }
die () { echo $@ ; exit 1; }
. ../../../nvm.sh

View File

@@ -2,13 +2,10 @@
mkdir ../../../v0.1.3
mkdir ../../../v0.2.3
mkdir ../../../versions
. ../../../nvm.sh
mkdir ../../../versions
[ -z "$(nvm ls | \grep 'versions')" ]
# The result should contain only the appropriate version numbers.
rmdir ../../../versions

View File

@@ -6,6 +6,6 @@ mkdir ../../../v0.1.2
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. | grep v0.1.2 &&
nvm ls v0.1.1 | grep N/A

27
test/fast/Listing versions/teardown Normal file → Executable file
View File

@@ -1,12 +1,17 @@
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
rmdir ../../../versions
unalias nvm_has_system_node
rmdir ../../../v0.0.1 >/dev/null 2>&1
rmdir ../../../v0.0.2 >/dev/null 2>&1
rmdir ../../../v0.0.3 >/dev/null 2>&1
rmdir ../../../v0.0.9 >/dev/null 2>&1
rmdir ../../../v0.0.20 >/dev/null 2>&1
rmdir ../../../v0.1.2 >/dev/null 2>&1
rmdir ../../../v0.1.3 >/dev/null 2>&1
rmdir ../../../v0.2.3 >/dev/null 2>&1
rmdir ../../../v0.3.1 >/dev/null 2>&1
rmdir ../../../v0.3.3 >/dev/null 2>&1
rmdir ../../../v0.3.9 >/dev/null 2>&1
rmdir ../../../v0.20.3 >/dev/null 2>&1
rmdir ../../../versions >/dev/null 2>&1
unalias nvm_has_system_node >/dev/null 2>&1
rm -f ../../../alias/stable >/dev/null 2>&1
rm -f ../../../alias/unstable >/dev/null 2>&1

View File

@@ -7,8 +7,11 @@ die () { echo $@ ; exit 1; }
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
. ../../nvm.sh
nvm use v0.2.3 &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` != 0 ] || die "Failed to activate v0.2.3"
nvm use v0.2.3 || die "Failed to activate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"
# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable
nvm deactivate &&
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] && [ `expr $NODE_PATH : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "Failed to deactivate v0.2.3"
nvm deactivate || die "Failed to deactivate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly"

View File

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

View File

@@ -0,0 +1,22 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
rm -rf ../../alias/foo
}
. ../../nvm.sh
echo 'foo' > ../../alias/foo
OUTPUT="$(nvm use foo 2>&1)"
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
cleanup;

View File

@@ -1,5 +1,6 @@
#!/bin/bash
export NVM_SYMLINK_CURRENT=true
. ../../nvm.sh
rm -rf ../../v0.10.29

View File

@@ -34,7 +34,7 @@ function cleanup() {
function runNvmUse() {
mkdir ../../${TEST_NODE_VERSION}
nvm use ${TEST_NODE_VERSION} &> /dev/null
nvm use ${TEST_NODE_VERSION} > /dev/null 2>&1
rmdir ../../${TEST_NODE_VERSION}
}
@@ -45,39 +45,40 @@ function isCurrentSymlinkPresent() {
NVM_SYMLINK_CURRENT=false
cleanup
runNvmUse
isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!"
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!"
registerExpectedNoSymlink $?
NVM_SYMLINK_CURRENT=true
cleanup
runNvmUse
isCurrentSymlinkPresent || echo "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!"
isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!"
registerExpectedSymlink $?
NVM_SYMLINK_CURRENT=garbagevalue
cleanup
runNvmUse
isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!"
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!"
registerExpectedNoSymlink $?
NVM_SYMLINK_CURRENT=0
cleanup
runNvmUse
isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!"
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!"
registerExpectedNoSymlink $?
NVM_SYMLINK_CURRENT=1
cleanup
runNvmUse
isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!"
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!"
registerExpectedNoSymlink $?
unset NVM_SYMLINK_CURRENT
cleanup
runNvmUse
isCurrentSymlinkPresent || echo "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!"
registerExpectedSymlink $?
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!"
registerExpectedNoSymlink $?
cleanup
[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true

33
test/fast/Unit tests/nvm_alias Executable file
View File

@@ -0,0 +1,33 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../../alias/test
}
. ../../../nvm.sh
OUTPUT="$(nvm_alias 2>&1)"
EXPECTED_OUTPUT='An alias is required.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias' produced wrong output; got $OUTPUT"
EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)"
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1"
rm -rf ../../../alias/nonexistent
OUTPUT="$(nvm_alias nonexistent 2>&1)"
EXPECTED_OUTPUT='Alias does not exist.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias nonexistent' produced wrong output; got $OUTPUT"
EXIT_CODE="$(nvm_alias nonexistent >/dev/null 2>&1 ; echo $?)"
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_alias nonexistent' exited with $EXIT_CODE, expected 2"
EXPECTED_OUTPUT="0.10"
nvm alias test "$EXPECTED_OUTPUT" || die "'nvm alias test $EXPECTED_OUTPUT' failed"
OUTPUT="$(nvm_alias test)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias test' produced wrong output; got $OUTPUT"
cleanup

View File

@@ -0,0 +1,26 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
setup() {
cleanup
mkdir -p tmp_nvm_find_up/a/b/c/d
touch tmp_nvm_find_up/test
touch tmp_nvm_find_up/a/b/c/test
}
cleanup () {
rm -rf tmp_nvm_find_up
}
. ../../../nvm.sh
setup
TEST_DIR="$PWD"
[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up"
[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up"
[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir"
[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir"
cleanup

View File

@@ -0,0 +1,14 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
OUTPUT="$(nvm_format_version 0.1.2)"
EXPECTED_OUTPUT="v0.1.2"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT"
OUTPUT="$(nvm_format_version 0.1)"
EXPECTED_OUTPUT="v0.1.0"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT"

View File

@@ -0,0 +1,20 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_has
}
. ../../../nvm.sh
nvm_has() { return 1 ; }
OUTPUT="$(nvm_get_latest 2>&1)"
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_nvm needs curl or wget to proceed." ] \
|| die "no curl/wget did not report correct error message, got '$OUTPUT'"
[ "_$EXIT_CODE" = "_1" ] \
|| die "no curl/wget did not exit with code 1, got $EXIT_CODE"
cleanup

12
test/fast/Unit tests/nvm_has Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly'
[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output"
! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found"

View File

@@ -6,7 +6,7 @@ die () { echo $@ ; exit 1; }
return_zero () { return 0; }
[ "$( (nvm deactivate > /dev/null 2>&1) && nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'
[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'
TEST_PWD=$(pwd)
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"

View File

@@ -0,0 +1,485 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_download
}
. ../../../nvm.sh
# sample output at the time the test was written
nvm_download() {
echo 'foo "v0.10.0'
echo 'foo "v0.10.0'
echo 'foo "v0.10.1'
echo 'foo "v0.10.1'
echo 'foo "v0.10.10'
echo 'foo "v0.10.10'
echo 'foo "v0.10.11'
echo 'foo "v0.10.11'
echo 'foo "v0.10.12'
echo 'foo "v0.10.12'
echo 'foo "v0.10.13'
echo 'foo "v0.10.13'
echo 'foo "v0.10.14'
echo 'foo "v0.10.14'
echo 'foo "v0.10.15'
echo 'foo "v0.10.15'
echo 'foo "v0.10.16'
echo 'foo "v0.10.16'
echo 'foo "v0.10.16'
echo 'foo "v0.10.16'
echo 'foo "v0.10.17'
echo 'foo "v0.10.17'
echo 'foo "v0.10.18'
echo 'foo "v0.10.18'
echo 'foo "v0.10.19'
echo 'foo "v0.10.19'
echo 'foo "v0.10.2'
echo 'foo "v0.10.2'
echo 'foo "v0.10.20'
echo 'foo "v0.10.20'
echo 'foo "v0.10.21'
echo 'foo "v0.10.21'
echo 'foo "v0.10.22'
echo 'foo "v0.10.22'
echo 'foo "v0.10.23'
echo 'foo "v0.10.23'
echo 'foo "v0.10.24'
echo 'foo "v0.10.24'
echo 'foo "v0.10.25'
echo 'foo "v0.10.25'
echo 'foo "v0.10.26'
echo 'foo "v0.10.26'
echo 'foo "v0.10.27'
echo 'foo "v0.10.27'
echo 'foo "v0.10.28'
echo 'foo "v0.10.28'
echo 'foo "v0.10.29'
echo 'foo "v0.10.29'
echo 'foo "v0.10.3'
echo 'foo "v0.10.3'
echo 'foo "v0.10.30'
echo 'foo "v0.10.30'
echo 'foo "v0.10.31'
echo 'foo "v0.10.31'
echo 'foo "v0.10.32'
echo 'foo "v0.10.32'
echo 'foo "v0.10.4'
echo 'foo "v0.10.4'
echo 'foo "v0.10.5'
echo 'foo "v0.10.5'
echo 'foo "v0.10.6'
echo 'foo "v0.10.6'
echo 'foo "v0.10.7'
echo 'foo "v0.10.7'
echo 'foo "v0.10.8'
echo 'foo "v0.10.8'
echo 'foo "v0.10.9'
echo 'foo "v0.10.9'
echo 'foo "v0.11.0'
echo 'foo "v0.11.0'
echo 'foo "v0.11.1'
echo 'foo "v0.11.1'
echo 'foo "v0.11.10'
echo 'foo "v0.11.10'
echo 'foo "v0.11.11'
echo 'foo "v0.11.11'
echo 'foo "v0.11.12'
echo 'foo "v0.11.12'
echo 'foo "v0.11.13'
echo 'foo "v0.11.13'
echo 'foo "v0.11.14'
echo 'foo "v0.11.14'
echo 'foo "v0.11.2'
echo 'foo "v0.11.2'
echo 'foo "v0.11.3'
echo 'foo "v0.11.3'
echo 'foo "v0.11.4'
echo 'foo "v0.11.4'
echo 'foo "v0.11.5'
echo 'foo "v0.11.5'
echo 'foo "v0.11.6'
echo 'foo "v0.11.6'
echo 'foo "v0.11.7'
echo 'foo "v0.11.7'
echo 'foo "v0.11.8'
echo 'foo "v0.11.8'
echo 'foo "v0.11.9'
echo 'foo "v0.11.9'
echo 'foo "v0.5.1'
echo 'foo "v0.5.1'
echo 'foo "v0.5.10'
echo 'foo "v0.5.10'
echo 'foo "v0.5.2'
echo 'foo "v0.5.2'
echo 'foo "v0.5.3'
echo 'foo "v0.5.3'
echo 'foo "v0.5.4'
echo 'foo "v0.5.4'
echo 'foo "v0.5.5'
echo 'foo "v0.5.5'
echo 'foo "v0.5.6'
echo 'foo "v0.5.6'
echo 'foo "v0.5.7'
echo 'foo "v0.5.7'
echo 'foo "v0.5.8'
echo 'foo "v0.5.8'
echo 'foo "v0.5.9'
echo 'foo "v0.5.9'
echo 'foo "v0.6.0'
echo 'foo "v0.6.0'
echo 'foo "v0.6.1'
echo 'foo "v0.6.1'
echo 'foo "v0.6.10'
echo 'foo "v0.6.10'
echo 'foo "v0.6.11'
echo 'foo "v0.6.11'
echo 'foo "v0.6.12'
echo 'foo "v0.6.12'
echo 'foo "v0.6.13'
echo 'foo "v0.6.13'
echo 'foo "v0.6.14'
echo 'foo "v0.6.14'
echo 'foo "v0.6.15'
echo 'foo "v0.6.15'
echo 'foo "v0.6.16'
echo 'foo "v0.6.16'
echo 'foo "v0.6.17'
echo 'foo "v0.6.17'
echo 'foo "v0.6.18'
echo 'foo "v0.6.18'
echo 'foo "v0.6.19'
echo 'foo "v0.6.19'
echo 'foo "v0.6.2'
echo 'foo "v0.6.2'
echo 'foo "v0.6.20'
echo 'foo "v0.6.20'
echo 'foo "v0.6.21'
echo 'foo "v0.6.21'
echo 'foo "v0.6.3'
echo 'foo "v0.6.3'
echo 'foo "v0.6.4'
echo 'foo "v0.6.4'
echo 'foo "v0.6.5'
echo 'foo "v0.6.5'
echo 'foo "v0.6.6'
echo 'foo "v0.6.6'
echo 'foo "v0.6.7'
echo 'foo "v0.6.7'
echo 'foo "v0.6.8'
echo 'foo "v0.6.8'
echo 'foo "v0.6.9'
echo 'foo "v0.6.9'
echo 'foo "v0.7.0'
echo 'foo "v0.7.0'
echo 'foo "v0.7.1'
echo 'foo "v0.7.1'
echo 'foo "v0.7.10'
echo 'foo "v0.7.10'
echo 'foo "v0.7.11'
echo 'foo "v0.7.11'
echo 'foo "v0.7.12'
echo 'foo "v0.7.12'
echo 'foo "v0.7.2'
echo 'foo "v0.7.2'
echo 'foo "v0.7.3'
echo 'foo "v0.7.3'
echo 'foo "v0.7.4'
echo 'foo "v0.7.4'
echo 'foo "v0.7.5'
echo 'foo "v0.7.5'
echo 'foo "v0.7.6'
echo 'foo "v0.7.6'
echo 'foo "v0.7.7'
echo 'foo "v0.7.7'
echo 'foo "v0.7.8'
echo 'foo "v0.7.8'
echo 'foo "v0.7.9'
echo 'foo "v0.7.9'
echo 'foo "v0.8.0'
echo 'foo "v0.8.0'
echo 'foo "v0.8.1'
echo 'foo "v0.8.1'
echo 'foo "v0.8.10'
echo 'foo "v0.8.10'
echo 'foo "v0.8.11'
echo 'foo "v0.8.11'
echo 'foo "v0.8.12'
echo 'foo "v0.8.12'
echo 'foo "v0.8.13'
echo 'foo "v0.8.13'
echo 'foo "v0.8.14'
echo 'foo "v0.8.14'
echo 'foo "v0.8.15'
echo 'foo "v0.8.15'
echo 'foo "v0.8.16'
echo 'foo "v0.8.16'
echo 'foo "v0.8.17'
echo 'foo "v0.8.17'
echo 'foo "v0.8.18'
echo 'foo "v0.8.18'
echo 'foo "v0.8.19'
echo 'foo "v0.8.19'
echo 'foo "v0.8.2'
echo 'foo "v0.8.2'
echo 'foo "v0.8.20'
echo 'foo "v0.8.20'
echo 'foo "v0.8.21'
echo 'foo "v0.8.21'
echo 'foo "v0.8.22'
echo 'foo "v0.8.22'
echo 'foo "v0.8.23'
echo 'foo "v0.8.23'
echo 'foo "v0.8.24'
echo 'foo "v0.8.24'
echo 'foo "v0.8.25'
echo 'foo "v0.8.25'
echo 'foo "v0.8.26'
echo 'foo "v0.8.26'
echo 'foo "v0.8.27'
echo 'foo "v0.8.27'
echo 'foo "v0.8.28'
echo 'foo "v0.8.28'
echo 'foo "v0.8.3'
echo 'foo "v0.8.3'
echo 'foo "v0.8.4'
echo 'foo "v0.8.4'
echo 'foo "v0.8.5'
echo 'foo "v0.8.5'
echo 'foo "v0.8.6'
echo 'foo "v0.8.6'
echo 'foo "v0.8.7'
echo 'foo "v0.8.7'
echo 'foo "v0.8.8'
echo 'foo "v0.8.8'
echo 'foo "v0.8.9'
echo 'foo "v0.8.9'
echo 'foo "v0.9.0'
echo 'foo "v0.9.0'
echo 'foo "v0.9.1'
echo 'foo "v0.9.1'
echo 'foo "v0.9.10'
echo 'foo "v0.9.10'
echo 'foo "v0.9.11'
echo 'foo "v0.9.11'
echo 'foo "v0.9.12'
echo 'foo "v0.9.12'
echo 'foo "v0.9.2'
echo 'foo "v0.9.2'
echo 'foo "v0.9.3'
echo 'foo "v0.9.3'
echo 'foo "v0.9.4'
echo 'foo "v0.9.4'
echo 'foo "v0.9.5'
echo 'foo "v0.9.5'
echo 'foo "v0.9.6'
echo 'foo "v0.9.6'
echo 'foo "v0.9.7'
echo 'foo "v0.9.7'
echo 'foo "v0.9.8'
echo 'foo "v0.9.8'
echo 'foo "v0.9.9'
echo 'foo "v0.9.9'
echo 'foo "v0.1.100'
echo 'foo "v0.1.100'
echo 'foo "v0.1.101'
echo 'foo "v0.1.101'
echo 'foo "v0.1.102'
echo 'foo "v0.1.102'
echo 'foo "v0.1.103'
echo 'foo "v0.1.103'
echo 'foo "v0.1.104'
echo 'foo "v0.1.104'
echo 'foo "v0.1.14'
echo 'foo "v0.1.14'
echo 'foo "v0.1.15'
echo 'foo "v0.1.15'
echo 'foo "v0.1.16'
echo 'foo "v0.1.16'
echo 'foo "v0.1.17'
echo 'foo "v0.1.17'
echo 'foo "v0.1.18'
echo 'foo "v0.1.18'
echo 'foo "v0.1.19'
echo 'foo "v0.1.19'
echo 'foo "v0.1.20'
echo 'foo "v0.1.20'
echo 'foo "v0.1.21'
echo 'foo "v0.1.21'
echo 'foo "v0.1.22'
echo 'foo "v0.1.22'
echo 'foo "v0.1.23'
echo 'foo "v0.1.23'
echo 'foo "v0.1.24'
echo 'foo "v0.1.24'
echo 'foo "v0.1.25'
echo 'foo "v0.1.25'
echo 'foo "v0.1.26'
echo 'foo "v0.1.26'
echo 'foo "v0.1.27'
echo 'foo "v0.1.27'
echo 'foo "v0.1.28'
echo 'foo "v0.1.28'
echo 'foo "v0.1.29'
echo 'foo "v0.1.29'
echo 'foo "v0.1.30'
echo 'foo "v0.1.30'
echo 'foo "v0.1.31'
echo 'foo "v0.1.31'
echo 'foo "v0.1.32'
echo 'foo "v0.1.32'
echo 'foo "v0.1.33'
echo 'foo "v0.1.33'
echo 'foo "v0.1.90'
echo 'foo "v0.1.90'
echo 'foo "v0.1.91'
echo 'foo "v0.1.91'
echo 'foo "v0.1.92'
echo 'foo "v0.1.92'
echo 'foo "v0.1.93'
echo 'foo "v0.1.93'
echo 'foo "v0.1.94'
echo 'foo "v0.1.94'
echo 'foo "v0.1.95'
echo 'foo "v0.1.95'
echo 'foo "v0.1.96'
echo 'foo "v0.1.96'
echo 'foo "v0.1.97'
echo 'foo "v0.1.97'
echo 'foo "v0.1.98'
echo 'foo "v0.1.98'
echo 'foo "v0.1.99'
echo 'foo "v0.1.99'
echo 'foo "v0.10.14'
echo 'foo "v0.10.14'
echo 'foo "v0.2.0'
echo 'foo "v0.2.0'
echo 'foo "v0.2.1'
echo 'foo "v0.2.1'
echo 'foo "v0.2.2'
echo 'foo "v0.2.2'
echo 'foo "v0.2.3'
echo 'foo "v0.2.3'
echo 'foo "v0.2.4'
echo 'foo "v0.2.4'
echo 'foo "v0.2.5'
echo 'foo "v0.2.5'
echo 'foo "v0.2.6'
echo 'foo "v0.2.6'
echo 'foo "v0.3.0'
echo 'foo "v0.3.0'
echo 'foo "v0.3.1'
echo 'foo "v0.3.1'
echo 'foo "v0.3.2'
echo 'foo "v0.3.2'
echo 'foo "v0.3.3'
echo 'foo "v0.3.3'
echo 'foo "v0.3.4'
echo 'foo "v0.3.4'
echo 'foo "v0.3.5'
echo 'foo "v0.3.5'
echo 'foo "v0.3.6'
echo 'foo "v0.3.6'
echo 'foo "v0.3.7'
echo 'foo "v0.3.7'
echo 'foo "v0.3.8'
echo 'foo "v0.3.8'
echo 'foo "v0.4.0'
echo 'foo "v0.4.0'
echo 'foo "v0.4.1'
echo 'foo "v0.4.1'
echo 'foo "v0.4.10'
echo 'foo "v0.4.10'
echo 'foo "v0.4.11'
echo 'foo "v0.4.11'
echo 'foo "v0.4.12'
echo 'foo "v0.4.12'
echo 'foo "v0.4.2'
echo 'foo "v0.4.2'
echo 'foo "v0.4.3'
echo 'foo "v0.4.3'
echo 'foo "v0.4.4'
echo 'foo "v0.4.4'
echo 'foo "v0.4.5'
echo 'foo "v0.4.5'
echo 'foo "v0.4.6'
echo 'foo "v0.4.6'
echo 'foo "v0.4.7'
echo 'foo "v0.4.7'
echo 'foo "v0.4.8'
echo 'foo "v0.4.8'
echo 'foo "v0.4.9'
echo 'foo "v0.4.9'
echo 'foo "v0.5.0'
echo 'foo "v0.5.0'
echo 'foo "v0.6.1'
echo 'foo "v0.6.1'
echo 'foo "v0.6.10'
echo 'foo "v0.6.10'
echo 'foo "v0.6.11'
echo 'foo "v0.6.11'
echo 'foo "v0.6.12'
echo 'foo "v0.6.12'
echo 'foo "v0.6.13'
echo 'foo "v0.6.13'
echo 'foo "v0.6.2'
echo 'foo "v0.6.2'
echo 'foo "v0.6.3'
echo 'foo "v0.6.3'
echo 'foo "v0.6.4'
echo 'foo "v0.6.4'
echo 'foo "v0.6.5'
echo 'foo "v0.6.5'
echo 'foo "v0.6.6'
echo 'foo "v0.6.6'
echo 'foo "v0.6.7'
echo 'foo "v0.6.7'
echo 'foo "v0.6.8'
echo 'foo "v0.6.8'
echo 'foo "v0.6.9'
echo 'foo "v0.6.9'
}
OUTPUT="$(nvm_ls_remote foo)"
EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
OUTPUT="$(nvm_ls_remote)"
EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")"
OUTPUT="$(nvm_ls_remote 0.3)"
EXPECTED_OUTPUT="v0.3.0
v0.3.1
v0.3.2
v0.3.3
v0.3.4
v0.3.5
v0.3.6
v0.3.7
v0.3.8"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT"
# Sanity checks
OUTPUT="$(nvm_print_implicit_alias remote stable)"
EXPECTED_OUTPUT="0.10"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT"
OUTPUT="$(nvm_print_implicit_alias remote unstable)"
EXPECTED_OUTPUT="0.11"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT"
OUTPUT="$(nvm_ls_remote stable)"
EXPECTED_OUTPUT="v0.10.32"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT"
OUTPUT="$(nvm_ls_remote unstable)"
EXPECTED_OUTPUT="v0.11.14"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT"
cleanup

View File

@@ -0,0 +1,21 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args 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 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 v1.2)" = "~2" ] || die "v1.2 should give 2"
[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2"
[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3"
[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3"
[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3"

View File

@@ -0,0 +1,26 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument."
[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \
|| die "nvm_print_implicit_alias did not require local|remote as first argument"
[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \
|| die "nvm_print_implicit_alias did not require local|remote as first argument"
FIRST_EXIT_CODE="$(nvm_print_implicit_alias > /dev/null 2>&1 ; echo $?)"
[ "_$FIRST_EXIT_CODE" = "_1" ] \
|| die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $FIRST_EXIT_CODE"
EXPECTED_SECOND_MSG="Only implicit aliases 'stable' and 'unstable' are supported."
[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \
|| die "nvm_print_implicit_alias did not require stable|unstable as second argument"
[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \
|| die "nvm_print_implicit_alias did not require stable|unstable as second argument"
SECOND_EXIT_CODE="$(nvm_print_implicit_alias local > /dev/null 2>&1 ; echo $?)"
[ "_$SECOND_EXIT_CODE" = "_2" ] \
|| die "nvm_print_implicit_alias without stable|unstable had wrong exit code: expected 2, got $SECOND_EXIT_CODE"

View File

@@ -0,0 +1,47 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
rm -rf ../../../v0.2.3
rm -rf ../../../v0.3.4
rm -rf ../../../v0.4.6
rm -rf ../../../v0.5.7
rm -rf ../../../v0.7.7
unset -f nvm_ls_remote
}
. ../../../nvm.sh
mkdir ../../../v0.2.3
mkdir ../../../v0.3.4
mkdir ../../../v0.4.6
mkdir ../../../v0.5.7
mkdir ../../../v0.7.7
LATEST_STABLE="$(nvm_print_implicit_alias local stable)"
[ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE"
LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest odd minor: expected 0.7, got $LATEST_UNSTABLE"
nvm_ls_remote() {
echo "v0.4.3"
echo "v0.5.4"
echo "v0.6.6"
echo "v0.7.7"
echo "v0.9.7"
echo "v0.4.3"
echo "v0.5.4"
echo "v0.6.6"
echo "v0.7.7"
echo "v0.9.7"
}
LATEST_STABLE="$(nvm_print_implicit_alias remote stable)"
[ "_$LATEST_STABLE" = "_0.6" ] || die "remote stable is not latest even minor: expected 0.6, got $LATEST_STABLE"
LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)"
[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd minor: expected 0.9, got $LATEST_UNSTABLE"
cleanup

View File

@@ -0,0 +1,35 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_ls_remote
}
. ../../../nvm.sh
nvm_ls_remote() {
echo "N/A"
}
OUTPUT="$(nvm_remote_version foo)"
EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
nvm_ls_remote() {
echo "test output"
echo "more test output"
echo "pattern received: _$1_"
}
OUTPUT="$(nvm_remote_version foo)"
EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_pattern received: _foo_" ] \
|| die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE"
cleanup

View File

@@ -0,0 +1,19 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXPECTED_MSG="Only implicit aliases 'stable' and 'unstable' are supported."
[ "_$(nvm_validate_implicit_alias 2>&1)" = "_$EXPECTED_MSG" ] \
|| die "nvm_validate_implicit_alias did not require stable|unstable"
[ "_$(nvm_validate_implicit_alias foo 2>&1)" = "_$EXPECTED_MSG" ] \
|| die "nvm_validate_implicit_alias did not require stable|unstable"
EXIT_CODE="$(nvm_validate_implicit_alias >/dev/null 2>&1 ; echo $?)"
[ "_$EXIT_CODE" = "_1" ] \
|| die "nvm_validate_implicit_alias without stable|unstable had wrong exit code: expected 1, got $EXIT_CODE"
nvm_validate_implicit_alias stable || die "nvm_validate_implicit_alias stable did not exit 0"
nvm_validate_implicit_alias unstable || die "nvm_validate_implicit_alias unstable did not exit 0"

View File

@@ -0,0 +1,67 @@
#!/bin/sh
cleanup () {
unset -f setup cleanup die
unset _PROFILE
rm -f .bashrc .bash_profile .zshrc .profile test_profile > /dev/null 2>&1
}
die () { echo $@ ; cleanup ; exit 1; }
NVM_ENV=testing . ../../install.sh
setup () {
touch .bashrc
touch .bash_profile
touch .zshrc
touch .profile
touch test_profile
}
#Let's hack $HOME
HOME="."
setup
# $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 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"
# Below are tests for when $PROFILE is undefined
rm test_profile
unset PROFILE
# It should favor .bashrc if file exists
_PROFILE=$(nvm_detect_profile)
[ "_$_PROFILE" = "_$HOME/.bashrc" ] || 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"
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"
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"
cleanup

View File

@@ -0,0 +1,9 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
NVM_ENV=testing . ../../install.sh
#nvm_do_install is available
type nvm_do_install > /dev/null 2>&1 || die 'nvm_do_install is not available'

30
test/install_script/nvm_reset Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/sh
cleanup () {
unset -f safe_type die cleanup
}
die () { echo $@ ; cleanup ; exit 1; }
NVM_ENV=testing . ../../install.sh
safe_type() {
type "$1" > /dev/null 2>&1
}
# Check nvm_reset exists
safe_type nvm_reset || die 'nvm_reset is not available'
# Apply nvm_reset
nvm_reset
# The names should be unset
! safe_type nvm_do_install || die 'nvm_do_install is still available'
! safe_type nvm_has || die 'nvm_has is still available'
! safe_type nvm_download || die 'nvm_download is still available'
! safe_type install_nvm_as_script || die 'install_nvm_as_script is still available'
! safe_type install_nvm_from_git || die 'install_nvm_from_git is still available'
! safe_type nvm_reset || die 'nvm_reset is still available'
! safe_type nvm_detect_profile || die 'nvm_detect_profile is still available'
cleanup

40
test/install_script/nvm_source Executable file
View File

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

View File

@@ -2,13 +2,13 @@
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
. ../../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
[ -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

View File

@@ -0,0 +1,18 @@
#!/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
# Install from binary
nvm install $NVM_TEST_VERSION || die "install $NVM_TEST_VERSION failed"
# Check
[ -d ../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"

View File

@@ -0,0 +1,18 @@
#!/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
# Install from source
nvm install -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"
# Check
[ -d ../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"

View File

@@ -0,0 +1,25 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
# 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 || die "'nvm install 0.9.7' failed"
nvm i 0.9.12 || die "'nvm i 0.9.12' failed"
# Check
[ -d ../../v0.9.7 ] || die "v0.9.7 didn't exist"
[ -d ../../v0.9.12 ] || die "v0.9.12 didn't exist"
# Use the first one
nvm use 0.9.7 || die "'nvm use 0.9.7' failed"
# Use the latest one
nvm use 0.9 || die "'nvm use 0.9' failed"
node --version | grep v0.9.12 || die "'node --version' was not v0.9.12, got: $(node --version)"

View File

@@ -0,0 +1,22 @@
#!/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
# Install from binary
echo "$NVM_TEST_VERSION" > .nvmrc
nvm install || die "'nvm install' failed"
# Check
[ -d ../../$NVM_TEST_VERSION ] || die "./$NVM_TEST_VERSION did not exist"
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION \
|| "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"

View File

@@ -0,0 +1,22 @@
#!/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
# Install from binary
echo "$NVM_TEST_VERSION" > .nvmrc
nvm install -s || "'nvm install -s' failed"
# Check
[ -d ../../$NVM_TEST_VERSION ] || die "$NVM_TEST_VERSION did not exist"
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION \
|| die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"

View File

@@ -0,0 +1,34 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
# 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
# Check
[ -d ../../v0.9.7 ] || die "nvm install 0.9.7 didn't install"
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"
nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7"
nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --reinstall-packages-from=0.9 failed"
[ -d ../../v0.9.12 ] || die "nvm install 0.9.12 didn't install"
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"

View File

@@ -0,0 +1,117 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f curl wget nvm_has
}
. ../../../nvm.sh
EXPECTED_VERSION="v12.3.456"
URL="https://github.com/creationix/nvm/releases/tag/$EXPECTED_VERSION"
EXPECTED_CURL_ARGS="-w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"
EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"
curl() {
if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_CURL_ARGS), got ($*)"
return 1
else
echo $URL
fi
}
wget() {
if [ "_$*" != "_$EXPECTED_WGET_ARGS" ]; then
echo 2>& "expected args ($EXPECTED_WGET_ARGS), got ($*)"
return 1
else
local WGET_CONTENTS
WGET_CONTENTS="
--2014-12-21 18:11:14-- http://latest.nvm.sh/
Resolving latest.nvm.sh... 50.31.209.229
Connecting to latest.nvm.sh|50.31.209.229|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Location: https://github.com/creationix/nvm/releases/latest
Content-Type: text/html; charset=utf-8
Content-Length: 84
Date: Mon, 22 Dec 2014 02:11:15 GMT
Location: https://github.com/creationix/nvm/releases/latest [following]
--2014-12-21 18:11:15-- https://github.com/creationix/nvm/releases/latest
Resolving github.com... 192.30.252.130
Connecting to github.com|192.30.252.130|:443... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Server: GitHub.com
Date: Mon, 22 Dec 2014 02:11:15 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Status: 302 Found
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com
Cache-Control: no-cache
Vary: X-PJAX
Location: $URL
X-UA-Compatible: IE=Edge,chrome=1
Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Fri, 22-Dec-2034 02:11:15 GMT; secure; HttpOnly
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzV9--e2fa4cf5305d61aa58c0e0bf21fdb335a9660dcf; path=/; secure; HttpOnly
X-Request-Id: 4b99bf200157dd845f76ab83e4093acc
X-Runtime: 0.030872
X-Rack-Cache: miss
X-GitHub-Request-Id: 45B56780:3913:880EF6:54977DC3
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
X-Served-By: ef97014f01ea59c1ef337fe51a4d0331
Location: $URL [following]
--2014-12-21 18:11:15-- $URL
Reusing existing connection to github.com:443.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: GitHub.com
Date: Mon, 22 Dec 2014 02:11:15 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Status: 200 OK
X-XSS-Protection: 1; mode=block
X-Frame-Options: deny
Content-Security-Policy: default-src *; script-src assets-cdn.github.com collector-cdn.github.com; object-src assets-cdn.github.com; style-src 'self' 'unsafe-inline' 'unsafe-eval' assets-cdn.github.com; img-src 'self' data: assets-cdn.github.com identicons.github.com www.google-analytics.com collector.githubapp.com *.githubusercontent.com *.gravatar.com *.wp.com; media-src 'none'; frame-src 'self' render.githubusercontent.com gist.github.com www.youtube.com player.vimeo.com checkout.paypal.com; font-src assets-cdn.github.com; connect-src 'self' ghconduit.com:25035 live.github.com uploads.github.com www.google-analytics.com s3.amazonaws.com
Cache-Control: no-cache, private
Vary: X-PJAX
X-UA-Compatible: IE=Edge,chrome=1
Set-Cookie: _gh_sess=eyJzZXNzaW9uX2lkIjoiNTMzNGNjZWUxM2VhZjNhN2M3MzIwZWUxNGYwNzhmNDkiLCJzcHlfcmVwbyI6ImNyZWF0aW9uaXgvbnZtIiwic3B5X3JlcG9fYXQiOjE0MTkyMTQyNzUsIl9jc3JmX3Rva2VuIjoiemZTVDNIRGo0QzF0dzkyNXp6NFBRdGJVbTl4NSsxTGo1cngwVFQ3NDVwdz0ifQ%3D%3D--b72bfd5241907dcf557b226e74351ff39f0e9ede; path=/; secure; HttpOnly
X-Request-Id: 305b0d158bf8c0b3fa488a33d7687091
X-Runtime: 0.038544
X-Rack-Cache: miss
X-GitHub-Request-Id: 45B56780:3913:880F19:54977DC3
Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
X-Content-Type-Options: nosniff
Vary: Accept-Encoding
X-Served-By: 926b734ea1992f8ee1f88ab967a93dac
Length: unspecified [text/html]
Saving to: /dev/null
0K .......... ......... 225K=0.09s
2014-12-21 18:11:15 (225 KB/s) - /dev/null saved [20298]
"
"$WGET_CONTENTS" | while read line
do
2>& echo "$line"
done
fi
}
OUTPUT="$(nvm_get_latest)"
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_VERSION" ] \
|| die "success path did not return version '$EXPECTED_VERSION', got '$OUTPUT'"
[ "_$EXIT_CODE" = "_0" ] \
|| die "success path did not exit with code 0, got $EXIT_CODE"
cleanup

View File

@@ -0,0 +1,26 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f curl wget
}
. ../../../nvm.sh
curl() {
return 1
}
wget() {
return 1
}
OUTPUT="$(nvm_get_latest 2>&1)"
EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_http://latest.nvm.sh did not redirect to the latest release on Github" ] \
|| die "failed redirect did not report correct error message, got '$OUTPUT'"
[ "_$EXIT_CODE" = "_2" ] \
|| die "failed redirect did not exit with code 2, got $EXIT_CODE"
cleanup

View File

@@ -1,6 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
. ../../nvm.sh
nvm deactivate
nvm uninstall v0.10.7
if [ -f ".nvmrc" ]; then

View File

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

View File

@@ -1,6 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
nvm deactivate
nvm uninstall v0.10.7
nvm uninstall v0.11.7

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -e
. ../../../nvm.sh
NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering.
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install from binary
nvm install $NVM_TEST_VERSION
# Check
[ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION

View File

@@ -1,17 +0,0 @@
#!/bin/sh
set -e
. ../../../nvm.sh
NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering.
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install from source
nvm install -s $NVM_TEST_VERSION
# Check
[ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION

View File

@@ -1,24 +0,0 @@
#!/bin/sh
set -e
. ../../../nvm.sh
# 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 i 0.9.12
# Check
[ -d ../../../v0.9.7 ]
[ -d ../../../v0.9.12 ]
# Use the first one
nvm use 0.9.7
# Use the latest one
nvm use 0.9
node --version | grep v0.9.12

View File

@@ -1,20 +0,0 @@
#!/bin/sh
set -e
. ../../../nvm.sh
NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering.
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install from binary
cat "$NVM_TEST_VERSION" > .nvmrc
nvm install
# Check
[ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION

View File

@@ -1,20 +0,0 @@
#!/bin/sh
set -e
. ../../../nvm.sh
NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering.
[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION
# Install from binary
cat "$NVM_TEST_VERSION" > .nvmrc
nvm install -s
# Check
[ -d ../../../$NVM_TEST_VERSION ]
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
nvm deactivate
nvm uninstall v0.10.7
rm .nvmrc

View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
echo '0.10.1' > ../../alias/default || die 'creation of default alias failed'
. ../../nvm.sh || die 'sourcing returned nonzero exit code'
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.1)"
[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT'"
# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
NVM_ALIAS_DEFAULT="$(nvm alias default)"
[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \
|| die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'"

12
test/sourcing/setup Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
mkdir -p ../../alias
rm -f ../../.nvmrc
rm -rf ../../v0.10.7
rm -rf ../../v0.9.7
rm -rf ../../v0.9.12
. ../../nvm.sh
nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed'
nvm unload || echo >&2 'nvm unload failed'

7
test/sourcing/teardown Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
rm -rf ../../alias
rm -rf ../../v0.10.1
rm -rf ../../v0.10.2
rm -f ../../.nvmrc