mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-02 02:34:43 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
661a702cdd | ||
![]() |
510b2fd44c | ||
![]() |
80a4e06af9 | ||
![]() |
22902f04a3 | ||
![]() |
6848c16d53 | ||
![]() |
3abb98124e | ||
![]() |
21c0c05130 | ||
![]() |
00af6341f7 | ||
![]() |
11a9d22607 | ||
![]() |
bbe032fa7e |
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
|
||||
|
||||
on: [pull_request]
|
||||
on: [pull_request_target]
|
||||
|
||||
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 }}
|
39
.travis.yml
39
.travis.yml
@@ -18,21 +18,13 @@ before_install:
|
||||
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
||||
- curl --version
|
||||
- wget --version
|
||||
- shellcheck --version
|
||||
install:
|
||||
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
|
||||
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
|
||||
script:
|
||||
- if [ -n "${MAKE_RELEASE-}" ]; then export GIT_EDITOR="sed -i '1 s/^/99.99.99 make release test/'" && git fetch --unshallow --tags && echo proceed | make TAG=99.99.99 release ; fi
|
||||
- if [ -n "${DOCTOCCHECK-}" ]; then cp README.md README.md.orig && npm run doctoc && diff -q README.md README.md.orig ; fi
|
||||
- if [ -n "${ECLINT-}" ]; then npm run eclint ; fi
|
||||
- if [ -n "${DOCKERFILE_LINT-}" ]; then npm run dockerfile_lint ; fi
|
||||
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash nvm.sh && shellcheck -s sh nvm.sh && shellcheck -s dash nvm.sh && shellcheck -s ksh nvm.sh ; fi
|
||||
- if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash install.sh bash_completion nvm-exec ; fi
|
||||
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi
|
||||
before_cache:
|
||||
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
|
||||
- if [ -n "${NODE-}" ]; then . nvm.sh && set -ex && nvm install --latest-npm "${NODE}" && npm --version; fi
|
||||
env:
|
||||
global:
|
||||
- CXX=g++
|
||||
@@ -41,27 +33,22 @@ env:
|
||||
- PATH="/usr/lib/ccache/:$PATH"
|
||||
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
||||
matrix:
|
||||
- MAKE_RELEASE=true
|
||||
- DOCTOCCHECK=true
|
||||
- SHELLCHECK=true
|
||||
- ECLINT=true
|
||||
- DOCKERFILE_LINT=true
|
||||
- SHELL=bash TEST_SUITE=install_script
|
||||
- SHELL=sh TEST_SUITE=fast
|
||||
- SHELL=dash TEST_SUITE=fast
|
||||
- SHELL=bash TEST_SUITE=fast
|
||||
- SHELL=zsh TEST_SUITE=fast
|
||||
# - SHELL=ksh TEST_SUITE=fast
|
||||
# - SHELL=ksh TEST_SUITE=fast
|
||||
- SHELL=sh TEST_SUITE=sourcing
|
||||
- SHELL=dash TEST_SUITE=sourcing
|
||||
- SHELL=bash TEST_SUITE=sourcing
|
||||
- SHELL=zsh TEST_SUITE=sourcing
|
||||
# - SHELL=ksh TEST_SUITE=sourcing
|
||||
# - SHELL=ksh TEST_SUITE=sourcing
|
||||
- SHELL=sh TEST_SUITE=slow
|
||||
- SHELL=dash TEST_SUITE=slow
|
||||
- SHELL=bash TEST_SUITE=slow
|
||||
- SHELL=zsh TEST_SUITE=slow
|
||||
# - SHELL=ksh TEST_SUITE=slow
|
||||
# - SHELL=ksh TEST_SUITE=slow
|
||||
- SHELL=sh TEST_SUITE=installation_node
|
||||
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=dash TEST_SUITE=installation_node
|
||||
@@ -70,8 +57,8 @@ env:
|
||||
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=zsh TEST_SUITE=installation_node
|
||||
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
# - SHELL=ksh TEST_SUITE=installation_node
|
||||
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
# - SHELL=ksh TEST_SUITE=installation_node
|
||||
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=sh TEST_SUITE=installation_iojs
|
||||
- SHELL=sh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
- SHELL=dash TEST_SUITE=installation_iojs
|
||||
@@ -80,17 +67,5 @@ env:
|
||||
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
- SHELL=zsh TEST_SUITE=installation_iojs
|
||||
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
# - SHELL=ksh TEST_SUITE=installation_iojs
|
||||
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
- NODE=10 TEST="nvm install-latest-npm"
|
||||
- NODE=9 TEST="nvm install-latest-npm"
|
||||
- NODE=8 TEST="nvm install-latest-npm"
|
||||
- NODE=7 TEST="nvm install-latest-npm"
|
||||
- NODE=6 TEST="nvm install-latest-npm"
|
||||
- NODE=5 TEST="nvm install-latest-npm"
|
||||
- NODE=5.9 TEST="nvm install-latest-npm"
|
||||
- NODE=4 TEST="nvm install-latest-npm"
|
||||
- NODE=4.6 TEST="nvm install-latest-npm"
|
||||
- NODE=4.5 TEST="nvm install-latest-npm"
|
||||
- NODE=4.4 TEST="nvm install-latest-npm"
|
||||
- NODE=2 TEST="nvm install-latest-npm"
|
||||
# - SHELL=ksh TEST_SUITE=installation_iojs
|
||||
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
|
||||
|
56
README.md
56
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` -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
@@ -24,6 +24,8 @@
|
||||
- [io.js](#iojs)
|
||||
- [System Version of Node](#system-version-of-node)
|
||||
- [Listing Versions](#listing-versions)
|
||||
- [Setting Custom Colors](#setting-custom-colors)
|
||||
- [Persisting custom colors](#persisting-custom-colors)
|
||||
- [Suppressing colorized output](#suppressing-colorized-output)
|
||||
- [.nvmrc](#nvmrc)
|
||||
- [Deeper Shell Integration](#deeper-shell-integration)
|
||||
@@ -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:
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash
|
||||
```
|
||||
```sh
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.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`).
|
||||
@@ -115,7 +117,7 @@ You can use a task:
|
||||
```yaml
|
||||
- name: nvm
|
||||
shell: >
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.1/install.sh | bash
|
||||
args:
|
||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||
```
|
||||
@@ -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
|
||||
- `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.37.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`
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
### Setting Custom Colors
|
||||
|
||||
You can set five colors that will be used to display version and alias information. These colors replace the default colors.
|
||||
Initial colors are: g b y r e
|
||||
|
||||
Color codes:
|
||||
|
||||
r/R = red / bold red
|
||||
|
||||
g/G = green / bold green
|
||||
|
||||
b/B = blue / bold blue
|
||||
|
||||
c/C = cyan / bold cyan
|
||||
|
||||
m/M = magenta / bold magenta
|
||||
|
||||
y/Y = yellow / bold yellow
|
||||
|
||||
k/K = black / bold black
|
||||
|
||||
e/W = light grey / white
|
||||
|
||||
```sh
|
||||
nvm set-colors rgBcm
|
||||
```
|
||||
|
||||
#### Persisting custom colors
|
||||
|
||||
If you want the custom colors to persist after terminating the shell, export the NVM_COLORS variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line:
|
||||
|
||||
```sh
|
||||
export NVM_COLORS='cmgRY'
|
||||
```
|
||||
|
||||
#### Suppressing colorized output
|
||||
|
||||
`nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
|
||||
`nvm help (or -h or --help)`, `nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
|
||||
|
||||
```sh
|
||||
nvm ls --no-colors
|
||||
nvm help --no-colors
|
||||
TERM=dumb nvm ls
|
||||
```
|
||||
|
||||
@@ -722,7 +760,7 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
|
||||
|
||||
```sh
|
||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.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.
|
||||
@@ -819,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)
|
||||
|
||||
[1]: https://github.com/nvm-sh/nvm.git
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.37.0/install.sh
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.37.1/install.sh
|
||||
[3]: https://travis-ci.org/nvm-sh/nvm
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.0
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.1
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
[Fish]: http://fishshell.com
|
||||
|
@@ -19,7 +19,7 @@ nvm_install_dir() {
|
||||
}
|
||||
|
||||
nvm_latest_version() {
|
||||
echo "v0.37.0"
|
||||
echo "v0.37.1"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
|
244
nvm.sh
244
nvm.sh
@@ -24,6 +24,10 @@ nvm_echo() {
|
||||
command printf %s\\n "$*" 2>/dev/null
|
||||
}
|
||||
|
||||
nvm_echo_with_colors() {
|
||||
command printf %b\\n "$*" 2>/dev/null
|
||||
}
|
||||
|
||||
nvm_cd() {
|
||||
\cd "$@"
|
||||
}
|
||||
@@ -32,6 +36,10 @@ nvm_err() {
|
||||
>&2 nvm_echo "$@"
|
||||
}
|
||||
|
||||
nvm_err_with_colors() {
|
||||
>&2 nvm_echo_with_colors "$@"
|
||||
}
|
||||
|
||||
nvm_grep() {
|
||||
GREP_OPTIONS='' command grep "$@"
|
||||
}
|
||||
@@ -70,11 +78,11 @@ nvm_command_info() {
|
||||
}
|
||||
|
||||
nvm_has_colors() {
|
||||
local NVM_COLORS
|
||||
local NVM_NUM_COLORS
|
||||
if nvm_has tput; then
|
||||
NVM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
|
||||
NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)"
|
||||
fi
|
||||
[ "${NVM_COLORS:--1}" -ge 8 ]
|
||||
[ "${NVM_NUM_COLORS:--1}" -ge 8 ]
|
||||
}
|
||||
|
||||
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_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() {
|
||||
local ALIAS
|
||||
ALIAS="${1-}"
|
||||
@@ -726,6 +820,21 @@ nvm_print_formatted_alias() {
|
||||
local VERSION_FORMAT
|
||||
local ALIAS_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'
|
||||
DEST_FORMAT='%s'
|
||||
VERSION_FORMAT='%s'
|
||||
@@ -739,26 +848,26 @@ nvm_print_formatted_alias() {
|
||||
if [ -z "${NVM_NO_COLORS}" ] && nvm_has_colors; then
|
||||
ARROW='\033[0;90m->\033[0m'
|
||||
if [ "_${DEFAULT}" = '_true' ]; then
|
||||
NEWLINE=' \033[0;37m(default)\033[0m\n'
|
||||
NEWLINE=" \033[${DEFAULT_COLOR}(default)\033[0m\n"
|
||||
fi
|
||||
if [ "_${VERSION}" = "_${NVM_CURRENT-}" ]; then
|
||||
ALIAS_FORMAT='\033[0;32m%s\033[0m'
|
||||
DEST_FORMAT='\033[0;32m%s\033[0m'
|
||||
VERSION_FORMAT='\033[0;32m%s\033[0m'
|
||||
ALIAS_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||
DEST_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||
VERSION_FORMAT="\033[${CURRENT_COLOR}%s\033[0m"
|
||||
elif nvm_is_version_installed "${VERSION}"; then
|
||||
ALIAS_FORMAT='\033[0;34m%s\033[0m'
|
||||
DEST_FORMAT='\033[0;34m%s\033[0m'
|
||||
VERSION_FORMAT='\033[0;34m%s\033[0m'
|
||||
ALIAS_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||
DEST_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||
VERSION_FORMAT="\033[${INSTALLED_COLOR}%s\033[0m"
|
||||
elif [ "${VERSION}" = '∞' ] || [ "${VERSION}" = 'N/A' ]; then
|
||||
ALIAS_FORMAT='\033[1;31m%s\033[0m'
|
||||
DEST_FORMAT='\033[1;31m%s\033[0m'
|
||||
VERSION_FORMAT='\033[1;31m%s\033[0m'
|
||||
ALIAS_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||
DEST_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||
VERSION_FORMAT="\033[${NOT_INSTALLED_COLOR}%s\033[0m"
|
||||
fi
|
||||
if [ "_${NVM_LTS-}" = '_true' ]; then
|
||||
ALIAS_FORMAT='\033[1;33m%s\033[0m'
|
||||
ALIAS_FORMAT="\033[${LTS_COLOR}%s\033[0m"
|
||||
fi
|
||||
if [ "_${DEST%/*}" = "_lts" ]; then
|
||||
DEST_FORMAT='\033[1;33m%s\033[0m'
|
||||
DEST_FORMAT="\033[${LTS_COLOR}%s\033[0m"
|
||||
fi
|
||||
elif [ "_${VERSION}" != '_∞' ] && [ "_${VERSION}" != '_N/A' ]; then
|
||||
VERSION_FORMAT='%s *'
|
||||
@@ -1458,7 +1567,26 @@ nvm_print_versions() {
|
||||
local LTS
|
||||
local FORMAT
|
||||
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_LATEST_LTS_COLOR=$(nvm_echo "${CURRENT_COLOR}" | command tr '0;' '1;')
|
||||
NVM_OLD_LTS_COLOR="${DEFAULT_COLOR}"
|
||||
local NVM_HAS_COLORS
|
||||
if [ -z "${NVM_NO_COLORS-}" ] && nvm_has_colors; then
|
||||
NVM_HAS_COLORS=1
|
||||
@@ -1475,19 +1603,19 @@ nvm_print_versions() {
|
||||
FORMAT='%15s'
|
||||
if [ "_${VERSION}" = "_${NVM_CURRENT}" ]; then
|
||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||
FORMAT='\033[0;32m-> %12s\033[0m'
|
||||
FORMAT="\033[${CURRENT_COLOR}-> %12s\033[0m"
|
||||
else
|
||||
FORMAT='-> %12s *'
|
||||
fi
|
||||
elif [ "${VERSION}" = "system" ]; then
|
||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||
FORMAT='\033[0;33m%15s\033[0m'
|
||||
FORMAT="\033[${SYSTEM_COLOR}%15s\033[0m"
|
||||
else
|
||||
FORMAT='%15s *'
|
||||
fi
|
||||
elif nvm_is_version_installed "${VERSION}"; then
|
||||
if [ "${NVM_HAS_COLORS-}" = '1' ]; then
|
||||
FORMAT='\033[0;34m%15s\033[0m'
|
||||
FORMAT="\033[${INSTALLED_COLOR}%15s\033[0m"
|
||||
else
|
||||
FORMAT='%15s *'
|
||||
fi
|
||||
@@ -1498,7 +1626,7 @@ nvm_print_versions() {
|
||||
LTS="${LTS##Latest }"
|
||||
LTS_LENGTH="${#LTS}"
|
||||
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
|
||||
LTS_FORMAT=" %${LTS_LENGTH}s"
|
||||
fi
|
||||
@@ -1506,7 +1634,7 @@ nvm_print_versions() {
|
||||
*)
|
||||
LTS_LENGTH="${#LTS}"
|
||||
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
|
||||
LTS_FORMAT=" %${LTS_LENGTH}s"
|
||||
fi
|
||||
@@ -2224,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
|
||||
# until none are left.
|
||||
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
|
||||
local NVM_CONFIG_VALUE
|
||||
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
|
||||
@@ -2430,6 +2558,46 @@ nvm() {
|
||||
do
|
||||
case $i in
|
||||
'-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
|
||||
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
|
||||
local NVM_NODE_PREFIX
|
||||
@@ -2447,6 +2615,7 @@ nvm() {
|
||||
nvm_echo
|
||||
nvm_echo 'Usage:'
|
||||
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 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`:'
|
||||
@@ -2502,6 +2671,18 @@ nvm() {
|
||||
nvm_echo ' --silent Silences stdout/stderr output when a version is omitted'
|
||||
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
||||
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
||||
nvm_echo ' 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 'Example:'
|
||||
nvm_echo ' nvm install 8.0.0 Install a specific version number'
|
||||
@@ -2516,6 +2697,8 @@ nvm() {
|
||||
nvm_echo ' nvm install --lts Install the latest LTS version'
|
||||
nvm_echo ' nvm use --lts Use the latest LTS version'
|
||||
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 ' to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)'
|
||||
nvm_echo
|
||||
@@ -3376,6 +3559,7 @@ nvm() {
|
||||
local PATTERN
|
||||
local NVM_NO_COLORS
|
||||
local NVM_NO_ALIAS
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1}" in
|
||||
--) ;;
|
||||
@@ -3413,6 +3597,7 @@ nvm() {
|
||||
local NVM_LTS
|
||||
local PATTERN
|
||||
local NVM_NO_COLORS
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1-}" in
|
||||
--) ;;
|
||||
@@ -3523,6 +3708,7 @@ nvm() {
|
||||
local NVM_NO_COLORS
|
||||
ALIAS='--'
|
||||
TARGET='--'
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "${1-}" in
|
||||
--) ;;
|
||||
@@ -3712,7 +3898,7 @@ nvm() {
|
||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||
;;
|
||||
"--version" | "-v")
|
||||
nvm_echo '0.37.0'
|
||||
nvm_echo '0.37.1'
|
||||
;;
|
||||
"unload")
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
@@ -3754,11 +3940,25 @@ nvm() {
|
||||
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
|
||||
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
|
||||
nvm_npmrc_bad_news_bears \
|
||||
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
|
||||
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_COLORS INSTALLED_COLOR SYSTEM_COLOR \
|
||||
CURRENT_COLOR NOT_INSTALLED_COLOR DEFAULT_COLOR LTS_COLOR \
|
||||
>/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
|
||||
return 127
|
||||
|
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.37.0",
|
||||
"version": "0.37.1",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
|
||||
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
|
||||
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); env -i TERM=\"$TERM\" bash -lc \"make TEST_SUITE=fast test-$shell\"",
|
||||
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
|
||||
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
|
||||
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",
|
||||
|
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
|
@@ -27,7 +27,9 @@ EXPECTED_OUTPUT="$(nvm_add_iojs_prefix ${VERSION})"
|
||||
|
||||
nvm use --delete-prefix iojs || die '`nvm use iojs` failed'
|
||||
|
||||
CURRENT="$(nvm current)"
|
||||
# Remove node_modules/.bin from the path so that the system version `which` is
|
||||
# used in nvm_ls_current
|
||||
PATH=$(echo "$PATH" | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") CURRENT="$(nvm current)"
|
||||
echo "current: ${CURRENT}"
|
||||
|
||||
[ "${CURRENT}" = "${IOJS_VERSION}" ] || die "expected >${IOJS_VERSION}<; got >${CURRENT}<"
|
||||
|
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() {
|
||||
unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs
|
||||
if [ -n TEMP_NVM_COLORS ]; then
|
||||
export NVM_COLORS=TEMP_NVM_COLORS
|
||||
fi
|
||||
unset TEMP_NVM_COLORS
|
||||
}
|
||||
|
||||
\. ../../../nvm.sh
|
||||
if [ -n ${NVM_COLORS} ]; then
|
||||
export TEMP_NVM_COLORS=NVM_COLORS
|
||||
unset NVM_COLORS
|
||||
fi
|
||||
|
||||
nvm deactivate 2>/dev/null || die 'unable to deactivate'
|
||||
|
||||
|
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
|
@@ -84,6 +84,9 @@ 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'"
|
||||
[ "_$EXIT_CODE" = "_4" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
|
||||
|
||||
OUTPUT="$(export FOO='NPM_CONFIG_PREFIX' ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop; got '$OUTPUT'"
|
||||
|
||||
# npmrc tests
|
||||
(
|
||||
cd "${TEST_DIR}"
|
||||
|
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
|
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