Skip to content
Myr

[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

7 files+186 added−6 removed

added:test/fast/Unit tests/nvm_default_packages+115 added
1#!/bin/sh23FILE="$NVM_DIR/default-packages"45die () { echo "$@" ; cleanup ; exit 1; }6setup () {7 if [ -f $FILE ]; then8 ORIG_DEFAULT_PACKAGES=$(cat $FILE)9 mkdir ./tmp/ ||:10 mv $FILE ./tmp/default-packages ||:11 fi12 touch $FILE13}14cleanup () {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}2122setup2324\. ../../../nvm.sh2526cat > $FILE << EOF27rimraf28object-inspect@1.0.22930# commented-package3132stevemao/left-pad33EOF3435nvm install v6.10.1 2>&136EXIT_CODE=$?37[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"3839nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'40if [ -z "$?" ]; then41 die "expected 'nvm exec v6.10.1 npm ls -g --depth=0 | grep -q 'rimraf'' to exit with 0, got $?"42fi4344cleanup4546setup4748\. ../../../nvm.sh4950cat > $FILE << EOF51rimraf52object-inspect@1.0.25354# commented-package5556stevemao/left-pad57EOF5859nvm install v6.10.1 --skip-default-packages 2>&160EXIT_CODE=$?61[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"6263if 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"65fi6667cleanup6869setup7071cat > $FILE << EOF72not~a~package~name73EOF7475nvm install v6.10.176EXIT_CODE=$?77[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"7879if 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 $?"81fi8283cleanup8485setup8687cat > $FILE << EOF88object-inspect @ 1.0.289EOF9091nvm install v6.10.1 2>&192EXIT_CODE=$?93[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm install v6.10.1' to exit with 1, got $EXIT_CODE"9495if 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 $?"97fi9899cleanup100101setup102103rm -rf $FILE104105nvm install v6.10.1 2>&1106EXIT_CODE=$?107[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm install v6.10.1' to exit with 0, got $EXIT_CODE"108109if 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 $?"111fi112113touch $FILE114115cleanup
modified:test/fast/Unit tests/nvm_get_checksum_alg+2 added
2 unmodified lines
3set -ex45die () { echo "$@" ; exit 1; }67set +e # TODO: fix8\. ../../../nvm.sh9set -e1011ALG="$(nvm_get_checksum_alg)"1213case "$ALG" in
7 unmodified lines
modified:test/fast/Unit tests/nvm_get_mirror+2 added-1 removed
5 unmodified lines
67unset NVM_NODEJS_ORG_MIRROR8unset NVM_IOJS_ORG_MIRROR910set +e # TODO: fix11\. ../../../nvm.sh12set -e1314! 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 lines
2930NVM_IOJS_ORG_MIRROR="test://domain"31[ "$(nvm_get_mirror iojs std)" = "test://domain" ] || die "iojs-std mirror should respect NVM_IOJS_ORG_MIRROR"32unset NVM_IOJS_ORG_MIRROR31
modified:test/fast/Running "nvm unload" should unset all function and variables.+2 added
8 unmodified lines
9die () { echo "$@" ; cleanup ; exit 1; }1011typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"1213set +e # TODO: fix14\. ../../nvm.sh15set -e1617type nvm > /dev/null 2>&1 || die "nvm not loaded"1819nvm unload
9 unmodified lines
modified:.gitignore+1 added
12 unmodified lines
13npm-debug.log1415.DS_Store16current17default-packages
modified:nvm.sh+51 added-5 removed
2200 unmodified lines
2201 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 lines
24212422 ADDITIONAL_PARAMETERS=''2423 local PROVIDED_REINSTALL_PACKAGES_FROM2424 local REINSTALL_PACKAGES_FROM2425 local SKIP_DEFAULT_PACKAGES2426 local DEFAULT_PACKAGES24272428 while [ $# -ne 0 ]2429 do2430 case "$1" in
4 unmodified lines
2435 --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 done24482449 if [ -z "$SKIP_DEFAULT_PACKAGES" ] && [ -f "${NVM_DIR}/default-packages" ]; then2450 DEFAULT_PACKAGES=""24512452 # Read lines from $NVM_DIR/default-packages2453 local line2454 while IFS=" " read -r line; do2455 # Skip empty lines.2456 [ -n "${line}" ] || continue24572458 # Skip comment lines that begin with `#`.2459 [ "$(echo "$line" | cut -c1)" != "#" ] || continue24602461 # 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 esac24682469 DEFAULT_PACKAGES="${DEFAULT_PACKAGES}${line} "2470 done < "${NVM_DIR}/default-packages"2471 fi24722473 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' ]; then
9 unmodified lines
2486 fi24872488 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 else
58 unmodified lines
2559 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 else
712 unmodified lines
3283 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 lines
3306 ;;3307 esac3308}33093310nvm_install_default_packages() {3311 nvm_echo "Installing default global packages from ${NVM_DIR}/default-packages..."33123313 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}33183319nvm_supports_source_options() {3320 # shellcheck disable=SC10913321 [ "_$(echo '[ $# -gt 0 ] && echo $1' | . /dev/stdin yes 2> /dev/null)" = "_yes" ]3322}
80 unmodified lines
modified:README.md+13 added
11 unmodified lines
12 - [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 lines
228nvm install 6 --reinstall-packages-from=5229nvm install v4.2 --reinstall-packages-from=iojs230```231232### Default global packages from file while installing233234If 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.235236```sh237# $NVM_DIR/default-packages238239rimraf240object-inspect@1.0.2241stevemao/left-pad242```243244### io.js245If you want to install [io.js](https://github.com/iojs/io.js/):246247```sh
271 unmodified lines