Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41466
## Context
In open source, all apps use the same turbomodulemanager delegate (i.e: the default delegate).
This diff introduces the buck infra that makes the oss default delegate work for meta apps.
Concretely, we are going to make React Native use the same delegate for **all** Meta apps.
Each Meta app will:
1. At build time, generate a unique TMProvider map
2. At app init time, initialize the default delegate with the TMProvider map.
## Implementation
**Step #1:** At build time, generate a unique TMProvider map
**Insight:** Buck genrules can accept, as input, the output of a buck query.
So, here's how we get this done:
1. Buck query (i.e: input to Genrule): Given the app's deps, query all the schemas in the app.
2. Genrule: Read the schemas to generate the TMProvider map. The TMProvider map will also contain **all** the app's C++ module codegen.
Concretely:
1. This diff introduces a macro: rn_codegen_appmodules(deps).
2. rn_codegen_appmodules(deps) generates appmodules.so, which contains the TMProvider map.
**Step #2:** At app init time, initialize the default delegate with the TMProvider map.
This is how we'll initialize the DefaultTurboModuleManagerDelegate:
1. DefaultTurboModuleManagerDelegate will load appmodules.so during init.
2. When loaded, appmodules.so will assign the code-generated TMProvider map to DefaultTurboModuleManagerDelegate.
## Impact
This should allow us to:
1. Get one step closer to getting rid of the `js1 build turbomodule-manager-delegates --target <app>` script
3. Remove the TurboModuleManagerDelegate from React Native's public API. (Because we use one delegate for all React Native apps in Meta and OSS)
Changelog: [Internal]
Reviewed By: mdvacca
Differential Revision: D50988397
fbshipit-source-id: 0ca5dec14e2dae89ec97f5d39a182c7937c5c7bf
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41554
This diff removes inefficiency where we first write schema to disk in `combine-js-to-schema.js`, and then read it from disk in `generate-specs-cli-executor.js`. With this change we can just pass it as an argument.
Changelog: [Internal]
Reviewed By: cipolleschi
Differential Revision: D51161162
fbshipit-source-id: 35d14ca3e53e4bf999520c635c66909c20081096
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/41534
This diff deletes calls to `node` from `generate-artifacts-executor.js`, and replaces them with normal `requires` of JS sources.
This is a squashed version of (D51116291 ... D51158799).
The following sequence of changes has been made:
1. Require and directly invoke `generate-specs-cli-executor` instead of using `node`.
2. Use `codegen-util` to get `RNCodegen` in `generate-provider-cli.js`.
3. Use `RNCodegen` directly instead of using `node`.
4. Move all implementation code from `combine-js-to-schema-cli.js` to `combine-js-to-schema.js`.
5. Decouple building the codegen from getting the codegen CLI.
6. Use `combine-js-to-schema` directly instead of using `node`.
7. Delete unit test that was testing node invocation.
8. Delete `nodeBinary` argument form `generate-codegen-artifacts.js` and its callsites.
Changelog: [Internal]
Reviewed By: cipolleschi
Differential Revision: D51158845
fbshipit-source-id: 5e039801c8045a42349f7cb6ca28e2df24634589
Summary:
In pnpm setups, codegen will fail during build because it cannot find its dependencies. Some of the dependencies it relies on at runtime are currently declared under `devDependencies`. This change moves them to `dependencies`.
## Changelog:
[GENERAL] [FIXED] - Fix `react-native/codegen` not being able to resolve dependencies in pnpm setups
Pull Request resolved: https://github.com/facebook/react-native/pull/41398
Test Plan: We are currently trying to [enable pnpm mode](https://github.com/microsoft/rnx-kit/pull/2811) in rnx-kit and hit this issue. We've patched this package locally and it works.
Reviewed By: christophpurrer
Differential Revision: D51169116
Pulled By: NickGerleman
fbshipit-source-id: 28906a0de412c660d2fc42f62deaf77240d27a58
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39036
Changelog: [General][Changed] Use `hermes-parser` instead of `flow-parser` to parse Flow Codegen specs.
`hermes-parser` is a WASM build of the Hermes parser (plus supporting code), maintained by the Flow and Hermes teams. It is the recommended way of parsing Flow code in Node and its benefits (compared to `flow-parser`) include better performance and improved type safety.
Here we update `react-native/codegen` to use `hermes-parser` instead of `flow-parser`. Both parsers produce ASTs that conform to the ESTree spec so this is mostly a drop-in replacement.
In future work we should be able to use the improved AST types available in `hermes-estree` to improve type safety within `react-native/codegen` itself.
Reviewed By: huntie
Differential Revision: D48384078
fbshipit-source-id: 310ad150ec62671ba395b0e2f6415ccae97ac04d
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39035
Changelog: [General][Fixed] Flow syntax errors in Codegen specs are no longer ignored.
Instead of throwing errors like most parsers, the `flow-parser` package returns errors as part of the AST (along with a best-effort parse). It turns out that `react-native/codegen` ignores such errors and only detects a subset of them after the fact. Here we change the behaviour to immediately throwing a descriptive error message (containing the file name and a code frame).
**This change is theoretically breaking** for any published packages that already contain broken Flow code (that somehow doesn't happen to affect the Codegen output today). Hopefully, anyone using Flow-flavoured RN Codegen is also typechecking with Flow and/or building with Metro (which would both flag the same errors), so the impact should be fairly contained.
Reviewed By: huntie
Differential Revision: D48385786
fbshipit-source-id: c7e1f5fb64a61fb0eb9e9f8f7501b43264c9626c
Summary:
Update various scripts to support AsExpressions, found by looking for scripts currently handling `TypeCastExpression`
Changelog: [Internal]
Reviewed By: SamChou19815
Differential Revision: D50822952
fbshipit-source-id: c88c04a507d94ddbc6458a68fd36509463e91953
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39540
This simplifies the use of Codegen when creating dev builds of `rn-tester` in the monorepo. It now runs from source for this internal scenario, and this package is now built using the shared monorepo build setup.
Changes:
- Migrate `packages/react-native-codegen` to the shared `yarn build` setup.
- Update package to use `"exports"` field and wrap entry point modules with `babel-register` (NOTE: This is only required for each entry point internally used in the monorepo).
- Fixup small Flow syntax quirks that fail under `hermes-parser`.
- Remove `BuildCodegenCLITask` task from Android build.
- Remove Codegen `build.sh` call from iOS build, use `require.resolve` for `combine-js-to-schema-cli.js` entry point.
Externally significant FYIs:
- `react-native/codegen` is converted to use the `"exports"` field — it should export all `.js` files, as before.
- `codegenPath` is now ignored and marked as deprecated on `ReactExtensions.kt`.
NOTE: TypeScript auto-generation is not yet enabled on this package, since it uses CommonJS `module.exports` syntax (unsupported by `flow-api-translator`).
Changelog: [Internal]
Reviewed By: cipolleschi
Differential Revision: D49370200
fbshipit-source-id: 992913155169912ea1a3cb24cb26efbd3f783058
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39566
Fixes running the `build.sh` script for `react-native-codegen` when on [EdenFS](https://github.com/facebook/sapling). This would previously fail due a filesystem "unable to copy extended attributes" error.
This only affects development within the React Native monorepo. Practically, this equates to a workflow improvement for Meta engineers when creating `RNTester` builds.
NOTE: **This is temporary**. The change from `mv` to `cp -R` makes this script more expensive, which will make Android builds via Gradle take slightly longer. I have a WIP cleanup planned which will 1/ move `react-native-codegen` to the [shared monorepo build setup](https://github.com/facebook/react-native/pull/38718), and 2/ drop this step entirely from the Android Gradle build.
Changelog: [Internal]
Reviewed By: christophpurrer
Differential Revision: D49468891
fbshipit-source-id: 25d5db81798cf8ab150a135174a45f4d4c2cb5a2
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39454
1. Build with C++ 20 everywhere.
2. Update folly in OSS build to avoid a warning, and let us opt out of heavy bits required for supporting coroutines (we are still more than a year behind).
3. Update the folly podspec for the new version of folly
4. Update the many, many, copy/pasted header search paths for folly dependencies to be able to resolve fmt, now exposed to folly headers
4. Replaces a deprecated atomic usage with equivalent.
5. Fixes a deprecated implicit capturing `this` by value in lambda (same behavior, added a TODO because it seems sus)
Changelog: [Internal]
Reviewed By: sammy-SC
Differential Revision: D49271685
fbshipit-source-id: 16610f7bcd1032d5796cc11f1cfa92a33d8c2593
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39422
Those scripts were used when Buck OSS was invoking codegen. As we don't do Buck OSS anymore, we can remove them.
Changelog:
[Internal] [Changed] - Remove Codegen buck-oss scripts as they're unused
Reviewed By: huntie
Differential Revision: D49229846
fbshipit-source-id: fad0526e609bab159c56a62b85c91690e4cdbbce
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39212
## Changelog:
[Internal] -
Some of the generated C++ code was badly formatted - even though it's normally not supposed to be read by humans, sometimes it's still useful/needed, so it helps when it's more readable.
Reviewed By: christophpurrer
Differential Revision: D48827010
fbshipit-source-id: 3481af68ee6158902007c431e72e631d852c8b3c
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39136
## Changelog:
[Internal] -
`getConstants()` method for TM was enforced to only use object literals for the return type specs.
This limits flexibility, in particular those data structures can't be consequently exported and picked up by codegen (not even mentioning the potential need for copypasting those obejct literals around).
This relaxes this restriction.
Note that I've been digging into the development history in order to find out whether there was any particular historical reason for such a limitation, but couldn't find any, so I assume it was rather incidental.
Reviewed By: christophpurrer
Differential Revision: D48620652
fbshipit-source-id: 92d6ba531fc99fb9b25b4957ae123e7832f44ee4
Summary:
Android builds with new arch fail on Windows build host (https://github.com/facebook/react-native/issues/36475). This tiny correction fixes generation of `schema.json` (without it codegen failed to find any files, and generated empty schema). Unfortunately, does not fixes the issue with Windows host entirely, as builds still fail later (on ninja build step).
## Changelog:
[Android] [Fixed] - A bug fix for Android builds with new arch on Windows host.
Pull Request resolved: https://github.com/facebook/react-native/pull/36542
Reviewed By: NickGerleman
Differential Revision: D48563587
Pulled By: cortinico
fbshipit-source-id: acd510308ce9768fb17d3a33c7927de3237748ac
Summary:
[Codegen 119] This PR introduces `emitBuildEventSchema` to parser commons and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[Internal] [Changed] - Add `emitBuildEventSchema` to parser commons and update usages.
Pull Request resolved: https://github.com/facebook/react-native/pull/38810
Test Plan:
Run `yarn jest react-native-codegen` locally and ensure CI is green
## Screenshot of test passing locally:
<img width="1047" alt="Screenshot 2023-08-07 at 8 03 49 AM" src="https://github.com/facebook/react-native/assets/64726664/ab87f004-d9f8-4b5f-800b-0e724430301f">
Reviewed By: rshest
Differential Revision: D48155051
Pulled By: cipolleschi
fbshipit-source-id: a3db3f4783d60681b366a871b1d2ee32eb864bc0
Summary:
[Codegen 131] This PR add a function `emitUnionProp` to the parser-primitives, as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[INTERNAL] [ADDED] - Add `emitUnionProp` function to parser-primitives
Pull Request resolved: https://github.com/facebook/react-native/pull/38705
Test Plan: `yarn test react-native-codegen`
Reviewed By: christophpurrer
Differential Revision: D47921708
Pulled By: rshest
fbshipit-source-id: c2c081c6317928e5eb8b0c1d0640c7b7f40a4b0b
Summary:
[Codegen 135] This PR introduces `getPaperTopLevelNameDeprecated` to parser base class and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[Internal] [Changed] - Add `getPaperTopLevelNameDeprecated` to parser base class and update usages.
Pull Request resolved: https://github.com/facebook/react-native/pull/38683
Test Plan:
Run `yarn jest react-native-codegen` locally and ensure CI is green
## Screenshot of test passing locally:
<img width="1060" alt="Screenshot 2023-07-30 at 10 04 24 AM" src="https://github.com/facebook/react-native/assets/64726664/3f61377b-9f44-45e8-bece-d4fd6bcc4567">
Reviewed By: cipolleschi
Differential Revision: D47902816
Pulled By: rshest
fbshipit-source-id: 6fab53e02cfc3f0aaa3ffd795c3fe1d2f723e060
Summary:
[Codegen 130] This PR add a `getLiteralValue` function to the Parser interface, which returns the literal value of an union represented, given an option. as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[INTERNAL] [ADDED] - Add `getLiteralValue` function to codegen Parser
Pull Request resolved: https://github.com/facebook/react-native/pull/38651
Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green
Reviewed By: cipolleschi
Differential Revision: D47912960
Pulled By: rshest
fbshipit-source-id: d9426fef4c0f92c5244d5c4c72202ec29099b76e
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/38295
Move constant to class instance so customers can use strongly typed name, feedback from D46159001
Changelog:
[Internal] [Changed] - Add module name constant to codegen'd class for downstream use
Reviewed By: christophpurrer
Differential Revision: D47095993
fbshipit-source-id: 741d0d837bf912d6b32e5f12c5df871563d46686
Summary:
This is a follow up PR to https://github.com/facebook/react-native/issues/37872 as it was not merged correctly.
## Changelog:
<!-- Help reviewers and the release process by writing your own changelog entry.
Pick one each for the category and type tags:
[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message
For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[Internal][Changed]: Add emitObjectProp in parser primitives
Pull Request resolved: https://github.com/facebook/react-native/pull/37904
Test Plan: `yarn test react-native-codegen`
Reviewed By: cipolleschi
Differential Revision: D46753690
Pulled By: rshest
fbshipit-source-id: a1d0a727222066f3721f62427a51ee0317e06f13
Summary:
[Codegen 128] This PR add a `getObjectProperties` function to the Parser interface, which returns the properties of an object represented by a type annotation as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[INTERNAL] [ADDED] - Add getObjectProperties function to codegen Parser
Pull Request resolved: https://github.com/facebook/react-native/pull/37789
Test Plan: Run `yarn jest react-native-codegen` and ensure CI is green
Reviewed By: cipolleschi
Differential Revision: D46584748
Pulled By: rshest
fbshipit-source-id: 7f509b6f8754472a9b3048214345dc94265604ba
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37832
This parameter is currently unused and is causing Android builds to fail
as they compile with `-Wall`
This is a follow-up to https://github.com/facebook/react-native/pull/37454/ as that PR updated only the `fromJs` and not the `toJs` method as well.
Changelog:
[Internal] [Changed] - Remove CallInvoker parameter from toJs method in Codegen
Reviewed By: rshest
Differential Revision: D46647110
fbshipit-source-id: 1f3e22aca7a3df11ac02b5c4b89c9311b8b1798c
Summary:
[Codegen 132] This PR introduces `emitMixedProp` to parser-primitives and abstracts the logic out of typescript and parser events as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[Internal] [Changed] - Add emitMixedProp to parser-primitives and update usages.
Pull Request resolved: https://github.com/facebook/react-native/pull/37608
Test Plan:
Run yarn jest react-native-codegen and ensure CI is green
## Screenshot of tests passing locally:
<img width="1182" alt="Screenshot 2023-05-28 at 12 46 49 PM" src="https://github.com/facebook/react-native/assets/64726664/dbea4daf-d954-4c7f-b121-c6aad1fb318e">
Reviewed By: dmytrorykun
Differential Revision: D46275638
Pulled By: cipolleschi
fbshipit-source-id: 803d82055c7925e49aca1f408b5c7a50c687349a
Summary:
[Codegen 138] This PR introduces `getProperties` to Parser base class and implements the function in Typescript and Flow Parsers.
This PR also gets rid of `getProperties` from :
- `packages/react-native-codegen/src/parsers/typescript/components/componentsUtils.js`
- `packages/react-native-codegen/src/parsers/flow/components/componentsUtils.js`
and updates the usages with `getProperties` from the respective parser objects as requested on https://github.com/facebook/react-native/issues/34872
## Changelog:
[Internal] [Changed] - Add getProperties to Parsers base class and update usages.
Pull Request resolved: https://github.com/facebook/react-native/pull/37633
Test Plan:
Run yarn jest react-native-codegen and ensure CI is green
## Screenshot of tests passing locally:

Reviewed By: cipolleschi
Differential Revision: D46322882
Pulled By: rshest
fbshipit-source-id: 5506ce5ff395946ea8c1258b152716fea0142b95