mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-20 04:23:43 +00:00
Compare commits
9 Commits
b0ea2afe05
...
1d87a73f59
Author | SHA1 | Date | |
---|---|---|---|
![]() |
1d87a73f59 | ||
![]() |
5dc31ac51b | ||
![]() |
8066dc8511 | ||
![]() |
59b40b8ae7 | ||
![]() |
ce777fa5cf | ||
![]() |
650b069bb8 | ||
![]() |
5a28180ed6 | ||
![]() |
05feeaa927 | ||
![]() |
e2ff1e7f08 |
1
nvm-exec
1
nvm-exec
@ -7,6 +7,7 @@ unset NVM_CD_FLAGS
|
||||
# shellcheck disable=SC1090,SC1091
|
||||
\. "$DIR/nvm.sh" --no-use
|
||||
|
||||
nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
|
||||
if [ -n "$NODE_VERSION" ]; then
|
||||
nvm use "$NODE_VERSION" > /dev/null || exit 127
|
||||
elif ! nvm use >/dev/null 2>&1; then
|
||||
|
10
nvm.sh
10
nvm.sh
@ -700,10 +700,12 @@ nvm_ensure_version_installed() {
|
||||
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
||||
fi
|
||||
nvm_err ""
|
||||
if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
||||
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`.'
|
||||
if [ "${PROVIDED_VERSION}" = 'lts' ]; then
|
||||
nvm_err '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
||||
elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
||||
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
|
||||
return 1
|
||||
fi
|
||||
|
19
test/fast/Running 'nvm-exec' should display required node version
Executable file
19
test/fast/Running 'nvm-exec' should display required node version
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
\. ../../nvm.sh
|
||||
|
||||
NVM_TEST_VERSION=v0.42
|
||||
|
||||
# Write it to nvmrc
|
||||
echo "$NVM_TEST_VERSION" > .nvmrc
|
||||
|
||||
OUTPUT="$(../../nvm-exec 2>&1)";
|
||||
EXPECTED="N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.
|
||||
|
||||
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
|
||||
No NODE_VERSION provided; no .nvmrc file found";
|
||||
|
||||
# Skip install, we want to test the error message
|
||||
diff <(echo "${EXPECTED}") <(echo "${OUTPUT}")
|
||||
rm .nvmrc
|
@ -2,7 +2,7 @@
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
set -e
|
||||
#set -e #nvm use system returns 127 and No system set message
|
||||
|
||||
die () {
|
||||
# echo "$@" ;
|
||||
@ -24,7 +24,7 @@ fi
|
||||
# default system color
|
||||
nvm use system
|
||||
OUTPUT=$(nvm_print_versions system)
|
||||
FORMAT="\033[0;32m-> %12s\033[0m"
|
||||
FORMAT="\033[0;33m%15s\033[0m"
|
||||
VERSION='system'
|
||||
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||
|
||||
@ -34,7 +34,7 @@ nvm_ls_current() { echo "current";}
|
||||
|
||||
# default current color
|
||||
OUTPUT=$(nvm_print_versions current)
|
||||
FORMAT="\033[0;32m-> %12s\033[0m"
|
||||
FORMAT="\033[0;32m->%13s\033[0m"
|
||||
VERSION="current"
|
||||
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||
|
||||
@ -43,7 +43,7 @@ EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||
# custom current color
|
||||
nvm set-colors YCMGR
|
||||
OUTPUT=$(nvm_print_versions current)
|
||||
FORMAT="\033[1;35m-> %12s\033[0m"
|
||||
FORMAT="\033[1;35m->%13s\033[0m"
|
||||
VERSION="current"
|
||||
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
|
||||
|
||||
|
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"
|
Loading…
x
Reference in New Issue
Block a user