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

Code before:

  local NVM_NPM_PREFIX
  NVM_NPM_PREFIX="$(npm config 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 delete prefix
    else
      nvm deactivate >/dev/null 2>&1
      echo >&2 "nvm is not compatible with the npm config \"prefix\" option: currently set to \"$NVM_NPM_PREFIX\""
      if nvm_has 'npm'; then
        echo >&2 "Run \`npm config delete prefix\` or \`$NVM_COMMAND\` to unset it."
      else
        echo >&2 "Run \`$NVM_COMMAND\` to unset it."
      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.
iojs_version_has_solaris_binary() {
  local IOJS_VERSION=$1
  nvm_version_greater_than_or_equal_to "$(nvm_strip_iojs_prefix $IOJS_VERSION)" v3.3.1
}

node_version_has_solaris_binary() {
  local NODE_VERSION=$1
  nvm_version_greater_than_or_equal_to "$NODE_VERSION" v0.8.6
}

nvm_has_solaris_binary() {
  local VERSION=$1
  if nvm_is_iojs_version "$VERSION"; then
    iojs_version_has_solaris_binary "$VERSION"
  else
    node_version_has_solaris_binary "$VERSION"
  fi
}

nvm() {
  if [ $# -lt 1 ]; then
    nvm help
    return
  fi

  local GREP_OPTIONS
  GREP_OPTIONS=''

Review comment (performance):
This is great - could you also add lines that error out with an explicit error code if it's not an iojs version? Feel free to optimize a bit by storing `"$(nvm_strip_iojs_prefix $IOJS_VERSION)"` in a local, and just testing if it's equal to `$IOJS_VERSION` :-)


Code after:

  local NVM_NPM_PREFIX
  NVM_NPM_PREFIX="$(npm config 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 delete prefix
    else
      nvm deactivate >/dev/null 2>&1
      echo >&2 "nvm is not compatible with the npm config \"prefix\" option: currently set to \"$NVM_NPM_PREFIX\""
      if nvm_has 'npm'; then
        echo >&2 "Run \`npm config delete prefix\` or \`$NVM_COMMAND\` to unset it."
      else
        echo >&2 "Run \`$NVM_COMMAND\` to unset it."
      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.
iojs_version_has_solaris_binary() {
  local IOJS_VERSION=$1
  local 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
}

# Succeeds if $NODE_VERSION represents a node version that has a
# Solaris binary, fails otherwise.
# Currently, node versions starting from v0.8.6 have a Solaris binary
# avaliable.
node_version_has_solaris_binary() {
  local NODE_VERSION=$1
  # Error out if $NODE_VERSION is actually an io.js version
  local STRIPPED_IOJS_VERSION="$(nvm_strip_iojs_prefix $NODE_VERSION)"
  if [ "_$STRIPPED_IOJS_VERSION" != "_$NODE_VERSION" ]; then
    return 1
  fi

  # node (unmerged) started shipping Solaris binaries with v0.8.6 and
  # node versions v1.0.0 or greater are not considered valid "unmerged" node
  # versions.
  nvm_version_greater_than_or_equal_to "$NODE_VERSION" v0.8.6 &&