2016-11-04 14:42:55 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; exit 1; }
|
2016-11-04 14:42:55 +08:00
|
|
|
|
|
|
|
. ../../nvm.sh
|
|
|
|
|
2022-12-23 03:26:27 +08:00
|
|
|
VERSION='v18.0.0'
|
2016-11-04 14:42:55 +08:00
|
|
|
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'
|
|
|
|
|
2018-06-01 06:26:30 +08:00
|
|
|
# an existing but empty VERSION_PATH directory should not be enough to satisfy nvm_is_version_installed
|
|
|
|
rm -rf "${VERSION_PATH}"
|
|
|
|
mkdir -p "${VERSION_PATH}"
|
|
|
|
nvm_is_version_installed "${VERSION}" && die 'nvm_is_version_installed check not strict enough'
|
|
|
|
rmdir "${VERSION_PATH}"
|
|
|
|
|
2016-11-04 14:42:55 +08:00
|
|
|
OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"
|
|
|
|
USE_OUTPUT="$(nvm use "${VERSION}")"
|
|
|
|
EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}
|
2016-11-06 20:43:47 +08:00
|
|
|
Downloading and installing node ${VERSION}...
|
2017-03-28 06:00:50 +08:00
|
|
|
${USE_OUTPUT}"
|
2016-11-04 14:42:55 +08:00
|
|
|
|
|
|
|
[ "${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}
|
2016-11-06 20:43:47 +08:00
|
|
|
Downloading and installing node ${VERSION}...
|
2016-11-04 14:42:55 +08:00
|
|
|
${USE_OUTPUT}
|
|
|
|
failed"
|
|
|
|
|
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|