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

Code before:
    nvm_err 'Second argument "nvm command" must be nonempty'
    return 2
  fi

  # npm first looks at $PREFIX (case-sensitive)
  # we do not bother to test the value here; if this env var is set, unset it to continue.
  if [ -n "${PREFIX-}" ]; then
    nvm deactivate >/dev/null 2>&1
    nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\""
    nvm_err 'Run `unset PREFIX` to unset it.'
    return 3
  fi

  # npm normalizes NPM_CONFIG_-prefixed env vars
  # https://github.com/npm/npmconf/blob/22827e4038d6eebaafeb5c13ed2b92cf97b8fb82/npmconf.js#L331-L348
  # https://github.com/npm/npm/blob/5e426a78ca02d0044f8dd26e0c5f881217081cbd/lib/config/core.js#L343-L359
  #
  # here, we avoid trying to replicate "which one wins" or testing the value; if any are defined, it errors
  # until none are left.
  local NVM_NPM_CONFIG_PREFIX_ENV
  NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
  if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then
    local NVM_CONFIG_VALUE
    eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
    if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then
      nvm deactivate >/dev/null 2>&1
      nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
      nvm_err "Run \`unset ${NVM_NPM_CONFIG_PREFIX_ENV}\` to unset it."
      return 4
    fi
  fi

  if ! nvm_has 'npm'; then
    return
  fi

  local NVM_NPM_PREFIX
  local NVM_OS
  NVM_OS="$(nvm_get_os)"
  NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
  if ! (nvm_tree_contains_path "${NVM_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then
    if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
      npm config --loglevel=warn delete prefix
    else
      nvm deactivate >/dev/null 2>&1
      nvm_err "nvm is not compatible with the npm config \"prefix\" option: currently set to \"${NVM_NPM_PREFIX}\""
      if nvm_has 'npm'; then
        nvm_err "Run \`npm config delete prefix\` or \`${NVM_COMMAND}\` to unset it."
      else
        nvm_err "Run \`${NVM_COMMAND}\` to unset it."
      fi

Review comment (suggestion):
```suggestion
        nvm_err "Make sure your username ($(whoami)) matches the one in your \$HOME path (${HOME})."
```

Code after:
      nvm_err "Run \`unset ${NVM_NPM_CONFIG_PREFIX_ENV}\` to unset it."
      return 4
    fi
  fi

  if ! nvm_has 'npm'; then
    return
  fi

  local NVM_NPM_PREFIX
  local NVM_OS
  NVM_OS="$(nvm_get_os)"
  NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
  if ! (nvm_tree_contains_path "${NVM_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then
    if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
      npm config --loglevel=warn delete prefix
    else
      nvm deactivate >/dev/null 2>&1
      nvm_err "nvm is not compatible with the npm config \"prefix\" option: currently set to \"${NVM_NPM_PREFIX}\""
      if nvm_has 'npm'; then
        nvm_err "Run \`npm config delete prefix\` or \`${NVM_COMMAND}\` to unset it."
      else
        nvm_err "Run \`${NVM_COMMAND}\` to unset it."
      fi
      if [ "${NVM_OS}" = 'darwin' ]; then
        nvm_err "Make sure your username ($(whoami)) matches the one in your \$HOME path."
        nvm_err "See the \"macOS Troubleshooting\" section in the docs for more information."
      fi
      return 10
    fi
  fi
}

# Succeeds if $IOJS_VERSION represents an io.js version that has a
# Solaris binary, fails otherwise.
# Currently, only io.js 3.3.1 has a Solaris binary available, and it's the
# latest io.js version available. The expectation is that any potential io.js
# version later than v3.3.1 will also have Solaris binaries.
nvm_iojs_version_has_solaris_binary() {
  local IOJS_VERSION
  IOJS_VERSION="$1"
  local STRIPPED_IOJS_VERSION
  STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix "${IOJS_VERSION}")"
  if [ "_${STRIPPED_IOJS_VERSION}" = "${IOJS_VERSION}" ]; then
    return 1
  fi

  # io.js started shipping Solaris binaries with io.js v3.3.1
  nvm_version_greater_than_or_equal_to "${STRIPPED_IOJS_VERSION}" v3.3.1
}