Compare commits

...

10 Commits

Author SHA1 Message Date
Bark
f0fdd7509c
Merge 8066dc8511 into 759f70f196 2025-02-07 14:50:11 -06:00
Jordan Harband
759f70f196
[Refactor] prefer case over if/else chains 2025-02-04 22:45:35 -08:00
Jordan Harband
06a9179309
[Refactor] combine sed -e invocations/arguments 2025-02-04 15:55:10 -08:00
Stiliyan Tonev (Bark)
8066dc8511 remove test from slow folder 2024-07-31 16:44:25 +03:00
Stiliyan Tonev (Bark)
59b40b8ae7 Rookie mistake from my side, forgot to clean-up the nvmrc, which caused other tests to fail.
Updated version color printing test because it did not pass.
2024-07-31 16:42:03 +03:00
Stiliyan Tonev (Bark)
ce777fa5cf Merge branch 'fork-dev' of https://github.com/userwiths/nvm into fork-dev 2024-07-31 12:02:53 +03:00
Stiliyan Tonev (Bark)
650b069bb8 Seems changes done in docker do not persist, had to reapply them 2024-07-30 11:56:35 +03:00
Stiliyan Tonev (Bark)
5a28180ed6 tests: Add test to check if the message contains the relevant information. 2024-07-30 11:51:32 +03:00
Bark
05feeaa927
[Fix] nvm exec: Do a version check on nvm-exec
This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise.
2024-03-06 16:03:10 +02:00
Bark
e2ff1e7f08 fix: Do a version check on nvm-exec
This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise.
2024-03-06 16:03:10 +02:00
4 changed files with 50 additions and 25 deletions

View File

@ -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

47
nvm.sh
View File

@ -136,15 +136,17 @@ nvm_download() {
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
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 /')
ARGS=$(nvm_echo "$@" | command sed "
s/--progress-bar /--progress=bar /
s/--compressed //
s/--fail //
s/-L //
s/-I /--server-response /
s/-s /-q /
s/-sS /-nv /
s/-o /-O /
s/-C - /-c /
")
if [ -n "${NVM_AUTH_HEADER:-}" ]; then
ARGS="${ARGS} --header \"${NVM_AUTH_HEADER}\""
@ -1413,11 +1415,11 @@ nvm_add_iojs_prefix() {
nvm_strip_iojs_prefix() {
local NVM_IOJS_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
if [ "${1-}" = "${NVM_IOJS_PREFIX}" ]; then
nvm_echo
else
nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}"
fi
case "${1-}" in
"${NVM_IOJS_PREFIX}") nvm_echo ;;
*) nvm_echo "${1#"${NVM_IOJS_PREFIX}"-}" ;;
esac
}
nvm_ls() {
@ -1549,12 +1551,15 @@ nvm_ls() {
fi
if [ "${NVM_ADD_SYSTEM-}" = true ]; then
if [ -z "${PATTERN}" ] || [ "${PATTERN}" = 'v' ]; then
VERSIONS="${VERSIONS}
case "${PATTERN}" in
'' | v)
VERSIONS="${VERSIONS}
system"
elif [ "${PATTERN}" = 'system' ]; then
VERSIONS="system"
fi
;;
system)
VERSIONS="system"
;;
esac
fi
if [ -z "${VERSIONS}" ]; then
@ -1688,7 +1693,7 @@ EOF
LTS="${LTS#lts/}"
fi
VERSIONS="$({ command awk -v lts="${LTS-}" '{
VERSIONS="$( { command awk -v lts="${LTS-}" '{
if (!$1) { next }
if (lts && $10 ~ /^\-?$/) { next }
if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next }
@ -2732,7 +2737,7 @@ nvm_npm_global_modules() {
local NPMLIST
local VERSION
VERSION="$1"
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')
NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed -e '1d' -e '/UNMET PEER DEPENDENCY/d')
local INSTALLS
INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)

View 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

View File

@ -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}")