Skip to content

Commit

Permalink
set NVM_DIR to real path to avoid symlink issues
Browse files Browse the repository at this point in the history
  • Loading branch information
singlow authored and ljharb committed Feb 3, 2025
1 parent b77fcec commit a0e9c15
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,29 @@ else
fi
unset NVM_SCRIPT_SOURCE 2>/dev/null

# Convert NVM_DIR to actual path if symlinked
export NVM_DIR=$(nvm_real_dir "${NVM_DIR}")

nvm_real_dir() {
local NVM_DIR_INPUT
NVM_DIR_INPUT="${1}"

if [ -z "${NVM_DIR_INPUT}" ]; then
nvm_err '$NVM_DIR cannot be empty'
return 2
fi

local NVM_REAL_DIR
NVM_REAL_DIR=$(command cd "${NVM_DIR_INPUT}" && command pwd -P)

if [ -z "${NVM_REAL_DIR}" ] || [ ! -d "${NVM_REAL_DIR}" ]; then
nvm_err "NVM_DIR is not a valid path"
return 2
fi

nvm_echo "${NVM_REAL_DIR}"
}

nvm_tree_contains_path() {
local tree
tree="${1-}"
Expand Down

0 comments on commit a0e9c15

Please sign in to comment.