Compare commits

...

54 Commits

Author SHA1 Message Date
Jordan Harband
4054bd70ce v0.37.0 2020-11-06 10:11:29 -08:00
Jordan Harband
499d303746 [Perf] use/nvm_die_on_prefix: replicate npm config algorithm and remove npm config call 2020-08-24 22:44:25 -07:00
Peter Dave Hello
31bc0a13c2 [Dockerfile] Clean up dated comment 2020-11-03 17:19:03 +08:00
Dena Burd
c72f2c6f21 [Fix] nvm ls-remote: accept versions that end with a dot
Fixes #983.
2020-09-24 13:46:29 -07:00
Alex Aubuchon
f2c5ce459a [Tests] Fix nvm unload fast test cleanup 2020-10-22 20:43:36 -07:00
Jordan Harband
0f0d5e8270 [dev deps] alphabetize dependencies 2020-10-22 20:41:45 -07:00
Alex Aubuchon
e77ed07ccc [Tests] Fix nvm_ls_current fast test 2020-10-13 12:32:41 -04:00
Dylan Armstrong
e01060fa2c [Fix] nvm_die_on_prefix: use directory comparison rather than string 2020-10-09 09:43:21 -05:00
Dylan Armstrong
96069da0d5 [Fix] nvm_ls: zsh: unset markdirs and local_options
Fixes #2315.
2020-10-09 09:43:21 -05:00
Peter Dave Hello
4436638816 [Tests] Drop deprecated sudo: option in TravisCI config
That config was deprecated for a while, reference:
- https://blog.travis-ci.com/2018-10-04-combining-linux-infrastructures
2020-09-21 20:28:09 +08:00
Matthieu Bosquet
344cc32ac3 [readme] bash shell integration: Amended example to call cd when booting a terminal (previously only called on cd).
It means that works with for example VS Code's integrated terminal.
2020-10-05 17:30:03 +01:00
Jordan Harband
7929190e6e [Docs] improve nvm --help output
Fixes #2301
2020-10-02 22:22:12 -07:00
Jordan Harband
8debf39f24 v0.36.0 2020-09-23 16:18:37 -07:00
Jordan Harband
c7ca08d575 [Fix] latest-npm: ensure npm 7 is not installed on node < 10 2020-09-23 14:50:33 -07:00
Peter Dave Hello
6110d31969 [dockerfile] Add missing apt pacakge locales
locale-gen command seems missing since uncertain point for a while:

```
Step 15/33 : RUN locale-gen en_US.UTF-8
 ---> Running in fae073c89c01
 /bin/bash: locale-gen: command not found
 The command '/bin/bash -o pipefail -c locale-gen en_US.UTF-8' returned
 a non-zero code: 127
```

This patch should fix the Docker image build
2020-09-21 18:20:50 +08:00
Peter Dave Hello
68d2f47c0a [dockerfile] Update ShellCheck download URL in Dockerfile
see koalaman/shellcheck#1871
2020-09-21 09:36:30 +08:00
Jordan Harband
6e0562ac6d [Tests] pin postcss to v7 2020-09-21 15:40:41 -07:00
Peter Dave Hello
68d331a816 [dockerfile] Remove ShellCheck Segmentation fault workaround
The workaround came from this GitHub issue comment:
https://github.com/koalaman/shellcheck/issues/1053#issuecomment-357816927

Looks like the problem doesn't exist any more:

```
.
.
.
Step 14/33 : RUN shellcheck -V
 ---> Running in 4b7a718c1cbf
ShellCheck - shell script analysis tool
version: 0.7.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
.
.
.
```

The workaround should be removed so that the Dockerfile will be easier
to be understand and read.
2020-09-21 02:47:57 +08:00
Saikat Das
22e07cc0c1 [readme] fix LTS upgrade command
Edited the LTS upgrade scenario command to fix the issue discussed in #2271
2020-08-27 19:27:29 +05:30
Jordan Harband
cf92956e5d [New] add nvm_find_project_dir helper 2020-08-23 14:40:42 -07:00
Jordan Harband
1d88ecfce5 [Fix] nvm_die_on_prefix: check that the prefix is inside the version dir, not just the nvm dir
- also pass the version dir as the third argument
2020-08-23 22:50:41 -07:00
Jordan Harband
035bf9e28e [readme] update autocompletion output examples 2020-08-23 23:29:48 -07:00
Michael Potter
f7fbad2bd6 [performance] nvm_auto: only call nvm_ls_current in use mode 2020-08-19 11:40:45 -07:00
Steve Lee
19c55b9936 [readme] Mention problem with windows cmd echo 2020-08-11 18:39:32 +01:00
Jordan Harband
9dc6f3e4a5 [Refactor] nvm run/nvm exec: use NVM_SILENT consistently internally 2020-08-13 14:37:41 -07:00
Jordan Harband
1c00753fd9 [New] nvm deactivate/nvm which: add --silent 2020-08-13 13:40:32 -07:00
Yash-Singh1
b1200c659b [Fix] nvm use: fix --silent when version is omitted
Fixed a bug where --silent mode was failing for nvm use I ran a test
 that just ran ```nvm use node --silent``` that I wrote by myself.
 Unfortunately I noticed a bug where it still prints out some messages in
 different cases. This pull request is to fix that bug. * Added in an argument
 called ***quiet***  to the nvm_rc_version() function at *line 339* * Printed
 anything inside the nvm_rc_version() only in the scenario where quiet mode is
 off * Ran the nvm_rc_version() function in quiet mode only if silent mode is
 on in the "use" command of nvm at *line 2990* * Ran *nvm_echo* and *nvm_err*
 inside the "use" command of nvm only in the scenario where silent mode is off
 (There were 4 scenarios where this was forgotten) * Edited the ```nvm
 deactivate``` command to include a silent mode * Changed the help page to
 include the --silent option for ```nvm deactivate``` * Added in aliases for
 the --silent flag in ```nvm deactivate``` and ```nvm use``` * Used silent
 mode inside the ```nvm use``` when running ```nvm deactivate``` inside it and
 silent mode is on A test was attached in the 'test/slow/nvm use' directory.
 It is named *Running "nvm use node --silent" doesn't print anything*. It runs
 ```nvm use node --silent and checks``` and succeeds if the OUTPUT matches the
 EXPECTED_OUTPUT which is *null*  or *''*. When the test was run locally, it
 still ouputed results if someone deleted some contents of the *.nvm/* folder.
 This output was given from the ```nvm deactivate command```. This was the
 reason that the ```nvm deactivate``` was edited to include silent mode.
2020-08-08 17:27:46 -07:00
Jordan Harband
16b75b7333 [Robustness] add command to xargs/rm in nvm_get_default_packages
Fixes #2281.
2020-08-11 10:16:42 -07:00
Naomi Quinones
1bf567bd0b [Fix] ensure --help is intercepted on any command
Co-authored-by: Naomi Quinones <52065567+naomiquinones@users.noreply.github.com>
Co-authored-by: Dena Burd <me@Denas-MacBook-Air.local>
2020-08-04 16:32:19 -07:00
Dimitris Karagiannis
a01deb11dc [patch] Update docs and add warning for 'nvm is not compatible with the npm config "prefix" option' edgecase error on Mac OS 2020-08-03 10:04:20 -07:00
Kayla Altepeter
a5aec107df [New] adding default and alias option to nvm install
For: `nvm install 8.12.0` after install:

--alias=8 is equivalent to `nvm alias 8 8.12.0`
--default is equivalent to `nvm alias default 8.12.0`

Co-authored-by: Kayla Altepeter <kayla@kaylaaltepeter.com>
Co-authored-by: Dena Burd <me@Denas-MacBook-Air.local>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2018-10-22 08:32:29 -05:00
Saikat Das
18c6f98acc [readme] Add documentation for LTS updates which reinstall existing packages
Added an example for LTS updates that also reinstall the existing packages.
This is useful for individuals who run the latest LTS version along with global packages and need to update when the LTS version gets bumped
2020-07-28 19:31:30 +05:30
Jordan Harband
424aeb38b4 [Refactor] add nvm_get_checksum_binary; use it in nvm debug 2020-07-31 22:13:21 -07:00
Jordan Harband
abfe0a5891 [Refactor] remove unused nvm_checksum function 2020-07-31 22:10:28 -07:00
Naomi Quinones
3561bbc54a [Fix] --help: Add more examples
Fixes #2120.
2020-07-28 17:56:48 -07:00
Jordan Harband
83043c4d3a [debug] add whoami output 2020-07-25 13:38:52 -07:00
Dena Burd
55eafcd814 [New] add nvm -v as an alias for nvm --version
Fixes #2200.
2020-07-27 10:26:35 -07:00
ritmos
06c3bf6a8f [Docs] --help: explain more clearly that <version> parameter is optional and can be provided by .nvmrc on nvm install, nvm use, nvm exec, and nvm run. 2020-06-20 15:15:01 +02:00
DeeDeeG
4b1100e515 [New] nvm_supports_xz: Add Mac/FreeBSD xz platform support checks
macOS only supports extracting xz tarballs with `tar` in 10.9 and up.

GNU tar needs an `xz` executable on the `PATH` to extract xz tarballs.

(These are the most common variants of tar, so until further testing
is done, conservatively assume all variants of tar (other than the one
shipped with macOS) need an xz executable on the PATH in order to
decompress xz tarballs.)

Fixes #2155.
2020-01-29 16:20:15 -05:00
Bram Wubs
f6d11bae41 [readme] Fix fish load_nvm function 2020-07-07 08:29:00 +02:00
Marcus Kazmierczak
d2d232ea2b [readme] Update macOS troubleshooting w/ 10.15 zsh default
The default shell for macOS 10.15 is now zsh, by default a .zshrc file
is not created, so switch instruction for touch ~/.zshrc
2020-06-24 11:02:01 -07:00
Connor Leech
7b3af45cf7 [readme] Update install instructions troubleshooting
This is in response to a popular stack overflow answer that has helped people resolve the "command not found" hiccup: https://stackoverflow.com/a/17707224/2031033

Also mentioned here: https://github.com/nvm-sh/nvm/issues/748
2020-05-25 07:36:40 -07:00
Peter Dave Hello
bac5393e12 [Docs] Syntax highlight for Ansible task example in README.md 2020-05-29 21:01:47 +08:00
Szymon Dzialowski
2d4e877b61 [readme] Stop removing spaces from nvm_path
It breaks switching version of node through nvm in directories with space somewhere in it's path.
2020-06-10 18:28:14 +01:00
Jordan Harband
6575b6b052 [Fix] install: improved arg parsing around --reinstall-packages-from
Fixes #1762
2020-06-04 16:15:39 -07:00
Bruce A. MacNaughton
33fa27dabe [Docs] Update README for environment variables 2020-02-07 12:01:57 -08:00
Sehrope Sarkuni
91a55dd91a [Refactor] Rename solaris and iojs helper functions to be nvm_ prefixed
Renames node_version_has_solaris_binary and nvm_iojs_version_has_solaris_binary
to be prefixed with nvm_ so they do not show up in tab completion following the
word "node".
2020-05-08 16:08:27 -04:00
Jordan Harband
7aba64a2d5 [meta] further TOC action tweaks 2020-04-29 20:18:40 -07:00
Jared Ramirez
dcc8059ef8 [readme] include deeper integration instructions for fish 2020-04-29 15:25:23 -07:00
Jordan Harband
8e1e5df059 [meta] fix TOC action 2020-04-29 15:13:30 -07:00
Jordan Harband
e0ed1eacfd [meta] add actions: Automatic Rebase for PRs, auto-update-TOC for push 2020-04-29 12:06:01 -07:00
Peter Dave Hello
73438e339e Update Dockerfile base image to Ubuntu 16.04, cc #2008 2020-03-30 02:17:28 +08:00
Magnus Markling
b02617028f [Tests] Source nvm.sh before defining FILE 2020-03-19 12:13:29 +01:00
Jordan Harband
f607f2f783 [Fix] reinstall-packages: do not include unmet peer deps
Closes #1948.
2020-03-10 23:51:17 -07:00
42 changed files with 949 additions and 372 deletions

View File

@@ -18,5 +18,11 @@ indent_size = false
[test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
indent_size = false
[test/fast/Unit tests/mocks/**]
insert_final_newline = off
[test/**/.urchin*]
insert_final_newline = off
[Makefile]
indent_style = tab

15
.github/workflows/rebase.yml vendored Normal file
View File

@@ -0,0 +1,15 @@
name: Automatic Rebase
on: [pull_request]
jobs:
_:
name: "Automatic Rebase"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

29
.github/workflows/toc.yml vendored Normal file
View File

@@ -0,0 +1,29 @@
name: update readme TOC
on: [push]
jobs:
_:
name: "update readme TOC"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# https://github.com/actions/checkout/issues/217#issue-599945005
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
# pulls all tags (needed for lerna / semantic release to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install
- run: npm run doctoc
- name: commit changes
uses: ljharb/actions-js-build/commit@v3+amendpush
with:
amend: true
force: true

View File

@@ -1,6 +1,5 @@
language: generic
dist: xenial
sudo: required
addons:
apt:
packages:

View File

@@ -6,9 +6,7 @@
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
# build this image, it depends on your hardware.
# Use Ubuntu Trusty Tahr as base image as we're using on Travis CI
# I also tested with Ubuntu 16.04, should be good with it!
FROM ubuntu:14.04
FROM ubuntu:16.04
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
LABEL name="nvm-dev-env"
LABEL version="latest"
@@ -20,7 +18,7 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
ENV DEBIAN_FRONTEND noninteractive
# ShellCheck version
ENV SHELLCHECK_VERSION=0.6.0
ENV SHELLCHECK_VERSION=0.7.0
# Pick a Ubuntu apt mirror site for better speed
# ref: https://launchpad.net/ubuntu/+archivemirrors
@@ -43,6 +41,7 @@ RUN apt update && \
file \
openssl \
libssl-dev \
locales \
ca-certificates \
ssh \
wget \
@@ -65,14 +64,11 @@ RUN apt update && \
bash-completion && \
apt-get clean
# ShellCheck with Ubuntu 14.04 container workaround
RUN wget https://storage.googleapis.com/shellcheck/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
rmdir shellcheck-v$SHELLCHECK_VERSION && \
touch /tmp/libc.so.6 && \
echo "alias shellcheck='LD_LIBRARY_PATH=/tmp /bin/shellcheck'" >> /etc/bash.bashrc
RUN LD_LIBRARY_PATH=/tmp shellcheck -V
rmdir shellcheck-v$SHELLCHECK_VERSION
RUN shellcheck -V
# Set locale
RUN locale-gen en_US.UTF-8

114
README.md
View File

@@ -1,4 +1,4 @@
# Node Version Manager [![Build Status](https://travis-ci.org/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.35.3-yellow.svg)][4] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684)
# Node Version Manager [![Build Status](https://travis-ci.org/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.37.0-yellow.svg)][4] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684)
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -31,8 +31,11 @@
- [Automatically call `nvm use`](#automatically-call-nvm-use)
- [zsh](#zsh)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
- [fish](#fish)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file-1)
- [License](#license)
- [Running Tests](#running-tests)
- [Environment variables](#environment-variables)
- [Bash Completion](#bash-completion)
- [Usage](#usage-1)
- [Compatibility Issues](#compatibility-issues)
@@ -56,10 +59,10 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
```
```sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
```
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
@@ -91,9 +94,11 @@ Since OS X 10.9, `/usr/bin/git` has been preset by Xcode command line tools, whi
If you get `nvm: command not found` after running the install script, one of the following might be the reason:
- Your system may not have a `.bash_profile` file where the command is set up. Create one with `touch ~/.bash_profile` and run the install script again
- Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again.
- You might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.
- If you use bash, the previous default shell, run `touch ~/.bash_profile` to create the necessary profile file if it does not exist.
- You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
If the above doesn't fix the problem, you may try the following:
@@ -107,10 +112,10 @@ If the above doesn't fix the problem, you may try the following:
You can use a task:
```
```yaml
- name: nvm
shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
```
@@ -169,7 +174,7 @@ If you have `git` installed (requires git v1.7.10+):
1. clone this repo in the root of your user profile
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.35.3`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.37.0`
1. activate `nvm` by sourcing it from your shell: `. nvm.sh`
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
@@ -285,6 +290,12 @@ Node has a [schedule](https://github.com/nodejs/Release#release-schedule) for lo
Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
To get the latest LTS version of node and migrate your existing installed packages, use
```sh
nvm install 'lts/*' --reinstall-packages-from=current
```
### Migrating Global Packages While Installing
If you want to install a new version of Node.js and migrate npm packages from a previous version:
@@ -425,6 +436,8 @@ $ echo "lts/*" > .nvmrc # to default to the latest LTS version
$ echo "node" > .nvmrc # to default to the latest version
```
[NB these examples assume a POSIX-compliant shell version of `echo`. If you use a Windows `cmd` development environment, eg the `.nvmrc` file is used to configure a remote Linux deployment, then keep in mind the `"`s will be copied leading to an invalid file. Remove them.]
Then when you run nvm:
```sh
@@ -460,7 +473,7 @@ find-up () {
cdnvm() {
cd "$@";
nvm_path=$(find-up .nvmrc | tr -d '[:space:]')
nvm_path=$(find-up .nvmrc | tr -d '\n')
# If there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
@@ -501,6 +514,7 @@ cdnvm(){
fi
}
alias cd='cdnvm'
cd $PWD
```
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
@@ -536,6 +550,45 @@ add-zsh-hook chpwd load-nvmrc
load-nvmrc
```
#### fish
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
This requires that you have [bass](https://github.com/edc/bass) installed.
```fish
# ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
# ~/.config/fish/functions/nvm_find_nvmrc.fish
function nvm_find_nvmrc
bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc
end
# ~/.config/fish/functions/load_nvm.fish
function load_nvm --on-variable="PWD"
set -l default_node_version (nvm version default)
set -l node_version (nvm version)
set -l nvmrc_path (nvm_find_nvmrc)
if test -n "$nvmrc_path"
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
if test "$nvmrc_node_version" = "N/A"
nvm install (cat $nvmrc_path)
else if test nvmrc_node_version != node_version
nvm use $nvmrc_node_version
end
else if test "$node_version" != "$default_node_version"
echo "Reverting to default Node version"
nvm use default
end
end
# ~/.config/fish/config.fish
# You must call it on initialization or listening to directory switching won't work
load_nvm
```
## License
nvm is released under the MIT license.
@@ -572,6 +625,19 @@ Run all of the tests like this:
Nota bene: Avoid running nvm while the tests are running.
## Environment variables
nvm exposes the following environment variables:
- `NVM_DIR` - nvm's installation directory.
- `NVM_BIN` - where node, npm, and global packages for the active version of node are installed.
- `NVM_INC` - node's include file directory (useful for building C/C++ addons for node).
- `NVM_CD_FLAGS` - used to maintain compatibility with zsh.
- `NVM_RC_VERSION` - version from .nvmrc file if being used.
Additionally, nvm modifies `PATH`, and, if present, `MANPATH` and `NODE_PATH` when changing versions.
## Bash Completion
To activate, you need to source `bash_completion`:
@@ -588,36 +654,36 @@ nvm:
> $ nvm <kbd>Tab</kbd>
```
alias deactivate install ls run unload
clear-cache exec list ls-remote unalias use
current help list-remote reinstall-packages uninstall version
alias deactivate install list-remote reinstall-packages uninstall version
cache exec install-latest-npm ls run unload version-remote
current help list ls-remote unalias use which
```
nvm alias:
> $ nvm alias <kbd>Tab</kbd>
```
default
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
```
> $ nvm alias my_alias <kbd>Tab</kbd>
```
v0.6.21 v0.8.26 v0.10.28
v10.22.0 v12.18.3 v14.8.0
```
nvm use:
> $ nvm use <kbd>Tab</kbd>
```
my_alias default v0.6.21 v0.8.26 v0.10.28
my_alias default v10.22.0 v12.18.3 v14.8.0
```
nvm uninstall:
> $ nvm uninstall <kbd>Tab</kbd>
```
my_alias default v0.6.21 v0.8.26 v0.10.28
my_alias default v10.22.0 v12.18.3 v14.8.0
```
## Compatibility Issues
@@ -656,7 +722,7 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
```
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
@@ -742,9 +808,19 @@ sudo chmod ugo-x /usr/libexec/path_helper
More on this issue in [dotphiles/dotzsh](https://github.com/dotphiles/dotzsh#mac-os-x).
**nvm is not compatible with the npm config "prefix" option**
Some solutions for this issue can be found [here](https://github.com/nvm-sh/nvm/issues/1245)
There is one more edge case causing this issue, and that's a **mismatch between the `$HOME` path and the user's home directory's actual name**.
You have to make sure that the user directory name in `$HOME` and the user directory name you'd see from running `ls /Users/` **are capitalized the same way** ([See this issue](https://github.com/nvm-sh/nvm/issues/2261)).
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
[1]: https://github.com/nvm-sh/nvm.git
[2]: https://github.com/nvm-sh/nvm/blob/v0.35.3/install.sh
[2]: https://github.com/nvm-sh/nvm/blob/v0.37.0/install.sh
[3]: https://travis-ci.org/nvm-sh/nvm
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.35.3
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.0
[Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com

View File

@@ -19,7 +19,7 @@ nvm_install_dir() {
}
nvm_latest_version() {
echo "v0.35.3"
echo "v0.37.0"
}
nvm_profile_is_bash_or_zsh() {

525
nvm.sh
View File

@@ -243,6 +243,12 @@ nvm_install_latest_npm() {
fi
fi
local NVM_IS_10_OR_ABOVE
NVM_IS_10_OR_ABOVE=0
if [ $NVM_IS_9_3_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 10.0.0; then
NVM_IS_10_OR_ABOVE=1
fi
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
}; then
@@ -260,6 +266,9 @@ nvm_install_latest_npm() {
; then
nvm_echo '* `npm` `v6.9` is the last version that works on `node` `v6.0.x`, `v6.1.x`, `v9.0.x`, `v9.1.x`, or `v9.2.x`'
$NVM_NPM_CMD install -g npm@6.9
elif [ $NVM_IS_10_OR_ABOVE -eq 0 ]; then
nvm_echo '* `npm` `v6.x` is the last version that works on `node` below `v10.0.0`'
$NVM_NPM_CMD install -g npm@6
else
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
$NVM_NPM_CMD install -g npm
@@ -317,6 +326,15 @@ nvm_tree_contains_path() {
[ "${pathdir}" = "${tree}" ]
}
nvm_find_project_dir() {
local path_
path_="${PWD}"
while [ "${path_}" != "" ] && [ ! -f "${path_}/package.json" ] && [ ! -d "${path_}/node_modules" ]; do
path_=${path_%/*}
done
nvm_echo "${path_}"
}
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path_
@@ -341,15 +359,21 @@ nvm_rc_version() {
local NVMRC_PATH
NVMRC_PATH="$(nvm_find_nvmrc)"
if [ ! -e "${NVMRC_PATH}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "No .nvmrc file found"
fi
return 1
fi
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
if [ -z "${NVM_RC_VERSION}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Warning: empty .nvmrc file found at \"${NVMRC_PATH}\""
fi
return 2
fi
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
fi
}
nvm_clang_version() {
@@ -1065,6 +1089,7 @@ nvm_ls() {
esac
nvm_is_zsh && setopt local_options shwordsplit
nvm_is_zsh && unsetopt local_options markdirs
local NVM_DIRS_TO_SEARCH1
NVM_DIRS_TO_SEARCH1=''
@@ -1215,6 +1240,10 @@ nvm_ls_remote_index_tab() {
local PATTERN
PATTERN="${3-}"
if [ "${PATTERN#"${PATTERN%?}"}" = '.' ]; then
PATTERN="${PATTERN%.}"
fi
local VERSIONS
if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
if [ "${FLAVOR}" = 'iojs' ]; then
@@ -1286,32 +1315,47 @@ EOF
nvm_echo "${VERSIONS}"
}
nvm_get_checksum_alg() {
if nvm_has_non_aliased "sha256sum"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "shasum"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "sha256"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "gsha256sum"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "openssl"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "bssl"; then
nvm_echo 'sha-256'
elif nvm_has_non_aliased "sha1sum"; then
nvm_echo 'sha-1'
elif nvm_has_non_aliased "sha1"; then
nvm_echo 'sha-1'
elif nvm_has_non_aliased "shasum"; then
nvm_echo 'sha-1'
nvm_get_checksum_binary() {
if nvm_has_non_aliased 'sha256sum'; then
nvm_echo 'sha256sum'
elif nvm_has_non_aliased 'shasum'; then
nvm_echo 'shasum'
elif nvm_has_non_aliased 'sha256'; then
nvm_echo 'sha256'
elif nvm_has_non_aliased 'gsha256sum'; then
nvm_echo 'gsha256sum'
elif nvm_has_non_aliased 'openssl'; then
nvm_echo 'openssl'
elif nvm_has_non_aliased 'bssl'; then
nvm_echo 'bssl'
elif nvm_has_non_aliased 'sha1sum'; then
nvm_echo 'sha1sum'
elif nvm_has_non_aliased 'sha1'; then
nvm_echo 'sha1'
else
nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.'
nvm_err 'Unaliased sha1sum, sha1, or shasum not found.'
nvm_err 'Unaliased sha1sum or sha1 not found.'
return 1
fi
}
nvm_get_checksum_alg() {
local NVM_CHECKSUM_BIN
NVM_CHECKSUM_BIN="$(nvm_get_checksum_binary 2>/dev/null)"
case "${NVM_CHECKSUM_BIN-}" in
sha256sum | shasum | sha256 | gsha256sum | openssl | bssl)
nvm_echo 'sha-256'
;;
sha1sum | sha1)
nvm_echo 'sha-1'
;;
*)
nvm_get_checksum_binary
return $?
;;
esac
}
nvm_compute_checksum() {
local FILE
FILE="${1-}"
@@ -1347,9 +1391,6 @@ nvm_compute_checksum() {
elif nvm_has_non_aliased "sha1"; then
nvm_err 'Computing checksum with sha1 -q'
command sha1 -q "${FILE}"
elif nvm_has_non_aliased "shasum"; then
nvm_err 'Computing checksum with shasum'
command shasum "${FILE}" | command awk '{print $1}'
fi
}
@@ -1412,49 +1453,6 @@ nvm_get_checksum() {
nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.tar.${5}\" == \$2) print \$1}"
}
nvm_checksum() {
local NVM_CHECKSUM
if [ -z "${3-}" ] || [ "${3-}" = 'sha1' ]; then
if nvm_has_non_aliased "sha1sum"; then
NVM_CHECKSUM="$(command sha1sum "${1-}" | command awk '{print $1}')"
elif nvm_has_non_aliased "sha1"; then
NVM_CHECKSUM="$(command sha1 -q "${1-}")"
elif nvm_has_non_aliased "shasum"; then
NVM_CHECKSUM="$(command shasum "${1-}" | command awk '{print $1}')"
else
nvm_err 'Unaliased sha1sum, sha1, or shasum not found.'
return 2
fi
else
if nvm_has_non_aliased "sha256sum"; then
NVM_CHECKSUM="$(command sha256sum "${1-}" | command awk '{print $1}')"
elif nvm_has_non_aliased "shasum"; then
NVM_CHECKSUM="$(command shasum -a 256 "${1-}" | command awk '{print $1}')"
elif nvm_has_non_aliased "sha256"; then
NVM_CHECKSUM="$(command sha256 -q "${1-}" | command awk '{print $1}')"
elif nvm_has_non_aliased "gsha256sum"; then
NVM_CHECKSUM="$(command gsha256sum "${1-}" | command awk '{print $1}')"
elif nvm_has_non_aliased "openssl"; then
NVM_CHECKSUM="$(command openssl dgst -sha256 "${1-}" | command awk '{print $NF}')"
elif nvm_has_non_aliased "bssl"; then
NVM_CHECKSUM="$(command bssl sha256sum "${1-}" | command awk '{print $1}')"
else
nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.'
nvm_err 'WARNING: Continuing *without checksum verification*'
return
fi
fi
if [ "_${NVM_CHECKSUM}" = "_${2-}" ]; then
return
elif [ -z "${2-}" ]; then
nvm_echo 'Checksums empty' #missing in raspberry pi binary
return
fi
nvm_err 'Checksums do not match.'
return 1
}
nvm_print_versions() {
local VERSION
local LTS
@@ -1802,6 +1800,10 @@ nvm_install_binary() {
command mv "${TMPDIR}/"* "${VERSION_PATH}" && \
command rm -rf "${TMPDIR}"
); then
if [ -n "${ALIAS-}" ]; then
nvm alias "${ALIAS}" "${provided_version}"
fi
return 0
fi
@@ -2167,7 +2169,7 @@ nvm_npm_global_modules() {
local NPMLIST
local VERSION
VERSION="$1"
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d)
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')
local INSTALLS
INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)
@@ -2178,9 +2180,18 @@ nvm_npm_global_modules() {
nvm_echo "${INSTALLS} //// ${LINKS}"
}
nvm_npmrc_bad_news_bears() {
local NVM_NPMRC
NVM_NPMRC="${1-}"
if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
return 0
fi
return 1
}
nvm_die_on_prefix() {
local NVM_DELETE_PREFIX
NVM_DELETE_PREFIX="$1"
NVM_DELETE_PREFIX="${1-}"
case "${NVM_DELETE_PREFIX}" in
0 | 1) ;;
*)
@@ -2189,9 +2200,11 @@ nvm_die_on_prefix() {
;;
esac
local NVM_COMMAND
NVM_COMMAND="$2"
if [ -z "${NVM_COMMAND}" ]; then
nvm_err 'Second argument "nvm command" must be nonempty'
NVM_COMMAND="${2-}"
local NVM_VERSION_DIR
NVM_VERSION_DIR="${3-}"
if [ -z "${NVM_COMMAND}" ] || [ -z "${NVM_VERSION_DIR}" ]; then
nvm_err 'Second argument "nvm command", and third argument "nvm version dir", must both be nonempty'
return 2
fi
@@ -2223,23 +2236,70 @@ nvm_die_on_prefix() {
fi
fi
if ! nvm_has 'npm'; then
return
# here, npm config checks npmrc files.
# the stack is: cli, env, project, user, global, builtin, defaults
# cli does not apply; env is covered above, defaults don't exist for prefix
# there are 4 npmrc locations to check: project, global, user, and builtin
# project: find the closest node_modules or package.json-containing dir, `.npmrc`
# global: default prefix + `/etc/npmrc`
# user: $HOME/.npmrc
# builtin: npm install location, `npmrc`
#
# if any of them have a `prefix`, fail.
# if any have `globalconfig`, fail also, just in case, to avoid spidering configs.
local NVM_NPM_BUILTIN_NPMRC
NVM_NPM_BUILTIN_NPMRC="${NVM_VERSION_DIR}/lib/node_modules/npm/npmrc"
if nvm_npmrc_bad_news_bears "${NVM_NPM_BUILTIN_NPMRC}"; then
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
else
nvm_err "Your builtin npmrc file ($(nvm_sanitize_path "${NVM_NPM_BUILTIN_NPMRC}"))"
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
return 10
fi
fi
local NVM_NPM_PREFIX
NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
if ! (nvm_tree_contains_path "${NVM_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then
local NVM_NPM_GLOBAL_NPMRC
NVM_NPM_GLOBAL_NPMRC="${NVM_VERSION_DIR}/etc/npmrc"
if nvm_npmrc_bad_news_bears "${NVM_NPM_GLOBAL_NPMRC}"; then
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
npm config --global --loglevel=warn delete prefix
npm config --global --loglevel=warn delete globalconfig
else
nvm_err "Your global npmrc file ($(nvm_sanitize_path "${NVM_NPM_GLOBAL_NPMRC}"))"
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
return 10
fi
fi
local NVM_NPM_USER_NPMRC
NVM_NPM_USER_NPMRC="${HOME}/.npmrc"
if nvm_npmrc_bad_news_bears "${NVM_NPM_USER_NPMRC}"; then
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_USER_NPMRC}"
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_USER_NPMRC}"
else
nvm_err "Your users .npmrc file ($(nvm_sanitize_path "${NVM_NPM_USER_NPMRC}"))"
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
return 10
fi
fi
local NVM_NPM_PROJECT_NPMRC
NVM_NPM_PROJECT_NPMRC="$(nvm_find_project_dir)/.npmrc"
if nvm_npmrc_bad_news_bears "${NVM_NPM_PROJECT_NPMRC}"; then
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
npm config --loglevel=warn delete prefix
npm config --loglevel=warn delete globalconfig
else
nvm deactivate >/dev/null 2>&1
nvm_err "nvm is not compatible with the npm config \"prefix\" option: currently set to \"${NVM_NPM_PREFIX}\""
if nvm_has 'npm'; then
nvm_err "Run \`npm config delete prefix\` or \`${NVM_COMMAND}\` to unset it."
else
nvm_err "Your project npmrc file ($(nvm_sanitize_path "${NVM_NPM_PROJECT_NPMRC}"))"
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
fi
return 10
fi
fi
@@ -2250,7 +2310,7 @@ nvm_die_on_prefix() {
# Currently, only io.js 3.3.1 has a Solaris binary available, and it's the
# latest io.js version available. The expectation is that any potential io.js
# version later than v3.3.1 will also have Solaris binaries.
iojs_version_has_solaris_binary() {
nvm_iojs_version_has_solaris_binary() {
local IOJS_VERSION
IOJS_VERSION="$1"
local STRIPPED_IOJS_VERSION
@@ -2267,7 +2327,7 @@ iojs_version_has_solaris_binary() {
# Solaris binary, fails otherwise.
# Currently, node versions starting from v0.8.6 have a Solaris binary
# available.
node_version_has_solaris_binary() {
nvm_node_version_has_solaris_binary() {
local NODE_VERSION
NODE_VERSION="$1"
# Error out if $NODE_VERSION is actually an io.js version
@@ -2291,9 +2351,9 @@ nvm_has_solaris_binary() {
if nvm_is_merged_node_version "${VERSION}"; then
return 0 # All merged node versions have a Solaris binary
elif nvm_is_iojs_version "${VERSION}"; then
iojs_version_has_solaris_binary "${VERSION}"
nvm_iojs_version_has_solaris_binary "${VERSION}"
else
node_version_has_solaris_binary "${VERSION}"
nvm_node_version_has_solaris_binary "${VERSION}"
fi
}
@@ -2366,16 +2426,10 @@ nvm() {
return $?
fi
local COMMAND
COMMAND="${1-}"
shift
# initialize local variables
local VERSION
local ADDITIONAL_PARAMETERS
case $COMMAND in
'help' | '--help')
for i in "$@"
do
case $i in
'-h'|'help'|'--help')
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
local NVM_NODE_PREFIX
@@ -2394,23 +2448,33 @@ nvm() {
nvm_echo 'Usage:'
nvm_echo ' nvm --help Show this message'
nvm_echo ' nvm --version Print out the installed version of nvm'
nvm_echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available'
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'
nvm_echo ' -s Skip binary download, install from source only.'
nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'
nvm_echo ' --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version'
nvm_echo ' --no-progress Disable the progress bar on any downloads'
nvm_echo ' --alias=<name> After installing, set the alias specified to the version specified. (same as: nvm alias <name> <version>)'
nvm_echo ' --default After installing, set default alias to the version specified. (same as: nvm alias default <version>)'
nvm_echo ' nvm uninstall <version> Uninstall a version'
nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'
nvm_echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'
nvm_echo ' nvm use [<version>] Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.'
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm use`:'
nvm_echo ' --silent Silences stdout/stderr output'
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available'
nvm_echo ' nvm exec [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available and version is omitted.'
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm exec`:'
nvm_echo ' --silent Silences stdout/stderr output'
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
nvm_echo ' nvm run [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.'
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm run`:'
nvm_echo ' --silent Silences stdout/stderr output'
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
nvm_echo ' nvm current Display currently activated version of Node'
@@ -2426,6 +2490,7 @@ nvm() {
nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'
nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'
nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'
nvm_echo ' --silent Silences stdout/stderr output'
nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
nvm_echo ' --no-colors Suppress colored output'
nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
@@ -2433,7 +2498,8 @@ nvm() {
nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
nvm_echo ' nvm unload Unload `nvm` from shell'
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available'
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available and version is omitted.'
nvm_echo ' --silent Silences stdout/stderr output when a version is omitted'
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
nvm_echo ' nvm cache clear Empty cache directory for nvm'
nvm_echo
@@ -2445,11 +2511,28 @@ nvm() {
nvm_echo ' nvm alias default 8.1.0 Set default node version on a shell'
nvm_echo ' nvm alias default node Always default to the latest available node version on a shell'
nvm_echo
nvm_echo ' nvm install node Install the latest available version'
nvm_echo ' nvm use node Use the latest version'
nvm_echo ' nvm install --lts Install the latest LTS version'
nvm_echo ' nvm use --lts Use the latest LTS version'
nvm_echo
nvm_echo 'Note:'
nvm_echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'
nvm_echo
return 0;
;;
esac
done
local COMMAND
COMMAND="${1-}"
shift
# initialize local variables
local VERSION
local ADDITIONAL_PARAMETERS
case $COMMAND in
"cache")
case "${1-}" in
dir) nvm_cache_dir ;;
@@ -2480,6 +2563,7 @@ nvm() {
nvm_err "\$SHELL: ${SHELL}"
# shellcheck disable=SC2169
nvm_err "\$SHLVL: ${SHLVL-}"
nvm_err "whoami: '$(whoami)'"
nvm_err "\${HOME}: ${HOME}"
nvm_err "\${NVM_DIR}: '$(nvm_sanitize_path "${NVM_DIR}")'"
nvm_err "\${PATH}: $(nvm_sanitize_path "${PATH}")"
@@ -2489,6 +2573,7 @@ nvm() {
nvm_err "\$NVM_IOJS_ORG_MIRROR: '${NVM_IOJS_ORG_MIRROR}'"
nvm_err "shell version: '$(${SHELL} --version | command head -n 1)'"
nvm_err "uname -a: '$(command uname -a | command awk '{$2=""; print}' | command xargs)'"
nvm_err "checksum binary: '$(nvm_get_checksum_binary 2>/dev/null)'"
if [ "$(nvm_get_os)" = "darwin" ] && nvm_has sw_vers; then
OS_VERSION="$(sw_vers | command awk '{print $2}' | command xargs)"
elif [ -r "/etc/issue" ]; then
@@ -2570,8 +2655,15 @@ nvm() {
nobinary=0
noprogress=0
local LTS
local ALIAS
local NVM_UPGRADE_NPM
NVM_UPGRADE_NPM=0
local PROVIDED_REINSTALL_PACKAGES_FROM
local REINSTALL_PACKAGES_FROM
local SKIP_DEFAULT_PACKAGES
local DEFAULT_PACKAGES
while [ $# -ne 0 ]; do
case "$1" in
---*)
@@ -2603,6 +2695,56 @@ nvm() {
NVM_UPGRADE_NPM=1
shift
;;
--default)
if [ -n "${ALIAS-}" ]; then
nvm_err '--default and --alias are mutually exclusive, and may not be provided more than once'
return 6
fi
ALIAS='default'
shift
;;
--alias=*)
if [ -n "${ALIAS-}" ]; then
nvm_err '--default and --alias are mutually exclusive, and may not be provided more than once'
return 6
fi
ALIAS="${1##--alias=}"
shift
;;
--reinstall-packages-from=*)
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
nvm_err '--reinstall-packages-from may not be provided more than once'
return 6
fi
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
return 6
fi
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
shift
;;
--copy-packages-from=*)
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
nvm_err '--reinstall-packages-from may not be provided more than once, or combined with `--copy-packages-from`'
return 6
fi
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
nvm_err 'If --copy-packages-from is provided, it must point to an installed version of node.'
return 6
fi
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
shift
;;
--reinstall-packages-from | --copy-packages-from)
nvm_err "If ${1} is provided, it must point to an installed version of node using \`=\`."
return 6
;;
--skip-default-packages)
SKIP_DEFAULT_PACKAGES=true
shift
;;
*)
break # stop parsing args
;;
@@ -2667,14 +2809,14 @@ nvm() {
fi
ADDITIONAL_PARAMETERS=''
local PROVIDED_REINSTALL_PACKAGES_FROM
local REINSTALL_PACKAGES_FROM
local SKIP_DEFAULT_PACKAGES
local DEFAULT_PACKAGES
while [ $# -ne 0 ]; do
case "$1" in
--reinstall-packages-from=*)
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
nvm_err '--reinstall-packages-from may not be provided more than once'
return 6
fi
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 27-)"
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node.'
@@ -2682,14 +2824,22 @@ nvm() {
fi
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
;;
--reinstall-packages-from)
nvm_err 'If --reinstall-packages-from is provided, it must point to an installed version of node using `=`.'
return 6
;;
--copy-packages-from=*)
if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ]; then
nvm_err '--reinstall-packages-from may not be provided more than once, or combined with `--copy-packages-from`'
return 6
fi
PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"
if [ -z "${PROVIDED_REINSTALL_PACKAGES_FROM}" ]; then
nvm_err 'If --copy-packages-from is provided, it must point to an installed version of node.'
return 6
fi
REINSTALL_PACKAGES_FROM="$(nvm_version "${PROVIDED_REINSTALL_PACKAGES_FROM}")" ||:
;;
--reinstall-packages-from | --copy-packages-from)
nvm_err "If ${1} is provided, it must point to an installed version of node using \`=\`."
return 6
;;
--skip-default-packages)
SKIP_DEFAULT_PACKAGES=true
;;
@@ -2742,6 +2892,11 @@ nvm() {
else
nvm_ensure_default_set "${provided_version}"
fi
if [ -n "${ALIAS}" ]; then
nvm alias "${ALIAS}" "${provided_version}"
fi
return $?
fi
@@ -2899,47 +3054,68 @@ nvm() {
done
;;
"deactivate")
local NVM_SILENT
while [ $# -ne 0 ]; do
case "${1}" in
--silent) NVM_SILENT=1 ;;
--) ;;
esac
shift
done
local NEWPATH
NEWPATH="$(nvm_strip_path "${PATH}" "/bin")"
if [ "_${PATH}" = "_${NEWPATH}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Could not find ${NVM_DIR}/*/bin in \${PATH}"
fi
else
export PATH="${NEWPATH}"
hash -r
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "${NVM_DIR}/*/bin removed from \${PATH}"
fi
fi
if [ -n "${MANPATH-}" ]; then
NEWPATH="$(nvm_strip_path "${MANPATH}" "/share/man")"
if [ "_${MANPATH}" = "_${NEWPATH}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Could not find ${NVM_DIR}/*/share/man in \${MANPATH}"
fi
else
export MANPATH="${NEWPATH}"
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "${NVM_DIR}/*/share/man removed from \${MANPATH}"
fi
fi
fi
if [ -n "${NODE_PATH-}" ]; then
NEWPATH="$(nvm_strip_path "${NODE_PATH}" "/lib/node_modules")"
if [ "_${NODE_PATH}" != "_${NEWPATH}" ]; then
export NODE_PATH="${NEWPATH}"
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "${NVM_DIR}/*/lib/node_modules removed from \${NODE_PATH}"
fi
fi
fi
unset NVM_BIN
unset NVM_INC
;;
"use")
local PROVIDED_VERSION
local NVM_USE_SILENT
NVM_USE_SILENT=0
local NVM_SILENT
local NVM_SILENT_ARG
local NVM_DELETE_PREFIX
NVM_DELETE_PREFIX=0
local NVM_LTS
while [ $# -ne 0 ]; do
case "$1" in
--silent) NVM_USE_SILENT=1 ;;
--silent)
NVM_SILENT=1
NVM_SILENT_ARG='--silent'
;;
--delete-prefix) NVM_DELETE_PREFIX=1 ;;
--) ;;
--lts) NVM_LTS='*' ;;
@@ -2957,7 +3133,7 @@ nvm() {
if [ -n "${NVM_LTS-}" ]; then
VERSION="$(nvm_match_version "lts/${NVM_LTS:-*}")"
elif [ -z "${PROVIDED_VERSION-}" ]; then
nvm_rc_version
NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version
if [ -n "${NVM_RC_VERSION-}" ]; then
PROVIDED_VERSION="${NVM_RC_VERSION}"
VERSION="$(nvm_version "${PROVIDED_VERSION}")"
@@ -2977,30 +3153,32 @@ nvm() {
fi
if [ "_${VERSION}" = '_system' ]; then
if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then
if [ $NVM_USE_SILENT -ne 1 ]; then
if nvm_has_system_node && nvm deactivate "${NVM_SILENT_ARG-}" >/dev/null 2>&1; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"
fi
return
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then
if [ $NVM_USE_SILENT -ne 1 ]; then
elif nvm_has_system_iojs && nvm deactivate "${NVM_SILENT_ARG-}" >/dev/null 2>&1; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
fi
return
elif [ $NVM_USE_SILENT -ne 1 ]; then
elif [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err 'System version of node not found.'
fi
return 127
elif [ "_${VERSION}" = "_∞" ]; then
if [ $NVM_USE_SILENT -ne 1 ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "The alias \"${PROVIDED_VERSION}\" leads to an infinite loop. Aborting."
fi
return 8
fi
if [ "${VERSION}" = 'N/A' ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "N/A: version \"${PROVIDED_VERSION} -> ${VERSION}\" is not yet installed."
nvm_err ""
nvm_err "You need to run \"nvm install ${PROVIDED_VERSION}\" to install it before using it."
fi
return 3
# This nvm_ensure_version_installed call can be a performance bottleneck
# on shell startup. Perhaps we can optimize it away or make it faster.
@@ -3031,7 +3209,7 @@ nvm() {
fi
local NVM_USE_OUTPUT
NVM_USE_OUTPUT=''
if [ $NVM_USE_SILENT -ne 1 ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
if nvm_is_iojs_version "${VERSION}"; then
NVM_USE_OUTPUT="Now using io.js $(nvm_strip_iojs_prefix "${VERSION}")$(nvm_print_npm_version)"
else
@@ -3044,14 +3222,14 @@ nvm() {
if [ -n "${PROVIDED_VERSION}" ]; then
NVM_USE_CMD="${NVM_USE_CMD} ${VERSION}"
fi
if [ $NVM_USE_SILENT -eq 1 ]; then
if [ "${NVM_SILENT:-0}" -eq 1 ]; then
NVM_USE_CMD="${NVM_USE_CMD} --silent"
fi
if ! nvm_die_on_prefix "${NVM_DELETE_PREFIX}" "${NVM_USE_CMD}"; then
if ! nvm_die_on_prefix "${NVM_DELETE_PREFIX}" "${NVM_USE_CMD}" "${NVM_VERSION_DIR}"; then
return 11
fi
fi
if [ -n "${NVM_USE_OUTPUT-}" ]; then
if [ -n "${NVM_USE_OUTPUT-}" ] && [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "${NVM_USE_OUTPUT}"
fi
;;
@@ -3062,10 +3240,15 @@ nvm() {
# run given version of node
local NVM_SILENT
local NVM_SILENT_ARG
local NVM_LTS
while [ $# -gt 0 ]; do
case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;;
--silent)
NVM_SILENT=1
NVM_SILENT_ARG='--silent'
shift
;;
--lts) NVM_LTS='*' ; shift ;;
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
*)
@@ -3079,11 +3262,7 @@ nvm() {
done
if [ $# -lt 1 ] && [ -z "${NVM_LTS-}" ]; then
if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
fi
NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
if [ -n "${NVM_RC_VERSION-}" ]; then
VERSION="$(nvm_version "${NVM_RC_VERSION-}")" ||:
fi
@@ -3101,11 +3280,7 @@ nvm() {
if [ "_${VERSION:-N/A}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then
provided_version=''
if [ $has_checked_nvmrc -ne 1 ]; then
if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1
else
nvm_rc_version && has_checked_nvmrc=1
fi
NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
fi
VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||:
unset NVM_RC_VERSION
@@ -3131,9 +3306,9 @@ nvm() {
if [ "_${VERSION}" = "_N/A" ]; then
nvm_ensure_version_installed "${provided_version}"
elif [ "${NVM_IOJS}" = true ]; then
nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "${VERSION}" iojs "$@"
nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" iojs "$@"
else
nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "${VERSION}" node "$@"
nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" node "$@"
fi
EXIT_CODE="$?"
return $EXIT_CODE
@@ -3143,7 +3318,7 @@ nvm() {
local NVM_LTS
while [ $# -gt 0 ]; do
case "$1" in
--silent) NVM_SILENT='--silent' ; shift ;;
--silent) NVM_SILENT=1 ; shift ;;
--lts) NVM_LTS='*' ; shift ;;
--lts=*) NVM_LTS="${1##--lts=}" ; shift ;;
--) break ;;
@@ -3169,11 +3344,7 @@ nvm() {
elif [ -n "${provided_version}" ]; then
VERSION="$(nvm_version "${provided_version}")" ||:
if [ "_${VERSION}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then
if [ -n "${NVM_SILENT-}" ]; then
nvm_rc_version >/dev/null 2>&1
else
nvm_rc_version
fi
NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1
provided_version="${NVM_RC_VERSION}"
unset NVM_RC_VERSION
VERSION="$(nvm_version "${provided_version}")" ||:
@@ -3188,7 +3359,7 @@ nvm() {
return $EXIT_CODE
fi
if [ -z "${NVM_SILENT-}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
if [ "${NVM_LTS-}" = '*' ]; then
nvm_echo "Running node latest LTS -> $(nvm_version "${VERSION}")$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
elif [ -n "${NVM_LTS-}" ]; then
@@ -3286,19 +3457,27 @@ nvm() {
nvm_version current
;;
"which")
local NVM_SILENT
local provided_version
provided_version="${1-}"
if [ $# -eq 0 ]; then
nvm_rc_version
while [ $# -ne 0 ]; do
case "${1}" in
--silent) NVM_SILENT=1 ;;
--) ;;
*) provided_version="${1-}" ;;
esac
shift
done
if [ -z "${provided_version-}" ]; then
NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version
if [ -n "${NVM_RC_VERSION}" ]; then
provided_version="${NVM_RC_VERSION}"
VERSION=$(nvm_version "${NVM_RC_VERSION}") ||:
fi
unset NVM_RC_VERSION
elif [ "_${1}" != '_system' ]; then
elif [ "${provided_version}" != 'system' ]; then
VERSION="$(nvm_version "${provided_version}")" ||:
else
VERSION="${1-}"
VERSION="${provided_version-}"
fi
if [ -z "${VERSION}" ]; then
>&2 nvm --help
@@ -3317,8 +3496,8 @@ nvm() {
fi
nvm_err 'System version of node not found.'
return 127
elif [ "_${VERSION}" = "_∞" ]; then
nvm_err "The alias \"$2\" leads to an infinite loop. Aborting."
elif [ "${VERSION}" = '∞' ]; then
nvm_err "The alias \"${2}\" leads to an infinite loop. Aborting."
return 8
fi
@@ -3532,8 +3711,8 @@ nvm() {
esac
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
;;
"--version")
nvm_echo '0.35.3'
"--version" | "-v")
nvm_echo '0.37.0'
;;
"unload")
nvm deactivate >/dev/null 2>&1
@@ -3546,7 +3725,8 @@ nvm() {
nvm_install_binary nvm_install_source nvm_clang_version \
nvm_get_mirror nvm_get_download_slug nvm_download_artifact \
nvm_install_npm_if_needed nvm_use_if_needed nvm_check_file_permissions \
nvm_print_versions nvm_compute_checksum nvm_checksum \
nvm_print_versions nvm_compute_checksum \
nvm_get_checksum_binary \
nvm_get_checksum_alg nvm_get_checksum nvm_compare_checksum \
nvm_version nvm_rc_version nvm_match_version \
nvm_ensure_default_set nvm_get_arch nvm_get_os \
@@ -3557,7 +3737,7 @@ nvm() {
nvm_normalize_version nvm_is_valid_version \
nvm_ensure_version_installed nvm_cache_dir \
nvm_version_path nvm_alias_path nvm_version_dir \
nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \
nvm_find_nvmrc nvm_find_up nvm_find_project_dir nvm_tree_contains_path \
nvm_version_greater nvm_version_greater_than_or_equal_to \
nvm_print_npm_version nvm_install_latest_npm nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \
@@ -3571,8 +3751,9 @@ nvm() {
nvm_list_aliases nvm_make_alias nvm_print_alias_path \
nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \
nvm_sanitize_path nvm_has_colors nvm_process_parameters \
node_version_has_solaris_binary iojs_version_has_solaris_binary \
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
nvm_npmrc_bad_news_bears \
>/dev/null 2>&1
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \
@@ -3596,7 +3777,7 @@ nvm_get_default_packages() {
# ensure a trailing newline
WORK=$(mktemp -d) || exit $?
# shellcheck disable=SC2064
trap "rm -rf '$WORK'" EXIT
trap "command rm -rf '$WORK'" EXIT
# shellcheck disable=SC1003
sed -e '$a\' "${NVM_DEFAULT_PACKAGE_FILE}" > "${WORK}/default-packages"
while IFS=' ' read -r line; do
@@ -3616,7 +3797,7 @@ nvm_get_default_packages() {
DEFAULT_PACKAGES="${DEFAULT_PACKAGES}${line} "
done < "${WORK}/default-packages"
echo "${DEFAULT_PACKAGES}" | xargs
echo "${DEFAULT_PACKAGES}" | command xargs
fi
}
@@ -3639,10 +3820,32 @@ EOF
}
nvm_supports_xz() {
if [ -z "${1-}" ] || ! command which xz >/dev/null 2>&1; then
if [ -z "${1-}" ]; then
return 1
fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
if [ "_${NVM_OS}" = '_darwin' ]; then
local MACOS_VERSION
MACOS_VERSION="$(sw_vers -productVersion)"
if nvm_version_greater "10.9.0" "${MACOS_VERSION}"; then
# macOS 10.8 and earlier doesn't support extracting xz-compressed tarballs with tar
return 1
fi
elif [ "_${NVM_OS}" = '_freebsd' ]; then
if ! [ -e '/usr/lib/liblzma.so' ]; then
# FreeBSD without /usr/lib/liblzma.so doesn't support extracting xz-compressed tarballs with tar
return 1
fi
else
if ! command which xz >/dev/null 2>&1; then
# Most OSes without xz on the PATH don't support extracting xz-compressed tarballs with tar
# (Should correctly handle Linux, SmartOS, maybe more)
return 1
fi
fi
# all node versions v4.0.0 and later have xz
if nvm_is_merged_node_version "${1}"; then
return 0
@@ -3658,8 +3861,6 @@ nvm_supports_xz() {
return 0
fi
local NVM_OS
NVM_OS="$(nvm_get_os)"
case "${NVM_OS}" in
darwin)
# darwin only has xz for io.js v2.3.2 and later
@@ -3673,11 +3874,10 @@ nvm_supports_xz() {
}
nvm_auto() {
local NVM_CURRENT
NVM_CURRENT="$(nvm_ls_current)"
local NVM_MODE
NVM_MODE="${1-}"
local VERSION
local NVM_CURRENT
if [ "_${NVM_MODE}" = '_install' ]; then
VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)"
if [ -n "${VERSION}" ]; then
@@ -3686,6 +3886,7 @@ nvm_auto() {
nvm install >/dev/null
fi
elif [ "_$NVM_MODE" = '_use' ]; then
NVM_CURRENT="$(nvm_ls_current)"
if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
if [ -n "${VERSION}" ]; then

View File

@@ -1,6 +1,6 @@
{
"name": "nvm",
"version": "0.35.3",
"version": "0.37.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
@@ -37,10 +37,10 @@
"homepage": "https://github.com/nvm-sh/nvm",
"devDependencies": {
"dockerfile_lint": "^0.3.2",
"doctoc": "^1.2.0",
"eclint": "^2.6.0",
"replace": "^0.3.0",
"semver": "^5.0.1",
"urchin": "^0.0.5",
"doctoc": "^1.2.0"
"urchin": "^0.0.5"
}
}

View File

@@ -0,0 +1,40 @@
#!/bin/zsh
\. ../../../nvm.sh
\. ../../common.sh
if type setopt >/dev/null 2>&1; then setopt local_options markdirs; fi
die () {
if type unsetopt >/dev/null 2>&1; then unsetopt local_options markdirs; fi
echo "$@";
exit 1;
}
make_fake_node v0.0.1
make_fake_node v0.0.3
make_fake_node v0.0.9
make_fake_node v0.3.1
make_fake_node v0.3.3
make_fake_node v0.3.9
make_fake_node v0.12.87
make_fake_node v0.12.9
make_fake_iojs v0.1.2
make_fake_iojs v0.10.2
OUTPUT="$(nvm_ls)"
EXPECTED_OUTPUT="v0.0.1
v0.0.3
v0.0.9
iojs-v0.1.2
v0.3.1
v0.3.3
v0.3.9
iojs-v0.10.2
v0.12.9
v0.12.87"
if nvm_has_system_node || nvm_has_system_iojs; then
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
system"
fi
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@@ -5,7 +5,7 @@ set -ex
BEFORE="./before.tmp"
AFTER="./after.tmp"
cleanup () { echo rm -f "${BEFORE}" "${AFTER}"; }
cleanup () { rm -f "${BEFORE}" "${AFTER}"; }
die () { echo "$@" ; cleanup ; exit 1; }
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"

View File

@@ -1,17 +0,0 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
assert_not_ok iojs_version_has_solaris_binary ""
assert_not_ok iojs_version_has_solaris_binary "foo"
assert_not_ok iojs_version_has_solaris_binary "v1.1.0"
assert_ok iojs_version_has_solaris_binary "v3.3.1"
assert_ok iojs_version_has_solaris_binary "iojs-v3.3.1"
assert_ok iojs_version_has_solaris_binary "v3.3.2"
assert_ok iojs_version_has_solaris_binary "iojs-v3.3.2"
assert_ok iojs_version_has_solaris_binary "v3.4.1"
assert_ok iojs_version_has_solaris_binary "iojs-v3.4.1"

View File

@@ -1,33 +0,0 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
# Invalid version numbers fail
assert_not_ok node_version_has_solaris_binary ""
assert_not_ok node_version_has_solaris_binary "foo"
# "Invalid" node version numbers fail
assert_not_ok node_version_has_solaris_binary "v1.0.0"
assert_not_ok node_version_has_solaris_binary "v3.3.1"
# Valid io.js version numbers that have a Solaris binary fail
assert_not_ok node_version_has_solaris_binary "iojs-v3.3.1"
# Invalid io.js version numbers fail
assert_not_ok node_version_has_solaris_binary "iojs-v0.12.7"
# Valid node version numbers that don't have a Solaris binary fail
assert_not_ok node_version_has_solaris_binary "v0.8.5"
# Valid node version numbers that have a Solaris binary succeed
assert_ok node_version_has_solaris_binary "v0.8.6"
assert_ok node_version_has_solaris_binary "v0.10.0"
assert_ok node_version_has_solaris_binary "v0.12.7"
# Valid "merged" version numbers fail, because they're not
# considered node version numbers
assert_not_ok node_version_has_solaris_binary "v4.0.0"
assert_not_ok node_version_has_solaris_binary "v4.1.1"

View File

@@ -0,0 +1,9 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
TERM=dumb nvm clear-cache --help | grep 'Usage:' || die 'did not print help menu'
TERM=dumb nvm cache help version | grep 'Usage:' || die 'did not print help menu'
TERM=dumb nvm cache -h version| grep 'Usage:' || die 'did not print help menu'

View File

@@ -1,18 +0,0 @@
#!/bin/sh
cleanup () {
rm tmp/emptyfile tmp/testfile
rmdir tmp
}
die () { echo "$@" ; cleanup; exit 1; }
\. ../../../nvm.sh
mkdir -p tmp
touch tmp/emptyfile
echo -n "test" > tmp/testfile
nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string"
nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum"
cleanup

View File

@@ -1,13 +1,26 @@
#!/bin/sh
TEST_PWD=$(pwd)
TEST_DIR="$TEST_PWD/nvm_die_on_prefix_tmp"
\. ../../../nvm.sh
TEST_VERSION_DIR="${TEST_DIR}/version"
cleanup () {
rm -rf "$TEST_DIR"
alias nvm_has='\nvm_has'
alias npm='\npm'
unset -f nvm_has npm
}
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
die () {
echo "$@";
cleanup;
exit 1;
}
[ ! -e "$TEST_DIR" ] && mkdir "$TEST_DIR"
OUTPUT="$(nvm_die_on_prefix 2>&1)"
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
@@ -22,60 +35,155 @@ EXIT_CODE="$(nvm_die_on_prefix 2 >/dev/null 2>&1; echo $?)"
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
OUTPUT="$(nvm_die_on_prefix 0 2>&1)"
EXPECTED_OUTPUT="Second argument \"nvm command\" must be nonempty"
EXPECTED_OUTPUT='Second argument "nvm command", and third argument "nvm version dir", must both be nonempty'
EXIT_CODE="$(nvm_die_on_prefix 0 >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_die_on_prefix 0' did not exit with 2; got '$EXIT_CODE'"
nvm_has() { return 1; } # ie, npm is not installed
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
OUTPUT="$(nvm_die_on_prefix 0 version_dir foo 2>&1)"
[ -z "$OUTPUT" ] || die "nvm_die_on_prefix was not a noop when nvm_has returns 1, got '$OUTPUT'"
nvm_has() { return 0; }
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
mkdir -p "$(nvm_version_dir new)"
ln -s "$(nvm_version_dir new)" "$TEST_DIR/node"
npm() {
local args
args="$@"
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
echo "$(nvm_version_dir new)/good prefix"
echo "$TEST_DIR/node"
fi
}
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when directory is equivalent; got '$OUTPUT'"
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
Run `unset PREFIX` to unset it.'
EXIT_CODE="$(export PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
EXIT_CODE="$(export PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_3" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 3; got '$EXIT_CODE'"
OUTPUT="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo 2>&1)"
OUTPUT="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "NPM_CONFIG_PREFIX" environment variable: currently set to "bar"
Run `unset NPM_CONFIG_PREFIX` to unset it.'
EXIT_CODE="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
EXIT_CODE="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
OUTPUT="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo 2>&1)"
OUTPUT="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
EXPECTED_OUTPUT='nvm is not compatible with the "npm_CONFIG_PREFIX" environment variable: currently set to "bar"
Run `unset npm_CONFIG_PREFIX` to unset it.'
EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_4" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
npm() {
local args
args="$@"
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
echo "./bad prefix"
fi
}
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"
Run \`npm config delete prefix\` or \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
# npmrc tests
(
cd "${TEST_DIR}"
touch package.json
# project: prefix
echo 'prefix=garbage' > .npmrc
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
# project: globalconfig
echo 'globalconfig=garbage' > .npmrc
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
rm "${TEST_DIR}/.npmrc" || die '.npmrc could not be removed'
mkdir -p "${TEST_VERSION_DIR}"
GLOBAL_NPMRC="${TEST_VERSION_DIR}/etc/npmrc"
mkdir -p "${TEST_VERSION_DIR}/etc"
BUILTIN_NPMRC="${TEST_VERSION_DIR}/lib/node_modules/npm/npmrc"
mkdir -p "${TEST_VERSION_DIR}/lib/node_modules/npm/"
export HOME="${TEST_VERSION_DIR}"
USER_NPMRC="${TEST_VERSION_DIR}/.npmrc"
# global: prefix
echo 'prefix=garbage' > "${GLOBAL_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your global npmrc file ($(nvm_sanitize_path "${GLOBAL_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
# global: globalconfig
echo 'globalconfig=garbage' > "${GLOBAL_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your global npmrc file ($(nvm_sanitize_path "${GLOBAL_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
rm "${GLOBAL_NPMRC}" || die "${GLOBAL_NPMRC} could not be removed"
# builtin: prefix
echo 'prefix=garbage' > "${BUILTIN_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your builtin npmrc file ($(nvm_sanitize_path "${BUILTIN_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
# builtin: globalconfig
echo 'globalconfig=garbage' > "${BUILTIN_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your builtin npmrc file ($(nvm_sanitize_path "${BUILTIN_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
rm "${BUILTIN_NPMRC}" || die "${BUILTIN_NPMRC} could not be removed"
# user: prefix
echo 'prefix=garbage' > "${USER_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your users .npmrc file ($(nvm_sanitize_path "${USER_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
# user: globalconfig
echo 'globalconfig=garbage' > "${USER_NPMRC}"
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="Your users .npmrc file ($(nvm_sanitize_path "${USER_NPMRC}"))
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
Run \`foo\` to unset it."
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
)
cleanup

View File

@@ -0,0 +1,33 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
set -ex
TEST_DIR="$PWD/mocks/project_dirs"
ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested/node_modules/foo/bar nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested" ] || die "inside-n_m-nested: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo/bar nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/inside-n_m-nested-pkg/node_modules/foo" ] || die "inside-n_m-nested-pkg: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/nested-both/a/b/c/d nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/nested-both" ] || die "nested-both: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/nested-pkg/a/b/c/d nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/nested-pkg" ] || die "nested-pkg: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/nested-n_m/a/b/c/d nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/nested-n_m" ] || die "nested-n_m: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/no-nesting-both nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-both" ] || die "no-nesting-both: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/no-nesting-n_m nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-n_m" ] || die "no-nesting-n_m: got ${ACTUAL}"
ACTUAL="$(PWD=$TEST_DIR/no-nesting-pkg nvm_find_project_dir)"
[ "${ACTUAL}" = "$TEST_DIR/no-nesting-pkg" ] || die "no-nesting-pkg: got ${ACTUAL}"

View File

@@ -0,0 +1,20 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
set +e # TODO: fix
\. ../../../nvm.sh
set -e
BIN="$(nvm_get_checksum_binary)"
case "${BIN-}" in
sha256sum | shasum | sha256 | gsha256sum | openssl | bssl | sha1sum | sha1 | shasum)
echo "${BIN} found"
;;
*)
die "sha256sum | shasum | sha256 | gsha256sum | openssl | bssl | sha1sum | sha1 | shasum not found: found ${BIN}"
;;
esac

View File

@@ -1,8 +1,9 @@
#!/bin/sh
FILE="$NVM_DIR/default-packages"
\. ../../../nvm.sh
FILE="$NVM_DIR/default-packages"
die () { echo "$@" ; cleanup ; exit 1; }
setup () {
if [ -f $FILE ]; then

View File

@@ -0,0 +1,17 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
assert_not_ok nvm_iojs_version_has_solaris_binary ""
assert_not_ok nvm_iojs_version_has_solaris_binary "foo"
assert_not_ok nvm_iojs_version_has_solaris_binary "v1.1.0"
assert_ok nvm_iojs_version_has_solaris_binary "v3.3.1"
assert_ok nvm_iojs_version_has_solaris_binary "iojs-v3.3.1"
assert_ok nvm_iojs_version_has_solaris_binary "v3.3.2"
assert_ok nvm_iojs_version_has_solaris_binary "iojs-v3.3.2"
assert_ok nvm_iojs_version_has_solaris_binary "v3.4.1"
assert_ok nvm_iojs_version_has_solaris_binary "iojs-v3.4.1"

View File

@@ -19,7 +19,8 @@ fi
rm -rf "$TEST_DIR"
mkdir "$TEST_DIR"
ln -s "$(command which which)" "$TEST_DIR/which"
# Ensure that the system version of which is used, not node_modules/.bin/which
ln -s "$(PATH=$(echo $PATH | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") command which which)" "$TEST_DIR/which"
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
ln -s "$(command which printf)" "$TEST_DIR/printf"
@@ -27,12 +28,12 @@ ln -s "$(command which printf)" "$TEST_DIR/printf"
[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'
echo "#!/bin/bash" > "$TEST_DIR/node"
echo "echo 'VERSION FOO!'" > "$TEST_DIR/node"
echo "echo 'VERSION FOO!'" >> "$TEST_DIR/node"
chmod a+x "$TEST_DIR/node"
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
alias node='node --harmony'
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
cleanup

View File

@@ -40,6 +40,19 @@ v0.3.8"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $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_PATH="${MOCKS_DIR}/nvm_print_implicit_alias remote stable.txt"

View File

@@ -0,0 +1,33 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
# Invalid version numbers fail
assert_not_ok nvm_node_version_has_solaris_binary ""
assert_not_ok nvm_node_version_has_solaris_binary "foo"
# "Invalid" node version numbers fail
assert_not_ok nvm_node_version_has_solaris_binary "v1.0.0"
assert_not_ok nvm_node_version_has_solaris_binary "v3.3.1"
# Valid io.js version numbers that have a Solaris binary fail
assert_not_ok nvm_node_version_has_solaris_binary "iojs-v3.3.1"
# Invalid io.js version numbers fail
assert_not_ok nvm_node_version_has_solaris_binary "iojs-v0.12.7"
# Valid node version numbers that don't have a Solaris binary fail
assert_not_ok nvm_node_version_has_solaris_binary "v0.8.5"
# Valid node version numbers that have a Solaris binary succeed
assert_ok nvm_node_version_has_solaris_binary "v0.8.6"
assert_ok nvm_node_version_has_solaris_binary "v0.10.0"
assert_ok nvm_node_version_has_solaris_binary "v0.12.7"
# Valid "merged" version numbers fail, because they're not
# considered node version numbers
assert_not_ok nvm_node_version_has_solaris_binary "v4.0.0"
assert_not_ok nvm_node_version_has_solaris_binary "v4.1.1"

View File

@@ -7,6 +7,7 @@ die () { echo "$@" ; exit 1; }
# Remove the stuff we're clobbering.
[ -e "${NVM_DIR}/versions/node/v9.7.0" ] && rm -R "${NVM_DIR}/versions/node/v9.7.0"
[ -e "${NVM_DIR}/versions/node/v9.10.0" ] && rm -R "${NVM_DIR}/versions/node/v9.10.0"
[ -e "${NVM_DIR}/versions/node/v4.9.1" ] && rm -R "${NVM_DIR}/versions/node/v4.9.1"
# Install from binary
nvm install 9.7.0
@@ -31,3 +32,15 @@ nvm use 9
node --version | grep v9.10.0 > /dev/null || die "nvm ls 9 didn't use v9.10.0"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"
# LTS
nvm install --lts=argon --reinstall-packages-from=9 || die "nvm install 9.10.0 --reinstall-packages-from=9 failed"
[ -d "${NVM_DIR}/versions/node/v4.9.1" ] || die "nvm install 4.9.1 didn't install"
nvm use --lts=argon
node --version | grep v4.9.1 > /dev/null || die "nvm ls --lts=argon didn't use v4.9.1"
npm list --global | grep object-is > /dev/null || die "object-is isn't installed"

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
\. ../../nvm.sh
nvm install --alias=9 9.11.2 || die '`nvm install --alias=9 9.11.2` failed'
TERM=dumb nvm alias | grep '9 -> 9.11.2 (-> v9.11.2 \*)' || die 'did not make the expected alias'

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
\. ../../nvm.sh
nvm install --default node || die '`nvm install --default` failed'
TERM=dumb nvm alias | grep "default -> node (-> $(nvm version node) \*)" || die 'did not make the expected alias'

View File

@@ -10,8 +10,8 @@ nvm exec 0.10.29 npm install -g npm@~1.4.11 && nvm install-latest-npm # this is
nvm use 0.10.28
(cd test-npmlink && npm link)
EXPECTED_PACKAGES="autoprefixer bower david grunt-cli grunth-cli http-server jshint marked node-gyp npmlist recursive-blame spawn-sync test-npmlink uglify-js yo"
EXPECTED_PACKAGES_INSTALL="autoprefixer bower david@11 grunt-cli grunth-cli http-server jshint marked node-gyp npmlist recursive-blame spawn-sync test-npmlink uglify-js yo@1"
EXPECTED_PACKAGES="autoprefixer bower david grunt-cli grunth-cli http-server jshint marked node-gyp npmlist postcss recursive-blame spawn-sync test-npmlink uglify-js yo"
EXPECTED_PACKAGES_INSTALL="autoprefixer bower david@11 grunt-cli grunth-cli http-server jshint marked node-gyp npmlist postcss@7 recursive-blame spawn-sync test-npmlink uglify-js yo@1"
echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
nvm deactivate 2>&1 >/dev/null || die 'deactivate failed'
OUTPUT=$(nvm use node --silent || die 'nvm use node failed')
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use node --silent' output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'"