[Refactor] add `nvm_get_artifact_compression`
parent
a5742d4e9e
commit
d396181ffb
30
nvm.sh
30
nvm.sh
|
@ -1559,7 +1559,7 @@ nvm_get_checksum() {
|
|||
SHASUMS_URL="${MIRROR}/${3}/SHASUMS.txt"
|
||||
fi
|
||||
|
||||
nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.tar.${5}\" == \$2) print \$1}"
|
||||
nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.${5}\" == \$2) print \$1}"
|
||||
}
|
||||
|
||||
nvm_print_versions() {
|
||||
|
@ -1983,6 +1983,22 @@ nvm_get_download_slug() {
|
|||
fi
|
||||
}
|
||||
|
||||
nvm_get_artifact_compression() {
|
||||
local VERSION
|
||||
VERSION="${1-}"
|
||||
|
||||
local NVM_OS
|
||||
NVM_OS="$(nvm_get_os)"
|
||||
|
||||
local COMPRESSION
|
||||
COMPRESSION='tar.gz'
|
||||
if nvm_supports_xz "${VERSION}"; then
|
||||
COMPRESSION='tar.xz'
|
||||
fi
|
||||
|
||||
nvm_echo "${COMPRESSION}"
|
||||
}
|
||||
|
||||
# args: flavor, kind, type, version
|
||||
nvm_download_artifact() {
|
||||
local FLAVOR
|
||||
|
@ -2029,10 +2045,7 @@ nvm_download_artifact() {
|
|||
SLUG="$(nvm_get_download_slug "${FLAVOR}" "${KIND}" "${VERSION}")"
|
||||
|
||||
local COMPRESSION
|
||||
COMPRESSION='gz'
|
||||
if nvm_supports_xz "${VERSION}"; then
|
||||
COMPRESSION='xz'
|
||||
fi
|
||||
COMPRESSION="$(nvm_get_artifact_compression "${VERSION}")"
|
||||
|
||||
local CHECKSUM
|
||||
CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")"
|
||||
|
@ -2049,13 +2062,13 @@ nvm_download_artifact() {
|
|||
)
|
||||
|
||||
local TARBALL
|
||||
TARBALL="${tmpdir}/${SLUG}.tar.${COMPRESSION}"
|
||||
TARBALL="${tmpdir}/${SLUG}.${COMPRESSION}"
|
||||
local TARBALL_URL
|
||||
if nvm_version_greater_than_or_equal_to "${VERSION}" 0.1.14; then
|
||||
TARBALL_URL="${MIRROR}/${VERSION}/${SLUG}.tar.${COMPRESSION}"
|
||||
TARBALL_URL="${MIRROR}/${VERSION}/${SLUG}.${COMPRESSION}"
|
||||
else
|
||||
# node <= 0.1.13 does not have a directory
|
||||
TARBALL_URL="${MIRROR}/${SLUG}.tar.${COMPRESSION}"
|
||||
TARBALL_URL="${MIRROR}/${SLUG}.${COMPRESSION}"
|
||||
fi
|
||||
|
||||
if [ -r "${TARBALL}" ]; then
|
||||
|
@ -3944,6 +3957,7 @@ nvm() {
|
|||
nvm_npmrc_bad_news_bears \
|
||||
nvm_get_colors nvm_set_colors nvm_print_color_code nvm_format_help_message_colors \
|
||||
nvm_echo_with_colors nvm_err_with_colors \
|
||||
nvm_get_artifact_compression \
|
||||
>/dev/null 2>&1
|
||||
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
||||
NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh
|
||||
|
||||
cleanup () {
|
||||
unset -f die cleanup
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
# nvm_get_artifact_compression by default
|
||||
[ "$(nvm_get_artifact_compression)" = 'tar.gz' ] || die 'nvm_get_artifact_compression should return "tar.gz" by default'
|
||||
|
||||
# nvm_get_artifact_compression with xz
|
||||
[ "$(nvm_get_artifact_compression "14.0.0")" = 'tar.xz' ] || die 'nvm_get_artifact_compression should return "tar.xz" for this version'
|
||||
|
||||
cleanup
|
|
@ -31,14 +31,14 @@ nvm_download() {
|
|||
nvm_get_checksum_alg() {
|
||||
echo 'sha-256'
|
||||
}
|
||||
OUTPUT="$(nvm_get_checksum node std foo bar baz)"
|
||||
OUTPUT="$(nvm_get_checksum node std foo bar tar.baz)"
|
||||
EXPECTED_OUTPUT="mirror-node-std/foo/SHASUMS256.txt"
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
||||
|
||||
nvm_get_checksum_alg() {
|
||||
echo 'sha-1'
|
||||
}
|
||||
OUTPUT="$(nvm_get_checksum iojs std foo bar baz)"
|
||||
OUTPUT="$(nvm_get_checksum iojs std foo bar tar.baz)"
|
||||
EXPECTED_OUTPUT="mirror-iojs-std/foo/SHASUMS.txt"
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<"
|
||||
|
||||
|
|
Loading…
Reference in New Issue