diff --git a/nvm.sh b/nvm.sh index 268c080706e..4b229a7e8e4 100644 --- a/nvm.sh +++ b/nvm.sh @@ -113,6 +113,7 @@ nvm_download() { -e 's/-L //' \ -e 's/-I /--server-response /' \ -e 's/-s /-q /' \ + -e 's/-sS /-nv /' \ -e 's/-o /-O /' \ -e 's/-C - /-c /') # shellcheck disable=SC2086 @@ -1715,10 +1716,16 @@ nvm_install_binary() { local TMPDIR local VERSION_PATH + local PROGRESS_BAR local NODE_OR_IOJS if [ "${FLAVOR}" = 'node' ]; then NODE_OR_IOJS="${FLAVOR}" fi + if [ "${NVM_NO_PROGRESS-}" = "1" ]; then + PROGRESS_BAR="-sS" + else + PROGRESS_BAR="--progress-bar" + fi nvm_echo "Downloading and installing ${NODE_OR_IOJS-} ${VERSION}..." TARBALL="$(nvm_download_artifact "${FLAVOR}" binary "${TYPE-}" "${VERSION}" | command tail -1)" if [ -f "${TARBALL}" ]; then @@ -1877,7 +1884,7 @@ nvm_download_artifact() { command rm -rf "${TARBALL}" fi nvm_err "Downloading ${TARBALL_URL}..." - nvm_download -L -C - --progress-bar "${TARBALL_URL}" -o "${TARBALL}" || ( + nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${TARBALL}" || ( command rm -rf "${TARBALL}" "${tmpdir}" nvm_err "Binary download from ${TARBALL_URL} failed, trying source." return 4 @@ -2023,7 +2030,13 @@ nvm_install_source() { local TARBALL local TMPDIR local VERSION_PATH + local PROGRESS_BAR + if [ "${NVM_NO_PROGRESS-}" = "1" ]; then + PROGRESS_BAR="-sS" + else + PROGRESS_BAR="--progress-bar" + fi TARBALL="$(nvm_download_artifact "${FLAVOR}" source "${TYPE}" "${VERSION}" | command tail -1)" && \ [ -f "${TARBALL}" ] && \ TMPDIR="$(dirname "${TARBALL}")/files" && \ @@ -2481,7 +2494,9 @@ nvm() { fi local nobinary + local noprogress nobinary=0 + noprogress=0 local LTS local NVM_UPGRADE_NPM NVM_UPGRADE_NPM=0 @@ -2497,6 +2512,10 @@ nvm() { nvm_get_make_jobs "$1" shift # consume job count ;; + --no-progress) + noprogress=1 + shift + ;; --lts) LTS='*' shift @@ -2705,7 +2724,7 @@ nvm() { # skip binary install if "nobinary" option specified. if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then - nvm_install_binary "${FLAVOR}" std "${VERSION}" + NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}" EXIT_CODE=$? fi if [ "$EXIT_CODE" -ne 0 ]; then @@ -2713,7 +2732,7 @@ nvm() { nvm_get_make_jobs fi - nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}" + NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}" EXIT_CODE=$? fi diff --git a/test/fast/Unit tests/nvm_install_no_progress_bar b/test/fast/Unit tests/nvm_install_no_progress_bar new file mode 100644 index 00000000000..d43194dc879 --- /dev/null +++ b/test/fast/Unit tests/nvm_install_no_progress_bar @@ -0,0 +1,43 @@ +#!/bin/sh + +set -e + +cleanup () { + nvm cache clear + nvm deactivate + rm -rf ${NVM_DIR}/v* + nvm unalias default +} + +die () { >&2 echo "$@" ; cleanup ; exit 1; } + +\. ../../../nvm.sh + +nvm_has_colors() { return 1 ; } + +cleanup + +OUTPUT="$(2>&1 nvm install --no-progress v0.12.18)" +EXPECTED_OUTPUT="Downloading and installing node v0.12.18... +Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz... +Computing checksum with sha256sum +Checksums matched! +Now using node v0.12.18 (npm v2.15.11) +Creating default alias: default -> v0.12.18 *" + +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + +cleanup + +OUTPUT="$(2>&1 nvm install v0.12.18)" +EXPECTED_OUTPUT="Downloading and installing node v0.12.18... +Downloading https://nodejs.org/dist/v0.12.18/node-v0.12.18-linux-x64.tar.xz... +######################################################################## 100.0% +Computing checksum with sha256sum +Checksums matched! +Now using node v0.12.18 (npm v2.15.11) +Creating default alias: default -> v0.12.18 *" + +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + +cleanup