Compare commits

..

2 Commits

Author SHA1 Message Date
Siddhant
9603fc8b5d Merge 58029b1ddc into 1be4257e96 2024-11-02 17:08:16 +07:00
Siddhant
58029b1ddc Enhance logging system with levels and timestamps
- Add new logging functions: nvm_log, nvm_debug, nvm_info, nvm_warn, nvm_error
- Implement log levels (DEBUG, INFO, WARN, ERROR)
- Add timestamps to log messages
- Create nvm_run_command for logging command executions
- Implement nvm_time_operation for timing long-running operations
- Add nvm_log_env to log environment information
- Update nvm function to log version and environment on start
2024-09-11 16:30:16 +05:30
19 changed files with 239 additions and 394 deletions

View File

@@ -1,11 +1,3 @@
---
name: File an issue…
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
<!-- Thank you for being interested in nvm! Please help us by filling out the following form if youre having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! --> <!-- Thank you for being interested in nvm! Please help us by filling out the following form if youre having trouble. If you have a feature request, or some other question, please feel free to clear out the form. Thanks! -->

View File

@@ -1 +0,0 @@
blank_issues_enabled: false

View File

@@ -37,11 +37,6 @@ jobs:
matrix: matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }} node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
include: include:
- node-version: "21"
- node-version: "20.5"
- node-version: "20.4"
- node-version: "14.17"
- node-version: "14.16"
- node-version: "9.2" - node-version: "9.2"
- node-version: "9.1" - node-version: "9.1"
- node-version: "9.0" - node-version: "9.0"

View File

@@ -19,8 +19,6 @@ jobs:
raw.githubusercontent.com:443 raw.githubusercontent.com:443
registry.npmjs.org:443 registry.npmjs.org:443
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-tags: true
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: "14" node-version: "14"

View File

@@ -1,6 +1,6 @@
name: urchin tests name: urchin tests
on: [push, pull_request] on: [push]
permissions: permissions:
contents: read contents: read
@@ -31,8 +31,6 @@ jobs:
suite: suite:
- install_script - install_script
- sourcing - sourcing
- slow
- installation_iojs
shell: shell:
- sh - sh
- bash - bash

View File

@@ -20,7 +20,6 @@ jobs:
allowed-endpoints: allowed-endpoints:
github.com:443 github.com:443
registry.npmjs.org:443 registry.npmjs.org:443
api.github.com:443
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
# https://github.com/actions/checkout/issues/217#issue-599945005 # https://github.com/actions/checkout/issues/217#issue-599945005
@@ -31,7 +30,7 @@ jobs:
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- uses: actions/setup-node@v4 - uses: actions/setup-node@v4
with: with:
node-version: 'lts/*' node-version: '16'
- run: npm install - run: npm install
- run: npm run doctoc - run: npm run doctoc
- name: commit changes - name: commit changes

View File

@@ -87,8 +87,18 @@ env:
- 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=slow
- SHELL=dash TEST_SUITE=slow
- SHELL=bash TEST_SUITE=slow
- SHELL=zsh TEST_SUITE=slow
# - SHELL=ksh TEST_SUITE=slow
- 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 WITHOUT_CURL=1 - SHELL=dash TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=bash TEST_SUITE=installation_iojs
- 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 WITHOUT_CURL=1 - SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_iojs
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1 # - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1

View File

@@ -113,11 +113,3 @@ Co-authored-by: Name Here <email@here>
# Where can I ask for help? # Where can I ask for help?
If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com). If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com).
# Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
- The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
- The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
- The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
- I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

View File

@@ -91,20 +91,16 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Switch to user "nvm" from now # Switch to user "nvm" from now
USER nvm USER nvm
# Create a script file sourced by both interactive and non-interactive bash shells
ENV BASH_ENV /home/nvm/.bash_env
RUN touch "$BASH_ENV"
RUN echo '. "$BASH_ENV"' >> "$HOME/.bashrc"
# nvm # nvm
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$BASH_ENV" RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc"
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$BASH_ENV" RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc"
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$BASH_ENV" RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc"
# nodejs and tools # nodejs and tools
RUN nvm install node RUN bash -c 'source $HOME/.nvm/nvm.sh && \
RUN npm install -g doctoc urchin eclint dockerfile_lint nvm install node && \
RUN npm install --prefix "$HOME/.nvm/" npm install -g doctoc urchin eclint dockerfile_lint && \
npm install --prefix "$HOME/.nvm/"'
# Set WORKDIR to nvm directory # Set WORKDIR to nvm directory
WORKDIR /home/nvm/.nvm WORKDIR /home/nvm/.nvm

129
README.md
View File

@@ -6,7 +6,7 @@
</a> </a>
# Node Version Manager [![Build Status](https://app.travis-ci.com/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.3-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/projects/684) # Node Version Manager [![Build Status](https://app.travis-ci.com/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.40.1-yellow.svg)][4] [![CII Best Practices](https://bestpractices.dev/projects/684/badge)](https://bestpractices.dev/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 -->
@@ -18,8 +18,6 @@
- [Installing and Updating](#installing-and-updating) - [Installing and Updating](#installing-and-updating)
- [Install & Update Script](#install--update-script) - [Install & Update Script](#install--update-script)
- [Additional Notes](#additional-notes) - [Additional Notes](#additional-notes)
- [Installing in Docker](#installing-in-docker)
- [Installing in Docker for CICD-Jobs](#installing-in-docker-for-cicd-jobs)
- [Troubleshooting on Linux](#troubleshooting-on-linux) - [Troubleshooting on Linux](#troubleshooting-on-linux)
- [Troubleshooting on macOS](#troubleshooting-on-macos) - [Troubleshooting on macOS](#troubleshooting-on-macos)
- [Ansible](#ansible) - [Ansible](#ansible)
@@ -104,13 +102,13 @@ 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.40.3/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
``` ```
```sh ```sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.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 (`~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, or `~/.profile`). If you find the install script is updating the wrong profile file, set the `$PROFILE` env var to the profile files path, and then rerun the installation script. 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`).
<a id="profile_snippet"></a> <a id="profile_snippet"></a>
```sh ```sh
@@ -122,94 +120,14 @@ export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || pr
- If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub> - If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
- You can add `--no-use` to the end of the above script to postpone using `nvm` until you manually [`use`](#usage) it: - You can add `--no-use` to the end of the above script (...`nvm.sh --no-use`) to postpone using `nvm` until you manually [`use`](#usage) it.
```sh
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use # This loads nvm, without auto-using the default version
```
- You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables. - You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables.
Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash. Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash.
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available. - The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash'` - You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash'`
#### Installing in Docker
When invoking bash as a non-interactive shell, like in a Docker container, none of the regular profile files are sourced. In order to use `nvm`, `node`, and `npm` like normal, you can instead specify the special `BASH_ENV` variable, which bash sources when invoked non-interactively.
```Dockerfile
# Use bash for the shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Create a script file sourced by both interactive and non-interactive bash shells
ENV BASH_ENV /home/user/.bash_env
RUN touch "${BASH_ENV}"
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
# Download and install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | PROFILE="${BASH_ENV}" bash
RUN echo node > .nvmrc
RUN nvm install
```
##### Installing in Docker for CICD-Jobs
More robust, works in CI/CD-Jobs. Can be run in interactive and non-interactive containers.
See https://github.com/nvm-sh/nvm/issues/3531.
```Dockerfile
FROM ubuntu:latest
ARG NODE_VERSION=20
# install curl
RUN apt update && apt install curl -y
# install nvm
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# set env
ENV NVM_DIR=/root/.nvm
# install node
RUN bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION"
# set ENTRYPOINT for reloading nvm-environment
ENTRYPOINT ["bash", "-c", "source $NVM_DIR/nvm.sh && exec \"$@\"", "--"]
# set cmd to bash
CMD ["/bin/bash"]
```
This example defaults to installation of nodejs version 20.x.y. Optionally you can easily override the version with docker build args like:
```
docker build -t nvmimage --build-arg NODE_VERSION=19 .
```
After creation of the image you can start container interactively and run commands, for example:
```
docker run --rm -it nvmimage
root@0a6b5a237c14:/# nvm -v
0.40.3
root@0a6b5a237c14:/# node -v
v19.9.0
root@0a6b5a237c14:/# npm -v
9.6.3
```
Noninteractive example:
```
user@host:/tmp/test $ docker run --rm -it nvmimage node -v
v19.9.0
user@host:/tmp/test $ docker run --rm -it nvmimage npm -v
9.6.3
```
#### Troubleshooting on Linux #### Troubleshooting on Linux
@@ -257,7 +175,7 @@ You can use a task:
```yaml ```yaml
- name: Install nvm - name: Install nvm
ansible.builtin.shell: > ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
args: args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh" creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
``` ```
@@ -289,7 +207,7 @@ If you're running a system without prepackaged binary available, which means you
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell - [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup - [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell - [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
- [nvm.fish](https://github.com/jorgebucaran/nvm.fish) - The Node.js version manager you'll adore, crafted just for Fish - [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used. - [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket: **Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:
@@ -309,7 +227,7 @@ If you're running a system without prepackaged binary available, which means you
Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue. Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue.
**Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade ([you can set](https://github.com/lukechilds/zsh-nvm#auto-use) `NVM_AUTO_USE=true` to have it automatically detect and use `.nvmrc` files). **Note:** If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade.
**Note:** Git versions before v1.7 may face a problem of cloning `nvm` source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to [v1.17.10](https://github.com/git/git/commit/5a7d5b683f869d3e3884a89775241afa515da9e7) can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article. **Note:** Git versions before v1.7 may face a problem of cloning `nvm` source from GitHub via https protocol, and there is also different behavior of git before v1.6, and git prior to [v1.17.10](https://github.com/git/git/commit/5a7d5b683f869d3e3884a89775241afa515da9e7) can not clone tags, so the minimum required git version is v1.7.10. If you are interested in the problem we mentioned here, please refer to GitHub's [HTTPS cloning errors](https://help.github.com/articles/https-cloning-errors/) article.
@@ -319,7 +237,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.40.3` 1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.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:
@@ -670,7 +588,9 @@ Run [`npx nvmrc`](https://npmjs.com/nvmrc) to validate an `.nvmrc` file. If that
### Deeper Shell Integration ### Deeper Shell Integration
You can use [`nvshim`](https://github.com/iamogbz/nvshim) to shim the `node`, `npm`, and `npx` bins to automatically use the `nvm` config in the current directory. `nvshim` is **not** supported by the `nvm` maintainers. Please [report issues to the `nvshim` team](https://github.com/iamogbz/nvshim/issues/new). You can use [`avn`](https://github.com/wbyoung/avn) to deeply integrate into your shell and automatically invoke `nvm` when changing directories. `avn` is **not** supported by the `nvm` maintainers. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/issues/new).
You can also use [`nvshim`](https://github.com/iamogbz/nvshim) to shim the `node`, `npm`, and `npx` bins to automatically use the `nvm` config in the current directory. `nvshim` is **not** supported by the `nvm` maintainers. Please [report issues to the `nvshim` team](https://github.com/iamogbz/nvshim/issues/new).
If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` maintainers. We are, however, accepting pull requests for more examples. If you prefer a lighter-weight solution, the recipes below have been contributed by `nvm` users. They are **not** supported by the `nvm` maintainers. We are, however, accepting pull requests for more examples.
@@ -765,8 +685,6 @@ add-zsh-hook chpwd load-nvmrc
load-nvmrc load-nvmrc
``` ```
After saving the file, run `source ~/.zshrc` to reload the configuration with the latest changes made.
##### fish ##### fish
This requires that you have [bass](https://github.com/edc/bass) installed. This requires that you have [bass](https://github.com/edc/bass) installed.
@@ -890,7 +808,7 @@ my_alias default v10.22.0 v12.18.3 v14.8.0
## Compatibility Issues ## Compatibility Issues
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](https://github.com/nvm-sh/nvm/issues/606)) `nvm` will encounter some issues if you have some non-default settings set. (see [#606](https://github.com/creationix/nvm/issues/606))
The following are known to cause issues: The following are known to cause issues:
Inside `~/.npmrc`: Inside `~/.npmrc`:
@@ -925,13 +843,13 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
### Alpine Linux 3.13+ ### Alpine Linux 3.13+
```sh ```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
``` ```
### Alpine Linux 3.5 - 3.12 ### Alpine Linux 3.5 - 3.12
```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.40.3/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
``` ```
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._ _Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
@@ -1034,9 +952,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.40.3/install.sh [2]: https://github.com/nvm-sh/nvm/blob/v0.40.1/install.sh
[3]: https://app.travis-ci.com/nvm-sh/nvm [3]: https://app.travis-ci.com/nvm-sh/nvm
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.3 [4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.1
[Urchin]: https://git.sdf.org/tlevine/urchin [Urchin]: https://git.sdf.org/tlevine/urchin
[Fish]: https://fishshell.com [Fish]: https://fishshell.com
@@ -1094,7 +1012,7 @@ Here's what you will need to do:
If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag. If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag.
However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors. However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors.
If you want to avoid the possible hassle of dealing with this, include that flag. If you want to avoid the possible hassle of dealing with this, include that flag.
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.376) For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.176)
- Exit back to your native shell. - Exit back to your native shell.
@@ -1121,7 +1039,7 @@ Now you should be able to use node as usual.
If you've encountered this error on WSL-2: If you've encountered this error on WSL-2:
```sh ```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com 0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
@@ -1156,7 +1074,7 @@ Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more ma
## Project Support ## Project Support
Only the latest version (v0.40.3 at this time) is supported. Only the latest version (v0.40.1 at this time) is supported.
## Enterprise Support ## Enterprise Support
@@ -1170,5 +1088,6 @@ See [LICENSE.md](./LICENSE.md).
## Copyright notice ## Copyright notice
Copyright [OpenJS Foundation](https://openjsf.org) and `nvm` contributors. All rights reserved. The [OpenJS Foundation](https://openjsf.org) has registered trademarks and uses trademarks. For a list of trademarks of the [OpenJS Foundation](https://openjsf.org), please see our [Trademark Policy](https://trademark-policy.openjsf.org/) and [Trademark List](https://trademark-list.openjsf.org/). Trademarks and logos not indicated on the [list of OpenJS Foundation trademarks](https://trademark-list.openjsf.org) are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them. Copyright [OpenJS Foundation](https://openjsf.org) and `nvm` contributors. All rights reserved. The [OpenJS Foundation](https://openjsf.org) has registered trademarks and uses trademarks. For a list of trademarks of the [OpenJS Foundation](https://openjsf.org), please see our [Trademark Policy](https://trademark-policy.openjsf.org/) and [Trademark List](https://trademark-list.openjsf.org/). Node.js is a trademark of Joyent, Inc. and is used with its permission. Trademarks and logos not indicated on the [list of OpenJS Foundation trademarks](https://trademark-list.openjsf.org) are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
[The OpenJS Foundation](https://openjsf.org/) | [Terms of Use](https://terms-of-use.openjsf.org/) | [Privacy Policy](https://privacy-policy.openjsf.org/) | [Bylaws](https://bylaws.openjsf.org/) | [Code of Conduct](https://code-of-conduct.openjsf.org) | [Trademark Policy](https://trademark-policy.openjsf.org/) | [Trademark List](https://trademark-list.openjsf.org/) | [Cookie Policy](https://www.linuxfoundation.org/cookies/)
[The OpenJS Foundation](https://openjsf.org/) | [Terms of Use](https://terms-of-use.openjsf.org/) | [Privacy Policy](https://privacy-policy.openjsf.org/) | [OpenJS Foundation Bylaws](https://bylaws.openjsf.org/) | [Trademark Policy](https://trademark-policy.openjsf.org/) | [Trademark List](https://trademark-list.openjsf.org/) | [Cookie Policy](https://www.linuxfoundation.org/cookies/)

View File

@@ -33,7 +33,7 @@ nvm_install_dir() {
} }
nvm_latest_version() { nvm_latest_version() {
nvm_echo "v0.40.3" nvm_echo "v0.40.1"
} }
nvm_profile_is_bash_or_zsh() { nvm_profile_is_bash_or_zsh() {
@@ -296,17 +296,17 @@ nvm_detect_profile() {
DETECTED_PROFILE="$HOME/.bash_profile" DETECTED_PROFILE="$HOME/.bash_profile"
fi fi
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
if [ -f "${ZDOTDIR:-${HOME}}/.zshrc" ]; then if [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc" DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then elif [ -f "$HOME/.zprofile" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile" DETECTED_PROFILE="$HOME/.zprofile"
fi fi
fi fi
if [ -z "$DETECTED_PROFILE" ]; then if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc" for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
do do
if DETECTED_PROFILE="$(nvm_try_profile "${ZDOTDIR:-${HOME}}/${EACH_PROFILE}")"; then if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
break break
fi fi
done done

307
nvm.sh
View File

@@ -13,6 +13,42 @@
# shellcheck disable=SC3028 # shellcheck disable=SC3028
NVM_SCRIPT_SOURCE="$_" NVM_SCRIPT_SOURCE="$_"
NVM_LOG_LEVEL=${NVM_LOG_LEVEL:-INFO}
NVM_VERSION="0.39.0" # Update this with the actual nvm version
nvm_log() {
local level=$1
shift
if [[ $NVM_LOG_LEVEL == DEBUG || ($NVM_LOG_LEVEL == INFO && $level != DEBUG) ]]; then
printf "[%s] [%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$level" "$*" >&2
fi
}
nvm_debug() { nvm_log DEBUG "$@"; }
nvm_info() { nvm_log INFO "$@"; }
nvm_warn() { nvm_log WARN "$@"; }
nvm_error() { nvm_log ERROR "$@"; }
nvm_run_command() {
nvm_debug "Executing: $*"
"$@"
}
nvm_time_operation() {
local start_time=$(date +%s)
"$@"
local end_time=$(date +%s)
local duration=$((end_time - start_time))
nvm_info "Operation took ${duration} seconds"
}
nvm_log_env() {
nvm_debug "Environment:"
nvm_debug " NVM_DIR: $NVM_DIR"
nvm_debug " PATH: $PATH"
nvm_debug " Shell: $SHELL"
}
nvm_is_zsh() { nvm_is_zsh() {
[ -n "${ZSH_VERSION-}" ] [ -n "${ZSH_VERSION-}" ]
} }
@@ -136,17 +172,15 @@ nvm_download() {
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}" eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed " ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
s/--progress-bar /--progress=bar / -e 's/--compressed //' \
s/--compressed // -e 's/--fail //' \
s/--fail // -e 's/-L //' \
s/-L // -e 's/-I /--server-response /' \
s/-I /--server-response / -e 's/-s /-q /' \
s/-s /-q / -e 's/-sS /-nv /' \
s/-sS /-nv / -e 's/-o /-O /' \
s/-o /-O / -e 's/-C - /-c /')
s/-C - /-c /
")
if [ -n "${NVM_AUTH_HEADER:-}" ]; then if [ -n "${NVM_AUTH_HEADER:-}" ]; then
ARGS="${ARGS} --header \"${NVM_AUTH_HEADER}\"" ARGS="${ARGS} --header \"${NVM_AUTH_HEADER}\""
@@ -356,21 +390,6 @@ nvm_install_latest_npm() {
if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then
NVM_IS_20_5_OR_ABOVE=1 NVM_IS_20_5_OR_ABOVE=1
fi fi
local NVM_IS_20_17_OR_ABOVE
NVM_IS_20_17_OR_ABOVE=0
if [ $NVM_IS_20_5_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.17.0; then
NVM_IS_20_17_OR_ABOVE=1
fi
local NVM_IS_21_OR_ABOVE
NVM_IS_21_OR_ABOVE=0
if [ $NVM_IS_20_17_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 21.0.0; then
NVM_IS_21_OR_ABOVE=1
fi
local NVM_IS_22_9_OR_ABOVE
NVM_IS_22_9_OR_ABOVE=0
if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 22.9.0; then
NVM_IS_22_9_OR_ABOVE=1
fi
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || { if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \ [ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
@@ -416,15 +435,8 @@ nvm_install_latest_npm() {
[ $NVM_IS_18_17_OR_ABOVE -eq 0 ] \ [ $NVM_IS_18_17_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_19_OR_ABOVE -eq 1 ] && [ $NVM_IS_20_5_OR_ABOVE -eq 0 ]; } \ || { [ $NVM_IS_19_OR_ABOVE -eq 1 ] && [ $NVM_IS_20_5_OR_ABOVE -eq 0 ]; } \
; then ; then
# TODO: 10.8.3 can run on 16.20.2?? https://github.com/nodejs/Release/issues/884#issuecomment-2558077691
nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`' nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`'
$NVM_NPM_CMD install -g npm@9 $NVM_NPM_CMD install -g npm@9
elif \
[ $NVM_IS_20_17_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_21_OR_ABOVE -eq 1 ] && [ $NVM_IS_22_9_OR_ABOVE -eq 0 ]; } \
; then
nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`'
$NVM_NPM_CMD install -g npm@10
else else
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!' nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
$NVM_NPM_CMD install -g npm $NVM_NPM_CMD install -g npm
@@ -446,7 +458,8 @@ fi
if [ -z "${NVM_DIR-}" ]; then if [ -z "${NVM_DIR-}" ]; then
# shellcheck disable=SC2128 # shellcheck disable=SC2128
if [ -n "${BASH_SOURCE-}" ]; then if [ -n "${BASH_SOURCE-}" ]; then
NVM_SCRIPT_SOURCE="${BASH_SOURCE}" # shellcheck disable=SC2169,SC3054
NVM_SCRIPT_SOURCE="${BASH_SOURCE[0]}"
fi fi
# shellcheck disable=SC2086 # shellcheck disable=SC2086
NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)" NVM_DIR="$(nvm_cd ${NVM_CD_FLAGS} "$(dirname "${NVM_SCRIPT_SOURCE:-$0}")" >/dev/null && \pwd)"
@@ -820,7 +833,7 @@ nvm_remote_versions() {
esac esac
if nvm_validate_implicit_alias "${PATTERN-}" 2>/dev/null; then if nvm_validate_implicit_alias "${PATTERN-}" 2>/dev/null; then
nvm_err 'Implicit aliases are not supported in nvm_remote_versions.' nvm_error 'Implicit aliases are not supported in nvm_remote_versions.'
return 1 return 1
fi fi
@@ -912,13 +925,13 @@ nvm_normalize_lts() {
if [ "${RESULT}" != '*' ]; then if [ "${RESULT}" != '*' ]; then
nvm_echo "lts/${RESULT}" nvm_echo "lts/${RESULT}"
else else
nvm_err 'That many LTS releases do not exist yet.' nvm_error 'That many LTS releases do not exist yet.'
return 2 return 2
fi fi
;; ;;
*) *)
if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then
nvm_err 'LTS names must be lowercase' nvm_error 'LTS names must be lowercase'
return 3 return 3
fi fi
nvm_echo "${LTS}" nvm_echo "${LTS}"
@@ -966,7 +979,7 @@ nvm_num_version_groups() {
nvm_strip_path() { nvm_strip_path() {
if [ -z "${NVM_DIR-}" ]; then if [ -z "${NVM_DIR-}" ]; then
nvm_err '${NVM_DIR} not set!' nvm_error '${NVM_DIR} not set!'
return 1 return 1
fi fi
command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: ' command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: '
@@ -979,10 +992,10 @@ nvm_strip_path() {
} }
nvm_change_path() { nvm_change_path() {
# if theres no initial path, just return the supplementary path # if there's no initial path, just return the supplementary path
if [ -z "${1-}" ]; then if [ -z "${1-}" ]; then
nvm_echo "${3-}${2-}" nvm_echo "${3-}${2-}"
# if the initial path doesnt contain an nvm path, prepend the supplementary # if the initial path doesn't contain an nvm path, prepend the supplementary
# path # path
elif ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/[^/]*${2-}" \ elif ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/[^/]*${2-}" \
&& ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then && ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then
@@ -1049,7 +1062,7 @@ nvm_get_colors() {
COLOR=$(nvm_echo "$SYS_COLOR" | command tr '0;' '1;') COLOR=$(nvm_echo "$SYS_COLOR" | command tr '0;' '1;')
;; ;;
*) *)
nvm_err "Invalid color index, ${1-}" nvm_error "Invalid color index, ${1-}"
return 1 return 1
;; ;;
esac esac
@@ -1089,7 +1102,7 @@ nvm_print_color_code() {
'e') nvm_echo '0;37m' ;; 'e') nvm_echo '0;37m' ;;
'W') nvm_echo '1;37m' ;; 'W') nvm_echo '1;37m' ;;
*) *)
nvm_err "Invalid color code: ${1-}"; nvm_error "Invalid color code: ${1-}";
return 1 return 1
;; ;;
esac esac
@@ -1171,13 +1184,13 @@ nvm_print_alias_path() {
local NVM_ALIAS_DIR local NVM_ALIAS_DIR
NVM_ALIAS_DIR="${1-}" NVM_ALIAS_DIR="${1-}"
if [ -z "${NVM_ALIAS_DIR}" ]; then if [ -z "${NVM_ALIAS_DIR}" ]; then
nvm_err 'An alias dir is required.' nvm_error 'An alias dir is required.'
return 1 return 1
fi fi
local ALIAS_PATH local ALIAS_PATH
ALIAS_PATH="${2-}" ALIAS_PATH="${2-}"
if [ -z "${ALIAS_PATH}" ]; then if [ -z "${ALIAS_PATH}" ]; then
nvm_err 'An alias path is required.' nvm_error 'An alias path is required.'
return 2 return 2
fi fi
local ALIAS local ALIAS
@@ -1193,7 +1206,7 @@ nvm_print_default_alias() {
local ALIAS local ALIAS
ALIAS="${1-}" ALIAS="${1-}"
if [ -z "${ALIAS}" ]; then if [ -z "${ALIAS}" ]; then
nvm_err 'A default alias is required.' nvm_error 'A default alias is required.'
return 1 return 1
fi fi
local DEST local DEST
@@ -1207,13 +1220,13 @@ nvm_make_alias() {
local ALIAS local ALIAS
ALIAS="${1-}" ALIAS="${1-}"
if [ -z "${ALIAS}" ]; then if [ -z "${ALIAS}" ]; then
nvm_err "an alias name is required" nvm_error "an alias name is required"
return 1 return 1
fi fi
local VERSION local VERSION
VERSION="${2-}" VERSION="${2-}"
if [ -z "${VERSION}" ]; then if [ -z "${VERSION}" ]; then
nvm_err "an alias target version is required" nvm_error "an alias target version is required"
return 2 return 2
fi fi
nvm_echo "${VERSION}" | tee "$(nvm_alias_path)/${ALIAS}" >/dev/null nvm_echo "${VERSION}" | tee "$(nvm_alias_path)/${ALIAS}" >/dev/null
@@ -1276,7 +1289,7 @@ nvm_alias() {
local ALIAS local ALIAS
ALIAS="${1-}" ALIAS="${1-}"
if [ -z "${ALIAS}" ]; then if [ -z "${ALIAS}" ]; then
nvm_err 'An alias is required.' nvm_error 'An alias is required.'
return 1 return 1
fi fi
if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then
@@ -1290,7 +1303,7 @@ nvm_alias() {
local NVM_ALIAS_PATH local NVM_ALIAS_PATH
NVM_ALIAS_PATH="$(nvm_alias_path)/${ALIAS}" NVM_ALIAS_PATH="$(nvm_alias_path)/${ALIAS}"
if [ ! -f "${NVM_ALIAS_PATH}" ]; then if [ ! -f "${NVM_ALIAS_PATH}" ]; then
nvm_err 'Alias does not exist.' nvm_error 'Alias does not exist.'
return 2 return 2
fi fi
@@ -1415,11 +1428,11 @@ nvm_add_iojs_prefix() {
nvm_strip_iojs_prefix() { nvm_strip_iojs_prefix() {
local NVM_IOJS_PREFIX local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
if [ "${1-}" = "${NVM_IOJS_PREFIX}" ]; then
case "${1-}" in nvm_echo
"${NVM_IOJS_PREFIX}") nvm_echo ;; else
*) nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" ;; nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}"
esac fi
} }
nvm_ls() { nvm_ls() {
@@ -1551,15 +1564,12 @@ nvm_ls() {
fi fi
if [ "${NVM_ADD_SYSTEM-}" = true ]; then if [ "${NVM_ADD_SYSTEM-}" = true ]; then
case "${PATTERN}" in if [ -z "${PATTERN}" ] || [ "${PATTERN}" = 'v' ]; then
'' | v)
VERSIONS="${VERSIONS} VERSIONS="${VERSIONS}
system" system"
;; elif [ "${PATTERN}" = 'system' ]; then
system)
VERSIONS="system" VERSIONS="system"
;; fi
esac
fi fi
if [ -z "${VERSIONS}" ]; then if [ -z "${VERSIONS}" ]; then
@@ -1598,7 +1608,7 @@ nvm_ls_remote_index_tab() {
local LTS local LTS
LTS="${NVM_LTS-}" LTS="${NVM_LTS-}"
if [ "$#" -lt 3 ]; then if [ "$#" -lt 3 ]; then
nvm_err 'not enough arguments' nvm_error 'not enough arguments'
return 5 return 5
fi fi
@@ -1620,11 +1630,11 @@ nvm_ls_remote_index_tab() {
iojs-std) PREFIX="$(nvm_iojs_prefix)-" ;; iojs-std) PREFIX="$(nvm_iojs_prefix)-" ;;
node-std) PREFIX='' ;; node-std) PREFIX='' ;;
iojs-*) iojs-*)
nvm_err 'unknown type of io.js release' nvm_error 'unknown type of io.js release'
return 4 return 4
;; ;;
*) *)
nvm_err 'unknown type of node.js release' nvm_error 'unknown type of node.js release'
return 4 return 4
;; ;;
esac esac
@@ -1738,8 +1748,8 @@ nvm_get_checksum_binary() {
elif nvm_has_non_aliased 'sha1'; then elif nvm_has_non_aliased 'sha1'; then
nvm_echo 'sha1' nvm_echo 'sha1'
else else
nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.' nvm_error 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, or bssl not found.'
nvm_err 'Unaliased sha1sum or sha1 not found.' nvm_error 'Unaliased sha1sum or sha1 not found.'
return 1 return 1
fi fi
} }
@@ -1765,36 +1775,36 @@ nvm_compute_checksum() {
local FILE local FILE
FILE="${1-}" FILE="${1-}"
if [ -z "${FILE}" ]; then if [ -z "${FILE}" ]; then
nvm_err 'Provided file to checksum is empty.' nvm_error 'Provided file to checksum is empty.'
return 2 return 2
elif ! [ -f "${FILE}" ]; then elif ! [ -f "${FILE}" ]; then
nvm_err 'Provided file to checksum does not exist.' nvm_error 'Provided file to checksum does not exist.'
return 1 return 1
fi fi
if nvm_has_non_aliased "sha256sum"; then if nvm_has_non_aliased "sha256sum"; then
nvm_err 'Computing checksum with sha256sum' nvm_debug 'Computing checksum with sha256sum'
command sha256sum "${FILE}" | command awk '{print $1}' command sha256sum "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "shasum"; then elif nvm_has_non_aliased "shasum"; then
nvm_err 'Computing checksum with shasum -a 256' nvm_debug 'Computing checksum with shasum -a 256'
command shasum -a 256 "${FILE}" | command awk '{print $1}' command shasum -a 256 "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "sha256"; then elif nvm_has_non_aliased "sha256"; then
nvm_err 'Computing checksum with sha256 -q' nvm_debug 'Computing checksum with sha256 -q'
command sha256 -q "${FILE}" | command awk '{print $1}' command sha256 -q "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "gsha256sum"; then elif nvm_has_non_aliased "gsha256sum"; then
nvm_err 'Computing checksum with gsha256sum' nvm_debug 'Computing checksum with gsha256sum'
command gsha256sum "${FILE}" | command awk '{print $1}' command gsha256sum "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "openssl"; then elif nvm_has_non_aliased "openssl"; then
nvm_err 'Computing checksum with openssl dgst -sha256' nvm_debug 'Computing checksum with openssl dgst -sha256'
command openssl dgst -sha256 "${FILE}" | command awk '{print $NF}' command openssl dgst -sha256 "${FILE}" | command awk '{print $NF}'
elif nvm_has_non_aliased "bssl"; then elif nvm_has_non_aliased "bssl"; then
nvm_err 'Computing checksum with bssl sha256sum' nvm_debug 'Computing checksum with bssl sha256sum'
command bssl sha256sum "${FILE}" | command awk '{print $1}' command bssl sha256sum "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "sha1sum"; then elif nvm_has_non_aliased "sha1sum"; then
nvm_err 'Computing checksum with sha1sum' nvm_debug 'Computing checksum with sha1sum'
command sha1sum "${FILE}" | command awk '{print $1}' command sha1sum "${FILE}" | command awk '{print $1}'
elif nvm_has_non_aliased "sha1"; then elif nvm_has_non_aliased "sha1"; then
nvm_err 'Computing checksum with sha1 -q' nvm_debug 'Computing checksum with sha1 -q'
command sha1 -q "${FILE}" command sha1 -q "${FILE}"
fi fi
} }
@@ -1803,10 +1813,10 @@ nvm_compare_checksum() {
local FILE local FILE
FILE="${1-}" FILE="${1-}"
if [ -z "${FILE}" ]; then if [ -z "${FILE}" ]; then
nvm_err 'Provided file to checksum is empty.' nvm_error 'Provided file to checksum is empty.'
return 4 return 4
elif ! [ -f "${FILE}" ]; then elif ! [ -f "${FILE}" ]; then
nvm_err 'Provided file to checksum does not exist.' nvm_error 'Provided file to checksum does not exist.'
return 3 return 3
fi fi
@@ -1816,19 +1826,19 @@ nvm_compare_checksum() {
local CHECKSUM local CHECKSUM
CHECKSUM="${2-}" CHECKSUM="${2-}"
if [ -z "${CHECKSUM}" ]; then if [ -z "${CHECKSUM}" ]; then
nvm_err 'Provided checksum to compare to is empty.' nvm_error 'Provided checksum to compare to is empty.'
return 2 return 2
fi fi
if [ -z "${COMPUTED_SUM}" ]; then if [ -z "${COMPUTED_SUM}" ]; then
nvm_err "Computed checksum of '${FILE}' is empty." # missing in raspberry pi binary nvm_error "Computed checksum of '${FILE}' is empty." # missing in raspberry pi binary
nvm_err 'WARNING: Continuing *without checksum verification*' nvm_warn 'WARNING: Continuing *without checksum verification*'
return return
elif [ "${COMPUTED_SUM}" != "${CHECKSUM}" ] && [ "${COMPUTED_SUM}" != "\\${CHECKSUM}" ]; then elif [ "${COMPUTED_SUM}" != "${CHECKSUM}" ] && [ "${COMPUTED_SUM}" != "\\${CHECKSUM}" ]; then
nvm_err "Checksums do not match: '${COMPUTED_SUM}' found, '${CHECKSUM}' expected." nvm_error "Checksums do not match: '${COMPUTED_SUM}' found, '${CHECKSUM}' expected."
return 1 return 1
fi fi
nvm_err 'Checksums matched!' nvm_debug 'Checksums matched!'
} }
# args: flavor, type, version, slug, compression # args: flavor, type, version, slug, compression
@@ -1837,7 +1847,7 @@ nvm_get_checksum() {
case "${1-}" in case "${1-}" in
node | iojs) FLAVOR="${1}" ;; node | iojs) FLAVOR="${1}" ;;
*) *)
nvm_err 'supported flavors: node, iojs' nvm_error 'supported flavors: node, iojs'
return 2 return 2
;; ;;
esac esac
@@ -1958,7 +1968,7 @@ nvm_validate_implicit_alias() {
return return
;; ;;
*) *)
nvm_err "Only implicit aliases 'stable', 'unstable', '${NVM_IOJS_PREFIX}', and '${NVM_NODE_PREFIX}' are supported." nvm_error "Only implicit aliases 'stable', 'unstable', '${NVM_IOJS_PREFIX}', and '${NVM_NODE_PREFIX}' are supported."
return 1 return 1
;; ;;
esac esac
@@ -1966,7 +1976,7 @@ nvm_validate_implicit_alias() {
nvm_print_implicit_alias() { nvm_print_implicit_alias() {
if [ "_$1" != "_local" ] && [ "_$1" != "_remote" ]; then if [ "_$1" != "_local" ] && [ "_$1" != "_remote" ]; then
nvm_err "nvm_print_implicit_alias must be specified with local or remote as the first argument." nvm_error "nvm_print_implicit_alias must be specified with local or remote as the first argument."
return 1 return 1
fi fi
@@ -2127,13 +2137,13 @@ nvm_get_minor_version() {
VERSION="$1" VERSION="$1"
if [ -z "${VERSION}" ]; then if [ -z "${VERSION}" ]; then
nvm_err 'a version is required' nvm_error 'a version is required'
return 1 return 1
fi fi
case "${VERSION}" in case "${VERSION}" in
v | .* | *..* | v*[!.0123456789]* | [!v]*[!.0123456789]* | [!v0123456789]* | v[!0123456789]*) v | .* | *..* | v*[!.0123456789]* | [!v]*[!.0123456789]* | [!v0123456789]* | v[!0123456789]*)
nvm_err 'invalid version number' nvm_error 'invalid version number'
return 2 return 2
;; ;;
esac esac
@@ -2144,7 +2154,7 @@ nvm_get_minor_version() {
local MINOR local MINOR
MINOR="$(nvm_echo "${PREFIXED_VERSION}" | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2)" MINOR="$(nvm_echo "${PREFIXED_VERSION}" | nvm_grep -e '^v' | command cut -c2- | command cut -d . -f 1,2)"
if [ -z "${MINOR}" ]; then if [ -z "${MINOR}" ]; then
nvm_err 'invalid version number! (please report this)' nvm_error 'invalid version number! (please report this)'
return 3 return 3
fi fi
nvm_echo "${MINOR}" nvm_echo "${MINOR}"
@@ -2154,7 +2164,7 @@ nvm_ensure_default_set() {
local VERSION local VERSION
VERSION="$1" VERSION="$1"
if [ -z "${VERSION}" ]; then if [ -z "${VERSION}" ]; then
nvm_err 'nvm_ensure_default_set: a version is required' nvm_error 'nvm_ensure_default_set: a version is required'
return 1 return 1
elif nvm_alias default >/dev/null 2>&1; then elif nvm_alias default >/dev/null 2>&1; then
# default already set # default already set
@@ -2164,7 +2174,7 @@ nvm_ensure_default_set() {
OUTPUT="$(nvm alias default "${VERSION}")" OUTPUT="$(nvm alias default "${VERSION}")"
local EXIT_CODE local EXIT_CODE
EXIT_CODE="$?" EXIT_CODE="$?"
nvm_echo "Creating default alias: ${OUTPUT}" nvm_info "Creating default alias: ${OUTPUT}"
return $EXIT_CODE return $EXIT_CODE
} }
@@ -2179,21 +2189,21 @@ nvm_get_mirror() {
node-std) NVM_MIRROR="${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;; node-std) NVM_MIRROR="${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;
iojs-std) NVM_MIRROR="${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;; iojs-std) NVM_MIRROR="${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;;
*) *)
nvm_err 'unknown type of node.js or io.js release' nvm_error 'unknown type of node.js or io.js release'
return 1 return 1
;; ;;
esac esac
case "${NVM_MIRROR}" in case "${NVM_MIRROR}" in
*\`* | *\\* | *\'* | *\(* | *' '* ) *\`* | *\\* | *\'* | *\(* | *' '* )
nvm_err '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL' nvm_error '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL'
return 2 return 2
;; ;;
esac esac
if ! nvm_echo "${NVM_MIRROR}" | command awk '{ $0 ~ "^https?://[a-zA-Z0-9./_-]+$" }'; then if ! nvm_echo "${NVM_MIRROR}" | command awk '{ $0 ~ "^https?://[a-zA-Z0-9./_-]+$" }'; then
nvm_err '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL' nvm_error '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL'
return 2 return 2
fi fi
@@ -2203,7 +2213,7 @@ nvm_get_mirror() {
# args: os, prefixed version, version, tarball, extract directory # args: os, prefixed version, version, tarball, extract directory
nvm_install_binary_extract() { nvm_install_binary_extract() {
if [ "$#" -ne 5 ]; then if [ "$#" -ne 5 ]; then
nvm_err 'nvm_install_binary_extract needs 5 parameters' nvm_error 'nvm_install_binary_extract needs 5 parameters'
return 1 return 1
fi fi
@@ -2221,7 +2231,7 @@ nvm_install_binary_extract() {
local VERSION_PATH local VERSION_PATH
[ -n "${TMPDIR-}" ] && \ [ -n "${TMPDIR-}" ] && \
command mkdir -p "${TMPDIR}" && \ nvm_run_command mkdir -p "${TMPDIR}" && \
VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" || return 1 VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" || return 1
# For Windows system (GitBash with MSYS, Cygwin) # For Windows system (GitBash with MSYS, Cygwin)
@@ -2255,7 +2265,7 @@ nvm_install_binary() {
case "${1-}" in case "${1-}" in
node | iojs) FLAVOR="${1}" ;; node | iojs) FLAVOR="${1}" ;;
*) *)
nvm_err 'supported flavors: node, iojs' nvm_error 'supported flavors: node, iojs'
return 4 return 4
;; ;;
esac esac
@@ -2266,7 +2276,7 @@ nvm_install_binary() {
local PREFIXED_VERSION local PREFIXED_VERSION
PREFIXED_VERSION="${3-}" PREFIXED_VERSION="${3-}"
if [ -z "${PREFIXED_VERSION}" ]; then if [ -z "${PREFIXED_VERSION}" ]; then
nvm_err 'A version number is required.' nvm_error 'A version number is required.'
return 3 return 3
fi fi
@@ -2294,18 +2304,17 @@ nvm_install_binary() {
NODE_OR_IOJS="io.js" NODE_OR_IOJS="io.js"
fi fi
if [ "${NVM_NO_PROGRESS-}" = "1" ]; then if [ "${NVM_NO_PROGRESS-}" = "1" ]; then
# --silent, --show-error, use short option as @samrocketman mentions the compatibility issue.
PROGRESS_BAR="-sS" PROGRESS_BAR="-sS"
else else
PROGRESS_BAR="--progress-bar" PROGRESS_BAR="--progress-bar"
fi fi
nvm_echo "Downloading and installing ${NODE_OR_IOJS-} ${VERSION}..." nvm_info "Downloading and installing ${NODE_OR_IOJS-} ${VERSION}..."
TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" binary "${TYPE-}" "${VERSION}" | command tail -1)" TARBALL="$(PROGRESS_BAR="${PROGRESS_BAR}" nvm_download_artifact "${FLAVOR}" binary "${TYPE-}" "${VERSION}" | command tail -1)"
if [ -f "${TARBALL}" ]; then if [ -f "${TARBALL}" ]; then
TMPDIR="$(dirname "${TARBALL}")/files" TMPDIR="$(dirname "${TARBALL}")/files"
fi fi
if nvm_install_binary_extract "${NVM_OS}" "${PREFIXED_VERSION}" "${VERSION}" "${TARBALL}" "${TMPDIR}"; then if nvm_time_operation nvm_install_binary_extract "${NVM_OS}" "${PREFIXED_VERSION}" "${VERSION}" "${TARBALL}" "${TMPDIR}"; then
if [ -n "${ALIAS-}" ]; then if [ -n "${ALIAS-}" ]; then
nvm alias "${ALIAS}" "${provided_version}" nvm alias "${ALIAS}" "${provided_version}"
fi fi
@@ -2315,11 +2324,11 @@ nvm_install_binary() {
# Read nosource from arguments # Read nosource from arguments
if [ "${nosource-}" = '1' ]; then if [ "${nosource-}" = '1' ]; then
nvm_err 'Binary download failed. Download from source aborted.' nvm_error 'Binary download failed. Download from source aborted.'
return 0 return 0
fi fi
nvm_err 'Binary download failed, trying source.' nvm_warn 'Binary download failed, trying source.'
if [ -n "${TMPDIR-}" ]; then if [ -n "${TMPDIR-}" ]; then
command rm -rf "${TMPDIR}" command rm -rf "${TMPDIR}"
fi fi
@@ -2332,7 +2341,7 @@ nvm_get_download_slug() {
case "${1-}" in case "${1-}" in
node | iojs) FLAVOR="${1}" ;; node | iojs) FLAVOR="${1}" ;;
*) *)
nvm_err 'supported flavors: node, iojs' nvm_error 'supported flavors: node, iojs'
return 1 return 1
;; ;;
esac esac
@@ -2341,7 +2350,7 @@ nvm_get_download_slug() {
case "${2-}" in case "${2-}" in
binary | source) KIND="${2}" ;; binary | source) KIND="${2}" ;;
*) *)
nvm_err 'supported kinds: binary, source' nvm_error 'supported kinds: binary, source'
return 2 return 2
;; ;;
esac esac
@@ -2402,7 +2411,7 @@ nvm_download_artifact() {
case "${1-}" in case "${1-}" in
node | iojs) FLAVOR="${1}" ;; node | iojs) FLAVOR="${1}" ;;
*) *)
nvm_err 'supported flavors: node, iojs' nvm_error 'supported flavors: node, iojs'
return 1 return 1
;; ;;
esac esac
@@ -2411,7 +2420,7 @@ nvm_download_artifact() {
case "${2-}" in case "${2-}" in
binary | source) KIND="${2}" ;; binary | source) KIND="${2}" ;;
*) *)
nvm_err 'supported kinds: binary, source' nvm_error 'supported kinds: binary, source'
return 1 return 1
;; ;;
esac esac
@@ -2429,12 +2438,12 @@ nvm_download_artifact() {
VERSION="${4}" VERSION="${4}"
if [ -z "${VERSION}" ]; then if [ -z "${VERSION}" ]; then
nvm_err 'A version number is required.' nvm_error 'A version number is required.'
return 3 return 3
fi fi
if [ "${KIND}" = 'binary' ] && ! nvm_binary_available "${VERSION}"; then if [ "${KIND}" = 'binary' ] && ! nvm_binary_available "${VERSION}"; then
nvm_err "No precompiled binary available for ${VERSION}." nvm_error "No precompiled binary available for ${VERSION}."
return return
fi fi
@@ -2454,7 +2463,7 @@ nvm_download_artifact() {
tmpdir="$(nvm_cache_dir)/src/${SLUG}" tmpdir="$(nvm_cache_dir)/src/${SLUG}"
fi fi
command mkdir -p "${tmpdir}/files" || ( command mkdir -p "${tmpdir}/files" || (
nvm_err "creating directory ${tmpdir}/files failed" nvm_error "creating directory ${tmpdir}/files failed"
return 3 return 3
) )
@@ -2469,27 +2478,27 @@ nvm_download_artifact() {
fi fi
if [ -r "${TARBALL}" ]; then if [ -r "${TARBALL}" ]; then
nvm_err "Local cache found: $(nvm_sanitize_path "${TARBALL}")" nvm_error "Local cache found: $(nvm_sanitize_path "${TARBALL}")"
if nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" >/dev/null 2>&1; then if nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" >/dev/null 2>&1; then
nvm_err "Checksums match! Using existing downloaded archive $(nvm_sanitize_path "${TARBALL}")" nvm_info "Checksums match! Using existing downloaded archive $(nvm_sanitize_path "${TARBALL}")"
nvm_echo "${TARBALL}" nvm_echo "${TARBALL}"
return 0 return 0
fi fi
nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" nvm_compare_checksum "${TARBALL}" "${CHECKSUM}"
nvm_err "Checksum check failed!" nvm_error "Checksum check failed!"
nvm_err "Removing the broken local cache..." nvm_error "Removing the broken local cache..."
command rm -rf "${TARBALL}" command rm -rf "${TARBALL}"
fi fi
nvm_err "Downloading ${TARBALL_URL}..." nvm_info "Downloading ${TARBALL_URL}..."
nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${TARBALL}" || ( nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${TARBALL}" || (
command rm -rf "${TARBALL}" "${tmpdir}" command rm -rf "${TARBALL}" "${tmpdir}"
nvm_err "download from ${TARBALL_URL} failed" nvm_error "download from ${TARBALL_URL} failed"
return 4 return 4
) )
if nvm_grep '404 Not Found' "${TARBALL}" >/dev/null; then if nvm_grep '404 Not Found' "${TARBALL}" >/dev/null; then
command rm -rf "${TARBALL}" "${tmpdir}" command rm -rf "${TARBALL}" "${tmpdir}"
nvm_err "HTTP 404 at URL ${TARBALL_URL}" nvm_error "HTTP 404 at URL ${TARBALL_URL}"
return 5 return 5
fi fi
@@ -2504,7 +2513,7 @@ nvm_download_artifact() {
# args: nvm_os, version, tarball, tmpdir # args: nvm_os, version, tarball, tmpdir
nvm_extract_tarball() { nvm_extract_tarball() {
if [ "$#" -ne 4 ]; then if [ "$#" -ne 4 ]; then
nvm_err 'nvm_extract_tarball requires exactly 4 arguments' nvm_error 'nvm_extract_tarball requires exactly 4 arguments'
return 5 return 5
fi fi
@@ -2550,7 +2559,7 @@ nvm_get_make_jobs() {
return return
elif [ -n "${1-}" ]; then elif [ -n "${1-}" ]; then
unset NVM_MAKE_JOBS unset NVM_MAKE_JOBS
nvm_err "$1 is invalid for number of \`make\` jobs, must be a natural number" nvm_error "$1 is invalid for number of \`make\` jobs, must be a natural number"
fi fi
local NVM_OS local NVM_OS
NVM_OS="$(nvm_get_os)" NVM_OS="$(nvm_get_os)"
@@ -2570,8 +2579,8 @@ nvm_get_make_jobs() {
;; ;;
esac esac
if ! nvm_is_natural_num "${NVM_CPU_CORES}"; then if ! nvm_is_natural_num "${NVM_CPU_CORES}"; then
nvm_err 'Can not determine how many core(s) are available, running in single-threaded mode.' nvm_error 'Can not determine how many core(s) are available, running in single-threaded mode.'
nvm_err 'Please report an issue on GitHub to help us make nvm run faster on your computer!' nvm_error 'Please report an issue on GitHub to help us make nvm run faster on your computer!'
NVM_MAKE_JOBS=1 NVM_MAKE_JOBS=1
else else
nvm_echo "Detected that you have ${NVM_CPU_CORES} CPU core(s)" nvm_echo "Detected that you have ${NVM_CPU_CORES} CPU core(s)"
@@ -2591,7 +2600,7 @@ nvm_install_source() {
case "${1-}" in case "${1-}" in
node | iojs) FLAVOR="${1}" ;; node | iojs) FLAVOR="${1}" ;;
*) *)
nvm_err 'supported flavors: node, iojs' nvm_error 'supported flavors: node, iojs'
return 4 return 4
;; ;;
esac esac
@@ -2602,7 +2611,7 @@ nvm_install_source() {
local PREFIXED_VERSION local PREFIXED_VERSION
PREFIXED_VERSION="${3-}" PREFIXED_VERSION="${3-}"
if [ -z "${PREFIXED_VERSION}" ]; then if [ -z "${PREFIXED_VERSION}" ]; then
nvm_err 'A version number is required.' nvm_error 'A version number is required.'
return 3 return 3
fi fi
@@ -2682,7 +2691,7 @@ nvm_install_source() {
command rm -f "${VERSION_PATH}" 2>/dev/null && \ command rm -f "${VERSION_PATH}" 2>/dev/null && \
$make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install $make -j "${NVM_MAKE_JOBS}" ${MAKE_CXX-} install
); then ); then
nvm_err "nvm: install ${VERSION} failed!" nvm_error "nvm: install ${VERSION} failed!"
command rm -rf "${TMPDIR-}" command rm -rf "${TMPDIR-}"
return 1 return 1
fi fi
@@ -2701,10 +2710,10 @@ nvm_install_npm_if_needed() {
if ! nvm_has "npm"; then if ! nvm_has "npm"; then
nvm_echo 'Installing npm...' nvm_echo 'Installing npm...'
if nvm_version_greater 0.2.0 "${VERSION}"; then if nvm_version_greater 0.2.0 "${VERSION}"; then
nvm_err 'npm requires node v0.2.3 or higher' nvm_error 'npm requires node v0.2.3 or higher'
elif nvm_version_greater_than_or_equal_to "${VERSION}" 0.2.0; then elif nvm_version_greater_than_or_equal_to "${VERSION}" 0.2.0; then
if nvm_version_greater 0.2.3 "${VERSION}"; then if nvm_version_greater 0.2.3 "${VERSION}"; then
nvm_err 'npm requires node v0.2.3 or higher' nvm_error 'npm requires node v0.2.3 or higher'
else else
nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
fi fi
@@ -2737,10 +2746,10 @@ nvm_npm_global_modules() {
local NPMLIST local NPMLIST
local VERSION local VERSION
VERSION="$1" VERSION="$1"
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed -e '1d' -e '/UNMET PEER DEPENDENCY/d') NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')
local INSTALLS local INSTALLS
INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' -e '/^corepack@[^ ]*.*$/ d' | command xargs) INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)
local LINKS local LINKS
LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')" LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"
@@ -2763,7 +2772,7 @@ nvm_die_on_prefix() {
case "${NVM_DELETE_PREFIX}" in case "${NVM_DELETE_PREFIX}" in
0 | 1) ;; 0 | 1) ;;
*) *)
nvm_err 'First argument "delete the prefix" must be zero or one' nvm_error 'First argument "delete the prefix" must be zero or one'
return 1 return 1
;; ;;
esac esac
@@ -2772,7 +2781,7 @@ nvm_die_on_prefix() {
local NVM_VERSION_DIR local NVM_VERSION_DIR
NVM_VERSION_DIR="${3-}" NVM_VERSION_DIR="${3-}"
if [ -z "${NVM_COMMAND}" ] || [ -z "${NVM_VERSION_DIR}" ]; then if [ -z "${NVM_COMMAND}" ] || [ -z "${NVM_VERSION_DIR}" ]; then
nvm_err 'Second argument "nvm command", and third argument "nvm version dir", must both be nonempty' nvm_error 'Second argument "nvm command", and third argument "nvm version dir", must both be nonempty'
return 2 return 2
fi fi
@@ -2781,8 +2790,8 @@ nvm_die_on_prefix() {
# however, `npm exec` in npm v7.2+ sets $PREFIX; if set, inherit it # however, `npm exec` in npm v7.2+ sets $PREFIX; if set, inherit it
if [ -n "${PREFIX-}" ] && [ "$(nvm_version_path "$(node -v)")" != "${PREFIX}" ]; then if [ -n "${PREFIX-}" ] && [ "$(nvm_version_path "$(node -v)")" != "${PREFIX}" ]; then
nvm deactivate >/dev/null 2>&1 nvm deactivate >/dev/null 2>&1
nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\"" nvm_error "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\""
nvm_err 'Run `unset PREFIX` to unset it.' nvm_error 'Run `unset PREFIX` to unset it.'
return 3 return 3
fi fi
@@ -2805,8 +2814,8 @@ nvm_die_on_prefix() {
fi fi
if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then
nvm deactivate >/dev/null 2>&1 nvm deactivate >/dev/null 2>&1
nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_x_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\"" nvm_error "nvm is not compatible with the \"${NVM_NPM_CONFIG_x_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
nvm_err "Run \`unset ${NVM_NPM_CONFIG_x_PREFIX_ENV}\` to unset it." nvm_error "Run \`unset ${NVM_NPM_CONFIG_x_PREFIX_ENV}\` to unset it."
return 4 return 4
fi fi
fi fi
@@ -2830,9 +2839,9 @@ nvm_die_on_prefix() {
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_BUILTIN_NPMRC}" npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_BUILTIN_NPMRC}" npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
else else
nvm_err "Your builtin npmrc file ($(nvm_sanitize_path "${NVM_NPM_BUILTIN_NPMRC}"))" nvm_error "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_error 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it." nvm_error "Run \`${NVM_COMMAND}\` to unset it."
return 10 return 10
fi fi
fi fi
@@ -2844,9 +2853,9 @@ nvm_die_on_prefix() {
npm config --global --loglevel=warn delete prefix npm config --global --loglevel=warn delete prefix
npm config --global --loglevel=warn delete globalconfig npm config --global --loglevel=warn delete globalconfig
else else
nvm_err "Your global npmrc file ($(nvm_sanitize_path "${NVM_NPM_GLOBAL_NPMRC}"))" nvm_error "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_error 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it." nvm_error "Run \`${NVM_COMMAND}\` to unset it."
return 10 return 10
fi fi
fi fi
@@ -2858,9 +2867,9 @@ nvm_die_on_prefix() {
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_USER_NPMRC}" npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_USER_NPMRC}"
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_USER_NPMRC}" npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_USER_NPMRC}"
else else
nvm_err "Your users .npmrc file ($(nvm_sanitize_path "${NVM_NPM_USER_NPMRC}"))" nvm_error "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_error 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it." nvm_error "Run \`${NVM_COMMAND}\` to unset it."
return 10 return 10
fi fi
fi fi
@@ -2872,9 +2881,9 @@ nvm_die_on_prefix() {
npm config --loglevel=warn delete prefix npm config --loglevel=warn delete prefix
npm config --loglevel=warn delete globalconfig npm config --loglevel=warn delete globalconfig
else else
nvm_err "Your project npmrc file ($(nvm_sanitize_path "${NVM_NPM_PROJECT_NPMRC}"))" nvm_error "Your project npmrc file ($(nvm_sanitize_path "${NVM_NPM_PROJECT_NPMRC}"))"
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.' nvm_error 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
nvm_err "Run \`${NVM_COMMAND}\` to unset it." nvm_error "Run \`${NVM_COMMAND}\` to unset it."
return 10 return 10
fi fi
fi fi
@@ -2965,7 +2974,7 @@ nvm_write_nvmrc() {
fi fi
echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || { echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || {
if [ "${NVM_SILENT:-0}" -ne 1 ]; then if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc" nvm_error "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"
fi fi
return 3 return 3
} }
@@ -2980,13 +2989,13 @@ nvm_check_file_permissions() {
for FILE in "$1"/* "$1"/.[!.]* "$1"/..?* ; do for FILE in "$1"/* "$1"/.[!.]* "$1"/..?* ; do
if [ -d "$FILE" ]; then if [ -d "$FILE" ]; then
if [ -n "${NVM_DEBUG-}" ]; then if [ -n "${NVM_DEBUG-}" ]; then
nvm_err "${FILE}" nvm_error "${FILE}"
fi fi
if [ ! -L "${FILE}" ] && ! nvm_check_file_permissions "${FILE}"; then if [ ! -L "${FILE}" ] && ! nvm_check_file_permissions "${FILE}"; then
return 2 return 2
fi fi
elif [ -e "$FILE" ] && [ ! -w "$FILE" ] && [ ! -O "$FILE" ]; then elif [ -e "$FILE" ] && [ ! -w "$FILE" ] && [ ! -O "$FILE" ]; then
nvm_err "file is not writable or self-owned: $(nvm_sanitize_path "$FILE")" nvm_error "file is not writable or self-owned: $(nvm_sanitize_path "$FILE")"
return 1 return 1
fi fi
done done
@@ -4438,7 +4447,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.40.3' nvm_echo '0.40.1'
;; ;;
"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.40.3", "version": "0.40.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"
@@ -45,9 +45,9 @@
"dockerfile_lint": "^0.3.4", "dockerfile_lint": "^0.3.4",
"doctoc": "^2.2.1", "doctoc": "^2.2.1",
"eclint": "^2.8.1", "eclint": "^2.8.1",
"markdown-link-check": "^3.13.7", "markdown-link-check": "^3.12.2",
"replace": "^1.2.2", "replace": "^1.2.2",
"semver": "^7.7.1", "semver": "^7.6.3",
"urchin": "^0.0.5" "urchin": "^0.0.5"
} }
} }

View File

@@ -3,16 +3,12 @@
setup () { setup () {
HOME="." HOME="."
NVM_ENV=testing \. ../../install.sh NVM_ENV=testing \. ../../install.sh
ZDOTDIR="$HOME/zdotdir"
mkdir -p zdotdir
touch ".bashrc" touch ".bashrc"
touch ".bash_profile" touch ".bash_profile"
touch ".zprofile" touch ".zprofile"
touch ".zshrc" touch ".zshrc"
touch ".profile" touch ".profile"
touch "test_profile" touch "test_profile"
touch "zdotdir/.zshrc"
touch "zdotdir/.zprofile"
} }
cleanup () { cleanup () {
@@ -21,9 +17,7 @@ cleanup () {
unset NVM_DETECT_PROFILE unset NVM_DETECT_PROFILE
unset SHELL unset SHELL
unset -f setup cleanup die unset -f setup cleanup die
unset ZDOTDIR
rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1 rm -f ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".profile" "test_profile" > "/dev/null" 2>&1
rm -rf zdotdir 2>&1
} }
die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; } die () { echo "$@" '$NVM_DETECT_PROFILE:' "$NVM_DETECT_PROFILE"; cleanup; exit 1; }
@@ -35,54 +29,49 @@ setup
# #
# setting $PROFILE to /dev/null should return no detected profile # setting $PROFILE to /dev/null should return no detected profile
NVM_DETECT_PROFILE="$(PROFILE='/dev/null' nvm_detect_profile)" NVM_DETECT_PROFILE="$(PROFILE='/dev/null'; nvm_detect_profile)"
if [ -n "$NVM_DETECT_PROFILE" ]; then if [ -n "$NVM_DETECT_PROFILE" ]; then
die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null" die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null"
fi fi
# .bashrc should be detected for bash # .bashrc should be detected for bash
NVM_DETECT_PROFILE="$(SHELL="/bin/bash" PROFILE= nvm_detect_profile)" NVM_DETECT_PROFILE="$(SHELL="/bin/bash"; unset PROFILE; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
die "nvm_detect_profile didn't pick \$HOME/.bashrc for bash" die "nvm_detect_profile didn't pick \$HOME/.bashrc for bash"
fi fi
# $PROFILE should override .bashrc profile detection # $PROFILE should override .bashrc profile detection
NVM_DETECT_PROFILE="$(SHELL="/bin/bash" PROFILE="test_profile" nvm_detect_profile)" NVM_DETECT_PROFILE="$(SHELL="/bin/bash"; PROFILE="test_profile"; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE" die "nvm_detect_profile ignored \$PROFILE"
fi fi
# zdotdir/.zshrc should be detected for zsh
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh" PROFILE= nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then
die "nvm_detect_profile didn't pick \$ZDOTDIR/.zshrc for zsh"
fi
# .zshrc should be detected for zsh # .zshrc should be detected for zsh
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh" PROFILE= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(SHELL="/bin/zsh"; unset PROFILE; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh" die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
fi fi
# $PROFILE should override .zshrc profile detection # $PROFILE should override .zshrc profile detection
NVM_DETECT_PROFILE="$(SHELL="/usr/bin/zsh" PROFILE="test_profile" nvm_detect_profile)" NVM_DETECT_PROFILE="$(SHELL="/usr/bin/zsh"; PROFILE="test_profile"; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile ignored \$PROFILE" die "nvm_detect_profile ignored \$PROFILE"
fi fi
# #
# Confirm $PROFILE is only returned when it points to a valid file # Confirm $PROFILE is only returned when it points to a valid file
# #
# $PROFILE is a valid file # $PROFILE is a valid file
NVM_DETECT_PROFILE="$(PROFILE="test_profile" SHELL= nvm_detect_profile)" NVM_DETECT_PROFILE="$(PROFILE="test_profile"; unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
die "nvm_detect_profile didn't pick \$PROFILE when it was a valid file" die "nvm_detect_profile didn't pick \$PROFILE when it was a valid file"
fi fi
# $PROFILE is not a valid file # $PROFILE is not a valid file
rm "test_profile" rm "test_profile"
NVM_DETECT_PROFILE="$(PROFILE="test_profile" nvm_detect_profile)" NVM_DETECT_PROFILE="$(PROFILE="test_profile"; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" = "test_profile" ]; then if [ "$NVM_DETECT_PROFILE" = "test_profile" ]; then
die "nvm_detect_profile picked \$PROFILE when it was an invalid file" die "nvm_detect_profile picked \$PROFILE when it was an invalid file"
fi fi
@@ -94,58 +83,44 @@ fi
# #
# It should favor .profile if file exists # It should favor .profile if file exists
NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then
die "nvm_detect_profile should have selected .profile; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have selected .profile"
fi fi
# Otherwise, it should favor .bashrc if file exists # Otherwise, it should favor .bashrc if file exists
rm ".profile" rm ".profile"
NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
die "nvm_detect_profile should have selected .bashrc; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have selected .bashrc"
fi fi
# Otherwise, it should favor .bash_profile if file exists # Otherwise, it should favor .bash_profile if file exists
rm ".bashrc" rm ".bashrc"
NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
die "nvm_detect_profile should have selected .bash_profile; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have selected .bash_profile"
fi
# Otherwise, it should favor zdotdir/.zprofile if file exists
rm ".bash_profile"
NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zprofile" ]; then
die "nvm_detect_profile should have selected zdotdir/.zprofile; got $NVM_DETECT_PROFILE"
fi fi
# Otherwise, it should favor .zprofile if file exists # Otherwise, it should favor .zprofile if file exists
rm "zdotdir/.zprofile" rm ".bash_profile"
NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.zprofile" ]; then
die "nvm_detect_profile should have selected .zprofile; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have selected .zprofile"
fi
# Otherwise, it should favor zdotdir/.zshrc if file exists
rm ".zprofile"
NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$ZDOTDIR/.zshrc" ]; then
die "nvm_detect_profile should have selected zdotdir/.zshrc; got $NVM_DETECT_PROFILE"
fi fi
# Otherwise, it should favor .zshrc if file exists # Otherwise, it should favor .zshrc if file exists
rm "zdotdir/.zshrc" rm ".zprofile"
NVM_DETECT_PROFILE="$(SHELL= ZDOTDIR= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
die "nvm_detect_profile should have selected .zshrc; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have selected .zshrc"
fi fi
# It should be empty if none is found # It should be empty if none is found
rm ".zshrc" rm ".zshrc"
NVM_DETECT_PROFILE="$(SHELL= nvm_detect_profile)" NVM_DETECT_PROFILE="$(unset SHELL; nvm_detect_profile)"
if [ ! -z "$NVM_DETECT_PROFILE" ]; then if [ ! -z "$NVM_DETECT_PROFILE" ]; then
die "nvm_detect_profile should have returned an empty value; got $NVM_DETECT_PROFILE" die "nvm_detect_profile should have returned an empty value"
fi fi
cleanup cleanup

View File

@@ -16,7 +16,7 @@ EXPECTED_PACKAGES_INSTALL="autoprefixer bower david@11 grunt-cli grunth-cli http
echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet echo "$EXPECTED_PACKAGES_INSTALL" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet
get_packages() { get_packages() {
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
} }
nvm use 0.10.29 nvm use 0.10.29

View File

@@ -5,7 +5,7 @@ die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh \. ../../../nvm.sh
get_packages() { get_packages() {
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' -e '/^corepack$/ d' | xargs npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
} }
nvm use 4.7.2 nvm use 4.7.2
@@ -14,14 +14,5 @@ ORIGINAL_PACKAGES=$(get_packages)
nvm reinstall-packages 4.7.1 nvm reinstall-packages 4.7.1
FINAL_PACKAGES=$(get_packages) FINAL_PACKAGES=$(get_packages)
[ -z "${ORIGINAL_PACKAGES}" ] || die "v4: original packages were not empty: ${ORIGINAL_PACKAGES}" [ -z "${ORIGINAL_PACKAGES}" ] || die "original packages were not empty: ${ORIGINAL_PACKAGES}"
[ -z "${FINAL_PACKAGES}" ] || die "v4: final packages were not empty: ${FINAL_PACKAGES}" [ -z "${FINAL_PACKAGES}" ] || die "final packages were not empty: ${FINAL_PACKAGES}"
nvm use 23.8.20
ORIGINAL_PACKAGES=$(get_packages)
nvm reinstall-packages 23.8.0
FINAL_PACKAGES=$(get_packages)
[ -z "${ORIGINAL_PACKAGES}" ] || die "v23: original packages were not empty: ${ORIGINAL_PACKAGES}"
[ -z "${FINAL_PACKAGES}" ] || die "v23: final packages were not empty: ${FINAL_PACKAGES}"

View File

@@ -1,28 +0,0 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
. ../../../nvm.sh
echo "0.10.7" > .nvmrc
# Check nvm run without --silent
OUTPUT="$(nvm run --version)"
EXPECTED_OUTPUT="Found '${PWD}/.nvmrc' with version <0.10.7>
Running node v0.10.7 (npm v1.2.21)
v0.10.7"
[ ">${OUTPUT}<" = ">${EXPECTED_OUTPUT}<" ] \
|| die "\`nvm run\` failed to run; did not match with the .nvmrc version; got >${OUTPUT}<"
OUTPUT="$(nvm run --silent --version)"
EXPECTED_OUTPUT="v0.10.7"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] \
|| die "\`nvm run --silent\` failed to run silently; expected no output, got >${OUTPUT}<"
# Output shouldn't be silent if --silent flag is not at the third argument position
OUTPUT="$(nvm run --version --silent)"
EXPECTED_OUTPUT=""
[ "${OUTPUT}" != "${EXPECTED_OUTPUT}" ] \
|| die "\`nvm run --version --silent\` should not be silent; expected >${OUTPUT}<, got no output"