[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
Provenance
- Commit
4fdef42- Tree
0bdbaaa- Author
Sladyn Nunes <sladynnunes98@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
d9b11ba
3 files changed+93 added−1 removed
added:test/fast/Unit tests/nvm_install_binary_nosource+30 added
1+#!/bin/sh2+3+cleanup () {4+ nvm cache clear5+ nvm deactivate6+ rm -rf ${NVM_DIR}/v*7+ nvm unalias default8+}9+10+die () { echo "$@" ; cleanup; exit 1;}11+12+\. ../../../nvm.sh13+14+nvm_binary_available() {15+ return 116+}17+18+# Unit test to check if the function errors out when the flag is set19+OUTPUT="$(nvm_install_binary node std 8.0.0 1 2>&1)"20+EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'21+if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then22+ die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"23+fi24+25+# Unit test to check if the function errors out when the flag is set26+OUTPUT="$(nvm_install_binary node std 8.0.0 0 2>&1)"27+EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'28+if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then29+ die "No source binary flag is not active and should have downloaded from source. Instead it returned >${OUTPUT}<"30+fiadded:test/installation_node/install from binary with binary flag set+37 added
1+#!/bin/sh2+3+die () { echo "$@" ; exit 1; }4+5+\. ../../nvm.sh6+7+nvm unalias default || die 'unable to unalias default'8+9+NVM_TEST_VERSION=v0.10.710+11+# Remove the stuff we're clobbering.12+[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION13+14+# Install from binary15+nvm install -b $NVM_TEST_VERSION || die "install $NVM_TEST_VERSION failed"16+17+# Check18+[ -d ../../$NVM_TEST_VERSION ]19+nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"20+21+# ensure default is set22+NVM_CURRENT_DEFAULT="$(nvm_alias default)"23+[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)"24+25+# Falls back to source but if -b is set fails binary download.26+OUTPUT="$(nvm install -b 9.0.0 2>&1)"27+EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'28+if [ "${OUTPUT#*$EXPECTED_OUTPUT}" = "${OUTPUT}" ]; then29+ die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"30+fi31+32+# Falls back to source but if -b is not set.33+OUTPUT="$(nvm install 9.0.0 2>&1)"34+EXPECTED_OUTPUT='Binary download failed. Download from source aborted.'35+if [ "${OUTPUT#*$EXPECTED_OUTPUT}" != "${OUTPUT}" ]; then36+ die "No source binary flag is active and should have returned >${EXPECTED_OUTPUT}<. Instead it returned >${OUTPUT}<"37+fimodified:nvm.sh+26 added-1 removed
1924 unmodified lines1925 nvm_err 'A version number is required.'1926 return 31927 fi1928 1929+ local nosource1930+ nosource="${4-}"1931+1932 local VERSION1933 VERSION="$(nvm_strip_iojs_prefix "${PREFIXED_VERSION}")"1934 1935 local NVM_OS31 unmodified lines1967 fi1968 return 01969 fi1970 1971+1972+ # Read nosource from arguments1973+ if [ "${nosource-}" = '1' ]; then1974+ nvm_err 'Binary download failed. Download from source aborted.'1975+ return 01976+ fi1977+1978 nvm_err 'Binary download failed, trying source.'1979 if [ -n "${TMPDIR-}" ]; then1980 command rm -rf "${TMPDIR}"1981 fi692 unmodified lines2674 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 lines2889 version_not_provided=12890 fi2891 2892 local nobinary2893+ local nosource2894 local noprogress2895 nobinary=02896 noprogress=02897+ nosource=02898 local LTS2899 local ALIAS2900 local NVM_UPGRADE_NPM2901 NVM_UPGRADE_NPM=011 unmodified lines2913 ;;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 count255 unmodified lines3189 fi3190 3191 # 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-}" ]; then987 unmodified lines