Skip to content

Commit 0f4bfc6

Browse files
userwithsljharb
authored andcommitted
[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.
1 parent 24deac7 commit 0f4bfc6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

nvm-exec

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ unset NVM_CD_FLAGS
77
# shellcheck disable=SC1090,SC1091
88
\. "$DIR/nvm.sh" --no-use
99

10+
nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
1011
if [ -n "$NODE_VERSION" ]; then
1112
nvm use "$NODE_VERSION" > /dev/null || exit 127
1213
elif ! nvm use >/dev/null 2>&1; then
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -x
4+
\. ../../nvm.sh
5+
6+
NVM_TEST_VERSION=v0.42
7+
8+
# Write it to nvmrc
9+
echo "$NVM_TEST_VERSION" > .nvmrc
10+
11+
OUTPUT="$(../../nvm-exec 2>&1)";
12+
EXPECTED="N/A: version \`${NVM_TEST_VERSION}\` is not yet installed.
13+
14+
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
15+
No NODE_VERSION provided; no .nvmrc file found";
16+
17+
# Skip install, we want to test the error message
18+
diff <(echo "${EXPECTED}") <(echo "${OUTPUT}")

0 commit comments

Comments
 (0)