Skip to content

Commit dba3404

Browse files
Phil Sturgeonmcaskill
Phil Sturgeon
authored andcommitted
Check for both files then up to the parent
1 parent 008bf47 commit dba3404

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

nvm.sh

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -452,24 +452,27 @@ nvm_find_project_dir() {
452452
# Traverse up in directory tree to find containing folder
453453
nvm_find_up() {
454454
local path_
455+
local file
455456
path_="${PWD}"
456-
while [ "${path_}" != "" ] && [ "${path_}" != '.' ] && [ ! -f "${path_}/${1-}" ]; do
457-
path_=${path_%/*}
457+
458+
# Iterate through the multiple files
459+
while [ $# -ne 0 ]; do
460+
# Look for files in turn in this path_
461+
while [ "${path_}" != "" ] && [ "${path_}" != '.' ]; do
462+
# Is the file here?
463+
if [ -f "${path_}/${1-}" ]; then
464+
file="${path_}/${1-}"
465+
echo "${file}"
466+
break 2
467+
fi
468+
path_=${path_%/*}
469+
done
470+
shift
458471
done
459-
nvm_echo "${path_}"
460472
}
461473

462474
nvm_find_nvmrc() {
463-
local dir
464-
dir="$(nvm_find_up '.nvmrc')"
465-
if [ -e "${dir}/.nvmrc" ]; then
466-
nvm_echo "${dir}/.nvmrc"
467-
else
468-
dir="$(nvm_find_up '.node-version')"
469-
if [ -e "${dir}/.node-version" ]; then
470-
nvm_echo "${dir}/.node-version"
471-
fi
472-
fi
475+
nvm_echo "$(nvm_find_up '.nvmrc' '.node-version')"
473476
}
474477

475478
# Obtain nvm version from rc file
@@ -483,15 +486,16 @@ nvm_rc_version() {
483486
fi
484487
return 1
485488
fi
489+
NVMRC_BASENAME="$(command basename "$NVMRC_PATH")"
486490
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf ''
487491
if [ -z "${NVM_RC_VERSION}" ]; then
488492
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
489-
nvm_err "Warning: empty nvm file found at \"${NVMRC_PATH}\""
493+
nvm_err "Warning: empty '${NVMRC_BASENAME}' file found at \"${NVMRC_PATH}\""
490494
fi
491495
return 2
492496
fi
493497
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
494-
nvm_echo "Found '${NVMRC_PATH}' with version <${NVM_RC_VERSION}>"
498+
nvm_echo "Found '${NVMRC_BASENAME}' with version <${NVM_RC_VERSION}>"
495499
fi
496500
}
497501

0 commit comments

Comments
 (0)