From 50e505dac888eaccac76fee5ab8fd8988b460d4a 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 ## Changelog [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 | 6 ++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/react.gradle b/react.gradle index 04b94aad9ee513..84b1f60df6e7b7 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 0d0a155b238bfe..c972be576fe152 100755 --- a/scripts/find-node.sh +++ b/scripts/find-node.sh @@ -31,3 +31,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then eval "$(anyenv init -)" 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