Skip to content

Commit

Permalink
Invoke node directly in generate-specs.sh (#30781)
Browse files Browse the repository at this point in the history
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: #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
  • Loading branch information
ivanmoskalev authored and facebook-github-bot committed Feb 2, 2021
1 parent a74347e commit 07e4953
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scripts/generate-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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

Expand All @@ -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"
Expand Down

0 comments on commit 07e4953

Please sign in to comment.