-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix loading of nvm for brew-installed nvm #2162
Conversation
TIL some formula can have unique prefixes, which is probably why the formula name is an optional argument to the
My guess is that this bug pretty much fully invalidates There might be a way to introduce a convenience function like |
@davidpfarrell What's the next step here? |
plugins/available/nvm.plugin.bash
Outdated
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] | ||
if _bash_it_homebrew_check && [[ -s "$(brew --prefix nvm)/nvm.sh" ]] | ||
then | ||
source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" | ||
source "$(brew --prefix nvm)/nvm.sh" |
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.
When we were using a variable that almost-certainly existed with a valid value, the reference was fine.
BUT using the result of a sub-shell that may not return a valid value seems more risky.
ie. When brew is not managing the nvm install, you get a msg on stderr:
Error: No available formula with the name "nvm".
But the test continues, essentially checking for "/nvm.sh".
I think we need to isolate the fetching of the prefix call and check it if it's valid before using it.
Also, invoking brew
twice seems a bit heavy.
It also feels like it runs the risk of triggering brew's random update check, although I haven't researched if it can be triggered during a --prefix
check ...
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 is only reverting to the old approach. I think that we should probably merge this fix, and then improve BASH_IT_HOMEBREW_PREFIX as a further improvement
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.
@davidpfarrell I've attempted a slightly different approach. Can you take a look please?
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.
Also, I've verified that brew --prefix ...
is actually quite a lightweight operation and won't trigger auto-updates: https://github.com/Homebrew/brew/blob/8421b702c5bdc0861b4c794af342d8705e6bc622/Library/Homebrew/brew.sh#L99-L101
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.
Hey!
Glad to see progress on this. I'm totally fine punting on a global brew_prefix_installed
function and just checking it explicitly here.
I do have a few notes, but I think its close!
plugins/available/nvm.plugin.bash
Outdated
then | ||
source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" | ||
source "$(brew --prefix nvm)/nvm.sh" |
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.
Since $NVM_BREW_PREFIX
already contains the result of $(brew --prefix nvm)
, shouldn't this be:
source "${NVM_BREW_PREFIX}/nvm.sh"
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.
fair point, fixed
NVM_BREW_PREFIX="" | ||
if _bash_it_homebrew_check | ||
then | ||
NVM_BREW_PREFIX=$(brew --prefix nvm 2>/dev/null) |
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.
In my (now old) message, I mentioned:
$(brew --prefix --installed $forumula)
With the --installed
option, it only returns a value if the formula is installed.
Without it, when the formula is not installed, it would return where the formula would be installed (vs returning nothing)
Maybe you can test this logic locally to confirm, but I think we want the --installed
flag here.
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.
brew --prefix --installed $formula
runs about 30x slower (over a second on my machine) than brew --prefix $formula
(30ms) because it has to exec a ruby script instead of just staying in the bash
portion of brew
. And since we're checking the existence of the script just below, I don't think we should care about the specifics of brew --prefix --installed nvm
vs just brew --prefix nvm
This reverts to the original (working) version from 2017. During the most recent refactor to use the `_bash_it_homebrew_check` helper method, it was overlooked that `${BASH_IT_HOMEBREW_PREFIX}/nvm.sh` is not the equivalent to `$(brew --prefix nvm)/nvm.sh` since `BASH_IT_HOMEBREW_PREFIX` is set from `brew --prefix` instead of `brew --prefix nvm`.
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.
seemsw legit.
Loading a brew-installed
nvm
was previously broken. This PR fixes it.Description
This reverts to the original (working) version from 2017. During the most recent refactor to use the
_bash_it_homebrew_check
helper method, it was overlooked that${BASH_IT_HOMEBREW_PREFIX}/nvm.sh
is not the equivalent to$(brew --prefix nvm)/nvm.sh
sinceBASH_IT_HOMEBREW_PREFIX
is set frombrew --prefix
instead ofbrew --prefix nvm
.Motivation and Context
This fixes a regression caused by 65ef8e2.
How Has This Been Tested?
I've tested this on my local instance where I have
nvm
installed viabrew
.Screenshots (if appropriate):
N/A
Types of changes
Checklist:
clean_files.txt
and formatted it usinglint_clean_files.sh
.