[Refactor] add `nvm_get_artifact_compression`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by nmarghetti · committed by Jordan Harband · parent a5742d4 · Browse files · 3 files·+40 added−10 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+40 added−10 removed
- tests:+18 added−2 removed
- other:+22 added−8 removed
Provenance
- Commit
d396181- Tree
a457301- Author
nmarghetti <marghettinicolas@hotmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
a5742d4
3 files changed+40 added−10 removed
added:test/fast/Unit tests/nvm_get_artifact_compression+16 added
1+#!/bin/sh2+3+cleanup () {4+ unset -f die cleanup5+}6+die () { echo "$@" ; cleanup ; exit 1; }7+8+\. ../../../nvm.sh9+10+# nvm_get_artifact_compression by default11+[ "$(nvm_get_artifact_compression)" = 'tar.gz' ] || die 'nvm_get_artifact_compression should return "tar.gz" by default'12+13+# nvm_get_artifact_compression with xz14+[ "$(nvm_get_artifact_compression "14.0.0")" = 'tar.xz' ] || die 'nvm_get_artifact_compression should return "tar.xz" for this version'15+16+cleanupmodified:test/fast/Unit tests/nvm_get_checksum+2 added-2 removed
29 unmodified lines30 31 nvm_get_checksum_alg() {32 echo 'sha-256'33 }34-OUTPUT="$(nvm_get_checksum node std foo bar baz)"34+OUTPUT="$(nvm_get_checksum node std foo bar tar.baz)"35 EXPECTED_OUTPUT="mirror-node-std/foo/SHASUMS256.txt"36 [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"37 38 nvm_get_checksum_alg() {39 echo 'sha-1'40 }41-OUTPUT="$(nvm_get_checksum iojs std foo bar baz)"41+OUTPUT="$(nvm_get_checksum iojs std foo bar tar.baz)"42 EXPECTED_OUTPUT="mirror-iojs-std/foo/SHASUMS.txt"43 [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"44 45 cleanupmodified:nvm.sh+22 added-8 removed
1557 unmodified lines1558 else1559 SHASUMS_URL="${MIRROR}/${3}/SHASUMS.txt"1560 fi1561 1562- nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.tar.${5}\" == \$2) print \$1}"1562+ nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.${5}\" == \$2) print \$1}"1563 }1564 1565 nvm_print_versions() {1566 local VERSION415 unmodified lines1982 nvm_echo "${FLAVOR}-${VERSION}"1983 fi1984 }1985 1986+nvm_get_artifact_compression() {1987+ local VERSION1988+ VERSION="${1-}"1989+1990+ local NVM_OS1991+ NVM_OS="$(nvm_get_os)"1992+1993+ local COMPRESSION1994+ COMPRESSION='tar.gz'1995+ if nvm_supports_xz "${VERSION}"; then1996+ COMPRESSION='tar.xz'1997+ fi1998+1999+ nvm_echo "${COMPRESSION}"2000+}2001+2002 # args: flavor, kind, type, version2003 nvm_download_artifact() {2004 local FLAVOR2005 case "${1-}" in38 unmodified lines2044 local SLUG2045 SLUG="$(nvm_get_download_slug "${FLAVOR}" "${KIND}" "${VERSION}")"2046 2047 local COMPRESSION2032- COMPRESSION='gz'2033- if nvm_supports_xz "${VERSION}"; then2034- COMPRESSION='xz'2035- fi2048+ COMPRESSION="$(nvm_get_artifact_compression "${VERSION}")"2049 2050 local CHECKSUM2051 CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")"2052 8 unmodified lines2061 return 32062 )2063 2064 local TARBALL2052- TARBALL="${tmpdir}/${SLUG}.tar.${COMPRESSION}"2065+ TARBALL="${tmpdir}/${SLUG}.${COMPRESSION}"2066 local TARBALL_URL2067 if nvm_version_greater_than_or_equal_to "${VERSION}" 0.1.14; then2055- TARBALL_URL="${MIRROR}/${VERSION}/${SLUG}.tar.${COMPRESSION}"2068+ TARBALL_URL="${MIRROR}/${VERSION}/${SLUG}.${COMPRESSION}"2069 else2070 # node <= 0.1.13 does not have a directory2058- TARBALL_URL="${MIRROR}/${SLUG}.tar.${COMPRESSION}"2071+ TARBALL_URL="${MIRROR}/${SLUG}.${COMPRESSION}"2072 fi2073 2074 if [ -r "${TARBALL}" ]; then2075 nvm_err "Local cache found: $(nvm_sanitize_path "${TARBALL}")"1880 unmodified lines3956 nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \3957 nvm_npmrc_bad_news_bears \3958 nvm_get_colors nvm_set_colors nvm_print_color_code nvm_format_help_message_colors \3959 nvm_echo_with_colors nvm_err_with_colors \3960+ nvm_get_artifact_compression \3961 >/dev/null 2>&13962 unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \3963 NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \3964 NVM_COLORS INSTALLED_COLOR SYSTEM_COLOR \165 unmodified lines