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] [test/fast/Listing versions/Running "nvm ls --no-alias" does not call into nvm_alias]
indent_size = false indent_size = false
[test/fast/Unit tests/mocks/**]
insert_final_newline = off
[test/**/.urchin*]
insert_final_newline = off
[Makefile] [Makefile]
indent_style = tab 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 language: generic
dist: xenial dist: xenial
sudo: required
addons: addons:
apt: apt:
packages: packages:

View File

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

118
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` --> <!-- 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 --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
@@ -31,8 +31,11 @@
- [Automatically call `nvm use`](#automatically-call-nvm-use) - [Automatically call `nvm use`](#automatically-call-nvm-use)
- [zsh](#zsh) - [zsh](#zsh)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file) - [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) - [License](#license)
- [Running Tests](#running-tests) - [Running Tests](#running-tests)
- [Environment variables](#environment-variables)
- [Bash Completion](#bash-completion) - [Bash Completion](#bash-completion)
- [Usage](#usage-1) - [Usage](#usage-1)
- [Compatibility Issues](#compatibility-issues) - [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: 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 ```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 ```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`). 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: 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: 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: You can use a task:
``` ```yaml
- name: nvm - name: nvm
shell: > 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: args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh" 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 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` - `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` 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: 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. 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 ### Migrating Global Packages While Installing
If you want to install a new version of Node.js and migrate npm packages from a previous version: 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 $ 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: Then when you run nvm:
```sh ```sh
@@ -450,7 +463,7 @@ If you prefer a lighter-weight solution, the recipes below have been contributed
Put the following at the end of your `$HOME/.bashrc`: Put the following at the end of your `$HOME/.bashrc`:
```bash ```bash
find-up () { find-up() {
path=$(pwd) path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*} path=${path%/*}
@@ -458,9 +471,9 @@ find-up () {
echo "$path" echo "$path"
} }
cdnvm(){ cdnvm() {
cd "$@"; 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 there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then if [[ ! $nvm_path = *[^[:space:]]* ]]; then
@@ -501,6 +514,7 @@ cdnvm(){
fi fi
} }
alias cd='cdnvm' 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. 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 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 ## License
nvm is released under the MIT 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. 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 ## Bash Completion
To activate, you need to source `bash_completion`: To activate, you need to source `bash_completion`:
@@ -588,36 +654,36 @@ nvm:
> $ nvm <kbd>Tab</kbd> > $ nvm <kbd>Tab</kbd>
``` ```
alias deactivate install ls run unload alias deactivate install list-remote reinstall-packages uninstall version
clear-cache exec list ls-remote unalias use cache exec install-latest-npm ls run unload version-remote
current help list-remote reinstall-packages uninstall version current help list ls-remote unalias use which
``` ```
nvm alias: nvm alias:
> $ nvm alias <kbd>Tab</kbd> > $ 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> > $ 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:
> $ nvm use <kbd>Tab</kbd> > $ 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:
> $ nvm uninstall <kbd>Tab</kbd> > $ 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 ## Compatibility Issues
@@ -656,7 +722,7 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
```sh ```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils 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. 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). 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 [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 [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 [Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com [Fish]: http://fishshell.com

View File

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

669
nvm.sh

File diff suppressed because it is too large Load Diff

View File

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

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" BEFORE="./before.tmp"
AFTER="./after.tmp" AFTER="./after.tmp"
cleanup () { echo rm -f "${BEFORE}" "${AFTER}"; } cleanup () { rm -f "${BEFORE}" "${AFTER}"; }
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}" 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 #!/bin/sh
TEST_PWD=$(pwd)
TEST_DIR="$TEST_PWD/nvm_die_on_prefix_tmp"
\. ../../../nvm.sh
TEST_VERSION_DIR="${TEST_DIR}/version"
cleanup () { cleanup () {
rm -rf "$TEST_DIR"
alias nvm_has='\nvm_has' alias nvm_has='\nvm_has'
alias npm='\npm' alias npm='\npm'
unset -f nvm_has 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)" OUTPUT="$(nvm_die_on_prefix 2>&1)"
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one" 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"" [ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
OUTPUT="$(nvm_die_on_prefix 0 2>&1)" 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 $?)" 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'" [ "_$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'" [ "_$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 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'" [ -z "$OUTPUT" ] || die "nvm_die_on_prefix was not a noop when nvm_has returns 1, got '$OUTPUT'"
nvm_has() { return 0; } 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() { npm() {
local args local args
args="$@" args="$@"
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
echo "$(nvm_version_dir new)/good prefix" echo "$TEST_DIR/node"
fi 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" EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
Run `unset PREFIX` to unset it.' 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'" [ "_$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'" [ "_$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" 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.' 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'" [ "_$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'" [ "_$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" 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.' 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'" [ "_$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'" [ "_$EXIT_CODE" = "_4" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
npm() { # npmrc tests
local args (
args="$@" cd "${TEST_DIR}"
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then touch package.json
echo "./bad prefix"
fi # project: prefix
} echo 'prefix=garbage' > .npmrc
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)" OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\" EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
Run \`npm config delete prefix\` or \`foo\` to unset it." has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
EXIT_CODE="$(nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)" Run \`foo\` to unset it."
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'" EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'" [ "_$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 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 #!/bin/sh
FILE="$NVM_DIR/default-packages"
\. ../../../nvm.sh \. ../../../nvm.sh
FILE="$NVM_DIR/default-packages"
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
setup () { setup () {
if [ -f $FILE ]; then 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" rm -rf "$TEST_DIR"
mkdir "$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 dirname)" "$TEST_DIR/dirname"
ln -s "$(command which printf)" "$TEST_DIR/printf" 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' [ "@$(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 "#!/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" 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 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 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" = "_$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 # Sanity checks
OUTPUT="$(nvm_print_implicit_alias remote stable)" OUTPUT="$(nvm_print_implicit_alias remote stable)"
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm_print_implicit_alias remote stable.txt" 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. # 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.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/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 # Install from binary
nvm install 9.7.0 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" 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" 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 nvm use 0.10.28
(cd test-npmlink && npm link) (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="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 recursive-blame spawn-sync test-npmlink uglify-js yo@1" 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 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'"