[New] support external install hook “$NVM_INSTALL_THIRD_PARTY_HOOK”.
Fixes #1207.
parent
cadbbced20
commit
24f8ae5c46
28
nvm.sh
28
nvm.sh
|
@ -1567,8 +1567,6 @@ nvm_install_binary() {
|
|||
local VERSION
|
||||
VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"
|
||||
|
||||
local VERSION_PATH
|
||||
|
||||
if [ -z "$(nvm_get_os)" ]; then
|
||||
return 2
|
||||
fi
|
||||
|
@ -2358,6 +2356,29 @@ nvm() {
|
|||
return $?
|
||||
fi
|
||||
|
||||
local NVM_INSTALL_SUCCESS
|
||||
if [ -n "${NVM_INSTALL_THIRD_PARTY_HOOK-}" ]; then
|
||||
nvm_err '** $NVM_INSTALL_THIRD_PARTY_HOOK env var set; dispatching to third-party installation method **'
|
||||
local NVM_METHOD_PREFERENCE
|
||||
NVM_METHOD_PREFERENCE='binary'
|
||||
if [ $nobinary -eq 1 ]; then
|
||||
NVM_METHOD_PREFERENCE='source'
|
||||
fi
|
||||
local VERSION_PATH
|
||||
VERSION_PATH="$(nvm_version_path "${VERSION}")"
|
||||
local EXIT_CODE
|
||||
"${NVM_INSTALL_THIRD_PARTY_HOOK}" "${VERSION}" "${FLAVOR}" std "${NVM_METHOD_PREFERENCE}" "${VERSION_PATH}" || {
|
||||
EXIT_CODE=$?
|
||||
nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var failed to install! ***'
|
||||
return $EXIT_CODE
|
||||
}
|
||||
if ! nvm_is_version_installed "${VERSION}"; then
|
||||
nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var claimed to succeed, but failed to install! ***'
|
||||
return 33
|
||||
fi
|
||||
NVM_INSTALL_SUCCESS=true
|
||||
else
|
||||
|
||||
if [ "_$NVM_OS" = "_freebsd" ]; then
|
||||
# node.js and io.js do not have a FreeBSD binary
|
||||
nobinary=1
|
||||
|
@ -2370,7 +2391,6 @@ nvm() {
|
|||
fi
|
||||
fi
|
||||
|
||||
local NVM_INSTALL_SUCCESS
|
||||
# skip binary install if "nobinary" option specified.
|
||||
if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then
|
||||
if nvm_install_binary "${FLAVOR}" std "${VERSION}"; then
|
||||
|
@ -2387,6 +2407,8 @@ nvm() {
|
|||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then
|
||||
nvm_ensure_default_set "$provided_version"
|
||||
if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../nvm.sh
|
||||
|
||||
VERSION='v0.11.0'
|
||||
VERSION_PATH="$(nvm_version_path "${VERSION}")"
|
||||
|
||||
succeed() {
|
||||
nvm_echo "$@"
|
||||
NVM_INSTALL_THIRD_PARTY_HOOK= nvm install "${VERSION}"
|
||||
}
|
||||
|
||||
fail() {
|
||||
succeed "$@"
|
||||
return 11
|
||||
}
|
||||
|
||||
! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed'
|
||||
|
||||
OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"
|
||||
USE_OUTPUT="$(nvm use "${VERSION}")"
|
||||
EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}
|
||||
${USE_OUTPUT}
|
||||
${USE_OUTPUT}" # double use output is from the normal install in succeed()
|
||||
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||
|
||||
! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall 2 failed'
|
||||
|
||||
OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=fail nvm install "${VERSION}" || echo 'failed')"
|
||||
USE_OUTPUT="$(nvm use "${VERSION}")"
|
||||
EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}
|
||||
${USE_OUTPUT}
|
||||
failed"
|
||||
|
||||
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||
|
||||
|
Loading…
Reference in New Issue