[New] `install`: add `-b` flag to skip building from source
Fixes #2114.
parent
d9b11ba208
commit
4fdef427e4
27
nvm.sh
27
nvm.sh
|
@ -1926,6 +1926,9 @@ nvm_install_binary() {
|
|||
return 3
|
||||
fi
|
||||
|
||||
local nosource
|
||||
nosource="${4-}"
|
||||
|
||||
local VERSION
|
||||
VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"
|
||||
|
||||
|
@ -1965,6 +1968,13 @@ nvm_install_binary() {
|
|||
return 0
|
||||
fi
|
||||
|
||||
|
||||
# Read nosource from arguments
|
||||
if [ "${nosource-}" = '1' ]; then
|
||||
nvm_err 'Binary download failed. Download from source aborted.'
|
||||
return 0
|
||||
fi
|
||||
|
||||
nvm_err 'Binary download failed, trying source.'
|
||||
if [ -n "${TMPDIR-}" ]; then
|
||||
command rm -rf "${TMPDIR}"
|
||||
|
@ -2665,6 +2675,7 @@ nvm() {
|
|||
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'
|
||||
nvm_echo ' -s Skip binary download, install from source only.'
|
||||
nvm_echo ' -b Skip source download, install from binary only.'
|
||||
nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
|
||||
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
|
||||
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
|
||||
|
@ -2879,9 +2890,11 @@ nvm() {
|
|||
fi
|
||||
|
||||
local nobinary
|
||||
local nosource
|
||||
local noprogress
|
||||
nobinary=0
|
||||
noprogress=0
|
||||
nosource=0
|
||||
local LTS
|
||||
local ALIAS
|
||||
local NVM_UPGRADE_NPM
|
||||
|
@ -2901,6 +2914,18 @@ nvm() {
|
|||
-s)
|
||||
shift # consume "-s"
|
||||
nobinary=1
|
||||
if [ $nosource -eq 1 ]; then
|
||||
nvm err '-s and -b cannot be set together since they would skip install from both binary and source'
|
||||
return 6
|
||||
fi
|
||||
;;
|
||||
-b)
|
||||
shift # consume "-b"
|
||||
nosource=1
|
||||
if [ $nobinary -eq 1 ]; then
|
||||
nvm err '-s and -b cannot be set together since they would skip install from both binary and source'
|
||||
return 6
|
||||
fi
|
||||
;;
|
||||
-j)
|
||||
shift # consume "-j"
|
||||
|
@ -3165,7 +3190,7 @@ nvm() {
|
|||
|
||||
# skip binary install if "nobinary" option specified.
|
||||
if [ $nobinary -ne 1 ] && nvm_binary_available "${VERSION}"; then
|
||||
NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}"
|
||||
NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}" "${nosource}"
|
||||
EXIT_CODE=$?
|
||||
fi
|
||||
if [ $EXIT_CODE -ne 0 ]; then
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/sh
|
||||
|
||||
cleanup () {
|
||||
nvm cache clear
|
||||
nvm deactivate
|
||||
rm -rf ${NVM_DIR}/v*
|
||||
nvm unalias default
|
||||
}
|
||||
|
||||
die () { echo "$@" ; cleanup; exit 1;}
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
nvm_binary_available() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Unit test to check if the function errors out when the flag is set
|
||||
OUTPUT="$(nvm_install_binary node std 8.0.0 1 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
|
||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||
fi
|
||||
|
||||
# Unit test to check if the function errors out when the flag is set
|
||||
OUTPUT="$(nvm_install_binary node std 8.0.0 0 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
|
||||
die "No source binary flag is not active and should have downloaded from source. Instead it returned >${OUTPUT}<"
|
||||
fi
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../nvm.sh
|
||||
|
||||
nvm unalias default || die 'unable to unalias default'
|
||||
|
||||
NVM_TEST_VERSION=v0.10.7
|
||||
|
||||
# Remove the stuff we're clobbering.
|
||||
[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION
|
||||
|
||||
# Install from binary
|
||||
nvm install -b $NVM_TEST_VERSION || die "install $NVM_TEST_VERSION failed"
|
||||
|
||||
# Check
|
||||
[ -d ../../$NVM_TEST_VERSION ]
|
||||
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"
|
||||
|
||||
# ensure default is set
|
||||
NVM_CURRENT_DEFAULT="$(nvm_alias default)"
|
||||
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"
|
||||
|
||||
# Falls back to source but if -b is set fails binary download.
|
||||
OUTPUT="$(nvm install -b 9.0.0 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then
|
||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||
fi
|
||||
|
||||
# Falls back to source but if -b is not set.
|
||||
OUTPUT="$(nvm install 9.0.0 2>&1)"
|
||||
EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'
|
||||
if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then
|
||||
die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"
|
||||
fi
|
Loading…
Reference in New Issue