Skip to content
Myr

[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

3 files+40 added−10 removed

added:test/fast/Unit tests/nvm_get_artifact_compression+16 added
1#!/bin/sh23cleanup () {4 unset -f die cleanup5}6die () { echo "$@" ; cleanup ; exit 1; }78\. ../../../nvm.sh910# nvm_get_artifact_compression by default11[ "$(nvm_get_artifact_compression)" = 'tar.gz' ] || die 'nvm_get_artifact_compression should return "tar.gz" by default'1213# 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'1516cleanup
modified:test/fast/Unit tests/nvm_get_checksum+2 added-2 removed
29 unmodified lines
3031nvm_get_checksum_alg() {32 echo 'sha-256'33}34OUTPUT="$(nvm_get_checksum node std foo bar baz)"34OUTPUT="$(nvm_get_checksum node std foo bar tar.baz)"35EXPECTED_OUTPUT="mirror-node-std/foo/SHASUMS256.txt"36[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"3738nvm_get_checksum_alg() {39 echo 'sha-1'40}41OUTPUT="$(nvm_get_checksum iojs std foo bar baz)"41OUTPUT="$(nvm_get_checksum iojs std foo bar tar.baz)"42EXPECTED_OUTPUT="mirror-iojs-std/foo/SHASUMS.txt"43[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"4445cleanup
modified:nvm.sh+22 added-8 removed
1557 unmodified lines
1558 else1559 SHASUMS_URL="${MIRROR}/${3}/SHASUMS.txt"1560 fi15611562 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}15641565nvm_print_versions() {1566 local VERSION
415 unmodified lines
1982 nvm_echo "${FLAVOR}-${VERSION}"1983 fi1984}19851986nvm_get_artifact_compression() {1987 local VERSION1988 VERSION="${1-}"19891990 local NVM_OS1991 NVM_OS="$(nvm_get_os)"19921993 local COMPRESSION1994 COMPRESSION='tar.gz'1995 if nvm_supports_xz "${VERSION}"; then1996 COMPRESSION='tar.xz'1997 fi19981999 nvm_echo "${COMPRESSION}"2000}20012002# args: flavor, kind, type, version2003nvm_download_artifact() {2004 local FLAVOR2005 case "${1-}" in
38 unmodified lines
2044 local SLUG2045 SLUG="$(nvm_get_download_slug "${FLAVOR}" "${KIND}" "${VERSION}")"20462047 local COMPRESSION2032 COMPRESSION='gz'2033 if nvm_supports_xz "${VERSION}"; then2034 COMPRESSION='xz'2035 fi2048 COMPRESSION="$(nvm_get_artifact_compression "${VERSION}")"20492050 local CHECKSUM2051 CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")"2052
8 unmodified lines
2061 return 32062 )20632064 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 fi20732074 if [ -r "${TARBALL}" ]; then2075 nvm_err "Local cache found: $(nvm_sanitize_path "${TARBALL}")"
1880 unmodified lines
3956 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