Skip to content

Commit fb2991e

Browse files
janicduplessisalloy
authored andcommitted
Build rn-codegen in a temporary directory (#30292)
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
1 parent 06fedcd commit fb2991e

File tree

1 file changed

+30
-4
lines changed
  • packages/react-native-codegen/scripts/oss

1 file changed

+30
-4
lines changed

packages/react-native-codegen/scripts/oss/build.sh

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,35 @@ THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOUR
1111
set -e
1212
set -u
1313

14-
pushd "$THIS_DIR/../.." >/dev/null
14+
CODEGEN_DIR="$THIS_DIR/../.."
1515

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

19-
popd >/dev/null
18+
YARN_BINARY="${YARN_BINARY:-$(command -v yarn)}"
19+
20+
if [[ "$FBSOURCE_ENV" -eq "1" ]]; then
21+
# Custom FB-specific setup
22+
pushd "$CODEGEN_DIR" >/dev/null
23+
24+
"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)
25+
# Note: Within FBSOURCE_ENV, this has to explicitly run build.
26+
"$YARN_BINARY" run build
27+
28+
popd >/dev/null
29+
else
30+
# Run yarn install in a separate tmp dir to avoid conflict with the rest of the repo.
31+
# Note: OSS-only.
32+
TMP_DIR=$(mktemp -d)
33+
34+
cp -R "$CODEGEN_DIR/." "$TMP_DIR"
35+
36+
pushd "$TMP_DIR" >/dev/null
37+
38+
# Note: this automatically runs build as well.
39+
"$YARN_BINARY" install 2> >(grep -v '^warning' 1>&2)
40+
41+
popd >/dev/null
42+
43+
mv "$TMP_DIR/lib" "$TMP_DIR/node_modules" "$CODEGEN_DIR"
44+
rm -rf "$TMP_DIR"
45+
fi

0 commit comments

Comments
 (0)