Add shared monorepo build setup
Summary:
Context
RFC: Decoupling Flipper from React Native core: https://github.com/react-native-community/discussions-and-proposals/pull/641
Changes
To support incoming new React Native packages around debugging (including migrating over @react-native-community/cli-plugin-metro) — which target Node.js and require a build step, this PR adds a minimal shared build setup across the react-native monorepo.
The setup is closely inspired/based on the build scripts in Jest, Metro, and React Native CLI — and is a simple set of script wrappers around Babel and Chokidar. These are available as build commands at the root of the repo:
-
yarn build -
yarn clean -
yarn watch
Build configuration (i.e. Babel config) is shared as a set standard across the monorepo, and packages are opted-in to requiring a build, configured in scripts/build.config.js.
const buildConfig /*: BuildConfig */ = {
// The packages to include for build and their build options
packages: {
'dev-middleware': {target: 'node'},
},
};
For now, there is a single target: 'node' option — this is necessary as react-native, unlike the above other projects, is a repository with packages targeting several runtimes. We may, in future, introduce a build step for other, non-Node, packages — which may be useful for things such as auto-generated TypeScript definitions.
Current integration points
-
.circleci/config.yml— Added torun_yarn(with project install). - Root
yarn start— Convenience for local developers. -
yarn startwithinpackages/rn-tester— Convenience for local developers.
Planned: I will be adding notes on yarn build to the following "Contributing" website pages:
- https://reactnative.dev/contributing/overview#contributing-code
- https://reactnative.dev/contributing/how-to-open-a-pull-request#chapter-ii-implementing-your-changes
This is not load bearing quite yet: There are not yet any built packages added to the dependencies of packages/react-native/, so this will be further tested in a later PR (internally stacked as the next change).
Alternative designs
Per-package config file
Replace scripts/build/config.js with a package-defined key in in package.json, similar to Jest's publishConfig.
"buildConfig": {
"type": "node"
},
This would be the only customisation required, with a single Babel config still standardised. Another option this might receive in future is enableTypeScriptCodgeen.
Rollup
More sophisticated build tool for Node.js, used by the React codebase (albeit within a custom script setup as well).
Lerna and Nx
- Most sophisticated setup enabling caching and optimised cloud runs.
- Probably the most likely thing we'll move towards at a later stage.
Changelog: [Internal]
Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
| Warnings | |
|---|---|
| :warning: | :lock: package.json - Changes were made to package.json. This will require a manual import by a Facebook employee. |
Generated by :no_entry_sign: dangerJS against 87edd0e1a8e6651065ad37bdd852842955438896
Note: Includes https://github.com/facebook/react-native/pull/38194, will be rebased.
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 8,836,447 | +4 |
| android | hermes | armeabi-v7a | 8,146,331 | +0 |
| android | hermes | x86 | 9,341,813 | +0 |
| android | hermes | x86_64 | 9,184,550 | +2 |
| android | jsc | arm64-v8a | 9,448,262 | +3 |
| android | jsc | armeabi-v7a | 8,630,015 | +0 |
| android | jsc | x86 | 9,530,933 | +0 |
| android | jsc | x86_64 | 9,774,146 | +1 |
Base commit: 0cdb9e6a52f69ebee635d5bfaa34a52f6059dd47 Branch: main
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
This pull request was exported from Phabricator. Differential Revision: D46759508
Abandoning in favour of a runnable-from-source approach (that still includes build) — will be a separate PR replacing this.