install: adding some debugging output
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by elliottcable · committed by elliottcable · parent 0717d5f · Browse files · 3 files·+71 added−11 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+71 added−11 removed
- tests:+40 added−7 removed
- other:+31 added−4 removed
Provenance
- Commit
c8efe3d- Tree
3a54939- Author
elliottcable <me@ell.io>- Committer
elliottcable <me@ell.io>- Parent
0717d5f
3 files changed+71 added−11 removed
modified:test/install_script/nvm_check_global_modules+40 added-7 removed
1 #!/bin/sh2+puts() (IFS=" "; printf %s\\n "$*" ;)3 4 cleanup () {5 rm -rf "$npm_config_prefix/lib" >/dev/null 2>&16 unset npm_config_prefix7 8 rm -f npm9 PATH="$ORIGINAL_PATH"10 10- unset -f setup cleanup die skip11+ unset -f setup cleanup die12 unset message ORIGINAL_PATH13 }13-die () { echo $@ ; cleanup ; exit 1; }14 15+die () { puts "!! $@" ; cleanup ; exit 1; }16+17 NVM_ENV=testing . ../../install.sh18 19 setup () {20 ORIGINAL_PATH="$PATH"2 unmodified lines23 export npm_config_prefix24 mkdir -p "$npm_config_prefix/lib"25 }26 25-27 setup28 29+30 npm install -g nop >/dev/null31 message=$(nvm_check_global_modules)30-[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed"32+[ ! -z "$message" ] || {33+ puts '-- `npm --version`: '"$(npm --version)"34+ puts '-- `npm list -g`:'35+ npm list -g --depth=036+ puts '-- Printed message:'37+ puts "'''$message'''"38 39+ die "nvm_check_global_modules should have printed a notice when npm had global modules installed" ;}40+41+42 npm uninstall -g nop >/dev/null43 message=$(nvm_check_global_modules)34-[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed"44+[ -z "$message" ] || {45+ puts '-- `npm --version`: '"$(npm --version)"46+ puts '-- `npm list -g`:'47+ npm list -g --depth=048+ puts '-- Printed message:'49+ puts "'''$message'''"50 51+ die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed" ;}52+53+54 # Faking an installation of npm55 mkdir -p "$npm_config_prefix/lib/node_modules/npm"56 cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"57 { "name": "npm", "version": "0.0.1fake" }58 JSON59 60 message=$(nvm_check_global_modules)43-[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module"61+[ -z "$message" ] || {62+ puts '-- `which npm`: ' "$(which npm)"63+ puts '-- `npm --version`: ' "$(npm --version)"64+ puts '-- `npm list -g`:'65+ npm list -g --depth=066+ puts '-- Printed message:'67+ puts "'''$message'''"68 69+ die "nvm_check_global_modules should not have printed a notice when npm had only itself installed as a global module" ;}70+71+72 # Faking the absence of npm73 PATH=".:$PATH"74 touch npm75 chmod +x npm76 77 message=$(nvm_check_global_modules)51-[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable"78+[ -z "$message" ] || {79+ puts '-- `which npm`: ' "$(which npm)"80+ puts '-- `npm --version`: ' "$(npm --version)"81+ puts '-- Printed message:'82+ puts "'''$message'''"83 84+ die "nvm_check_global_modules should not have printed a notice when npm was unavailable" ;}85 86+87 cleanupmodified:.travis.yml+1 added-1 removed
3 unmodified lines456788910111227 unmodified lines3 unmodified lines - (mkdir /tmp/urchin && cd /tmp/urchin && curl -s "$(curl -s https://registry.npmjs.com/urchin | grep -Eo '"tarball":\s*"[^"]+"' | tail -n 1 | awk -F\" '{ print $4 }')" -O && tar -x -f urchin*) - chmod +x /tmp/urchin/package/urchin - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y'script: - NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELL - DEBUG='nvm:*' NVM_DIR=$TRAVIS_BUILD_DIR make TEST_SUITE=$TEST_SUITE URCHIN=/tmp/urchin/package/urchin test-$SHELLenv: - SHELL=sh TEST_SUITE=install_script - SHELL=dash TEST_SUITE=install_script - SHELL=bash TEST_SUITE=install_script27 unmodified linesmodified:install.sh+30 added-3 removed
1 #!/bin/bash2-2 set -e3 4+puts() (IFS=" "; printf %s\\n "$*" ;)5+error() (IFS=" "; printf %s\\n "$*" >&2 ;)6+debug() (IFS=" "; printf %s\\n ".. $*" >&2 ;)7+8+if [ "$DEBUG" = 'nvm:*' ] || [ "$DEBUG" = 'nvm:install' ]; then9+ NVM_DEBUG=010+ debug 'Script debugging enabled (in: `install.sh`).'11+fi12+13+14 nvm_has() {15 type "$1" > /dev/null 2>&116 }17 32 unmodified lines50 }51 52 nvm_download() {53 if nvm_has "curl"; then54+ [ "$NVM_DEBUG" = 0 ] && set +x55 curl $*56+ [ "$NVM_DEBUG" = 0 ] && set -x57 elif nvm_has "wget"; then58 # Emulate curl with wget59 ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \60 -e 's/-L //' \61 -e 's/-I /--server-response /' \62 -e 's/-s /-q /' \63 -e 's/-o /-O /' \64 -e 's/-C - /-c /')65+ [ "$NVM_DEBUG" = 0 ] && set +x66 wget $ARGS67+ [ "$NVM_DEBUG" = 0 ] && set +x68 fi69 }70 71 install_nvm_from_git() {6 unmodified lines78 else79 # Cloning to $NVM_DIR80 echo "=> Downloading nvm from git to '$NVM_DIR'"81 printf "\r=> "82+ [ "$NVM_DEBUG" = 0 ] && set +x83 mkdir -p "$NVM_DIR"84 command git clone "$(nvm_source git)" "$NVM_DIR"85+ [ "$NVM_DEBUG" = 0 ] && set -x86 fi72- cd "$NVM_DIR" && command git checkout --quiet $(nvm_latest_version) && command git branch --quiet -D master >/dev/null 2>&187+ 88+ [ "$NVM_DEBUG" = 0 ] && set +x89+ cd "$NVM_DIR" || return $?90+ command git checkout --quiet $(nvm_latest_version) || return $?91+ command git branch --quiet -D master >/dev/null 2>&1 || return $?92+ [ "$NVM_DEBUG" = 0 ] && set +x93+ 94 return95 }96 97 install_nvm_as_script() {52 unmodified lines150 151 local NPM_VERSION152 NPM_VERSION="$(npm --version)"153 NPM_VERSION="${NPM_VERSION:-0}"154+ [ "$NVM_DEBUG" = 0 ] && debug "NPM detected (at version ${NPM_VERSION}.)"155 [ "${NPM_VERSION%%[!0-9]*}" -gt 1 ] || return 0156 157 local NPM_GLOBAL_MODULES158 NPM_GLOBAL_MODULES="$(npm list -g --depth=0 | sed '/ npm@/d')"3 unmodified lines162 printf %s\\n "$NPM_GLOBAL_MODULES" |163 sed -ne '1!p' | # Remove the first line164 wc -l | tr -d ' ' # Count entries165 )"166+ [ "$NVM_DEBUG" = 0 ] && {167+ debug "(${MODULE_COUNT}) global modules detected:"168+ error "$NPM_GLOBAL_MODULES" ;}169 170 if [ $MODULE_COUNT -ne 0 ]; then171 cat <<-'END_MESSAGE'172 => You currently have modules installed globally with `npm`. These will no74 unmodified lines247 # Unsets the various functions defined248 # during the execution of the install script249 #250 nvm_reset() {251+ unset -f puts error debug \226- unset -f nvm_reset nvm_has nvm_latest_version \252+ nvm_reset nvm_has nvm_latest_version \253 nvm_source nvm_download install_nvm_as_script install_nvm_from_git \254 nvm_detect_profile nvm_check_global_modules nvm_do_install 255+ unset NPM_DEBUG256 }257 258 [ "_$NVM_ENV" = "_testing" ] || nvm_do_install