mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Mike Grabowski
parent
5ada078578
commit
7004cac535
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user