Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: React Native CodeGen integration for 0.64-stable #31027

Merged
merged 7 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down
Empty file.
Empty file.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"promise": "^8.0.3",
"prop-types": "^15.7.2",
"react-devtools-core": "^4.6.0",
"react-native-codegen": "^0.0.7",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: On 0.64-stable branch, React Native will always use CodeGen from npm, even when running from RNTester.

I wish we had Yarn Workspaces set up right, that way, I could point here to use local version of CodeGen when running from this repository.

Something we will have to improve in order to merge this to master.

CC: @hramos

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, this is more than fine. Right now, on 0.64-stable, in packages, we have CodeGen at 0.0.6 which doesn't work with this release. We would need to cherry-pick ALL commits related to CodeGen to bump it to 0.0.7.

By using an npm version instead, we can test RNTester and others. This isn't ideal setup, but works.

Copy link
Contributor

@janicduplessis janicduplessis Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use repo-config/package.json to add the codegen dep? This one is a regular workspace. Also what about using peerDeps? I don't fully understand the issue tho so I'm just throwing random ideas haha.

"react-refresh": "^0.4.0",
"regenerator-runtime": "^0.13.2",
"scheduler": "^0.20.1",
Expand Down Expand Up @@ -155,4 +156,4 @@
}
}
}
}
}
27 changes: 12 additions & 15 deletions scripts/generate-specs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,30 @@ 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
# Check if user-defined CODEGEN_PATH is correct
if [[ "$CODEGEN_PATH" && ! -d "$CODEGEN_PATH" ]]; then
grabbou marked this conversation as resolved.
Show resolved Hide resolved
echo "error: Could not find react-native-codegen at ${CODEGEN_PATH}. " \
"Perhaps you need to run npm install or otherwise " \
"point the CODEGEN_PATH variable to your custom location." >&2
exit 1
fi

# Default value of CODEGEN_PATH is a location of a react-native-codegen package
if [[ -z "$CODEGEN_PATH" ]]; then
CODEGEN_PATH=$("$NODE_BINARY" -e "console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))")
fi

# 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"

Expand Down
1 change: 0 additions & 1 deletion template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down