mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-11 15:44:19 +00:00
Compare commits
5 Commits
travis3
...
2685f6d5a1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2685f6d5a1 | ||
|
|
5dc31ac51b | ||
|
|
da2720a429 | ||
|
|
9fb9dec710 | ||
|
|
09c4fcfbed |
@@ -100,6 +100,8 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
|
|||||||
|
|
||||||
### Install & Update Script
|
### Install & Update Script
|
||||||
|
|
||||||
|
**If you use macOS, you must install Xcode and agree to the Xcode License before you install nvm.**
|
||||||
|
|
||||||
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
||||||
```sh
|
```sh
|
||||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
||||||
@@ -108,7 +110,7 @@ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
|||||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). **If you don't have a profile file in your home dir, you'll need to add the appropriate one before you run the script.**
|
||||||
|
|
||||||
<a id="profile_snippet"></a>
|
<a id="profile_snippet"></a>
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
31
nvm.sh
31
nvm.sh
@@ -700,10 +700,12 @@ nvm_ensure_version_installed() {
|
|||||||
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
||||||
fi
|
fi
|
||||||
nvm_err ""
|
nvm_err ""
|
||||||
if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
if [ "${PROVIDED_VERSION}" = 'lts' ]; then
|
||||||
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
nvm_err '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
||||||
else
|
elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
||||||
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
||||||
|
else
|
||||||
|
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -891,6 +893,10 @@ nvm_normalize_lts() {
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then
|
||||||
|
nvm_err 'LTS names must be lowercase'
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
nvm_echo "${LTS}"
|
nvm_echo "${LTS}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -1249,7 +1255,9 @@ nvm_alias() {
|
|||||||
nvm_err 'An alias is required.'
|
nvm_err 'An alias is required.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
ALIAS="$(nvm_normalize_lts "${ALIAS}")"
|
if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "${ALIAS}" ]; then
|
if [ -z "${ALIAS}" ]; then
|
||||||
return 2
|
return 2
|
||||||
@@ -1652,7 +1660,9 @@ $VERSION_LIST
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "${LTS-}" ]; then
|
if [ -n "${LTS-}" ]; then
|
||||||
LTS="$(nvm_normalize_lts "lts/${LTS}")"
|
if ! LTS="$(nvm_normalize_lts "lts/${LTS}")"; then
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
LTS="${LTS#lts/}"
|
LTS="${LTS#lts/}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -3417,9 +3427,11 @@ nvm() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
local EXIT_CODE
|
||||||
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
|
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
|
||||||
|
EXIT_CODE="$?"
|
||||||
|
|
||||||
if [ "${VERSION}" = 'N/A' ]; then
|
if [ "${VERSION}" = 'N/A' ] || [ $EXIT_CODE -ne 0 ]; then
|
||||||
local LTS_MSG
|
local LTS_MSG
|
||||||
local REMOTE_CMD
|
local REMOTE_CMD
|
||||||
if [ "${LTS-}" = '*' ]; then
|
if [ "${LTS-}" = '*' ]; then
|
||||||
@@ -3428,6 +3440,10 @@ nvm() {
|
|||||||
elif [ -n "${LTS-}" ]; then
|
elif [ -n "${LTS-}" ]; then
|
||||||
LTS_MSG="(with LTS filter '${LTS}') "
|
LTS_MSG="(with LTS filter '${LTS}') "
|
||||||
REMOTE_CMD="nvm ls-remote --lts=${LTS}"
|
REMOTE_CMD="nvm ls-remote --lts=${LTS}"
|
||||||
|
if [ -z "${provided_version}" ]; then
|
||||||
|
nvm_err "Version with LTS filter '${LTS}' not found - try \`${REMOTE_CMD}\` to browse available versions."
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
REMOTE_CMD='nvm ls-remote'
|
REMOTE_CMD='nvm ls-remote'
|
||||||
fi
|
fi
|
||||||
@@ -3492,7 +3508,6 @@ nvm() {
|
|||||||
FLAVOR="$(nvm_node_prefix)"
|
FLAVOR="$(nvm_node_prefix)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local EXIT_CODE
|
|
||||||
EXIT_CODE=0
|
EXIT_CODE=0
|
||||||
|
|
||||||
if nvm_is_version_installed "${VERSION}"; then
|
if nvm_is_version_installed "${VERSION}"; then
|
||||||
|
|||||||
35
test/fast/Unit tests/nvm install with nonlowercase LTS name
Executable file
35
test/fast/Unit tests/nvm install with nonlowercase LTS name
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
||||||
|
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
|
||||||
|
|
||||||
|
nvm_download() {
|
||||||
|
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
|
||||||
|
cat "${REMOTE}"
|
||||||
|
elif [ "$*" = "-L -s $(nvm_get_mirror iojs)/index.tab -o -" ]; then
|
||||||
|
cat "${REMOTE_IOJS}"
|
||||||
|
else
|
||||||
|
nvm_err "unknown nvm_download call: $*"
|
||||||
|
return 42
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
nvm_install_binary() {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
nvm_install_source() {
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
|
||||||
|
ACTUAL="$(nvm install lts/ARGON 2>&1)"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
[ $EXIT_CODE -eq 3 ] || die "Expected exit code of 3, got ${EXIT_CODE}"
|
||||||
|
|
||||||
|
EXPECTED="LTS names must be lowercase
|
||||||
|
Version with LTS filter 'ARGON' not found - try \`nvm ls-remote --lts=ARGON\` to browse available versions."
|
||||||
|
|
||||||
|
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@@ -56,6 +54,14 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
|
|||||||
INDEX=$(($INDEX + 1))
|
INDEX=$(($INDEX + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
|
OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'"
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT="LTS names must be lowercase
|
||||||
|
N/A"
|
||||||
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
|
||||||
|
|
||||||
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
|
||||||
nvm_ls_remote() {
|
nvm_ls_remote() {
|
||||||
cat "${REMOTE}"
|
cat "${REMOTE}"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ cleanup () {
|
|||||||
nvm cache clear
|
nvm cache clear
|
||||||
nvm deactivate
|
nvm deactivate
|
||||||
rm -rf ${NVM_DIR}/v*
|
rm -rf ${NVM_DIR}/v*
|
||||||
nvm unalias default
|
nvm unalias default || true
|
||||||
}
|
}
|
||||||
|
|
||||||
die () { >&2 echo "$@" ; cleanup ; exit 1; }
|
die () { >&2 echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ ACTUAL="$(nvm_normalize_lts "lts/*")"
|
|||||||
EXPECTED='lts/*'
|
EXPECTED='lts/*'
|
||||||
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
|
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
|
||||||
|
|
||||||
|
if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then
|
||||||
|
die "expected failure, got >${ACTUAL}<"
|
||||||
|
fi
|
||||||
|
|
||||||
MOCKS_DIR="../Unit tests/mocks"
|
MOCKS_DIR="../Unit tests/mocks"
|
||||||
STAR="$(cat "$MOCKS_DIR/lts-star.txt")"
|
STAR="$(cat "$MOCKS_DIR/lts-star.txt")"
|
||||||
|
|||||||
@@ -9,20 +9,20 @@ die () { echo "$@" ; exit 1; }
|
|||||||
nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
|
nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
|
||||||
|
|
||||||
set +ex # needed for stderr
|
set +ex # needed for stderr
|
||||||
OUTPUT="$(nvm install --lts 3 2>&1)"
|
OUTPUT="$(nvm install --lts 0.12 2>&1)"
|
||||||
|
EXIT_CODE="$?"
|
||||||
set -ex
|
set -ex
|
||||||
EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)"
|
EXPECTED_OUTPUT="Version '0.12' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
|
||||||
EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
|
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 0.12\` did not exit with 3, got >${EXIT_CODE}<"
|
||||||
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<"
|
|
||||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
||||||
|
|
||||||
set +ex # needed for stderr
|
set +ex # needed for stderr
|
||||||
OUTPUT="$(nvm install --lts=argon 3 2>&1)"
|
OUTPUT="$(nvm install --lts=argon 0.12 2>&1)"
|
||||||
set -ex
|
EXIT_CODE="$?"
|
||||||
EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)"
|
set -x
|
||||||
EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
|
EXPECTED_OUTPUT="Version '0.12' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
|
||||||
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<"
|
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 0.12\` did not exit with 3, got >${EXIT_CODE}<"
|
||||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 0.12\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
||||||
|
|
||||||
nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed'
|
nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed'
|
||||||
|
|
||||||
|
|||||||
19
test/slow/nvm use/Running 'nvm use lts' shows actionable error
Executable file
19
test/slow/nvm use/Running 'nvm use lts' shows actionable error
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
# Deactivate any active node version
|
||||||
|
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
|
||||||
|
|
||||||
|
# Attempt to use 'lts' without '--' and capture the error message
|
||||||
|
ERROR_OUTPUT=$(nvm use lts 2>&1) || true
|
||||||
|
|
||||||
|
EXPECTED_ERROR='`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
||||||
|
|
||||||
|
# Check if the error message matches the expected output
|
||||||
|
echo "$ERROR_OUTPUT" | grep -q "$EXPECTED_ERROR" \
|
||||||
|
|| die "Expected error message not found. Got: $ERROR_OUTPUT"
|
||||||
Reference in New Issue
Block a user