-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[Fix] Make installation less restrictive when NVM_DIR is set #1986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
install.sh
Outdated
| nvm_do_install() { | ||
| if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then | ||
| echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment." | ||
| # If NVM_DIR is set to something other than the default, exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like the right behavior - it's expected and by design that a user setting NVM_DIR beforehand can alter the location in which nvm is installed.
The specific thing that's a problem is when the specified override directory does not exist (and this PR is, I believe, hoping to skip that error checking when the directory doesn't exist but it's the default path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If NVM_dir is defined and it is NOT what the installer would set it to (i.e. "$HOME/.nvm"), complain and exit
#1962 (comment)
This comment in the issue had the above suggestion and I assumed this is the required behavior.
So what would the correct behavior be if I ignore that comment? Should I attempt to create the specified override directory if it does not exist only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only time I think it's reasonable to create the directory is if it a) does not exist and b) is what the default would be anyways. If it does not exist, and is not the default, I think the current behavior should remain.
|
@ljharb I corrected the behavior and added a check for the case when |
ljharb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some tweaks; let me know if this still matches what you hope :-)
| if [ -n "${NVM_DIR-}" ] && ! [ -d "${NVM_DIR}" ]; then | ||
| echo >&2 "You have \$NVM_DIR set to \"${NVM_DIR}\", but that directory does not exist. Check your profile files and environment." | ||
| exit 1 | ||
| if [ -e "${NVM_DIR}" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this logic up; if it's a non-directory file, we always want to error out.
| type "$1" > /dev/null 2>&1 | ||
| } | ||
|
|
||
| nvm_default_install_dir() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this logic here, so that both of the legitimate defaults could be respected without hardcoding either more than once.
|
@ljharb Seems good to me 😄 |
This PR fixes #1962.
It handles the following cases while installing nvm:
IfNVM_DIRis defined and set to anything other than the default value, exit installationNVM_DIRis defined and set to a file location not a directory, exit installationNVM_DIRdoesn't already exist, create the folder