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.
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.
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.
@davidpfarrell I've attempted a slightly different approach. Can you take a look please?
There was a problem hiding this comment.
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
davidpfarrell
left a comment
There was a problem hiding this comment.
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
| if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] | ||
| then | ||
| source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" | ||
| source "$(brew --prefix nvm)/nvm.sh" |
There was a problem hiding this comment.
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.
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.
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.
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`.
Loading a brew-installed
nvmwas 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_checkhelper method, it was overlooked that${BASH_IT_HOMEBREW_PREFIX}/nvm.shis not the equivalent to$(brew --prefix nvm)/nvm.shsinceBASH_IT_HOMEBREW_PREFIXis set frombrew --prefixinstead 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
nvminstalled viabrew.Screenshots (if appropriate):
N/A
Types of changes
Checklist:
clean_files.txtand formatted it usinglint_clean_files.sh.