mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 14:21:50 +00:00
Check for both files then up to the parent
This commit is contained in:
parent
008bf47d3f
commit
dba3404693
34
nvm.sh
34
nvm.sh
@ -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
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user