Skip to content
Myr

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

3 files+71 added−11 removed

modified:test/install_script/nvm_check_global_modules+40 added-7 removed
1#!/bin/sh2puts() (IFS=" "; printf %s\\n "$*" ;)34cleanup () {5 rm -rf "$npm_config_prefix/lib" >/dev/null 2>&16 unset npm_config_prefix78 rm -f npm9 PATH="$ORIGINAL_PATH"1010 unset -f setup cleanup die skip11 unset -f setup cleanup die12 unset message ORIGINAL_PATH13}13die () { echo $@ ; cleanup ; exit 1; }1415die () { puts "!! $@" ; cleanup ; exit 1; }1617NVM_ENV=testing . ../../install.sh1819setup () {20 ORIGINAL_PATH="$PATH"
2 unmodified lines
23 export npm_config_prefix24 mkdir -p "$npm_config_prefix/lib"25}262527setup282930npm install -g nop >/dev/null31message=$(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'''"3839 die "nvm_check_global_modules should have printed a notice when npm had global modules installed" ;}404142npm uninstall -g nop >/dev/null43message=$(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'''"5051 die "nvm_check_global_modules should not have printed a notice when npm had no global modules installed" ;}525354# Faking an installation of npm55mkdir -p "$npm_config_prefix/lib/node_modules/npm"56cat <<'JSON' >"$npm_config_prefix/lib/node_modules/npm/package.json"57{ "name": "npm", "version": "0.0.1fake" }58JSON5960message=$(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'''"6869 die "nvm_check_global_modules should not have printed a notice when npm had only itself installed as a global module" ;}707172# Faking the absence of npm73PATH=".:$PATH"74touch npm75chmod +x npm7677message=$(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'''"8384 die "nvm_check_global_modules should not have printed a notice when npm was unavailable" ;}858687cleanup
modified:.travis.yml+1 added-1 removed
modified:install.sh+30 added-3 removed
1#!/bin/bash22set -e34puts() (IFS=" "; printf %s\\n "$*" ;)5error() (IFS=" "; printf %s\\n "$*" >&2 ;)6debug() (IFS=" "; printf %s\\n ".. $*" >&2 ;)78if [ "$DEBUG" = 'nvm:*' ] || [ "$DEBUG" = 'nvm:install' ]; then9 NVM_DEBUG=010 debug 'Script debugging enabled (in: `install.sh`).'11fi121314nvm_has() {15 type "$1" > /dev/null 2>&116}17
32 unmodified lines
50}5152nvm_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}7071install_nvm_from_git() {
6 unmodified lines
78 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}9697install_nvm_as_script() {
52 unmodified lines
150151 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 0156157 local NPM_GLOBAL_MODULES158 NPM_GLOBAL_MODULES="$(npm list -g --depth=0 | sed '/ npm@/d')"
3 unmodified lines
162 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" ;}169170 if [ $MODULE_COUNT -ne 0 ]; then171 cat <<-'END_MESSAGE'172 => You currently have modules installed globally with `npm`. These will no
74 unmodified lines
247# Unsets the various functions defined248# during the execution of the install script249#250nvm_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}257258[ "_$NVM_ENV" = "_testing" ] || nvm_do_install