Skip to content
Myr

[Refactor] add `nvm_extract_tarball` to consolidate extraction logic

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

authored by Bob Bregant II · committed by Jordan Harband · parent 9600617 · Browse files · 2 files+49 added−27 removed
This commit

State

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

Diff stats

2 files+49 added−27 removed

  • tests:+12 added−0 removed
  • other:+37 added−27 removed

2 files+49 added−27 removed

added:test/fast/Unit tests/nvm_extract_tarball+12 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../../nvm.sh67[ "$(nvm_extract_tarball 2>&1)" = "nvm_extract_tarball requires exactly 4 arguments" ] || die 'incorrect error message with no args'8[ "$(nvm_extract_tarball > /dev/null 2>&1 ; echo $?)" = "5" ] || die 'incorrect error code with no args'9[ "$(nvm_extract_tarball one two three 2>&1)" = "nvm_extract_tarball requires exactly 4 arguments" ] || die 'incorrect error message with three args'10[ "$(nvm_extract_tarball one two three > /dev/null 2>&1 ; echo $?)" = "5" ] || die 'incorrect error code with three args'11[ "$(nvm_extract_tarball one two three four five 2>&1)" = "nvm_extract_tarball requires exactly 4 arguments" ] || die 'incorrect error message with five args'12[ "$(nvm_extract_tarball one two three four five > /dev/null 2>&1 ; echo $?)" = "5" ] || die 'incorrect error code with five args'
modified:nvm.sh+37 added-27 removed
1969 unmodified lines
1970 VERSION_PATH="${VERSION_PATH}/bin"1971 command unzip -q "${TARBALL}" -d "${TMPDIR}" || return 11972 # For non Windows system (including WSL running on Windows)1973 else1974 local tar_compression_flag1975 tar_compression_flag='z'1976 if nvm_supports_xz "${VERSION}"; then1977 tar_compression_flag='J'1978 fi19791980 local tar1981 if [ "${NVM_OS}" = 'aix' ]; then1982 tar='gtar'1983 else1984 tar='tar'1985 fi1986 command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 11974 nvm_extract_tarball "${NVM_OS}" "${VERSION}" "${TARBALL}" "${TMPDIR}"1975 fi19761977 command mkdir -p "${VERSION_PATH}" || return 11978
259 unmodified lines
22382239 nvm_echo "${TARBALL}"2240}22412242# args: nvm_os, version, tarball, tmpdir2243nvm_extract_tarball() {2244 if [ "$#" -ne 4 ]; then2245 nvm_err 'nvm_extract_tarball requires exactly 4 arguments'2246 return 52247 fi22482249 local NVM_OS2250 NVM_OS="${1-}"22512252 local VERSION2253 VERSION="${2-}"22542255 local TARBALL2256 TARBALL="${3-}"22572258 local TMPDIR2259 TMPDIR="${4-}"22602261 local tar_compression_flag2262 tar_compression_flag='z'2263 if nvm_supports_xz "${VERSION}"; then2264 tar_compression_flag='J'2265 fi22662267 local tar2268 tar='tar'2269 if [ "${NVM_OS}" = 'aix' ]; then2270 tar='gtar'2271 fi22722273 command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 12274}22752276nvm_get_make_jobs() {2277 if nvm_is_natural_num "${1-}"; then2278 NVM_MAKE_JOBS="$1"2279 nvm_echo "number of \`make\` jobs: ${NVM_MAKE_JOBS}"
103 unmodified lines
2383 MAKE_CXX="CC=${CC:-cc} CXX=${CXX:-c++}"2384 fi2385 fi23862365 local tar_compression_flag2366 tar_compression_flag='z'2367 if nvm_supports_xz "${VERSION}"; then2368 tar_compression_flag='J'2369 fi23702371 local tar2372 tar='tar'2373 if [ "${NVM_OS}" = 'aix' ]; then2374 tar='gtar'2375 fi23762387 local TARBALL2388 local TMPDIR2389 local VERSION_PATH2390
11 unmodified lines
2402 TMPDIR="$(dirname "${TARBALL}")/files" && \2403 if ! (2404 # shellcheck disable=SC20862405 command mkdir -p "${TMPDIR}" && \2396 command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 && \2406 nvm_extract_tarball "${NVM_OS}" "${VERSION}" "${TARBALL}" "${TMPDIR}" && \2407 VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" && \2408 nvm_cd "${TMPDIR}" && \2409 nvm_echo '$>'./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS'<' && \2410 ./configure --prefix="${VERSION_PATH}" $ADDITIONAL_PARAMETERS && \
1749 unmodified lines
4160 nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \4161 nvm_npmrc_bad_news_bears \4162 nvm_get_colors nvm_set_colors nvm_print_color_code nvm_format_help_message_colors \4163 nvm_echo_with_colors nvm_err_with_colors \4154 nvm_get_artifact_compression nvm_install_binary_extract \4164 nvm_get_artifact_compression nvm_install_binary_extract nvm_extract_tarball \4165 >/dev/null 2>&14166 unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \4167 NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \4168 NVM_COLORS INSTALLED_COLOR SYSTEM_COLOR \
165 unmodified lines