From 50480e49b978a52f865285181d32d720026db001 Mon Sep 17 00:00:00 2001 From: Bark Date: Wed, 6 Mar 2024 16:03:10 +0200 Subject: [PATCH] [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. --- nvm-exec | 1 + ...-exec' should display required node version | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100755 test/fast/Running 'nvm-exec' should display required node version diff --git a/nvm-exec b/nvm-exec index 44d5ddb116..c082f8fb2b 100755 --- a/nvm-exec +++ b/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 diff --git a/test/fast/Running 'nvm-exec' should display required node version b/test/fast/Running 'nvm-exec' should display required node version new file mode 100755 index 0000000000..17f79e0388 --- /dev/null +++ b/test/fast/Running 'nvm-exec' should display required node version @@ -0,0 +1,18 @@ +#!/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}")