Merge branch 'master' into master

This commit is contained in:
hierarchy-orbit 2021-04-02 00:15:55 +08:00 committed by GitHub
commit 6d27119e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 83 deletions

View File

@ -28,14 +28,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main - uses: ljharb/actions/node/run@main
name: 'npm install && npm run dockerfile_lint' name: 'npm install && npm run doctoc'
with: with:
node-version: 'lts/*' node-version: 'lts/*'
shell-command: | command: "doctoc:check"
set -e
cp README.md README.md.orig
npm run doctoc
diff -q README.md README.md.orig
test_naming: test_naming:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -1,4 +1,4 @@
# Node Version Manager [![Build Status](https://travis-ci.org/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.37.2-yellow.svg)][4] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684) # Node Version Manager [![Build Status](https://travis-ci.org/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.38.0-yellow.svg)][4] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684)
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` --> <!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
@ -27,6 +27,9 @@
- [Setting Custom Colors](#setting-custom-colors) - [Setting Custom Colors](#setting-custom-colors)
- [Persisting custom colors](#persisting-custom-colors) - [Persisting custom colors](#persisting-custom-colors)
- [Suppressing colorized output](#suppressing-colorized-output) - [Suppressing colorized output](#suppressing-colorized-output)
- [Restoring PATH](#restoring-path)
- [Set default node version](#set-default-node-version)
- [Use a mirror of node binaries](#use-a-mirror-of-node-binaries)
- [.nvmrc](#nvmrc) - [.nvmrc](#nvmrc)
- [Deeper Shell Integration](#deeper-shell-integration) - [Deeper Shell Integration](#deeper-shell-integration)
- [bash](#bash) - [bash](#bash)
@ -61,10 +64,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.37.2/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
``` ```
```sh ```sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
``` ```
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
@ -89,6 +92,15 @@ Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not conta
#### Troubleshooting on Linux #### Troubleshooting on Linux
On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again. On Linux, after running the install script, if you get `nvm: command not found` or see no feedback from your terminal after you type `command -v nvm`, simply close your current terminal, open a new terminal, and try verifying again.
Alternatively, you can run run the following commands for the different shells on the command line:
*bash*: `source ~/.bashrc`
*zsh*: `source ~/.zshrc`
*ksh*: `. ~/.profile`
These should pick up the `nvm` command.
#### Troubleshooting on macOS #### Troubleshooting on macOS
@ -98,11 +110,13 @@ If you get `nvm: command not found` after running the install script, one of the
- Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again. - Since macOS 10.15, the default shell is `zsh` and nvm will look for `.zshrc` to update, none is installed by default. Create one with `touch ~/.zshrc` and run the install script again.
- If you use bash, the previous default shell, run `touch ~/.bash_profile` to create the necessary profile file if it does not exist. - If you use bash, the previous default shell, your system may not have a `.bash_profile` file where the command is set up. Create one with `touch ~/.bash_profile` and run the install script again. Then, run `source ~/.bash_profile` to pick up the `nvm` command.
- You have previously used `bash`, but you have `zsh` installed. You need to manually add [these lines](#manual-install) to `~/.zshrc` and run `. ~/.zshrc`.
- You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration. - You might need to restart your terminal instance or run `. ~/.nvm/nvm.sh`. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
- You have previously used `bash`, but you have `zsh` installed. You need to manually add [these lines](#manual-install) to `~/.zshrc` and run `. ~/.zshrc`. - If the above didn't help, you might need to restart your terminal instance. Try opening a new tab/window in your terminal and retry.
If the above doesn't fix the problem, you may try the following: If the above doesn't fix the problem, you may try the following:
@ -119,7 +133,7 @@ You can use a task:
```yaml ```yaml
- name: nvm - name: nvm
shell: > shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
args: args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh" creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
``` ```
@ -138,10 +152,11 @@ which should output `nvm` if the installation was successful. Please note that `
If you're running a system without prepackaged binary available, which means you're going to install nodejs or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work. If you're running a system without prepackaged binary available, which means you're going to install nodejs or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work.
**Note:** `nvm` does not support Windows (see [#284](https://github.com/nvm-sh/nvm/issues/284)), but may work in WSL (Windows Subsystem for Linux) depending on the version of WSL. For Windows, two alternatives exist, which are neither supported nor developed by us: **Note:** `nvm` does not support Windows (see [#284](https://github.com/nvm-sh/nvm/issues/284)), but may work in WSL (Windows Subsystem for Linux) depending on the version of WSL. For Windows, a few alternatives exist, which are neither supported nor developed by us:
- [nvm-windows](https://github.com/coreybutler/nvm-windows) - [nvm-windows](https://github.com/coreybutler/nvm-windows)
- [nodist](https://github.com/marcelklehr/nodist) - [nodist](https://github.com/marcelklehr/nodist)
- [nvs](https://github.com/jasongin/nvs)
**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us: **Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
@ -178,7 +193,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.37.2` 1. `cd ~/.nvm` and check out the latest version with `git checkout v0.38.0`
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh` 1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login: Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
@ -429,18 +444,21 @@ nvm help --no-colors
TERM=dumb nvm ls TERM=dumb nvm ls
``` ```
#### Restoring PATH
To restore your PATH, you can deactivate it: To restore your PATH, you can deactivate it:
```sh ```sh
nvm deactivate nvm deactivate
``` ```
#### Set default node version
To set a default Node version to be used in any new shell, use the alias 'default': To set a default Node version to be used in any new shell, use the alias 'default':
```sh ```sh
nvm alias default node nvm alias default node
``` ```
#### Use a mirror of node binaries
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`: To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
```sh ```sh
@ -754,7 +772,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.37.2/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
``` ```
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries. The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
@ -851,9 +869,9 @@ 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.37.2/install.sh [2]: https://github.com/nvm-sh/nvm/blob/v0.38.0/install.sh
[3]: https://travis-ci.org/nvm-sh/nvm [3]: https://travis-ci.org/nvm-sh/nvm
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.2 [4]: https://github.com/nvm-sh/nvm/releases/tag/v0.38.0
[Urchin]: https://github.com/scraperwiki/urchin [Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com [Fish]: http://fishshell.com
@ -901,13 +919,19 @@ arm64
$ nvm install v12.20.1 $ nvm install v12.20.1
# Now uninstall the version we want to replace: # Now uninstall the version we want to replace:
$ nvm uninstall v14.15.4 $ nvm uninstall v14.15.4
# Set the architecture for our shell to 64-bit X86: # Launch a new zsh process under the 64-bit X86 architecture:
$ arch -x86_64 zsh $ arch -x86_64 zsh
# Install node using nvm. This should download the precompiled x64 binary: # Install node using nvm. This should download the precompiled x64 binary:
$ nvm install v14.15.4 $ nvm install v14.15.4
# Now check that the architecture is correct: # Now check that the architecture is correct:
$ node -p process.arch $ node -p process.arch
x64 x64
# It is now safe to revert zsh back to the native architecture: # It is now safe to return to the arm64 zsh process:
$ arch -arm64 zsh $ exit
# We're back to a native shell:
$ arch
arm64
# And the new version is now available to use:
$ nvm use v14.15.4
Now using node v14.15.4 (npm v6.14.10)
``` ```

View File

@ -6,6 +6,10 @@ nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
nvm_echo() {
command printf %s\\n "$*" 2>/dev/null
}
nvm_grep() { nvm_grep() {
GREP_OPTIONS='' command grep "$@" GREP_OPTIONS='' command grep "$@"
} }
@ -23,7 +27,7 @@ nvm_install_dir() {
} }
nvm_latest_version() { nvm_latest_version() {
echo "v0.37.2" nvm_echo "v0.38.0"
} }
nvm_profile_is_bash_or_zsh() { nvm_profile_is_bash_or_zsh() {
@ -64,18 +68,18 @@ nvm_source() {
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git" NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
else else
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD" nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1 return 1
fi fi
fi fi
echo "$NVM_SOURCE_URL" nvm_echo "$NVM_SOURCE_URL"
} }
# #
# Node.js version to install # Node.js version to install
# #
nvm_node_version() { nvm_node_version() {
echo "$NODE_VERSION" nvm_echo "$NODE_VERSION"
} }
nvm_download() { nvm_download() {
@ -108,7 +112,7 @@ install_nvm_from_git() {
: :
# Check if version is an existing changeset # Check if version is an existing changeset
elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then
echo >&2 "Failed to find '$NVM_VERSION' version." nvm_echo >&2 "Failed to find '$NVM_VERSION' version."
exit 1 exit 1
fi fi
fi fi
@ -116,29 +120,29 @@ install_nvm_from_git() {
local fetch_error local fetch_error
if [ -d "$INSTALL_DIR/.git" ]; then if [ -d "$INSTALL_DIR/.git" ]; then
# Updating repo # Updating repo
echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git" nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
command printf '\r=> ' command printf '\r=> '
fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself." fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself."
else else
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!" fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
echo "=> Downloading nvm from git to '$INSTALL_DIR'" nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
command printf '\r=> ' command printf '\r=> '
mkdir -p "${INSTALL_DIR}" mkdir -p "${INSTALL_DIR}"
if [ "$(ls -A "${INSTALL_DIR}")" ]; then if [ "$(ls -A "${INSTALL_DIR}")" ]; then
# Initializing repo # Initializing repo
command git init "${INSTALL_DIR}" || { command git init "${INSTALL_DIR}" || {
echo >&2 'Failed to initialize nvm repo. Please report this!' nvm_echo >&2 'Failed to initialize nvm repo. Please report this!'
exit 2 exit 2
} }
command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \ command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \
|| command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || { || command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || {
echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!' nvm_echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
exit 2 exit 2
} }
else else
# Cloning repo # Cloning repo
command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || { command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
echo >&2 'Failed to clone nvm repo. Please report this!' nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
exit 2 exit 2
} }
fi fi
@ -148,28 +152,28 @@ install_nvm_from_git() {
: :
# Fetch given version # Fetch given version
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then
echo >&2 "$fetch_error" nvm_echo >&2 "$fetch_error"
exit 1 exit 1
fi fi
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet FETCH_HEAD || { command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet FETCH_HEAD || {
echo >&2 "Failed to checkout the given version $NVM_VERSION. Please report this!" nvm_echo >&2 "Failed to checkout the given version $NVM_VERSION. Please report this!"
exit 2 exit 2
} }
if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then if [ -n "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1 command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
else else
echo >&2 "Your version of git is out of date. Please update it!" nvm_echo >&2 "Your version of git is out of date. Please update it!"
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1 command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch -D master >/dev/null 2>&1
fi fi
fi fi
echo "=> Compressing and cleaning up git repository" nvm_echo "=> Compressing and cleaning up git repository"
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" reflog expire --expire=now --all; then if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" reflog expire --expire=now --all; then
echo >&2 "Your version of git is out of date. Please update it!" nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi fi
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then
echo >&2 "Your version of git is out of date. Please update it!" nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi fi
return return
} }
@ -185,15 +189,15 @@ nvm_install_node() {
return 0 return 0
fi fi
echo "=> Installing Node.js version $NODE_VERSION_LOCAL" nvm_echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
nvm install "$NODE_VERSION_LOCAL" nvm install "$NODE_VERSION_LOCAL"
local CURRENT_NVM_NODE local CURRENT_NVM_NODE
CURRENT_NVM_NODE="$(nvm_version current)" CURRENT_NVM_NODE="$(nvm_version current)"
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed" nvm_echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
else else
echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL" nvm_echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
fi fi
} }
@ -210,20 +214,20 @@ install_nvm_as_script() {
# Downloading to $INSTALL_DIR # Downloading to $INSTALL_DIR
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
if [ -f "$INSTALL_DIR/nvm.sh" ]; then if [ -f "$INSTALL_DIR/nvm.sh" ]; then
echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script" nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"
else else
echo "=> Downloading nvm as script to '$INSTALL_DIR'" nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'"
fi fi
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || { nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'" nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
return 1 return 1
} & } &
nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || { nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
echo >&2 "Failed to download '$NVM_EXEC_SOURCE'" nvm_echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2 return 2
} & } &
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || { nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || {
echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'" nvm_echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'"
return 2 return 2
} & } &
for job in $(jobs -p | command sort) for job in $(jobs -p | command sort)
@ -231,7 +235,7 @@ install_nvm_as_script() {
wait "$job" || return $? wait "$job" || return $?
done done
chmod a+x "$INSTALL_DIR/nvm-exec" || { chmod a+x "$INSTALL_DIR/nvm-exec" || {
echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable" nvm_echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
return 3 return 3
} }
} }
@ -240,7 +244,7 @@ nvm_try_profile() {
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
return 1 return 1
fi fi
echo "${1}" nvm_echo "${1}"
} }
# #
@ -256,7 +260,7 @@ nvm_detect_profile() {
fi fi
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
echo "${PROFILE}" nvm_echo "${PROFILE}"
return return
fi fi
@ -283,7 +287,7 @@ nvm_detect_profile() {
fi fi
if [ -n "$DETECTED_PROFILE" ]; then if [ -n "$DETECTED_PROFILE" ]; then
echo "$DETECTED_PROFILE" nvm_echo "$DETECTED_PROFILE"
fi fi
} }
@ -316,37 +320,37 @@ nvm_check_global_modules() {
if [ "${MODULE_COUNT}" != '0' ]; then if [ "${MODULE_COUNT}" != '0' ]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '=> You currently have modules installed globally with `npm`. These will no' nvm_echo '=> You currently have modules installed globally with `npm`. These will no'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '=> longer be linked to the active version of Node when you install a new node' nvm_echo '=> longer be linked to the active version of Node when you install a new node'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)' nvm_echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '=> override the binaries of modules installed with `nvm`:' nvm_echo '=> override the binaries of modules installed with `nvm`:'
echo nvm_echo
command printf %s\\n "$NPM_GLOBAL_MODULES" command printf %s\\n "$NPM_GLOBAL_MODULES"
echo '=> If you wish to uninstall them at a later point (or re-install them under your' nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '=> `nvm` Nodes), you can remove them from the system Node as follows:' nvm_echo '=> `nvm` Nodes), you can remove them from the system Node as follows:'
echo nvm_echo
echo ' $ nvm use system' nvm_echo ' $ nvm use system'
echo ' $ npm uninstall -g a_module' nvm_echo ' $ npm uninstall -g a_module'
echo nvm_echo
fi fi
} }
nvm_do_install() { nvm_do_install() {
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
if [ -e "${NVM_DIR}" ]; then if [ -e "${NVM_DIR}" ]; then
echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory." nvm_echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
exit 1 exit 1
fi fi
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
mkdir "${NVM_DIR}" mkdir "${NVM_DIR}"
else else
echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment." nvm_echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
exit 1 exit 1
fi fi
fi fi
@ -357,27 +361,27 @@ nvm_do_install() {
elif nvm_has nvm_download; then elif nvm_has nvm_download; then
install_nvm_as_script install_nvm_as_script
else else
echo >&2 'You need git, curl, or wget to install nvm' nvm_echo >&2 'You need git, curl, or wget to install nvm'
exit 1 exit 1
fi fi
elif [ "${METHOD}" = 'git' ]; then elif [ "${METHOD}" = 'git' ]; then
if ! nvm_has git; then if ! nvm_has git; then
echo >&2 "You need git to install nvm" nvm_echo >&2 "You need git to install nvm"
exit 1 exit 1
fi fi
install_nvm_from_git install_nvm_from_git
elif [ "${METHOD}" = 'script' ]; then elif [ "${METHOD}" = 'script' ]; then
if ! nvm_has nvm_download; then if ! nvm_has nvm_download; then
echo >&2 "You need curl or wget to install nvm" nvm_echo >&2 "You need curl or wget to install nvm"
exit 1 exit 1
fi fi
install_nvm_as_script install_nvm_as_script
else else
echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method." nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
exit 1 exit 1
fi fi
echo nvm_echo
local NVM_PROFILE local NVM_PROFILE
NVM_PROFILE="$(nvm_detect_profile)" NVM_PROFILE="$(nvm_detect_profile)"
@ -395,32 +399,32 @@ nvm_do_install() {
if [ -n "${PROFILE}" ]; then if [ -n "${PROFILE}" ]; then
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), " TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
fi fi
echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again" nvm_echo "=> Create one of them and run this script again"
echo " OR" nvm_echo " OR"
echo "=> Append the following lines to the correct file yourself:" nvm_echo "=> Append the following lines to the correct file yourself:"
command printf "${SOURCE_STR}" command printf "${SOURCE_STR}"
echo nvm_echo
else else
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
BASH_OR_ZSH=true BASH_OR_ZSH=true
fi fi
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
echo "=> Appending nvm source string to $NVM_PROFILE" nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf "${SOURCE_STR}" >> "$NVM_PROFILE" command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
else else
echo "=> nvm source string already in ${NVM_PROFILE}" nvm_echo "=> nvm source string already in ${NVM_PROFILE}"
fi fi
# shellcheck disable=SC2016 # shellcheck disable=SC2016
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
echo "=> Appending bash_completion source string to $NVM_PROFILE" nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
command printf "$COMPLETION_STR" >> "$NVM_PROFILE" command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
else else
echo "=> bash_completion source string already in ${NVM_PROFILE}" nvm_echo "=> bash_completion source string already in ${NVM_PROFILE}"
fi fi
fi fi
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
echo "=> Please also append the following lines to the if you are using bash/zsh shell:" nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
command printf "${COMPLETION_STR}" command printf "${COMPLETION_STR}"
fi fi
@ -434,7 +438,7 @@ nvm_do_install() {
nvm_reset nvm_reset
echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:" nvm_echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
command printf "${SOURCE_STR}" command printf "${SOURCE_STR}"
if ${BASH_OR_ZSH} ; then if ${BASH_OR_ZSH} ; then
command printf "${COMPLETION_STR}" command printf "${COMPLETION_STR}"

2
nvm.sh
View File

@ -3971,7 +3971,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.37.2' nvm_echo '0.38.0'
;; ;;
"unload") "unload")
nvm deactivate >/dev/null 2>&1 nvm deactivate >/dev/null 2>&1

View File

@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.37.2", "version": "0.38.0",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"
@ -15,6 +15,9 @@
"test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell", "test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell",
"test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell", "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell",
"doctoc": "doctoc --title='## Table of Contents' --github README.md", "doctoc": "doctoc --title='## Table of Contents' --github README.md",
"predoctoc:check": "cp README.md v-README.md.orig && npm run doctoc",
"doctoc:check": "diff -q README.md v-README.md.orig",
"postdoctoc:check": "mv v-README.md.orig README.md",
"eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)", "eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)",
"dockerfile_lint": "dockerfile_lint" "dockerfile_lint": "dockerfile_lint"
}, },
@ -36,11 +39,11 @@
}, },
"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.4",
"doctoc": "^2.0.0", "doctoc": "^2.0.0",
"eclint": "^2.6.0", "eclint": "^2.8.1",
"replace": "^1.2.0", "replace": "^1.2.1",
"semver": "^7.3.4", "semver": "^7.3.5",
"urchin": "^0.0.5" "urchin": "^0.0.5"
} }
} }