Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
661a702cdd | ||
|
|
510b2fd44c | ||
|
|
80a4e06af9 | ||
|
|
22902f04a3 | ||
|
|
6848c16d53 | ||
|
|
3abb98124e | ||
|
|
21c0c05130 | ||
|
|
00af6341f7 | ||
|
|
11a9d22607 | ||
|
|
bbe032fa7e | ||
|
|
4054bd70ce | ||
|
|
499d303746 | ||
|
|
31bc0a13c2 | ||
|
|
c72f2c6f21 | ||
|
|
f2c5ce459a | ||
|
|
0f0d5e8270 | ||
|
|
e77ed07ccc | ||
|
|
e01060fa2c | ||
|
|
96069da0d5 | ||
|
|
4436638816 | ||
|
|
344cc32ac3 | ||
|
|
7929190e6e |
50
.github/workflows/latest-npm.yml
vendored
Normal file
50
.github/workflows/latest-npm.yml
vendored
Normal 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
38
.github/workflows/lint.yml
vendored
Normal 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
|
||||||
2
.github/workflows/rebase.yml
vendored
2
.github/workflows/rebase.yml
vendored
@@ -1,6 +1,6 @@
|
|||||||
name: Automatic Rebase
|
name: Automatic Rebase
|
||||||
|
|
||||||
on: [pull_request]
|
on: [pull_request_target]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
_:
|
_:
|
||||||
|
|||||||
24
.github/workflows/release.yml
vendored
Normal file
24
.github/workflows/release.yml
vendored
Normal 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
|
||||||
14
.github/workflows/require-allow-edits.yml
vendored
Normal file
14
.github/workflows/require-allow-edits.yml
vendored
Normal 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
31
.github/workflows/shellcheck.yml
vendored
Normal 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 }}
|
||||||
40
.travis.yml
40
.travis.yml
@@ -1,6 +1,5 @@
|
|||||||
language: generic
|
language: generic
|
||||||
dist: xenial
|
dist: xenial
|
||||||
sudo: required
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
@@ -19,21 +18,13 @@ before_install:
|
|||||||
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
||||||
- curl --version
|
- curl --version
|
||||||
- wget --version
|
- wget --version
|
||||||
- shellcheck --version
|
|
||||||
install:
|
install:
|
||||||
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
|
- 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'
|
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
|
||||||
script:
|
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
|
- 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:
|
before_cache:
|
||||||
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
|
- 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:
|
env:
|
||||||
global:
|
global:
|
||||||
- CXX=g++
|
- CXX=g++
|
||||||
@@ -42,27 +33,22 @@ env:
|
|||||||
- PATH="/usr/lib/ccache/:$PATH"
|
- PATH="/usr/lib/ccache/:$PATH"
|
||||||
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
||||||
matrix:
|
matrix:
|
||||||
- MAKE_RELEASE=true
|
|
||||||
- DOCTOCCHECK=true
|
|
||||||
- SHELLCHECK=true
|
|
||||||
- ECLINT=true
|
|
||||||
- DOCKERFILE_LINT=true
|
|
||||||
- SHELL=bash TEST_SUITE=install_script
|
- SHELL=bash TEST_SUITE=install_script
|
||||||
- SHELL=sh TEST_SUITE=fast
|
- SHELL=sh TEST_SUITE=fast
|
||||||
- SHELL=dash TEST_SUITE=fast
|
- SHELL=dash TEST_SUITE=fast
|
||||||
- SHELL=bash TEST_SUITE=fast
|
- SHELL=bash TEST_SUITE=fast
|
||||||
- SHELL=zsh TEST_SUITE=fast
|
- SHELL=zsh TEST_SUITE=fast
|
||||||
# - SHELL=ksh TEST_SUITE=fast
|
# - SHELL=ksh TEST_SUITE=fast
|
||||||
- SHELL=sh TEST_SUITE=sourcing
|
- SHELL=sh TEST_SUITE=sourcing
|
||||||
- SHELL=dash TEST_SUITE=sourcing
|
- SHELL=dash TEST_SUITE=sourcing
|
||||||
- SHELL=bash TEST_SUITE=sourcing
|
- SHELL=bash TEST_SUITE=sourcing
|
||||||
- SHELL=zsh TEST_SUITE=sourcing
|
- SHELL=zsh TEST_SUITE=sourcing
|
||||||
# - SHELL=ksh TEST_SUITE=sourcing
|
# - SHELL=ksh TEST_SUITE=sourcing
|
||||||
- SHELL=sh TEST_SUITE=slow
|
- SHELL=sh TEST_SUITE=slow
|
||||||
- SHELL=dash TEST_SUITE=slow
|
- SHELL=dash TEST_SUITE=slow
|
||||||
- SHELL=bash TEST_SUITE=slow
|
- SHELL=bash TEST_SUITE=slow
|
||||||
- SHELL=zsh 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
|
||||||
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
- SHELL=dash TEST_SUITE=installation_node
|
- SHELL=dash TEST_SUITE=installation_node
|
||||||
@@ -71,8 +57,8 @@ env:
|
|||||||
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
- SHELL=zsh TEST_SUITE=installation_node
|
- SHELL=zsh TEST_SUITE=installation_node
|
||||||
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
# - SHELL=ksh TEST_SUITE=installation_node
|
# - SHELL=ksh TEST_SUITE=installation_node
|
||||||
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||||
- SHELL=sh TEST_SUITE=installation_iojs
|
- SHELL=sh TEST_SUITE=installation_iojs
|
||||||
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
- SHELL=dash TEST_SUITE=installation_iojs
|
- SHELL=dash TEST_SUITE=installation_iojs
|
||||||
@@ -81,17 +67,5 @@ env:
|
|||||||
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
- SHELL=zsh TEST_SUITE=installation_iojs
|
- SHELL=zsh TEST_SUITE=installation_iojs
|
||||||
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||||
# - SHELL=ksh TEST_SUITE=installation_iojs
|
# - SHELL=ksh TEST_SUITE=installation_iojs
|
||||||
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
# - 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"
|
|
||||||
|
|||||||
@@ -6,8 +6,6 @@
|
|||||||
# 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
|
|
||||||
# I also tested with Ubuntu 16.04, should be good with it!
|
|
||||||
FROM ubuntu:16.04
|
FROM ubuntu:16.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"
|
||||||
@@ -66,7 +64,6 @@ 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://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 && \
|
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
|
||||||
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
||||||
|
|||||||
61
README.md
61
README.md
@@ -1,4 +1,4 @@
|
|||||||
# Node Version Manager [][3] [][4] [](https://bestpractices.coreinfrastructure.org/projects/684)
|
# Node Version Manager [][3] [][4] [](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 -->
|
||||||
@@ -24,6 +24,8 @@
|
|||||||
- [io.js](#iojs)
|
- [io.js](#iojs)
|
||||||
- [System Version of Node](#system-version-of-node)
|
- [System Version of Node](#system-version-of-node)
|
||||||
- [Listing Versions](#listing-versions)
|
- [Listing Versions](#listing-versions)
|
||||||
|
- [Setting Custom Colors](#setting-custom-colors)
|
||||||
|
- [Persisting custom colors](#persisting-custom-colors)
|
||||||
- [Suppressing colorized output](#suppressing-colorized-output)
|
- [Suppressing colorized output](#suppressing-colorized-output)
|
||||||
- [.nvmrc](#nvmrc)
|
- [.nvmrc](#nvmrc)
|
||||||
- [Deeper Shell Integration](#deeper-shell-integration)
|
- [Deeper Shell Integration](#deeper-shell-integration)
|
||||||
@@ -59,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:
|
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.36.0/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash
|
||||||
```
|
```
|
||||||
```sh
|
```sh
|
||||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/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`).
|
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`).
|
||||||
@@ -115,7 +117,7 @@ You can use a task:
|
|||||||
```yaml
|
```yaml
|
||||||
- name: nvm
|
- name: nvm
|
||||||
shell: >
|
shell: >
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash
|
||||||
args:
|
args:
|
||||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||||
```
|
```
|
||||||
@@ -174,7 +176,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.36.0`
|
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`
|
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:
|
||||||
@@ -380,12 +382,48 @@ If you want to see what versions are available to install:
|
|||||||
nvm ls-remote
|
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
|
#### 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
|
```sh
|
||||||
nvm ls --no-colors
|
nvm ls --no-colors
|
||||||
|
nvm help --no-colors
|
||||||
TERM=dumb nvm ls
|
TERM=dumb nvm ls
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -463,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`:
|
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%/*}
|
||||||
@@ -471,7 +509,7 @@ find-up () {
|
|||||||
echo "$path"
|
echo "$path"
|
||||||
}
|
}
|
||||||
|
|
||||||
cdnvm(){
|
cdnvm() {
|
||||||
cd "$@";
|
cd "$@";
|
||||||
nvm_path=$(find-up .nvmrc | tr -d '\n')
|
nvm_path=$(find-up .nvmrc | tr -d '\n')
|
||||||
|
|
||||||
@@ -514,6 +552,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.
|
||||||
@@ -721,7 +760,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.36.0/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.
|
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
|
||||||
@@ -818,8 +857,8 @@ You have to make sure that the user directory name in `$HOME` and the user direc
|
|||||||
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
|
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.36.0/install.sh
|
[2]: https://github.com/nvm-sh/nvm/blob/v0.37.1/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.36.0
|
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.1
|
||||||
[Urchin]: https://github.com/scraperwiki/urchin
|
[Urchin]: https://github.com/scraperwiki/urchin
|
||||||
[Fish]: http://fishshell.com
|
[Fish]: http://fishshell.com
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ nvm_install_dir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_latest_version() {
|
nvm_latest_version() {
|
||||||
echo "v0.36.0"
|
echo "v0.37.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_profile_is_bash_or_zsh() {
|
nvm_profile_is_bash_or_zsh() {
|
||||||
|
|||||||
358
nvm.sh
358
nvm.sh
@@ -24,6 +24,10 @@ nvm_echo() {
|
|||||||
command printf %s\\n "$*" 2>/dev/null
|
command printf %s\\n "$*" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_echo_with_colors() {
|
||||||
|
command printf %b\\n "$*" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
nvm_cd() {
|
nvm_cd() {
|
||||||
\cd "$@"
|
\cd "$@"
|
||||||
}
|
}
|
||||||
@@ -32,6 +36,10 @@ nvm_err() {
|
|||||||
>&2 nvm_echo "$@"
|
>&2 nvm_echo "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_err_with_colors() {
|
||||||
|
>&2 nvm_echo_with_colors "$@"
|
||||||
|
}
|
||||||
|
|
||||||
nvm_grep() {
|
nvm_grep() {
|
||||||
GREP_OPTIONS='' command grep "$@"
|
GREP_OPTIONS='' command grep "$@"
|
||||||
}
|
}
|
||||||
@@ -70,11 +78,11 @@ nvm_command_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nvm_has_colors() {
|
nvm_has_colors() {
|
||||||
local NVM_COLORS
|
local NVM_NUM_COLORS
|
||||||
if nvm_has tput; then
|
if nvm_has tput; then
|
||||||
NVM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
|
NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
|
||||||
fi
|
fi
|
||||||
[ "${NVM_COLORS:--1}" -ge 8 ]
|
[ "${NVM_NUM_COLORS:--1}" -ge 8 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_curl_libz_support() {
|
nvm_curl_libz_support() {
|
||||||
@@ -713,6 +721,92 @@ nvm_binary_available() {
|
|||||||
nvm_version_greater_than_or_equal_to "$(nvm_strip_iojs_prefix "${1-}")" v0.8.6
|
nvm_version_greater_than_or_equal_to "$(nvm_strip_iojs_prefix "${1-}")" v0.8.6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_set_colors() {
|
||||||
|
if [ "${#1}" -eq 5 ] && nvm_echo "$1" | nvm_grep -E "^[rRgGbBcCyYmMkKeW]{1,}$" 1>/dev/null; then
|
||||||
|
local INSTALLED_COLOR
|
||||||
|
local LTS_AND_SYSTEM_COLOR
|
||||||
|
local CURRENT_COLOR
|
||||||
|
local NOT_INSTALLED_COLOR
|
||||||
|
local DEFAULT_COLOR
|
||||||
|
|
||||||
|
INSTALLED_COLOR="$(echo "$1" | awk '{ print substr($0, 1, 1); }')"
|
||||||
|
LTS_AND_SYSTEM_COLOR="$(echo "$1" | awk '{ print substr($0, 2, 1); }')"
|
||||||
|
CURRENT_COLOR="$(echo "$1" | awk '{ print substr($0, 3, 1); }')"
|
||||||
|
NOT_INSTALLED_COLOR="$(echo "$1" | awk '{ print substr($0, 4, 1); }')"
|
||||||
|
DEFAULT_COLOR="$(echo "$1" | awk '{ print substr($0, 5, 1); }')"
|
||||||
|
if ! nvm_has_colors; then
|
||||||
|
nvm_echo "Setting colors to: ${INSTALLED_COLOR} ${LTS_AND_SYSTEM_COLOR} ${CURRENT_COLOR} ${NOT_INSTALLED_COLOR} ${DEFAULT_COLOR}"
|
||||||
|
nvm_echo "WARNING: Colors may not display because they are not supported in this shell."
|
||||||
|
else
|
||||||
|
nvm_echo_with_colors "Setting colors to: \033[$(nvm_print_color_code "${INSTALLED_COLOR}") ${INSTALLED_COLOR}\033[$(nvm_print_color_code "${LTS_AND_SYSTEM_COLOR}") ${LTS_AND_SYSTEM_COLOR}\033[$(nvm_print_color_code "${CURRENT_COLOR}") ${CURRENT_COLOR}\033[$(nvm_print_color_code "${NOT_INSTALLED_COLOR}") ${NOT_INSTALLED_COLOR}\033[$(nvm_print_color_code "${DEFAULT_COLOR}") ${DEFAULT_COLOR}\033[0m"
|
||||||
|
fi
|
||||||
|
export NVM_COLORS="$1"
|
||||||
|
else
|
||||||
|
return 17
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_get_colors() {
|
||||||
|
local COLOR
|
||||||
|
local SYS_COLOR
|
||||||
|
if [ -n "${NVM_COLORS-}" ]; then
|
||||||
|
case $1 in
|
||||||
|
1) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 1, 1); }')");;
|
||||||
|
2) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 2, 1); }')");;
|
||||||
|
3) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 3, 1); }')");;
|
||||||
|
4) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 4, 1); }')");;
|
||||||
|
5) COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 5, 1); }')");;
|
||||||
|
6)
|
||||||
|
SYS_COLOR=$(nvm_print_color_code "$(echo "$NVM_COLORS" | awk '{ print substr($0, 2, 1); }')")
|
||||||
|
COLOR=$(nvm_echo "$SYS_COLOR" | command tr '0;' '1;')
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
nvm_err "Invalid color index, ${1-}"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
case $1 in
|
||||||
|
1) COLOR='0;34m';;
|
||||||
|
2) COLOR='0;33m';;
|
||||||
|
3) COLOR='0;32m';;
|
||||||
|
4) COLOR='0;31m';;
|
||||||
|
5) COLOR='0;37m';;
|
||||||
|
6) COLOR='1;33m';;
|
||||||
|
*)
|
||||||
|
nvm_err "Invalid color index, ${1-}"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$COLOR"
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_print_color_code() {
|
||||||
|
case "${1-}" in
|
||||||
|
r) nvm_echo '0;31m';;
|
||||||
|
R) nvm_echo '1;31m';;
|
||||||
|
g) nvm_echo '0;32m';;
|
||||||
|
G) nvm_echo '1;32m';;
|
||||||
|
b) nvm_echo '0;34m';;
|
||||||
|
B) nvm_echo '1;34m';;
|
||||||
|
c) nvm_echo '0;36m';;
|
||||||
|
C) nvm_echo '1;36m';;
|
||||||
|
m) nvm_echo '0;35m';;
|
||||||
|
M) nvm_echo '1;35m';;
|
||||||
|
y) nvm_echo '0;33m';;
|
||||||
|
Y) nvm_echo '1;33m';;
|
||||||
|
k) nvm_echo '0;30m';;
|
||||||
|
K) nvm_echo '1;30m';;
|
||||||
|
e) nvm_echo '0;37m';;
|
||||||
|
W) nvm_echo '1;37m';;
|
||||||
|
*) nvm_err 'Invalid color code';
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
nvm_print_formatted_alias() {
|
nvm_print_formatted_alias() {
|
||||||
local ALIAS
|
local ALIAS
|
||||||
ALIAS="${1-}"
|
ALIAS="${1-}"
|
||||||
@@ -726,6 +820,21 @@ nvm_print_formatted_alias() {
|
|||||||
local VERSION_FORMAT
|
local VERSION_FORMAT
|
||||||
local ALIAS_FORMAT
|
local ALIAS_FORMAT
|
||||||
local DEST_FORMAT
|
local DEST_FORMAT
|
||||||
|
|
||||||
|
local INSTALLED_COLOR
|
||||||
|
local SYSTEM_COLOR
|
||||||
|
local CURRENT_COLOR
|
||||||
|
local NOT_INSTALLED_COLOR
|
||||||
|
local DEFAULT_COLOR
|
||||||
|
local LTS_COLOR
|
||||||
|
|
||||||
|
INSTALLED_COLOR=$(nvm_get_colors 1)
|
||||||
|
SYSTEM_COLOR=$(nvm_get_colors 2)
|
||||||
|
CURRENT_COLOR=$(nvm_get_colors 3)
|
||||||
|
NOT_INSTALLED_COLOR=$(nvm_get_colors 4)
|
||||||
|
DEFAULT_COLOR=$(nvm_get_colors 5)
|
||||||
|
LTS_COLOR=$(nvm_get_colors 6)
|
||||||
|
|
||||||
ALIAS_FORMAT='%s'
|
ALIAS_FORMAT='%s'
|
||||||
DEST_FORMAT='%s'
|
DEST_FORMAT='%s'
|
||||||
VERSION_FORMAT='%s'
|
VERSION_FORMAT='%s'
|
||||||
@@ -739,26 +848,26 @@ nvm_print_formatted_alias() {
|
|||||||
if [ -z "${NVM_NO_COLORS}" ] && nvm_has_colors; then
|
if [ -z "${NVM_NO_COLORS}" ] && nvm_has_colors; then
|
||||||
ARROW='\033[0;90m->\033[0m'
|
ARROW='\033[0;90m->\033[0m'
|
||||||
if [ "_${DEFAULT}" = '_true' ]; then
|
if [ "_${DEFAULT}" = '_true' ]; then
|
||||||
NEWLINE=' \033[0;37m(default)\033[0m\n'
|
NEWLINE=" \033[${DEFAULT_COLOR}(default)\033[0m\n"
|
||||||
fi
|
fi
|
||||||
if [ "_${VERSION}" = "_${NVM_CURRENT-}" ]; then
|
if [ "_${VERSION}" = "_${NVM_CURRENT-}" ]; then
|
||||||
ALIAS_FORMAT='\033[0;32m%s\033[0m'
|
ALIAS_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||||
DEST_FORMAT='\033[0;32m%s\033[0m'
|
DEST_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||||
VERSION_FORMAT='\033[0;32m%s\033[0m'
|
VERSION_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||||
elif nvm_is_version_installed "${VERSION}"; then
|
elif nvm_is_version_installed "${VERSION}"; then
|
||||||
ALIAS_FORMAT='\033[0;34m%s\033[0m'
|
ALIAS_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||||
DEST_FORMAT='\033[0;34m%s\033[0m'
|
DEST_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||||
VERSION_FORMAT='\033[0;34m%s\033[0m'
|
VERSION_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||||
elif [ "${VERSION}" = '∞' ] || [ "${VERSION}" = 'N/A' ]; then
|
elif [ "${VERSION}" = '∞' ] || [ "${VERSION}" = 'N/A' ]; then
|
||||||
ALIAS_FORMAT='\033[1;31m%s\033[0m'
|
ALIAS_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||||
DEST_FORMAT='\033[1;31m%s\033[0m'
|
DEST_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||||
VERSION_FORMAT='\033[1;31m%s\033[0m'
|
VERSION_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||||
fi
|
fi
|
||||||
if [ "_${NVM_LTS-}" = '_true' ]; then
|
if [ "_${NVM_LTS-}" = '_true' ]; then
|
||||||
ALIAS_FORMAT='\033[1;33m%s\033[0m'
|
ALIAS_FORMAT="\033[${LTS_COLOR}%s\033[0m"
|
||||||
fi
|
fi
|
||||||
if [ "_${DEST%/*}" = "_lts" ]; then
|
if [ "_${DEST%/*}" = "_lts" ]; then
|
||||||
DEST_FORMAT='\033[1;33m%s\033[0m'
|
DEST_FORMAT="\033[${LTS_COLOR}%s\033[0m"
|
||||||
fi
|
fi
|
||||||
elif [ "_${VERSION}" != '_∞' ] && [ "_${VERSION}" != '_N/A' ]; then
|
elif [ "_${VERSION}" != '_∞' ] && [ "_${VERSION}" != '_N/A' ]; then
|
||||||
VERSION_FORMAT='%s *'
|
VERSION_FORMAT='%s *'
|
||||||
@@ -1089,6 +1198,7 @@ nvm_ls() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
nvm_is_zsh && setopt local_options shwordsplit
|
nvm_is_zsh && setopt local_options shwordsplit
|
||||||
|
nvm_is_zsh && unsetopt local_options markdirs
|
||||||
|
|
||||||
local NVM_DIRS_TO_SEARCH1
|
local NVM_DIRS_TO_SEARCH1
|
||||||
NVM_DIRS_TO_SEARCH1=''
|
NVM_DIRS_TO_SEARCH1=''
|
||||||
@@ -1239,6 +1349,10 @@ nvm_ls_remote_index_tab() {
|
|||||||
local PATTERN
|
local PATTERN
|
||||||
PATTERN="${3-}"
|
PATTERN="${3-}"
|
||||||
|
|
||||||
|
if [ "${PATTERN#"${PATTERN%?}"}" = '.' ]; then
|
||||||
|
PATTERN="${PATTERN%.}"
|
||||||
|
fi
|
||||||
|
|
||||||
local VERSIONS
|
local VERSIONS
|
||||||
if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
|
if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
|
||||||
if [ "${FLAVOR}" = 'iojs' ]; then
|
if [ "${FLAVOR}" = 'iojs' ]; then
|
||||||
@@ -1453,7 +1567,26 @@ nvm_print_versions() {
|
|||||||
local LTS
|
local LTS
|
||||||
local FORMAT
|
local FORMAT
|
||||||
local NVM_CURRENT
|
local NVM_CURRENT
|
||||||
|
local NVM_LATEST_LTS_COLOR
|
||||||
|
local NVM_OLD_LTS_COLOR
|
||||||
|
|
||||||
|
local INSTALLED_COLOR
|
||||||
|
local SYSTEM_COLOR
|
||||||
|
local CURRENT_COLOR
|
||||||
|
local NOT_INSTALLED_COLOR
|
||||||
|
local DEFAULT_COLOR
|
||||||
|
local LTS_COLOR
|
||||||
|
|
||||||
|
INSTALLED_COLOR=$(nvm_get_colors 1)
|
||||||
|
SYSTEM_COLOR=$(nvm_get_colors 2)
|
||||||
|
CURRENT_COLOR=$(nvm_get_colors 3)
|
||||||
|
NOT_INSTALLED_COLOR=$(nvm_get_colors 4)
|
||||||
|
DEFAULT_COLOR=$(nvm_get_colors 5)
|
||||||
|
LTS_COLOR=$(nvm_get_colors 6)
|
||||||
|
|
||||||
NVM_CURRENT=$(nvm_ls_current)
|
NVM_CURRENT=$(nvm_ls_current)
|
||||||
|
NVM_LATEST_LTS_COLOR=$(nvm_echo "${CURRENT_COLOR}" | command tr '0;' '1;')
|
||||||
|
NVM_OLD_LTS_COLOR="${DEFAULT_COLOR}"
|
||||||
local NVM_HAS_COLORS
|
local NVM_HAS_COLORS
|
||||||
if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
|
if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
|
||||||
NVM_HAS_COLORS=1
|
NVM_HAS_COLORS=1
|
||||||
@@ -1470,19 +1603,19 @@ nvm_print_versions() {
|
|||||||
FORMAT='%15s'
|
FORMAT='%15s'
|
||||||
if [ "_${VERSION}" = "_${NVM_CURRENT}" ]; then
|
if [ "_${VERSION}" = "_${NVM_CURRENT}" ]; then
|
||||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||||
FORMAT='\033[0;32m-> %12s\033[0m'
|
FORMAT="\033[${CURRENT_COLOR}-> %12s\033[0m"
|
||||||
else
|
else
|
||||||
FORMAT='-> %12s *'
|
FORMAT='-> %12s *'
|
||||||
fi
|
fi
|
||||||
elif [ "${VERSION}" = "system" ]; then
|
elif [ "${VERSION}" = "system" ]; then
|
||||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||||
FORMAT='\033[0;33m%15s\033[0m'
|
FORMAT="\033[${SYSTEM_COLOR}%15s\033[0m"
|
||||||
else
|
else
|
||||||
FORMAT='%15s *'
|
FORMAT='%15s *'
|
||||||
fi
|
fi
|
||||||
elif nvm_is_version_installed "${VERSION}"; then
|
elif nvm_is_version_installed "${VERSION}"; then
|
||||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||||
FORMAT='\033[0;34m%15s\033[0m'
|
FORMAT="\033[${INSTALLED_COLOR}%15s\033[0m"
|
||||||
else
|
else
|
||||||
FORMAT='%15s *'
|
FORMAT='%15s *'
|
||||||
fi
|
fi
|
||||||
@@ -1493,7 +1626,7 @@ nvm_print_versions() {
|
|||||||
LTS="${LTS##Latest }"
|
LTS="${LTS##Latest }"
|
||||||
LTS_LENGTH="${#LTS}"
|
LTS_LENGTH="${#LTS}"
|
||||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||||
LTS_FORMAT=" \\033[1;32m%${LTS_LENGTH}s\\033[0m"
|
LTS_FORMAT=" \\033[${NVM_LATEST_LTS_COLOR}%${LTS_LENGTH}s\\033[0m"
|
||||||
else
|
else
|
||||||
LTS_FORMAT=" %${LTS_LENGTH}s"
|
LTS_FORMAT=" %${LTS_LENGTH}s"
|
||||||
fi
|
fi
|
||||||
@@ -1501,7 +1634,7 @@ nvm_print_versions() {
|
|||||||
*)
|
*)
|
||||||
LTS_LENGTH="${#LTS}"
|
LTS_LENGTH="${#LTS}"
|
||||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||||
LTS_FORMAT=" \\033[0;37m%${LTS_LENGTH}s\\033[0m"
|
LTS_FORMAT=" \\033[${NVM_OLD_LTS_COLOR}%${LTS_LENGTH}s\\033[0m"
|
||||||
else
|
else
|
||||||
LTS_FORMAT=" %${LTS_LENGTH}s"
|
LTS_FORMAT=" %${LTS_LENGTH}s"
|
||||||
fi
|
fi
|
||||||
@@ -2175,6 +2308,15 @@ nvm_npm_global_modules() {
|
|||||||
nvm_echo "${INSTALLS} //// ${LINKS}"
|
nvm_echo "${INSTALLS} //// ${LINKS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_npmrc_bad_news_bears() {
|
||||||
|
local NVM_NPMRC
|
||||||
|
NVM_NPMRC="${1-}"
|
||||||
|
if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
nvm_die_on_prefix() {
|
nvm_die_on_prefix() {
|
||||||
local NVM_DELETE_PREFIX
|
local NVM_DELETE_PREFIX
|
||||||
NVM_DELETE_PREFIX="${1-}"
|
NVM_DELETE_PREFIX="${1-}"
|
||||||
@@ -2210,7 +2352,7 @@ nvm_die_on_prefix() {
|
|||||||
# here, we avoid trying to replicate "which one wins" or testing the value; if any are defined, it errors
|
# here, we avoid trying to replicate "which one wins" or testing the value; if any are defined, it errors
|
||||||
# until none are left.
|
# until none are left.
|
||||||
local NVM_NPM_CONFIG_PREFIX_ENV
|
local NVM_NPM_CONFIG_PREFIX_ENV
|
||||||
NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
|
NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i ^NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
|
||||||
if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then
|
if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then
|
||||||
local NVM_CONFIG_VALUE
|
local NVM_CONFIG_VALUE
|
||||||
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
|
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
|
||||||
@@ -2222,29 +2364,70 @@ nvm_die_on_prefix() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! nvm_has 'npm'; then
|
# here, npm config checks npmrc files.
|
||||||
return
|
# the stack is: cli, env, project, user, global, builtin, defaults
|
||||||
|
# cli does not apply; env is covered above, defaults don't exist for prefix
|
||||||
|
# there are 4 npmrc locations to check: project, global, user, and builtin
|
||||||
|
# project: find the closest node_modules or package.json-containing dir, `.npmrc`
|
||||||
|
# global: default prefix + `/etc/npmrc`
|
||||||
|
# user: $HOME/.npmrc
|
||||||
|
# builtin: npm install location, `npmrc`
|
||||||
|
#
|
||||||
|
# if any of them have a `prefix`, fail.
|
||||||
|
# if any have `globalconfig`, fail also, just in case, to avoid spidering configs.
|
||||||
|
|
||||||
|
local NVM_NPM_BUILTIN_NPMRC
|
||||||
|
NVM_NPM_BUILTIN_NPMRC="${NVM_VERSION_DIR}/lib/node_modules/npm/npmrc"
|
||||||
|
if nvm_npmrc_bad_news_bears "${NVM_NPM_BUILTIN_NPMRC}"; then
|
||||||
|
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||||
|
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
|
||||||
|
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
|
||||||
|
else
|
||||||
|
nvm_err "Your builtin npmrc file ($(nvm_sanitize_path "${NVM_NPM_BUILTIN_NPMRC}"))"
|
||||||
|
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||||
|
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||||
|
return 10
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local NVM_NPM_PREFIX
|
local NVM_NPM_GLOBAL_NPMRC
|
||||||
local NVM_OS
|
NVM_NPM_GLOBAL_NPMRC="${NVM_VERSION_DIR}/etc/npmrc"
|
||||||
NVM_OS="$(nvm_get_os)"
|
if nvm_npmrc_bad_news_bears "${NVM_NPM_GLOBAL_NPMRC}"; then
|
||||||
NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
|
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||||
if [ "${NVM_VERSION_DIR}" != "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then
|
npm config --global --loglevel=warn delete prefix
|
||||||
|
npm config --global --loglevel=warn delete globalconfig
|
||||||
|
else
|
||||||
|
nvm_err "Your global npmrc file ($(nvm_sanitize_path "${NVM_NPM_GLOBAL_NPMRC}"))"
|
||||||
|
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||||
|
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||||
|
return 10
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
local NVM_NPM_USER_NPMRC
|
||||||
|
NVM_NPM_USER_NPMRC="${HOME}/.npmrc"
|
||||||
|
if nvm_npmrc_bad_news_bears "${NVM_NPM_USER_NPMRC}"; then
|
||||||
|
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||||
|
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_USER_NPMRC}"
|
||||||
|
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_USER_NPMRC}"
|
||||||
|
else
|
||||||
|
nvm_err "Your user’s .npmrc file ($(nvm_sanitize_path "${NVM_NPM_USER_NPMRC}"))"
|
||||||
|
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||||
|
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||||
|
return 10
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
local NVM_NPM_PROJECT_NPMRC
|
||||||
|
NVM_NPM_PROJECT_NPMRC="$(nvm_find_project_dir)/.npmrc"
|
||||||
|
if nvm_npmrc_bad_news_bears "${NVM_NPM_PROJECT_NPMRC}"; then
|
||||||
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||||
npm config --loglevel=warn delete prefix
|
npm config --loglevel=warn delete prefix
|
||||||
|
npm config --loglevel=warn delete globalconfig
|
||||||
else
|
else
|
||||||
nvm deactivate >/dev/null 2>&1
|
nvm_err "Your project npmrc file ($(nvm_sanitize_path "${NVM_NPM_PROJECT_NPMRC}"))"
|
||||||
nvm_err "nvm is not compatible with the npm config \"prefix\" option: currently set to \"${NVM_NPM_PREFIX}\""
|
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||||
if nvm_has 'npm'; then
|
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||||
nvm_err "Run \`npm config delete prefix\` or \`${NVM_COMMAND}\` to unset it."
|
|
||||||
else
|
|
||||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
|
||||||
fi
|
|
||||||
if [ "${NVM_OS}" = 'darwin' ]; then
|
|
||||||
nvm_err "Make sure your username ($(whoami)) matches the one in your \$HOME path."
|
|
||||||
nvm_err "See the \"macOS Troubleshooting\" section in the docs for more information."
|
|
||||||
fi
|
|
||||||
return 10
|
return 10
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -2375,6 +2558,46 @@ nvm() {
|
|||||||
do
|
do
|
||||||
case $i in
|
case $i in
|
||||||
'-h'|'help'|'--help')
|
'-h'|'help'|'--help')
|
||||||
|
NVM_NO_COLORS=""
|
||||||
|
for j in "$@"; do
|
||||||
|
if [ "${j}" = '--no-colors' ]; then
|
||||||
|
NVM_NO_COLORS="${j}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
local INITIAL_COLOR_INFO
|
||||||
|
local RED_INFO
|
||||||
|
local GREEN_INFO
|
||||||
|
local BLUE_INFO
|
||||||
|
local CYAN_INFO
|
||||||
|
local MAGENTA_INFO
|
||||||
|
local YELLOW_INFO
|
||||||
|
local BLACK_INFO
|
||||||
|
local GREY_WHITE_INFO
|
||||||
|
|
||||||
|
if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
|
||||||
|
INITIAL_COLOR_INFO='\033[0;32m g\033[0m \033[0;34m b\033[0m \033[0;33m y\033[0m \033[0;31m r\033[0m \033[0;37m e\033[0m'
|
||||||
|
RED_INFO='\033[0;31m r\033[0m/\033[1;31mR\033[0m = \033[0;31mred\033[0m / \033[1;31mbold red\033[0m'
|
||||||
|
GREEN_INFO='\033[0;32m g\033[0m/\033[1;32mG\033[0m = \033[0;32mgreen\033[0m / \033[1;32mbold green\033[0m'
|
||||||
|
BLUE_INFO='\033[0;34m b\033[0m/\033[1;34mB\033[0m = \033[0;34mblue\033[0m / \033[1;34mbold blue\033[0m'
|
||||||
|
CYAN_INFO='\033[0;36m c\033[0m/\033[1;36mC\033[0m = \033[0;36mcyan\033[0m / \033[1;36mbold cyan\033[0m'
|
||||||
|
MAGENTA_INFO='\033[0;35m m\033[0m/\033[1;35mM\033[0m = \033[0;35mmagenta\033[0m / \033[1;35mbold magenta\033[0m'
|
||||||
|
YELLOW_INFO='\033[0;33m y\033[0m/\033[1;33mY\033[0m = \033[0;33myellow\033[0m / \033[1;33mbold yellow\033[0m'
|
||||||
|
BLACK_INFO='\033[0;30m k\033[0m/\033[1;30mK\033[0m = \033[0;30mblack\033[0m / \033[1;30mbold black\033[0m'
|
||||||
|
GREY_WHITE_INFO='\033[0;37m e\033[0m/\033[1;37mW\033[0m = \033[0;37mlight grey\033[0m / \033[1;37mwhite\033[0m'
|
||||||
|
else
|
||||||
|
INITIAL_COLOR_INFO='gbYre'
|
||||||
|
RED_INFO='r/R = red / bold red'
|
||||||
|
GREEN_INFO='g/G = green / bold green'
|
||||||
|
BLUE_INFO='b/B = blue / bold blue'
|
||||||
|
CYAN_INFO='c/C = cyan / bold cyan'
|
||||||
|
MAGENTA_INFO='m/M = magenta / bold magenta'
|
||||||
|
YELLOW_INFO='y/Y = yellow / bold yellow'
|
||||||
|
BLACK_INFO='k/K = black / bold black'
|
||||||
|
GREY_WHITE_INFO='e/W = light grey / white'
|
||||||
|
fi
|
||||||
|
|
||||||
local NVM_IOJS_PREFIX
|
local NVM_IOJS_PREFIX
|
||||||
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
||||||
local NVM_NODE_PREFIX
|
local NVM_NODE_PREFIX
|
||||||
@@ -2392,8 +2615,11 @@ nvm() {
|
|||||||
nvm_echo
|
nvm_echo
|
||||||
nvm_echo 'Usage:'
|
nvm_echo 'Usage:'
|
||||||
nvm_echo ' nvm --help Show this message'
|
nvm_echo ' nvm --help Show this message'
|
||||||
|
nvm_echo ' --no-colors Suppress colored output'
|
||||||
nvm_echo ' nvm --version Print out the installed version of nvm'
|
nvm_echo ' nvm --version Print out the installed version of nvm'
|
||||||
nvm_echo ' nvm install [-s] [<version>] Download and install a <version>, [-s] from source. Uses .nvmrc if available'
|
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'
|
||||||
|
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'
|
||||||
|
nvm_echo ' -s Skip binary download, install from source only.'
|
||||||
nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
|
nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
|
||||||
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
|
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
|
||||||
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
|
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
|
||||||
@@ -2405,13 +2631,19 @@ nvm() {
|
|||||||
nvm_echo ' nvm uninstall <version> Uninstall a version'
|
nvm_echo ' nvm uninstall <version> Uninstall a version'
|
||||||
nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'
|
nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||||
nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'
|
nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'
|
||||||
nvm_echo ' nvm use [--silent] [<version>] Modify PATH to use <version>. Uses .nvmrc if available'
|
nvm_echo ' nvm use [<version>] Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.'
|
||||||
|
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm use`:'
|
||||||
|
nvm_echo ' --silent Silences stdout/stderr output'
|
||||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||||
nvm_echo ' nvm exec [--silent] [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available'
|
nvm_echo ' nvm exec [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available and version is omitted.'
|
||||||
|
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm exec`:'
|
||||||
|
nvm_echo ' --silent Silences stdout/stderr output'
|
||||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||||
nvm_echo ' nvm run [--silent] [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
|
nvm_echo ' nvm run [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.'
|
||||||
|
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm run`:'
|
||||||
|
nvm_echo ' --silent Silences stdout/stderr output'
|
||||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||||
nvm_echo ' nvm current Display currently activated version of Node'
|
nvm_echo ' nvm current Display currently activated version of Node'
|
||||||
@@ -2426,7 +2658,8 @@ nvm() {
|
|||||||
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
|
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
|
||||||
nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'
|
nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'
|
||||||
nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'
|
nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'
|
||||||
nvm_echo ' nvm deactivate [--silent] Undo effects of `nvm` on current shell'
|
nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'
|
||||||
|
nvm_echo ' --silent Silences stdout/stderr output'
|
||||||
nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
|
nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
|
||||||
nvm_echo ' --no-colors Suppress colored output'
|
nvm_echo ' --no-colors Suppress colored output'
|
||||||
nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
|
nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
|
||||||
@@ -2434,9 +2667,22 @@ nvm() {
|
|||||||
nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'
|
nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'
|
||||||
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
|
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
|
||||||
nvm_echo ' nvm unload Unload `nvm` from shell'
|
nvm_echo ' nvm unload Unload `nvm` from shell'
|
||||||
nvm_echo ' nvm which [--silent] [current | <version>] Display path to installed node version. Uses .nvmrc if available'
|
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available and version is omitted.'
|
||||||
|
nvm_echo ' --silent Silences stdout/stderr output when a version is omitted'
|
||||||
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
||||||
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
||||||
|
nvm_echo ' nvm set-colors [<color codes>] Set five text colors using format "yMeBg". Available when supported.'
|
||||||
|
nvm_echo ' Initial colors are:'
|
||||||
|
nvm_echo_with_colors " ${INITIAL_COLOR_INFO}"
|
||||||
|
nvm_echo ' Color codes:'
|
||||||
|
nvm_echo_with_colors " ${RED_INFO}"
|
||||||
|
nvm_echo_with_colors " ${GREEN_INFO}"
|
||||||
|
nvm_echo_with_colors " ${BLUE_INFO}"
|
||||||
|
nvm_echo_with_colors " ${CYAN_INFO}"
|
||||||
|
nvm_echo_with_colors " ${MAGENTA_INFO}"
|
||||||
|
nvm_echo_with_colors " ${YELLOW_INFO}"
|
||||||
|
nvm_echo_with_colors " ${BLACK_INFO}"
|
||||||
|
nvm_echo_with_colors " ${GREY_WHITE_INFO}"
|
||||||
nvm_echo
|
nvm_echo
|
||||||
nvm_echo 'Example:'
|
nvm_echo 'Example:'
|
||||||
nvm_echo ' nvm install 8.0.0 Install a specific version number'
|
nvm_echo ' nvm install 8.0.0 Install a specific version number'
|
||||||
@@ -2451,6 +2697,8 @@ nvm() {
|
|||||||
nvm_echo ' nvm install --lts Install the latest LTS version'
|
nvm_echo ' nvm install --lts Install the latest LTS version'
|
||||||
nvm_echo ' nvm use --lts Use the latest LTS version'
|
nvm_echo ' nvm use --lts Use the latest LTS version'
|
||||||
nvm_echo
|
nvm_echo
|
||||||
|
nvm_echo ' nvm set-colors cgYmW Set text colors to cyan, green, bold yellow, magenta, and white'
|
||||||
|
nvm_echo
|
||||||
nvm_echo 'Note:'
|
nvm_echo 'Note:'
|
||||||
nvm_echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'
|
nvm_echo ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'
|
||||||
nvm_echo
|
nvm_echo
|
||||||
@@ -3311,6 +3559,7 @@ nvm() {
|
|||||||
local PATTERN
|
local PATTERN
|
||||||
local NVM_NO_COLORS
|
local NVM_NO_COLORS
|
||||||
local NVM_NO_ALIAS
|
local NVM_NO_ALIAS
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
--) ;;
|
--) ;;
|
||||||
@@ -3348,6 +3597,7 @@ nvm() {
|
|||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
local PATTERN
|
local PATTERN
|
||||||
local NVM_NO_COLORS
|
local NVM_NO_COLORS
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "${1-}" in
|
case "${1-}" in
|
||||||
--) ;;
|
--) ;;
|
||||||
@@ -3458,6 +3708,7 @@ nvm() {
|
|||||||
local NVM_NO_COLORS
|
local NVM_NO_COLORS
|
||||||
ALIAS='--'
|
ALIAS='--'
|
||||||
TARGET='--'
|
TARGET='--'
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "${1-}" in
|
case "${1-}" in
|
||||||
--) ;;
|
--) ;;
|
||||||
@@ -3647,7 +3898,7 @@ nvm() {
|
|||||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||||
;;
|
;;
|
||||||
"--version" | "-v")
|
"--version" | "-v")
|
||||||
nvm_echo '0.36.0'
|
nvm_echo '0.37.1'
|
||||||
;;
|
;;
|
||||||
"unload")
|
"unload")
|
||||||
nvm deactivate >/dev/null 2>&1
|
nvm deactivate >/dev/null 2>&1
|
||||||
@@ -3688,11 +3939,26 @@ nvm() {
|
|||||||
nvm_sanitize_path nvm_has_colors nvm_process_parameters \
|
nvm_sanitize_path nvm_has_colors nvm_process_parameters \
|
||||||
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
|
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
|
||||||
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
|
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
|
||||||
|
nvm_npmrc_bad_news_bears \
|
||||||
|
nvm_get_colors nvm_set_colors nvm_print_color_code nvm_format_help_message_colors \
|
||||||
|
nvm_echo_with_colors nvm_err_with_colors \
|
||||||
>/dev/null 2>&1
|
>/dev/null 2>&1
|
||||||
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
||||||
NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \
|
NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \
|
||||||
|
NVM_COLORS INSTALLED_COLOR SYSTEM_COLOR \
|
||||||
|
CURRENT_COLOR NOT_INSTALLED_COLOR DEFAULT_COLOR LTS_COLOR \
|
||||||
>/dev/null 2>&1
|
>/dev/null 2>&1
|
||||||
;;
|
;;
|
||||||
|
"set-colors")
|
||||||
|
local EXIT_CODE
|
||||||
|
nvm_set_colors "${1-}"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
if [ "$EXIT_CODE" -eq 17 ]; then
|
||||||
|
>&2 nvm --help
|
||||||
|
nvm_echo
|
||||||
|
nvm_err_with_colors "\033[1;37mPlease pass in five \033[1;31mvalid color codes\033[1;37m. Choose from: rRgGbBcCyYmMkKeW\033[0m"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
>&2 nvm --help
|
>&2 nvm --help
|
||||||
return 127
|
return 127
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "nvm",
|
"name": "nvm",
|
||||||
"version": "0.36.0",
|
"version": "0.37.1",
|
||||||
"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"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
|
"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/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/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",
|
"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",
|
"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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable file
25
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable 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
|
||||||
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable file
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable 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
|
||||||
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable file
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable 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
|
||||||
40
test/fast/Listing versions/Running "nvm ls" should not show a trailing slash
Executable file
40
test/fast/Listing versions/Running "nvm ls" should not show a trailing slash
Executable 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}<"
|
||||||
@@ -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}"
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ EXPECTED_OUTPUT="$(nvm_add_iojs_prefix ${VERSION})"
|
|||||||
|
|
||||||
nvm use --delete-prefix iojs || die '`nvm use iojs` failed'
|
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}"
|
echo "current: ${CURRENT}"
|
||||||
|
|
||||||
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"
|
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"
|
||||||
|
|||||||
21
test/fast/Set Colors/nvm_echo_with_colors
Executable file
21
test/fast/Set Colors/nvm_echo_with_colors
Executable 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
|
||||||
19
test/fast/Set Colors/nvm_err_with_colors
Executable file
19
test/fast/Set Colors/nvm_err_with_colors
Executable 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
|
||||||
24
test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors
Executable file
24
test/fast/Set Colors/nvm_print_default_alias calls nvm_get_colors
Executable 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
|
||||||
52
test/fast/Set Colors/nvm_print_versions calls nvm_get_colors
Executable file
52
test/fast/Set Colors/nvm_print_versions calls nvm_get_colors
Executable 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
|
||||||
@@ -6,9 +6,17 @@ die () { echo "$@" ; cleanup ; exit 1; }
|
|||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs
|
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
|
\. ../../../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'
|
nvm deactivate 2>/dev/null || die 'unable to deactivate'
|
||||||
|
|
||||||
|
|||||||
52
test/fast/Unit tests/nvm set_colors
Executable file
52
test/fast/Unit tests/nvm set_colors
Executable 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
|
||||||
@@ -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"
|
||||||
@@ -33,15 +46,22 @@ OUTPUT="$(nvm_die_on_prefix 0 version_dir foo 2>&1)"
|
|||||||
|
|
||||||
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 "$(nvm_version_dir new)" 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 prefix is good; got '$OUTPUT'"
|
[ -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)"
|
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"
|
||||||
@@ -64,18 +84,109 @@ EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_versi
|
|||||||
[ "_$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() {
|
OUTPUT="$(export FOO='NPM_CONFIG_PREFIX' ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||||
local args
|
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop; got '$OUTPUT'"
|
||||||
args="$@"
|
|
||||||
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
|
# npmrc tests
|
||||||
echo "./bad prefix"
|
(
|
||||||
fi
|
cd "${TEST_DIR}"
|
||||||
}
|
touch package.json
|
||||||
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
|
||||||
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"
|
# project: prefix
|
||||||
Run \`npm config delete prefix\` or \`foo\` to unset it."
|
echo 'prefix=garbage' > .npmrc
|
||||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
|
EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
|
||||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
|
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 user’s .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 user’s .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
|
||||||
|
|||||||
79
test/fast/Unit tests/nvm_get_colors
Executable file
79
test/fast/Unit tests/nvm_get_colors
Executable 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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
20
test/fast/Unit tests/nvm_print_color_code
Executable file
20
test/fast/Unit tests/nvm_print_color_code
Executable 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<")"
|
||||||
Reference in New Issue
Block a user