Compare commits

..

No commits in common. "master" and "v0.17.2" have entirely different histories.

388 changed files with 2142 additions and 20284 deletions

View File

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

View File

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

1
.gitattributes vendored
View File

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

12
.github/FUNDING.yml vendored
View File

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

View File

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

View File

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

27
.github/SECURITY.md vendored
View File

@ -1,27 +0,0 @@
# Security
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
## OpenSSF CII Best Practices
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684)
There are three “tiers”: passing, silver, and gold.
### Passing
We meet 100% of the “passing” criteria.
### Silver
We meet 95% of the “silver” criteria. The gaps are as follows:
- we do not have a DCO or a CLA process for contributions.
- because we only have one maintainer, the project has no way to continue if that maintainer stops being active.
- we do not currently document “what the user can and cannot expect in terms of security” for our project. This is planned to be completed in 2023.
### Gold
We meet 65% of the “gold” criteria. The gaps are as follows:
- we do not yet have the “silver” badge; see all the gaps above.
- We do not include a copyright or license statement in each source file. Efforts are underway to change this archaic practice into a suggestion instead of a hard requirement.
## Threat Model
See [THREAT_MODEL.md](./THREAT_MODEL.md).

View File

@ -1,109 +0,0 @@
# `nvm` Threat Model
## Introduction
Threat model analysis assists organizations to proactively identify potential security threats and vulnerabilities, enabling them to develop effective strategies to mitigate these risks before they are exploited by attackers.
Furthermore, this often helps to improve the overall security and resilience of a system or application.
The aim of this section is to facilitate the identification of potential security threats and vulnerabilities that may be exploited by adversaries, along with possible outcomes and appropriate mitigations.
## Relevant assets and threat actors
The following assets are considered important for the `nvm` project:
- `nvm` source code and project documentation
- Underlying `nvm` dependencies
- `nvm` development infrastructure
- `nvm` installed devices including servers
The following threat actors are considered relevant to the `nvm` application:
- External malicious attackers
- Internal malicious attackers
- Services
- Malicious insider actors
- Third-party libraries
## Attack surface for external/internal attackers and services
In threat modeling, an attack surface refers to any possible point of entry that an attacker might use to exploit a system or application.
This includes all the paths and interfaces that an attacker may use to access, manipulate or extract sensitive data from a system.
By understanding the attack surface, organizations are typically able to identify potential attack vectors and implement appropriate countermeasures to mitigate risks.
In the following diagrams, _External Malicious Attacker_ applies to threat actors who do not yet have direct access to the `nvm` application and the underlying operating system, while the _Internal Malicious Attacker_ applies to an attacker with access to the device (computer, server), potentially after successfully exploiting a threat from the _External Malicious Attacker_ scenario.
**Please note that some of the external threats may be also exploitable from internal threats and vice versa.**
<img src="./external-threat-actor.png" alt="Fig.: Possible attacks from internal and external threat actors and services" />
Fig.: Possible attacks from internal and external threat actors and services
## Identified threats
The identified threats against the `nvm` application are as follows:
### Threat ID 1: `nvm` commands
Overview: The `nvm` commands and subcommands take user input for handling and executing appropriate functions from the project directory (or any parent directory).
When user-controlled inputs are not adequately validated and later passed to the `nvm` functions as a part of a command, an attacker might be able to execute operating system commands triggered by any parsing functionality.
Possible Outcome: Attacks against `nvm` commands could lead to unauthorized access to user data or unauthorized access to the device (i.e. laptop or server, depending on where `nvm` is installed), resulting in loss of user private data stored on the device, among other possibilities.
Recommendation: Input validation should be implemented to prevent attackers from requesting operating system commands.
Similarly, secure coding practices ought to be in place to minimize the risk of buffer overflow vulnerabilities.
### Threat ID 2: URI scheme
Overview: `nvm` commands heavily use the [Secure HyperText Transfer](https://datatracker.ietf.org/doc/html/rfc2660) protocol for `nvm` related actions.
Missing [scheme](https://datatracker.ietf.org/doc/html/rfc3986#section-3.1) validation for any `nvm` command might result in file retrieval, enumeration, file overwrite, or [path traversal](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/05-Authorization_Testing/01-Testing_Directory_Traversal_File_Include) attacks.
An example of this could be path validation for [`nvm_download`](https://github.com/nvm-sh/nvm/blob/ef7fc2f2c06ad75fe7fbabf28d427561ae7b007d/nvm.sh#L118), among many other possibilities.
Possible Outcome: Security misconfiguration flaws for URI scheme may lead to unauthorized access to user data, as well as data integrity compromises.
Recommendation: Adequate input validation should be implemented to prevent attackers from enumerating, retrieving and writing to application files and paths.
### Threat ID 3: Communication channel
Overview: The `nvm` commands and its subcommands use network protocol to communicate with external services.
Insecure communication may allow malicious attackers to perform [_Man-in-the-Middle_](https://owasp.org/www-community/attacks/Manipulator-in-the-middle_attack) attacks in order to manipulate the data sent during the users active connection.
Possible Outcome: Usage of plaintext communication protocols, like HTTP could lead to data sniffing and modification through insecure communications channels.
Recommendation: Mitigation countermeasures such as data encryption should be in place to prevent data manipulation via insecure communication channels.
### Threat ID 4: Environment variables
Overview: Each `nvm` installation defines its environment variables, which should be secured from internal malicious attackers, preventing access control attack vectors.
Missing stringent restrictions on setting variables, might allow attackers to prepare various targeted attacks against other local users, who use `nvm` in their user space.
For example, [_Privilege Escalation_](https://owasp.org/Top10/A01_2021-Broken_Access_Control/), [_Command Injection_](https://cwe.mitre.org/data/definitions/77.html), as well as many other parser-related attacks.
Possible Outcome: Attacks against environment variables could lead to unauthorized access to the user space, resulting in the loss of user private data and disruptions in service availability.
Recommendation: Adequate hardening of configuration file permissions should be in place for all relevant configuration files, as this provides protection against attackers able to manipulate variables and inject malicious code.
## Attack surface for malicious insider actors and third-party libraries
The following diagram summarizes the main possible threats against the `nvm` project from malicious insider actors and third-party libraries:
<img src="./insider-threat-actor-and-libs.png" alt="Fig.: Possible attacks from insider threat actors and third-party libraries" />
Fig.: Possible attacks from insider threat actors and third-party libraries
The identified threats against the `nvm` project are as follows:
### Threat ID 1: Insider threat actor
**Overview**: An insider threat actor, such as an `nvm` project contributor or employee with access to the code base, might abuse their role in the organization to modify the `nvm` application source code.
For example, intentionally adding malicious code snippets, clearing logs after being written and/or modifying specific sections of the documentation.
**Possible Outcome**: Reputation damage, financial losses.
**Recommendation**: Secure coding practices, code reviews, automated code scanning and separation of duties (i.e. requiring at least two developers to approve any code change) are potentially useful security controls to identify and mitigate vulnerabilities that may be introduced by an insider threat actor.
### Threat ID 2: Third-party libraries
**Overview**: Please note that while `nvm` does not currently make use of any third-party libraries, this might become an attack vector if that changes in the future.
Third-party libraries may introduce potential risks related to maintaining security requirements by third-party vendors.
As a result, third-party libraries used by the `nvm` project, might contain vulnerabilities, such as [_Buffer Overflows_](https://owasp.org/www-community/vulnerabilities/Buffer_Overflow), [_Format String Vulnerabilities_](https://owasp.org/www-community/attacks/Format_string_attack), as well as many other types of weaknesses that, in a worst-case scenario may lead to _Remote Code Execution_ (_RCE_).
Additionally, the maintainer of a third-party dependency might introduce a vulnerability on purpose, or be compromised by an attacker that subsequently introduces vulnerable code.
**Possible Outcome**: Code vulnerabilities may lead to unauthorized access to user data, loss of user private data, service disruptions and reputation damage.
**Recommendation**: Third-party libraries should be kept up-to-date, applying patches to address publicly known vulnerabilities in a timely fashion.
Monitoring and logging capabilities should also be in place to detect and respond to potential attacks.
SLSA compliance may also be considered for further supply chain security hardening.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

View File

@ -1,86 +0,0 @@
name: 'Tests: `nvm install-latest-npm`'
on: [pull_request, push]
permissions:
contents: read
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
latest: ${{ steps.set-matrix.outputs.requireds }}
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
iojs.org:443
nodejs.org:443
raw.githubusercontent.com: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: "21"
- node-version: "20.5"
- node-version: "20.4"
- node-version: "14.17"
- node-version: "14.16"
- 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@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
iojs.org:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v4
- uses: ljharb/actions/node/install@main
name: 'install node'
with:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
skip-install: true
skip-latest-npm: true
- run: npm --version
- run: '. ./nvm.sh ; nvm install-latest-npm'
name: 'nvm install-latest-npm'
- run: npm --version
node:
permissions:
contents: none
name: 'nvm install-latest-npm'
needs: [nodes]
runs-on: ubuntu-latest
steps:
- run: true

View File

@ -1,72 +0,0 @@
name: 'Tests: linting'
on: [pull_request, push]
permissions:
contents: read
jobs:
eclint:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v4
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: 'lts/*'
- run: npm run eclint
dockerfile_lint:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
ghcr.io:443
github.com:443
raw.githubusercontent.com:443
pkg-containers.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v4
- uses: ljharb/actions/node/install@main
name: 'nvm install ${{ matrix.node-version }} && npm install'
with:
node-version: 'lts/*'
- run: npm run dockerfile_lint
doctoc:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
nodejs.org:443
registry.npmjs.org:443
- uses: actions/checkout@v4
- 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:
runs-on: ubuntu-latest
steps:
- uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
raw.githubusercontent.com:443
- uses: actions/checkout@v4
- name: check tests filenames
run: ./rename_test.sh --check

View File

@ -1,104 +0,0 @@
name: 'Tests: nvm install with set -e'
on:
pull_request:
push:
workflow_dispatch:
inputs:
ref:
description: 'git ref to use'
required: false
default: 'HEAD'
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: matrix
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.ref }}" ]; then
echo "matrix=\"[\"${{ github.event.inputs.ref }}\"]\"" >> $GITHUB_OUTPUT
else
TAGS="$((echo "HEAD" && git tag --sort=-v:refname --merged HEAD --format='%(refname:strip=2) %(creatordate:short)' | grep '^v' | while read tag date; do
if [ "$(uname)" == "Darwin" ]; then
timestamp=$(date -j -f "%Y-%m-%d" "$date" +%s)
threshold=$(date -j -v-4y +%s)
else
timestamp=$(date -d "$date" +%s)
threshold=$(date -d "4 years ago" +%s)
fi
if [ $timestamp -ge $threshold ]; then echo "$tag"; fi
done) | xargs)"
echo $TAGS
TAGS_JSON=$(printf "%s\n" $TAGS | jq -R . | jq -sc .)
echo "matrix=${TAGS_JSON}" >> $GITHUB_OUTPUT
fi
test:
needs: [matrix]
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.ref == 'v0.40.0' }} # https://github.com/nvm-sh/nvm/issues/3405
strategy:
fail-fast: false
matrix:
ref: ${{ fromJson(needs.matrix.outputs.matrix) }}
has-nvmrc:
- 'no nvmrc'
- 'nvmrc'
shell-level:
- 1 shlvl
- 2 shlvls
steps:
- uses: actions/checkout@v4
- name: resolve HEAD to sha
run: |
if [ '${{ matrix.ref }}' = 'HEAD' ]; then
REF="$(git rev-parse HEAD)"
else
REF="${{ matrix.ref }}"
fi
echo "resolved ref: ${REF}"
echo "ref="$REF"" >> $GITHUB_ENV
- run: echo $- # which options are set
- run: echo node > .nvmrc
if: ${{ matrix.has-nvmrc == 'nvmrc' }}
- run: curl -I --compressed -v https://nodejs.org/dist/
- name: 'install nvm'
run: |
set -e
export NVM_INSTALL_VERSION="${ref}"
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${ref}/install.sh" | bash
- name: nvm --version
run: |
set +e
. $NVM_DIR/nvm.sh && nvm --version
- name: nvm install in 1 shell level, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '1 shlvl' }}
run: |
set -ex
. $NVM_DIR/nvm.sh
echo nvm.sh sourced
nvm --version
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
nvm install
fi
- name: nvm install in 2 shell levels, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '2 shlvls' }}
run: |
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version && nvm install"
else
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version"
fi
finisher:
runs-on: ubuntu-latest
needs: [test]
steps:
- run: true

View File

@ -1,26 +0,0 @@
name: Automatic Rebase
on: [pull_request_target]
permissions:
contents: read
jobs:
_:
permissions:
contents: write
name: "Automatic Rebase"
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
api.github.com:443
github.com:443
- uses: actions/checkout@v4
- uses: ljharb/rebase@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,38 +0,0 @@
name: 'Tests: release process'
on: [pull_request, push]
permissions:
contents: read
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
api.github.com:443
objects.githubusercontent.com:443
raw.githubusercontent.com:443
registry.npmjs.org:443
- uses: actions/checkout@v4
with:
fetch-tags: true
- uses: actions/setup-node@v4
with:
node-version: "14"
- run: npm install
- name: Configure git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git fetch --unshallow --tags -f || git fetch --tags -f
- name: Attempt `make release` process
run: echo proceed | make TAG=99.99.99 release
env:
GIT_EDITOR: "sed -i '1 s/^/99.99.99 make release test/'"
- name: Ensure tag is created
run: git tag | grep v99.99.99

View File

@ -1,24 +0,0 @@
name: Require “Allow Edits”
on: [pull_request_target]
permissions:
contents: read
jobs:
_:
permissions:
pull-requests: read
name: "Require “Allow Edits”"
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
api.github.com:443
- uses: ljharb/require-allow-edits@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,56 +0,0 @@
name: 'Tests: shellcheck'
on: [pull_request, push]
permissions:
contents: read
jobs:
shellcheck_matrix:
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@v2
with:
allowed-endpoints:
ghcr.io:443
github.com:443
pkg-containers.githubusercontent.com:443
formulae.brew.sh:443
- uses: actions/checkout@v4
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Install latest shellcheck
run: brew install shellcheck
env:
HOMEBREW_NO_ANALYTICS: 1
- run: which shellcheck
- 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:
- run: true

View File

@ -1,80 +0,0 @@
name: urchin tests
on: [push, pull_request]
permissions:
contents: read
jobs:
tests:
permissions:
contents: write
name: "tests"
runs-on: ubuntu-latest
defaults:
run:
shell: 'script -q -e -c "${{ matrix.shell }} {0}"'
strategy:
fail-fast: false
matrix:
exclude:
- shell: sh
suite: install_script
- shell: dash
suite: install_script
- shell: zsh
suite: install_script
- shell: ksh
suite: install_script
suite:
- install_script
- sourcing
- slow
- installation_iojs
shell:
- sh
- bash
- dash
- zsh
# - ksh
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
raw.githubusercontent.com:443
nodejs.org:443
iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
- uses: actions/checkout@v4
- run: sudo apt-get update; sudo apt-get install ${{ matrix.shell }}
if: matrix.shell == 'zsh' || matrix.shell == 'ksh'
# zsh (https://github.com/actions/runner-images/issues/264) and ksh are not in the ubuntu image
shell: bash
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: curl --version
- run: wget --version
- uses: ljharb/actions/node/install@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
- run: npm ls urchin
- run: npx which urchin
- run: env
- run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }}
nvm:
permissions:
contents: none
name: 'all test suites, all shells'
needs: [tests]
runs-on: ubuntu-latest
steps:
- run: true

View File

@ -1,41 +0,0 @@
name: update readme TOC
on: [push]
permissions:
contents: read
jobs:
_:
permissions:
contents: write
name: "update readme TOC"
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
allowed-endpoints:
github.com:443
registry.npmjs.org:443
api.github.com:443
- uses: actions/checkout@v4
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@v4
with:
node-version: 'lts/*'
- run: npm install
- run: npm run doctoc
- name: commit changes
uses: ljharb/actions-js-build/commit@v3+amendpush
with:
amend: true
force: true

View File

@ -1,193 +0,0 @@
name: 'Tests on Windows: `nvm install`'
on: [pull_request, push]
permissions:
contents: read
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:
continue-on-error: true
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/' # see https://archlinux.org/mirrors/clarkson.edu/1603/ for uptime status
export SITE='https://mirrors.kernel.org/sourceware/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:
continue-on-error: true
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 # fails
- Ubuntu-20.04
- Ubuntu-18.04
npm-node-version:
- '--lts'
- '21'
- '18'
- '16'
- '14'
- '12'
- '10'
exclude:
- wsl-distrib: Ubuntu-18.04
npm-node-version: '--lts'
- wsl-distrib: Ubuntu-18.04
npm-node-version: '21'
- wsl-distrib: Ubuntu-18.04
npm-node-version: '18'
method:
- ''
- 'script'
steps:
- uses: Vampire/setup-wsl@v3
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 }}
node -v
wsl_matrix_unofficial:
continue-on-error: true
name: 'WSL nvm install'
defaults:
run:
shell: wsl-bash {0}
runs-on: windows-latest
env:
WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p
NVM_NODEJS_ORG_MIRROR: https://unofficial-builds.nodejs.org/download/release
strategy:
fail-fast: false
matrix:
wsl-distrib:
- Alpine
npm-node-version:
- '--lts'
- '21'
- '18'
- '16'
- '14'
- '12'
- '11'
- '10'
method:
- ''
- 'script'
steps:
- uses: Vampire/setup-wsl@v3
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_NODEJS_ORG_MIRROR=${{ env.NVM_NODEJS_ORG_MIRROR }} nvm install ${{ matrix.npm-node-version }}
nvm_windows:
name: 'tests, on windows'
permissions:
contents: none
needs: [wsl_matrix, wsl_matrix_unofficial, cygwin_matrix, msys_matrix, msys_fail_install]
runs-on: ubuntu-latest
steps:
- run: true

14
.gitignore vendored
View File

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

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "test/fixtures/nvmrc"]
path = test/fixtures/nvmrc
url = git@github.com:nvm-sh/nvmrc.git

View File

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

4
.npmignore Normal file
View File

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

1
.npmrc
View File

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

View File

@ -1,94 +1,31 @@
language: generic
dist: focal
addons:
apt:
packages:
- zsh
# - ksh
# - gcc-4.8
# - g++-4.8
# https://gist.github.com/iedemam/9830045
git:
submodules: false
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
# https://gist.github.com/iedemam/9830045
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
- git submodule update --init --recursive
- $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 python
- pyenv local 2.7.18 || pyenv install 2.7.18
- pyenv local 2.7.18 || echo 'pyenv failed'
- python -V
language: c # defaults to ruby
install:
- if [ -z "${SHELLCHECK-}" ]; then nvm install 16 && nvm unalias default && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi
- sudo apt-get install ksh zsh -y
- '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'
before_script:
- '[ -n "$WITHOUT_CURL" ] || curl -o /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
- '[ -z "$WITHOUT_CURL" ] || wget -O /tmp/urchin https://raw.githubusercontent.com/scraperwiki/urchin/master/urchin'
- chmod +x /tmp/urchin
script:
- if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ] || [ "${TEST_SUITE}" = 'xenial' ]; 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
jobs:
include:
- env: SHELL=bash TEST_SUITE=installation_node
dist: xenial
- env: SHELL=bash TEST_SUITE=installation_node WITHOUT_CURL=1
dist: xenial
- env: SHELL=sh TEST_SUITE=installation_node
dist: xenial
- env: SHELL=sh TEST_SUITE=installation_node WITHOUT_CURL=1
dist: xenial
- env: SHELL=dash TEST_SUITE=installation_node
dist: xenial
- env: SHELL=dash TEST_SUITE=installation_node WITHOUT_CURL=1
dist: xenial
- env: SHELL=zsh TEST_SUITE=installation_node
dist: xenial
- env: SHELL=zsh TEST_SUITE=installation_node WITHOUT_CURL=1
dist: xenial
#- env: SHELL=ksh TEST_SUITE=installation_node
# dist: xenial
#- env: SHELL=ksh TEST_SUITE=installation_node WITHOUT_CURL=1
# dist: xenial
- env: SHELL=bash TEST_SUITE=xenial
dist: xenial
- env: SHELL=sh TEST_SUITE=xenial
dist: xenial
- env: SHELL=dash TEST_SUITE=xenial
dist: xenial
- env: SHELL=zsh TEST_SUITE=xenial
dist: xenial
#- env: SHELL=ksh TEST_SUITE=xenial
# dist: xenial
- NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin $SHELL
env:
global:
- CXX=g++
- CC=gcc
- PATH="$(echo $PATH | sed 's/::/:/')"
- PATH="/usr/lib/ccache/:$PATH"
- NVM_DIR="${TRAVIS_BUILD_DIR}"
matrix:
- 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=installation_iojs WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=bash TEST_SUITE=installation_iojs WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation_iojs WITHOUT_CURL=1
# - SHELL=ksh TEST_SUITE=installation_iojs WITHOUT_CURL=1
- 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=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
- SHELL=sh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=dash TEST_SUITE=installation
- SHELL=dash TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=bash TEST_SUITE=installation
- SHELL=bash TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=zsh TEST_SUITE=installation
- SHELL=zsh TEST_SUITE=installation WITHOUT_CURL=1
- SHELL=ksh TEST_SUITE=installation
- SHELL=ksh TEST_SUITE=installation WITHOUT_CURL=1

View File

@ -1,125 +0,0 @@
# Code of Conduct
`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v2.1](https://www.contributor-covenant.org/version/2/1/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/2/1)
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/HEAD/CODE_OF_CONDUCT.md).
---
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [@ljharb](ljharb@gmail.com).
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

View File

@ -1,123 +1,15 @@
# Contributing
Thanks for contributing to `nvm`!
:+1::tada: First off, thanks for taking the time to contribute to `nvm`! :tada::+1:
We love pull requests and issues, they're our favorite.
The following is a set of guidelines for contributing to `nvm` managed by [@LJHarb](https://github.com/ljharb), which is hosted on GitHub. These are mostly guidelines, not rules. Use your best judgment, and feel free to propose changes to this document in a pull request.
We love pull requests, they're our favorite.
However, before submitting, please review the following:
# How Can I Contribute?
- 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.
There are lots of ways to get involved. Here are some suggestions of things we'd love some help with.
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.
## Resolving existing issues
Thanks again!
You can consider helping out with issues already requiring attention - look for a "help wanted" label.
### How Do I Submit a (Good) Bug Report? :bug:
Explain the problem and include additional details to help maintainers reproduce the problem:
* **Use a clear and descriptive title** for the issue to identify the problem.
* **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining which command exactly you used in the terminal. When listing steps, **don't just say what you did, but explain how you did it**. For example, if you moved the cursor to the end of a line, explain if you used the mouse, or a keyboard shortcut or a command, and if so which one?
* **Provide specific examples to demonstrate the steps**. Include links to files or Github projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines).
* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
* **Explain which behavior you expected to see instead and why.**
* **Provide as much context as possible** in order to help others verify and ultimately fix the issue. This includes giving us as much details as possible about your environment, so we can more easily confirm the problem.
## Documentation
We are happy to welcome contributions from anyone willing to improve documentation by adding missing information or making it more consistent and coherent.
# Dev Environment
Please refer to the [README](README.md) for complete instructions how to install, update, as well as troubleshoot `nvm` in your environment depending on your Operating System.
# Style Guide / Coding conventions
### Pull requests
#### Before creating a pull request
- 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 the default branch. 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.
#### How to create a pull request
Create a new branch
```
git checkout -b issue1234
```
Commit the changes to your branch, including a coherent commit message that follows our [standards](#commit-messages)
```
git commit -a
```
Before sending the pull request, make sure your code is running on the latest available code by rebasing onto the upstream source
```
git fetch upstream
git rebase upstream/main
```
Verify your changes
```
npm test
```
Push your changes
```
git push origin issue1234
```
Send the [pull request](https://docs.github.com/en/pull-requests), make requested changes, and get merged.
### Commit Messages
* Limit the first line of the commit message (message summary) to 72 characters or less.
* Use the present tense ("Add feature" not "Added feature") and imperative mood ("Move cursor to..." not "Moves cursor to...") when providing a description of what you did.
* If your PR addresses an issue, reference it in the body of the commit message.
* See the rest of the conventions [here](https://gist.github.com/ljharb/772b0334387a4bee89af24183114b3c7)
#### Commit message example
```
[Tag]: Short description of what you did
Longer description here if necessary
Fixes #1234
```
> **Note:** Add co-authors to your commit message for commits with multiple authors
```
Co-authored-by: Name Here <email@here>
```
# Code of Conduct
[Code of Conduct](https://github.com/nvm-sh/nvm/blob/HEAD/CODE_OF_CONDUCT.md)
# Where can I ask for help?
If you have any questions, please contact [@LJHarb](mailto:ljharb@gmail.com).
# Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
- The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
- The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
- The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
- I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

View File

@ -1,112 +0,0 @@
# Dockerized nvm development environment
#
# This Dockerfile is for building nvm development environment only,
# not for any distribution/production usage.
#
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
# build this image, it depends on your hardware.
FROM ubuntu:22.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
# 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 \
g++ \
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
# Create a script file sourced by both interactive and non-interactive bash shells
ENV BASH_ENV /home/nvm/.bash_env
RUN touch "$BASH_ENV"
RUN echo '. "$BASH_ENV"' >> "$HOME/.bashrc"
# nvm
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$BASH_ENV"
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$BASH_ENV"
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$BASH_ENV"
# nodejs and tools
RUN nvm install node
RUN npm install -g doctoc urchin eclint dockerfile_lint
RUN npm install --prefix "$HOME/.nvm/"
# Set WORKDIR to nvm directory
WORKDIR /home/nvm/.nvm
ENTRYPOINT ["/bin/bash"]

View File

@ -1,10 +0,0 @@
# `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.

View File

@ -1,8 +1,6 @@
The MIT License (MIT)
Copyright (c) 2010 Tim Caswell
Copyright (c) 2014 Jordan Harband
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
@ -20,3 +18,4 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
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.

View File

@ -1,89 +1,26 @@
# 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 {} \;)
URCHIN=`which urchin`
SHELLS=sh bash dash ksh zsh
TEST_SUITE=fast
.PHONY: $(SHELLS) test verify-tag release
# 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/$(TEST_SUITE)
# 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: $(SHELLS)
@$(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" ] && [ -z "$$GITHUB_ACTIONS" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
for suite in $(TEST_SUITE); do \
echo "Running test suite: $$suite"; \
$(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:
verify-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)
$(error TAG is undefined)
endif
# Ensures there are version tags in repository
.PHONY: _ensure-current-version
release: verify-tag
@ OLD_TAG=`git describe --abbrev=0 --tags` && \
replace "$${OLD_TAG/v/}" "$(TAG)" -- nvm.sh install.sh README.markdown package.json && \
git commit -m "v$(TAG)" nvm.sh install.sh README.markdown package.json && \
git tag "v$(TAG)"
_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"

View File

@ -1,49 +0,0 @@
# `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 projects 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

175
README.markdown Normal file
View File

@ -0,0 +1,175 @@
# Node Version Manager [![Build Status](https://travis-ci.org/creationix/nvm.svg?branch=master)][3]
## Installation
First you'll need to make sure your system has a c++ compiler. For OSX, XCode will work, for Ubuntu, the build-essential and libssl-dev packages work.
### Install script
To install you could use the [install script][2] using cURL:
curl https://raw.githubusercontent.com/creationix/nvm/v0.17.2/install.sh | bash
or Wget:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.17.2/install.sh | bash
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
<sub>*NB. The installer can use Git, curl, or wget to download NVM, whatever is available.*</sub>
### Manual install
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in a folder called `nvm`.
Or if you have `git` installed, then just clone it, and check out the latest version:
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
To activate nvm, you need to source it from your shell:
source ~/.nvm/nvm.sh
I always add this line to my `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login.
Often I also put in a line to use a specific version of node.
## Usage
You can create an `.nvmrc` file containing version number in the project root directory (or any parent directory).
`nvm use`, `nvm install`, `nvm exec`, and `nvm run` will all respect an `.nvmrc` file.
To download, compile, and install the latest v0.10.x release of node, do this:
nvm install 0.10
And then in any new shell just use the installed version:
nvm use 0.10
Or you can just run it:
nvm run 0.10 --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 0.10 node --version
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
`nvm use` will, by defaut, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to any value other than "true" to disable this behavior.
## 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.6.21 v0.8.26 v0.10.28
nvm use
$ nvm use [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28
nvm uninstall
$ nvm uninstall [tab][tab]
my_alias default v0.6.21 v0.8.26 v0.10.28
## Problems
If you try to install a node version and the installation fails, be sure to delete the node downloads from src (~/.nvm/src/) or you might get an error when trying to reinstall them again or you might get an error like the following:
curl: (33) HTTP server doesn't seem to support byte ranges. Cannot resume.
Where's my 'sudo node'? 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.17.2/install.sh
[3]: https://travis-ci.org/creationix/nvm
[Urchin]: https://github.com/scraperwiki/urchin

1174
README.md

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -2,79 +2,80 @@
# bash completion for Node Version Manager (NVM)
if ! command -v nvm &> /dev/null; then
return
fi
__nvm_generate_completion() {
__nvm_generate_completion()
{
declare current_word
current_word="${COMP_WORDS[COMP_CWORD]}"
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$1" -- "${current_word}"))
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 exec
alias unalias reinstall-packages
current list ls list-remote ls-remote
install-latest-npm
cache deactivate unload
version version-remote which'
COMMANDS='\
help install uninstall use run exec\
alias unalias copy-packages
current list ls list-remote ls-remote\
clear-cache deactivate unload
version'
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="$(command cd "${NVM_DIR}/alias" && command find "${PWD}" -type f | command sed "s:${PWD}/::")"
if [ -d $NVM_DIR/alias ]; then
aliases="`cd $NVM_DIR/alias && ls`"
fi
echo "${aliases} node stable unstable iojs"
echo "${aliases}"
}
__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 | exec | ls | list | uninstall) __nvm_installed_nodes ;;
alias | unalias) __nvm_alias ;;
*) __nvm_commands ;;
case "$previous_word" in
use|run|ls|list|uninstall) __nvm_installed_nodes ;;
alias|unalias) __nvm_alias ;;
*) __nvm_commands ;;
esac
return 0
@ -84,16 +85,8 @@ __nvm() {
# 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
# 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
autoload -U +X bashcompinit && bashcompinit
fi
complete -o default -F __nvm nvm
complete -o default -o nospace -F __nvm nvm

View File

@ -1,495 +1,131 @@
#!/usr/bin/env bash
#!/bin/bash
{ # this ensures the entire script is downloaded #
set -e
nvm_has() {
type "$1" > /dev/null 2>&1
return $?
}
nvm_echo() {
command printf %s\\n "$*" 2>/dev/null
}
if [ -z "${BASH_VERSION}" ] || [ -n "${ZSH_VERSION}" ]; then
# shellcheck disable=SC2016
nvm_echo >&2 'Error: the install instructions explicitly say to pipe the install script to `bash`; please follow them'
exit 1
if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
nvm_grep() {
GREP_OPTIONS='' command grep "$@"
}
nvm_default_install_dir() {
[ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm"
}
nvm_install_dir() {
if [ -n "$NVM_DIR" ]; then
printf %s "${NVM_DIR}"
else
nvm_default_install_dir
fi
}
nvm_latest_version() {
nvm_echo "v0.40.3"
}
nvm_profile_is_bash_or_zsh() {
local TEST_PROFILE
TEST_PROFILE="${1-}"
case "${TEST_PROFILE-}" in
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
return
;;
*)
return 1
;;
esac
}
#
# Outputs the location to NVM depending on:
# * The availability of $NVM_SOURCE
# * The presence of $NVM_INSTALL_GITHUB_REPO
# * 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}"
if [ "${NVM_GITHUB_REPO}" != 'nvm-sh/nvm' ]; then
{ nvm_echo >&2 "$(cat)" ; } << EOF
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE REPO IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
The default repository for this install is \`nvm-sh/nvm\`,
but the environment variables \`\$NVM_INSTALL_GITHUB_REPO\` is
currently set to \`${NVM_GITHUB_REPO}\`.
If this is not intentional, interrupt this installation and
verify your environment variables.
EOF
fi
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 "$@"
curl $*
elif nvm_has "wget"; then
# Emulate curl with wget
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
ARGS=$(echo "$*" | sed -e 's/--progress-bar /--progress=bar /' \
-e 's/-L //' \
-e 's/-I /--server-response /' \
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
fi
}
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
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://github.com/creationix/nvm.git"
fi
local fetch_error
if [ -d "$INSTALL_DIR/.git" ]; then
# Updating repo
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
command printf '\r=> '
fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself."
if [ -d "$NVM_DIR/.git" ]; then
echo "=> nvm is already installed in $NVM_DIR, trying to update"
printf "\r=> "
cd "$NVM_DIR" && (git fetch 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 1
})
else
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
# 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!"
# Cloning to $NVM_DIR
echo "=> Downloading nvm from git to '$NVM_DIR'"
printf "\r=> "
mkdir -p "$NVM_DIR"
git clone "$NVM_SOURCE" "$NVM_DIR"
fi
cd "$NVM_DIR" && git checkout v0.17.2 && git branch -D master >/dev/null 2>&1
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'"
if [ -z "$NVM_SOURCE" ]; then
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.17.2/nvm.sh"
fi
nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {
nvm_echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
# 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"
else
echo "=> Downloading nvm as script to '$NVM_DIR'"
fi
nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
echo >&2 "Failed to download '$NVM_SOURCE'.."
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
}
}
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 "${ZDOTDIR:-${HOME}}/.zshrc" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zshrc"
elif [ -f "${ZDOTDIR:-${HOME}}/.zprofile" ]; then
DETECTED_PROFILE="${ZDOTDIR:-${HOME}}/.zprofile"
fi
fi
if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
do
if DETECTED_PROFILE="$(nvm_try_profile "${ZDOTDIR:-${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` node installs), 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
# Disable the optional which check, https://www.shellcheck.net/wiki/SC2230
# shellcheck disable=SC2230
if nvm_has xcode-select && [ "$(xcode-select -p >/dev/null 2>/dev/null ; echo $?)" = '2' ] && [ "$(which git)" = '/usr/bin/git' ] && [ "$(which curl)" = '/usr/bin/curl' ]; then
nvm_echo >&2 'You may be on a Mac, and need to install the Xcode Command Line Developer Tools.'
# shellcheck disable=SC2016
nvm_echo >&2 'If so, run `xcode-select --install` and try again. If not, please report this!'
exit 1
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
if [ -z "$METHOD" ]; then
# Autodetect install method
if nvm_has "git"; then
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
elif nvm_has "nvm_download"; then
install_nvm_as_script
else
nvm_echo >&2 "The environment variable \$METHOD is set to \"${METHOD}\", which is not recognized as a valid installation method."
echo >&2 "You need git, curl, or wget to install nvm"
exit 1
fi
elif [ "~$METHOD" = "~git" ]; then
if ! nvm_has "git"; then
echo >&2 "You need git to install nvm"
exit 1
fi
install_nvm_from_git
elif [ "~$METHOD" = "~script" ]; then
if ! nvm_has "nvm_download"; then
echo >&2 "You need curl or wget to install nvm"
exit 1
fi
install_nvm_as_script
fi
nvm_echo
echo
local NVM_PROFILE
NVM_PROFILE="$(nvm_detect_profile)"
local PROFILE_INSTALL_DIR
PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")"
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
if [ -z "$PROFILE" ]; then
if [ -f "$HOME/.bashrc" ]; then
PROFILE="$HOME/.bashrc"
elif [ -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"
fi
fi
SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n"
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
# shellcheck disable=SC2016
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
nvm_echo "=> Profile not found. Tried ${TRIED_PROFILE-}~/.bashrc, ~/.bash_profile, ~/.zprofile, ~/.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
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
if [ -z "$PROFILE" ]; then
echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
echo "=> Create one of them and run this script again"
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
echo "=> Profile $PROFILE not found"
echo "=> Create it (touch $PROFILE) and run this script again"
fi
if ${BASH_OR_ZSH} && [ -z "${NVM_PROFILE-}" ] ; then
nvm_echo "=> Please also append the following lines to the if you are using bash/zsh shell:"
command printf "${COMPLETION_STR}"
echo " OR"
echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR"
echo
else
if ! grep -qc 'nvm.sh' "$PROFILE"; then
echo "=> Appending source string to $PROFILE"
printf "$SOURCE_STR\n" >> "$PROFILE"
else
echo "=> Source string already in $PROFILE"
fi
fi
# Source nvm
# shellcheck source=/dev/null
\. "$(nvm_install_dir)/nvm.sh"
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
}
#
# 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 #
echo "=> Close and reopen your terminal to start using nvm"

View File

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

4974
nvm.sh Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,53 +1,34 @@
{
"name": "nvm",
"version": "0.40.3",
"version": "0.17.2",
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
"directories": {
"test": "test"
},
"scripts": {
"test": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make test-$shell",
"test/fast": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); 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",
"test:check-exec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ ! -x \"$file\" ] && [[ \"$file\" != *.* ]] && [[ \"$file\" != test/fixtures/* ]]; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
"test:check-nonexec": "(IFS=$'\\n'; for file in $(git ls-files test); do if [ -x \"$file\" ] && [ ! -d \"$file\" ] && { [[ \"$file\" =~ '\\.(json|txt|sh|js|log)$' ]] || [[ \"$file\" =~ '^test/(mocks|fixtures)/.*' ]]; }; then echo \"$file\"; fi; done) | tee /dev/stderr | awk 'END {if (NR > 0) exit 1}'",
"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"
"test": "urchin test",
"test/fast": "urchin -f test/fast",
"test/slow": "urchin -f test/slow",
"test/installation": "urchin -f test/installation"
},
"repository": {
"type": "git",
"url": "git://github.com/nvm-sh/nvm.git"
"url": "git://github.com/creationix/nvm.git"
},
"keywords": [
"nvm",
"node",
"iojs",
"version",
"manager"
],
"author": "Tim Caswell <tim@creationix.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/nvm-sh/nvm/issues"
"url": "https://github.com/creationix/nvm/issues"
},
"homepage": "https://github.com/nvm-sh/nvm",
"homepage": "https://github.com/creationix/nvm",
"devDependencies": {
"dockerfile_lint": "^0.3.4",
"doctoc": "^2.2.1",
"eclint": "^2.8.1",
"markdown-link-check": "^3.13.7",
"replace": "^1.2.2",
"semver": "^7.7.1",
"urchin": "^0.0.5"
"urchin": "~0.0.2"
}
}

View File

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

View File

@ -1,247 +0,0 @@
assert_ok() {
local FUNCTION=$1
shift
$($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have succeeded, but failed'
}
assert_not_ok() {
local FUNCTION=$1
shift
! $($FUNCTION $@) || die '"'"$FUNCTION $@"'" should have failed, but succeeded'
}
strip_colors() {
while read -r line; do
echo "$line" | LC_ALL=C command sed 's/\[[ -?]*[@-~]//g'
done
}
make_echo() {
echo "#!/bin/sh" > "$1"
echo "echo \"${2}\"" > "$1"
chmod a+x "$1"
}
make_fake_node() {
local VERSION
VERSION="${1-}"
[ -n "${VERSION}" ] || return 1
local FORMATTED_VERSION
FORMATTED_VERSION="$(nvm_format_version "${VERSION}")"
local BIN_PATH
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
[ "${BIN_PATH}" != "/bin" ] || {
echo >&2 'nvm_version_path was empty'
return 5
}
mkdir -p "${BIN_PATH}" || {
echo >&2 'unable to make bin dir'
return 2
}
make_echo "${BIN_PATH}/node" "${VERSION}" || {
echo >&2 'unable to make fake node bin'
return 3
}
nvm_is_version_installed "${FORMATTED_VERSION}" || {
echo >&2 'fake node is not installed'
return 4
}
}
make_fake_iojs() {
local VERSION
VERSION="${1-}"
[ -n "${VERSION}" ] || return 1
local FORMATTED_VERSION
FORMATTED_VERSION="$(nvm_format_version "iojs-${VERSION}")"
local BIN_PATH
BIN_PATH="$(nvm_version_path "${FORMATTED_VERSION}")/bin"
[ "${BIN_PATH}" != "/bin" ] || {
echo >&2 'nvm_version_path was empty'
return 5
}
mkdir -p "${BIN_PATH}" || {
echo >&2 'unable to make bin dir'
return 2
}
make_echo "${BIN_PATH}/node" "${VERSION}" || {
echo >&2 'unable to make fake node bin'
return 3
}
make_echo "${BIN_PATH}/iojs" "${VERSION}" || {
echo >&2 'unable to make fake iojs bin'
return 3
}
nvm_is_version_installed "${FORMATTED_VERSION}" || {
echo >&2 'fake iojs is not installed'
return 4
}
}
watch() {
$@ &
local JOB
JOB=$!
while true; do sleep 15; >&2 echo '* ping *'; done &
wait $JOB;
local EXIT_CODE
EXIT_CODE=$?
kill %2;
return $EXIT_CODE
}
# JSON parsing from https://gist.github.com/assaf/ee377a186371e2e269a7
nvm_json_throw() {
nvm_err "$*"
exit 1
}
nvm_json_awk_egrep() {
local pattern_string
pattern_string="${1}"
awk '{
while ($0) {
start=match($0, pattern);
token=substr($0, start, RLENGTH);
print token;
$0=substr($0, start+RLENGTH);
}
}' "pattern=${pattern_string}"
}
nvm_json_tokenize() {
local GREP
GREP='grep -Eao'
local ESCAPE
local CHAR
# if echo "test string" | grep -Eo "test" > /dev/null 2>&1; then
# ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
# CHAR='[^[:cntrl:]"\\]'
# else
GREP=nvm_json_awk_egrep
ESCAPE='(\\\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
CHAR='[^[:cntrl:]"\\\\]'
# fi
local STRING
STRING="\"${CHAR}*(${ESCAPE}${CHAR}*)*\""
local NUMBER
NUMBER='-?(0|[1-9][0-9]*)([.][0-9]*)?([eE][+-]?[0-9]*)?'
local KEYWORD
KEYWORD='null|false|true'
local SPACE
SPACE='[[:space:]]+'
$GREP "${STRING}|${NUMBER}|${KEYWORD}|${SPACE}|." | TERM=dumb grep -Ev "^${SPACE}$"
}
_json_parse_array() {
local index=0
local ary=''
read -r token
case "$token" in
']') ;;
*)
while :; do
_json_parse_value "${1}" "${index}"
index=$((index+1))
ary="${ary}${value}"
read -r token
case "${token}" in
']') break ;;
',') ary="${ary}," ;;
*) nvm_json_throw "EXPECTED , or ] GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
:
}
_json_parse_object() {
local key
local obj=''
read -r token
case "$token" in
'}') ;;
*)
while :; do
case "${token}" in
'"'*'"') key="${token}" ;;
*) nvm_json_throw "EXPECTED string GOT ${token:-EOF}" ;;
esac
read -r token
case "${token}" in
':') ;;
*) nvm_json_throw "EXPECTED : GOT ${token:-EOF}" ;;
esac
read -r token
_json_parse_value "${1}" "${key}"
obj="${obj}${key}:${value}"
read -r token
case "${token}" in
'}') break ;;
',') obj="${obj}," ;;
*) nvm_json_throw "EXPECTED , or } GOT ${token:-EOF}" ;;
esac
read -r token
done
;;
esac
:
}
_json_parse_value() {
local jpath="${1:+$1,}$2"
local isleaf=0
local isempty=0
local print=0
case "$token" in
'{') _json_parse_object "${jpath}" ;;
'[') _json_parse_array "${jpath}" ;;
# At this point, the only valid single-character tokens are digits.
''|[!0-9]) nvm_json_throw "EXPECTED value GOT >${token:-EOF}<" ;;
*)
value=$token
isleaf=1
[ "${value}" = '""' ] && isempty=1
;;
esac
[ "${value}" = '' ] && return
[ "${isleaf}" -eq 1 ] && [ $isempty -eq 0 ] && print=1
[ "${print}" -eq 1 ] && printf "[%s]\t%s\n" "${jpath}" "${value}"
:
}
_json_parse() {
read -r token
_json_parse_value
read -r token
case "${token}" in
'') ;;
*) nvm_json_throw "EXPECTED EOF GOT >${token}<" ;;
esac
}
nvm_json_extract() {
nvm_json_tokenize | _json_parse | grep -e "${1}" | awk '{print $2 $3}'
}

View File

@ -1,20 +0,0 @@
#!/bin/sh
die() { echo "$@" ; exit 1; }
export NVM_DIR="$(cd ../../.. && pwd)"
\. "${NVM_DIR}/nvm.sh"
\. ../../common.sh
echo "
v0.0.1
" > ../../../alias/test-blank-lines
EXPECTED='v0.0.1'
ACTUAL="$(nvm_alias test-blank-lines)"
EXIT_CODE="$(nvm_alias test-blank-lines 2>&1 >/dev/null; echo $?)"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
[ "${EXIT_CODE}" = '0' ] || die "expected exit code 0, got ${EXIT_CODE}"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,28 @@
#!/bin/sh
. ../../../nvm.sh
die () { echo $@ ; exit 1; }
NVM_ALIAS_OUTPUT=$(nvm alias)
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test1 -> 0.0.1 (-> v0.0.1)$' \
|| die "did not find test1 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test2 -> 0.0.2 (-> v0.0.2)$' \
|| die "did not find test2 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test3 -> 0.0.3 (-> v0.0.3)$' \
|| die "did not find test3 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test4 -> 0.0.4 (-> v0.0.4)$' \
|| die "did not find test4 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test5 -> 0.0.5 (-> v0.0.5)$' \
|| die "did not find test5 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test6 -> 0.0.6 (-> v0.0.6)$' \
|| die "did not find test6 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test7 -> 0.0.7 (-> v0.0.7)$' \
|| die "did not find test7 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test8 -> 0.0.8 (-> v0.0.8)$' \
|| die "did not find test8 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test9 -> 0.0.9 (-> v0.0.9)$' \
|| die "did not find test9 alias"
echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test10 -> 0.0.10 (-> v0.0.10)$' \
|| die "did not find test10 alias"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,36 +0,0 @@
#!/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"

View File

@ -1,36 +0,0 @@
#!/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"

View File

@ -1,9 +0,0 @@
#!/bin/sh
echo loopback > ../../../../alias/loopback
echo two > ../../../../alias/one
echo three > ../../../../alias/two
echo one > ../../../../alias/three
echo two > ../../../../alias/four

View File

@ -1,9 +0,0 @@
#!/bin/sh
rm -f ../../../../alias/loopback
rm -f ../../../../alias/one
rm -f ../../../../alias/two
rm -f ../../../../alias/three
rm -f ../../../../alias/four

View File

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

View File

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

View File

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

View File

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

View File

@ -1,22 +0,0 @@
#!/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}<"

View File

@ -1,31 +0,0 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
echo "$@"
exit 1
}
set -e
MOCKS_DIR="../Unit tests/mocks"
# sample output at the time the test was written
TAB_PATH="$MOCKS_DIR/nodejs.org-dist-index.tab"
nvm_download() {
cat "$TAB_PATH"
}
nvm_alias_path() {
nvm_echo "../../../alias"
}
nvm ls-remote >/dev/null || die 'nvm ls-remote (to populate LTS aliases) failed'
EXPECTED_OUTPUT="$(cat "$MOCKS_DIR/lts-star.txt")"
STDOUT_OUTPUT="$(nvm_list_aliases "lts/*")"
STDERR_OUTPUT="$(nvm_list_aliases "lts/*" 2>&1 >/dev/null)"
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"
[ "${STDOUT_OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected ${EXPECTED_OUTPUT}, got >${STDOUT_OUTPUT}<"

View File

@ -1,21 +0,0 @@
#!/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}<"

View File

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

View File

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

View File

@ -1,49 +0,0 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
export NVM_DIR="$(cd ../../.. && pwd)"
\. "${NVM_DIR}/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"
echo "
v0.0.1
v0.0.2
v0.0.3
" > ../../../alias/test-multi-lines
EXPECTED='v0.0.1'
ACTUAL="$(nvm_resolve_alias test-multi-lines)"
EXIT_CODE="$(nvm_resolve_alias test-multi-lines 2>&1 >/dev/null; echo $?)"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
[ "${EXIT_CODE}" = '0' ] || die "expected exit code 0, got ${EXIT_CODE}"

View File

@ -1,35 +0,0 @@
#!/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"

View File

@ -1,16 +0,0 @@
#!/bin/sh
export NVM_DIR="$(cd ../../.. && pwd)"
\. ../../../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

7
test/fast/Aliases/setup_dir Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
for i in $(seq 1 10)
do
echo 0.0.$i > ../../../alias/test$i
mkdir -p ../../../v0.0.$i
done

View File

@ -1,19 +0,0 @@
#!/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"
rm -f "../../../alias/test-blank-lines"
rm -f "../../../alias/test-multi-lines"

8
test/fast/Aliases/teardown_dir Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
for i in $(seq 1 10)
do
rm -f "../../../alias/test$i"
rm -rf "../../../v0.0.$i"
done

View File

@ -1,27 +0,0 @@
#!/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'"

View File

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

View File

@ -1,3 +0,0 @@
rm -rf ../../../v0.0.2
rm -rf ../../../v0.0.20
rm -rf ../../../v0.12.0

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,18 @@
#!/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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,12 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
die () { echo $@ ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
mkdir -p ../../../versions/v0.12.1
mkdir ../../../v0.1.3
make_fake_node v0.12.1
make_fake_node v0.1.3
. ../../../nvm.sh
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'

View File

@ -1,11 +1,11 @@
#!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
mkdir ../../../v0.1.2
make_fake_node v0.1.2
. ../../../nvm.sh
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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,29 +0,0 @@
#!/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"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,16 +1,14 @@
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
rmdir ../../../v0.0.1 >/dev/null 2>&1
rmdir ../../../v0.0.2 >/dev/null 2>&1
rmdir ../../../v0.0.3 >/dev/null 2>&1
rmdir ../../../v0.0.9 >/dev/null 2>&1
rmdir ../../../v0.0.20 >/dev/null 2>&1
rmdir ../../../v0.1.2 >/dev/null 2>&1
rmdir ../../../v0.1.3 >/dev/null 2>&1
rmdir ../../../v0.2.3 >/dev/null 2>&1
rmdir ../../../v0.3.1 >/dev/null 2>&1
rmdir ../../../v0.3.3 >/dev/null 2>&1
rmdir ../../../v0.3.9 >/dev/null 2>&1
rmdir ../../../versions >/dev/null 2>&1
unalias nvm_has_system_node >/dev/null 2>&1

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