Skip to content

Commit

Permalink
Build rn-codegen in a temporary directory (#30292)
Browse files Browse the repository at this point in the history
Summary:
When running yarn install from the codegen directory it will reinstall all dependencies for the react-native workspace inside the react-native package. In my case this caused issues with metro because it would now have 2 copies of it (node_modules/metro and node_modules/react-native/node_modules/metro).

To avoid this copy the react-native-codegen source in a temporary directory and yarn install from there, then copy the built files back.

## Changelog

[Internal] - Build rn-codegen in a temporary directory

Pull Request resolved: #30292

Test Plan: Tested the script in an app with codegen enabled. Fresh install with rn-codegen not built, made sure no extra modules are installed under node_modules/react-native/node_modules.

Reviewed By: yungsters

Differential Revision: D24893216

Pulled By: fkgozali

fbshipit-source-id: 2c372b755632ea6f50ad5d4562248612b349a9a6
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Nov 12, 2020
1 parent 28cb7a7 commit d5db2cb
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/react-native-codegen/scripts/oss/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,35 @@ THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOUR
set -e
set -u

pushd "$THIS_DIR/../.." >/dev/null
CODEGEN_DIR="$THIS_DIR/../.."

yarn install 2> >(grep -v '^warning' 1>&2)
yarn run build
rm -rf "${CODEGEN_DIR:?}/lib" "${CODEGEN_DIR:?}/node_modules"

popd >/dev/null
YARN_BINARY="${YARN_BINARY:-$(command -v yarn)}"

if [[ "$FBSOURCE_ENV" -eq "1" ]]; then
# Custom FB-specific setup
pushd "$CODEGEN_DIR" >/dev/null

"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)
# Note: Within FBSOURCE_ENV, this has to explicitly run build.
"$YARN_BINARY" run build

popd >/dev/null
else
# Run yarn install in a separate tmp dir to avoid conflict with the rest of the repo.
# Note: OSS-only.
TMP_DIR=$(mktemp -d)

cp -R "$CODEGEN_DIR/." "$TMP_DIR"

pushd "$TMP_DIR" >/dev/null

# Note: this automatically runs build as well.
"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)

popd >/dev/null

mv "$TMP_DIR/lib" "$TMP_DIR/node_modules" "$CODEGEN_DIR"
rm -rf "$TMP_DIR"
fi

0 comments on commit d5db2cb

Please sign in to comment.