Skip to content

Commit

Permalink
[New] Support --no-progress for nvm install, close nvm-sh#1079
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDaveHello committed Apr 24, 2018
1 parent d5dacdf commit 218439b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
25 changes: 22 additions & 3 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" && \
Expand Down Expand Up @@ -2481,7 +2494,9 @@ nvm() {
fi

local nobinary
local noprogress
nobinary=0
noprogress=0
local LTS
local NVM_UPGRADE_NPM
NVM_UPGRADE_NPM=0
Expand All @@ -2497,6 +2512,10 @@ nvm() {
nvm_get_make_jobs "$1"
shift # consume job count
;;
--no-progress)
noprogress=1
shift
;;
--lts)
LTS='*'
shift
Expand Down Expand Up @@ -2705,15 +2724,15 @@ 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
if [ -z "${NVM_MAKE_JOBS-}" ]; then
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

Expand Down
43 changes: 43 additions & 0 deletions test/fast/Unit tests/nvm_install_no_progress_bar
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 218439b

Please sign in to comment.