Skip to content
Myr

[New] `install`: add `-b` flag to skip building from source

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

Fixes #2114.

authored by Sladyn Nunes · committed by Jordan Harband · parent d9b11ba · Browse files · 3 files+93 added−1 removed
This commit

State

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

Diff stats

3 files+93 added−1 removed

  • tests:+67 added−0 removed
  • other:+26 added−1 removed

3 files+93 added−1 removed

added:test/fast/Unit tests/nvm_install_binary_nosource+30 added
1#!/bin/sh23cleanup () {4 nvm cache clear5 nvm deactivate6 rm -rf ${NVM_DIR}/v*7 nvm unalias default8}910die () { echo "$@" ; cleanup; exit 1;}1112\. ../../../nvm.sh1314nvm_binary_available() {15 return 116}1718# Unit test to check if the function errors out when the flag is set19OUTPUT="$(nvm_install_binary node std 8.0.0 1 2>&1)"20EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'21if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then22 die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"23fi2425# Unit test to check if the function errors out when the flag is set26OUTPUT="$(nvm_install_binary node std 8.0.0 0 2>&1)"27EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'28if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then29 die "No source binary flag is not active and should have downloaded from source. Instead it returned >${OUTPUT}<"30fi
added:test/installation_node/install from binary with binary flag set+37 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../nvm.sh67nvm unalias default || die 'unable to unalias default'89NVM_TEST_VERSION=v0.10.71011# Remove the stuff we're clobbering.12[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION1314# Install from binary15nvm install -b $NVM_TEST_VERSION || die "install $NVM_TEST_VERSION failed"1617# Check18[ -d ../../$NVM_TEST_VERSION ]19nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"2021# ensure default is set22NVM_CURRENT_DEFAULT="$(nvm_alias default)"23[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"2425# Falls back to source but if -b is set fails binary download.26OUTPUT="$(nvm install -b 9.0.0 2>&1)"27EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'28if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then29 die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"30fi3132# Falls back to source but if -b is not set.33OUTPUT="$(nvm install 9.0.0 2>&1)"34EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'35if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then36 die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"37fi
modified:nvm.sh+26 added-1 removed
1924 unmodified lines
1925 nvm_err 'A version number is required.'1926 return 31927 fi19281929 local nosource1930 nosource="${4-}"19311932 local VERSION1933 VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"19341935 local NVM_OS
31 unmodified lines
1967 fi1968 return 01969 fi197019711972 # Read nosource from arguments1973 if [ "${nosource-}" = '1' ]; then1974 nvm_err 'Binary download failed. Download from source aborted.'1975 return 01976 fi19771978 nvm_err 'Binary download failed, trying source.'1979 if [ -n "${TMPDIR-}" ]; then1980 command rm -rf "${TMPDIR}"1981 fi
692 unmodified lines
2674 nvm_echo ' nvm --version Print out the installed version of nvm'2675 nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'2676 nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'2677 nvm_echo ' -s Skip binary download, install from source only.'2678 nvm_echo ' -b Skip source download, install from binary only.'2679 nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'2680 nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'2681 nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'2682 nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'
206 unmodified lines
2889 version_not_provided=12890 fi28912892 local nobinary2893 local nosource2894 local noprogress2895 nobinary=02896 noprogress=02897 nosource=02898 local LTS2899 local ALIAS2900 local NVM_UPGRADE_NPM2901 NVM_UPGRADE_NPM=0
11 unmodified lines
2913 ;;2914 -s)2915 shift # consume "-s"2916 nobinary=12917 if [ $nosource -eq 1 ]; then2918 nvm err '-s and -b cannot be set together since they would skip install from both binary and source'2919 return 62920 fi2921 ;;2922 -b)2923 shift # consume "-b"2924 nosource=12925 if [ $nobinary -eq 1 ]; then2926 nvm err '-s and -b cannot be set together since they would skip install from both binary and source'2927 return 62928 fi2929 ;;2930 -j)2931 shift # consume "-j"2932 nvm_get_make_jobs "$1"2933 shift # consume job count
255 unmodified lines
3189 fi31903191 # skip binary install if "nobinary" option specified.3192 if [ $nobinary -ne 1 ] && nvm_binary_available "${VERSION}"; then3168 NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}"3193 NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_binary "${FLAVOR}" std "${VERSION}" "${nosource}"3194 EXIT_CODE=$?3195 fi3196 if [ $EXIT_CODE -ne 0 ]; then3197 if [ -z "${NVM_MAKE_JOBS-}" ]; then
987 unmodified lines