Skip to content
Myr

[New] support external install hook “$NVM_INSTALL_THIRD_PARTY_HOOK”.

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

Fixes #1207.

authored by Jordan Harband · committed by Jordan Harband · parent cadbbce · Browse files · 2 files+85 added−23 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+85 added−23 removed

  • tests:+40 added−0 removed
  • other:+45 added−23 removed

2 files+85 added−23 removed

added:test/installation_node/install hook+40 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../nvm.sh67VERSION='v0.11.0'8VERSION_PATH="$(nvm_version_path "${VERSION}")"910succeed() {11 nvm_echo "$@"12 NVM_INSTALL_THIRD_PARTY_HOOK= nvm install "${VERSION}"13}1415fail() {16 succeed "$@"17 return 1118}1920! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed'2122OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"23USE_OUTPUT="$(nvm use "${VERSION}")"24EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}25${USE_OUTPUT}26${USE_OUTPUT}" # double use output is from the normal install in succeed()2728[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"2930! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall 2 failed'3132OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=fail nvm install "${VERSION}" || echo 'failed')"33USE_OUTPUT="$(nvm use "${VERSION}")"34EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}35${USE_OUTPUT}36failed"3738[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"3940
modified:nvm.sh+45 added-23 removed
1565 unmodified lines
15661567 local VERSION1568 VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"15691570 local VERSION_PATH15711570 if [ -z "$(nvm_get_os)" ]; then1571 return 21572 fi1573
781 unmodified lines
2355 fi2356 return $?2357 fi23582361 if [ "_$NVM_OS" = "_freebsd" ]; then2362 # node.js and io.js do not have a FreeBSD binary2363 nobinary=12364 nvm_err "Currently, there is no binary for $NVM_OS"2365 elif [ "_$NVM_OS" = "_sunos" ]; then2366 # Not all node/io.js versions have a Solaris binary2367 if ! nvm_has_solaris_binary "$VERSION"; then2368 nobinary=12369 nvm_err "Currently, there is no binary of version $VERSION for $NVM_OS"2359 local NVM_INSTALL_SUCCESS2360 if [ -n "${NVM_INSTALL_THIRD_PARTY_HOOK-}" ]; then2361 nvm_err '** $NVM_INSTALL_THIRD_PARTY_HOOK env var set; dispatching to third-party installation method **'2362 local NVM_METHOD_PREFERENCE2363 NVM_METHOD_PREFERENCE='binary'2364 if [ $nobinary -eq 1 ]; then2365 NVM_METHOD_PREFERENCE='source'2366 fi2367 local VERSION_PATH2368 VERSION_PATH="$(nvm_version_path "${VERSION}")"2369 local EXIT_CODE2370 "${NVM_INSTALL_THIRD_PARTY_HOOK}" "${VERSION}" "${FLAVOR}" std "${NVM_METHOD_PREFERENCE}" "${VERSION_PATH}" || {2371 EXIT_CODE=$?2372 nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var failed to install! ***'2373 return $EXIT_CODE2374 }2375 if ! nvm_is_version_installed "${VERSION}"; then2376 nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var claimed to succeed, but failed to install! ***'2377 return 332371 fi2378 fi2379 NVM_INSTALL_SUCCESS=true2380 else23812373 local NVM_INSTALL_SUCCESS2374 # skip binary install if "nobinary" option specified.2375 if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then2376 if nvm_install_binary "${FLAVOR}" std "${VERSION}"; then2377 NVM_INSTALL_SUCCESS=true2382 if [ "_$NVM_OS" = "_freebsd" ]; then2383 # node.js and io.js do not have a FreeBSD binary2384 nobinary=12385 nvm_err "Currently, there is no binary for $NVM_OS"2386 elif [ "_$NVM_OS" = "_sunos" ]; then2387 # Not all node/io.js versions have a Solaris binary2388 if ! nvm_has_solaris_binary "$VERSION"; then2389 nobinary=12390 nvm_err "Currently, there is no binary of version $VERSION for $NVM_OS"2391 fi2392 fi2379 fi2380 if [ "$NVM_INSTALL_SUCCESS" != true ]; then2381 if [ -z "${NVM_MAKE_JOBS-}" ]; then2382 nvm_get_make_jobs23932394 # skip binary install if "nobinary" option specified.2395 if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then2396 if nvm_install_binary "${FLAVOR}" std "${VERSION}"; then2397 NVM_INSTALL_SUCCESS=true2398 fi2399 fi2400 if [ "$NVM_INSTALL_SUCCESS" != true ]; then2401 if [ -z "${NVM_MAKE_JOBS-}" ]; then2402 nvm_get_make_jobs2403 fi24042385 if nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"; then2386 NVM_INSTALL_SUCCESS=true2405 if nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"; then2406 NVM_INSTALL_SUCCESS=true2407 fi2408 fi24092410 fi24112412 if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then2413 nvm_ensure_default_set "$provided_version"
816 unmodified lines