Commit Graph

417 Commits

Author SHA1 Message Date
Kevin Gozali 1bbcbd55ff Android OSS: fixed unbound variable error for codegen build script
Summary:
If $FBSOURCE_ENV isn't set, this failed with `/root/react-native/packages/react-native-codegen/android/../scripts/oss/build.sh: line 20: FBSOURCE_ENV: unbound variable`.

This commit fixes https://app.circleci.com/pipelines/github/facebook/react-native/7080/workflows/5cf18a1f-e6d2-4648-8217-d42e9a61fef1/jobs/176451

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24912950

fbshipit-source-id: 113e3dd7f78c75fc3adea0b21c9e38910be8c065
2020-11-11 22:39:27 -08:00
Janic Duplessis d5db2cb5d1 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: https://github.com/facebook/react-native/pull/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
2020-11-11 19:17:12 -08:00
Ramanpreet Nara 00cfb0f919 Remove pipes from Object literal Flow types
Summary:
## Changes
{| ... |} -> { ... }

**Motivation:** In Flow, object literals are exact by default. So, there's no need for the pipes. Also: Now, the syntax for object literals is consistent across react-native-codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24774771

fbshipit-source-id: 24ceb6f5876122aa8ad9e08c7e903215864ad6f5
2020-11-06 16:24:44 -08:00
Ramanpreet Nara 1ee406b9cc Pull out ReservedPropTypeAnnotation into type alias
Summary:
This type annotation was declared inline twice. Just pulling it out into a type alias in this diff.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723191

fbshipit-source-id: 9f2061087172979ea838dfdf2533e17b9b559c71
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0de4b514be Simplify Int32EnumTypeAnnotation and StringEnumTypeAnnotation
Summary:
Int32EnumTypeAnnotation represents a union of numbers. In the corresponding type annotation, we represent options as `$ReadOnlyArray<{value: number}>`. Since each option is a number, we could instead represent options as `$ReadOnlyArray<number>` - there's no need to use an object with a singular property (i.e: 'value'). The same is could be said of StringEnumTypeAnnotation.

In this diff, we change `Int32EnumTypeAnnotation.options` to `$ReadOnlyArray<number>`, and `StringEnumTypeAnnotation.options` to `$ReadOnlyArray<string>`.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24723107

fbshipit-source-id: 4734cf72a4a29b6b321d8161bea70cf524ce0963
2020-11-05 18:30:09 -08:00
Ramanpreet Nara a31d7aa2d3 Standardize on one FunctionTypeAnnotation shape
Summary:
Commands are `FunctionTypeAnnotation`, but they don't have a return type. I this diff, I introduced a `FunctionTypeAnnotation<+P, +R>` utility type, and made the `CommandTypeAnnotation` be an instantiation of it, with the return type fixed to `VoidTypeAnnotation`.

Now, the shape of a FunctionTypeAnnotation is unified across the NativeModule and Component schemas.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D24719965

fbshipit-source-id: 0089c3b23f05b0c534ba28dbe336c7f2db5866b3
2020-11-05 18:30:09 -08:00
Ramanpreet Nara 0d748cf8bb Rename NativeModulePropertySchema -> NativeModulePropertyShape
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara c6b8c75b6b Remove miscellaneous exports of NativeModule Flow types in Codegen Schema
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 04f235e7fb Rename Commands* -> Command*
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 688caa0bdc Introduce ObjectTypeAnnotation utility type
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara b9f6937288 Reorganize CodegenSchema types into "use before declaration" order
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 1231db0d7f Rename ReservedFunctionValueTypeAnnotation to ReservedTypeAnnotation
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 856bc2978c Introduce NamedShape utility type
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
2020-11-05 18:30:08 -08:00
Ramanpreet Nara 0e46080847 Clean up EventObjectPropertyType
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
2020-11-05 18:30:07 -08:00
Kevin Gozali 17a8737ecb Codegen Android: update Docker configuration to support codegen (#30268)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/30268

This addresses the following CI failure:
https://app.circleci.com/pipelines/github/facebook/react-native/6847/workflows/36d59aab-bc4a-4d21-9ce1-a8348e71aea3/jobs/173669

The problem was missing directories because we didn't copy the relevant ones for docker build.

In addition:
* The codegen depends on `invariant`, but didn't specify the dep in package.json. This fixes it.
* Also ask Metro to ignore buck-out

Note that this will depend on docker image v1.0.5 (to be released later) to fully build. v1.0.5 will need to install `rsync`, see this patch: https://gist.github.com/fkgozali/1d8cae92a5bc521e0f2e4f275008db93. With my test image (of 1.0.5 local build), I got the docker build to pass:

```
$ docker build -t reactnativeci/android -f .circleci/Dockerfiles/Dockerfile.android .
[+] Building 1624.2s (27/27) FINISHED
 => [internal] load build definition from Dockerfile.android                                                                                           0.0s
 => => transferring dockerfile: 52B                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                        0.0s
 => [internal] load metadata for docker.io/reactnativecommunity/react-native-android:1.0.5                                                             0.0s
 => [1/22] FROM docker.io/reactnativecommunity/react-native-android:1.0.5                                                                              0.0s
 => [internal] load build context                                                                                                                      5.6s
 => => transferring context: 7.11MB                                                                                                                    5.5s
 => CACHED [2/22] ADD .buckconfig /app/.buckconfig                                                                                                     0.0s
 => CACHED [3/22] ADD .buckjavaargs /app/.buckjavaargs                                                                                                 0.0s
 => CACHED [4/22] ADD Libraries /app/Libraries                                                                                                         0.0s
 => CACHED [5/22] ADD ReactAndroid /app/ReactAndroid                                                                                                   0.0s
 => CACHED [6/22] ADD ReactCommon /app/ReactCommon                                                                                                     0.0s
 => CACHED [7/22] ADD React /app/React                                                                                                                 0.0s
 => CACHED [8/22] ADD keystores /app/keystores                                                                                                         0.0s
 => CACHED [9/22] ADD packages/react-native-codegen /app/packages/react-native-codegen                                                                 0.0s
 => CACHED [10/22] ADD tools /app/tools                                                                                                                0.0s
 => CACHED [11/22] WORKDIR /app                                                                                                                        0.0s
 => CACHED [12/22] RUN buck fetch ReactAndroid/src/test/java/com/facebook/react/modules                                                                0.0s
 => CACHED [13/22] RUN buck fetch ReactAndroid/src/main/java/com/facebook/react                                                                        0.0s
 => CACHED [14/22] RUN buck fetch ReactAndroid/src/main/java/com/facebook/react/shell                                                                  0.0s
 => CACHED [15/22] RUN buck fetch ReactAndroid/src/test/...                                                                                            0.0s
 => CACHED [16/22] RUN buck fetch ReactAndroid/src/androidTest/...                                                                                     0.0s
 => CACHED [17/22] RUN buck build ReactAndroid/src/main/java/com/facebook/react                                                                        0.0s
 => CACHED [18/22] RUN buck build ReactAndroid/src/main/java/com/facebook/react/shell                                                                  0.0s
 => [19/22] ADD . /app                                                                                                                                28.1s
 => [20/22] RUN yarn                                                                                                                                  50.2s
 => [21/22] RUN ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog  235.8s
 => [22/22] RUN ./gradlew :ReactAndroid:packageReactNdkLibsForBuck -Pjobs=1                                                                         1240.1s
 => exporting to image                                                                                                                                64.2s
 => => exporting layers                                                                                                                               64.2s
 => => writing image sha256:6449dc629ed12395c9c98d880fb421284193bc9b5d2a77578760a23b5c3c1acd                                                           0.0s
 => => naming to docker.io/reactnativeci/android
```

To test with a custom local docker image:
* https://docs.docker.com/get-started/ (install the Mac client)
* git clone https://github.com/react-native-community/docker-android
* Make the local change then create the fake v1.0.5 image:
  * `docker build --tag reactnativecommunity/react-native-android:1.0.5 .`
  * Run the image from Docker Mac client
* Then build RN docker test pasted above.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D24611539

fbshipit-source-id: 7435e720bbb2e8d6528ce2a7344f1def15803898
2020-10-28 21:48:20 -07:00
Dulmandakh e9fd93f53f Bump Gradle Wrapper to 6.7 (#30200)
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
2020-10-27 23:35:51 -07:00
Dulmandakh dfa9db49e3 bump Android Gradle Plugin to 4.1.0 (#30201)
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
2020-10-27 23:35:51 -07:00
Kevin Gozali 3a41125e80 Android CI: Fix up //packages/react-native-codegen:setup_cli src copy issue
Summary:
This fixed bad src copy for Buck-building: `//packages/react-native-codegen:setup_cli`. Using rsync -L will correctly copy file contents instead of preserving symlinks (which confused yarn).

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24577333

fbshipit-source-id: 4f586ba95d2d95d6ce8e3389e355cfb1a9121745
2020-10-27 17:27:33 -07:00
Kevin Gozali 4630e57821 Codegen Android: fixed CI due to bad SRC->OUT dir copy
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
2020-10-27 09:26:32 -07:00
Kevin Gozali f023519e49 TurboModule Android: Enable TurboModule by default on RNTester
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
2020-10-26 23:47:54 -07:00
Kevin Gozali f2ba978cad Codegen Android: build react-native-codegen via yarn when building from source
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
2020-10-26 23:47:54 -07:00
Kevin Gozali a1d374e504 Codegen Android: optional NativeModule method should not be marked abstract
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
2020-10-26 22:02:05 -07:00
Kevin Gozali f760f90f1e Codegen BUCK: define codegen entrypoint under react-native-github/Libraries/ for core modules
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
2020-10-26 22:02:05 -07:00
Ramanpreet Nara f1f9cef9d3 Disallow object spreads in ObjectTypeAnnotations
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
2020-10-26 16:23:03 -07:00
Kevin Gozali 2a634f452c Codegen BUCK: moved generate-test.sh to be general-purpose generate-all CLI
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
2020-10-24 14:02:47 -07:00
Kevin Gozali 16044b3c2a Codegen Buck: fork schema generator target for FB vs OSS via rn_codegen_cli()
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
2020-10-22 17:09:30 -07:00
Kevin Gozali 7cfc7d65f7 Codegen: Make react-native-codegen BUCK deps OSS-compatible
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
2020-10-22 17:09:29 -07:00
Héctor Ramos 9218e0c2e6 iOS: Generate FBReactNativeSpec ObjC++ files at build time
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
2020-10-21 20:47:09 -07:00
Ramanpreet Nara 5b270e0243 Version bump to 0.0.5
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
2020-10-20 23:43:00 -07:00
Kevin Gozali eca9d9772c Codegen: Make BUCK & DEFS.bzl OSS friendly
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
2020-10-20 14:11:46 -07:00
Kevin Gozali 82c95fadc1 Codegen (FB): define internal BUCK targets for Android + JNI
Summary:
`rn_codegen_modules()` now defines 2 additional Android targets:
* the rn_android_library()
* the C++ library for JNI files

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24411783

fbshipit-source-id: 5ee4550dc313041f87e133397f266279b3eec6ee
2020-10-20 14:11:45 -07:00
Kevin Gozali 13d9927a48 Codegen: separate Android/Cxx/iOS modules codegen outputs
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
2020-10-20 14:11:45 -07:00
Ramanpreet Nara 9c1f0c697d Make NativeModule spec parser collect all parsing errors
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
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 2f438b03d7 Make buildModuleSchema and buildComponentSchema operate on Program AST nodes
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
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 33789ba0ea GenerateModuleCpp: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386276

fbshipit-source-id: d5913122221960c06c5256af10ace1d2f7a60b49
2020-10-19 21:59:29 -07:00
Ramanpreet Nara de32fd2539 GenerateModuleH: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386278

fbshipit-source-id: b6cfa9fe17e1f7c54f4d541fd19281bf9a6c6796
2020-10-19 21:59:29 -07:00
Ramanpreet Nara ac46837d35 GenerateModuleJavaSpec: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Differential Revision: D24386277

fbshipit-source-id: 28fbc0eab2c4455d391a1644b5c42c0cb39f69ad
2020-10-19 21:59:29 -07:00
Ramanpreet Nara 5a73af684d GenerateModuleJniCpp: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386280

fbshipit-source-id: 9af78d8aabd86a6afb53660ff97d550973e5d11b
2020-10-19 21:59:28 -07:00
Ramanpreet Nara 35ee7c8246 GenerateModuleJniH: Replace string replace with string templates
Summary:
## Benefits:
- Improved Readability
- Improved type-safety with templates

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24386281

fbshipit-source-id: 558bc13edff51e801b605669613cd63309522236
2020-10-19 21:59:28 -07:00
Ramanpreet Nara fc94054915 Refactor: Rename codegenModuleName to hasteModuleName
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
2020-10-19 21:59:28 -07:00
Kevin Gozali b05294dd99 Codegen fbsource: filter JS files for all cases, then enable codegen_module=True for react-native-github
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
2020-10-19 15:30:05 -07:00
Kevin Gozali 4dfa3be871 Codegen Android: handle nullable getConstants() properties generation.
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
2020-10-19 09:33:53 -07:00
Ramanpreet Nara 6c88afc044 Refactor: Rename moduleName to hasteModuleName
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
2020-10-18 19:04:58 -07:00
Kevin Gozali 76098831fd Codegen: exclude NativeModules that are not for the specific platform
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
2020-10-17 02:45:48 -07:00
Kevin Gozali ec094e75bd Codegen: denote Android/iOS exclusive platform modules in the schema
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
2020-10-17 02:45:48 -07:00
Ramanpreet Nara 518c9a2e1a Update JavaPoet Module generator to follow new NativeModule schema
Summary:
Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: fkgozali

Differential Revision: D24236813

fbshipit-source-id: 1fa573fade09914da673cd3750d78e4619ff4581
2020-10-15 22:53:56 -07:00
Ramanpreet Nara c4f23354fd Update Module Generators to follow new NativeModuleSchema
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
2020-10-15 22:53:56 -07:00
Ramanpreet Nara ee177f6cba Update ViewConfig generator test to follow new ComponentSchema
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
2020-10-15 22:53:56 -07:00
Ramanpreet Nara 100c0528f3 Update component generators to follow new ComponentSchema
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
2020-10-15 22:53:55 -07:00
Ramanpreet Nara a5a12cffeb Update SchemaValidator test to follow new CodegenSchema
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
2020-10-15 22:53:55 -07:00