Skip to content

Commit

Permalink
Check for both files then up to the parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sturgeon authored and mcaskill committed May 14, 2024
1 parent 008bf47 commit 03653f2
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -452,24 +452,27 @@ nvm_find_project_dir() {
# Traverse up in directory tree to find containing folder
nvm_find_up() {
local path_
local file
path_="${PWD}"
while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/${1-}" ]; do
path_=${path_%/*}

# Iterate through the multiple files
while [ $# -ne 0 ]; do
# Look for files in turn in this path_
while [ "${path_}" != "" ] && [ "${path_}" != '.' ]; do
# Is the file here?
if [ -f "${path_}/${1-}" ]; then
file="${path_}/${1-}"
echo $file
break 2
fi
path_=${path_%/*}
done
shift
done
nvm_echo "${path_}"
}

nvm_find_nvmrc() {
local dir
dir="$(nvm_find_up '.nvmrc')"
if [ -e "${dir}/.nvmrc" ]; then
nvm_echo "${dir}/.nvmrc"
else
dir="$(nvm_find_up '.node-version')"
if [ -e "${dir}/.node-version" ]; then
nvm_echo "${dir}/.node-version"
fi
fi
nvm_echo "$(nvm_find_up '.nvmrc' '.node-version')"
}

# Obtain nvm version from rc file
Expand All @@ -483,15 +486,16 @@ nvm_rc_version() {
fi
return 1
fi
NVMRC_BASENAME="$(command basename "$NVMRC_PATH")"
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
if [ -z "${NVM_RC_VERSION}" ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Warning: empty nvm file found at \"${NVMRC_PATH}\""
nvm_err "Warning: empty '${NVMRC_BASENAME}' file found at \"${NVMRC_PATH}\""
fi
return 2
fi
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
nvm_echo "Found '${NVMRC_BASENAME}' with version <${NVM_RC_VERSION}>"
fi
}

Expand Down

0 comments on commit 03653f2

Please sign in to comment.