-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Properly detect NVM path on macOS using homebrew #5786
Conversation
NVM explicitly doesn't support installing with homebrew, so we definitely don't want to be using homebrew to install NVM. I'd be okay with the
|
That seems reasonable. I didn't realise nvm wasn't supported via homebrew. I think rather than warning people who use nvm via homebrew, let's just silently try to use it if it's there and the regular way of running nvm fails. The reason being, if they have installed it via homebrew and aren't having problems (as I have, with zero issues) then I don't see a need to rattle their cage over this issue. I also pushed up a change to my logic so rather than first checking for homebrew, it first checks for the standard location of nvm.sh, inside the .nvm dir, before trying homebrew as a fallback. |
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'm not particularly fussed about whether to include the warning about using homebrew, let's see if we get more reports as we get more people using the script.
bin/install-node-nvm.sh
Outdated
. "$NVM_DIR/nvm.sh" --no-use | ||
if [ -f "$NVM_DIR/nvm.sh" ]; then | ||
. "$NVM_DIR/nvm.sh" --no-use | ||
elif [ -n "$(command -v brew)" ]; 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.
Use command_exists
here. eg:
elif command_exists "brew"; 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.
(Side note: command_exists
is a helper function we use: https://github.com/WordPress/gutenberg/blob/master/bin/includes.sh#L123-L134)
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.
Cool, fixed
bin/install-node-nvm.sh
Outdated
@@ -9,8 +9,12 @@ set -e | |||
|
|||
# Load NVM | |||
if [ -n "$NVM_DIR" ]; then | |||
# The --no-use option ensures loading NVM doesn't switch the current version. |
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.
Any particular reason for deleting this 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.
User error ;) fixed.
bin/install-node-nvm.sh
Outdated
. "$NVM_DIR/nvm.sh" --no-use | ||
elif [ -n "$(command -v brew)" ]; then | ||
# use homebrew that to find path to nvm.sh | ||
. "$(brew --prefix nvm)/nvm.sh" --no-use |
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.
Need to check that the file exists before including it: it could've been installed with some other package manager.
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.
Good catch.
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.
👍🏻
Description
When attempting to build the plugin on macOS, I encountered the following error:
By detecting homebrew and using the
--prefix
command, we can find the true path to nvm.sh on macOS systems.How Has This Been Tested?
By running ./bin/setup-local-env.sh and seeing that it completes without error. Hopefully my
else
clause allows this to work properly on Linux machines, which I have NOT tested.I also tried with
nvm
uninstalled, ensuring thatbrew
was used to installnvm
on systems with homebrew available.Types of changes
Check for
brew
command and use to findnvm.sh
, and to installnvm
if necessary.Checklist: