Repository: nvm-sh/nvm
File: nvm.sh (Shell)

Code before:
  local NPMLIST
  local VERSION
  VERSION="$1"
  NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')

  local INSTALLS
  INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)

  local LINKS
  LINKS="$(nvm_echo "${NPMLIST}" | command sed -n 's/.* -> \(.*\)/\1/ p')"

  nvm_echo "${INSTALLS} //// ${LINKS}"
}

nvm_npmrc_bad_news_bears() {
  local NVM_NPMRC
  NVM_NPMRC="${1-}"
  if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
    return 0
  fi
  return 1
}

# args: path to check and transform if needed
nvm_ensure_posix_path() {
  [ -z "$1" ] && nvm_err "Need the location as first parameter" && return 1
  local location
  location="$1"

  # If already posix path, just return it
  [ "$(printf '%s' "$location" | command cut -b 1)" = "/" ] && nvm_echo "$location" && return 0

  local letter
  letter=$(printf '%s' "$location" | command cut -b 1 | command tr '[:upper:]' '[:lower:]')
  local letter_upper
  letter_upper=$(printf '%s' "$letter" | command tr '[:lower:]' '[:upper:]')
  local letter_prefix
  [ -d '/mnt/' ] && letter_prefix='/mnt'
  # prefix like /mnt/c or /c
  if [ -d "$letter_prefix/$letter" ]; then
    letter_prefix="$letter_prefix/$letter"
  # prefix like /mnt/C or /C
  elif [ -d "$letter_prefix/$letter_upper" ]; then
    letter_prefix="$letter_prefix/$letter_upper"
  else
    nvm_err "Unable to convert the path to posix"
    return 1
  fi
  # Remove Windows prefix (eg. C:) and replace \ by /
  location=$(printf '%s' "$location" | command cut -b 3- | command sed 's#\\#/#g')
  nvm_echo "${letter_prefix}${location}"

Review comment (suggestion):
```suggestion
  [ -z "${1-}" ] && nvm_err "Need the location as first parameter" && return 1
```

Code after:
  nvm use "$@"
}

nvm_install_npm_if_needed() {
  local VERSION
  VERSION="$(nvm_ls_current)"
  if ! nvm_has "npm"; then
    nvm_echo 'Installing npm...'
    if nvm_version_greater 0.2.0 "${VERSION}"; then
      nvm_err 'npm requires node v0.2.3 or higher'
    elif nvm_version_greater_than_or_equal_to "${VERSION}" 0.2.0; then
      if nvm_version_greater 0.2.3 "${VERSION}"; then
        nvm_err 'npm requires node v0.2.3 or higher'
      else
        nvm_download -L https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh
      fi
    else
      nvm_download -L https://npmjs.org/install.sh -o - | clean=yes sh
    fi
  fi
  return $?
}

nvm_match_version() {
  local NVM_IOJS_PREFIX
  NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
  local PROVIDED_VERSION
  PROVIDED_VERSION="$1"
  case "_${PROVIDED_VERSION}" in
    "_${NVM_IOJS_PREFIX}" | '_io.js')
      nvm_version "${NVM_IOJS_PREFIX}"
    ;;
    '_system')
      nvm_echo 'system'
    ;;
    *)
      nvm_version "${PROVIDED_VERSION}"
    ;;
  esac
}

nvm_npm_global_modules() {
  local NPMLIST
  local VERSION
  VERSION="$1"
  NPMLIST=$(nvm use "${VERSION}" >/dev/null && npm list -g --depth=0 2>/dev/null | command sed 1,1d | nvm_grep -v 'UNMET PEER DEPENDENCY')

  local INSTALLS
  INSTALLS=$(nvm_echo "${NPMLIST}" | command sed -e '/ -> / d' -e '/\(empty\)/ d' -e 's/^.* \(.*@[^ ]*\).*/\1/' -e '/^npm@[^ ]*.*$/ d' | command xargs)

  local LINKS