[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
Provenance
- Commit
24f8ae5- Tree
dd2b5cd- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
cadbbce
2 files changed+85 added−23 removed
added:test/installation_node/install hook+40 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../nvm.sh6+7+VERSION='v0.11.0'8+VERSION_PATH="$(nvm_version_path "${VERSION}")"9+10+succeed() {11+ nvm_echo "$@"12+ NVM_INSTALL_THIRD_PARTY_HOOK= nvm install "${VERSION}"13+}14+15+fail() {16+ succeed "$@"17+ return 1118+}19+20+! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed'21+22+OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"23+USE_OUTPUT="$(nvm use "${VERSION}")"24+EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}25+${USE_OUTPUT}26+${USE_OUTPUT}" # double use output is from the normal install in succeed()27+28+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"29+30+! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall 2 failed'31+32+OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=fail nvm install "${VERSION}" || echo 'failed')"33+USE_OUTPUT="$(nvm use "${VERSION}")"34+EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}35+${USE_OUTPUT}36+failed"37+38+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"39+40+modified:nvm.sh+45 added-23 removed
1565 unmodified lines1566 1567 local VERSION1568 VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"1569 1570- local VERSION_PATH1571-1570 if [ -z "$(nvm_get_os)" ]; then1571 return 21572 fi1573 781 unmodified lines2355 fi2356 return $?2357 fi2358 2361- 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+ else2381 2373- 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_jobs2393+2394+ # 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+ fi2404 2385- 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 fi2409+2410 fi2411 2412 if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then2413 nvm_ensure_default_set "$provided_version"816 unmodified lines