From 898124fd60b80b432d7600276ec80dd499b74666 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 25 Oct 2026 11:42:45 -0700 Subject: [PATCH] [Fix] `nvm debug`: don't let the shell read stdin when asked for its version busybox's shells have no `--version`, and start an interactive shell instead, so with `$SHELL` set to busybox `sh` on a terminal, `nvm debug` waited for input forever, which hung the alpine `sh` CI lanes in the "mirror URL credentials are masked in output" test. Like the other busybox tools, its version now comes from `--help`, and every shell is given no stdin to read. --- nvm.sh | 9 ++- ...s not read stdin to find the shell version | 58 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 test/fast/Unit tests/nvm debug does not read stdin to find the shell version diff --git a/nvm.sh b/nvm.sh index 83431490..2719409d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -4268,7 +4268,14 @@ nvm() { nvm_err "\${NPM_CONFIG_PREFIX}: '$(nvm_sanitize_path "${NPM_CONFIG_PREFIX-}")'" nvm_err "\$NVM_NODEJS_ORG_MIRROR: '$(nvm_sanitize_url "${NVM_NODEJS_ORG_MIRROR-}")'" nvm_err "\$NVM_IOJS_ORG_MIRROR: '$(nvm_sanitize_url "${NVM_IOJS_ORG_MIRROR-}")'" - nvm_err "shell version: '$(${SHELL} --version | command head -n 1)'" + local NVM_SHELL_VERSION + # busybox's shells have no `--version`, and start an interactive shell instead + if command ls -l "$(command -v "${SHELL}" 2>/dev/null)" 2>/dev/null | nvm_grep -q busybox; then + NVM_SHELL_VERSION="$(${SHELL} --help 2>&1 /dev/null)'" if [ "$(nvm_get_os)" = "darwin" ] && nvm_has sw_vers; then diff --git a/test/fast/Unit tests/nvm debug does not read stdin to find the shell version b/test/fast/Unit tests/nvm debug does not read stdin to find the shell version new file mode 100755 index 00000000..559a7987 --- /dev/null +++ b/test/fast/Unit tests/nvm debug does not read stdin to find the shell version @@ -0,0 +1,58 @@ +#!/bin/sh + +TMP_DIR='' + +cleanup () { + case "${TMP_DIR}" in + /*) rm -rf "${TMP_DIR}" ;; + esac +} + +die () { echo "$@" ; cleanup ; exit 1; } + +: nvm.sh +\. ../../../nvm.sh + +TMP_DIR="$(mktemp -d)" + +# like busybox's `sh`, which starts an interactive shell for `--version` +cat > "${TMP_DIR}/busybox" <<'FAKE' +#!/bin/sh +if [ "$1" = '--help' ]; then + echo 'BusyBox v9.9.9 (fake) multi-call binary.' +elif read -r LINE; then + echo 'interactive shell read stdin' +fi +FAKE +chmod +x "${TMP_DIR}/busybox" || die 'could not make the fake busybox' +ln -s "${TMP_DIR}/busybox" "${TMP_DIR}/sh" || die 'could not link the fake busybox sh' + +cat > "${TMP_DIR}/fakesh" <<'FAKE' +#!/bin/sh +if read -r LINE; then + echo 'fake shell read stdin' +else + echo 'fake shell 1.0' +fi +FAKE +chmod +x "${TMP_DIR}/fakesh" || die 'could not make the fake shell' + +OUTPUT="$(SHELL="${TMP_DIR}/sh" nvm debug 2>&1 <${OUTPUT}<" ;; +esac + +OUTPUT="$(SHELL="${TMP_DIR}/fakesh" nvm debug 2>&1 <${OUTPUT}<" ;; +esac + +cleanup