mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 14:21:50 +00:00
Merge 6cc90a4b8d
into 4a7275a0c6
This commit is contained in:
commit
57bed37a98
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@ -0,0 +1,16 @@
|
||||
HEAD
|
||||
.cache
|
||||
v*
|
||||
alias
|
||||
|
||||
# For testing
|
||||
test/bak
|
||||
.urchin.log
|
||||
.urchin_stdout
|
||||
test/**/test_output
|
||||
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
|
||||
.DS_Store
|
||||
current
|
28
.editorconfig
Normal file
28
.editorconfig
Normal file
@ -0,0 +1,28 @@
|
||||
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
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
||||
* eol=lf
|
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
# 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']
|
44
.github/ISSUE_TEMPLATE.md
vendored
Normal file
44
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
<!-- Thank you for being interested in nvm! Please help us by filling out the following form if you‘re 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>
|
3
.github/SECURITY.md
vendored
Normal file
3
.github/SECURITY.md
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Security
|
||||
|
||||
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
76
.github/workflows/latest-npm.yml
vendored
Normal file
76
.github/workflows/latest-npm.yml
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
name: 'Tests: `nvm install-latest-npm`'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
matrix:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
latest: ${{ steps.set-matrix.outputs.requireds }}
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
iojs.org:443
|
||||
nodejs.org:443
|
||||
- uses: ljharb/actions/node/matrix@main
|
||||
id: set-matrix
|
||||
with:
|
||||
versionsAsRoot: true
|
||||
type: majors
|
||||
preset: '>=1'
|
||||
|
||||
nodes:
|
||||
needs: [matrix]
|
||||
permissions:
|
||||
contents: read
|
||||
name: 'nvm install-latest-npm'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
|
||||
include:
|
||||
- node-version: "9.2"
|
||||
- node-version: "9.1"
|
||||
- node-version: "9.0"
|
||||
- node-version: "6.1"
|
||||
- node-version: "5.9"
|
||||
- node-version: "4.6"
|
||||
- node-version: "4.5"
|
||||
- node-version: "4.4"
|
||||
- node-version: "0.12"
|
||||
- node-version: "0.10"
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
iojs.org:443
|
||||
nodejs.org:443
|
||||
registry.npmjs.org:443
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install-latest-npm'
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
skip-ls-check: true
|
||||
skip-install: true
|
||||
- run: npm --version
|
||||
|
||||
node:
|
||||
permissions:
|
||||
contents: none
|
||||
name: 'nvm install-latest-npm'
|
||||
needs: [nodes]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
egress-policy: block
|
||||
- run: 'echo tests completed'
|
73
.github/workflows/lint.yml
vendored
Normal file
73
.github/workflows/lint.yml
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
name: 'Tests: linting'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
eclint:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
nodejs.org:443
|
||||
registry.npmjs.org:443
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm run eclint
|
||||
|
||||
dockerfile_lint:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
ghcr.io:443
|
||||
github.com:443
|
||||
pkg-containers.githubusercontent.com:443
|
||||
nodejs.org:443
|
||||
registry.npmjs.org:443
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm run dockerfile_lint
|
||||
|
||||
doctoc:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
nodejs.org:443
|
||||
registry.npmjs.org:443
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'nvm install ${{ matrix.node-version }} && npm install'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm run doctoc:check
|
||||
|
||||
test_naming:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
- uses: actions/checkout@v2
|
||||
- name: check tests filenames
|
||||
run: ./rename_test.sh --check
|
23
.github/workflows/rebase.yml
vendored
Normal file
23
.github/workflows/rebase.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: Automatic Rebase
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
contents: write
|
||||
name: "Automatic Rebase"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
github.com:443
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ljharb/rebase@master
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
32
.github/workflows/release.yml
vendored
Normal file
32
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
name: 'Tests: release process'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
release:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
- 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
|
21
.github/workflows/require-allow-edits.yml
vendored
Normal file
21
.github/workflows/require-allow-edits.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Require “Allow Edits”
|
||||
|
||||
on: [pull_request_target]
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
pull-requests: read
|
||||
name: "Require “Allow Edits”"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
api.github.com:443
|
||||
- uses: ljharb/require-allow-edits@main
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
55
.github/workflows/shellcheck.yml
vendored
Normal file
55
.github/workflows/shellcheck.yml
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
name: 'Tests: shellcheck'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
shellcheck_matrix:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
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:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
ghcr.io:443
|
||||
github.com:443
|
||||
pkg-containers.githubusercontent.com:443
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install shellcheck
|
||||
run: brew install shellcheck
|
||||
env:
|
||||
HOMEBREW_NO_ANALYTICS: 1
|
||||
- run: "shellcheck --version"
|
||||
- name: Run shellcheck on ${{ matrix.file }}
|
||||
run: shellcheck -s ${{ matrix.shell }} ${{ matrix.file }}
|
||||
|
||||
shellcheck:
|
||||
permissions:
|
||||
contents: none
|
||||
needs: [shellcheck_matrix]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
egress-policy: block
|
||||
- run: 'echo tests completed'
|
37
.github/workflows/toc.yml
vendored
Normal file
37
.github/workflows/toc.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: update readme TOC
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
_:
|
||||
permissions:
|
||||
contents: write
|
||||
name: "update readme TOC"
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v1
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
- 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
|
133
.github/workflows/windows-npm.yml
vendored
Normal file
133
.github/workflows/windows-npm.yml
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
name: 'Tests on Windows: `nvm install`'
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
env:
|
||||
NVM_INSTALL_GITHUB_REPO: ${{ github.repository }}
|
||||
NVM_INSTALL_VERSION: ${{ github.sha }}
|
||||
|
||||
jobs:
|
||||
msys_fail_install:
|
||||
# Default installation does not work due to npm_config_prefix set to C:\npm\prefix
|
||||
permissions:
|
||||
contents: none
|
||||
name: 'MSYS fail prefix nvm install'
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Retrieve nvm
|
||||
shell: bash
|
||||
run: |
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
! nvm install --lts
|
||||
|
||||
msys_matrix:
|
||||
permissions:
|
||||
contents: none
|
||||
name: 'MSYS nvm install'
|
||||
runs-on: windows-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
npm-node-version:
|
||||
- '--lts'
|
||||
- '--default 12'
|
||||
- '--no-progress 10'
|
||||
steps:
|
||||
- name: Retrieve nvm
|
||||
shell: bash
|
||||
run: |
|
||||
unset npm_config_prefix
|
||||
if [ "${{ matrix.npm-node-version }}" = "--lts" ]; then
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||
else
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||
fi
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
nvm install ${{ matrix.npm-node-version }}
|
||||
|
||||
cygwin_matrix:
|
||||
permissions:
|
||||
contents: none
|
||||
name: 'Cygwin nvm install'
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Install Cygwin
|
||||
shell: bash
|
||||
run: |
|
||||
export SITE='https://mirror.clarkson.edu/cygwin/'
|
||||
export LOCALDIR="$(pwd)"
|
||||
export ROOTDIR="$USERPROFILE\\cygwin"
|
||||
export PACKAGES='bash,git,curl'
|
||||
|
||||
curl -fsSLo setup-x86_64.exe 'https://cygwin.com/setup-x86_64.exe'
|
||||
./setup-x86_64.exe --disable-buggy-antivirus -q -s "$SITE" -l "$LOCALDIR" -R "$ROOTDIR" -P "$PACKAGES"
|
||||
|
||||
cat >~/setup.sh <<EOM
|
||||
unset npm_config_prefix
|
||||
export NVM_INSTALL_GITHUB_REPO="$NVM_INSTALL_GITHUB_REPO"
|
||||
export NVM_INSTALL_VERSION="$NVM_INSTALL_VERSION"
|
||||
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
nvm install --lts
|
||||
|
||||
nvm deactivate
|
||||
rm -rf "$HOME/.nvm/nvm.sh"
|
||||
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
nvm install 9
|
||||
EOM
|
||||
- name: Retrieve nvm
|
||||
shell: cmd
|
||||
run: |
|
||||
cd %USERPROFILE%\cygwin\bin
|
||||
bash.exe "%USERPROFILE%\setup.sh"
|
||||
|
||||
wsl_matrix:
|
||||
name: 'WSL nvm install'
|
||||
defaults:
|
||||
run:
|
||||
shell: wsl-bash {0}
|
||||
runs-on: windows-latest
|
||||
env:
|
||||
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
wsl-distrib:
|
||||
- Debian
|
||||
- Alpine
|
||||
- Ubuntu-18.04
|
||||
npm-node-version:
|
||||
- '--lts'
|
||||
- '14'
|
||||
- '12'
|
||||
- '11'
|
||||
- '10'
|
||||
method:
|
||||
- ''
|
||||
- 'script'
|
||||
steps:
|
||||
- uses: Vampire/setup-wsl@v1
|
||||
with:
|
||||
distribution: ${{ matrix.wsl-distrib }}
|
||||
additional-packages: bash git curl ca-certificates wget
|
||||
- name: Retrieve nvm on WSL
|
||||
run: |
|
||||
if [ -z "${{ matrix.method }}" ]; then
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash
|
||||
else
|
||||
curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD="${{matrix.method}}" bash
|
||||
fi
|
||||
. "$HOME/.nvm/nvm.sh"
|
||||
nvm install ${{ matrix.npm-node-version }}
|
||||
|
||||
nvm_windows:
|
||||
permissions:
|
||||
contents: none
|
||||
needs: [wsl_matrix, cygwin_matrix, msys_matrix, msys_fail_install]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: 'echo tests completed'
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# gitignore
|
||||
HEAD
|
||||
src
|
||||
.cache
|
||||
v*
|
||||
alias
|
||||
|
||||
@ -7,8 +8,16 @@ alias
|
||||
test/bak
|
||||
.urchin.log
|
||||
.urchin_stdout
|
||||
test/**/test_output
|
||||
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
|
||||
.DS_Store
|
||||
current
|
||||
/default-packages
|
||||
|
||||
# Only apps should have lockfiles
|
||||
npm-shrinkwrap.json
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
|
@ -1,4 +0,0 @@
|
||||
src
|
||||
v*
|
||||
alias
|
||||
|
81
.travis.yml
81
.travis.yml
@ -1,8 +1,75 @@
|
||||
language: c # defaults to ruby
|
||||
install:
|
||||
- sudo apt-get install ksh zsh -y
|
||||
before_script:
|
||||
- curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin && chmod +x /tmp/urchin
|
||||
script:
|
||||
- NVM_DIR=$TRAVIS_BUILD_DIR make URCHIN=/tmp/urchin test
|
||||
language: generic
|
||||
dist: xenial
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- zsh
|
||||
# - ksh
|
||||
# - gcc-4.8
|
||||
# - g++-4.8
|
||||
|
||||
cache:
|
||||
ccache: true
|
||||
directories:
|
||||
- $TRAVIS_BUILD_DIR/.cache
|
||||
- $TRAVIS_BUILD_DIR/node_modules
|
||||
before_install:
|
||||
- sudo sed -i 's/mozilla\/DST_Root_CA_X3.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf
|
||||
- sudo update-ca-certificates -f
|
||||
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
|
||||
- curl --version
|
||||
- wget --version
|
||||
- bash --version | head
|
||||
- zsh --version
|
||||
- dpkg -s dash | grep ^Version | awk '{print $2}'
|
||||
install:
|
||||
- if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
|
||||
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
|
||||
script:
|
||||
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi
|
||||
before_cache:
|
||||
- if [ -n "$WITHOUT_CURL" ]; then sudo apt-get install curl -y ; fi
|
||||
env:
|
||||
global:
|
||||
- CXX=g++
|
||||
- CC=gcc
|
||||
- PATH="$(echo $PATH | sed 's/::/:/')"
|
||||
- PATH="/usr/lib/ccache/:$PATH"
|
||||
- NVM_DIR="${TRAVIS_BUILD_DIR}"
|
||||
matrix:
|
||||
- SHELL=bash TEST_SUITE=install_script
|
||||
- SHELL=sh TEST_SUITE=fast
|
||||
- SHELL=dash TEST_SUITE=fast
|
||||
- SHELL=bash TEST_SUITE=fast
|
||||
- SHELL=zsh TEST_SUITE=fast
|
||||
# - SHELL=ksh TEST_SUITE=fast
|
||||
- SHELL=sh TEST_SUITE=sourcing
|
||||
- SHELL=dash TEST_SUITE=sourcing
|
||||
- SHELL=bash TEST_SUITE=sourcing
|
||||
- SHELL=zsh TEST_SUITE=sourcing
|
||||
# - SHELL=ksh TEST_SUITE=sourcing
|
||||
- SHELL=sh TEST_SUITE=slow
|
||||
- SHELL=dash TEST_SUITE=slow
|
||||
- SHELL=bash TEST_SUITE=slow
|
||||
- SHELL=zsh TEST_SUITE=slow
|
||||
# - SHELL=ksh TEST_SUITE=slow
|
||||
- SHELL=sh TEST_SUITE=installation_node
|
||||
- SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=dash TEST_SUITE=installation_node
|
||||
- SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=bash TEST_SUITE=installation_node
|
||||
- SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=zsh TEST_SUITE=installation_node
|
||||
- SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
# - SHELL=ksh TEST_SUITE=installation_node
|
||||
# - SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
|
||||
- SHELL=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
|
||||
|
106
CODE_OF_CONDUCT.md
Normal file
106
CODE_OF_CONDUCT.md
Normal file
@ -0,0 +1,106 @@
|
||||
# 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
|
@ -1,15 +1,21 @@
|
||||
Thanks for contributing to `nvm`!
|
||||
|
||||
We love pull requests, they're our favorite.
|
||||
We love pull requests and issues, they're our favorite.
|
||||
|
||||
However, before submitting, please review the following:
|
||||
|
||||
- Please include tests. Changes with tests will be merged very quickly.
|
||||
- Please manually confirm that your changes, and all tests, pass in `bash`, `sh`, and `zsh`. We hope to soon automatically run all these tests, but in the meantime, we have to rely on each contributor doing so.
|
||||
- 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.
|
||||
For bug reports:
|
||||
|
||||
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 make sure the bug is reproducible, and give us the steps to reproduce it, so that we can dig into the problem.
|
||||
- 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!
|
||||
|
||||
|
111
Dockerfile
Normal file
111
Dockerfile
Normal file
@ -0,0 +1,111 @@
|
||||
# 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:18.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 \
|
||||
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"]
|
10
GOVERNANCE.md
Normal file
10
GOVERNANCE.md
Normal file
@ -0,0 +1,10 @@
|
||||
# `nvm` Project Governance
|
||||
|
||||
## Maintainers
|
||||
- [@ljharb](https://github.com/ljharb)
|
||||
|
||||
Maintainers are responsible for issue/PR triage, feature additions, maintenance, bugfixes, security fixes, releases, promoting existing contributors to maintainers, managing repo and CI configuration, etc.
|
||||
|
||||
## Contributors
|
||||
|
||||
Anyone who contributes code or content or time, via issues or pull requests or otherwise. Contributors do not have any additional permissions on the project.
|
@ -1,6 +1,8 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2010-2014 Tim Caswell
|
||||
Copyright (c) 2010 Tim Caswell
|
||||
|
||||
Copyright (c) 2014 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
|
||||
@ -18,4 +20,3 @@ 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.
|
||||
|
||||
|
89
Makefile
89
Makefile
@ -1,16 +1,85 @@
|
||||
URCHIN=`which urchin`
|
||||
SHELLS=sh bash dash ksh zsh
|
||||
# Since we rely on paths relative to the makefile location, abort if make isn't being run from there.
|
||||
$(if $(findstring /,$(MAKEFILE_LIST)),$(error Please only invoke this makefile from the directory it resides in))
|
||||
# Note: With Travis CI:
|
||||
# - the path to urchin is passed via the command line.
|
||||
# - the other utilities are NOT needed, so we skip the test for their existence.
|
||||
URCHIN := urchin
|
||||
ifeq ($(findstring /,$(URCHIN)),) # urchin path was NOT passed in.
|
||||
# Add the local npm packages' bin folder to the PATH, so that `make` can find them, when invoked directly.
|
||||
# Note that rather than using `$(npm bin)` the 'node_modules/.bin' path component is hard-coded, so that invocation works even from an environment
|
||||
# where npm is (temporarily) unavailable due to having deactivated an nvm instance loaded into the calling shell in order to avoid interference with tests.
|
||||
export PATH := $(shell printf '%s' "$$PWD/node_modules/.bin:$$PATH")
|
||||
# The list of all supporting utilities, installed with `npm install`.
|
||||
UTILS := $(URCHIN) replace semver
|
||||
# Make sure that all required utilities can be located.
|
||||
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
|
||||
# The files that need updating when incrementing the version number.
|
||||
VERSIONED_FILES := nvm.sh install.sh README.md package.json
|
||||
# Define all shells to test with. Can be overridden with `make SHELLS=... <target>`.
|
||||
SHELLS := sh bash dash zsh # ksh (#574)
|
||||
# Generate 'test-<shell>' target names from specified shells.
|
||||
# The embedded shell names are extracted on demand inside the recipes.
|
||||
SHELL_TARGETS := $(addprefix test-,$(SHELLS))
|
||||
# Define the default test suite(s). This can be overridden with `make TEST_SUITE=<...> <target>`.
|
||||
# Test suites are the names of subfolders of './test'.
|
||||
TEST_SUITE := $(shell find ./test/* -type d -prune -exec basename {} \;)
|
||||
|
||||
.PHONY: $(SHELLS) test
|
||||
|
||||
fast: $(SHELLS)
|
||||
# Default target (by virtue of being the first non '.'-prefixed in the file).
|
||||
.PHONY: _no-target-specified
|
||||
_no-target-specified:
|
||||
$(error Please specify the target to make - `make list` shows targets. Alternatively, use `npm test` to run the default tests; `npm run` shows all tests)
|
||||
|
||||
$(SHELLS):
|
||||
@printf '\n\033[0;34m%s\033[0m\n' "Running tests in $@"
|
||||
@$@ $(URCHIN) -f test/fast
|
||||
# Lists all targets defined in this makefile.
|
||||
.PHONY: list
|
||||
list:
|
||||
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
|
||||
|
||||
test: fast
|
||||
@$(URCHIN) -f test/slow
|
||||
# Set of test-<shell> targets; each runs the specified test suites for a single shell.
|
||||
# Note that preexisting NVM_* variables are unset to avoid interfering with tests, except when running the Travis tests (where NVM_DIR must be passed in and the env. is assumed to be pristine).
|
||||
.PHONY: $(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; } && \
|
||||
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; \
|
||||
for suite in $(TEST_SUITE); do $(URCHIN) -f -s $$shell test/$$suite || exit; done
|
||||
|
||||
default: test
|
||||
# All-tests target: invokes the specified test suites for ALL shells defined in $(SHELLS).
|
||||
.PHONY: test
|
||||
test: $(SHELL_TARGETS)
|
||||
|
||||
.PHONY: _ensure-tag
|
||||
_ensure-tag:
|
||||
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)
|
||||
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.
|
||||
.PHONY: _ensure-clean
|
||||
_ensure-clean:
|
||||
@[ -z "$$(git status --porcelain --untracked-files=no || echo err)" ] || { echo "Workspace is not clean; please commit changes first." >&2; exit 2; }
|
||||
|
||||
# Makes a release; invoke with `make TAG=<versionOrIncrementSpec> release`.
|
||||
.PHONY: release
|
||||
release: _ensure-tag _ensure-clean _ensure-current-version
|
||||
@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}; \
|
||||
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 -r "> $$old_ver" "$$new_ver" >/dev/null || { echo 'Invalid version number specified: $(TAG) - must be HIGHER than current one.' >&2; exit 2; } \
|
||||
else \
|
||||
new_ver=`semver -i "$$new_ver" "$$old_ver"` || { echo 'Invalid version-increment specifier: $(TAG)' >&2; exit 2; } \
|
||||
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; }; \
|
||||
replace "$$old_ver" "$$new_ver" $(VERSIONED_FILES) && \
|
||||
git commit -m "v$$new_ver" $(VERSIONED_FILES) && \
|
||||
git tag -a "v$$new_ver"
|
||||
|
49
PROJECT_CHARTER.md
Normal file
49
PROJECT_CHARTER.md
Normal file
@ -0,0 +1,49 @@
|
||||
# `nvm` Charter
|
||||
|
||||
nvm is a version manager for Node.js, 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.
|
||||
|
||||
## Section 0: Guiding Principles
|
||||
|
||||
The `nvm` project is part of the [OpenJS Foundation][openjs foundation], which operates transparently, openly, collaboratively, and ethically. Project proposals, timelines, and status must not merely be open, but also easily visible to outsiders.
|
||||
|
||||
## Section 1: Scope
|
||||
|
||||
`nvm` is a node version manager, focused on making it easy to install and manage multiple Node.js versions. Any features related to managing the installation and removal of Node.js on any node-supported platform are potentially in scope.
|
||||
|
||||
## Section 2: Relationship with OpenJS Foundation CPC.
|
||||
|
||||
Technical leadership for the projects within the [OpenJS Foundation][openjs foundation] is delegated to the projects through their project charters by the [OpenJS Foundation Cross-Project Council](https://openjsf.org/about/governance/) (CPC). In the case of the `nvm` project, it is delegated to the [`nvm` Maintainers](README.md#maintainers) (the “Maintainers”). The OpenJS Foundation's business leadership is the Board of Directors (the “Board”).
|
||||
|
||||
This `nvm` Charter reflects a carefully constructed balanced role for the Maintainers and the CPC in the governance of the OpenJS Foundation. The charter amendment process is for the Maintainers to propose changes using simple majority of the full Maintainers, the proposed changes being subject to review and approval by the CPC. The CPC may additionally make amendments to the project charter at any time, though the CPC will not interfere with day-to-day discussions, votes or meetings of the Maintainers.
|
||||
|
||||
### 2.1 Other Formal Project Relationships
|
||||
|
||||
Section Intentionally Left Blank
|
||||
|
||||
## Section 3: `nvm`'s Maintainers Governing Body
|
||||
|
||||
`nvm` is governed by its [maintainers](README.md#maintainers).
|
||||
|
||||
## Section 4: Roles & Responsibilities
|
||||
|
||||
The roles and responsibilities of `nvm`'s Maintainers are described in [GOVERNANCE.md](./GOVERNANCE.md).
|
||||
|
||||
### Section 4.1 Project Operations & Management
|
||||
|
||||
Section Intentionally Left Blank
|
||||
|
||||
### Section 4.2: Decision-making, Voting, and/or Elections
|
||||
|
||||
Section Intentionally Left Blank
|
||||
|
||||
### Section 4.3: Other Project Roles
|
||||
|
||||
Section Intentionally Left Blank
|
||||
|
||||
## Section 5: Definitions
|
||||
|
||||
- *Contributors*: contribute code or other artifacts, but do not have the right to commit to the codebase. Contributors work with the project’s maintainers to have code committed to the code base. A Contributor may be promoted to a Maintainer by the Maintainers. Contributors should rarely be encumbered by the Maintainers and never by the CPC or OpenJS Foundation Board.
|
||||
|
||||
- *Maintainers*: Contributors with any kind of decision-making authority in the project.
|
||||
|
||||
[openjs foundation]: https://openjsf.org
|
170
README.markdown
170
README.markdown
@ -1,170 +0,0 @@
|
||||
# Node Version Manager [][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.
|
||||
|
||||
### Install script
|
||||
|
||||
To install you could use the [install script][2] using cURL:
|
||||
|
||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.5.1/install.sh | sh
|
||||
|
||||
or Wget:
|
||||
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.5.1/install.sh | sh
|
||||
|
||||
<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 `NVM_PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` 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:
|
||||
|
||||
git clone https://github.com/creationix/nvm.git ~/.nvm
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
You can create an `.nvmrc` file containing version number in the project root folder; run the following command to switch versions:
|
||||
|
||||
nvm use
|
||||
|
||||
Or you can just run it:
|
||||
|
||||
nvm run 0.10
|
||||
|
||||
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 0.10
|
||||
|
||||
To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
|
||||
|
||||
export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist
|
||||
nvm install 0.10
|
||||
|
||||
NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist nvm install 0.10
|
||||
|
||||
## 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 copy-packages help list run uninstall version
|
||||
clear-cache deactivate install ls unalias use
|
||||
|
||||
nvm alias
|
||||
|
||||
$ nvm alias [tab][tab]
|
||||
default
|
||||
|
||||
$ nvm alias my_alias [tab][tab]
|
||||
v0.4.11 v0.4.12 v0.6.14
|
||||
|
||||
nvm use
|
||||
|
||||
$ nvm use [tab][tab]
|
||||
my_alias default v0.4.11 v0.4.12 v0.6.14
|
||||
|
||||
nvm uninstall
|
||||
|
||||
$ nvm uninstall [tab][tab]
|
||||
my_alias default v0.4.11 v0.4.12 v0.6.14
|
||||
|
||||
## 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'? Checkout 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.5.1/install.sh
|
||||
[3]: https://travis-ci.org/creationix/nvm
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
|
970
README.md
Normal file
970
README.md
Normal file
@ -0,0 +1,970 @@
|
||||
# Node Version Manager [][3] [][4] [](https://bestpractices.coreinfrastructure.org/projects/684)
|
||||
|
||||
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
## Table of Contents
|
||||
|
||||
- [Intro](#intro)
|
||||
- [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)
|
||||
- [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)
|
||||
- [Maintainers](#maintainers)
|
||||
- [License](#license)
|
||||
- [Copyright notice](#copyright-notice)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
## Intro
|
||||
|
||||
`nvm` allows you to quickly install and use different versions of node via the command line.
|
||||
|
||||
**Example:**
|
||||
```sh
|
||||
$ nvm use 16
|
||||
Now using node v16.9.1 (npm v7.21.1)
|
||||
$ node -v
|
||||
v16.9.1
|
||||
$ nvm use 14
|
||||
Now using node v14.18.0 (npm v6.14.15)
|
||||
$ node -v
|
||||
v14.18.0
|
||||
$ nvm install 12
|
||||
Now using node v12.22.6 (npm v6.14.5)
|
||||
$ node -v
|
||||
v12.22.6
|
||||
```
|
||||
|
||||
Simple as that!
|
||||
|
||||
|
||||
## 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](https://github.com/nvm-sh/nvm#important-notes).
|
||||
|
||||
<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.39.0/install.sh | bash
|
||||
```
|
||||
```sh
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.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 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)
|
||||
|
||||
**Note** For Macs with the M1 chip, node started providing **arm64** arch darwin packages since v16.0.0. For earlier versions, there were only **darwin_x64** packages available but no **darwin_arm64**. If you are facing issues installing node using `nvm`, you may want to update to v16 or later.
|
||||
|
||||
#### Ansible
|
||||
|
||||
You can use a task:
|
||||
|
||||
```yaml
|
||||
- name: nvm
|
||||
shell: >
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.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.
|
||||
|
||||
**Note:** 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.
|
||||
|
||||
### 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` also support Windows in some cases. It should work through WSL (Windows Subsystem for Linux) depending on the version of WSL. It should also work with [GitBash](https://gitforwindows.org/) (MSYS) or [Cygwin](https://cygwin.com). Otherwise, 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.39.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
|
||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
||||
```
|
||||
|
||||
### 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 14.7.0 # or 16.3.0, 12.22.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 12.22
|
||||
```
|
||||
|
||||
In place of a version pointer like "14.7" or "16.3" or "12.22.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` maintainers. 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` maintainers. 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() {
|
||||
command 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
|
||||
```
|
||||
|
||||
## 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](https://github.com/creationix/nvm/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.39.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 18.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.39.0/install.sh
|
||||
[3]: https://travis-ci.org/nvm-sh/nvm
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.39.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
|
||||
- after `nvm` successfully compiles some versions, `yarn` or `npm` may later fail to install packages with an `incorrect data check` error.
|
||||
|
||||
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
|
||||
- you have Rosetta 2 installed (macOS prompts you to install Rosetta 2 the first time you open a Intel-only non-command-line application, or you may install Rosetta 2 from the command line with `softwareupdate --install-rosetta`)
|
||||
|
||||
```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)
|
||||
```
|
||||
|
||||
## Maintainers
|
||||
|
||||
Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more maintainers are quite welcome, and we hope to add folks to the team over time. [Governance](./GOVERNANCE.md) will be re-evaluated as the project evolves.
|
||||
|
||||
## License
|
||||
|
||||
See [LICENSE.md](./LICENSE.md).
|
||||
|
||||
## Copyright notice
|
||||
|
||||
Copyright [OpenJS Foundation](https://openjsf.org) and `nvm` contributors. All rights reserved. The [OpenJS Foundation](https://openjsf.org) has registered trademarks and uses trademarks. For a list of trademarks of the [OpenJS Foundation](https://openjsf.org), please see our [Trademark Policy](https://trademark-policy.openjsf.org/) and [Trademark List](https://trademark-list.openjsf.org/). Node.js is a trademark of Joyent, Inc. and is used with its permission. Trademarks and logos not indicated on the [list of OpenJS Foundation trademarks](https://trademark-list.openjsf.org) are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
|
||||
|
||||
[The OpenJS Foundation](https://openjsf.org/) | [Terms of Use](https://terms-of-use.openjsf.org/) | [Privacy Policy](https://privacy-policy.openjsf.org/) | [OpenJS Foundation Bylaws](https://bylaws.openjsf.org/) | [Trademark Policy](https://trademark-policy.openjsf.org/) | [Trademark List](https://trademark-list.openjsf.org/) | [Cookie Policy](https://www.linuxfoundation.org/cookies/)
|
9
ROADMAP.md
Normal file
9
ROADMAP.md
Normal file
@ -0,0 +1,9 @@
|
||||
# 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
|
@ -2,89 +2,98 @@
|
||||
|
||||
# bash completion for Node Version Manager (NVM)
|
||||
|
||||
__nvm_generate_completion()
|
||||
{
|
||||
if ! command -v nvm &> /dev/null; then
|
||||
return
|
||||
fi
|
||||
|
||||
__nvm_generate_completion() {
|
||||
declare current_word
|
||||
current_word="${COMP_WORDS[COMP_CWORD]}"
|
||||
COMPREPLY=($(compgen -W "$1" -- "$current_word"))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
|
||||
return 0
|
||||
}
|
||||
|
||||
__nvm_commands ()
|
||||
{
|
||||
__nvm_commands() {
|
||||
declare current_word
|
||||
declare command
|
||||
|
||||
current_word="${COMP_WORDS[COMP_CWORD]}"
|
||||
|
||||
COMMANDS='\
|
||||
help install uninstall use run\
|
||||
ls ls-remote list list-remote deactivate\
|
||||
alias unalias copy-packages clear-cache version'
|
||||
COMMANDS='
|
||||
help install uninstall use run exec
|
||||
alias unalias reinstall-packages
|
||||
current list ls list-remote ls-remote
|
||||
install-latest-npm
|
||||
cache deactivate unload
|
||||
version version-remote which'
|
||||
|
||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||
if [ ${#COMP_WORDS[@]} == 4 ]; then
|
||||
|
||||
command="${COMP_WORDS[COMP_CWORD-2]}"
|
||||
case "${command}" in
|
||||
alias) __nvm_installed_nodes ;;
|
||||
esac
|
||||
command="${COMP_WORDS[COMP_CWORD - 2]}"
|
||||
case "${command}" in
|
||||
alias) __nvm_installed_nodes ;;
|
||||
esac
|
||||
|
||||
else
|
||||
else
|
||||
|
||||
case "${current_word}" in
|
||||
-*) __nvm_options ;;
|
||||
*) __nvm_generate_completion "$COMMANDS" ;;
|
||||
esac
|
||||
case "${current_word}" in
|
||||
-*) __nvm_options ;;
|
||||
*) __nvm_generate_completion "${COMMANDS}" ;;
|
||||
esac
|
||||
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
__nvm_options ()
|
||||
{
|
||||
__nvm_options() {
|
||||
OPTIONS=''
|
||||
__nvm_generate_completion "$OPTIONS"
|
||||
__nvm_generate_completion "${OPTIONS}"
|
||||
}
|
||||
|
||||
__nvm_installed_nodes ()
|
||||
{
|
||||
__nvm_installed_nodes() {
|
||||
__nvm_generate_completion "$(nvm_ls) $(__nvm_aliases)"
|
||||
}
|
||||
|
||||
__nvm_aliases ()
|
||||
{
|
||||
__nvm_aliases() {
|
||||
declare aliases
|
||||
aliases=""
|
||||
if [ -d $NVM_DIR/alias ]; then
|
||||
aliases="`cd $NVM_DIR/alias && ls`"
|
||||
if [ -d "${NVM_DIR}/alias" ]; then
|
||||
aliases="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
|
||||
fi
|
||||
echo "${aliases}"
|
||||
echo "${aliases} node stable unstable iojs"
|
||||
}
|
||||
|
||||
__nvm_alias ()
|
||||
{
|
||||
__nvm_alias() {
|
||||
__nvm_generate_completion "$(__nvm_aliases)"
|
||||
}
|
||||
|
||||
__nvm ()
|
||||
{
|
||||
__nvm() {
|
||||
declare previous_word
|
||||
previous_word="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
previous_word="${COMP_WORDS[COMP_CWORD - 1]}"
|
||||
|
||||
case "$previous_word" in
|
||||
use|run|ls|list|uninstall) __nvm_installed_nodes ;;
|
||||
alias|unalias) __nvm_alias ;;
|
||||
*) __nvm_commands ;;
|
||||
case "${previous_word}" in
|
||||
use | run | exec | ls | list | uninstall) __nvm_installed_nodes ;;
|
||||
alias | unalias) __nvm_alias ;;
|
||||
*) __nvm_commands ;;
|
||||
esac
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# complete is a bash builtin, but recent versions of ZSH come with a function
|
||||
# called bashcompinit that will create a complete in ZSH. If the user is in
|
||||
# complete is a bash builtin, but recent versions of ZSH come with a function
|
||||
# called bashcompinit that will create a complete in ZSH. If the user is in
|
||||
# ZSH, load and run bashcompinit before calling the complete function.
|
||||
if [[ -n ${ZSH_VERSION-} ]]; then
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
# First calling compinit (only if not called yet!)
|
||||
# and then bashcompinit as mentioned by zsh man page.
|
||||
if ! command -v compinit > /dev/null; then
|
||||
autoload -U +X compinit && if [[ ${ZSH_DISABLE_COMPFIX-} = true ]]; then
|
||||
compinit -u
|
||||
else
|
||||
compinit
|
||||
fi
|
||||
fi
|
||||
autoload -U +X bashcompinit && bashcompinit
|
||||
fi
|
||||
|
||||
complete -o default -o nospace -F __nvm nvm
|
||||
|
||||
complete -o default -F __nvm nvm
|
||||
|
533
install.sh
533
install.sh
@ -1,130 +1,463 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
{ # this ensures the entire script is downloaded #
|
||||
|
||||
has() {
|
||||
nvm_has() {
|
||||
type "$1" > /dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
if [ -z "$NVM_DIR" ]; then
|
||||
NVM_DIR="$HOME/.nvm"
|
||||
fi
|
||||
nvm_echo() {
|
||||
command printf %s\\n "$*" 2>/dev/null
|
||||
}
|
||||
|
||||
if ! has "curl"; then
|
||||
if has "wget"; then
|
||||
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_echo "v0.39.0"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
local TEST_PROFILE
|
||||
TEST_PROFILE="${1-}"
|
||||
case "${TEST_PROFILE-}" in
|
||||
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
|
||||
return
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
#
|
||||
# Outputs the location to NVM depending on:
|
||||
# * The availability of $NVM_SOURCE
|
||||
# * The method used ("script" or "git" in the script, defaults to "git")
|
||||
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
|
||||
#
|
||||
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
|
||||
NVM_METHOD="$1"
|
||||
local NVM_SOURCE_URL
|
||||
NVM_SOURCE_URL="$NVM_SOURCE"
|
||||
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
|
||||
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_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
|
||||
if [ "_$NVM_METHOD" = "_script" ]; then
|
||||
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm.sh"
|
||||
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
|
||||
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
|
||||
else
|
||||
nvm_echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
nvm_echo "$NVM_SOURCE_URL"
|
||||
}
|
||||
|
||||
#
|
||||
# Node.js version to install
|
||||
#
|
||||
nvm_node_version() {
|
||||
nvm_echo "$NODE_VERSION"
|
||||
}
|
||||
|
||||
nvm_download() {
|
||||
if nvm_has "curl"; then
|
||||
curl --fail --compressed -q "$@"
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
curl() {
|
||||
ARGS="$* "
|
||||
ARGS=${ARGS/-s /-q }
|
||||
ARGS=${ARGS/-o /-O }
|
||||
wget $ARGS
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
install_from_git() {
|
||||
if [ -z "$NVM_SOURCE" ]; then
|
||||
NVM_SOURCE="https://github.com/creationix/nvm.git"
|
||||
fi
|
||||
|
||||
if [ -d "$NVM_DIR/.git" ]; then
|
||||
echo "=> nvm is already installed in $NVM_DIR, trying to update"
|
||||
echo -e "\r=> \c"
|
||||
cd "$NVM_DIR" && git pull 2> /dev/null || {
|
||||
echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.."
|
||||
}
|
||||
else
|
||||
# Cloning to $NVM_DIR
|
||||
echo "=> Downloading nvm from git to '$NVM_DIR'"
|
||||
echo -e "\r=> \c"
|
||||
mkdir -p "$NVM_DIR"
|
||||
git clone "$NVM_SOURCE" "$NVM_DIR"
|
||||
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/--compressed //' \
|
||||
-e 's/--fail //' \
|
||||
-e 's/-L //' \
|
||||
-e 's/-I /--server-response /' \
|
||||
-e 's/-s /-q /' \
|
||||
-e 's/-sS /-nv /' \
|
||||
-e 's/-o /-O /' \
|
||||
-e 's/-C - /-c /')
|
||||
# shellcheck disable=SC2086
|
||||
eval wget $ARGS
|
||||
fi
|
||||
}
|
||||
|
||||
install_as_script() {
|
||||
if [ -z "$NVM_SOURCE" ]; then
|
||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/master/nvm.sh"
|
||||
install_nvm_from_git() {
|
||||
local INSTALL_DIR
|
||||
INSTALL_DIR="$(nvm_install_dir)"
|
||||
local NVM_VERSION
|
||||
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
|
||||
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then
|
||||
# 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
|
||||
|
||||
# Downloading to $NVM_DIR
|
||||
mkdir -p "$NVM_DIR"
|
||||
if [ -d "$NVM_DIR/nvm.sh" ]; then
|
||||
echo "=> nvm is already installed in $NVM_DIR, trying to update"
|
||||
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
|
||||
echo "=> Downloading nvm as script to '$NVM_DIR'"
|
||||
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
|
||||
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
|
||||
command printf '\r=> '
|
||||
mkdir -p "${INSTALL_DIR}"
|
||||
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
|
||||
# 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
|
||||
curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
|
||||
echo >&2 "Failed to download '$NVM_SOURCE'.."
|
||||
# Try to fetch tag
|
||||
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$NVM_VERSION" --depth=1 2>/dev/null; then
|
||||
:
|
||||
# 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 --no-pager --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
|
||||
command git --no-pager --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 --no-pager --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
|
||||
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() {
|
||||
local INSTALL_DIR
|
||||
INSTALL_DIR="$(nvm_install_dir)"
|
||||
local NVM_SOURCE_LOCAL
|
||||
NVM_SOURCE_LOCAL="$(nvm_source script)"
|
||||
local NVM_EXEC_SOURCE
|
||||
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
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
if [ -f "$INSTALL_DIR/nvm.sh" ]; then
|
||||
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"
|
||||
else
|
||||
nvm_echo "=> Downloading nvm as script to '$INSTALL_DIR'"
|
||||
fi
|
||||
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
|
||||
nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
|
||||
return 1
|
||||
} &
|
||||
nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
|
||||
nvm_echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
|
||||
return 2
|
||||
} &
|
||||
nvm_download -s "$NVM_BASH_COMPLETION_SOURCE" -o "$INSTALL_DIR/bash_completion" || {
|
||||
nvm_echo >&2 "Failed to download '$NVM_BASH_COMPLETION_SOURCE'"
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
if [ -z "$METHOD" ]; then
|
||||
# Autodetect install method
|
||||
if has "git"; then
|
||||
install_from_git
|
||||
elif has "curl"; then
|
||||
install_as_script
|
||||
nvm_try_profile() {
|
||||
if [ -z "${1-}" ] || [ ! -f "${1}" ]; then
|
||||
return 1
|
||||
fi
|
||||
nvm_echo "${1}"
|
||||
}
|
||||
|
||||
#
|
||||
# Detect profile file if not specified as environment variable
|
||||
# (eg: PROFILE=~/.myprofile)
|
||||
# The echo'ed path is guaranteed to be an existing file
|
||||
# Otherwise, an empty string is returned
|
||||
#
|
||||
nvm_detect_profile() {
|
||||
if [ "${PROFILE-}" = '/dev/null' ]; then
|
||||
# the user has specifically requested NOT to have nvm touch their profile
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
|
||||
nvm_echo "${PROFILE}"
|
||||
return
|
||||
fi
|
||||
|
||||
local DETECTED_PROFILE
|
||||
DETECTED_PROFILE=''
|
||||
|
||||
if [ "${SHELL#*bash}" != "$SHELL" ]; then
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
DETECTED_PROFILE="$HOME/.bashrc"
|
||||
elif [ -f "$HOME/.bash_profile" ]; then
|
||||
DETECTED_PROFILE="$HOME/.bash_profile"
|
||||
fi
|
||||
elif [ "${SHELL#*zsh}" != "$SHELL" ]; then
|
||||
if [ -f "$HOME/.zshrc" ]; then
|
||||
DETECTED_PROFILE="$HOME/.zshrc"
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
#
|
||||
# Check whether the user has any globally-installed npm modules in their system
|
||||
# Node, and warn them if so.
|
||||
#
|
||||
nvm_check_global_modules() {
|
||||
local NPM_COMMAND
|
||||
NPM_COMMAND="$(command -v npm 2>/dev/null)" || return 0
|
||||
[ -n "${NVM_DIR}" ] && [ -z "${NPM_COMMAND%%"$NVM_DIR"/*}" ] && return 0
|
||||
|
||||
local NPM_VERSION
|
||||
NPM_VERSION="$(npm --version)"
|
||||
NPM_VERSION="${NPM_VERSION:--1}"
|
||||
[ "${NPM_VERSION%%[!-0-9]*}" -gt 0 ] || return 0
|
||||
|
||||
local NPM_GLOBAL_MODULES
|
||||
NPM_GLOBAL_MODULES="$(
|
||||
npm list -g --depth=0 |
|
||||
command sed -e '/ npm@/d' -e '/ (empty)$/d'
|
||||
)"
|
||||
|
||||
local MODULE_COUNT
|
||||
MODULE_COUNT="$(
|
||||
command printf %s\\n "$NPM_GLOBAL_MODULES" |
|
||||
command sed -ne '1!p' | # Remove the first line
|
||||
wc -l | command tr -d ' ' # Count entries
|
||||
)"
|
||||
|
||||
if [ "${MODULE_COUNT}" != '0' ]; then
|
||||
# shellcheck disable=SC2016
|
||||
nvm_echo '=> You currently have modules installed globally with `npm`. These will no'
|
||||
# shellcheck disable=SC2016
|
||||
nvm_echo '=> longer be linked to the active version of Node when you install a new node'
|
||||
# shellcheck disable=SC2016
|
||||
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"
|
||||
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
|
||||
# shellcheck disable=SC2016
|
||||
nvm_echo '=> `nvm` Nodes), you can remove them from the system Node as follows:'
|
||||
nvm_echo
|
||||
nvm_echo ' $ nvm use system'
|
||||
nvm_echo ' $ npm uninstall -g a_module'
|
||||
nvm_echo
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_do_install() {
|
||||
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; 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
|
||||
if nvm_has git; then
|
||||
install_nvm_from_git
|
||||
elif nvm_has curl || nvm_has wget; then
|
||||
install_nvm_as_script
|
||||
else
|
||||
nvm_echo >&2 'You need git, curl, or wget to install nvm'
|
||||
exit 1
|
||||
fi
|
||||
elif [ "${METHOD}" = 'git' ]; then
|
||||
if ! nvm_has git; then
|
||||
nvm_echo >&2 "You need git to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
install_nvm_from_git
|
||||
elif [ "${METHOD}" = 'script' ]; then
|
||||
if ! nvm_has curl && ! nvm_has wget; then
|
||||
nvm_echo >&2 "You need curl or wget to install nvm"
|
||||
exit 1
|
||||
fi
|
||||
install_nvm_as_script
|
||||
else
|
||||
echo >&2 "You need git, curl or wget to install nvm"
|
||||
nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$METHOD" = "git" ]; then
|
||||
if ! has "git"; then
|
||||
echo >&2 "You need git to install nvm"
|
||||
exit 1
|
||||
|
||||
nvm_echo
|
||||
|
||||
local NVM_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"
|
||||
|
||||
# shellcheck disable=SC2016
|
||||
COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n'
|
||||
BASH_OR_ZSH=false
|
||||
|
||||
if [ -z "${NVM_PROFILE-}" ] ; then
|
||||
local TRIED_PROFILE
|
||||
if [ -n "${PROFILE}" ]; then
|
||||
TRIED_PROFILE="${NVM_PROFILE} (as defined in \$PROFILE), "
|
||||
fi
|
||||
install_from_git
|
||||
fi
|
||||
if [ "$METHOD" = "script" ]; then
|
||||
if ! has "curl"; then
|
||||
echo >&2 "You need curl or wget to install nvm"
|
||||
exit 1
|
||||
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
|
||||
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
|
||||
BASH_OR_ZSH=true
|
||||
fi
|
||||
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
|
||||
nvm_echo "=> nvm 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
|
||||
install_as_script
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
|
||||
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
||||
if [ -z "$PROFILE" ]; then
|
||||
if [ -f "$HOME/.bash_profile" ]; then
|
||||
PROFILE="$HOME/.bash_profile"
|
||||
elif [ -f "$HOME/.zshrc" ]; then
|
||||
PROFILE="$HOME/.zshrc"
|
||||
elif [ -f "$HOME/.profile" ]; then
|
||||
PROFILE="$HOME/.profile"
|
||||
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
|
||||
fi
|
||||
|
||||
SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm"
|
||||
# Source nvm
|
||||
# shellcheck source=/dev/null
|
||||
\. "$(nvm_install_dir)/nvm.sh"
|
||||
|
||||
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
||||
if [ -z $PROFILE ]; then
|
||||
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
|
||||
echo "=> Create one of them and run this script again"
|
||||
else
|
||||
echo "=> Profile $PROFILE not found"
|
||||
echo "=> Create it (touch $PROFILE) and run this script again"
|
||||
nvm_check_global_modules
|
||||
|
||||
nvm_install_node
|
||||
|
||||
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
|
||||
echo " OR"
|
||||
echo "=> Append the following line to the correct file yourself:"
|
||||
echo
|
||||
echo " $SOURCE_STR"
|
||||
echo
|
||||
else
|
||||
if ! grep -qc 'nvm.sh' $PROFILE; then
|
||||
echo "=> Appending source string to $PROFILE"
|
||||
echo "" >> "$PROFILE"
|
||||
echo $SOURCE_STR >> "$PROFILE"
|
||||
else
|
||||
echo "=> Source string already in $PROFILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=> Close and reopen your terminal to start using nvm"
|
||||
#
|
||||
# Unsets the various functions defined
|
||||
# during the execution of the install script
|
||||
#
|
||||
nvm_reset() {
|
||||
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
|
||||
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
|
||||
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
|
||||
nvm_do_install nvm_reset nvm_default_install_dir nvm_grep
|
||||
}
|
||||
|
||||
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install
|
||||
|
||||
} # this ensures the entire script is downloaded #
|
||||
|
15
nvm-exec
15
nvm-exec
@ -1,14 +1,15 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$DIR/nvm.sh"
|
||||
# shellcheck disable=SC1090,SC1091
|
||||
\. "$DIR/nvm.sh" --no-use
|
||||
|
||||
if [ -n "$NODE_VERSION" ]; then
|
||||
nvm use $NODE_VERSION || (echo "NODE_VERSION not set" && exit 127)
|
||||
else
|
||||
nvm use || (echo "No .nvmrc file found" && exit 127)
|
||||
nvm use "$NODE_VERSION" > /dev/null || exit 127
|
||||
elif ! nvm use >/dev/null 2>&1; then
|
||||
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
|
||||
exit 127
|
||||
fi
|
||||
|
||||
exec $@
|
||||
|
||||
exec "$@"
|
||||
|
36
package.json
36
package.json
@ -1,33 +1,51 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.5.1",
|
||||
"version": "0.39.0",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "urchin test",
|
||||
"test/fast": "urchin -f test/fast",
|
||||
"test/slow": "urchin -f test/slow"
|
||||
"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/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell",
|
||||
"test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell",
|
||||
"test/installation": "npm run --silent test/installation/node && npm run --silent test/installation/iojs",
|
||||
"test/installation/node": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_node 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",
|
||||
"markdown-link-check": "git ls-files | command grep -E '\\.md$' | xargs -n 1 markdown-link-check -p"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/creationix/nvm.git"
|
||||
"url": "git://github.com/nvm-sh/nvm.git"
|
||||
},
|
||||
"keywords": [
|
||||
"nvm",
|
||||
"node",
|
||||
"iojs",
|
||||
"version",
|
||||
"manager"
|
||||
],
|
||||
"author": "Tim Caswell <tim@creationix.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/creationix/nvm/issues"
|
||||
"url": "https://github.com/nvm-sh/nvm/issues"
|
||||
},
|
||||
"homepage": "https://github.com/creationix/nvm",
|
||||
"homepage": "https://github.com/nvm-sh/nvm",
|
||||
"devDependencies": {
|
||||
"urchin": "~0.0.2"
|
||||
"dockerfile_lint": "^0.3.4",
|
||||
"doctoc": "^2.1.0",
|
||||
"eclint": "^2.8.1",
|
||||
"markdown-link-check": "^3.8.7",
|
||||
"replace": "^1.2.1",
|
||||
"semver": "^7.3.5",
|
||||
"urchin": "^0.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
|
52
rename_test.sh
Executable file
52
rename_test.sh
Executable file
@ -0,0 +1,52 @@
|
||||
#! /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 "$@"
|
103
test/common.sh
Normal file
103
test/common.sh
Normal file
@ -0,0 +1,103 @@
|
||||
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
|
||||
}
|
26
test/fast/Aliases/'nvm alias' should not accept aliases with slashes
Executable file
26
test/fast/Aliases/'nvm alias' should not accept aliases with slashes
Executable file
@ -0,0 +1,26 @@
|
||||
#!/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'"
|
@ -0,0 +1,17 @@
|
||||
#!/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'"
|
@ -0,0 +1,25 @@
|
||||
#!/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'"
|
26
test/fast/Aliases/'nvm unalias' should not accept aliases with slashes
Executable file
26
test/fast/Aliases/'nvm unalias' should not accept aliases with slashes
Executable file
@ -0,0 +1,26 @@
|
||||
#!/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'"
|
@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ../../../nvm.sh
|
||||
[ $(nvm alias test1 | wc -l) = '2' ]
|
@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ../../../nvm.sh
|
||||
[ $(nvm alias | wc -l) = '10' ]
|
@ -0,0 +1,24 @@
|
||||
#!/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'"
|
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
[ $(nvm alias test-stable-1 | wc -l) = '2' ]
|
@ -0,0 +1,26 @@
|
||||
#!/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'"
|
@ -0,0 +1,49 @@
|
||||
#!/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
|
48
test/fast/Aliases/Running 'nvm alias' should list all aliases
Executable file
48
test/fast/Aliases/Running 'nvm alias' should list all aliases
Executable file
@ -0,0 +1,48 @@
|
||||
#!/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'"
|
36
test/fast/Aliases/circular/nvm_resolve_alias
Executable file
36
test/fast/Aliases/circular/nvm_resolve_alias
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
\. ../../../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../../nvm.sh
|
||||
|
||||
ALIAS="$(nvm_resolve_alias loopback | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias loopback was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias loopback | strip_colors)"
|
||||
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_alias one | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias one was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias one | strip_colors)"
|
||||
EXPECTED_OUTPUT="one -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_alias two | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias two was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias two | strip_colors)"
|
||||
EXPECTED_OUTPUT="two -> three (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_alias three | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias three was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias three | strip_colors)"
|
||||
EXPECTED_OUTPUT="three -> one (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_alias four | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_alias four was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias four | strip_colors)"
|
||||
EXPECTED_OUTPUT="four -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"
|
36
test/fast/Aliases/circular/nvm_resolve_local_alias
Executable file
36
test/fast/Aliases/circular/nvm_resolve_local_alias
Executable file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
\. ../../../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../../nvm.sh
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias loopback | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias loopback was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias loopback | strip_colors)"
|
||||
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias one | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias one was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias one | strip_colors)"
|
||||
EXPECTED_OUTPUT="one -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias two | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias two was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias two | strip_colors)"
|
||||
EXPECTED_OUTPUT="two -> three (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias three | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias three was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias three | strip_colors)"
|
||||
EXPECTED_OUTPUT="three -> one (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
|
||||
|
||||
ALIAS="$(nvm_resolve_local_alias four | strip_colors)"
|
||||
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias four was not ∞; got $ALIAS"
|
||||
OUTPUT="$(nvm alias four | strip_colors)"
|
||||
EXPECTED_OUTPUT="four -> two (-> ∞)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"
|
9
test/fast/Aliases/circular/setup
Executable file
9
test/fast/Aliases/circular/setup
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo loopback > ../../../../alias/loopback
|
||||
|
||||
echo two > ../../../../alias/one
|
||||
echo three > ../../../../alias/two
|
||||
echo one > ../../../../alias/three
|
||||
|
||||
echo two > ../../../../alias/four
|
9
test/fast/Aliases/circular/teardown
Executable file
9
test/fast/Aliases/circular/teardown
Executable file
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
rm -f ../../../../alias/loopback
|
||||
|
||||
rm -f ../../../../alias/one
|
||||
rm -f ../../../../alias/two
|
||||
rm -f ../../../../alias/three
|
||||
|
||||
rm -f ../../../../alias/four
|
18
test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists
Executable file
18
test/fast/Aliases/lts/'nvm alias' should ensure LTS alias dir exists
Executable file
@ -0,0 +1,18 @@
|
||||
#!/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"
|
10
test/fast/Aliases/lts/setup_dir
Executable file
10
test/fast/Aliases/lts/setup_dir
Executable file
@ -0,0 +1,10 @@
|
||||
#!/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
|
10
test/fast/Aliases/lts/teardown_dir
Executable file
10
test/fast/Aliases/lts/teardown_dir
Executable file
@ -0,0 +1,10 @@
|
||||
#!/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
|
20
test/fast/Aliases/nvm_ensure_default_set
Executable file
20
test/fast/Aliases/nvm_ensure_default_set
Executable file
@ -0,0 +1,20 @@
|
||||
#!/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"
|
22
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable file
22
test/fast/Aliases/nvm_list_aliases calls nvm_get_colors
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
die () { echo "$@" ; 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 "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
21
test/fast/Aliases/nvm_list_aliases works with no LTS aliases present
Executable file
21
test/fast/Aliases/nvm_list_aliases works with no LTS aliases present
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
die () {
|
||||
mv "$(nvm_alias_path)/_lts.bak" "$(nvm_alias_path)/lts"
|
||||
echo "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
nvm_alias_path() {
|
||||
nvm_echo "../../../alias"
|
||||
}
|
||||
|
||||
mv "$(nvm_alias_path)/lts" "$(nvm_alias_path)/_lts.bak"
|
||||
|
||||
STDERR_OUTPUT="$(nvm_list_aliases 2>&1 >/dev/null)"
|
||||
|
||||
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"
|
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable file
28
test/fast/Aliases/nvm_print_alias_path calls nvm_get_colors
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
die () {
|
||||
# echo "$@" ;
|
||||
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
nvm_get_colors(){
|
||||
echo "0;95m"
|
||||
}
|
||||
|
||||
# nvm_print_alias_path call nvm_print_formatted_alias which calls nvm_get-colors
|
||||
# the output of nvm_print_alias_path uses the color code returned by nvm_get_colors (redefined above)
|
||||
NVM_ALIAS_DIR='../../../alias'
|
||||
|
||||
OUTPUT=$(command printf %b $(nvm_print_alias_path "$NVM_ALIAS_DIR" "$NVM_ALIAS_DIR"/test-stable-1) | awk '{ print substr($0, 1, 24); }')
|
||||
|
||||
EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1\033[0m")
|
||||
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||
|
||||
|
||||
set +e
|
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable file
21
test/fast/Aliases/nvm_print_formatted_alias calls nvm_get_colors
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
die () {
|
||||
echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
# # # expecting in red and two grays:
|
||||
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
|
||||
EXPECTED_OUTPUT="$(command printf %b "\033[0;31mfakealias\033[0m ")"
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
||||
|
||||
# expecting in bold yellow and two grays:
|
||||
nvm set-colors bbbYb
|
||||
OUTPUT=$(echo $(nvm_print_formatted_alias fakealias fakedest) | awk '{ print substr($0, 1, 21); }')
|
||||
EXPECTED_OUTPUT="$(command printf %b "\033[1;33mfakealias\033[0m ")"
|
||||
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
|
33
test/fast/Aliases/nvm_resolve_alias
Executable file
33
test/fast/Aliases/nvm_resolve_alias
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
EXIT_CODE=$(nvm_resolve_alias ; echo $?)
|
||||
[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE"
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
STABLE_ALIAS="$(nvm_resolve_alias test-stable-$i)"
|
||||
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|
||||
|| die "'nvm_resolve_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
|
||||
UNSTABLE_ALIAS="$(nvm_resolve_alias test-unstable-$i)"
|
||||
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|
||||
|| die "'nvm_resolve_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
|
||||
done
|
||||
|
||||
EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?)
|
||||
[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE"
|
||||
|
||||
STABLE="$(nvm_resolve_alias stable)"
|
||||
[ "_$STABLE" = "_v0.0" ] || die "'nvm_resolve_alias stable' was not v0.0; got $STABLE"
|
||||
|
||||
NODE="$(nvm_resolve_alias node)"
|
||||
[ "_$NODE" = "_stable" ] || die "'nvm_resolve_alias node' was not stable; got $NODE"
|
||||
|
||||
UNSTABLE="$(nvm_resolve_alias unstable)"
|
||||
[ "_$UNSTABLE" = "_v0.1" ] || die "'nvm_resolve_alias unstable' was not v0.1; got $UNSTABLE"
|
||||
|
||||
IOJS="$(nvm_resolve_alias iojs)"
|
||||
[ "_$IOJS" = "_iojs-v0.2" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2; got $IOJS"
|
35
test/fast/Aliases/nvm_resolve_local_alias
Executable file
35
test/fast/Aliases/nvm_resolve_local_alias
Executable file
@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
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"
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
STABLE_ALIAS="$(nvm_resolve_local_alias test-stable-$i)"
|
||||
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|
||||
|| die "'nvm_resolve_local_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
|
||||
UNSTABLE_ALIAS="$(nvm_resolve_local_alias test-unstable-$i)"
|
||||
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|
||||
|| die "'nvm_resolve_local_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
|
||||
done
|
||||
|
||||
OUTPUT="$(nvm_resolve_local_alias nonexistent)"
|
||||
EXIT_CODE=$(nvm_resolve_local_alias nonexistent > /dev/null 2>&1 ; echo $?)
|
||||
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_resolve_local_alias nonexistent' did not return 2; got $EXIT_CODE"
|
||||
[ "_$OUTPUT" = "_" ] || die "'nvm_resolve_local_alias nonexistent' did not have empty output; got $OUTPUT"
|
||||
|
||||
STABLE="$(nvm_resolve_local_alias stable)"
|
||||
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias stable' was not v0.0.10; got $STABLE"
|
||||
|
||||
NODE="$(nvm_resolve_local_alias node)"
|
||||
[ "_$NODE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias node' was not v0.0.10; got $NODE"
|
||||
|
||||
UNSTABLE="$(nvm_resolve_local_alias unstable)"
|
||||
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_local_alias unstable' was not v0.1.10; got $UNSTABLE"
|
||||
|
||||
IOJS="$(nvm_resolve_local_alias iojs)"
|
||||
[ "_$IOJS" = "_iojs-v0.2.10" ] || die "'nvm_resolve_local_alias iojs' was not iojs-v0.2.10; got $IOJS"
|
14
test/fast/Aliases/setup
Executable file
14
test/fast/Aliases/setup
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
echo 0.0.$i > ../../../alias/test-stable-$i
|
||||
make_fake_node v0.0.$i
|
||||
echo 0.1.$i > ../../../alias/test-unstable-$i
|
||||
make_fake_node v0.1.$i
|
||||
echo 0.2.$i > ../../../alias/test-iojs-$i
|
||||
make_fake_iojs v0.2.$i
|
||||
done
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
echo v0.0.$i > ../../../alias/test$i
|
||||
done
|
17
test/fast/Aliases/teardown
Executable file
17
test/fast/Aliases/teardown
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
|
||||
for i in $(seq 1 10)
|
||||
do
|
||||
rm -f "../../../alias/test-stable-$i"
|
||||
rm -rf "../../../v0.0.$i"
|
||||
rm -f "../../../alias/test-unstable-$i"
|
||||
rm -rf "../../../v0.1.$i"
|
||||
rm -rf "../../../alias/test-iojs-$i"
|
||||
rm -rf "../../../versions/io.js/v0.2.$i"
|
||||
done
|
||||
|
||||
rm -f "../../../alias/stable"
|
||||
rm -f "../../../alias/unstable"
|
||||
rm -f "../../../alias/node"
|
||||
rm -f "../../../alias/iojs"
|
||||
rm -f "../../../alias/default"
|
@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.0.2
|
||||
make_fake_node v0.0.20
|
||||
make_fake_node v0.12.0
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
|
||||
nvm which 0.0.2 || die "v0.0.2 not found"
|
||||
NVM_BIN="$(nvm which 0.0.2)"
|
||||
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.2)/bin/node" ] \
|
||||
|| die "'nvm which 0.0.2' did not contain the correct path: got '$NVM_BIN'"
|
||||
|
||||
nvm which 0.0.20 || die "v0.0.20 not found"
|
||||
NVM_BIN="$(nvm which 0.0.20)"
|
||||
[ "_$NVM_BIN" = "_$(nvm_version_path v0.0.20)/bin/node" ] \
|
||||
|| die "'nvm which 0.20.0' did not contain the correct path: got '$NVM_BIN'"
|
||||
|
||||
nvm which 0.12.0 || die "v0.0.20 not found"
|
||||
NVM_BIN="$(nvm which 0.12.0)"
|
||||
[ "_$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'"
|
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm which nonexistent_version
|
||||
[ "_$?" = "_1" ]
|
3
test/fast/Listing paths/teardown
Executable file
3
test/fast/Listing paths/teardown
Executable file
@ -0,0 +1,3 @@
|
||||
rm -rf ../../../v0.0.2
|
||||
rm -rf ../../../v0.0.20
|
||||
rm -rf ../../../v0.12.0
|
@ -1,12 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
mkdir ../../../v0.1.3
|
||||
mkdir ../../../v0.2.3
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
nvm ls 0.2 | grep v0.2.3 &&
|
||||
nvm ls 0.1 | grep -v v0.2.3 &&
|
||||
nvm ls 0.1 | grep v0.1.3 &&
|
||||
nvm ls v0.2 | grep v0.2.3
|
@ -1,18 +0,0 @@
|
||||
#!/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
|
||||
|
||||
# The result should contain the version numbers.
|
||||
nvm ls | grep v0.0.1 &&
|
||||
nvm ls | grep v0.0.3 &&
|
||||
nvm ls | grep v0.0.9 &&
|
||||
nvm ls | grep v0.3.1 &&
|
||||
nvm ls | grep v0.3.3 &&
|
||||
nvm ls | grep v0.3.9
|
@ -0,0 +1,34 @@
|
||||
#!/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}<"
|
15
test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors
Executable file
15
test/fast/Listing versions/Running 'nvm ls --no-alias' with a pattern errors
Executable file
@ -0,0 +1,15 @@
|
||||
#!/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}<"
|
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.0.2
|
||||
make_fake_node v0.0.20
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
|
||||
nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '"nvm ls 0.0.2" contained v0.0.2'
|
||||
fi
|
||||
|
||||
nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
die '"nvm ls 0.0.2" contained v0.0.20'
|
||||
fi
|
@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.1.3
|
||||
make_fake_node v0.2.3
|
||||
make_fake_node v0.20.3
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
# The result should contain only the appropriate version numbers.
|
||||
|
||||
nvm ls 0.1 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo '"nvm ls 0.1" contained v0.2.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.1 | grep 'v0.20.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
die '"nvm ls 0.1" contained v0.20.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.1 | grep 'v0.1.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.1" did not contain v0.1.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.2" did not contain v0.2.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.20.3' > /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
die '"nvm ls 0.2" contained v0.20.3'
|
||||
fi
|
||||
|
||||
nvm ls 0.2 | grep 'v0.2.3' > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
die '"nvm ls 0.2" did not contain v0.2.3'
|
||||
fi
|
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm ls nonexistent_version
|
||||
[ "$?" = "3" ]
|
6
test/fast/Listing versions/Running 'nvm ls io' should return NA
Executable file
6
test/fast/Listing versions/Running 'nvm ls io' should return NA
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm ls io
|
||||
[ "$?" = "3" ]
|
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm ls node_
|
||||
[ "$?" = "3" ]
|
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
make_fake_node v0.2.3
|
||||
make_fake_node v0.3.3
|
||||
|
||||
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")"
|
||||
|
||||
nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \
|
||||
|| die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)"
|
||||
|
||||
nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \
|
||||
|| die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)"
|
||||
|
||||
make_fake_node v0.1.4
|
||||
nvm alias stable 0.1
|
||||
|
||||
nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \
|
||||
|| die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.4"
|
||||
nvm ls stable | \grep v0.1.4 >/dev/null \
|
||||
|| die "'nvm ls stable' did not contain v0.1.4"
|
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../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
|
||||
|
||||
nvm_has_system_node() { return 0; }
|
||||
nvm ls system | grep system 2>&1 > /dev/null
|
||||
[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present'
|
||||
|
||||
nvm_has_system_node() { return 1; }
|
||||
nvm ls system | grep system 2>&1 > /dev/null
|
||||
[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present'
|
35
test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias
Executable file
35
test/fast/Listing versions/Running 'nvm ls' calls into nvm_alias
Executable file
@ -0,0 +1,35 @@
|
||||
#!/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}<"
|
@ -0,0 +1,44 @@
|
||||
#!/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}<"
|
10
test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm'
Executable file
10
test/fast/Listing versions/Running 'nvm ls' should filter out '.nvm'
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.1.3
|
||||
make_fake_node v0.2.3
|
||||
|
||||
[ -z `nvm ls | grep '^ *\.'` ]
|
||||
# The result should contain only the appropriate version numbers.
|
10
test/fast/Listing versions/Running 'nvm ls' should filter out 'versions'
Executable file
10
test/fast/Listing versions/Running 'nvm ls' should filter out 'versions'
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.1.3
|
||||
make_fake_node v0.2.3
|
||||
|
||||
[ -z "$(nvm ls | \grep 'versions')" ]
|
||||
# The result should contain only the appropriate version numbers.
|
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../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
|
||||
|
||||
nvm_has_system_node() { return 0; }
|
||||
nvm ls | grep system 2>&1 > /dev/null
|
||||
[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present'
|
||||
|
||||
nvm_has_system_node() { return 1; }
|
||||
nvm ls | grep system 2>&1 > /dev/null
|
||||
[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'
|
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.12.1
|
||||
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.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory'
|
40
test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash
Executable file
40
test/fast/Listing versions/Running 'nvm ls' should not show a trailing slash
Executable file
@ -0,0 +1,40 @@
|
||||
#!/bin/zsh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
if type setopt >/dev/null 2>&1; then setopt local_options markdirs; fi
|
||||
|
||||
die () {
|
||||
if type unsetopt >/dev/null 2>&1; then unsetopt local_options markdirs; fi
|
||||
echo "$@";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
make_fake_node v0.0.1
|
||||
make_fake_node v0.0.3
|
||||
make_fake_node v0.0.9
|
||||
make_fake_node v0.3.1
|
||||
make_fake_node v0.3.3
|
||||
make_fake_node v0.3.9
|
||||
make_fake_node v0.12.87
|
||||
make_fake_node v0.12.9
|
||||
make_fake_iojs v0.1.2
|
||||
make_fake_iojs v0.10.2
|
||||
|
||||
OUTPUT="$(nvm_ls)"
|
||||
EXPECTED_OUTPUT="v0.0.1
|
||||
v0.0.3
|
||||
v0.0.9
|
||||
iojs-v0.1.2
|
||||
v0.3.1
|
||||
v0.3.3
|
||||
v0.3.9
|
||||
iojs-v0.10.2
|
||||
v0.12.9
|
||||
v0.12.87"
|
||||
if nvm_has_system_node || nvm_has_system_iojs; then
|
||||
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
|
||||
system"
|
||||
fi
|
||||
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
make_fake_node v0.1.2
|
||||
|
||||
nvm ls v0.1 | 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.1 | grep N/A
|
23
test/fast/Listing versions/Running 'nvm ls' with nounset should not fail
Executable file
23
test/fast/Listing versions/Running 'nvm ls' with nounset should not fail
Executable file
@ -0,0 +1,23 @@
|
||||
#!/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}"
|
19
test/fast/Listing versions/Using a nonstandard IFS should not break
Executable file
19
test/fast/Listing versions/Using a nonstandard IFS should not break
Executable file
@ -0,0 +1,19 @@
|
||||
#!/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
|
16
test/fast/Listing versions/teardown
Executable file
16
test/fast/Listing versions/teardown
Executable file
@ -0,0 +1,16 @@
|
||||
rm -rf ../../../v0.0.1
|
||||
rm -rf ../../../v0.0.2
|
||||
rm -rf ../../../v0.0.3
|
||||
rm -rf ../../../v0.0.9
|
||||
rm -rf ../../../v0.0.20
|
||||
rm -rf ../../../v0.1.2
|
||||
rm -rf ../../../v0.1.3
|
||||
rm -rf ../../../v0.1.4
|
||||
rm -rf ../../../v0.2.3
|
||||
rm -rf ../../../v0.3.1
|
||||
rm -rf ../../../v0.3.3
|
||||
rm -rf ../../../v0.3.9
|
||||
rm -rf ../../../v0.20.3
|
||||
rm -rf ../../../versions
|
||||
rm -f ../../../alias/stable
|
||||
rm -f ../../../alias/unstable
|
@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
. ../../nvm.sh
|
||||
nvm alias test v0.1.2
|
||||
[ "$(cat ../../alias/test)" = "v0.1.2" ]
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../nvm.sh
|
||||
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version"
|
@ -1,14 +0,0 @@
|
||||
#!/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 &&
|
||||
[ `expr $PATH : ".*v0.2.3/.*/bin"` != 0 ] || die "Failed to activate v0.2.3"
|
||||
|
||||
nvm deactivate &&
|
||||
[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || die "Failed to deactivate v0.2.3"
|
@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo v0.1.2 > ../../alias/test
|
||||
. ../../nvm.sh
|
||||
nvm unalias test
|
||||
! [ -e ../../alias/test ]
|
@ -1,10 +0,0 @@
|
||||
#!/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' ]
|
@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm alias test v0.1.2
|
||||
|
||||
[ "$(cat "$(nvm_alias_path)/test")" = "v0.1.2" ]
|
11
test/fast/Running 'nvm current' should display current nvm environment
Executable file
11
test/fast/Running 'nvm current' should display current nvm environment
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm deactivate 2>&1
|
||||
|
||||
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'
|
@ -0,0 +1,23 @@
|
||||
#!/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'"
|
@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
cleanup () {
|
||||
rm -rf "${NVM_DIR}/v0.10.4"
|
||||
}
|
||||
|
||||
\. ../../nvm.sh
|
||||
\. ../common.sh
|
||||
|
||||
make_fake_node v0.10.4
|
||||
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
|
||||
set +ex # needed for stderr
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)"
|
||||
set -ex
|
||||
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'"
|
||||
|
||||
set +e # TODO: fix
|
||||
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)"
|
||||
set -e
|
||||
[ $INSTALL_EXIT_CODE -eq 5 ] \
|
||||
|| die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got ${INSTALL_EXIT_CODE}"
|
||||
|
||||
set +ex # needed for stderr
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)"
|
||||
set -ex
|
||||
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'"
|
||||
|
||||
set +e # TODO: fix
|
||||
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"
|
||||
set -e
|
||||
[ $INSTALL_EXIT_CODE -eq 4 ] \
|
||||
|| die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"
|
||||
|
||||
set +ex # needed for stderr
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from 2>&1)"
|
||||
set -ex
|
||||
EXPECTED_ERROR_MSG='If --reinstall-packages-from is provided, it must point to an installed version of node using `=`.'
|
||||
[ "~$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'"
|
||||
|
||||
set +ex # needed for stderr
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from= 2>&1)"
|
||||
set -ex
|
||||
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'"
|
||||
|
||||
cleanup
|
13
test/fast/Running 'nvm install' with an invalid version fails nicely
Executable file
13
test/fast/Running 'nvm install' with an invalid version fails nicely
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
set +ex # needed for stderr
|
||||
OUTPUT="$(nvm install invalid.invalid 2>&1)"
|
||||
set -ex
|
||||
EXPECTED_OUTPUT="Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions."
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm installing an invalid version did not print a nice error message"
|
13
test/fast/Running 'nvm unalias' should remove the alias file
Executable file
13
test/fast/Running 'nvm unalias' should remove the alias file
Executable file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
ALIAS_PATH="../../alias"
|
||||
|
||||
echo v0.1.2 > "${ALIAS_PATH}/test"
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm unalias test
|
||||
|
||||
! [ -e "${ALIAS_PATH}/test" ]
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user