From 9895f4b48cf182150e5a38d81e98f86705878cd5 Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 09:21:42 +0530 Subject: [PATCH 1/6] Refactor nvm_remote_version to handle "lts" as a special case --- nvm.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nvm.sh b/nvm.sh index 9eeede2..d06bb9f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -748,6 +748,9 @@ nvm_remote_version() { "$(nvm_iojs_prefix)") VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs | command tail -1)" &&: ;; + "lts") + VERSION="$(NVM_LTS="lts/*" nvm_ls_remote | command tail -1)" &&: + ;; *) VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "${PATTERN}")" &&: ;; From d2e1836fcd2314e56a8cfa414842853424926e7a Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 10:07:46 +0530 Subject: [PATCH 2/6] Removed handling of lts as an alias and modified error handling for `nvm use lts` --- nvm.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/nvm.sh b/nvm.sh index d06bb9f..c28c5b5 100755 --- a/nvm.sh +++ b/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 "You 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 @@ -748,9 +750,6 @@ nvm_remote_version() { "$(nvm_iojs_prefix)") VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs | command tail -1)" &&: ;; - "lts") - VERSION="$(NVM_LTS="lts/*" nvm_ls_remote | command tail -1)" &&: - ;; *) VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "${PATTERN}")" &&: ;; From 0ad41dd1c2f7fcf299c9dac32ef82b328934f458 Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 11:32:56 +0530 Subject: [PATCH 3/6] test for 'nvm use lts' to show actionable error --- ...nning 'nvm use lts' shows actionable error | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/slow/nvm use/Running 'nvm use lts' shows actionable error diff --git a/test/slow/nvm use/Running 'nvm use lts' shows actionable error b/test/slow/nvm use/Running 'nvm use lts' shows actionable error new file mode 100644 index 0000000..0f766b6 --- /dev/null +++ b/test/slow/nvm use/Running 'nvm use lts' shows actionable error @@ -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="You 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" \ No newline at end of file From d8d653147c82c9c712a37093f89710eb82db261d Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 11:38:17 +0530 Subject: [PATCH 4/6] fixed lint error - final newline --- test/slow/nvm use/Running 'nvm use lts' shows actionable error | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/slow/nvm use/Running 'nvm use lts' shows actionable error b/test/slow/nvm use/Running 'nvm use lts' shows actionable error index 0f766b6..f5555a5 100644 --- a/test/slow/nvm use/Running 'nvm use lts' shows actionable error +++ b/test/slow/nvm use/Running 'nvm use lts' shows actionable error @@ -16,4 +16,4 @@ EXPECTED_ERROR="You need to run \`nvm install --lts\` to install and \`nvm use - # 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" \ No newline at end of file + || die "Expected error message not found. Got: $ERROR_OUTPUT" From 68fe9f1b800201f79d84913a2f3bbf55187f0b75 Mon Sep 17 00:00:00 2001 From: Reetik Rajan <44093575+r4reetik@users.noreply.github.com> Date: Sat, 5 Oct 2024 12:09:32 +0530 Subject: [PATCH 5/6] accepting suggestion Co-authored-by: Jordan Harband --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index c28c5b5..5f785f8 100755 --- a/nvm.sh +++ b/nvm.sh @@ -701,7 +701,7 @@ nvm_ensure_version_installed() { fi nvm_err "" if [ "${PROVIDED_VERSION}" = 'lts' ]; then - nvm_err "You need to run \`nvm install --lts\` to install and \`nvm use --lts\` to use it." + 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 From 70afc73fa5457068282529e36549b5b1895c872d Mon Sep 17 00:00:00 2001 From: Reetik Rajan Date: Sat, 5 Oct 2024 12:11:21 +0530 Subject: [PATCH 6/6] updated error message test --- test/slow/nvm use/Running 'nvm use lts' shows actionable error | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/slow/nvm use/Running 'nvm use lts' shows actionable error b/test/slow/nvm use/Running 'nvm use lts' shows actionable error index f5555a5..903abac 100644 --- a/test/slow/nvm use/Running 'nvm use lts' shows actionable error +++ b/test/slow/nvm use/Running 'nvm use lts' shows actionable error @@ -12,7 +12,7 @@ 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="You need to run \`nvm install --lts\` to install and \`nvm use --lts\` to use it." +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" \