Merge pull request #1986 from Sayegh7/master

[Fix] Make installation less restrictive when NVM_DIR is set
Jordan Harband 2019-01-22 10:50:10 -08:00 committed by GitHub
commit 66d2909650
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 7 deletions

View File

@ -6,16 +6,22 @@ nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
nvm_install_dir() { nvm_default_install_dir() {
if [ -n "$NVM_DIR" ]; then if [ -n "$XDG_CONFIG_HOME" ]; then
printf %s "${NVM_DIR}"
elif [ -n "$XDG_CONFIG_HOME" ]; then
printf %s "${XDG_CONFIG_HOME/nvm}" printf %s "${XDG_CONFIG_HOME/nvm}"
else else
printf %s "$HOME/.nvm" printf %s "$HOME/.nvm"
fi fi
} }
nvm_install_dir() {
if [ -n "$NVM_DIR" ]; then
printf %s "${NVM_DIR}"
else
nvm_default_install_dir
fi
}
nvm_latest_version() { nvm_latest_version() {
echo "v0.34.0" echo "v0.34.0"
} }
@ -304,9 +310,18 @@ nvm_check_global_modules() {
nvm_do_install() { nvm_do_install() {
if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then
if [ -e "${NVM_DIR}" ]; then
echo >&2 "File \"${NVM_DIR}\" has the same name as installation directory."
exit 1
fi
if [ "${NVM_DIR}" = "$(nvm_default_install_dir)" ]; then
mkdir "${NVM_DIR}"
else
echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment." echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment."
exit 1 exit 1
fi fi
fi
if [ -z "${METHOD}" ]; then if [ -z "${METHOD}" ]; then
# Autodetect install method # Autodetect install method
if nvm_has git; then if nvm_has git; then
@ -406,7 +421,7 @@ nvm_reset() {
unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \ unset -f nvm_has nvm_install_dir nvm_latest_version nvm_profile_is_bash_or_zsh \
nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \ nvm_source nvm_node_version nvm_download install_nvm_from_git nvm_install_node \
install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \ install_nvm_as_script nvm_try_profile nvm_detect_profile nvm_check_global_modules \
nvm_do_install nvm_reset nvm_do_install nvm_reset nvm_default_install_dir
} }
[ "_$NVM_ENV" = "_testing" ] || nvm_do_install [ "_$NVM_ENV" = "_testing" ] || nvm_do_install