Skip to content
Myr

[Fix] `nvm exec`: Do a version check on `nvm-exec`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise.

authored by Bark · committed by Jordan Harband · parent 0fbe3a6 · Browse files · 3 files+30 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+30 added−7 removed

  • tests:+24 added−4 removed
  • other:+6 added−3 removed

3 files+30 added−7 removed

modified:test/fast/Set Colors/nvm_print_versions calls nvm_get_colors+4 added-4 removed
1#!/bin/sh23\. ../../../nvm.sh45set -e5#set -e #nvm use system returns 127 and No system set message67die () {8 # echo "$@" ;9 echo "Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
13 unmodified lines
2324# default system color25nvm use system26OUTPUT=$(nvm_print_versions system)27FORMAT="\033[0;32m-> %12s\033[0m"27FORMAT="\033[0;33m%15s\033[0m"28VERSION='system'29EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")3031[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
1 unmodified line
33nvm_ls_current() { echo "current";}3435# default current color36OUTPUT=$(nvm_print_versions current)37FORMAT="\033[0;32m-> %12s\033[0m"37FORMAT="\033[0;32m->%13s\033[0m"38VERSION="current"39EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")4041[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die4243# custom current color44nvm set-colors YCMGR45OUTPUT=$(nvm_print_versions current)46FORMAT="\033[1;35m-> %12s\033[0m"46FORMAT="\033[1;35m->%13s\033[0m"47VERSION="current"48EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")4950[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die
2 unmodified lines
added:test/fast/Running 'nvm-exec' should display required node version+20 added
1#!/bin/bash23set -x4\. ../../nvm.sh56die () { echo "$@" ; rm .nvmrc ; exit 1; }78NVM_TEST_VERSION=v0.42910# Write it to nvmrc11echo "$NVM_TEST_VERSION" > .nvmrc1213OUTPUT="$(../../nvm-exec 2>&1)";14EXPECTED="N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.1516You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.17No NODE_VERSION provided; no .nvmrc file found";1819# Skip install, we want to test the error message20[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"
modified:nvm-exec+6 added-3 removed
7 unmodified lines
8\. "$DIR/nvm.sh" --no-use910if [ -n "$NODE_VERSION" ]; then11 nvm use "$NODE_VERSION" > /dev/null || exit 12712else13 nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";12elif ! nvm use >/dev/null 2>&1; then13 echo "No NODE_VERSION provided; no .nvmrc file found" >&214 exit 12714 if ! nvm use >/dev/null 2>&1; then15 echo "No NODE_VERSION provided; no .nvmrc file found" >&216 exit 12717 fi18fi1920exec "$@"