From bec5e147cb0a84225f88b3dbc2f87c39c0ef0bc7 Mon Sep 17 00:00:00 2001 From: Ivan Moskalev Date: Sat, 16 Jan 2021 09:52:39 +0300 Subject: [PATCH 1/3] Invoke `node` directly in generate-specs.sh Codegen script for Xcode invokes `yarn --silent node <...>`, which breaks both when Yarn is not installed (if NPM is used), or when Yarn v2 ("Berry") is active. This commit changes generate-specs.sh to use `node` set via a `NODE_BINARY` env var, or, if it is not defined, find it with `command -v node`. --- scripts/generate-specs.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index cd4ef2902d2bdf..e5ab83749eeafd 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -28,6 +28,7 @@ THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOUR TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX) RN_DIR=$(cd "$THIS_DIR/.." && pwd) YARN_BINARY="${YARN_BINARY:-$(command -v yarn)}" +NODE_BINARY="${NODE_BINARY:-$(command -v node)}" USE_FABRIC="${USE_FABRIC:-0}" cleanup () { @@ -74,11 +75,11 @@ main() { 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 - "$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 mkdir -p "$CODEGEN_COMPONENTS_OUTPUT_DIR" "$CODEGEN_MODULES_OUTPUT_DIR" From 427a39d8805370d3d44a77d7ab3395869e0ed6c0 Mon Sep 17 00:00:00 2001 From: Ivan Moskalev Date: Mon, 1 Feb 2021 16:12:24 +0300 Subject: [PATCH 2/3] Call `$CODEGEN_PATH/scripts/oss/build.sh` from `generate-specs.sh` --- scripts/generate-specs.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index e5ab83749eeafd..3094f196b110ba 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -27,7 +27,6 @@ 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)}" NODE_BINARY="${NODE_BINARY:-$(command -v node)}" USE_FABRIC="${USE_FABRIC:-0}" @@ -68,10 +67,7 @@ main() { if [ ! -d "$CODEGEN_PATH/lib" ]; then describe "Building react-native-codegen package" - pushd "$CODEGEN_PATH" >/dev/null || exit - "$YARN_BINARY" - "$YARN_BINARY" build - popd >/dev/null || exit + bash "$CODEGEN_PATH/scripts/oss/build.sh" fi describe "Generating schema from flow types" From 9facb236a7f7f52a8f4fe1d63ec1b3a57d75e991 Mon Sep 17 00:00:00 2001 From: Ivan Moskalev Date: Mon, 1 Feb 2021 16:15:22 +0300 Subject: [PATCH 3/3] Fail `generate-specs.sh` gracefully if `node` executable cannot be located --- scripts/generate-specs.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index 3094f196b110ba..d3b082d0437125 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) -NODE_BINARY="${NODE_BINARY:-$(command -v node)}" +NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}" USE_FABRIC="${USE_FABRIC:-0}" cleanup () { @@ -64,12 +64,17 @@ main() { echo "Error: Could not determine react-native-codegen location. Try running 'yarn install' or 'npm install' in your project root." 1>&2 exit 1 fi - + if [ ! -d "$CODEGEN_PATH/lib" ]; then describe "Building react-native-codegen package" 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" "$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"