From 14db556963a63f0e7fbd74d2956fe56d7c941778 Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 1 Mar 2021 14:15:26 +0100 Subject: [PATCH] fix: React Native CodeGen integration for 0.64-stable (#31027) --- .gitignore | 1 - .../FBReactNativeSpec-generated.mm | 0 .../FBReactNativeSpec/FBReactNativeSpec.h | 0 package.json | 3 ++- scripts/generate-specs.sh | 24 ++++++------------ scripts/react-native-xcode.sh | 25 ++----------------- template/package.json | 1 - 7 files changed, 11 insertions(+), 43 deletions(-) create mode 100644 React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm create mode 100644 React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h diff --git a/.gitignore b/.gitignore index 9aea329a6c35fd..4f47d314cfb085 100644 --- a/.gitignore +++ b/.gitignore @@ -100,7 +100,6 @@ package-lock.json !/packages/rn-tester/Pods/__offline_mirrors__ # react-native-codegen -/React/FBReactNativeSpec/FBReactNativeSpec /packages/react-native-codegen/lib /ReactCommon/react/renderer/components/rncore/ diff --git a/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm b/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec-generated.mm new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/React/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/package.json b/package.json index b4e3edafdc5227..bd812e0ace956c 100644 --- a/package.json +++ b/package.json @@ -106,6 +106,7 @@ "promise": "^8.0.3", "prop-types": "^15.7.2", "react-devtools-core": "^4.6.0", + "react-native-codegen": "^0.0.7", "react-refresh": "^0.4.0", "regenerator-runtime": "^0.13.2", "scheduler": "^0.20.1", @@ -156,4 +157,4 @@ } } } -} \ No newline at end of file +} diff --git a/scripts/generate-specs.sh b/scripts/generate-specs.sh index ab297fd18d7fb2..aed955e01e1093 100755 --- a/scripts/generate-specs.sh +++ b/scripts/generate-specs.sh @@ -27,6 +27,10 @@ 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) + +# find node path +source "$RN_DIR/scripts/find-node.sh" + NODE_BINARY="${NODE_BINARY:-$(command -v node || true)}" USE_FABRIC="${USE_FABRIC:-0}" @@ -53,33 +57,19 @@ main() { TEMP_OUTPUT_DIR="$TEMP_DIR/out" SCHEMA_FILE="$TEMP_DIR/schema.json" - CODEGEN_REPO_PATH="$RN_DIR/packages/react-native-codegen" - CODEGEN_NPM_PATH="$RN_DIR/../react-native-codegen" - -if [ -z "$NODE_BINARY" ]; then + 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 - if [ -d "$CODEGEN_REPO_PATH" ]; then - CODEGEN_PATH=$(cd "$CODEGEN_REPO_PATH" && pwd) - elif [ -d "$CODEGEN_NPM_PATH" ]; then - CODEGEN_PATH=$(cd "$CODEGEN_NPM_PATH" && pwd) - else - 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 + CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))") + # Special case for running CodeGen from source: build it 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" diff --git a/scripts/react-native-xcode.sh b/scripts/react-native-xcode.sh index 9b059a6597d776..09b6c40e6ae5d2 100755 --- a/scripts/react-native-xcode.sh +++ b/scripts/react-native-xcode.sh @@ -64,9 +64,6 @@ PROJECT_ROOT=${PROJECT_ROOT:-"$REACT_NATIVE_DIR/../.."} cd "$PROJECT_ROOT" || exit -# Define NVM_DIR and source the nvm.sh setup script -[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm" - # Define entry file if [[ "$ENTRY_FILE" ]]; then # Use ENTRY_FILE defined by user @@ -82,26 +79,8 @@ if [[ $DEV != true && ! -f "$ENTRY_FILE" ]]; then exit 2 fi -if [[ -s "$HOME/.nvm/nvm.sh" ]]; then - . "$HOME/.nvm/nvm.sh" -elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then - . "$(brew --prefix nvm)/nvm.sh" -fi - -# Set up the nodenv node version manager if present -if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then - eval "$("$HOME/.nodenv/bin/nodenv" init -)" -elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then - eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)" -fi - -# Set up the ndenv of anyenv if preset -if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then - export PATH=${HOME}/.anyenv/bin:${PATH} - if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then - eval "$(anyenv init -)" - fi -fi +# find node path +source "$REACT_NATIVE_DIR/scripts/find-node.sh" # check and assign NODE_BINARY env # shellcheck source=/dev/null diff --git a/template/package.json b/template/package.json index e4bde1985d64a2..5705a7487966f7 100644 --- a/template/package.json +++ b/template/package.json @@ -21,7 +21,6 @@ "eslint": "7.14.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "^0.64.0", - "react-native-codegen": "^0.0.7", "react-test-renderer": "17.0.1" }, "jest": {