From 7004cac5358bab2b6b3d5f4aedc464d57a8bb615 Mon Sep 17 00:00:00 2001 From: Ivan Moskalev Date: Tue, 2 Feb 2021 15:06:17 -0800 Subject: [PATCH] Invoke `node` directly in generate-specs.sh (#30781) Summary: Currently, Codegen bash wrapper (`generate-specs.sh`) for Xcode invokes JS-based Codegen tooling via `yarn --silent node <...>`. This breaks both: - when Yarn is not installed (if NPM is used), for obvious reasons - when Yarn v2 ("Berry") is active This PR changes the way `generate-specs.sh` locates `node` executable to the following algorithm: - use the path provided in the `NODE_BINARY` env var - if `NODE_BINARY` env var is not defined, find `node` with `command -v node` ## Changelog [iOS] [Fixed] - Fix Codegen silently failing when Yarn is not installed, or when Yarn v2 is active. Pull Request resolved: https://github.com/facebook/react-native/pull/30781 Test Plan: ### Case 1 (no Yarn installed) 1. Ensure `yarn` is not present in PATH 2. Run Xcode build 3. Check that Codegen artifacts are produced ### Case 2 (Yarn v2 is used) 1. Ensure `yarn` is running in the v2 ("Berry") mode 2. Run Xcode build 3. Check that Codegen artifacts are produced Reviewed By: fkgozali Differential Revision: D26187081 Pulled By: hramos fbshipit-source-id: 77d3089f523b8c976d8223b77ff9553cb6cf68a5 --- scripts/generate-specs.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index 6397a7f3fb0..ab297fd18d7 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -27,7 +27,7 @@ set -e THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX) RN_DIR=$(cd "$THIS_DIR/.." && pwd) -YARN_BINARY="${YARN_BINARY:-$(command -v yarn || true)}" +NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}" USE_FABRIC="${USE_FABRIC:-0}" cleanup () { @@ -56,8 +56,8 @@ main() { CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen" - if [ -z "$YARN_BINARY" ]; then - echo "Error: Could not find yarn. Make sure it is in bash PATH or set the YARN_BINARY environment variable." 1>&2 +if [ -z "$NODE_BINARY" ]; then + echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 exit 1 fi @@ -72,18 +72,20 @@ main() { if [ ! -d "$CODEGEN_PATH/lib" ]; then describe "Building react-native-codegen package" - pushd "$CODEGEN_PATH" >/dev/null || exit 1 - "$YARN_BINARY" - "$YARN_BINARY" build - popd >/dev/null || exit 1 + bash "$CODEGEN_PATH/scripts/oss/build.sh" + fi + + if [ -z "$NODE_BINARY" ]; then + echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2 + exit 1 fi describe "Generating schema from flow types" - "$YARN_BINARY" node "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR" + "$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR" describe "Generating native code from schema (iOS)" pushd "$RN_DIR" >/dev/null || exit 1 - "$YARN_BINARY" --silent node scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME" + "$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME" popd >/dev/null || exit 1 describe "Copying output to final directory"