Compare commits

..

64 Commits

Author SHA1 Message Date
Jordan Harband
661a702cdd v0.37.1 2020-11-24 21:16:43 -08:00
Jordan Harband
510b2fd44c [Tests] fix eclint errors 2020-11-21 18:08:22 -08:00
Jordan Harband
80a4e06af9 [Tests] partially migrate to Github Actions 2020-11-07 00:09:08 -08:00
Alex Aubuchon
22902f04a3 [actions] Add release test workflow 2020-11-20 14:28:15 -05:00
Dena Burd
6848c16d53 [New] Added set-colors command. See details below:
This command allows users to replace default colors with their own custom colors.

 - top-level commands modified: alias, ls, ls-remote
 - helper functions added: nvm_echo_with_colors, nvm_err_with_colors,
nvm_set_colors, nvm_get_colors, nvm_print_color_code
 - functions modified: nvm_print_formatted_alias, nvm_print_versions, nvm_print_alias_path (implicitly), nvm_print_default_alias (implicitly), nvm_list_aliases (implicitly)

We added tests and info on using this command to the README!

Co-authored-by: Dena Burd <29719099+gitburd@users.noreply.github.com>
Co-authored-by: Naomi Quinones <52065567+naomiquinones@users.noreply.github.com>
2020-08-17 14:56:13 -07:00
Alex Aubuchon
3abb98124e [actions] Add shellcheck workflow
Co-authored-by: Alex Aubuchon <alex@aub.dev>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2020-11-18 12:49:28 -05:00
Matteo De Wint
21c0c05130 [Fix] nvm_die_on_prefix: only grep lines starting with env var name 2020-11-16 11:35:26 +01:00
Alex Aubuchon
00af6341f7 [Tests] Run fast test suite in clean environment 2020-11-03 19:05:34 -05:00
Jordan Harband
11a9d22607 [actions] add "Allow Edits" workflow 2020-11-06 23:56:55 -08:00
Jordan Harband
bbe032fa7e [actions] switch Automatic Rebase workflow to pull_request_target event 2020-11-06 23:55:52 -08:00
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
59 changed files with 1729 additions and 428 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

50
.github/workflows/latest-npm.yml vendored Normal file
View File

@@ -0,0 +1,50 @@
name: 'Tests: `nvm install-latest-npm`'
on: [pull_request, push]
jobs:
nodes:
name: 'nvm install-latest-npm'
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- "11"
- "10"
- "9"
- "9.2"
- "9.1"
- "9.0"
- "8"
- "7"
- "6"
- "6.1"
- "5"
- "5.9"
- "4"
- "4.6"
- "4.5"
- "4.4"
- "3"
- "2"
- "1"
- "0.12"
- "0.10"
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'nvm install-latest-npm'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
skip-install: true
shell-command: 'npm --version'
node:
name: 'nvm install-latest-npm'
needs: [nodes]
runs-on: ubuntu-latest
steps:
- run: 'echo tests completed'

38
.github/workflows/lint.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
name: 'Tests: linting'
on: [pull_request, push]
jobs:
eclint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run eclint'
with:
node-version: 'lts/*'
command: 'eclint'
dockerfile_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run dockerfile_lint'
with:
node-version: 'lts/*'
command: 'dockerfile_lint'
doctoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run dockerfile_lint'
with:
node-version: 'lts/*'
shell-command: |
set -e
cp README.md README.md.orig
npm run doctoc
diff -q README.md README.md.orig

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

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

24
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: 'Tests: release process'
on: [pull_request, push]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "14"
- run: npm install
- name: Configure git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git fetch --unshallow --tags || git fetch --tags
- name: Attempt `make release` process
run: echo proceed | make TAG=99.99.99 release
env:
GIT_EDITOR: "sed -i '1 s/^/99.99.99 make release test/'"
- name: Ensure tag is created
run: git tag | grep v99.99.99

View File

@@ -0,0 +1,14 @@
name: Require “Allow Edits”
on: [pull_request_target]
jobs:
_:
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- uses: ljharb/require-allow-edits@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

31
.github/workflows/shellcheck.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: 'Tests: shellcheck'
on: [pull_request, push]
jobs:
shellcheck:
runs-on: ubuntu-latest
strategy:
matrix:
shell:
- bash
- sh
- dash
- ksh
file:
- nvm.sh
include:
- shell: bash
file: install.sh # only supported on bash
- shell: bash
file: bash_completion # only needed in bash/zsh
- shell: bash
file: nvm-exec # only runs in bash
steps:
- uses: actions/checkout@v2
- name: Install shellcheck
run: brew install shellcheck
- run: "shellcheck --version"
- name: Run shellcheck on ${{ matrix.file }}
run: shellcheck -s ${{ matrix.shell }} ${{ matrix.file }}

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:
@@ -19,21 +18,13 @@ before_install:
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
- curl --version
- wget --version
- shellcheck --version
install:
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
script:
- if [ -n "${MAKE_RELEASE-}" ]; then export GIT_EDITOR="sed -i '1 s/^/99.99.99 make release test/'" && git fetch --unshallow --tags && echo proceed | make TAG=99.99.99 release ; fi
- if [ -n "${DOCTOCCHECK-}" ]; then cp README.md README.md.orig && npm run doctoc && diff -q README.md README.md.orig ; fi
- if [ -n "${ECLINT-}" ]; then npm run eclint ; fi
- if [ -n "${DOCKERFILE_LINT-}" ]; then npm run dockerfile_lint ; fi
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash nvm.sh && shellcheck -s sh nvm.sh && shellcheck -s dash nvm.sh && shellcheck -s ksh nvm.sh ; fi
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash install.sh bash_completion nvm-exec ; fi
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi
before_cache:
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
- if [ -n "${NODE-}" ]; then . nvm.sh && set -ex && nvm install --latest-npm "${NODE}" && npm --version; fi
env:
global:
- CXX=g++
@@ -42,27 +33,22 @@ env:
- PATH="/usr/lib/ccache/:$PATH"
- NVM_DIR="${TRAVIS_BUILD_DIR}"
matrix:
- MAKE_RELEASE=true
- DOCTOCCHECK=true
- SHELLCHECK=true
- ECLINT=true
- DOCKERFILE_LINT=true
- SHELL=bash TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast
- SHELL=zsh TEST_SUITE=fast
# - SHELL=ksh TEST_SUITE=fast
# - SHELL=ksh TEST_SUITE=fast
- SHELL=sh TEST_SUITE=sourcing
- SHELL=dash TEST_SUITE=sourcing
- SHELL=bash TEST_SUITE=sourcing
- SHELL=zsh TEST_SUITE=sourcing
# - SHELL=ksh TEST_SUITE=sourcing
# - SHELL=ksh TEST_SUITE=sourcing
- SHELL=sh TEST_SUITE=slow
- SHELL=dash TEST_SUITE=slow
- SHELL=bash TEST_SUITE=slow
- SHELL=zsh TEST_SUITE=slow
# - SHELL=ksh TEST_SUITE=slow
# - SHELL=ksh TEST_SUITE=slow
- SHELL=sh TEST_SUITE=installation_node
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation_node
@@ -71,8 +57,8 @@ env:
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation_node
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_node
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_node
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
- SHELL=sh TEST_SUITE=installation_iojs
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation_iojs
@@ -81,17 +67,5 @@ env:
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation_iojs
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_iojs
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
- NODE=10 TEST="nvm install-latest-npm"
- NODE=9 TEST="nvm install-latest-npm"
- NODE=8 TEST="nvm install-latest-npm"
- NODE=7 TEST="nvm install-latest-npm"
- NODE=6 TEST="nvm install-latest-npm"
- NODE=5 TEST="nvm install-latest-npm"
- NODE=5.9 TEST="nvm install-latest-npm"
- NODE=4 TEST="nvm install-latest-npm"
- NODE=4.6 TEST="nvm install-latest-npm"
- NODE=4.5 TEST="nvm install-latest-npm"
- NODE=4.4 TEST="nvm install-latest-npm"
- NODE=2 TEST="nvm install-latest-npm"
# - SHELL=ksh TEST_SUITE=installation_iojs
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1

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

158
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.1-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 -->
@@ -24,6 +24,8 @@
- [io.js](#iojs)
- [System Version of Node](#system-version-of-node)
- [Listing Versions](#listing-versions)
- [Setting Custom Colors](#setting-custom-colors)
- [Persisting custom colors](#persisting-custom-colors)
- [Suppressing colorized output](#suppressing-colorized-output)
- [.nvmrc](#nvmrc)
- [Deeper Shell Integration](#deeper-shell-integration)
@@ -31,8 +33,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 +61,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.1/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.1/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 +96,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 +114,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.1/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
```
@@ -169,7 +176,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.1`
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 +292,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:
@@ -369,12 +382,48 @@ If you want to see what versions are available to install:
nvm ls-remote
```
### Setting Custom Colors
You can set five colors that will be used to display version and alias information. These colors replace the default colors.
Initial colors are: g b y r e
Color codes:
r/R = red / bold red
g/G = green / bold green
b/B = blue / bold blue
c/C = cyan / bold cyan
m/M = magenta / bold magenta
y/Y = yellow / bold yellow
k/K = black / bold black
e/W = light grey / white
```sh
nvm set-colors rgBcm
```
#### Persisting custom colors
If you want the custom colors to persist after terminating the shell, export the NVM_COLORS variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line:
```sh
export NVM_COLORS='cmgRY'
```
#### Suppressing colorized output
`nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
`nvm help (or -h or --help)`, `nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
```sh
nvm ls --no-colors
nvm help --no-colors
TERM=dumb nvm ls
```
@@ -425,6 +474,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
@@ -450,7 +501,7 @@ If you prefer a lighter-weight solution, the recipes below have been contributed
Put the following at the end of your `$HOME/.bashrc`:
```bash
find-up () {
find-up() {
path=$(pwd)
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
path=${path%/*}
@@ -458,9 +509,9 @@ find-up () {
echo "$path"
}
cdnvm(){
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 +552,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 +588,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 +663,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 +692,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 +760,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.1/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 +846,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.1/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.1
[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.1"
}
nvm_profile_is_bash_or_zsh() {

911
nvm.sh

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,13 @@
{
"name": "nvm",
"version": "0.35.3",
"version": "0.37.1",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
},
"scripts": {
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); env -i TERM=\"$TERM\" bash -lc \"make TEST_SUITE=fast test-$shell\"",
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",
@@ -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,25 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
echo "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e
nvm_get_colors(){
echo "0;95m"
}
nvm_alias_path() {
nvm_echo "../../../alias"
}
OUTPUT=$(command printf %b $(nvm_list_aliases test-stable-1) | awk '{ print substr($0, 1, 19); }')
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }')
echo "\033[0m"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die

View File

@@ -0,0 +1,28 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
# echo "$@" ;
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e
nvm_get_colors(){
echo "0;95m"
}
# nvm_print_alias_path call nvm_print_formatted_alias which calls nvm_get-colors
# the output of nvm_print_alias_path uses the color code returned by nvm_get_colors (redefined above)
NVM_ALIAS_DIR='../../../alias'
OUTPUT=$(command printf %b $(nvm_print_alias_path "$NVM_ALIAS_DIR" "$NVM_ALIAS_DIR"/test-stable-1) | awk '{ print substr($0, 1, 24); }')
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1\033[0m")
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
set +e

View File

@@ -0,0 +1,21 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e
# # # expecting in red and two grays:
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
EXPECTED_OUTPUT="$(command printf %b "\033[0;31mfakealias\033[0m ")"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
# expecting in bold yellow and two grays:
nvm set-colors bbbYb
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
EXPECTED_OUTPUT="$(command printf %b "\033[1;33mfakealias\033[0m ")"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die

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

@@ -27,7 +27,9 @@ EXPECTED_OUTPUT="$(nvm_add_iojs_prefix ${VERSION})"
nvm use --delete-prefix iojs || die '`nvm use iojs` failed'
CURRENT="$(nvm current)"
# Remove node_modules/.bin from the path so that the system version `which` is
# used in nvm_ls_current
PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") CURRENT="$(nvm current)"
echo "current: ${CURRENT}"
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"

View File

@@ -0,0 +1,21 @@
#!/bin/sh
set -ex
die () {
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
cleanup() {
echo "Tested nvm_echo_with_colors"
}
\. ../../../nvm.sh
OUTPUT="$(nvm_echo_with_colors "\033[0;36mCyan-colored text")"
EXPECTED_OUTPUT=$(printf "\033[0;36mCyan-colored text")
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die
cleanup

View File

@@ -0,0 +1,19 @@
#!/bin/sh
set -ex
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
echo "Tested nvm_err_with_colors"
}
\. ../../../nvm.sh
set +ex
OUTPUT="$(nvm_err_with_colors "\033[0;35mMagenta-colored text" 2>&1)"
set -ex
EXPECTED_OUTPUT=$(printf "\033[0;35mMagenta-colored text")
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die
cleanup

View File

@@ -0,0 +1,24 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
# echo "$@" ;
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e
nvm_get_colors(){
echo "0;95m"
}
# nvm_print_default_alias call nvm_print_formatted_alias which calls nvm_get-colors
# the output of nvm_print_default_alias uses the color code returned by nvm_get_colors (redefined above)
OUTPUT=$(command printf %b $(nvm_print_default_alias node ./alias v14.7.0) | awk '{ print substr($0, 1, 11); }')
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mnode")
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
set +e

View File

@@ -0,0 +1,52 @@
#!/bin/sh
\. ../../../nvm.sh
set -e
die () {
# echo "$@" ;
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
cleanup() {
if [ -n TEMP_NVM_COLORS ]; then
export NVM_COLORS=TEMP_NVM_COLORS
fi
unset TEMP_NVM_COLORS
}
if [ -n ${NVM_COLORS} ]; then
export TEMP_NVM_COLORS=NVM_COLORS
unset NVM_COLORS
fi
# default system color
nvm use system
OUTPUT=$(nvm_print_versions system)
FORMAT="\033[0;32m-> %12s\033[0m"
VERSION='system'
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
nvm_ls_current() { echo "current";}
# default current color
OUTPUT=$(nvm_print_versions current)
FORMAT="\033[0;32m-> %12s\033[0m"
VERSION="current"
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
# custom current color
nvm set-colors YCMGR
OUTPUT=$(nvm_print_versions current)
FORMAT="\033[1;35m-> %12s\033[0m"
VERSION="current"
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
cleanup

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

@@ -6,9 +6,17 @@ die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs
if [ -n TEMP_NVM_COLORS ]; then
export NVM_COLORS=TEMP_NVM_COLORS
fi
unset TEMP_NVM_COLORS
}
\. ../../../nvm.sh
if [ -n ${NVM_COLORS} ]; then
export TEMP_NVM_COLORS=NVM_COLORS
unset NVM_COLORS
fi
nvm deactivate 2>/dev/null || die 'unable to deactivate'

View File

@@ -0,0 +1,52 @@
#!/bin/sh
set -ex
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
unset NVM_COLORS
unset -f nvm_has_colors
if [ -n TEMP_NVM_COLORS ]; then
export NVM_COLORS=TEMP_NVM_COLORS
fi
unset TEMP_NVM_COLORS
}
\. ../../../nvm.sh
# NVM_COLORS is not set
if [ -n ${NVM_COLORS} ]; then
export TEMP_NVM_COLORS=NVM_COLORS
unset NVM_COLORS
fi
# test valid setting colors/
nvm set-colors rgbyc
OUTPUT="${NVM_COLORS}"
EXPECTED_OUTPUT="rgbyc"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_SET_COLORS failed with valid input; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
# test invalid 4 colors
set +ex
OUTPUT="$(echo $(nvm set-colors rgby 2>&1) | awk '{ print substr($0, length($0)-92, 93); }')"
EXPECTED_OUTPUT="$(command printf %b "\033[1;37mPlease pass in five \033[1;31mvalid color codes\033[1;37m. Choose from: rRgGbBcCyYmMkKeW\033[0m")"
set -ex
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_SET_COLORS did not fail with invalid input; got >${OUTPUT}, < expected >${EXPECTED_OUTPUT}<"
# test invalid color codes
set +ex
OUTPUT="$(echo $(nvm set-colors p3gq7 2>&1) | awk '{ print substr($0, length($0)-92, 93); }')"
EXPECTED_OUTPUT="$(command printf %b "\033[1;37mPlease pass in five \033[1;31mvalid color codes\033[1;37m. Choose from: rRgGbBcCyYmMkKeW\033[0m")"
set -ex
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_SET_COLORS did not fail with invalid input; got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
#test system does not support at least 8 colors
nvm_has_colors() { return 1; }
set +ex
OUTPUT="$(echo $(nvm set-colors mcyGb 2>&1) | awk '{ print substr($0, length($0)-76, 77); }')"
set -ex
EXPECTED_OUTPUT="WARNING: Colors may not display because they are not supported in this shell."
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_SET_COLORS did not recognize lack of color support; got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
cleanup

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,158 @@ 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'"
OUTPUT="$(export FOO='NPM_CONFIG_PREFIX' ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop; got '$OUTPUT'"
# 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

@@ -0,0 +1,79 @@
#!/bin/sh
set -ex
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
unset NVM_COLORS
if [ -n TEMP_NVM_COLORS ]; then
export NVM_COLORS=TEMP_NVM_COLORS
fi
unset TEMP_NVM_COLORS
}
\. ../../../nvm.sh
# NVM_COLORS is not set
if [ -n ${NVM_COLORS} ]; then
export TEMP_NVM_COLORS=NVM_COLORS
unset NVM_COLORS
fi
OUTPUT=$(nvm_get_colors 1)
EXPECTED_OUTPUT='0;34m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (INSTALLED_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 2)
EXPECTED_OUTPUT='0;33m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (SYSTEM_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 3)
EXPECTED_OUTPUT='0;32m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (CURRENT_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 4)
EXPECTED_OUTPUT='0;31m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (NOT_INSTALLED_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 5)
EXPECTED_OUTPUT='0;37m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (DEFAULT_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 6)
EXPECTED_OUTPUT='1;33m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (LTS_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
# bad parameter
set +ex # needed for stderr
OUTPUT=$(nvm_get_colors bad 2>&1)
set -ex
EXPECTED_OUTPUT="Invalid color index, bad"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors did not have an error with bad output; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
# NVM_COLORS is set
nvm set-colors rgbyc
OUTPUT=$(nvm_get_colors 1)
EXPECTED_OUTPUT='0;31m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (INSTALLED_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 2)
EXPECTED_OUTPUT='0;32m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (SYSTEM_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 3)
EXPECTED_OUTPUT='0;34m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (CURRENT_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 4)
EXPECTED_OUTPUT='0;33m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (NOT_INSTALLED_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 5)
EXPECTED_OUTPUT='0;36m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (DEFAULT_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
OUTPUT=$(nvm_get_colors 6)
EXPECTED_OUTPUT='1;32m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_colors failed to return default color (LTS_COLOR); got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
cleanup

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

@@ -0,0 +1,20 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
# Testing valid input
OUTPUT=$(nvm_print_color_code m)
EXPECTED_OUTPUT='0;35m'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_color_code returned wrong code; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
# Testing invalid input
set +x # needed for stderr
OUTPUT="$(nvm_print_color_code q 2>&1)" ||:
set -x
echo "OUTPUT WAS SET TO: $OUTPUT"
EXPECTED_OUTPUT="Invalid color code"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_color_code did not recognize the invalid input; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"

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'"