Compare commits

..

2 Commits

Author SHA1 Message Date
Jordan Harband
00f3ba0831 v0.24.2 2015-05-22 15:20:49 -07:00
Jordan Harband
0f1efc825e Make sure sourcing nvm.sh on shells that don't support source options doesn't exit nonzero.
Fixes #721
2015-05-22 15:20:33 -07:00
343 changed files with 2983 additions and 15876 deletions

View File

@@ -1,16 +0,0 @@
HEAD
.cache
v*
alias
# For testing
test/bak
.urchin.log
.urchin_stdout
test/**/test_output
node_modules/
npm-debug.log
.DS_Store
current

View File

@@ -1,28 +0,0 @@
root = true
[*]
tab_width = 2
indent_size = 2
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.txt]
indent_size = false
[test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias]
indent_size = false
[test/fast/Listing versions/Running 'nvm ls --no-alias' does not call into nvm_alias]
indent_size = false
[test/fast/Unit tests/mocks/**]
insert_final_newline = off
[test/**/.urchin*]
insert_final_newline = off
[Makefile]
indent_style = tab

1
.gitattributes vendored
View File

@@ -1 +0,0 @@
* eol=lf

12
.github/FUNDING.yml vendored
View File

@@ -1,12 +0,0 @@
# These are supported funding model platforms
github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/nvm
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -1,44 +0,0 @@
<!-- 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! -->
#### Operating system and version:
#### `nvm debug` output:
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>
#### `nvm ls` output:
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>
#### How did you install `nvm`?
<!-- (e.g. install script in readme, Homebrew) -->
#### What steps did you perform?
#### What happened?
#### What did you expect to happen?
#### Is there anything in any of your profile files that modifies the `PATH`?
<!-- (e.g. `.bashrc`, `.bash_profile`, `.zshrc`, etc) -->
<!-- Please remove the following section if it does not apply to you -->
#### If you are having installation issues, or getting "N/A", what does `curl -I --compressed -v https://nodejs.org/dist/` print out?
<details>
<!-- do not delete the following blank line -->
```sh
```
</details>

View File

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

View File

@@ -1,41 +0,0 @@
name: 'Tests: linting'
on: [pull_request, push]
jobs:
eclint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run eclint'
with:
node-version: 'lts/*'
command: 'eclint'
dockerfile_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run dockerfile_lint'
with:
node-version: 'lts/*'
command: 'dockerfile_lint'
doctoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ljharb/actions/node/run@main
name: 'npm install && npm run doctoc'
with:
node-version: 'lts/*'
command: "doctoc:check"
test_naming:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: check tests filenames
run: ./rename_test.sh --check

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,29 +0,0 @@
name: update readme TOC
on: [push]
jobs:
_:
name: "update readme TOC"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
# https://github.com/actions/checkout/issues/217#issue-599945005
# pulls all commits (needed for lerna / semantic release to correctly version)
fetch-depth: "0"
# pulls all tags (needed for lerna / semantic release to correctly version)
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- uses: actions/setup-node@v2
with:
node-version: '12.x'
- run: npm install
- run: npm run doctoc
- name: commit changes
uses: ljharb/actions-js-build/commit@v3+amendpush
with:
amend: true
force: true

10
.gitignore vendored
View File

@@ -1,6 +1,5 @@
# gitignore
HEAD HEAD
.cache src
v* v*
alias alias
@@ -8,16 +7,9 @@ alias
test/bak test/bak
.urchin.log .urchin.log
.urchin_stdout .urchin_stdout
test/**/test_output
node_modules/ node_modules/
npm-debug.log npm-debug.log
.DS_Store .DS_Store
current current
/default-packages
# Only apps should have lockfiles
npm-shrinkwrap.json
package-lock.json
yarn.lock

View File

@@ -1 +0,0 @@
Michał Gołębiowski-Owczarek <m.goleb@gmail.com>

4
.npmignore Normal file
View File

@@ -0,0 +1,4 @@
src
v*
alias

1
.npmrc
View File

@@ -1 +0,0 @@
package-lock=false

View File

@@ -1,70 +1,42 @@
language: generic language: c # defaults to ruby
dist: xenial
addons: addons:
apt: apt_packages:
packages: - zsh
- zsh - ksh
# - ksh
# - gcc-4.8
# - g++-4.8
cache:
ccache: true
directories:
- $TRAVIS_BUILD_DIR/.cache
- $TRAVIS_BUILD_DIR/node_modules
before_install:
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
- curl --version
- wget --version
install: install:
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi - (mkdir /tmp/urchin && cd /tmp/urchin && curl -s "$(curl -s https://registry.npmjs.com/urchin | grep -Eo '"tarball":\s*"[^"]+"' | tail -n 1 | awk -F\" '{ print $4 }')" -O && tar -x -f urchin*)
- chmod +x /tmp/urchin/package/urchin
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y' - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
script: script:
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL
before_cache:
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
env: env:
global: - SHELL=sh TEST_SUITE=install_script
- CXX=g++ - SHELL=dash TEST_SUITE=install_script
- CC=gcc - SHELL=bash TEST_SUITE=install_script
- PATH="$(echo $PATH | sed 's/::/:/')" - SHELL=zsh TEST_SUITE=install_script
- PATH="/usr/lib/ccache/:$PATH" # - SHELL=ksh TEST_SUITE=install_script
- NVM_DIR="${TRAVIS_BUILD_DIR}" - SHELL=sh TEST_SUITE=fast
matrix: - SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=install_script - SHELL=bash TEST_SUITE=fast
- SHELL=sh TEST_SUITE=fast - SHELL=zsh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast # - SHELL=ksh TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast - SHELL=sh TEST_SUITE=slow
- SHELL=zsh TEST_SUITE=fast - SHELL=dash TEST_SUITE=slow
# - SHELL=ksh TEST_SUITE=fast - SHELL=bash TEST_SUITE=slow
- SHELL=sh TEST_SUITE=sourcing - SHELL=zsh TEST_SUITE=slow
- SHELL=dash TEST_SUITE=sourcing # - SHELL=ksh TEST_SUITE=slow
- SHELL=bash TEST_SUITE=sourcing - SHELL=sh TEST_SUITE=sourcing
- SHELL=zsh TEST_SUITE=sourcing - SHELL=dash TEST_SUITE=sourcing
# - SHELL=ksh TEST_SUITE=sourcing - SHELL=bash TEST_SUITE=sourcing
- SHELL=sh TEST_SUITE=slow - SHELL=zsh TEST_SUITE=sourcing
- SHELL=dash TEST_SUITE=slow # - SHELL=ksh TEST_SUITE=sourcing
- SHELL=bash TEST_SUITE=slow - SHELL=sh TEST_SUITE=installation
- SHELL=zsh TEST_SUITE=slow - SHELL=sh TEST_SUITE=installation WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=slow - SHELL=dash TEST_SUITE=installation
- SHELL=sh TEST_SUITE=installation_node - SHELL=dash TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1 - SHELL=bash TEST_SUITE=installation
- SHELL=dash TEST_SUITE=installation_node - SHELL=bash TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1 - SHELL=zsh TEST_SUITE=installation
- SHELL=bash TEST_SUITE=installation_node - SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1 # - SHELL=ksh TEST_SUITE=installation
- SHELL=zsh TEST_SUITE=installation_node # - SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_node
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
- SHELL=sh TEST_SUITE=installation_iojs
- 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=bash TEST_SUITE=installation_iojs
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation_iojs
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_iojs
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1

View File

@@ -1,106 +0,0 @@
# Code of Conduct
`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct) in English, and translations are available from the Contributor Covenant organisation:
- [contributor-covenant.org/translations](https://www.contributor-covenant.org/translations)
- [github.com/ContributorCovenant](https://github.com/ContributorCovenant/contributor_covenant/tree/release/content/version/1/4)
Refer to the sections on reporting and escalation in this document for the specific emails that can be used to report and escalate issues.
## Reporting
### Project Spaces
For reporting issues in spaces related to `nvm` please use the email `ljharb@gmail.com`. `nvm` handles CoC issues related to the spaces that it maintains. Projects maintainers commit to:
- maintain the confidentiality with regard to the reporter of an incident
- to participate in the path for escalation as outlined in
the section on Escalation when required.
### Foundation Spaces
For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization, use the email `report@lists.openjsf.org`. The Cross Project Council (CPC) is responsible for managing these reports and commits to:
- maintain the confidentiality with regard to the reporter of an incident
- to participate in the path for escalation as outlined in
the section on Escalation when required.
## Escalation
The OpenJS Foundation maintains a Code of Conduct Panel (CoCP). This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled. In order to escalate to the CoCP send an email to `coc-escalation@lists.openjsf.org`.
For more information, refer to the full [Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/master/CODE_OF_CONDUCT.md).
---
## Contributor Covenant Code of Conduct
### Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
### Our Standards
Examples of behavior that contributes to creating a positive environment include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
### Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
### Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
### Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at the email addresses listed above in
the [Reporting](#reporting) and [Escalation](#escalation) sections. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an
incident. Further details of specific enforcement policies may be posted
separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct/](https://www.contributor-covenant.org/version/1/4/code-of-conduct/)
[homepage]: https://www.contributor-covenant.org

View File

@@ -1,21 +1,15 @@
Thanks for contributing to `nvm`! Thanks for contributing to `nvm`!
We love pull requests and issues, they're our favorite. We love pull requests, they're our favorite.
However, before submitting, please review the following: However, before submitting, please review the following:
For bug reports: - Please include tests. Changes with tests will be merged very quickly.
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
- Any time you make a change to your PR, please rebase freshly on top of master. Nobody likes merge commits.
- Please make sure the bug is reproducible, and give us the steps to reproduce it, so that we can dig into the problem. Even if you don't have all of these items covered, please still feel free to submit a PR! Someone else may be inspired and volunteer to complete it for you.
- Please give us as much detail as possible about your environment, so we can more easily confirm the problem.
For pull requests:
- Please include tests. Changes with tests will be merged very quickly.
- Please manually confirm that your changes work in `bash`, `sh`/`dash`, `ksh`, and `zsh`. Fast tests do run in these shells, but it's nice to manually verify also.
- Please maintain consistent whitespace - 2-space indentation, trailing newlines in all files, etc.
- Any time you make a change to your PR, please rebase freshly on top of master. Nobody likes merge commits.
Even if you don't have all of these items covered, please still feel free to submit a PR/issue! Someone else may be inspired and volunteer to complete it for you.
Thanks again! Thanks again!

View File

@@ -1,112 +0,0 @@
# Dockerized nvm development environment
#
# This Dockerfile is for building nvm development environment only,
# not for any distribution/production usage.
#
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
# build this image, it depends on your hardware.
FROM ubuntu:16.04
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
LABEL name="nvm-dev-env"
LABEL version="latest"
# Set the SHELL to bash with pipefail option
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# Prevent dialog during apt install
ENV DEBIAN_FRONTEND noninteractive
# ShellCheck version
ENV SHELLCHECK_VERSION=0.7.0
# Pick a Ubuntu apt mirror site for better speed
# ref: https://launchpad.net/ubuntu/+archivemirrors
ENV UBUNTU_APT_SITE ubuntu.cs.utah.edu
# Disable src package source
RUN sed -i 's/^deb-src\ /\#deb-src\ /g' /etc/apt/sources.list
# Replace origin apt package site with the mirror site
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
# Install apt packages
RUN apt update && \
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && \
apt install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
coreutils \
util-linux \
bsdutils \
file \
openssl \
libssl-dev \
locales \
ca-certificates \
ssh \
wget \
patch \
sudo \
htop \
dstat \
vim \
tmux \
curl \
git \
jq \
realpath \
zsh \
ksh \
gcc-4.8 \
g++-4.8 \
xz-utils \
build-essential \
bash-completion && \
apt-get clean
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
rmdir shellcheck-v$SHELLCHECK_VERSION
RUN shellcheck -V
# Set locale
RUN locale-gen en_US.UTF-8
# Print tool versions
RUN bash --version | head -n 1
RUN zsh --version
RUN ksh --version || true
RUN dpkg -s dash | grep ^Version | awk '{print $2}'
RUN git --version
RUN curl --version
RUN wget --version
# Add user "nvm" as non-root user
RUN useradd -ms /bin/bash nvm
# Copy and set permission for nvm directory
COPY . /home/nvm/.nvm/
RUN chown nvm:nvm -R "home/nvm/.nvm"
# Set sudoer for "nvm"
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Switch to user "nvm" from now
USER nvm
# nvm
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc"
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' >> "$HOME/.bashrc"
# nodejs and tools
RUN bash -c 'source $HOME/.nvm/nvm.sh && \
nvm install node && \
npm install -g doctoc urchin eclint dockerfile_lint && \
npm install --prefix "$HOME/.nvm/"'
# Set WORKDIR to nvm directory
WORKDIR /home/nvm/.nvm
ENTRYPOINT ["/bin/bash"]

View File

@@ -1,8 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2010 Tim Caswell Copyright (c) 2010-2014 Tim Caswell
Copyright (c) 2014 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@@ -20,3 +18,4 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -15,7 +15,7 @@ ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS))) UTIL_CHECK := $(or $(shell PATH="$(PATH)" which $(UTILS) >/dev/null && echo 'ok'),$(error Did you forget to run `npm install` after cloning the repo? At least one of the required supporting utilities not found: $(UTILS)))
endif endif
# The files that need updating when incrementing the version number. # The files that need updating when incrementing the version number.
VERSIONED_FILES := nvm.sh install.sh README.md package.json VERSIONED_FILES := nvm.sh install.sh README.markdown package.json
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`. # Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
SHELLS := sh bash dash zsh # ksh (#574) SHELLS := sh bash dash zsh # ksh (#574)
# Generate 'test-<shell>' target names from specified shells. # Generate 'test-<shell>' target names from specified shells.
@@ -41,9 +41,9 @@ list:
.PHONY: $(SHELL_TARGETS) .PHONY: $(SHELL_TARGETS)
$(SHELL_TARGETS): $(SHELL_TARGETS):
@shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \ @shell='$@'; shell=$${shell##*-}; which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \ printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \ [ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS). # All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
.PHONY: test .PHONY: test
@@ -55,14 +55,6 @@ ifndef TAG
$(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number) $(error Please invoke with `make TAG=<new-version> release`, where <new-version> is either an increment specifier (patch, minor, major, prepatch, preminor, premajor, prerelease), or an explicit major.minor.patch version number)
endif endif
# Ensures there are version tags in repository
.PHONY: _ensure-current-version
_ensure-current-version:
ifeq ($(shell git tag),$(printf ''))
@git fetch --tags
endif
# Ensures that the git workspace is clean. # Ensures that the git workspace is clean.
.PHONY: _ensure-clean .PHONY: _ensure-clean
_ensure-clean: _ensure-clean:
@@ -70,16 +62,16 @@ _ensure-clean:
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`. # Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
.PHONY: release .PHONY: release
release: _ensure-tag _ensure-clean _ensure-current-version release: _ensure-tag _ensure-clean
@old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \ @old_ver=`git describe --abbrev=0 --tags --match 'v[0-9]*.[0-9]*.[0-9]*'` || { echo "Failed to determine current version." >&2; exit 1; }; old_ver=$${old_ver#v}; \
new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \ new_ver=`echo "$(TAG)" | sed 's/^v//'`; new_ver=$${new_ver:-patch}; \
if printf "$$new_ver" | grep -q '^[0-9]'; then \ if printf "$$new_ver" | grep -q '^[0-9]'; then \
semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \ semver "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be major.minor.patch' >&2; exit 2; }; \
semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \ semver -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
else \ else \
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \ new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
fi; \ fi; \
printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \ printf "=== Bumping version **$$old_ver** to **$$new_ver** before committing and tagging:\n=== TYPE 'proceed' TO PROCEED, anything else to abort: " && read response && [ "$$response" = 'proceed' ] || { echo 'Aborted.' >&2; exit 2; }; \
replace "$$old_ver" "$$new_ver" $(VERSIONED_FILES) && \ replace "$$old_ver" "$$new_ver" -- $(VERSIONED_FILES) && \
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \ git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
git tag -a "v$$new_ver" git tag -a -m "v$$new_ver" "v$$new_ver"

212
README.markdown Normal file
View File

@@ -0,0 +1,212 @@
# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)][3]
## Installation
First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.
Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/nvm/issues/284)). Two alternatives exist, which are not supported nor developed by us:
- [nvmw](https://github.com/hakobera/nvmw)
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). Two alternatives exist, which are not supported nor developed by us:
- [nvm-fish-wrapper](https://github.com/passcod/nvm-fish-wrapper)
- [nvm-fish](https://github.com/Alex7Kom/nvm-fish) (does not support iojs)
### Install script
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.24.2/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.24.2/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR`, and `PROFILE` variables.
Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
<sub>*NB. The installer can use `git`, `curl`, or `wget` to download `nvm`, whatever is available.*</sub>
### Manual install
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
Or if you have `git` installed, then just clone it, and check out the latest version:
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
To activate nvm, you need to source it from your shell:
source ~/.nvm/nvm.sh
I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login.
Often I also put in a line to use a specific version of node.
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied.
To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.10
And then in any new shell just use the installed version:
nvm use 0.10
Or you can just run it:
nvm run 0.10 --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
You can also get the path to the executable to where it was installed:
nvm which 0.10
In place of a version pointer like "0.10", you can use the special default aliases "stable" and "unstable":
nvm install stable
nvm install unstable
nvm use stable
nvm run unstable --version
If you want to install [io.js](https://github.com/iojs/io.js/):
nvm install iojs
If you want to use the system-installed version of node, you can use the special default alias "system":
nvm use system
nvm run system --version
If you want to see what versions are installed:
nvm ls
If you want to see what versions are available to install:
nvm ls-remote
To restore your PATH, you can deactivate it.
nvm deactivate
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default stable
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
nvm install 0.10
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 0.10
To use a mirror of the iojs binaries, set `$NVM_IOJS_ORG_MIRROR`:
export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
nvm install iojs-v1.0.3
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs.
## License
nvm is released under the MIT license.
Copyright (C) 2010-2014 Tim Caswell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Running tests
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install
There are slow tests and fast tests. The slow tests do things like install node
and check that the right versions are used. The fast tests fake this to test
things like aliases and uninstalling. From the root of the nvm git repository,
run the fast tests like this.
npm run test/fast
Run the slow tests like this.
npm run test/slow
Run all of the tests like this
npm test
Nota bene: Avoid running nvm while the tests are running.
## Bash completion
To activate, you need to source `bash_completion`:
[[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion
Put the above sourcing line just below the sourcing line for NVM in your profile (`.bashrc`, `.bash_profile`).
### Usage
nvm
$ nvm [tab][tab]
alias deactivate install ls run unload
clear-cache exec list ls-remote unalias use
current help list-remote reinstall-packages uninstall version
nvm alias
$ nvm alias [tab][tab]
default
$ nvm alias my_alias [tab][tab]
v0.6.21 v0.8.26 v0.10.28
nvm use
$ nvm use [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28
nvm uninstall
$ nvm uninstall [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28
## Problems
If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following:
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
Where's my 'sudo node'? Check out this link:
https://github.com/creationix/nvm/issues/43
On Arch Linux and other systems using python3 by default, before running *install* you need to
export PYTHON=python2
After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use `-s` option to force install from source:
nvm install -s 0.8.6
[1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.24.2/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com

937
README.md
View File

@@ -1,937 +0,0 @@
# 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` -->
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
## Table of Contents
- [About](#about)
- [Installing and Updating](#installing-and-updating)
- [Install & Update Script](#install--update-script)
- [Additional Notes](#additional-notes)
- [Troubleshooting on Linux](#troubleshooting-on-linux)
- [Troubleshooting on macOS](#troubleshooting-on-macos)
- [Ansible](#ansible)
- [Verify Installation](#verify-installation)
- [Important Notes](#important-notes)
- [Git Install](#git-install)
- [Manual Install](#manual-install)
- [Manual Upgrade](#manual-upgrade)
- [Usage](#usage)
- [Long-term Support](#long-term-support)
- [Migrating Global Packages While Installing](#migrating-global-packages-while-installing)
- [Default Global Packages From File While Installing](#default-global-packages-from-file-while-installing)
- [io.js](#iojs)
- [System Version of Node](#system-version-of-node)
- [Listing Versions](#listing-versions)
- [Setting Custom Colors](#setting-custom-colors)
- [Persisting custom colors](#persisting-custom-colors)
- [Suppressing colorized output](#suppressing-colorized-output)
- [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)
- [Deeper Shell Integration](#deeper-shell-integration)
- [bash](#bash)
- [Automatically call `nvm use`](#automatically-call-nvm-use)
- [zsh](#zsh)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file)
- [fish](#fish)
- [Calling `nvm use` automatically in a directory with a `.nvmrc` file](#calling-nvm-use-automatically-in-a-directory-with-a-nvmrc-file-1)
- [License](#license)
- [Running Tests](#running-tests)
- [Environment variables](#environment-variables)
- [Bash Completion](#bash-completion)
- [Usage](#usage-1)
- [Compatibility Issues](#compatibility-issues)
- [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux)
- [Uninstalling / Removal](#uninstalling--removal)
- [Manual Uninstall](#manual-uninstall)
- [Docker For Development Environment](#docker-for-development-environment)
- [Problems](#problems)
- [macOS Troubleshooting](#macos-troubleshooting)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
## About
nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be installed per-user, and invoked per-shell. `nvm` works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: unix, macOS, and windows WSL.
<a id="installation-and-update"></a>
<a id="install-script"></a>
## Installing and Updating
### Install & Update Script
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
```
```sh
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`).
<a id="profile_snippet"></a>
```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" # This loads nvm
```
#### Additional Notes
- 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 (...`nvm.sh --no-use`) to postpone using `nvm` until you manually [`use`](#usage) it.
- 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.
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
#### 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.
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
Since OS X 10.9, `/usr/bin/git` has been preset by Xcode command line tools, which means we can't properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see [#1782](https://github.com/nvm-sh/nvm/issues/1782))
If you get `nvm: command not found` after running the install script, one of the following might be the reason:
- 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, 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.
- 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 you use bash, it may be that your `.bash_profile` (or `~/.profile`) does not source your `~/.bashrc` properly. You could fix this by adding `source ~/<your_profile_file>` to it or follow the next step below.
- Try adding [the snippet from the install section](#profile_snippet), that finds the correct nvm directory and loads nvm, to your usual profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
- For more information about this issue and possible workarounds, please [refer here](https://github.com/nvm-sh/nvm/issues/576)
#### Ansible
You can use a task:
```yaml
- name: nvm
shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
```
### Verify Installation
To verify that nvm has been installed, do:
```sh
command -v nvm
```
which should output `nvm` if the installation was successful. Please note that `which nvm` will not work, since `nvm` is a sourced shell function, not an executable binary.
### Important Notes
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, a few alternatives exist, which are neither supported nor developed by us:
- [nvm-windows](https://github.com/coreybutler/nvm-windows)
- [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:
- [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
- [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
- [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.
**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:
- [[#900] [Bug] nodejs on FreeBSD may need to be patched](https://github.com/nvm-sh/nvm/issues/900)
- [nodejs/node#3716](https://github.com/nodejs/node/issues/3716)
**Note:** On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the `Command Line Tools`. You can check out this blog post on how to just that:
- [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/)
**Note:** On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that:
- When using `nvm` you do not need `sudo` to globally install a module with `npm -g`, so instead of doing `sudo npm install -g grunt`, do instead `npm install -g grunt`
- If you have an `~/.npmrc` file, make sure it does not contain any `prefix` settings (which is not compatible with `nvm`)
- You can (but should not?) keep your previous "system" node install, but `nvm` will only be available to your user account (the one used to install nvm). This might cause version mismatches, as other users will be using `/usr/local/lib/node_modules/*` VS your user account using `~/.nvm/versions/node/vX.X.X/lib/node_modules/*`
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.
**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.
### Git Install
If you have `git` installed (requires git v1.7.10+):
1. clone this repo in the root of your user profile
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.38.0`
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:
(you may have to add to more than one of the above files)
```sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
```
### Manual Install
For a fully manual install, execute the following lines to first clone the `nvm` repository into `$HOME/.nvm`, and then load `nvm`:
```sh
export NVM_DIR="$HOME/.nvm" && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
```
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
(you may have to add to more than one of the above files)
```sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
```
### Manual Upgrade
For manual upgrade with `git` (requires git v1.7.10+):
1. change to the `$NVM_DIR`
1. pull down the latest changes
1. check out the latest version
1. activate the new version
```sh
(
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
```
## Usage
To download, compile, and install the latest release of node, do this:
```sh
nvm install node # "node" is an alias for the latest version
```
To install a specific version of node:
```sh
nvm install 6.14.4 # or 10.10.0, 8.9.1, etc
```
The first version installed becomes the default. New shells will start with the default version of node (e.g., `nvm alias default`).
You can list available versions using `ls-remote`:
```sh
nvm ls-remote
```
And then in any new shell just use the installed version:
```sh
nvm use node
```
Or you can just run it:
```sh
nvm run node --version
```
Or, you can run any arbitrary command in a subshell with the desired version of node:
```sh
nvm exec 4.2 node --version
```
You can also get the path to the executable to where it was installed:
```sh
nvm which 5.0
```
In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
- `node`: this installs the latest version of [`node`](https://nodejs.org/en/)
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
- `stable`: this alias is deprecated, and only truly applies to `node` `v0.12` and earlier. Currently, this is an alias for `node`.
- `unstable`: this alias points to `node` `v0.11` - the last "unstable" node release, since post-1.0, all node versions are stable. (in SemVer, versions communicate breakage, not stability).
### Long-term Support
Node has a [schedule](https://github.com/nodejs/Release#release-schedule) for long-term support (LTS) You can reference LTS versions in aliases and `.nvmrc` files with the notation `lts/*` for the latest LTS, and `lts/argon` for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments:
- `nvm install --lts` / `nvm install --lts=argon` / `nvm install 'lts/*'` / `nvm install lts/argon`
- `nvm uninstall --lts` / `nvm uninstall --lts=argon` / `nvm uninstall 'lts/*'` / `nvm uninstall lts/argon`
- `nvm use --lts` / `nvm use --lts=argon` / `nvm use 'lts/*'` / `nvm use lts/argon`
- `nvm exec --lts` / `nvm exec --lts=argon` / `nvm exec 'lts/*'` / `nvm exec lts/argon`
- `nvm run --lts` / `nvm run --lts=argon` / `nvm run 'lts/*'` / `nvm run lts/argon`
- `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` `nvm ls-remote 'lts/*'` / `nvm ls-remote lts/argon`
- `nvm version-remote --lts` / `nvm version-remote --lts=argon` / `nvm version-remote 'lts/*'` / `nvm version-remote lts/argon`
Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
To get the latest LTS version of node and migrate your existing installed packages, use
```sh
nvm install 'lts/*' --reinstall-packages-from=current
```
### Migrating Global Packages While Installing
If you want to install a new version of Node.js and migrate npm packages from a previous version:
```sh
nvm install node --reinstall-packages-from=node
```
This will first use "nvm version node" to identify the current version you're migrating packages from. Then it resolves the new version to install from the remote server and installs it. Lastly, it runs "nvm reinstall-packages" to reinstall the npm packages from your prior version of Node to the new one.
You can also install and migrate npm packages from specific versions of Node like this:
```sh
nvm install 6 --reinstall-packages-from=5
nvm install v4.2 --reinstall-packages-from=iojs
```
Note that reinstalling packages _explicitly does not update the npm version_ — this is to ensure that npm isn't accidentally upgraded to a broken version for the new node version.
To update npm at the same time add the `--latest-npm` flag, like this:
```sh
nvm install 'lts/*' --reinstall-packages-from=default --latest-npm
```
or, you can at any time run the following command to get the latest supported npm version on the current node version:
```sh
nvm install-latest-npm
```
If you've already gotten an error to the effect of "npm does not support Node.js", you'll need to (1) revert to a previous node version (`nvm ls` & `nvm use <your latest _working_ version from the ls>`, (2) delete the newly created node version (`nvm uninstall <your _broken_ version of node from the ls>`), then (3) rerun your `nvm install` with the `--latest-npm` flag.
### Default Global Packages From File While Installing
If you have a list of default packages you want installed every time you install a new version, we support that too -- just add the package names, one per line, to the file `$NVM_DIR/default-packages`. You can add anything npm would accept as a package argument on the command line.
```sh
# $NVM_DIR/default-packages
rimraf
object-inspect@1.0.2
stevemao/left-pad
```
### io.js
If you want to install [io.js](https://github.com/iojs/io.js/):
```sh
nvm install iojs
```
If you want to install a new version of io.js and migrate npm packages from a previous version:
```sh
nvm install iojs --reinstall-packages-from=iojs
```
The same guidelines mentioned for migrating npm packages in node are applicable to io.js.
### System Version of Node
If you want to use the system-installed version of node, you can use the special default alias "system":
```sh
nvm use system
nvm run system --version
```
### Listing Versions
If you want to see what versions are installed:
```sh
nvm ls
```
If you want to see what versions are available to install:
```sh
nvm ls-remote
```
### Setting Custom Colors
You can set five colors that will be used to display version and alias information. These colors replace the default colors.
Initial colors are: g b y r e
Color codes:
r/R = red / bold red
g/G = green / bold green
b/B = blue / bold blue
c/C = cyan / bold cyan
m/M = magenta / bold magenta
y/Y = yellow / bold yellow
k/K = black / bold black
e/W = light grey / white
```sh
nvm set-colors rgBcm
```
#### Persisting custom colors
If you want the custom colors to persist after terminating the shell, export the NVM_COLORS variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line:
```sh
export NVM_COLORS='cmgRY'
```
#### Suppressing colorized output
`nvm help (or -h or --help)`, `nvm ls`, `nvm ls-remote` and `nvm alias` usually produce colorized output. You can disable colors with the `--no-colors` option (or by setting the environment variable `TERM=dumb`):
```sh
nvm ls --no-colors
nvm help --no-colors
TERM=dumb nvm ls
```
#### Restoring PATH
To restore your PATH, you can deactivate it:
```sh
nvm deactivate
```
#### Set default node version
To set a default Node version to be used in any new shell, use the alias 'default':
```sh
nvm alias default node
```
#### Use a mirror of node binaries
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
```sh
export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
nvm install node
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2
```
To use a mirror of the io.js binaries, set `$NVM_IOJS_ORG_MIRROR`:
```sh
export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist
nvm install iojs-v1.0.3
NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
```
`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions.
### .nvmrc
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
Afterwards, `nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line.
For example, to make nvm default to the latest 5.9 release, the latest LTS version, or the latest node version for the current directory:
```sh
$ echo "5.9" > .nvmrc
$ echo "lts/*" > .nvmrc # to default to the latest LTS version
$ echo "node" > .nvmrc # to default to the latest version
```
[NB these examples assume a POSIX-compliant shell version of `echo`. If you use a Windows `cmd` development environment, eg the `.nvmrc` file is used to configure a remote Linux deployment, then keep in mind the `"`s will be copied leading to an invalid file. Remove them.]
Then when you run nvm:
```sh
$ nvm use
Found '/path/to/project/.nvmrc' with version <5.9>
Now using node v5.9.1 (npm v3.7.3)
```
`nvm use` et. al. will traverse directory structure upwards from the current directory looking for the `.nvmrc` file. In other words, running `nvm use` et. al. in any subdirectory of a directory with an `.nvmrc` will result in that `.nvmrc` being utilized.
The contents of a `.nvmrc` file **must** be the `<version>` (as described by `nvm --help`) followed by a newline. No trailing spaces are allowed, and the trailing newline is required.
### Deeper Shell Integration
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` development team. Please [report issues to the `avn` team](https://github.com/wbyoung/avn/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` development team. We are, however, accepting pull requests for more examples.
#### bash
##### Automatically call `nvm use`
Put the following at the end of your `$HOME/.bashrc`:
```bash
cdnvm() {
cd "$@";
nvm_path=$(nvm_find_up .nvmrc | tr -d '\n')
# If there are no .nvmrc file, use the default nvm version
if [[ ! $nvm_path = *[^[:space:]]* ]]; then
declare default_version;
default_version=$(nvm version default);
# If there is no default version, set it to `node`
# This will use the latest version on your machine
if [[ $default_version == "N/A" ]]; then
nvm alias default node;
default_version=$(nvm version default);
fi
# If the current version is not the default version, set it to use the default version
if [[ $(nvm current) != "$default_version" ]]; then
nvm use default;
fi
elif [[ -s $nvm_path/.nvmrc && -r $nvm_path/.nvmrc ]]; then
declare nvm_version
nvm_version=$(<"$nvm_path"/.nvmrc)
declare locally_resolved_nvm_version
# `nvm ls` will check all locally-available versions
# If there are multiple matching versions, take the latest one
# Remove the `->` and `*` characters and spaces
# `locally_resolved_nvm_version` will be `N/A` if no local versions are found
locally_resolved_nvm_version=$(nvm ls --no-colors "$nvm_version" | tail -1 | tr -d '\->*' | tr -d '[:space:]')
# If it is not already installed, install it
# `nvm install` will implicitly use the newly-installed version
if [[ "$locally_resolved_nvm_version" == "N/A" ]]; then
nvm install "$nvm_version";
elif [[ $(nvm current) != "$locally_resolved_nvm_version" ]]; then
nvm use "$nvm_version";
fi
fi
}
alias cd='cdnvm'
cd $PWD
```
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
#### zsh
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you enter a directory that contains an
`.nvmrc` file with a string telling nvm which node to `use`:
```zsh
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
```
#### fish
##### Calling `nvm use` automatically in a directory with a `.nvmrc` file
This requires that you have [bass](https://github.com/edc/bass) installed.
```fish
# ~/.config/fish/functions/nvm.fish
function nvm
bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end
# ~/.config/fish/functions/nvm_find_nvmrc.fish
function nvm_find_nvmrc
bass source ~/.nvm/nvm.sh --no-use ';' nvm_find_nvmrc
end
# ~/.config/fish/functions/load_nvm.fish
function load_nvm --on-variable="PWD"
set -l default_node_version (nvm version default)
set -l node_version (nvm version)
set -l nvmrc_path (nvm_find_nvmrc)
if test -n "$nvmrc_path"
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
if test "$nvmrc_node_version" = "N/A"
nvm install (cat $nvmrc_path)
else if test nvmrc_node_version != node_version
nvm use $nvmrc_node_version
end
else if test "$node_version" != "$default_node_version"
echo "Reverting to default Node version"
nvm use default
end
end
# ~/.config/fish/config.fish
# You must call it on initialization or listening to directory switching won't work
load_nvm
```
## License
nvm is released under the MIT license.
Copyright (C) 2010 Tim Caswell and Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
## Running Tests
Tests are written in [Urchin]. Install Urchin (and other dependencies) like so:
npm install
There are slow tests and fast tests. The slow tests do things like install node
and check that the right versions are used. The fast tests fake this to test
things like aliases and uninstalling. From the root of the nvm git repository,
run the fast tests like this:
npm run test/fast
Run the slow tests like this:
npm run test/slow
Run all of the tests like this:
npm test
Nota bene: Avoid running nvm while the tests are running.
## Environment variables
nvm exposes the following environment variables:
- `NVM_DIR` - nvm's installation directory.
- `NVM_BIN` - where node, npm, and global packages for the active version of node are installed.
- `NVM_INC` - node's include file directory (useful for building C/C++ addons for node).
- `NVM_CD_FLAGS` - used to maintain compatibility with zsh.
- `NVM_RC_VERSION` - version from .nvmrc file if being used.
Additionally, nvm modifies `PATH`, and, if present, `MANPATH` and `NODE_PATH` when changing versions.
## Bash Completion
To activate, you need to source `bash_completion`:
```sh
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
```
Put the above sourcing line just below the sourcing line for nvm in your profile (`.bashrc`, `.bash_profile`).
### Usage
nvm:
> $ nvm <kbd>Tab</kbd>
```
alias deactivate install list-remote reinstall-packages uninstall version
cache exec install-latest-npm ls run unload version-remote
current help list ls-remote unalias use which
```
nvm alias:
> $ nvm alias <kbd>Tab</kbd>
```
default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable
```
> $ nvm alias my_alias <kbd>Tab</kbd>
```
v10.22.0 v12.18.3 v14.8.0
```
nvm use:
> $ nvm use <kbd>Tab</kbd>
```
my_alias default v10.22.0 v12.18.3 v14.8.0
```
nvm uninstall:
> $ nvm uninstall <kbd>Tab</kbd>
```
my_alias default v10.22.0 v12.18.3 v14.8.0
```
## Compatibility Issues
`nvm` will encounter some issues if you have some non-default settings set. (see [#606](/../../issues/606))
The following are known to cause issues:
Inside `~/.npmrc`:
```sh
prefix='some/path'
```
Environment Variables:
```sh
$NPM_CONFIG_PREFIX
$PREFIX
```
Shell settings:
```sh
set -e
```
## Installing nvm on Alpine Linux
In order to provide the best performance (and other optimisations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al).
Alpine Linux, unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that.
There is a `-s` flag for `nvm install` which requests nvm download Node source and compile it locally.
If installing nvm on Alpine Linux *is* still what you want or need to do, you should be able to achieve this by running the following from you Alpine Linux shell:
```sh
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.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.
As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
<a id="removal"></a>
## Uninstalling / Removal
### Manual Uninstall
To remove `nvm` manually, execute the following:
```sh
$ rm -rf "$NVM_DIR"
```
Edit `~/.bashrc` (or other shell resource config) and remove the lines below:
```sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[[ -r $NVM_DIR/bash_completion ]] && \. $NVM_DIR/bash_completion
```
## Docker For Development Environment
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 14.04 base image, prepared with essential and useful tools for `nvm` development, to build the docker image of the environment, run the docker command at the root of `nvm` repository:
```sh
$ docker build -t nvm-dev .
```
This will package your current nvm repository with our pre-defined development environment into a docker image named `nvm-dev`, once it's built with success, validate your image via `docker images`:
```sh
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvm-dev latest 9ca4c57a97d8 7 days ago 650 MB
```
If you got no error message, now you can easily involve in:
```sh
$ docker run -h nvm-dev -it nvm-dev
nvm@nvm-dev:~/.nvm$
```
Please note that it'll take about 8 minutes to build the image and the image size would be about 650MB, so it's not suitable for production usage.
For more information and documentation about docker, please refer to its official website:
- https://www.docker.com/
- https://docs.docker.com/
## Problems
- If you try to install a node version and the installation fails, be sure to run `nvm cache clear` to delete cached node downloads, or you might get an error like the following:
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
- Where's my `sudo node`? Check out [#43](https://github.com/nvm-sh/nvm/issues/43)
- After the v0.8.6 release of node, nvm tries to install from binary packages. But in some systems, the official binary packages don't work due to incompatibility of shared libs. In such cases, use `-s` option to force install from source:
```sh
nvm install -s 0.8.6
```
- If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node `PATH` is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/nvm-sh/nvm/issues/658))
## macOS Troubleshooting
**nvm node version not found in vim shell**
If you set node version to a version other than your system node version `nvm use 6.2.1` and open vim and run `:!node -v` you should see `v6.2.1` if you see your system version `v0.12.7`. You need to run:
```shell
sudo chmod ugo-x /usr/libexec/path_helper
```
More on this issue in [dotphiles/dotzsh](https://github.com/dotphiles/dotzsh#mac-os-x).
**nvm is not compatible with the npm config "prefix" option**
Some solutions for this issue can be found [here](https://github.com/nvm-sh/nvm/issues/1245)
There is one more edge case causing this issue, and that's a **mismatch between the `$HOME` path and the user's home directory's actual name**.
You have to make sure that the user directory name in `$HOME` and the user directory name you'd see from running `ls /Users/` **are capitalized the same way** ([See this issue](https://github.com/nvm-sh/nvm/issues/2261)).
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
[1]: https://github.com/nvm-sh/nvm.git
[2]: https://github.com/nvm-sh/nvm/blob/v0.38.0/install.sh
[3]: https://travis-ci.org/nvm-sh/nvm
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.38.0
[Urchin]: https://github.com/scraperwiki/urchin
[Fish]: http://fishshell.com
**Homebrew makes zsh directories unsecure**
```shell
zsh compinit: insecure directories, run compaudit for list.
Ignore insecure directories and continue [y] or abort compinit [n]? y
```
Homebrew causes insecure directories like `/usr/local/share/zsh/site-functions` and `/usr/local/share/zsh`. This is **not** an `nvm` problem - it is a homebrew problem. Refer [here](https://github.com/zsh-users/zsh-completions/issues/680) for some solutions related to the issue.
**Macs with M1 chip**
_January 2021:_ there are no pre-compiled NodeJS binaries for versions prior to 15.x for Apple's new M1 chip (arm64 architecture).
Some issues you may encounter:
- using `nvm` to install, say, `v14.15.4`:
- the C code compiles successfully
- but crashes with an out of memory error when used
- increasing the memory available to node still produces the out of memory errors:
```sh
$ NODE_OPTIONS="--max-old-space-size=4096" ./node_modules/.bin/your_node_package
```
- when using `nvm` to install some versions, the compilation fails
One solution to this issue is to change the architecture of your shell from arm64 to x86.
Let's assume that:
- you already have versions `12.20.1` and `14.15.4` installed using `nvm`
- the current version in use is `14.15.4`
- you are using the `zsh` shell
```sh
# Check what version you're running:
$ node --version
v14.15.4
# Check architecture of the `node` binary:
$ node -p process.arch
arm64
# This confirms that the arch is for the M1 chip, which is causing the problems.
# So we need to uninstall it.
# We can't uninstall the version we are currently using, so switch to another version:
$ nvm install v12.20.1
# Now uninstall the version we want to replace:
$ nvm uninstall v14.15.4
# Launch a new zsh process under the 64-bit X86 architecture:
$ arch -x86_64 zsh
# Install node using nvm. This should download the precompiled x64 binary:
$ nvm install v14.15.4
# Now check that the architecture is correct:
$ node -p process.arch
x64
# It is now safe to return to the arm64 zsh process:
$ 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

@@ -1,9 +0,0 @@
# nvm Road Map
This is a list of the primary features planned for `nvm`:
- [x] Rewriting installation code paths to support installing `io.js` and `node` `v4+` [from source](https://github.com/nvm-sh/nvm/issues/1188).
- This will include [reusing previously downloaded tarballs](https://github.com/nvm-sh/nvm/issues/1193) that match checksums, which is a nice performance and bandwidth bonus.
- [ ] Adding opt-in environment variable support to list, download, and install `node` [release candidates](https://github.com/nvm-sh/nvm/issues/779), and [nightly builds](https://github.com/nvm-sh/nvm/issues/1053).
- [ ] [`nvm update`](https://github.com/nvm-sh/nvm/issues/400): the ability to autoupdate `nvm` itself
- [ ] [v1.0.0](https://github.com/nvm-sh/nvm/milestone/1), including updating the [nvm on npm](https://github.com/nvm-sh/nvm/issues/304) to auto-install nvm properly

View File

@@ -2,79 +2,80 @@
# bash completion for Node Version Manager (NVM) # bash completion for Node Version Manager (NVM)
if ! command -v nvm &> /dev/null; then __nvm_generate_completion()
return {
fi
__nvm_generate_completion() {
declare current_word declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}" current_word="${COMP_WORDS[COMP_CWORD]}"
# shellcheck disable=SC2207 COMPREPLY=($(compgen -W "$1" -- "$current_word"))
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
return 0 return 0
} }
__nvm_commands() { __nvm_commands ()
{
declare current_word declare current_word
declare command declare command
current_word="${COMP_WORDS[COMP_CWORD]}" current_word="${COMP_WORDS[COMP_CWORD]}"
COMMANDS=' COMMANDS='\
help install uninstall use run exec help install uninstall use run exec \
alias unalias reinstall-packages alias unalias reinstall-packages \
current list ls list-remote ls-remote current list ls list-remote ls-remote \
install-latest-npm clear-cache deactivate unload \
cache deactivate unload version which'
version version-remote which'
if [ ${#COMP_WORDS[@]} == 4 ]; then if [ ${#COMP_WORDS[@]} == 4 ]; then
command="${COMP_WORDS[COMP_CWORD - 2]}" command="${COMP_WORDS[COMP_CWORD-2]}"
case "${command}" in case "${command}" in
alias) __nvm_installed_nodes ;; alias) __nvm_installed_nodes ;;
esac esac
else else
case "${current_word}" in case "${current_word}" in
-*) __nvm_options ;; -*) __nvm_options ;;
*) __nvm_generate_completion "${COMMANDS}" ;; *) __nvm_generate_completion "$COMMANDS" ;;
esac esac
fi fi
} }
__nvm_options() { __nvm_options ()
{
OPTIONS='' OPTIONS=''
__nvm_generate_completion "${OPTIONS}" __nvm_generate_completion "$OPTIONS"
} }
__nvm_installed_nodes() { __nvm_installed_nodes ()
{
__nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)" __nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"
} }
__nvm_aliases() { __nvm_aliases ()
{
declare aliases declare aliases
aliases="" aliases=""
if [ -d "${NVM_DIR}/alias" ]; then if [ -d $NVM_DIR/alias ]; then
aliases="$(cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")" aliases="`cd $NVM_DIR/alias && ls`"
fi fi
echo "${aliases} node stable unstable iojs" echo "${aliases}"
} }
__nvm_alias() { __nvm_alias ()
{
__nvm_generate_completion "$(__nvm_aliases)" __nvm_generate_completion "$(__nvm_aliases)"
} }
__nvm() { __nvm ()
{
declare previous_word declare previous_word
previous_word="${COMP_WORDS[COMP_CWORD - 1]}" previous_word="${COMP_WORDS[COMP_CWORD-1]}"
case "${previous_word}" in case "$previous_word" in
use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;; use|run|exec|ls|list|uninstall) __nvm_installed_nodes ;;
alias | unalias) __nvm_alias ;; alias|unalias) __nvm_alias ;;
*) __nvm_commands ;; *) __nvm_commands ;;
esac esac
return 0 return 0
@@ -84,13 +85,8 @@ __nvm() {
# called bashcompinit that will create a complete in ZSH. If the user is in # called bashcompinit that will create a complete in ZSH. If the user is in
# ZSH, load and run bashcompinit before calling the complete function. # ZSH, load and run bashcompinit before calling the complete function.
if [[ -n ${ZSH_VERSION-} ]]; then if [[ -n ${ZSH_VERSION-} ]]; then
# Calling compinit first and then bashcompinit as mentioned by zsh man page. autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
compinit -u
else
compinit
fi
autoload -U +X bashcompinit && bashcompinit
fi fi
complete -o default -F __nvm nvm complete -o default -o nospace -F __nvm nvm

View File

@@ -1,46 +1,17 @@
#!/usr/bin/env bash #!/bin/bash
{ # this ensures the entire script is downloaded # set -e
nvm_has() { nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
nvm_echo() { if [ -z "$NVM_DIR" ]; then
command printf %s\\n "$*" 2>/dev/null NVM_DIR="$HOME/.nvm"
} fi
nvm_grep() {
GREP_OPTIONS='' command grep "$@"
}
nvm_default_install_dir() {
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
}
nvm_install_dir() {
if [ -n "$NVM_DIR" ]; then
printf %s "${NVM_DIR}"
else
nvm_default_install_dir
fi
}
nvm_latest_version() { nvm_latest_version() {
nvm_echo "v0.38.0" echo "v0.24.2"
}
nvm_profile_is_bash_or_zsh() {
local TEST_PROFILE
TEST_PROFILE="${1-}"
case "${TEST_PROFILE-}" in
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
return
;;
*)
return 1
;;
esac
} }
# #
@@ -50,203 +21,88 @@ nvm_profile_is_bash_or_zsh() {
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec" # NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
# #
nvm_source() { nvm_source() {
local NVM_GITHUB_REPO
NVM_GITHUB_REPO="${NVM_INSTALL_GITHUB_REPO:-nvm-sh/nvm}"
local NVM_VERSION
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
local NVM_METHOD local NVM_METHOD
NVM_METHOD="$1" NVM_METHOD="$1"
local NVM_SOURCE_URL local NVM_SOURCE_URL
NVM_SOURCE_URL="$NVM_SOURCE" NVM_SOURCE_URL="$NVM_SOURCE"
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm-exec" NVM_SOURCE_URL="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm-exec"
elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/bash_completion"
elif [ -z "$NVM_SOURCE_URL" ]; then elif [ -z "$NVM_SOURCE_URL" ]; then
if [ "_$NVM_METHOD" = "_script" ]; then if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm.sh" NVM_SOURCE_URL="https://raw.githubusercontent.com/creationix/nvm/$(nvm_latest_version)/nvm.sh"
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/creationix/nvm.git"
else else
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD" echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1 return 1
fi fi
fi fi
nvm_echo "$NVM_SOURCE_URL" echo "$NVM_SOURCE_URL"
}
#
# Node.js version to install
#
nvm_node_version() {
nvm_echo "$NODE_VERSION"
} }
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl --fail --compressed -q "$@" curl $*
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/--compressed //' \ -e 's/-L //' \
-e 's/--fail //' \ -e 's/-I /--server-response /' \
-e 's/-L //' \ -e 's/-s /-q /' \
-e 's/-I /--server-response /' \ -e 's/-o /-O /' \
-e 's/-s /-q /' \ -e 's/-C - /-c /')
-e 's/-sS /-nv /' \ wget $ARGS
-e 's/-o /-O /' \
-e 's/-C - /-c /')
# shellcheck disable=SC2086
eval wget $ARGS
fi fi
} }
install_nvm_from_git() { install_nvm_from_git() {
local INSTALL_DIR if [ -d "$NVM_DIR/.git" ]; then
INSTALL_DIR="$(nvm_install_dir)" echo "=> nvm is already installed in $NVM_DIR, trying to update using git"
local NVM_VERSION printf "\r=> "
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}" cd "$NVM_DIR" && (command git fetch 2> /dev/null || {
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
# Check if version is an existing ref })
if command git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q "$NVM_VERSION" ; then
:
# Check if version is an existing changeset
elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then
nvm_echo >&2 "Failed to find '$NVM_VERSION' version."
exit 1
fi
fi
local fetch_error
if [ -d "$INSTALL_DIR/.git" ]; then
# Updating repo
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
command printf '\r=> '
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!" # Cloning to $NVM_DIR
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'" echo "=> Downloading nvm from git to '$NVM_DIR'"
command printf '\r=> ' printf "\r=> "
mkdir -p "${INSTALL_DIR}" mkdir -p "$NVM_DIR"
if [ "$(ls -A "${INSTALL_DIR}")" ]; then command git clone "$(nvm_source git)" "$NVM_DIR"
# Initializing repo
command git init "${INSTALL_DIR}" || {
nvm_echo >&2 'Failed to initialize nvm repo. Please report this!'
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 set-url origin "$(nvm_source)" || {
nvm_echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
exit 2
}
else
# Cloning repo
command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
exit 2
}
fi
fi fi
# Try to fetch tag cd "$NVM_DIR" && command git checkout --quiet $(nvm_latest_version)
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$NVM_VERSION" --depth=1 2>/dev/null; then if [ ! -z "$(cd "$NVM_DIR" && git show-ref refs/heads/master)" ]; then
: cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&1
# Fetch given version
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then
nvm_echo >&2 "$fetch_error"
exit 1
fi
command git -c advice.detachedHead=false --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout -f --quiet FETCH_HEAD || {
nvm_echo >&2 "Failed to checkout the given version $NVM_VERSION. Please report this!"
exit 2
}
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
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
else
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
fi
fi
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
nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi
if ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" gc --auto --aggressive --prune=now ; then
nvm_echo >&2 "Your version of git is out of date. Please update it!"
fi fi
return return
} }
#
# Automatically install Node.js
#
nvm_install_node() {
local NODE_VERSION_LOCAL
NODE_VERSION_LOCAL="$(nvm_node_version)"
if [ -z "$NODE_VERSION_LOCAL" ]; then
return 0
fi
nvm_echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
nvm install "$NODE_VERSION_LOCAL"
local CURRENT_NVM_NODE
CURRENT_NVM_NODE="$(nvm_version current)"
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
nvm_echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
else
nvm_echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
fi
}
install_nvm_as_script() { install_nvm_as_script() {
local INSTALL_DIR
INSTALL_DIR="$(nvm_install_dir)"
local NVM_SOURCE_LOCAL local NVM_SOURCE_LOCAL
NVM_SOURCE_LOCAL="$(nvm_source script)" NVM_SOURCE_LOCAL=$(nvm_source script)
local NVM_EXEC_SOURCE local NVM_EXEC_SOURCE
NVM_EXEC_SOURCE="$(nvm_source script-nvm-exec)" NVM_EXEC_SOURCE=$(nvm_source script-nvm-exec)
local NVM_BASH_COMPLETION_SOURCE
NVM_BASH_COMPLETION_SOURCE="$(nvm_source script-nvm-bash-completion)"
# Downloading to $INSTALL_DIR # Downloading to $NVM_DIR
mkdir -p "$INSTALL_DIR" mkdir -p "$NVM_DIR"
if [ -f "$INSTALL_DIR/nvm.sh" ]; then if [ -d "$NVM_DIR/nvm.sh" ]; then
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script" echo "=> nvm is already installed in $NVM_DIR, trying to update the script"
else else
nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'" echo "=> Downloading nvm as script to '$NVM_DIR'"
fi fi
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || { nvm_download -s "$NVM_SOURCE_LOCAL" -o "$NVM_DIR/nvm.sh" || {
nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'" 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 "$NVM_DIR/nvm-exec" || {
nvm_echo >&2 "Failed to download '$NVM_EXEC_SOURCE'" echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2 return 2
} & }
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || { chmod a+x "$NVM_DIR/nvm-exec" || {
nvm_echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'" echo >&2 "Failed to mark '$NVM_DIR/nvm-exec' as executable"
return 2
} &
for job in $(jobs -p | command sort)
do
wait "$job" || return $?
done
chmod a+x "$INSTALL_DIR/nvm-exec" || {
nvm_echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
return 3 return 3
} }
} }
nvm_try_profile() {
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
return 1
fi
nvm_echo "${1}"
}
# #
# Detect profile file if not specified as environment variable # Detect profile file if not specified as environment variable
# (eg: PROFILE=~/.myprofile) # (eg: PROFILE=~/.myprofile)
@@ -254,40 +110,16 @@ nvm_try_profile() {
# Otherwise, an empty string is returned # Otherwise, an empty string is returned
# #
nvm_detect_profile() { nvm_detect_profile() {
if [ "${PROFILE-}" = '/dev/null' ]; then if [ -f "$PROFILE" ]; then
# the user has specifically requested NOT to have nvm touch their profile echo "$PROFILE"
return elif [ -f "$HOME/.bashrc" ]; then
fi echo "$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then echo "$HOME/.bash_profile"
nvm_echo "${PROFILE}" elif [ -f "$HOME/.zshrc" ]; then
return echo "$HOME/.zshrc"
fi elif [ -f "$HOME/.profile" ]; then
echo "$HOME/.profile"
local DETECTED_PROFILE
DETECTED_PROFILE=''
if [ -n "${BASH_VERSION-}" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ -n "${ZSH_VERSION-}" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
do
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
break
fi
done
fi
if [ -n "$DETECTED_PROFILE" ]; then
nvm_echo "$DETECTED_PROFILE"
fi fi
} }
@@ -296,9 +128,7 @@ nvm_detect_profile() {
# Node, and warn them if so. # Node, and warn them if so.
# #
nvm_check_global_modules() { nvm_check_global_modules() {
local NPM_COMMAND command -v npm >/dev/null 2>&1 || return 0
NPM_COMMAND="$(command -v npm 2>/dev/null)" || return 0
[ -n "${NVM_DIR}" ] && [ -z "${NPM_COMMAND%%$NVM_DIR/*}" ] && return 0
local NPM_VERSION local NPM_VERSION
NPM_VERSION="$(npm --version)" NPM_VERSION="$(npm --version)"
@@ -308,141 +138,91 @@ nvm_check_global_modules() {
local NPM_GLOBAL_MODULES local NPM_GLOBAL_MODULES
NPM_GLOBAL_MODULES="$( NPM_GLOBAL_MODULES="$(
npm list -g --depth=0 | npm list -g --depth=0 |
command sed -e '/ npm@/d' -e '/ (empty)$/d' sed '/ npm@/d' |
sed '/ (empty)$/d'
)" )"
local MODULE_COUNT local MODULE_COUNT
MODULE_COUNT="$( MODULE_COUNT="$(
command printf %s\\n "$NPM_GLOBAL_MODULES" | printf %s\\n "$NPM_GLOBAL_MODULES" |
command sed -ne '1!p' | # Remove the first line sed -ne '1!p' | # Remove the first line
wc -l | command tr -d ' ' # Count entries wc -l | tr -d ' ' # Count entries
)" )"
if [ "${MODULE_COUNT}" != '0' ]; then if [ $MODULE_COUNT -ne 0 ]; then
# shellcheck disable=SC2016 cat <<-'END_MESSAGE'
nvm_echo '=> You currently have modules installed globally with `npm`. These will no' => You currently have modules installed globally with `npm`. These will no
# shellcheck disable=SC2016 => 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' => with `nvm`; and they may (depending on how you construct your `$PATH`)
# shellcheck disable=SC2016 => override the binaries of modules installed with `nvm`:
nvm_echo '=> with `nvm`; and they may (depending on how you construct your `$PATH`)'
# shellcheck disable=SC2016
nvm_echo '=> override the binaries of modules installed with `nvm`:'
nvm_echo
command printf %s\\n "$NPM_GLOBAL_MODULES" END_MESSAGE
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your' printf %s\\n "$NPM_GLOBAL_MODULES"
# shellcheck disable=SC2016 cat <<-'END_MESSAGE'
nvm_echo '=> `nvm` Nodes), you can remove them from the system Node as follows:'
nvm_echo => If you wish to uninstall them at a later point (or re-install them under your
nvm_echo ' $ nvm use system' => `nvm` Nodes), you can remove them from the system Node as follows:
nvm_echo ' $ npm uninstall -g a_module'
nvm_echo $ nvm use system
$ npm uninstall -g a_module
END_MESSAGE
fi fi
} }
nvm_do_install() { nvm_do_install() {
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then if [ -z "$METHOD" ]; then
if [ -e "${NVM_DIR}" ]; then
nvm_echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
exit 1
fi
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
mkdir "${NVM_DIR}"
else
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
fi
fi
if [ -z "${METHOD}" ]; then
# Autodetect install method # Autodetect install method
if nvm_has git; then if nvm_has "git"; then
install_nvm_from_git install_nvm_from_git
elif nvm_has nvm_download; then elif nvm_has "nvm_download"; then
install_nvm_as_script install_nvm_as_script
else else
nvm_echo >&2 'You need git, curl, or wget to install 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
nvm_echo >&2 "You need git to install 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
nvm_echo >&2 "You need curl or wget to install 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
nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
exit 1
fi fi
nvm_echo echo
local NVM_PROFILE local NVM_PROFILE
NVM_PROFILE="$(nvm_detect_profile)" NVM_PROFILE=$(nvm_detect_profile)
local PROFILE_INSTALL_DIR
PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")"
SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n" SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
# shellcheck disable=SC2016 if [ -z "$NVM_PROFILE" ] ; then
COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n' echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
BASH_OR_ZSH=false echo "=> Create one of them and run this script again"
echo "=> Create it (touch $NVM_PROFILE) and run this script again"
if [ -z "${NVM_PROFILE-}" ] ; then echo " OR"
local TRIED_PROFILE echo "=> Append the following lines to the correct file yourself:"
if [ -n "${PROFILE}" ]; then printf "$SOURCE_STR"
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), " echo
fi
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
nvm_echo "=> Create one of them and run this script again"
nvm_echo " OR"
nvm_echo "=> Append the following lines to the correct file yourself:"
command printf "${SOURCE_STR}"
nvm_echo
else else
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then if ! grep -qc 'nvm.sh' "$NVM_PROFILE"; then
BASH_OR_ZSH=true echo "=> Appending source string to $NVM_PROFILE"
fi printf "$SOURCE_STR\n" >> "$NVM_PROFILE"
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
nvm_echo "=> Appending nvm source string to $NVM_PROFILE"
command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
else else
nvm_echo "=> nvm source string already in ${NVM_PROFILE}" echo "=> Source string already in $NVM_PROFILE"
fi
# shellcheck disable=SC2016
if ${BASH_OR_ZSH} && ! command grep -qc '$NVM_DIR/bash_completion' "$NVM_PROFILE"; then
nvm_echo "=> Appending bash_completion source string to $NVM_PROFILE"
command printf "$COMPLETION_STR" >> "$NVM_PROFILE"
else
nvm_echo "=> bash_completion source string already in ${NVM_PROFILE}"
fi fi
fi fi
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
command printf "${COMPLETION_STR}"
fi
# Source nvm
# shellcheck source=/dev/null
\. "$(nvm_install_dir)/nvm.sh"
nvm_check_global_modules nvm_check_global_modules
nvm_install_node echo "=> Close and reopen your terminal to start using nvm"
nvm_reset nvm_reset
nvm_echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
command printf "${SOURCE_STR}"
if ${BASH_OR_ZSH} ; then
command printf "${COMPLETION_STR}"
fi
} }
# #
@@ -450,12 +230,9 @@ nvm_do_install() {
# during the execution of the install script # during the execution of the install script
# #
nvm_reset() { nvm_reset() {
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \ unset -f nvm_reset nvm_has nvm_latest_version \
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \ nvm_source nvm_download install_nvm_as_script install_nvm_from_git \
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \ nvm_detect_profile nvm_check_global_modules nvm_do_install
nvm_do_install nvm_reset nvm_default_install_dir nvm_grep
} }
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install [ "_$NVM_ENV" = "_testing" ] || nvm_do_install
} # this ensures the entire script is downloaded #

View File

@@ -1,15 +1,14 @@
#!/usr/bin/env bash #!/bin/bash
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# shellcheck disable=SC1090 source "$DIR/nvm.sh"
\. "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127 nvm use $NODE_VERSION > /dev/null || (echo "NODE_VERSION not set" >&2 && exit 127)
elif ! nvm use >/dev/null 2>&1; then else
echo "No NODE_VERSION provided; no .nvmrc file found" >&2 nvm use > /dev/null || (echo "No .nvmrc file found" >&2 && exit 127)
exit 127
fi fi
exec "$@" exec $@

4470
nvm.sh Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -1,49 +1,37 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.38.0", "version": "0.24.2",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions", "description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": { "directories": {
"test": "test" "test": "test"
}, },
"scripts": { "scripts": {
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell", "test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); env -i TERM=\"$TERM\" bash -lc \"make TEST_SUITE=fast test-$shell\"", "test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=fast test-$shell",
"test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell", "test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell", "test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs", "test/installation": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation test-$shell",
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node test-$shell", "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing 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",
"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)",
"dockerfile_lint": "dockerfile_lint"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/nvm-sh/nvm.git" "url": "git://github.com/creationix/nvm.git"
}, },
"keywords": [ "keywords": [
"nvm", "nvm",
"node", "node",
"iojs",
"version", "version",
"manager" "manager"
], ],
"author": "Tim Caswell <tim@creationix.com>", "author": "Tim Caswell <tim@creationix.com>",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/nvm-sh/nvm/issues" "url": "https://github.com/creationix/nvm/issues"
}, },
"homepage": "https://github.com/nvm-sh/nvm", "homepage": "https://github.com/creationix/nvm",
"devDependencies": { "devDependencies": {
"dockerfile_lint": "^0.3.4", "replace": "~0.3.0",
"doctoc": "^2.0.0", "semver": "~4.2.0",
"eclint": "^2.8.1", "urchin": "~0.0.5"
"replace": "^1.2.1",
"semver": "^7.3.5",
"urchin": "^0.0.5"
} }
} }

View File

@@ -1,52 +0,0 @@
#! /usr/bin/env bash
find_name(){
find test -name "*[\\/:\*\?\"<>\|]*" -o -name "*."
}
check_name() {
if [ "$(find_name | wc -l)" != "0" ]; then
printf '%s\n\n' "The following filenames contain unwanted characters:"
find_name
printf '\n%s\n%s\n' "Please run ./rename_test.sh" "If the problem persist, please open an issue."
exit 1
else
echo "Ok"
fi
}
rename_test() {
local filename
local new_filename
while read -r filename; do
# Even though it looks < and > are replaced by the same < and >, the latters are not ASCII code
# If you check with 'cat -v rename_test.sh' you would see 's/</M-KM-^B/g' and 's/>/M-KM-^C/g'
# M-KM-^B -> U+02C2
# M-KM-^C -> U+02C3
new_filename=$(echo "$filename" | sed -r \
-e "s/\"/'/g" \
-e 's/</˂/g' \
-e 's/>/˃/g' \
-e 's/^(.*)\.$/\1/'
)
printf '%s\n%s\n\n' "$filename" "$new_filename"
[ "$filename" != "$new_filename" ] && git mv "$filename" "$new_filename"
done < <(find_name)
if [ "$(find_name | wc -l)" != "0" ]; then
echo "Still some files to treat:"
find_name
else
echo "Done"
fi
}
main() {
if [ "$1" = "--check" ]; then
check_name
else
rename_test
fi
}
main "$@"

View File

@@ -1,103 +0,0 @@
assert_ok() {
local FUNCTION=$1
shift
$($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'
}
assert_not_ok() {
local FUNCTION=$1
shift
! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'
}
strip_colors() {
while read -r line; do
echo "$line" | LC_ALL=C command sed 's/\[[ -?]*[@-~]//g'
done
}
make_echo() {
echo "#!/bin/sh" > "$1"
echo "echo \"${2}\"" > "$1"
chmod a+x "$1"
}
make_fake_node() {
local VERSION
VERSION="${1-}"
[ -n "${VERSION}" ] || return 1
local FORMATTED_VERSION
FORMATTED_VERSION="$(nvm_format_version "${VERSION}")"
local BIN_PATH
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
[ "${BIN_PATH}" != "/bin" ] || {
echo >&2 'nvm_version_path was empty'
return 5
}
mkdir -p "${BIN_PATH}" || {
echo >&2 'unable to make bin dir'
return 2
}
make_echo "${BIN_PATH}/node" "${VERSION}" || {
echo >&2 'unable to make fake node bin'
return 3
}
nvm_is_version_installed "${FORMATTED_VERSION}" || {
echo >&2 'fake node is not installed'
return 4
}
}
make_fake_iojs() {
local VERSION
VERSION="${1-}"
[ -n "${VERSION}" ] || return 1
local FORMATTED_VERSION
FORMATTED_VERSION="$(nvm_format_version "iojs-${VERSION}")"
local BIN_PATH
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
[ "${BIN_PATH}" != "/bin" ] || {
echo >&2 'nvm_version_path was empty'
return 5
}
mkdir -p "${BIN_PATH}" || {
echo >&2 'unable to make bin dir'
return 2
}
make_echo "${BIN_PATH}/node" "${VERSION}" || {
echo >&2 'unable to make fake node bin'
return 3
}
make_echo "${BIN_PATH}/iojs" "${VERSION}" || {
echo >&2 'unable to make fake iojs bin'
return 3
}
nvm_is_version_installed "${FORMATTED_VERSION}" || {
echo >&2 'fake iojs is not installed'
return 4
}
}
watch() {
$@ &
local JOB
JOB=$!
while true; do sleep 15; >&2 echo '* ping *'; done &
wait $JOB;
local EXIT_CODE
EXIT_CODE=$?
kill %2;
return $EXIT_CODE
}

View File

@@ -1,26 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm alias foo/bar baz 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm alias foo/bar baz >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias with a slash should fail with code 1, got '$EXIT_CODE'"
OUTPUT="$(nvm alias foo/ baz 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias ending with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm alias foo/ baz >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias ending with a slash should fail with code 1, got '$EXIT_CODE'"
OUTPUT="$(nvm alias /bar baz 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to create an alias starting with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm alias /bar baz >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to create an alias starting with a slash should fail with code 1, got '$EXIT_CODE'"

View File

@@ -1,17 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
nvm alias node stable || die '`nvm alias node stable` failed'
nvm unalias node || die '`nvm unalias node` failed'
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"

View File

@@ -1,25 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias stable 2>&1)"
EXPECTED_OUTPUT="stable is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias unstable 2>&1)"
EXPECTED_OUTPUT="unstable is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias iojs 2>&1)"
EXPECTED_OUTPUT="iojs is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
OUTPUT="$(nvm unalias system 2>&1)"
EXPECTED_OUTPUT="system is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"

View File

@@ -1,26 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm unalias foo/bar 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm unalias foo/bar >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias with a slash should fail with code 1, got '$EXIT_CODE'"
OUTPUT="$(nvm unalias foo/ 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias ending with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm unalias foo/ >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias ending with a slash should fail with code 1, got '$EXIT_CODE'"
OUTPUT="$(nvm unalias /bar 2>&1)"
EXPECTED_OUTPUT="Aliases in subdirectories are not supported."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove an alias starting with a slash should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
EXIT_CODE="$(nvm unalias /bar >/dev/null 2>&1 ; echo $?)"
[ "$EXIT_CODE" = "1" ] || die "trying to remove an alias starting with a slash should fail with code 1, got '$EXIT_CODE'"

View File

@@ -0,0 +1,21 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
if [ -n "$ZSH_VERSION" ]; then
# set clobber option in order to test that this does not produce any
# incompatibilities
setopt noclobber
fi
nvm alias test-stable-1 0.0.2
nvm alias test-stable-1 | \grep -e "test-stable-1 -> 0.0.2 (-> v0.0.2)" \
|| die "nvm alias test-stable-1 0.0.2 did not set test-stable-1 to 0.0.2"
nvm alias test-stable-1 0.0.1
nvm alias test-stable-1 | \grep -e "test-stable-1 -> 0.0.1 (-> v0.0.1)" \
|| die "nvm alias test-stable-1 0.0.1 did not set test-stable-1 to 0.0.1"

View File

@@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh . ../../../nvm.sh
[ $(nvm alias test-stable-1 | wc -l) = '2' ] [ $(nvm alias test-stable-1 | wc -l) = '2' ]

View File

@@ -0,0 +1,26 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias)
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \
|| die "nvm alias did not contain the default local stable node version"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^node -> stable (-> $STABLE_VERSION) (default)$" \
|| die "nvm alias did not contain the default local stable node version under 'node'"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \
|| die "nvm alias did not contain the default local unstable node version"
EXPECTED_IOJS="$(nvm_print_implicit_alias local iojs)"
IOJS_VERSION="$(nvm_version "$EXPECTED_IOJS")"
echo "$NVM_ALIAS_OUTPUT" | \grep -e "^iojs -> $EXPECTED_IOJS (-> $IOJS_VERSION) (default)$" \
|| die "nvm alias did not contain the default local iojs version"

View File

@@ -0,0 +1,49 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../../alias/stable
rm -rf ../../../alias/unstable
rm -rf ../../../alias/node
rm -rf ../../../alias/iojs
rm -rf ../../../v0.8.1
rm -rf ../../../v0.9.1
rm -rf ../../../versions/io.js/v0.2.1
}
mkdir ../../../v0.8.1
mkdir ../../../v0.9.1
mkdir -p ../../../versions/io.js/v0.2.1
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \
|| die "stable and unstable versions are the same!"
nvm alias stable "$EXPECTED_UNSTABLE"
nvm alias unstable "$EXPECTED_STABLE"
nvm alias node stable
nvm alias iojs unstable
NVM_ALIAS_OUTPUT=$(nvm alias)
echo "$NVM_ALIAS_OUTPUT" | command grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'stable' alias"
echo "$NVM_ALIAS_OUTPUT" | command grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'unstable' alias"
echo "$NVM_ALIAS_OUTPUT" | command grep -e "^node -> stable (-> $UNSTABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'node' alias"
echo "$NVM_ALIAS_OUTPUT" | command grep -e "^iojs -> unstable (-> $STABLE_VERSION)$" \
|| die "nvm alias did not contain the overridden 'iojs' alias"
cleanup

View File

@@ -0,0 +1,48 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias)
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \
|| die "did not find test-stable-1 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \
|| die "did not find test-stable-2 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \
|| die "did not find test-stable-3 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \
|| die "did not find test-stable-4 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \
|| die "did not find test-stable-5 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \
|| die "did not find test-stable-6 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \
|| die "did not find test-stable-7 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \
|| die "did not find test-stable-8 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \
|| die "did not find test-stable-9 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \
|| die "did not find test-stable-10 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \
|| die "did not find test-unstable-1 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \
|| die "did not find test-unstable-2 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \
|| die "did not find test-unstable-3 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \
|| die "did not find test-unstable-4 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \
|| die "did not find test-unstable-5 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \
|| die "did not find test-unstable-6 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \
|| die "did not find test-unstable-7 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \
|| die "did not find test-unstable-8 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \
|| die "did not find test-unstable-9 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \
|| die "did not find test-unstable-10 alias"

View File

@@ -1,24 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
if [ -n "$ZSH_VERSION" ]; then
# set clobber option in order to test that this does not produce any
# incompatibilities
setopt noclobber
fi
nvm alias test-stable-1 0.0.2 || die '`nvm alias test-stable-1 0.0.2` failed'
OUTPUT="$(nvm alias test-stable-1 | strip_colors)"
EXPECTED_OUTPUT='test-stable-1 -> 0.0.2 (-> v0.0.2)'
echo "$OUTPUT" | \grep -F "$EXPECTED_OUTPUT" || die "nvm alias test-stable-1 0.0.2 did not set test-stable-1 to 0.0.2: got '$OUTPUT'"
nvm alias test-stable-1 0.0.1 || die '`nvm alias test-stable-1 0.0.1` failed'
OUTPUT="$(nvm alias test-stable-1 | strip_colors)"
EXPECTED_OUTPUT='test-stable-1 -> 0.0.1 (-> v0.0.1)'
echo "$OUTPUT" | \grep -F "$EXPECTED_OUTPUT" || die "nvm alias test-stable-1 0.0.1 did not set test-stable-1 to 0.0.1: got '$OUTPUT'"

View File

@@ -1,26 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias | strip_colors)
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -F "stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)" \
|| die "nvm alias did not contain the default local stable node version; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F "node -> stable (-> $STABLE_VERSION) (default)" \
|| die "nvm alias did not contain the default local stable node version under 'node'; got '$NVM_ALIAS_OUTPUT'"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
echo "$NVM_ALIAS_OUTPUT" | \grep -F "unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)" \
|| die "nvm alias did not contain the default local unstable node version; got '$NVM_ALIAS_OUTPUT'"
EXPECTED_IOJS="$(nvm_print_implicit_alias local iojs)"
IOJS_VERSION="$(nvm_version "$EXPECTED_IOJS")"
echo "$NVM_ALIAS_OUTPUT" | \grep -F "iojs -> $EXPECTED_IOJS (-> $IOJS_VERSION) (default)" \
|| die "nvm alias did not contain the default local iojs version; got '$NVM_ALIAS_OUTPUT'"

View File

@@ -1,49 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup () {
rm -rf "$(nvm_alias_path)/stable"
rm -rf "$(nvm_alias_path)/unstable"
rm -rf "$(nvm_alias_path)/node"
rm -rf "$(nvm_alias_path)/iojs"
rm -rf "${NVM_DIR}/v0.8.1"
rm -rf "${NVM_DIR}/v0.9.1"
rm -rf "${NVM_DIR}/versions/io.js/v0.2.1"
}
make_fake_node v0.8.1
make_fake_node v0.9.1
make_fake_iojs v0.2.1
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)"
UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")"
[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \
|| die "stable and unstable versions are the same!"
nvm alias stable "$EXPECTED_UNSTABLE"
nvm alias unstable "$EXPECTED_STABLE"
nvm alias node stable
nvm alias iojs unstable
NVM_ALIAS_OUTPUT=$(nvm alias | strip_colors)
echo "$NVM_ALIAS_OUTPUT" | command grep -F "stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)" \
|| die "nvm alias did not contain the overridden 'stable' alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | command grep -F "unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)" \
|| die "nvm alias did not contain the overridden 'unstable' alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | command grep -F "node -> stable (-> $UNSTABLE_VERSION)" \
|| die "nvm alias did not contain the overridden 'node' alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | command grep -F "iojs -> unstable (-> $STABLE_VERSION)" \
|| die "nvm alias did not contain the overridden 'iojs' alias; got '$NVM_ALIAS_OUTPUT'"
cleanup

View File

@@ -1,48 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
NVM_ALIAS_OUTPUT="$(nvm alias | strip_colors)"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-1 -> 0.0.1 (-> v0.0.1)' \
|| die "did not find test-stable-1 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-2 -> 0.0.2 (-> v0.0.2)' \
|| die "did not find test-stable-2 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-3 -> 0.0.3 (-> v0.0.3)' \
|| die "did not find test-stable-3 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-4 -> 0.0.4 (-> v0.0.4)' \
|| die "did not find test-stable-4 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-5 -> 0.0.5 (-> v0.0.5)' \
|| die "did not find test-stable-5 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-6 -> 0.0.6 (-> v0.0.6)' \
|| die "did not find test-stable-6 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-7 -> 0.0.7 (-> v0.0.7)' \
|| die "did not find test-stable-7 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-8 -> 0.0.8 (-> v0.0.8)' \
|| die "did not find test-stable-8 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-9 -> 0.0.9 (-> v0.0.9)' \
|| die "did not find test-stable-9 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-stable-10 -> 0.0.10 (-> v0.0.10)' \
|| die "did not find test-stable-10 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-1 -> 0.1.1 (-> v0.1.1)' \
|| die "did not find test-unstable-1 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-2 -> 0.1.2 (-> v0.1.2)' \
|| die "did not find test-unstable-2 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-3 -> 0.1.3 (-> v0.1.3)' \
|| die "did not find test-unstable-3 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-4 -> 0.1.4 (-> v0.1.4)' \
|| die "did not find test-unstable-4 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-5 -> 0.1.5 (-> v0.1.5)' \
|| die "did not find test-unstable-5 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-6 -> 0.1.6 (-> v0.1.6)' \
|| die "did not find test-unstable-6 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-7 -> 0.1.7 (-> v0.1.7)' \
|| die "did not find test-unstable-7 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-8 -> 0.1.8 (-> v0.1.8)' \
|| die "did not find test-unstable-8 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-9 -> 0.1.9 (-> v0.1.9)' \
|| die "did not find test-unstable-9 alias; got '$NVM_ALIAS_OUTPUT'"
echo "$NVM_ALIAS_OUTPUT" | \grep -F 'test-unstable-10 -> 0.1.10 (-> v0.1.10)' \
|| die "did not find test-unstable-10 alias; got '$NVM_ALIAS_OUTPUT'"

View File

@@ -1,36 +1,36 @@
#!/bin/sh #!/bin/sh
\. ../../../common.sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../../nvm.sh . ../../../../nvm.sh
ALIAS="$(nvm_resolve_alias loopback | strip_colors)" ALIAS="$(nvm_resolve_alias loopback)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias loopback was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias loopback was not ∞; got $ALIAS"
OUTPUT="$(nvm alias loopback | strip_colors)" OUTPUT="$(nvm alias loopback)"
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)" EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias one | strip_colors)" ALIAS="$(nvm_resolve_alias one)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias one was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias one was not ∞; got $ALIAS"
OUTPUT="$(nvm alias one | strip_colors)" OUTPUT="$(nvm alias one)"
EXPECTED_OUTPUT="one -> two (-> ∞)" EXPECTED_OUTPUT="one -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias two | strip_colors)" ALIAS="$(nvm_resolve_alias two)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias two was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias two was not ∞; got $ALIAS"
OUTPUT="$(nvm alias two | strip_colors)" OUTPUT="$(nvm alias two)"
EXPECTED_OUTPUT="two -> three (-> ∞)" EXPECTED_OUTPUT="two -> three (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias three | strip_colors)" ALIAS="$(nvm_resolve_alias three)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias three was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias three was not ∞; got $ALIAS"
OUTPUT="$(nvm alias three | strip_colors)" OUTPUT="$(nvm alias three)"
EXPECTED_OUTPUT="three -> one (-> ∞)" EXPECTED_OUTPUT="three -> one (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_alias four | strip_colors)" ALIAS="$(nvm_resolve_alias four)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias four was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias four was not ∞; got $ALIAS"
OUTPUT="$(nvm alias four | strip_colors)" OUTPUT="$(nvm alias four)"
EXPECTED_OUTPUT="four -> two (-> ∞)" EXPECTED_OUTPUT="four -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"

View File

@@ -1,36 +1,36 @@
#!/bin/sh #!/bin/sh
\. ../../../common.sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../../nvm.sh . ../../../../nvm.sh
ALIAS="$(nvm_resolve_local_alias loopback | strip_colors)" ALIAS="$(nvm_resolve_local_alias loopback)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias loopback was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias loopback was not ∞; got $ALIAS"
OUTPUT="$(nvm alias loopback | strip_colors)" OUTPUT="$(nvm alias loopback)"
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)" EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias one | strip_colors)" ALIAS="$(nvm_resolve_local_alias one)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias one was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias one was not ∞; got $ALIAS"
OUTPUT="$(nvm alias one | strip_colors)" OUTPUT="$(nvm alias one)"
EXPECTED_OUTPUT="one -> two (-> ∞)" EXPECTED_OUTPUT="one -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias two | strip_colors)" ALIAS="$(nvm_resolve_local_alias two)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias two was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias two was not ∞; got $ALIAS"
OUTPUT="$(nvm alias two | strip_colors)" OUTPUT="$(nvm alias two)"
EXPECTED_OUTPUT="two -> three (-> ∞)" EXPECTED_OUTPUT="two -> three (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias three | strip_colors)" ALIAS="$(nvm_resolve_local_alias three)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias three was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias three was not ∞; got $ALIAS"
OUTPUT="$(nvm alias three | strip_colors)" OUTPUT="$(nvm alias three)"
EXPECTED_OUTPUT="three -> one (-> ∞)" EXPECTED_OUTPUT="three -> one (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias four | strip_colors)" ALIAS="$(nvm_resolve_local_alias four)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias four was not ∞; got $ALIAS" [ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias four was not ∞; got $ALIAS"
OUTPUT="$(nvm alias four | strip_colors)" OUTPUT="$(nvm alias four)"
EXPECTED_OUTPUT="four -> two (-> ∞)" EXPECTED_OUTPUT="four -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"

View File

@@ -7,3 +7,4 @@ echo three > ../../../../alias/two
echo one > ../../../../alias/three echo one > ../../../../alias/three
echo two > ../../../../alias/four echo two > ../../../../alias/four

View File

@@ -7,3 +7,4 @@ rm -f ../../../../alias/two
rm -f ../../../../alias/three rm -f ../../../../alias/three
rm -f ../../../../alias/four rm -f ../../../../alias/four

View File

@@ -1,18 +0,0 @@
#!/bin/sh
set -ex
\. ../../../../nvm.sh
\. ../../../common.sh
LTS_ALIAS_PATH="$(nvm_alias_path)/lts"
rm -rf "${LTS_ALIAS_PATH}"
die () { echo "$@" ; exit 1; }
[ ! -d "${LTS_ALIAS_PATH}" ] || die "'${LTS_ALIAS_PATH}' exists and should not"
nvm alias >/dev/null 2>&1
[ -d "${LTS_ALIAS_PATH}" ] || die "'${LTS_ALIAS_PATH}' does not exist and should"

View File

@@ -1,10 +0,0 @@
#!/bin/sh
\. ../../../../nvm.sh
LTS_ALIAS_PATH="$(nvm_alias_path)/lts"
if [ -d "${LTS_ALIAS_PATH}" ]; then
mv "${LTS_ALIAS_PATH}" "${LTS_ALIAS_PATH}.bak"
rm -rf "${LTS_ALIAS_PATH}"
fi

View File

@@ -1,10 +0,0 @@
#!/bin/sh
\. ../../../../nvm.sh
LTS_ALIAS_PATH="$(nvm_alias_path)/lts"
if [ -d "${LTS_ALIAS_PATH}.bak" ]; then
rm -rf "${LTS_ALIAS_PATH}"
mv "${LTS_ALIAS_PATH}.bak" "${LTS_ALIAS_PATH}"
fi

View File

@@ -1,20 +0,0 @@
#!/bin/sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
nvm alias default 0.1 >/dev/null || die "'nvm alias default 0.1' failed"
nvm_ensure_default_set 0.3 || die "'nvm_ensure_default_set' with an existing default alias exits 0"
nvm unalias default || die "'nvm unalias default' failed"
OUTPUT="$(nvm_ensure_default_set 0.2)"
EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10)"
EXIT_CODE="$?"
[ "_$(echo "$OUTPUT" | strip_colors)" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set 0.2' did not output '$EXPECTED_OUTPUT', got '$OUTPUT'"
[ "_$EXIT_CODE" = "_0" ] || die "'nvm_ensure_default_set 0.2' did not exit with 0, got $EXIT_CODE"

View File

@@ -1,25 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
echo "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
exit 1
}
set -e
nvm_get_colors(){
echo "0;95m"
}
nvm_alias_path() {
nvm_echo "../../../alias"
}
OUTPUT=$(command printf %b $(nvm_list_aliases test-stable-1) | awk '{ print substr($0, 1, 19); }')
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }')
echo "\033[0m"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die

View File

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

View File

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

View File

@@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../nvm.sh . ../../../nvm.sh
EXIT_CODE=$(nvm_resolve_alias ; echo $?) EXIT_CODE=$(nvm_resolve_alias ; echo $?)
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE" [ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"

View File

@@ -1,8 +1,8 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../nvm.sh . ../../../nvm.sh
EXIT_CODE=$(nvm_resolve_local_alias ; echo $?) EXIT_CODE=$(nvm_resolve_local_alias ; echo $?)
[ "_$EXIT_CODE" = "_1" ] || die "nvm_resolve_local_alias without an argument did not return 1; got $EXIT_CODE" [ "_$EXIT_CODE" = "_1" ] || die "nvm_resolve_local_alias without an argument did not return 1; got $EXIT_CODE"

View File

@@ -1,14 +1,11 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
for i in $(seq 1 10) for i in $(seq 1 10)
do do
echo 0.0.$i > ../../../alias/test-stable-$i echo 0.0.$i > ../../../alias/test-stable-$i
make_fake_node v0.0.$i mkdir -p ../../../v0.0.$i
echo 0.1.$i > ../../../alias/test-unstable-$i echo 0.1.$i > ../../../alias/test-unstable-$i
make_fake_node v0.1.$i mkdir -p ../../../v0.1.$i
echo 0.2.$i > ../../../alias/test-iojs-$i echo 0.2.$i > ../../../alias/test-iojs-$i
make_fake_iojs v0.2.$i mkdir -p ../../../versions/io.js/v0.2.$i
done done

View File

@@ -14,4 +14,3 @@ rm -f "../../../alias/stable"
rm -f "../../../alias/unstable" rm -f "../../../alias/unstable"
rm -f "../../../alias/node" rm -f "../../../alias/node"
rm -f "../../../alias/iojs" rm -f "../../../alias/iojs"
rm -f "../../../alias/default"

View File

@@ -1,13 +1,12 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir -p ../../../v0.0.2
\. ../../common.sh mkdir -p ../../../v0.0.20
mkdir -p ../../../versions/node/v0.12.0
make_fake_node v0.0.2 . ../../../nvm.sh
make_fake_node v0.0.20
make_fake_node v0.12.0
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers. # The result should contain only the appropriate version numbers.
@@ -25,3 +24,4 @@ nvm which 0.12.0 || die "v0.0.20 not found"
NVM_BIN="$(nvm which 0.12.0)" NVM_BIN="$(nvm which 0.12.0)"
[ "_$NVM_BIN" = "_$(nvm_version_path v0.12.0)/bin/node" ] \ [ "_$NVM_BIN" = "_$(nvm_version_path v0.12.0)/bin/node" ] \
|| die "'nvm which 0.12.0' did not contain the correct path: got '$NVM_BIN'" || die "'nvm which 0.12.0' did not contain the correct path: got '$NVM_BIN'"

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh . ../../../nvm.sh
nvm which nonexistent_version nvm which nonexistent_version
[ "_$?" = "_1" ] [ "_$?" = "_1" ]

View File

@@ -1,3 +1,3 @@
rm -rf ../../../v0.0.2 rmdir ../../../v0.0.2 >/dev/null 2>&1
rm -rf ../../../v0.0.20 rmdir ../../../v0.0.20 >/dev/null 2>&1
rm -rf ../../../v0.12.0 rmdir ../../../v0.12.0 >/dev/null 2>&1

View File

@@ -1,12 +1,11 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir ../../../v0.0.2
\. ../../common.sh mkdir ../../../v0.0.20
make_fake_node v0.0.2 . ../../../nvm.sh
make_fake_node v0.0.20
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers. # The result should contain only the appropriate version numbers.
@@ -19,3 +18,4 @@ nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
die '"nvm ls 0.0.2" contained v0.0.20' die '"nvm ls 0.0.2" contained v0.0.20'
fi fi

View File

@@ -1,13 +1,12 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir ../../../v0.1.3
\. ../../common.sh mkdir ../../../v0.2.3
mkdir ../../../v0.20.3
make_fake_node v0.1.3 . ../../../nvm.sh
make_fake_node v0.2.3
make_fake_node v0.20.3
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
# The result should contain only the appropriate version numbers. # The result should contain only the appropriate version numbers.

View File

@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh . ../../../nvm.sh
nvm ls nonexistent_version nvm ls nonexistent_version
[ "$?" = "3" ] [ "$?" = "3" ]

View File

@@ -0,0 +1,7 @@
#!/bin/sh
. ../../../nvm.sh
nvm ls io
[ "$?" = "3" ]

View File

@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh . ../../../nvm.sh
nvm ls node_ nvm ls node_
[ "$?" = "3" ] [ "$?" = "3" ]

View File

@@ -1,12 +1,11 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh . ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
make_fake_node v0.2.3 mkdir ../../../v0.2.3
make_fake_node v0.3.3 mkdir ../../../v0.3.3
EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)"
STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")"
@@ -20,10 +19,11 @@ nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \
nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \
|| die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)"
make_fake_node v0.1.4 mkdir ../../../v0.1.2
nvm alias stable 0.1 nvm alias stable 0.1
nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \
|| die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.4" || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2"
nvm ls stable | \grep v0.1.4 >/dev/null \ nvm ls stable | \grep v0.1.2 >/dev/null \
|| die "'nvm ls stable' did not contain v0.1.4" || die "'nvm ls stable' did not contain v0.1.2"

View File

@@ -1,16 +1,15 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../nvm.sh . ../../../nvm.sh
\. ../../common.sh
make_fake_node v0.0.1 mkdir -p ../../../v0.0.1
make_fake_node v0.0.3 mkdir -p ../../../v0.0.3
make_fake_node v0.0.9 mkdir -p ../../../v0.0.9
make_fake_node v0.3.1 mkdir -p ../../../v0.3.1
make_fake_node v0.3.3 mkdir -p ../../../v0.3.3
make_fake_node v0.3.9 mkdir -p ../../../v0.3.9
nvm_has_system_node() { return 0; } nvm_has_system_node() { return 0; }
nvm ls system | grep system 2>&1 > /dev/null nvm ls system | grep system 2>&1 > /dev/null
@@ -19,3 +18,4 @@ nvm ls system | grep system 2>&1 > /dev/null
nvm_has_system_node() { return 1; } nvm_has_system_node() { return 1; }
nvm ls system | grep system 2>&1 > /dev/null nvm ls system | grep system 2>&1 > /dev/null
[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' [ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present'

View File

@@ -0,0 +1,24 @@
#!/bin/sh
. ../../../nvm.sh
mkdir ../../../v0.0.1
mkdir ../../../v0.0.3
mkdir ../../../v0.0.9
mkdir ../../../v0.3.1
mkdir ../../../v0.3.3
mkdir ../../../v0.3.9
mkdir -p ../../../versions/node/v0.12.87
mkdir -p ../../../versions/node/v0.12.9
mkdir -p ../../../versions/io.js/v0.1.2
mkdir -p ../../../versions/io.js/v0.10.2
# The result should contain the version numbers.
nvm ls | grep v0.0.1 >/dev/null &&
nvm ls | grep v0.0.3 >/dev/null &&
nvm ls | grep v0.0.9 >/dev/null &&
nvm ls | grep v0.3.1 >/dev/null &&
nvm ls | grep v0.3.3 >/dev/null &&
nvm ls | grep v0.3.9 >/dev/null &&
nvm ls | grep v0.12.87 >/dev/null &&
nvm ls | grep iojs-v0.1.2 >/dev/null

View File

@@ -1,10 +1,9 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir ../../../v0.1.3
\. ../../common.sh mkdir ../../../v0.2.3
make_fake_node v0.1.3 . ../../../nvm.sh
make_fake_node v0.2.3
[ -z `nvm ls | grep '^ *\.'` ] [ -z `nvm ls | grep '^ *\.'` ]
# The result should contain only the appropriate version numbers. # The result should contain only the appropriate version numbers.

View File

@@ -1,10 +1,11 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir ../../../v0.1.3
\. ../../common.sh mkdir ../../../v0.2.3
mkdir -p ../../../versions/node
make_fake_node v0.1.3 . ../../../nvm.sh
make_fake_node v0.2.3
[ -z "$(nvm ls | \grep 'versions')" ] [ -z "$(nvm ls | \grep 'versions')" ]
# The result should contain only the appropriate version numbers. # The result should contain only the appropriate version numbers.

View File

@@ -1,16 +1,15 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../nvm.sh . ../../../nvm.sh
\. ../../common.sh
make_fake_node v0.0.1 mkdir -p ../../../v0.0.1
make_fake_node v0.0.3 mkdir -p ../../../v0.0.3
make_fake_node v0.0.9 mkdir -p ../../../v0.0.9
make_fake_node v0.3.1 mkdir -p ../../../v0.3.1
make_fake_node v0.3.3 mkdir -p ../../../v0.3.3
make_fake_node v0.3.9 mkdir -p ../../../v0.3.9
nvm_has_system_node() { return 0; } nvm_has_system_node() { return 0; }
nvm ls | grep system 2>&1 > /dev/null nvm ls | grep system 2>&1 > /dev/null
@@ -19,3 +18,4 @@ nvm ls | grep system 2>&1 > /dev/null
nvm_has_system_node() { return 1; } nvm_has_system_node() { return 1; }
nvm ls | grep system 2>&1 > /dev/null nvm ls | grep system 2>&1 > /dev/null
[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' [ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'

View File

@@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo $@ ; exit 1; }
\. ../../../nvm.sh mkdir -p ../../../versions/node/v0.12.1
\. ../../common.sh mkdir ../../../v0.1.3
make_fake_node v0.12.1 . ../../../nvm.sh
make_fake_node v0.1.3
nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory'
nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory'

View File

@@ -1,11 +1,11 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh mkdir ../../../v0.1.2
\. ../../common.sh
make_fake_node v0.1.2 . ../../../nvm.sh
nvm ls v0.1 | grep v0.1.2 && nvm ls v0.1 | grep v0.1.2 &&
nvm ls v0.1.2 | grep v0.1.2 && nvm ls v0.1.2 | grep v0.1.2 &&
nvm ls v0.1. | grep v0.1.2 && nvm ls v0.1. | grep v0.1.2 &&
nvm ls v0.1.1 | grep N/A nvm ls v0.1.1 | grep N/A

View File

@@ -1,34 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; unset -f nvm_ls nvm_list_aliases; exit 1; }
make_fake_node v0.12.87 || die 'fake v0.12.87 could not be made'
make_fake_node v0.12.9 || die 'fake v0.12.9 could not be made'
make_fake_iojs v0.1.2 || die 'fake iojs-v0.1.2 could not be made'
make_fake_iojs v0.10.2 || die 'fake iojs-v0.10.2 could not be made'
set -e
nvm_list_aliases() {
echo 'sd-6'
}
# sanity check
OUTPUT="$(nvm alias)"
EXPECTED_OUTPUT='sd-6'
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
nvm_ls() {
echo v0.12.87
echo v0.12.9
echo iojs-v0.1.2
echo iojs-v0.10.2
}
OUTPUT="$(nvm ls --no-colors --no-alias)"
EXPECTED_OUTPUT=" v0.12.87 *
v0.12.9 *
iojs-v0.1.2 *
iojs-v0.10.2 *"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "2: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@@ -1,15 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; unset -f nvm_ls nvm_list_aliases; exit 1; }
set -e
OUTPUT="$(nvm ls --no-colors --no-alias pattern 2>&1 ||:)"
EXPECTED_OUTPUT='`--no-alias` is not supported when a pattern is provided.'
EXIT_CODE="$(nvm ls --no-colors --no-alias pattern >/dev/null 2>&1 || echo $?)"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
[ "${EXIT_CODE}" = 55 ] || die "expected 55; got >${EXIT_CODE}<"

View File

@@ -1,6 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
nvm ls io
[ "$?" = "3" ]

View File

@@ -1,35 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; unset -f nvm_ls nvm_list_aliases; exit 1; }
make_fake_node v0.12.87 || die 'fake v0.12.87 could not be made'
make_fake_node v0.12.9 || die 'fake v0.12.9 could not be made'
make_fake_iojs v0.1.2 || die 'fake iojs-v0.1.2 could not be made'
make_fake_iojs v0.10.2 || die 'fake iojs-v0.10.2 could not be made'
set -e
nvm_list_aliases() {
echo 'sd-6'
}
# sanity check
OUTPUT="$(nvm alias)"
EXPECTED_OUTPUT='sd-6'
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "1: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
nvm_ls() {
echo v0.12.87
echo v0.12.9
echo iojs-v0.1.2
echo iojs-v0.10.2
}
OUTPUT="$(nvm ls --no-colors)"
EXPECTED_OUTPUT=" v0.12.87 *
v0.12.9 *
iojs-v0.1.2 *
iojs-v0.10.2 *
sd-6"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "2: expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@@ -1,44 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
die () { echo "$@" ; exit 1; }
make_fake_node v0.0.1
make_fake_node v0.0.3
make_fake_node v0.0.9
make_fake_node v0.3.1
make_fake_node v0.3.3
make_fake_node v0.3.9
make_fake_node v0.12.87
make_fake_node v0.12.9
make_fake_iojs v0.1.2
make_fake_iojs v0.10.2
# The result should contain the version numbers.
nvm ls | grep v0.0.1 >/dev/null || die "v0.0.1 not found in: $(nvm ls)"
nvm ls | grep v0.0.3 >/dev/null || die "v0.0.3 not found in: $(nvm ls)"
nvm ls | grep v0.0.9 >/dev/null || die "v0.0.9 not found in: $(nvm ls)"
nvm ls | grep v0.3.1 >/dev/null || die "v0.3.1 not found in: $(nvm ls)"
nvm ls | grep v0.3.3 >/dev/null || die "v0.3.3 not found in: $(nvm ls)"
nvm ls | grep v0.3.9 >/dev/null || die "v0.3.9 not found in: $(nvm ls)"
nvm ls | grep v0.12.87 >/dev/null || die "v0.12.87 not found in: $(nvm ls)"
nvm ls | grep iojs-v0.1.2 >/dev/null || die "iojs-v0.1.2 not found in: $(nvm ls)"
OUTPUT="$(nvm_ls)"
EXPECTED_OUTPUT="v0.0.1
v0.0.3
v0.0.9
iojs-v0.1.2
v0.3.1
v0.3.3
v0.3.9
iojs-v0.10.2
v0.12.9
v0.12.87"
if nvm_has_system_node || nvm_has_system_iojs; then
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
system"
fi
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@@ -1,40 +0,0 @@
#!/bin/zsh
\. ../../../nvm.sh
\. ../../common.sh
if type setopt >/dev/null 2>&1; then setopt local_options markdirs; fi
die () {
if type unsetopt >/dev/null 2>&1; then unsetopt local_options markdirs; fi
echo "$@";
exit 1;
}
make_fake_node v0.0.1
make_fake_node v0.0.3
make_fake_node v0.0.9
make_fake_node v0.3.1
make_fake_node v0.3.3
make_fake_node v0.3.9
make_fake_node v0.12.87
make_fake_node v0.12.9
make_fake_iojs v0.1.2
make_fake_iojs v0.10.2
OUTPUT="$(nvm_ls)"
EXPECTED_OUTPUT="v0.0.1
v0.0.3
v0.0.9
iojs-v0.1.2
v0.3.1
v0.3.3
v0.3.9
iojs-v0.10.2
v0.12.9
v0.12.87"
if nvm_has_system_node || nvm_has_system_iojs; then
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
system"
fi
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"

View File

@@ -1,23 +0,0 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
make_fake_node v0.12.34 || die 'fake v0.12.34 could not be made'
# Enable no unset variable
set -u
# Try an alias that does not exist
output=$(nvm ls 99 2>&1 1>/dev/null || true)
test -z "${output}" || die "1: expected empty; got >${output}"
# Try a version that does not exist
output=$(nvm ls 0.12.00 2>&1 1>/dev/null || true)
test -z "${output}" || die "2: expected empty; got >${output}"
# Try a version that does exist
output=$(nvm ls 0.12.34 2>&1 1>/dev/null || true)
test -z "${output}" || die "3: expected empty; got >${output}"

View File

@@ -1,19 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
make_fake_node v0.0.1
make_fake_node v0.0.3
make_fake_node v0.0.9
make_fake_node v0.3.1
make_fake_node v0.3.3
make_fake_node v0.3.9
make_fake_node v0.12.87
make_fake_node v0.12.9
make_fake_iojs v0.1.2
make_fake_iojs v0.10.2
set -e
IFS='' nvm ls

View File

@@ -1,16 +1,17 @@
rm -rf ../../../v0.0.1 rmdir ../../../v0.0.1 >/dev/null 2>&1
rm -rf ../../../v0.0.2 rmdir ../../../v0.0.2 >/dev/null 2>&1
rm -rf ../../../v0.0.3 rmdir ../../../v0.0.3 >/dev/null 2>&1
rm -rf ../../../v0.0.9 rmdir ../../../v0.0.9 >/dev/null 2>&1
rm -rf ../../../v0.0.20 rmdir ../../../v0.0.20 >/dev/null 2>&1
rm -rf ../../../v0.1.2 rmdir ../../../v0.1.2 >/dev/null 2>&1
rm -rf ../../../v0.1.3 rmdir ../../../v0.1.3 >/dev/null 2>&1
rm -rf ../../../v0.1.4 rmdir ../../../v0.2.3 >/dev/null 2>&1
rm -rf ../../../v0.2.3 rmdir ../../../v0.3.1 >/dev/null 2>&1
rm -rf ../../../v0.3.1 rmdir ../../../v0.3.3 >/dev/null 2>&1
rm -rf ../../../v0.3.3 rmdir ../../../v0.3.9 >/dev/null 2>&1
rm -rf ../../../v0.3.9 rmdir ../../../v0.20.3 >/dev/null 2>&1
rm -rf ../../../v0.20.3 rmdir ../../../versions >/dev/null 2>&1
rm -rf ../../../versions unalias nvm_has_system_node >/dev/null 2>&1
rm -f ../../../alias/stable rm -f ../../../alias/stable >/dev/null 2>&1
rm -f ../../../alias/unstable rm -f ../../../alias/unstable >/dev/null 2>&1

View File

@@ -0,0 +1,5 @@
#!/bin/sh
. ../../nvm.sh
nvm alias test v0.1.2
[ "$(cat ../../alias/test)" = "v0.1.2" ]

View File

@@ -1,11 +1,10 @@
#!/bin/sh #!/bin/sh
set -ex die () { echo $@ ; exit 1; }
die () { echo "$@" ; exit 1; } . ../../nvm.sh
\. ../../nvm.sh
nvm deactivate 2>&1 nvm deactivate 2>&1
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' [ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'

View File

@@ -0,0 +1,17 @@
#!/bin/sh
mkdir -p ../../v0.2.3
die () { echo $@ ; exit 1; }
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
. ../../nvm.sh
nvm use v0.2.3 || die "Failed to activate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"
# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable
nvm deactivate || die "Failed to deactivate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly"

View File

@@ -0,0 +1,31 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup () {
rm -rf ../../v0.10.4
}
mkdir ../../v0.10.4
. ../../nvm.sh
nvm deactivate >/dev/null 2>&1
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)"
EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~5" ] \
|| die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE"
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)"
EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|| die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~4" ] \
|| die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"

View File

@@ -0,0 +1,7 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"

View File

@@ -0,0 +1,6 @@
#!/bin/sh
echo v0.1.2 > ../../alias/test
. ../../nvm.sh
nvm unalias test
! [ -e ../../alias/test ]

View File

@@ -0,0 +1,10 @@
#!/bin/sh
cd ../..
mkdir v0.0.1
mkdir src/node-v0.0.1
. ./nvm.sh
nvm uninstall v0.0.1
[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ]

View File

@@ -0,0 +1,12 @@
#!/bin/sh
fail () { echo $@ ; exit 1; }
. ../../nvm.sh
type nvm > /dev/null 2>&1 || fail "NVM not loaded"
nvm unload
type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0

View File

@@ -0,0 +1,22 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
rm -rf ../../alias/foo
}
. ../../nvm.sh
echo 'foo' > ../../alias/foo
OUTPUT="$(nvm use foo 2>&1)"
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
cleanup;

View File

@@ -0,0 +1,22 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
rm -rf ../../alias/foo
}
. ../../nvm.sh
echo 'foo' > ../../alias/foo
OUTPUT="$(nvm use foo 2>&1)"
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
cleanup;

View File

@@ -0,0 +1,13 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../nvm.sh
nvm_has_system_node() { return 0; }
[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node"
nvm_has_system_node() { return 1; }
[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"

View File

@@ -0,0 +1,33 @@
#!/bin/bash
export NVM_SYMLINK_CURRENT=true
. ../../nvm.sh
rm -rf ../../v0.10.29
mkdir ../../v0.10.29
nvm use 0.10.29
rmdir ../../v0.10.29
if [ ! -L ../../current ];then
echo "Expected 'current' symlink to be created!"
exit 1
fi
oldLink="$(readlink ../../current)"
if [ "$(basename $oldLink)" != 'v0.10.29' ];then
echo "Expected 'current' to point to v0.10.29 but was $oldLink"
exit 1
fi
rm -rf ../../v0.11.13
mkdir ../../v0.11.13
nvm use 0.11.13
rmdir ../../v0.11.13
newLink="$(readlink ../../current)"
if [ "$(basename $newLink)" != 'v0.11.13' ];then
echo "Expected 'current' to point to v0.11.13 but was $newLink"
exit 1
fi

View File

@@ -1,9 +1,6 @@
#!/bin/sh #!/bin/bash
set -ex . ../../nvm.sh
\. ../../nvm.sh
\. ../common.sh
TEST_NODE_VERSION="v0.10.29" TEST_NODE_VERSION="v0.10.29"
@@ -11,17 +8,17 @@ TEST_COUNT=0
TEST_PASSED=0 TEST_PASSED=0
TEST_FAILED=0 TEST_FAILED=0
registerExpectedSymlink() { function registerExpectedSymlink() {
registerResult ${1} registerResult ${1}
} }
registerExpectedNoSymlink() { function registerExpectedNoSymlink() {
[ $1 -ne 0 ] [ ${1} -ne 0 ]
registerResult $? registerResult $?
} }
registerResult() { function registerResult() {
result="${1}" result=${1}
TEST_COUNT=$(($TEST_COUNT + 1)) TEST_COUNT=$(($TEST_COUNT + 1))
@@ -30,19 +27,19 @@ registerResult() {
|| TEST_FAILED=$(($TEST_FAILED + 1)) || TEST_FAILED=$(($TEST_FAILED + 1))
} }
cleanup() { function cleanup() {
rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}" rm -rf ../../${TEST_NODE_VERSION}
rm -f "${NVM_DIR}/current" rm -f ../../current
} }
runNvmUse() { function runNvmUse() {
make_fake_node "$TEST_NODE_VERSION" mkdir ../../${TEST_NODE_VERSION}
nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&1 nvm use ${TEST_NODE_VERSION} > /dev/null 2>&1
rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}" rmdir ../../${TEST_NODE_VERSION}
} }
isCurrentSymlinkPresent() { function isCurrentSymlinkPresent() {
[ -L "${NVM_DIR}/current" ] [ -L ../../current ]
} }
NVM_SYMLINK_CURRENT=false NVM_SYMLINK_CURRENT=false
@@ -83,4 +80,5 @@ registerExpectedNoSymlink $?
cleanup cleanup
[ $TEST_FAILED -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true [ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true

View File

@@ -1,9 +0,0 @@
#!/bin/sh
set -ex
\. ../../nvm.sh
nvm alias test v0.1.2
[ "$(cat "$(nvm_alias_path)/test")" = "v0.1.2" ]

View File

@@ -1,23 +0,0 @@
#!/bin/sh
set -ex
die () { echo "$@" ; exit 1; }
\. ../../nvm.sh
\. ../common.sh
make_fake_node v0.2.3
[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin.*"` != 0 ] || die "PATH not set up properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules.*"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"
# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable
[ `expr "$NVM_BIN" : ".*v0.2.3/bin"` != 0 ] || die "NODE_BIN should contain bin directory path"
nvm deactivate || die "Failed to deactivate v0.2.3"
[ `expr "$PATH" : ".*v0.2.3/.*/bin.*"` = 0 ] || die "PATH not cleaned properly"
[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules.*"` = 0 ] || die "NODE_PATH not cleaned properly"
[ "_$NVM_BIN" = "_" ] || die "NVM_BIN should be unset: got '$NVM_BIN'"

Some files were not shown because too many files have changed in this diff Show More