Skip to content
Myr

[New] Dynamically detect if curl supports `--compressed`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Peter Dave Hello · committed by Peter Dave Hello · parent 6a3b1dd · Browse files · 3 files+60 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+60 added−3 removed

  • tests:+45 added−1 removed
  • other:+15 added−2 removed

3 files+60 added−3 removed

added:test/fast/Unit tests/nvm_curl_libz_support+39 added
1#!/bin/sh23cleanup() {4 unset -f curl5}67die() { cleanup; echo "$@" ; exit 1; }89\. ../../../nvm.sh1011curl() {12 # curl with libz feature13 if [ $# -ne 1 ] || [ "$1" != "-V" ]; then14 die "This fake curl only takes one parameter -V"15 fi16 echo "17curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.318Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp19Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets"20}2122nvm_curl_libz_support || die "nvm_curl_libz_support should return 0"2324unset -f curl2526curl() {27 # curl without libz feature28 if [ "$#" -ne 1 ] || [ "$1" != "-V" ]; then29 die "This fake curl only takes one parameter -V"30 fi31 echo "32curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3233Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp34Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL TLS-SRP UnixSockets"35}3637! nvm_curl_libz_support || die "nvm_curl_libz_support should return 1"3839unset -f curl
modified:test/slow/nvm_get_latest/nvm_get_latest+6 added-1 removed
12 unmodified lines
13EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null"14EXPECTED_WGET_ARGS="http://latest.nvm.sh --server-response -O /dev/null"1516curl() {17 if [ $# -eq 1 ] && [ "$1" = "-V" ]; then18 echo "19curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.320Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp21Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets"17 if [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then22 elif [ "_$*" != "_$EXPECTED_CURL_ARGS" ]; then23 echo >&2 "expected args ($EXPECTED_CURL_ARGS), got ($*)"24 return 125 else26 echo $URL
96 unmodified lines
modified:nvm.sh+15 added-2 removed
55 unmodified lines
56 fi57 [ "${NVM_COLORS:--1}" -ge 8 ]58}5960nvm_curl_libz_support() {61 curl -V | grep "^Features:" | grep -q "libz"62}6364nvm_get_latest() {65 local NVM_LATEST_URL66 local CURL_COMPRESSED_FLAG67 if nvm_curl_libz_support; then68 CURL_COMPRESSED_FLAG="--compressed"69 fi70 if nvm_has "curl"; then63 NVM_LATEST_URL="$(curl --compressed -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"71 NVM_LATEST_URL="$(curl "${CURL_COMPRESSED_FLAG:-}" -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"72 elif nvm_has "wget"; then73 NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"74 else75 nvm_err 'nvm needs curl or wget to proceed.'
6 unmodified lines
82 nvm_echo "${NVM_LATEST_URL##*/}"83}8485nvm_download() {86 local CURL_COMPRESSED_FLAG87 if nvm_curl_libz_support; then88 CURL_COMPRESSED_FLAG="--compressed"89 fi90 if nvm_has "curl"; then79 curl --compressed -q "$@"91 curl "${CURL_COMPRESSED_FLAG:-}" -q "$@"92 elif nvm_has "wget"; then93 # Emulate curl with wget94 ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \95 -e 's/--compressed //' \
3107 unmodified lines
3203 nvm_list_aliases nvm_make_alias nvm_print_alias_path \3204 nvm_print_default_alias nvm_print_formatted_alias nvm_resolve_local_alias \3205 nvm_sanitize_path nvm_has_colors nvm_process_parameters \3206 node_version_has_solaris_binary iojs_version_has_solaris_binary \3207 nvm_curl_libz_support \3208 > /dev/null 2>&13209 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \3210 NVM_CD_FLAGS NVM_BIN NVM_MAKE_JOBS \3211 > /dev/null 2>&1
92 unmodified lines