Summary:
Everywhere else in the CodegenSchema, type annotation partials are suffixed with "Shape". In the NativeModule schema, we were using the suffix "Schema". In this diff, we standardize on the "Shape" suffix.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24719395
fbshipit-source-id: 307935f5fe0681c31cd52e9cf4ae579f61c1ae68
Summary:
CodegenSchema exports `NativeModuleMethodParamSchema` and `NativeModuleObjectTypeAnnotationPropertySchema`, which are partials of NativeModule type annotations. This creates unnecessary coupling between the type annotations of CodegenSchema and the files that depend on it.
**Actual Problem:** Suppose that we want to rename one of these partials. Then, all imports in all files would have to be updated, even when the actual shape of the composed type annotation wasn't changed.
This diff removes these partials, which reduces the surface area of the exports of CodegenSchema.js
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24719396
fbshipit-source-id: c822aaa252f156c524f4ef4917ebb61b1a39ff9e
Summary:
The names of events and props flow type annotations are singular. The names of the commands flow types are however plural. This diff renames all "Commands*" flow types to be singular.
**Motivation:** Consistency
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24708276
fbshipit-source-id: 5d5d2123426ca1139953169d0ea764b82b2f3809
Summary:
All throughout the Codegen schema, we re-declare the following shape:
```
{
type: 'ObjectTypeAnnotation',
properties: $ReadOnlyArray<{
name: string,
optional: boolean,
typeAnnotation: ...
}>
}
```
This diff introduces an `ObjectTypeAnnotation<T>` utility type and replaces those re-declarations with instantiations of this type.
**Motivation:** To reduce noise in the CodegenSchema. This should be a pure refactor, and shouldn't actually change any behaviour.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24707963
fbshipit-source-id: 6b4eb711ddd041f3a041109ade5ad5644fb16924
Summary:
This diff re-organizes CodegenSchema to declare the larger types first, which use smaller undeclared types. The smaller types are declared further down the file, and they themselves use even smaller undeclared types.
**Motivation:** Increase the readability of CodegenSchema.js. Now, if people want to understand the shape of the Codegen Schema, they can just read the file from top to bottom.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24701424
fbshipit-source-id: 181e87bff5e32d998463221891f459b0df26ef52
Summary:
Reserved type annotations can appear in three different contexts: commands, props, and NativeModules. For now, commands and NativeModules share the same reserved type annotations. In the future, we may want to merge these reserved type annotations with the props reserved type annotations.
**Motivation:** The meaning of FunctionValue in FunctionValueTypeAnnotation isn't clear - in fact, it's downright confusing. Therefore, this diff renames this Flow type to ReservedTypeAnnotation, which I believe sufficiently captures the intent of the type annotation.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24701322
fbshipit-source-id: bde0273b4a89c9e7175c60ed3468ed870b320044
Summary:
Our CodegenSchema is littered with types that have the following shape
```
{
name: string,
optional: boolean,
typeAnnotation: ...
}
```
In all these types, the only difference is the typeAnnotation. This diff introduces a new utility type called `NamedShape`, that just creates this shape, given a type annotation. This should help reduce the amount of noise in the CodegenSchema, and make it a bit easier to read.
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24701331
fbshipit-source-id: a30d3e22933116e3dabf7929615905febacecba3
Summary:
All ObjectTypeAnnotation *properties* in the codegen have the following shape:
```
{
name: string,
optional: boolean,
typeAnnotation: ...
}
```
EventObjectTypeProperty is a property of some ObjectTypeAnnotation, yet it doesn't follow this pattern. This diff cleans up EventObjectPropertyType. This is a part of a larger effort to clean up the Component Schema and unify the notion of a "type annotation" across the Component and Module schemas.
Reviewed By: yungsters
Differential Revision: D24701027
fbshipit-source-id: edc7dc632a217fb5a82ffd8a62aef990baf398c2
Summary:
Bump Gradle Wrapper to 6.7, to keep tooling on edge. Here are the highlights of this release:
- File system watching is ready for production use
- Declare the version of Java your build requires
- Java 15 support
## Changelog
[Android] [Changed] - Bump Gradle Wrapper to 6.7
Pull Request resolved: https://github.com/facebook/react-native/pull/30200
Test Plan: RNTester builds and runs as expected. Also my apps.
Reviewed By: cpojer
Differential Revision: D24560233
Pulled By: fkgozali
fbshipit-source-id: 0d94b4527b2ee5b28b22478128c25761929fbdc7
Summary:
Android Studio 4.1 release with Android Gradle Plugin 4.1.0, thus I expect developers will update to newer version and expect React Native support. Thus release include many fixes and improvements, see[release notes](https://developer.android.com/studio/releases/gradle-plugin#4-1-0), but most importantly Google released it's API documentation at https://developer.android.com/reference/tools/gradle-api. We lacked the API documentation to develop proper React Gradle Plugin.
## Changelog
[Android] [Changed] - bump Android Gradle Plugin to 4.1.0
Pull Request resolved: https://github.com/facebook/react-native/pull/30201
Test Plan: RNTester builds and runs as expected, also my apps.
Reviewed By: cpojer
Differential Revision: D24560213
Pulled By: fkgozali
fbshipit-source-id: 9cf1e2373f278885b35b4f9176c7ad736ec50f6b
Summary:
The recursive copy statement fixed here behaved differently in MacOS vs Linus (CI), because of the missing dot (.)
The trailing slash on the source directory behaves differently on Mac (BSD) than Linux (GNU):
> If the source_file ends in a /, the contents of the directory are copied rather than the directory itself.
This should fix the CI failure: https://app.circleci.com/pipelines/github/facebook/react-native/6847/workflows/36d59aab-bc4a-4d21-9ce1-a8348e71aea3/jobs/173681
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24560543
fbshipit-source-id: c3ab2c28616b717891bcf5d2ad762340cfb97e3d
Summary:
This does a few things:
* Remove USE_CODEGEN flag so that TurboModule is enabled by default for RNTester
* Use the codegen output for Java/JNI spec files
* Remove the checked in com.facebook.fbreact.specs Java/JNI files
Changelog: [Changed][Android] RNTester now enables TurboModule by default using codegen.
Reviewed By: RSNara
Differential Revision: D24382083
fbshipit-source-id: 87e3e0581bac3287ef01c1a0deb070c1d7d40f2d
Summary:
The Gradle codegen integration requires the JS CLI to be first built via `yarn run build`. This commit puts that logic in a `build.sh` script, then defines a Gradle task to build it.
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24556992
fbshipit-source-id: 7092de7c1126edc157b122f4b2243e55f7188846
Summary:
This fixed a bug in the JS Java spec generator. Optional methods were still marked `abstract` before this fix. Instead it should be a normal method with potentially falsy return value.
The JavaPoet version does this correctly already, but there was a minor typo with void return type vs optional.
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24524432
fbshipit-source-id: 57a248580a78bc255f34d0492ebe3a4691e66667
Summary:
This defines a separate codegen entrypoint for the entire react-native repo, picking up all JS files under Libraries/ subdir. Buck can then build the codegen library targets. This is a pre-req for removing the checked in Java spec files for NativeModules.
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24518569
fbshipit-source-id: 2ece53c7274698e2431a00e590fad213e3a0bece
Summary:
We don't currently support object spreads in `ObjectTypeAnnotation`s. This diff adds an explicit error for the case in the parser, so that when people use object spreads in ObjectTypeAnnotations, they get feedback from the linter rule and parser.
Previously, the Linter would crash, and the parser would fail, but the error wouldn't be immediately obvious.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24543650
fbshipit-source-id: 76f389c72f858ee6281c5aff5ce797f3be685096
Summary:
This moves the test script that generates **all outputs using all generators** to a dedicated "generate-all" CLI. This allows us to use it via Buck, at FB and OSS.
Also renamed the target to be more specific: "rn_codegen" => "generate_all_from_schema"
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24513995
fbshipit-source-id: 8435d3d065718eb1309c1c61fe28fb592787311a
Summary:
Introduced a helper macro `rn_codegen_cli()` that defines ":write_to_json" and ":rn_codegen" targets differently based on the environment. When run at FB, it uses FB-specific setup. When run in OSS as a standalone repo, we use `yarn install` and `yarn run build` directly, then use `node` to run the output CLI.
This way, the same target can be used in both environments on other Buck targets.
Motivation: we need this to define rn_codegen_modules() to use codegen to produce Java TurboModule specs, that can be built by CircleCI (we build ReactAndroid via Buck as well). That way we can finally removed the checked-in .java spec files.
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24442468
fbshipit-source-id: b1e5fce275100cfe3a1b3ae6d61c1c6d4b25651b
Summary:
Added a few FB vs OSS polyfills:
* react_native_root_target() to refer to the root FB react-native-github/ dir or repo dir in OSS
* react_native_xplat_synced_target() for anything xplat
* a few others
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D24437245
fbshipit-source-id: ee290a87a98a8e9be67b102a96f2faac2a2cb92b
Summary:
Removes the generated FBReactNativeSpec files from source control.
## Generating FBReactNativeSpec files
The files will be generated automatically by CocoaPods when the `RNTesterPods` Xcode workspace is generated:
```
cd packages/rn-tester
pod install
```
The spec files can be re-generated by invoking the script directly:
```
./scripts/generate-native-modules-specs.sh
```
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24261167
fbshipit-source-id: acb7ac856e5e519932e4f587f79e24f49cd84a91
Summary:
Just published react-native-codegen to npm. This diff bumps the version in package.json
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24433252
fbshipit-source-id: 35327b11ca4db270f207b6f778dabf86dd7dcb4c
Summary:
This makes the build configuration compatible with OSS Buck (but doesn't provide the complete capability).
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24414408
fbshipit-source-id: 4632933b8659389543ed72ae7c11c63d86bb3dce
Summary:
For now, separate the definition of `modules` generator per platform to avoid file output collision. Additionally:
* For Android, produce files under java/ (plus nested subdirs based on packageName) and jni/ (for C++ files) - JavaPoet version already does it
* Allow configuring packageName for Android - JavaPoet version has this
* Avoid tmp directory dance in the CLI script, given the proper modules separation
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24410864
fbshipit-source-id: 9bd6bc1d65bec037bfca32ec478f3af50d72e927
Summary:
## Rationale
Previously, the NativeModule spec parser would throw an error the first time it encountered an invalid Flow type. While this is ideal from a parsing standpoint, from a linting standpoint, however, we may want to display all errors that make the NativeModule spec invalid.
## Changes
This diff extends the NativeModule spec parser to collect all parsing errors in an array. In the codegen, if after building the schema, any parsing errors were detected, we throw the first one. In the ESLint rule, if after building the schema, any parsing errors were detected, the plan is to display them all.
## Notes
- All ParserErrors keep a track of the invalid AST Node
- When a Parsing error occurs, the Parser tries its best to continue parsing the rest of the source. For function parameters, it'll move on to the next param. For object proroperties, it'll move to the next property. It'll form a half-baked schema in the process, when a parsing error occurs. However, higher up in the stack, we have a check that discards the half-baked schema, if any ParsingErrors were collected.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24379511
fbshipit-source-id: 1989433da9b356b9ad5d9dcf901b429f585803c2
Summary:
## Why
We want to reuse these functions inside the ESLint rule. Therefore, it's better to make them accept the AST node object, as opposed to a custom type defined in codegen.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24379512
fbshipit-source-id: 9f7378fc6c5f48cce34da109f5a7c017332b302a
Summary:
In our Codegen generators, we were using `codegenModuleName` to refer to the name of the spec file. Calling this `hasteModuleName` makes it more clear what this name refers to (i.e: the name of the spec file). This diff performs that rename.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24386282
fbshipit-source-id: fe2beda9a0abf63a5cf88fa0664f83416c9f1aa2
Summary:
The specific file filtering in the CLI only covers the case where the input is a directory. We should filter when files are provided as well.
Changelog: [Internal]
Reviewed By: hramos
Differential Revision: D24399225
fbshipit-source-id: 186e39c157faf90bdd825ec5c5860017d49e9404
Summary:
The GenerateModuleJavaSpec.js mistakenly treated nullable getConstants() properties as required, such that the Java spec will throw an exception when the properties are missing. This fixed it.
Note that the JavaPoet-based generator got this correct already.
Changelog: [Internal]
Differential Revision: D24381941
fbshipit-source-id: c95d2181c66443e2191318f09b6454a5296009e4
Summary:
The NativeModules spec parser uses `moduleName` to refer to the name of the NativeModule spec. This is confusing, because the NativeModules spec also has a `moduleNames` array, which refers to names of the NativeModules that get required in the spec.
This diff renames `moduleName` to `hasteModuleName` within the NativeModule spec parser.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24386279
fbshipit-source-id: 8e4eb8dfc647241bf2bdae54dc8d9ab0122f49f9
Summary:
If a native module schema has `excludedPlatforms` defined, honor it and skip the module that doesn't belong to the platform.
E.g. NativeImagePickerIOS shouldn't generate anything for Android codegen output.
Similarly, IntentAndroid shouldn't generate anything for iOS codegen output.
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24373092
fbshipit-source-id: cfeb455a18c92f60191d988af2e9ce7ea5021304
Summary:
Some existing NativeModules have either Android or IOS suffix to denote the exclusive intent for that platform. For now, note this in the codegen schema output, so that the generator can skip irrelevant modules. Long term, each Flow type for module Spec should denote the intended/excluded platforms directly.
Changelog: [Internal]
Reviewed By: RSNara
Differential Revision: D24370568
fbshipit-source-id: 8f725bdb39107d73c1aba0689db7f47ed7c374b0
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
## Changes
1. NativeModule generators now use the new RN Codegen NativeModule schema.
2. Tangential: We're no longer removing the `Native` prefix from the NativeModule filename, assuming that that's the module name (problem: wrong), and prefixing again with Native (problem: redundant), when we're generating code. Instead, like the internal codegen, we simply pass the filename to the Codegen output. Our linters enforce that all NativeModule specs are contained with files that start off with `Native`.
3. `GenerateModuleCpp` was fixed to use the actual module name as opposed to the spec name. I added a comment inline.
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236405
fbshipit-source-id: ccd6b5674d252c350be0ec8a86e7ca5f2f614778
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236504
fbshipit-source-id: 0ca70101a855fb713fa15ed63849b138eb73dc6c
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
## Changes
Previously, the "Module" schema could either contain a `components` property, or a `nativeModules` property. The existence of the `components` property was used to determine (1) if the generators would run and (2) filter schemas on which the generators would run. Now, we simply check whether the type of the "Module" schema is `Component`.
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236508
fbshipit-source-id: 68cb3f25178b6757c9a4aee767bb6173db4932a6
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236507
fbshipit-source-id: 2ffa0414db731a6ee844a2d1a5b07dc32bc763cb
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236502
fbshipit-source-id: 288c6d9588bde177732fe8165d3374eeacad999d
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236509
fbshipit-source-id: 1b603e8728d7be1e8bdede5878f57d6556b5c52f
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
## Changes
1. Update the RN Codegen Module Parser
2. Update all RN Codegen Module Parser Jest tests & snapshots.
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236505
fbshipit-source-id: e24a39b4837c75a90fb4c957c56dfcf789511cc9
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
## Changes
1. Update the RN Codegen Component Parser
2. Update all RN Codegen Component Parser snapshots.
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: PeteTheHeat
Differential Revision: D24236503
fbshipit-source-id: 975d97dd29bb5ca08e5de96e7814290c3dc4357b
Summary:
NOTE: Flow and Jest won't pass on this diff. Sandcastle, should, however, be green on D24236405 (i.e: the tip of this stack).
## Description
The Codegen deals with "Modules". Hence:
```
type SchemaType = {
modules: {
[moduleName]: ...
}
};
```
Each "Module" has a name, and represents a file. The `moduleName` is the base name of the file. This file can contain a component specification or a NativeModule specification. Hence:
```
type SchemaType = {
modules: {
[moduleName]: ComponentSchema | NativeModuleSchema
}
};
```
The `ComponentSchema` can contain specifications for many different components. Hence:
```
type ComponentSchema = {
type: 'Component'
components: {
[componentName]: ComponentShape
}
}
```
The `NativeModuleSchema` contains
1. Type aliases (no surprises/nothing new).
2. One Flow interface that extends `TurboModule`.
3. Potentially many different NativeModule requires (for now) via `TurboModuleRegistry.get(Enforcing)?<specName>('moduleName')`.
Hence, the shape looks like:
```
type NativeModuleSchema = {
type: 'NativeModule',
aliases: NativeModuleAliasMap, // nothing new
spec: NativeModuleSpec,
moduleNames: $ReadOnlyArray<string>
}
type NativeModuleSpec = {
properties: $ReadOnlyArray<...>,
}
```
## Major Notes
1. We now parse the NativeModule requires (TurboModuleRegistry.get(Enforcing)?<Spec> calls) and record them in the schema.
2. A Codegen "Module" can contain either a Component schema, or a NativeModule schema, but **not** both.
## Snapshot Updates
The changes to the schema are visible in the snapshots updated in D24236505.
Changelog: [Internal]
(Note: this ignores all push blocking failures!)
Reviewed By: fkgozali
Differential Revision: D24236510
fbshipit-source-id: bd344d67136418725d840e7332fd2f6957326bb4
Summary:
The codegen output for the native modules in `Libraries/` has been verified to work with RNTester.
Publishing a new version as a prerequisite to start using the codegen at build time in open source.
Changelog: [Internal]
Reviewed By: fkgozali
Differential Revision: D24314972
fbshipit-source-id: edd0066c1cf33ba8e536cc5f145c057ca992eec1