From 6cef0edd1823ac032804f4fa4d27a4e670848720 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 21 Oct 2026 12:44:44 -0700 Subject: [PATCH] [Fix] `nvm_ls`: no blank line before `system` when nothing is installed `nvm ls` then printed an empty row ahead of the system version. --- nvm.sh | 8 ++--- .../nvm_ls with only a system version | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100755 test/fast/Unit tests/nvm_ls with only a system version diff --git a/nvm.sh b/nvm.sh index feff68ff..19feb7f6 100755 --- a/nvm.sh +++ b/nvm.sh @@ -2193,11 +2193,11 @@ nvm_ls() { case "${PATTERN}" in '' | v) if [ -n "${SYSTEM_VERSION}" ]; then - VERSIONS="${VERSIONS} -system ${SYSTEM_VERSION}" + VERSIONS="${VERSIONS:+${VERSIONS} +}system ${SYSTEM_VERSION}" else - VERSIONS="${VERSIONS} -system" + VERSIONS="${VERSIONS:+${VERSIONS} +}system" fi ;; system) diff --git a/test/fast/Unit tests/nvm_ls with only a system version b/test/fast/Unit tests/nvm_ls with only a system version new file mode 100755 index 00000000..c6be5afe --- /dev/null +++ b/test/fast/Unit tests/nvm_ls with only a system version @@ -0,0 +1,31 @@ +#!/bin/sh + +ORIG_NVM_DIR="${NVM_DIR}" +TMP_DIR='' + +cleanup () { + case "${TMP_DIR}" in + /*) rm -rf "${TMP_DIR}" ;; + esac + NVM_DIR="${ORIG_NVM_DIR}" + export NVM_DIR +} + +die () { echo "$@" ; cleanup ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +TMP_DIR="$(mktemp -d)" +NVM_DIR="${TMP_DIR}/nvm" +export NVM_DIR +mkdir -p "${NVM_DIR}" || die 'could not create NVM_DIR' + +nvm_has_system_node() { return 0; } +nvm_has_system_iojs() { return 1; } +node() { echo 'v20.0.0'; } + +OUTPUT="$(nvm_ls)" +[ "_${OUTPUT}" = '_system v20.0.0' ] || die "nvm_ls with nothing installed should print only the system version; got >${OUTPUT}<" + +cleanup