Skip to content

Commit

Permalink
[Fix] nvm_die_on_prefix: avoid grepping env functions in bash
Browse files Browse the repository at this point in the history
ironically, nvm itself has functions that matched this grep.
  • Loading branch information
ljharb committed Sep 9, 2021
1 parent f03f695 commit 2dad045
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2456,18 +2456,22 @@ nvm_die_on_prefix() {
#
# 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_NPM_CONFIG_x_PREFIX_ENV
if [ -n "${BASH_SOURCE-}" ]; then
NVM_NPM_CONFIG_x_PREFIX_ENV="$(command set | command awk -F '=' '! /^[0-9A-Z_a-z]+=/ {exit} {print $1}' | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1)"
else
NVM_NPM_CONFIG_x_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
fi
if [ -n "${NVM_NPM_CONFIG_x_PREFIX_ENV-}" ]; then
local NVM_CONFIG_VALUE
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_x_PREFIX_ENV}\""
if [ -n "${NVM_CONFIG_VALUE-}" ] && [ "_${NVM_OS}" = "_win" ]; then
NVM_CONFIG_VALUE="$(cd "$NVM_CONFIG_VALUE" 2>/dev/null && pwd)"
fi
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."
nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_x_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
nvm_err "Run \`unset ${NVM_NPM_CONFIG_x_PREFIX_ENV}\` to unset it."
return 4
fi
fi
Expand Down

0 comments on commit 2dad045

Please sign in to comment.