[New] add support for `$NVM_DIR/default-packages` file
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Weston Ganger · committed by Jordan Harband · parent dc5dfe3 · Browse files · 7 files·+186 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+186 added−6 removed
- tests:+121 added−1 removed
- other:+65 added−5 removed
Provenance
- Commit
7f3145b- Tree
bec59e1- Author
Weston Ganger <westonganger@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
dc5dfe3
7 files changed+186 added−6 removed
added:test/fast/Unit tests/nvm_default_packages+115 added
1+#!/bin/sh2+3+FILE="$NVM_DIR/default-packages"4+5+die () { echo "$@" ; cleanup ; exit 1; }6+setup () {7+ if [ -f $FILE ]; then8+ ORIG_DEFAULT_PACKAGES=$(cat $FILE)9+ mkdir ./tmp/ ||:10+ mv $FILE ./tmp/default-packages ||:11+ fi12+ touch $FILE13+}14+cleanup () {15+ rm -rf "$(nvm_version_path v6.10.1)" $FILE16+ if [ "$ORIG_DEFAULT_PACKAGES" != "" ]; then17+ rm -rf ./tmp/18+ echo "$ORIG_DEFAULT_PACKAGES" > $FILE19+ fi20+}21+22+setup23+24+\. ../../../nvm.sh25+26+cat > $FILE << EOF27+rimraf28+object-inspect@1.0.229+30+# commented-package31+32+stevemao/left-pad33+EOF34+35+nvm install v6.10.1 2>&136+EXIT_CODE=$?37+[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"38+39+nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'40+if [ -z "$?" ]; then41+ die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'' to exit with 0, got $?"42+fi43+44+cleanup45+46+setup47+48+\. ../../../nvm.sh49+50+cat > $FILE << EOF51+rimraf52+object-inspect@1.0.253+54+# commented-package55+56+stevemao/left-pad57+EOF58+59+nvm install v6.10.1 --skip-default-packages 2>&160+EXIT_CODE=$?61+[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"62+63+if nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'; then64+ die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'' to be empty"65+fi66+67+cleanup68+69+setup70+71+cat > $FILE << EOF72+not~a~package~name73+EOF74+75+nvm install v6.10.176+EXIT_CODE=$?77+[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"78+79+if nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'not~a~package~name'; then80+ die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'not~a~package~name'' to exit with 1, got $?"81+fi82+83+cleanup84+85+setup86+87+cat > $FILE << EOF88+object-inspect @ 1.0.289+EOF90+91+nvm install v6.10.1 2>&192+EXIT_CODE=$?93+[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm install v6.10.1' to exit with 1, got $EXIT_CODE"94+95+if nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'object-inspect'; then96+ die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'object-inspect'' to exit with 1, got $?"97+fi98+99+cleanup100+101+setup102+103+rm -rf $FILE104+105+nvm install v6.10.1 2>&1106+EXIT_CODE=$?107+[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"108+109+if nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'object-inspect'; then110+ die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'object-inspect'' to exit with 1, got $?"111+fi112+113+touch $FILE114+115+cleanupmodified:test/fast/Unit tests/nvm_get_checksum_alg+2 added
2 unmodified lines3 set -ex4 5 die () { echo "$@" ; exit 1; }6 7+set +e # TODO: fix8 \. ../../../nvm.sh9+set -e10 11 ALG="$(nvm_get_checksum_alg)"12 13 case "$ALG" in7 unmodified linesmodified:test/fast/Unit tests/nvm_get_mirror+2 added-1 removed
5 unmodified lines6 7 unset NVM_NODEJS_ORG_MIRROR8 unset NVM_IOJS_ORG_MIRROR9 10+set +e # TODO: fix11 \. ../../../nvm.sh12+set -e13 14 ! nvm_get_mirror || die 'unknown release type did not error'15 ! nvm_get_mirror node || die 'unknown release type did not error'16 ! nvm_get_mirror iojs || die 'unknown release type did not error'12 unmodified lines29 30 NVM_IOJS_ORG_MIRROR="test://domain"31 [ "$(nvm_get_mirror iojs std)" = "test://domain" ] || die "iojs-std mirror should respect NVM_IOJS_ORG_MIRROR"32 unset NVM_IOJS_ORG_MIRROR31-modified:test/fast/Running "nvm unload" should unset all function and variables.+2 added
8 unmodified lines9 die () { echo "$@" ; cleanup ; exit 1; }10 11 typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"12 13+set +e # TODO: fix14 \. ../../nvm.sh15+set -e16 17 type nvm > /dev/null 2>&1 || die "nvm not loaded"18 19 nvm unload9 unmodified linesmodified:.gitignore+1 added
12 unmodified lines13 npm-debug.log14 15 .DS_Store16 current17+default-packagesmodified:nvm.sh+51 added-5 removed
2200 unmodified lines2201 nvm_echo ' nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available'2202 nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'2203 nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'2204 nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'2205+ nvm_echo ' --skip-default-packages When installing, skip the default-packages file if it exists'2206 nvm_echo ' nvm uninstall <version> Uninstall a version'2207 nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'2208 nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'2209 nvm_echo ' nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available'211 unmodified lines2421 2422 ADDITIONAL_PARAMETERS=''2423 local PROVIDED_REINSTALL_PACKAGES_FROM2424 local REINSTALL_PACKAGES_FROM2425+ local SKIP_DEFAULT_PACKAGES2426+ local DEFAULT_PACKAGES2427 2428 while [ $# -ne 0 ]2429 do2430 case "$1" in4 unmodified lines2435 --copy-packages-from=*)2436 PROVIDED_REINSTALL_PACKAGES_FROM="$(nvm_echo "$1" | command cut -c 22-)"2437 REINSTALL_PACKAGES_FROM="$(nvm_version "$PROVIDED_REINSTALL_PACKAGES_FROM")" ||:2438 ;;2439+ --skip-default-packages)2440+ SKIP_DEFAULT_PACKAGES=true2441+ ;;2442 *)2443 ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"2444 ;;2445 esac2446 shift2447 done2448 2449+ if [ -z "$SKIP_DEFAULT_PACKAGES" ] && [ -f "${NVM_DIR}/default-packages" ]; then2450+ DEFAULT_PACKAGES=""2451+2452+ # Read lines from $NVM_DIR/default-packages2453+ local line2454+ while IFS=" " read -r line; do2455+ # Skip empty lines.2456+ [ -n "${line}" ] || continue2457+2458+ # Skip comment lines that begin with `#`.2459+ [ "$(echo "$line" | cut -c1)" != "#" ] || continue2460+2461+ # Fail on lines that have multiple space-separated words2462+ case ${line} in2463+ *\ * )2464+ nvm_err "Only one package per line is allowed in the ${NVM_DIR}/default-packages file. Please remove any lines with multiple space-seperated values."2465+ return 12466+ ;;2467+ esac2468+2469+ DEFAULT_PACKAGES="${DEFAULT_PACKAGES}${line} "2470+ done < "${NVM_DIR}/default-packages"2471+ fi2472+2473 if [ -n "${PROVIDED_REINSTALL_PACKAGES_FROM-}" ] && [ "$(nvm_ensure_version_prefix "${PROVIDED_REINSTALL_PACKAGES_FROM}")" = "${VERSION}" ]; then2474 nvm_err "You can't reinstall global packages from the same version of node you're installing."2475 return 42476 elif [ "${REINSTALL_PACKAGES_FROM-}" = 'N/A' ]; then9 unmodified lines2486 fi2487 2488 if nvm_is_version_installed "$VERSION"; then2489 nvm_err "$VERSION is already installed."2490+ if nvm use "$VERSION"; then2491+ if [ -z "${SKIP_DEFAULT_PACKAGES-}" ] && [ -n "${DEFAULT_PACKAGES-}" ]; then2492+ nvm_install_default_packages "$DEFAULT_PACKAGES"2493+ fi2460- if nvm use "$VERSION" && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then2461- nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"2494+ if [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then2495+ nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"2496+ fi2497 fi2498 if [ -n "${LTS-}" ]; then2499 nvm_ensure_default_set "lts/${LTS}"2500 else58 unmodified lines2559 nvm_ensure_default_set "lts/${LTS}"2560 else2561 nvm_ensure_default_set "$provided_version"2562 fi2528- if [ -n "${REINSTALL_PACKAGES_FROM-}" ] \2529- && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then2563+ if [ -z "${SKIP_DEFAULT_PACKAGES-}" ] && [ -n "${DEFAULT_PACKAGES-}" ]; then2564+ nvm_install_default_packages "$DEFAULT_PACKAGES"2565+ fi2566+ if [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then2567 nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"2568 EXIT_CODE=$?2569 fi2570 else712 unmodified lines3283 nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \3284 nvm_version_greater nvm_version_greater_than_or_equal_to \3285 nvm_print_npm_version nvm_npm_global_modules \3286 nvm_has_system_node nvm_has_system_iojs \3250- nvm_download nvm_get_latest nvm_has \3287+ nvm_download nvm_get_latest nvm_has nvm_install_default_packages \3288 nvm_supports_source_options nvm_auto nvm_supports_xz \3289 nvm_echo nvm_err nvm_grep nvm_cd \3290 nvm_die_on_prefix nvm_get_make_jobs nvm_get_minor_version \3291 nvm_has_solaris_binary nvm_is_merged_node_version \14 unmodified lines3306 ;;3307 esac3308 }3309 3310+nvm_install_default_packages() {3311+ nvm_echo "Installing default global packages from ${NVM_DIR}/default-packages..."3312+3313+ if ! nvm_echo "$1" | command xargs npm install -g --quiet; then3314+ nvm_err "Failed installing default packages. Please check if your default-packages file or a package in it has problems!"3315+ return 13316+ fi3317+}3318+3319 nvm_supports_source_options() {3320 # shellcheck disable=SC10913321 [ "_$(echo '[ $# -gt 0 ] && echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]3322 }80 unmodified linesmodified:README.md+13 added
11 unmodified lines12 - [Manual upgrade](#manual-upgrade)13 - [Usage](#usage)14 - [Long-term support](#long-term-support)15 - [Migrating global packages while installing](#migrating-global-packages-while-installing)16+ - [Default global packages from file while installing](#default-global-packages-from-file-while-installing)17 - [io.js](#iojs)18 - [System version of node](#system-version-of-node)19 - [Listing versions](#listing-versions)20 - [.nvmrc](#nvmrc)207 unmodified lines228 nvm install 6 --reinstall-packages-from=5229 nvm install v4.2 --reinstall-packages-from=iojs230 ```231 232+### Default global packages from file while installing233+234+If you have a list of default packages you want installed every time you install a new version we support that too. You can add anything npm would accept as a package argument on the command line.235+236+```sh237+# $NVM_DIR/default-packages238+239+rimraf240+object-inspect@1.0.2241+stevemao/left-pad242+```243+244 ### io.js245 If you want to install [io.js](https://github.com/iojs/io.js/):246 247 ```sh271 unmodified lines