From 07739b483b37f938c7deda02313b9d847bb91c06 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 2 Jun 2021 15:30:52 -0700 Subject: [PATCH] find-node.sh supports Homebrew on M1 (#31622) 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 https://github.com/facebook/react-native/issues/31621 https://github.com/facebook/react-native/issues/31592 [General] [Changed] - find-node.sh supports Homebrew on M1 Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- react.gradle | 12 +++--------- scripts/find-node.sh | 8 +++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/react.gradle b/react.gradle index 5995ad5fbb328a..dd34c98cafff9f 100644 --- a/react.gradle +++ b/react.gradle @@ -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" diff --git a/scripts/find-node.sh b/scripts/find-node.sh index c111e70d927bb7..2ef8cf81484b0f 100755 --- a/scripts/find-node.sh +++ b/scripts/find-node.sh @@ -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 \ No newline at end of file +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