mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-04 03:48:06 +08:00
Compare commits
4 Commits
7079a5d61c
...
a6ec739430
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6ec739430 | ||
|
|
718e880890 | ||
|
|
ed4dbdfdd5 | ||
|
|
a9933f77a6 |
@@ -429,6 +429,7 @@ In place of a version pointer like "14.7" or "16.3" or "12.22.1", you can use th
|
||||
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
|
||||
- `stable`: this alias is deprecated, and only truly applies to `node` `v0.12` and earlier. Currently, this is an alias for `node`.
|
||||
- `unstable`: this alias points to `node` `v0.11` - the last "unstable" node release, since post-1.0, all node versions are stable. (in SemVer, versions communicate breakage, not stability).
|
||||
- `current`: the version currently active in this shell (i.e. what `node` resolves to via `$PATH`). It is **not** affected by `.nvmrc`. Useful when you want to refer to the active version explicitly — e.g. `nvm which current` always prints the path to the active `node`, regardless of whether an `.nvmrc` file is present.
|
||||
|
||||
### Long-term Support
|
||||
|
||||
@@ -645,7 +646,7 @@ NVM_AUTH_HEADER="Bearer secret-token" nvm install node
|
||||
### .nvmrc
|
||||
|
||||
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
|
||||
Afterwards, `nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line.
|
||||
Afterwards, `nvm use`, `nvm install`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line; if no `.nvmrc` is found either, they exit with status `127`. (`nvm exec` and `nvm run` follow the same `.nvmrc` lookup, but currently fall back to the active node if neither resolves — treat that fallback as undefined behavior; pass an explicit version if you need predictable scripting.) If you want the currently active version, pass `current` explicitly (e.g. `nvm which current`) — `current` is not affected by `.nvmrc`.
|
||||
|
||||
For example, to make nvm default to the latest 5.9 release, the latest LTS version, or the latest node version for the current directory:
|
||||
|
||||
|
||||
73
nvm.sh
73
nvm.sh
@@ -622,7 +622,7 @@ nvm_rc_version() {
|
||||
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||
if [ ! -e "${NVMRC_PATH}" ]; then
|
||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||
nvm_err "No .nvmrc file found"
|
||||
nvm_err "No version provided and no .nvmrc file found"
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
@@ -3222,7 +3222,7 @@ nvm() {
|
||||
nvm_echo ' nvm --help Show this message'
|
||||
nvm_echo ' --no-colors Suppress colored output'
|
||||
nvm_echo ' nvm --version Print out the installed version of nvm'
|
||||
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if version is omitted; otherwise errors.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'
|
||||
nvm_echo ' -s Skip binary download, install from source only.'
|
||||
nvm_echo ' -b Skip source download, install from binary only.'
|
||||
@@ -3239,23 +3239,23 @@ nvm() {
|
||||
nvm_echo ' nvm uninstall <version> Uninstall a version'
|
||||
nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm use [<version>] Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' nvm use [current | <version>] Modify PATH to use <version>. Uses .nvmrc if version is omitted; otherwise errors.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm use`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' --save Writes the specified version to .nvmrc.'
|
||||
nvm_echo ' nvm exec [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' nvm exec [current | <version>] [<command>] Run <command> on <version>. Uses .nvmrc if version is omitted; otherwise errors.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm exec`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm run [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' nvm run [current | <version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if version is omitted; otherwise errors.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm run`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm current Display currently activated version of Node'
|
||||
nvm_echo ' nvm current Display the active node version (resolved via $PATH; not affected by .nvmrc).'
|
||||
nvm_echo ' nvm ls [<version>] List installed versions, matching a given <version> if provided'
|
||||
nvm_echo ' --no-colors Suppress colored output'
|
||||
nvm_echo ' --no-alias Suppress `nvm alias` output'
|
||||
@@ -3276,7 +3276,7 @@ nvm() {
|
||||
nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'
|
||||
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
|
||||
nvm_echo ' nvm unload Unload `nvm` from shell'
|
||||
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if version is omitted; otherwise errors.'
|
||||
nvm_echo ' --silent Silences stdout/stderr output when a version is omitted'
|
||||
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
||||
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
||||
@@ -3338,7 +3338,9 @@ nvm() {
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm cache dir'
|
||||
nvm_err ' nvm cache clear'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
;;
|
||||
esac
|
||||
@@ -3594,7 +3596,9 @@ nvm() {
|
||||
else
|
||||
{ provided_version="$(nvm_rc_version 3>&1 1>&4)"; } 4>&1
|
||||
if [ $version_not_provided -eq 1 ] && [ -z "${provided_version}" ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm install [<version>]'
|
||||
nvm_err ' Provide a <version>, or run from a directory containing an .nvmrc file.'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
fi
|
||||
@@ -3852,7 +3856,10 @@ nvm() {
|
||||
;;
|
||||
"uninstall")
|
||||
if [ $# -ne 1 ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm uninstall <version>'
|
||||
nvm_err ' nvm uninstall --lts'
|
||||
nvm_err ' nvm uninstall --lts=<LTS name>'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
|
||||
@@ -4041,7 +4048,9 @@ nvm() {
|
||||
fi
|
||||
|
||||
if [ -z "${VERSION}" ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm use [<version>]'
|
||||
nvm_err ' Provide a <version>, or run from a directory containing an .nvmrc file.'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
|
||||
@@ -4165,7 +4174,9 @@ nvm() {
|
||||
VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||:
|
||||
fi
|
||||
if [ "${VERSION:-N/A}" = 'N/A' ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm run [<version>] [<args>]'
|
||||
nvm_err ' Provide a <version>, or run from a directory containing an .nvmrc file.'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
fi
|
||||
@@ -4179,6 +4190,14 @@ nvm() {
|
||||
if [ $has_checked_nvmrc -ne 1 ]; then
|
||||
{ NVM_RC_VERSION="$(NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version 3>&1 1>&4)"; } 4>&1 && has_checked_nvmrc=1
|
||||
fi
|
||||
if [ -z "${NVM_RC_VERSION-}" ]; then
|
||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||
nvm_err 'WARNING: `nvm run` was invoked without a version argument and without an .nvmrc file.'
|
||||
nvm_err ' Falling back to the active node version; this will become an error in a future release.'
|
||||
nvm_err ' Pass `current` explicitly (e.g. `nvm run current ...`) to silence this warning.'
|
||||
fi
|
||||
NVM_RC_VERSION="$(nvm_version current)" ||:
|
||||
fi
|
||||
provided_version="${NVM_RC_VERSION}"
|
||||
IS_VERSION_FROM_NVMRC=1
|
||||
VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||:
|
||||
@@ -4236,19 +4255,36 @@ nvm() {
|
||||
|
||||
local provided_version
|
||||
provided_version="$1"
|
||||
local VERSION_SOURCE
|
||||
VERSION_SOURCE=''
|
||||
if [ "${NVM_LTS-}" != '' ]; then
|
||||
provided_version="lts/${NVM_LTS:-*}"
|
||||
VERSION="${provided_version}"
|
||||
VERSION_SOURCE='lts'
|
||||
elif [ -n "${provided_version}" ]; then
|
||||
VERSION="$(nvm_version "${provided_version}")" ||:
|
||||
if [ "_${VERSION}" = '_N/A' ] && ! nvm_is_valid_version "${provided_version}"; then
|
||||
{ provided_version="$(NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version 3>&1 1>&4)"; } 4>&1 && has_checked_nvmrc=1
|
||||
VERSION="$(nvm_version "${provided_version}")" ||:
|
||||
if [ -n "${provided_version}" ]; then
|
||||
VERSION_SOURCE='nvmrc'
|
||||
fi
|
||||
else
|
||||
VERSION_SOURCE='arg'
|
||||
shift
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${VERSION_SOURCE}" ]; then
|
||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||
nvm_err 'WARNING: `nvm exec` was invoked without a version argument and without an .nvmrc file.'
|
||||
nvm_err ' Falling back to the active node version; this will become an error in a future release.'
|
||||
nvm_err ' Pass `current` explicitly (e.g. `nvm exec current ...`) to silence this warning.'
|
||||
fi
|
||||
provided_version='current'
|
||||
VERSION="$(nvm_version current)" ||:
|
||||
fi
|
||||
|
||||
nvm_ensure_version_installed "${provided_version}"
|
||||
EXIT_CODE=$?
|
||||
if [ "${EXIT_CODE}" != "0" ]; then
|
||||
@@ -4383,7 +4419,9 @@ nvm() {
|
||||
VERSION="${provided_version-}"
|
||||
fi
|
||||
if [ -z "${VERSION}" ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm which [current | <version>]'
|
||||
nvm_err ' Provide a <version>, or run from a directory containing an .nvmrc file.'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
|
||||
@@ -4480,7 +4518,8 @@ nvm() {
|
||||
NVM_ALIAS_DIR="$(nvm_alias_path)"
|
||||
command mkdir -p "${NVM_ALIAS_DIR}"
|
||||
if [ $# -ne 1 ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm unalias <name>'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
if [ "${1#*\/}" != "${1-}" ]; then
|
||||
@@ -4517,7 +4556,8 @@ nvm() {
|
||||
;;
|
||||
"install-latest-npm")
|
||||
if [ $# -ne 0 ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err 'Usage: nvm install-latest-npm'
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
|
||||
@@ -4525,7 +4565,8 @@ nvm() {
|
||||
;;
|
||||
"reinstall-packages" | "copy-packages")
|
||||
if [ $# -ne 1 ]; then
|
||||
>&2 nvm --help
|
||||
nvm_err "Usage: nvm ${COMMAND} <version>"
|
||||
nvm_err ' Run `nvm --help` for full help.'
|
||||
return 127
|
||||
fi
|
||||
|
||||
|
||||
44
test/fast/Running 'nvm --help' documents current and the .nvmrc fallback
Executable file
44
test/fast/Running 'nvm --help' documents current and the .nvmrc fallback
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
: nvm.sh
|
||||
\. ../../nvm.sh
|
||||
|
||||
\. ../common.sh
|
||||
|
||||
HELP="$(nvm --help 2>&1)"
|
||||
|
||||
# Signatures for use/exec/run advertise `current` (mirroring `nvm which`).
|
||||
for EXPECTED in \
|
||||
'nvm use [current | <version>]' \
|
||||
'nvm exec [current | <version>] [<command>]' \
|
||||
'nvm run [current | <version>] [<args>]' \
|
||||
'nvm which [current | <version>]' \
|
||||
; do
|
||||
case "${HELP}" in
|
||||
*"${EXPECTED}"*) ;;
|
||||
*) die "nvm --help did not contain signature >${EXPECTED}<" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# The .nvmrc fallback is documented as conditional, not free.
|
||||
case "${HELP}" in
|
||||
*'Uses .nvmrc if version is omitted; otherwise errors.'*) ;;
|
||||
*) die "nvm --help did not document the .nvmrc fallback caveat" ;;
|
||||
esac
|
||||
|
||||
# The stale, looser phrasing must be gone.
|
||||
case "${HELP}" in
|
||||
*'if available and version is omitted'*) die "nvm --help still contains the old .nvmrc phrasing" ;;
|
||||
esac
|
||||
|
||||
# `nvm current` is documented as resolving via \$PATH, not .nvmrc.
|
||||
case "${HELP}" in
|
||||
*'Display the active node version (resolved via $PATH; not affected by .nvmrc).'*) ;;
|
||||
*) die "nvm --help did not document that 'nvm current' resolves via \$PATH" ;;
|
||||
esac
|
||||
@@ -0,0 +1,63 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
cd "${ORIG_PWD}" 2>/dev/null || true
|
||||
[ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
: nvm.sh
|
||||
\. ../../nvm.sh
|
||||
|
||||
\. ../common.sh
|
||||
|
||||
ORIG_PWD="$(pwd)"
|
||||
|
||||
# Run from a fresh, empty directory so no ambient .nvmrc above the test dir
|
||||
# can satisfy the lookup and mask the warning.
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
cd "${TMP_DIR}" || die "could not cd to temp dir"
|
||||
|
||||
EXEC_WARNING='WARNING: `nvm exec` was invoked without a version argument and without an .nvmrc file.'
|
||||
RUN_WARNING='WARNING: `nvm run` was invoked without a version argument and without an .nvmrc file.'
|
||||
|
||||
# `nvm exec` with no version and no .nvmrc should warn on stderr (and fall back).
|
||||
set +ex # needed for stderr
|
||||
EXEC_STDERR="$(nvm exec </dev/null 2>&1 1>/dev/null)"
|
||||
set -ex
|
||||
case "${EXEC_STDERR}" in
|
||||
*"${EXEC_WARNING}"*) ;;
|
||||
*) die "'nvm exec' with no version did not warn; got >${EXEC_STDERR}<" ;;
|
||||
esac
|
||||
|
||||
# `--silent` should suppress the warning.
|
||||
set +ex # needed for stderr
|
||||
EXEC_SILENT_STDERR="$(nvm exec --silent </dev/null 2>&1 1>/dev/null)"
|
||||
set -ex
|
||||
case "${EXEC_SILENT_STDERR}" in
|
||||
*WARNING*) die "'nvm exec --silent' should not warn; got >${EXEC_SILENT_STDERR}<" ;;
|
||||
esac
|
||||
|
||||
# `nvm run` with an unresolvable version and no .nvmrc should warn (and fall back).
|
||||
set +ex # needed for stderr
|
||||
RUN_STDERR="$(nvm run bogusversion </dev/null 2>&1 1>/dev/null)"
|
||||
set -ex
|
||||
case "${RUN_STDERR}" in
|
||||
*"${RUN_WARNING}"*) ;;
|
||||
*) die "'nvm run' with no resolvable version did not warn; got >${RUN_STDERR}<" ;;
|
||||
esac
|
||||
|
||||
# `--silent` should suppress the warning.
|
||||
set +ex # needed for stderr
|
||||
RUN_SILENT_STDERR="$(nvm run --silent bogusversion </dev/null 2>&1 1>/dev/null)"
|
||||
set -ex
|
||||
case "${RUN_SILENT_STDERR}" in
|
||||
*WARNING*) die "'nvm run --silent' should not warn; got >${RUN_SILENT_STDERR}<" ;;
|
||||
esac
|
||||
|
||||
cleanup
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
cd "${ORIG_PWD}" 2>/dev/null || true
|
||||
[ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
export NVM_DIR="$(cd ../.. && pwd)"
|
||||
|
||||
: nvm.sh
|
||||
\. ../../nvm.sh
|
||||
|
||||
\. ../common.sh
|
||||
|
||||
ORIG_PWD="$(pwd)"
|
||||
|
||||
# Run from a fresh, empty directory so the "no version + no .nvmrc" cases
|
||||
# (install/run/which) are not masked by an ambient .nvmrc above the test dir.
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
cd "${TMP_DIR}" || die "could not cd to temp dir"
|
||||
|
||||
# Asserts a subcommand emits the given focused usage line (not the full help
|
||||
# dump) on stderr, and exits 127.
|
||||
assert_usage() {
|
||||
local EXPECTED_LINE
|
||||
EXPECTED_LINE="$1"
|
||||
shift
|
||||
|
||||
try_err "$@"
|
||||
|
||||
case "${CAPTURED_STDERR}" in
|
||||
*"${EXPECTED_LINE}"*) ;;
|
||||
*) die "\`$*\` did not show focused usage >${EXPECTED_LINE}<; got >${CAPTURED_STDERR}<" ;;
|
||||
esac
|
||||
# the focused usage should NOT be the full help dump
|
||||
case "${CAPTURED_STDERR}" in
|
||||
*'Show this message'*) die "\`$*\` dumped full help instead of a focused usage" ;;
|
||||
esac
|
||||
[ "_${CAPTURED_EXIT_CODE}" = "_127" ] \
|
||||
|| die "\`$*\` expected exit code 127; got ${CAPTURED_EXIT_CODE}"
|
||||
}
|
||||
|
||||
assert_usage 'Usage: nvm cache dir' nvm cache bogus
|
||||
assert_usage 'Usage: nvm install [<version>]' nvm install
|
||||
assert_usage 'Usage: nvm run [<version>] [<args>]' nvm run
|
||||
assert_usage 'Usage: nvm which [current | <version>]' nvm which
|
||||
assert_usage 'Usage: nvm uninstall <version>' nvm uninstall
|
||||
assert_usage 'Usage: nvm uninstall <version>' nvm uninstall a b
|
||||
assert_usage 'Usage: nvm unalias <name>' nvm unalias
|
||||
assert_usage 'Usage: nvm unalias <name>' nvm unalias a b
|
||||
assert_usage 'Usage: nvm install-latest-npm' nvm install-latest-npm extra
|
||||
assert_usage 'Usage: nvm reinstall-packages <version>' nvm reinstall-packages
|
||||
assert_usage 'Usage: nvm copy-packages <version>' nvm copy-packages a b
|
||||
|
||||
# `nvm use` reaches its focused-usage guard only when version resolution returns
|
||||
# an empty string. From the CLI that cannot happen: an omitted version is caught
|
||||
# earlier (the `Please see ... nvmrc` branch), and an unresolvable non-empty
|
||||
# version yields the "N/A" sentinel, never "". The branch is a defensive guard,
|
||||
# so drive it directly by stubbing the resolver to return empty. Keep this last:
|
||||
# the stub stays in effect for the rest of the shell.
|
||||
nvm_match_version() { nvm_echo ''; }
|
||||
assert_usage 'Usage: nvm use [<version>]' nvm use foo
|
||||
|
||||
cleanup
|
||||
39
test/fast/Unit tests/nvm_rc_version errors when no version and no .nvmrc
Executable file
39
test/fast/Unit tests/nvm_rc_version errors when no version and no .nvmrc
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
cleanup() {
|
||||
cd "${ORIG_PWD}" 2>/dev/null || true
|
||||
[ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"
|
||||
}
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
\. ../../common.sh
|
||||
|
||||
ORIG_PWD="$(pwd)"
|
||||
|
||||
# Run from a fresh, empty directory so no ambient .nvmrc above the test dir
|
||||
# is found by the upward lookup.
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
cd "${TMP_DIR}" || die "could not cd to temp dir"
|
||||
|
||||
# The message must name both halves of the problem: no argument AND no .nvmrc.
|
||||
try_err nvm_rc_version
|
||||
EXPECTED='No version provided and no .nvmrc file found'
|
||||
[ "_${CAPTURED_STDERR}" = "_${EXPECTED}" ] \
|
||||
|| die "nvm_rc_version did not print >${EXPECTED}<; got >${CAPTURED_STDERR}<"
|
||||
[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \
|
||||
|| die "nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"
|
||||
|
||||
# NVM_SILENT suppresses the message but the call still fails.
|
||||
export NVM_SILENT=1
|
||||
try_err nvm_rc_version
|
||||
unset NVM_SILENT
|
||||
[ -z "${CAPTURED_STDERR}" ] \
|
||||
|| die "NVM_SILENT nvm_rc_version should be silent; got >${CAPTURED_STDERR}<"
|
||||
[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \
|
||||
|| die "NVM_SILENT nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"
|
||||
|
||||
cleanup
|
||||
Reference in New Issue
Block a user