Skip to content

Commit

Permalink
find-node.sh supports Homebrew on M1 (facebook#31622)
Browse files Browse the repository at this point in the history
Summary:
Homebrew on M1 installs executable binaries in **/opt/homebrew/bin** (See https://brew.sh/2021/02/05/homebrew-3.0.0/), and FBReactNativeSpec.build is failing because it couldn't find node. This PR changes find-node.sh script to add /opt/homebrew/bin into $PATH.

The way **react.gradle** trying to execute node is not using user environment variables, but system defaults, so it couldn't find it. I removed node execution, and hard coded cli path in parity with iOS https://github.com/facebook/react-native/blob/d1ab03235cb4b93304150878d2b9057ab45bba77/scripts/react-native-xcode.sh#L106

Fixes facebook#31621 facebook#31592

[General] [Changed] - find-node.sh supports Homebrew on M1

Pull Request resolved: facebook#31622

Test Plan: On M1, create a RN project and it'll fail to build iOS app. Apply the patch, and build will succeed.

Reviewed By: ShikaSD

Differential Revision: D28808206

Pulled By: hramos

fbshipit-source-id: 8b313b6685462a15e67d99c61a0202d17fece1ec
  • Loading branch information
dulmandakh authored and danilobuerger committed Oct 28, 2021
1 parent 7d0e758 commit 07739b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 3 additions & 9 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ def detectCliPath(config) {
if (config.cliPath) {
return config.cliPath
}

def cliPath = ["node", "-e", "console.log(require('react-native/cli').bin);"].execute([], projectDir).text.trim()

if (cliPath) {
return cliPath
} else if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
return "${projectDir}/../../node_modules/react-native/cli.js"
} else {
throw new Exception("Couldn't determine CLI location. " +
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
}
throw new Exception("Couldn't determine CLI location. " +
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
}

def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js"
Expand Down
8 changes: 7 additions & 1 deletion scripts/find-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
eval "$(anyenv init -)"
fi
fi
fi

# Support Homebrew on M1
HOMEBREW_M1_BIN=/opt/homebrew/bin
if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
export PATH="$HOMEBREW_M1_BIN:$PATH"
fi

0 comments on commit 07739b4

Please sign in to comment.