Skip to content

Commit 07e4953

Browse files
ivanmoskalevfacebook-github-bot
authored andcommitted
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: #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
1 parent a74347e commit 07e4953

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

scripts/generate-specs.sh

+11-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set -e
2727
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
2828
TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX)
2929
RN_DIR=$(cd "$THIS_DIR/.." && pwd)
30-
YARN_BINARY="${YARN_BINARY:-$(command -v yarn || true)}"
30+
NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}"
3131
USE_FABRIC="${USE_FABRIC:-0}"
3232

3333
cleanup () {
@@ -56,8 +56,8 @@ main() {
5656
CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen"
5757
CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen"
5858

59-
if [ -z "$YARN_BINARY" ]; then
60-
echo "Error: Could not find yarn. Make sure it is in bash PATH or set the YARN_BINARY environment variable." 1>&2
59+
if [ -z "$NODE_BINARY" ]; then
60+
echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
6161
exit 1
6262
fi
6363

@@ -72,18 +72,20 @@ main() {
7272

7373
if [ ! -d "$CODEGEN_PATH/lib" ]; then
7474
describe "Building react-native-codegen package"
75-
pushd "$CODEGEN_PATH" >/dev/null || exit 1
76-
"$YARN_BINARY"
77-
"$YARN_BINARY" build
78-
popd >/dev/null || exit 1
75+
bash "$CODEGEN_PATH/scripts/oss/build.sh"
76+
fi
77+
78+
if [ -z "$NODE_BINARY" ]; then
79+
echo "Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
80+
exit 1
7981
fi
8082

8183
describe "Generating schema from flow types"
82-
"$YARN_BINARY" node "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"
84+
"$NODE_BINARY" "$CODEGEN_PATH/lib/cli/combine/combine-js-to-schema-cli.js" "$SCHEMA_FILE" "$SRCS_DIR"
8385

8486
describe "Generating native code from schema (iOS)"
8587
pushd "$RN_DIR" >/dev/null || exit 1
86-
"$YARN_BINARY" --silent node scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME"
88+
"$NODE_BINARY" scripts/generate-specs-cli.js ios "$SCHEMA_FILE" "$TEMP_OUTPUT_DIR" "$CODEGEN_MODULES_LIBRARY_NAME"
8789
popd >/dev/null || exit 1
8890

8991
describe "Copying output to final directory"

0 commit comments

Comments
 (0)