Граф коммитов

570 Коммитов

Автор SHA1 Сообщение Дата
Mike Grabowski c95ee5ac18 feat: Enable Hermes to work on iOS (#29914)
Summary:
This PR makes it possible to build iOS applications with Hermes. Note that it doesn't work with `use_frameworks!` just yet.

Fixes https://github.com/facebook/react-native/issues/27845 (by downgrading iOS deployment target for RCT-Folly to 9.0)
Fixes https://github.com/facebook/react-native/issues/28810 (as above)

Checklist:
- [x] Adjust release scripts to create Hermes bytecode bundle
- [x] Release new Hermes npm package that includes iOS files (unreleased right now, if you want to try locally, you have to clone Hermes and `yarn link` its master to this project)
- [x] Test on a new React Native application in both Debug and Release (Device)
- [x] Test on an RNTester application in both Debug and Release (Device)
- [x] Add missing `i386` to Hermes framework and enable Bitcode
- [x] Inspect CI failures for possible regressions
- [x] Resolve Folly issue as reported https://github.com/facebook/react-native/issues/27845 and https://github.com/facebook/react-native/issues/28810
- [x] Release new Hermes and test against it that everything works

## Changelog

[IOS] [FEATURE] - Enable Hermes on iOS
[INTERNAL] - Upgrade to CocoaPods 1.10.0 to resolve Xcode 12.0 issues
[INTERNAL] - Upgrade to Xcode 12.0 on the CircleCI
[INTERNAL] - Fix building RNTester in Release mode
[INTERNAL] - Fix build-time errors of `libevent` with `use_frameworks!`
[INTERNAL] - Introduce `USE_HERMES` variable and test all RNTester configurations on the CI
[INTERNAL] - Do not fetch CocoaPods repository since we're using CDN anyway

Pull Request resolved: https://github.com/facebook/react-native/pull/29914

Test Plan:
Turn on `hermes_enabled` to true in your `Podfile`, install pods, and run the iOS application. Your app should be running Hermes now.

Preview: (note "Engine: Hermes")

<img width="395" alt="Screenshot 2020-09-09 at 19 22 32" src="https://user-images.githubusercontent.com/2464966/92631584-d7c01d80-f2d1-11ea-9b40-33d73db96a53.png">

Reviewed By: hramos

Differential Revision: D24684845

Pulled By: cpojer

fbshipit-source-id: 900cbe3bf9398a6fd4a773d552899a001bf5146b
2020-11-03 01:14:38 -08:00
Héctor Ramos 538446e755 Bump Xcode to 12.1.0, bump CocoaPods 1.10.0 (#30250)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/30250

Upgrade the version of Xcode used in Circle CI to Xcode 12.1.0, and target iOS 14.1 in tests.

Reference:
* Circle CI Xcode 12.1 container manifest (new version):
https://circle-macos-docs.s3.amazonaws.com/image-manifest/v3985/index.html
* Circle CI Xcode 11.6.0 container manifest (previous version): https://circle-macos-docs.s3.amazonaws.com/image-manifest/v3299/index.html

> Source: https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions

The default version of CocoaPods used in the Xcode 12.1 container image has changed. Use `bundle exec` with `pod install` to ensure we use the same version of CocoaPods as prescribed in the Gemfile.

Changelog:
[iOS][Changed] - Update iOS project template for Xcode 12.1.0
[iOS][Changed] - Bump CocoaPods 1.10.0
[Internal] Bump Xcode version used for iOS tests.

Reviewed By: fkgozali

Differential Revision: D24545010

fbshipit-source-id: 4a39781352bc5a85dae55ed5cd4e1ed6043a4aeb
2020-10-30 23:03:26 -07: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
Janic Duplessis 1e9d7b70fc More reliable way to get ReactAndroid build dir in Android-prebuilt.mk (#30222)
Summary:
Pass the ReactAndroid project build directory as a variable to the ndk build so it can be used instead of assuming that the build directory is under ReactAndroid/build.

## Changelog

[Internal]

Pull Request resolved: https://github.com/facebook/react-native/pull/30222

Test Plan: Tested in an app with a custom build directory

Reviewed By: yungsters

Differential Revision: D24560643

Pulled By: fkgozali

fbshipit-source-id: cc65a70582f546ca2e2ca9fb6a2ff03ea70ca9d8
2020-10-27 10:06:58 -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
Ramanpreet Nara 758b63313c Use custom require hook to strip Flow types from NativeModule spec parser
Summary:
## Context
We currently run ESLint using `flow-node`. This is a very recent change that was introduced in these two diffs:
- Switch VSCode ESLint plugin using flow-node: D24454702.
- Switch all ESLint scripts to use flow-node: D24379783 (ad5802cf91).

## Problem
Because `react-native/eslint-plugin-codegen` (written in vanilla JavaScript) requires two files from `react-native-codegen` (written with Flow typings), we force all requires executed while initializing ESLint to compile out Flow types. Issues:
- In the grand scheme of things, this is such a tiny and isolated problem. It shouldn't be the reason why we switch over to using flow node. That's a larger decision that should be discussed outside of this diff.
- On VSCode cold start, in D24454702, I measured that using flow-node adds approximately 320ms to JavaScript file lint time. So, this is just slow.

## Solution
- Switch ESLint back to using regular node:
   - Revert the changes to VSCode's ESLint plugin: D24454702
   - Revert the changes to the internal ESLint scripts: D24379783 (ad5802cf91).
- Inside the ESLint plugin, register a temporary require hook to remove Flow types from the NativeModule spec parser, before we require it. We de-register this hook after the requires finish.

## Implementation Notes:
- The `with-babel-register/` is a fork of `babel/register`, except I simplified the implementation based on the assumption that we're using it literally to only compile `react-native-codegen`.
- `with-babel-register/` uses a disk cache, so we only call transformSync when a the input file (1) hasn't been transformed before, or (2) the cache entry was created before the file was last modified.
- I ported over the source-map logic, so that when the NativeModule spec parser throws non-parsing errors, we get the correct stack trace. **Note:** I'm not sure if the source maps will work if there's a babel/register earlier during initialization. However, I don't think this will pose an actual problem, since we don't use a babel/register hook earlier. So, I think we should punt on this investigation.

## Alternative: Why aren't we using babel/register?
Every time you call babel/register, it replaces the last registered hook. We don't want the ESLint plugin to be changing any existing require hooks that people have set up. Abandoned diff with babel/register: D24519349.

Changelog: [Internal]

Reviewed By: cpojer

Differential Revision: D24551549

fbshipit-source-id: bbd7c5be44f74c0e9adbb20fe86e09802410b123
2020-10-27 00:41:47 -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
Rick Hanlon 24bca492c3 Update React Native to React 17.0.0
Summary:
This sync includes the following changes:
- **[eaaf4cbce](https://github.com/facebook/react/commit/eaaf4cbce )**: 17.0.1 //<Dan Abramov>//
- **[6f62abb58](https://github.com/facebook/react/commit/6f62abb58 )**: Remove usage of Array#fill ([#20071](https://github.com/facebook/react/pull/20071)) //<Dan Abramov>//
- **[40cfe1f48](https://github.com/facebook/react/commit/40cfe1f48 )**: Update CHANGELOG.md //<Dan Abramov>//
- **[f021a983a](https://github.com/facebook/react/commit/f021a983a )**: Bump versions for 17 ([#20062](https://github.com/facebook/react/pull/20062)) //<Dan Abramov>//
- **[d1bb4d851](https://github.com/facebook/react/commit/d1bb4d851 )**: Profiler: Include ref callbacks in onCommit duration ([#20060](https://github.com/facebook/react/pull/20060)) //<Brian Vaughn>//
- **[c59c3dfe5](https://github.com/facebook/react/commit/c59c3dfe5 )**: useRef: Warn about reading or writing mutable values during render ([#18545](https://github.com/facebook/react/pull/18545)) //<Brian Vaughn>//
- **[7b6cac952](https://github.com/facebook/react/commit/7b6cac952 )**: Improved Profiler commit hooks test ([#20053](https://github.com/facebook/react/pull/20053)) //<Brian Vaughn>//
- **[dfb6a4033](https://github.com/facebook/react/commit/dfb6a4033 )**: [Fast Refresh] Fix crashes caused by rogue Proxies ([#20030](https://github.com/facebook/react/pull/20030)) ([#20039](https://github.com/facebook/react/pull/20039)) //<Kai Riemann>//
- **[37cb732c5](https://github.com/facebook/react/commit/37cb732c5 )**: Use bitwise OR to define flag masks ([#20044](https://github.com/facebook/react/pull/20044)) //<Andrew Clark>//
- **[eb3181e77](https://github.com/facebook/react/commit/eb3181e77 )**: Add Visibility flag for hiding/unhiding trees ([#20043](https://github.com/facebook/react/pull/20043)) //<Andrew Clark>//
- **[0dd809bdf](https://github.com/facebook/react/commit/0dd809bdf )**: Remove last schedulePassiveEffectCallback call ([#20042](https://github.com/facebook/react/pull/20042)) //<Andrew Clark>//
- **[8df7b7911](https://github.com/facebook/react/commit/8df7b7911 )**: Remove Passive flag from "before mutation" phase ([#20038](https://github.com/facebook/react/pull/20038)) //<Andrew Clark>//
- **[c57fe4a2c](https://github.com/facebook/react/commit/c57fe4a2c )**: ReactIs.isValidElementType Unit Test extended with PureComponent case ([#20033](https://github.com/facebook/react/pull/20033)) //<adasq>//
- **[02da938fd](https://github.com/facebook/react/commit/02da938fd )**: Don't double-invoke effects in legacy roots ([#20028](https://github.com/facebook/react/pull/20028)) //<Brian Vaughn>//
- **[d95c4938d](https://github.com/facebook/react/commit/d95c4938d )**: [EventSystem] Revise onBeforeBlur propagation mechanics ([#20020](https://github.com/facebook/react/pull/20020)) //<Dominic Gannaway>//
- **[f46a80ae1](https://github.com/facebook/react/commit/f46a80ae1 )**: Update outdated links and fix two broken links  ([#19985](https://github.com/facebook/react/pull/19985)) //<Saikat Guha>//
- **[0a4c7c565](https://github.com/facebook/react/commit/0a4c7c565 )**: [Flight] Don't warn for key, but error for ref ([#19986](https://github.com/facebook/react/pull/19986)) //<Sebastian Markbåge>//
- **[993ca533b](https://github.com/facebook/react/commit/993ca533b )**: Enable eager listeners statically ([#19983](https://github.com/facebook/react/pull/19983)) //<Dan Abramov>//
- **[40c52de96](https://github.com/facebook/react/commit/40c52de96 )**: [Flight] Add Runtime Errors for Non-serializable Values ([#19980](https://github.com/facebook/react/pull/19980)) //<Sebastian Markbåge>//
- **[1992d9730](https://github.com/facebook/react/commit/1992d9730 )**: Revert "Temporarily disable Profiler commit hooks flag ([#19900](https://github.com/facebook/react/pull/19900))" ([#19960](https://github.com/facebook/react/pull/19960)) //<Brian Vaughn>//
- **[44d39c4d7](https://github.com/facebook/react/commit/44d39c4d7 )**: Removed skip-error-boundaries modifications from old fork ([#19961](https://github.com/facebook/react/pull/19961)) //<Brian Vaughn>//
- **[cc77be957](https://github.com/facebook/react/commit/cc77be957 )**: Remove unnecessary error overriding in ([#19949](https://github.com/facebook/react/pull/19949)) //<Paul Doyle>//
- **[97625272a](https://github.com/facebook/react/commit/97625272a )**: Debug tracing tests for CPU bound suspense ([#19943](https://github.com/facebook/react/pull/19943)) //<Brian Vaughn>//
- **[43363e279](https://github.com/facebook/react/commit/43363e279 )**: Fix codestyle for typeof comparison ([#19928](https://github.com/facebook/react/pull/19928)) //<Eugene Maslovich>//
- **[5427b4657](https://github.com/facebook/react/commit/5427b4657 )**: Temporarily disable Profiler commit hooks flag ([#19900](https://github.com/facebook/react/pull/19900)) //<Brian Vaughn>//
- **[1faf9e3dd](https://github.com/facebook/react/commit/1faf9e3dd )**: Suspense for CPU-bound trees ([#19936](https://github.com/facebook/react/pull/19936)) //<Andrew Clark>//
- **[7f08e908b](https://github.com/facebook/react/commit/7f08e908b )**: Fix missing context to componentDidMount() when double-invoking lifecycles ([#19935](https://github.com/facebook/react/pull/19935)) //<Brian Vaughn>//
- **[9198a5cec](https://github.com/facebook/react/commit/9198a5cec )**: Refactor layout effect methods ([#19895](https://github.com/facebook/react/pull/19895)) //<Brian Vaughn>//
- **[ba82eea38](https://github.com/facebook/react/commit/ba82eea38 )**: Remove disableSchedulerTimeoutInWorkLoop flag ([#19902](https://github.com/facebook/react/pull/19902)) //<Andrew Clark>//
- **[c63741fb3](https://github.com/facebook/react/commit/c63741fb3 )**: offscreen double invoke effects ([#19523](https://github.com/facebook/react/pull/19523)) //<Luna Ruan>//
- **[c6917346f](https://github.com/facebook/react/commit/c6917346f )**: Fixed broken Profiler test ([#19894](https://github.com/facebook/react/pull/19894)) //<Brian Vaughn>//
- **[87c023b1c](https://github.com/facebook/react/commit/87c023b1c )**: Profiler onRender only called when we do work ([#19885](https://github.com/facebook/react/pull/19885)) //<Brian Vaughn>//
- **[81aaee56a](https://github.com/facebook/react/commit/81aaee56a )**: Don't call onCommit et al if there are no effects ([#19863](https://github.com/facebook/react/pull/19863)) //<Andrew Clark>//
- **[7355bf575](https://github.com/facebook/react/commit/7355bf575 )**: Consolidate commit phase hook functions ([#19864](https://github.com/facebook/react/pull/19864)) //<Andrew Clark>//
- **[bc6b7b6b1](https://github.com/facebook/react/commit/bc6b7b6b1 )**: Don't trigger lazy in DEV during element creation ([#19871](https://github.com/facebook/react/pull/19871)) //<Dan Abramov>//
- **[a774502e0](https://github.com/facebook/react/commit/a774502e0 )**: Use single quotes in getComponentName return ([#19873](https://github.com/facebook/react/pull/19873)) //<Gustavo Saiani>//
- **[8b2d3783e](https://github.com/facebook/react/commit/8b2d3783e )**: Use Passive flag to schedule onPostCommit ([#19862](https://github.com/facebook/react/pull/19862)) //<Andrew Clark>//
- **[50d9451f3](https://github.com/facebook/react/commit/50d9451f3 )**: Improve DevTools editing interface ([#19774](https://github.com/facebook/react/pull/19774)) //<Brian Vaughn>//
- **[6fddca27e](https://github.com/facebook/react/commit/6fddca27e )**: Remove passive intervention flag ([#19849](https://github.com/facebook/react/pull/19849)) //<Dan Abramov>//
- **[36df9185c](https://github.com/facebook/react/commit/36df9185c )**: chore(docs): Removed outdated comment about fb.me link  ([#19830](https://github.com/facebook/react/pull/19830)) //<Adnaan Bheda>//
- **[16fb2b6f9](https://github.com/facebook/react/commit/16fb2b6f9 )**: Moved resetChildLanes into complete work ([#19836](https://github.com/facebook/react/pull/19836)) //<Brian Vaughn>//
- **[cc581065d](https://github.com/facebook/react/commit/cc581065d )**: eslint-plugin-react-hooks@4.1.2 //<Dan Abramov>//
- **[0044805c8](https://github.com/facebook/react/commit/0044805c8 )**: Update CHANGELOG.md //<Dan Abramov>//
- **[0f70d4dd6](https://github.com/facebook/react/commit/0f70d4dd6 )**: Consider components in jsx as missing dependencies in typescript-eslint/parser@4.x ([#19815](https://github.com/facebook/react/pull/19815)) //<Sebastian Silbermann>//
- **[84558c61b](https://github.com/facebook/react/commit/84558c61b )**: Don't visit passive effects during layout phase ([#19809](https://github.com/facebook/react/pull/19809)) //<Andrew Clark>//
- **[ad8a0a8cd](https://github.com/facebook/react/commit/ad8a0a8cd )**: eslint-plugin-react-hooks@4.1.1 //<Dan Abramov>//
- **[77544a0d6](https://github.com/facebook/react/commit/77544a0d6 )**: Update CHANGELOG.md //<Dan Abramov>//
- **[ed4fdfc73](https://github.com/facebook/react/commit/ed4fdfc73 )**: test(eslint-plugin-react-hooks): Run with TS parsers >= 2.x ([#19792](https://github.com/facebook/react/pull/19792)) //<Sebastian Silbermann>//
- **[cd75f93c0](https://github.com/facebook/react/commit/cd75f93c0 )**: eslint-plugin-react-hooks: fix compatibility with typescript-eslint/parser@4.0.0+ ([#19751](https://github.com/facebook/react/pull/19751)) //<Matthias Schiffer>//
- **[781212aab](https://github.com/facebook/react/commit/781212aab )**: Remove double space in test name ([#19762](https://github.com/facebook/react/pull/19762)) //<Gustavo Saiani>//
- **[e7b255341](https://github.com/facebook/react/commit/e7b255341 )**: Internal `act`: Flush timers at end of scope ([#19788](https://github.com/facebook/react/pull/19788)) //<Andrew Clark>//
- **[d17086c7c](https://github.com/facebook/react/commit/d17086c7c )**: Decouple public, internal act implementation ([#19745](https://github.com/facebook/react/pull/19745)) //<Andrew Clark>//
- **[d38ec17b1](https://github.com/facebook/react/commit/d38ec17b1 )**: [Flight] Set dispatcher for duration of performWork() ([#19776](https://github.com/facebook/react/pull/19776)) //<Joseph Savona>//
- **[4f3f7eeb7](https://github.com/facebook/react/commit/4f3f7eeb7 )**: Bugfix: Effect clean up when deleting suspended tree ([#19752](https://github.com/facebook/react/pull/19752)) //<Andrew Clark>//
- **[7baf9d412](https://github.com/facebook/react/commit/7baf9d412 )**: Combine Flags and SubtreeFlags types ([#19775](https://github.com/facebook/react/pull/19775)) //<Andrew Clark>//
- **[166544360](https://github.com/facebook/react/commit/166544360 )**: Rename effect fields ([#19755](https://github.com/facebook/react/pull/19755)) //<Andrew Clark>//
- **[708fa77a7](https://github.com/facebook/react/commit/708fa77a7 )**: Decrease expiration time of input updates ([#19772](https://github.com/facebook/react/pull/19772)) //<Andrew Clark>//
- **[36df483af](https://github.com/facebook/react/commit/36df483af )**: Add feature flag to disable scheduler timeout in work loop ([#19771](https://github.com/facebook/react/pull/19771)) //<Ricky>//
- **[bcc0aa463](https://github.com/facebook/react/commit/bcc0aa463 )**: Revert "Revert "Remove onScroll bubbling flag ([#19535](https://github.com/facebook/react/pull/19535))" ([#19655](https://github.com/facebook/react/pull/19655))" ([#19761](https://github.com/facebook/react/pull/19761)) //<Dan Abramov>//
- **[99cae887f](https://github.com/facebook/react/commit/99cae887f )**: Add failing test for passive effect cleanup functions and memoized components ([#19750](https://github.com/facebook/react/pull/19750)) //<Brian Vaughn>//
- **[2cfd73c4d](https://github.com/facebook/react/commit/2cfd73c4d )**: Fix typo in comment (Noticable→Noticeable) ([#19737](https://github.com/facebook/react/pull/19737)) //<Ikko Ashimine>//
- **[53e622ca7](https://github.com/facebook/react/commit/53e622ca7 )**: Fix instances of function declaration after return ([#19733](https://github.com/facebook/react/pull/19733)) //<Bhumij Gupta>//
- **[b7d18c4da](https://github.com/facebook/react/commit/b7d18c4da )**: Support Babel's envName option in React Refresh plugin ([#19009](https://github.com/facebook/react/pull/19009)) //<Kevin Weber>//
- **[1f38dcff6](https://github.com/facebook/react/commit/1f38dcff6 )**: Remove withSuspenseConfig ([#19724](https://github.com/facebook/react/pull/19724)) //<Andrew Clark>//
- **[1396e4a8f](https://github.com/facebook/react/commit/1396e4a8f )**: Fixes eslint warning when node type is ChainExpression ([#19680](https://github.com/facebook/react/pull/19680)) //<Pascal Fong Kye>//
- **[a8500be89](https://github.com/facebook/react/commit/a8500be89 )**: Add `startTransition` as a known stable method ([#19720](https://github.com/facebook/react/pull/19720)) //<Andrew Clark>//
- **[380dc95de](https://github.com/facebook/react/commit/380dc95de )**: Revert "Append text string to <Text> error message ([#19581](https://github.com/facebook/react/pull/19581))" ([#19723](https://github.com/facebook/react/pull/19723)) //<Timothy Yung>//
- **[ddd1faa19](https://github.com/facebook/react/commit/ddd1faa19 )**: Remove config argument from useTransition ([#19719](https://github.com/facebook/react/pull/19719)) //<Andrew Clark>//
- **[92fcd46cc](https://github.com/facebook/react/commit/92fcd46cc )**: Replace SuspenseConfig object with an integer ([#19706](https://github.com/facebook/react/pull/19706)) //<Andrew Clark>//
- **[b754caaaf](https://github.com/facebook/react/commit/b754caaaf )**: Enable eager listeners in open source ([#19716](https://github.com/facebook/react/pull/19716)) //<Dan Abramov>//
- **[c1ac05215](https://github.com/facebook/react/commit/c1ac05215 )**: [Flight] Support more element types and Hooks for Server and Hybrid Components ([#19711](https://github.com/facebook/react/pull/19711)) //<Dan Abramov>//
- **[1eaafc9ad](https://github.com/facebook/react/commit/1eaafc9ad )**: Clean up timeoutMs-related implementation details ([#19704](https://github.com/facebook/react/pull/19704)) //<Andrew Clark>//
- **[8da0da093](https://github.com/facebook/react/commit/8da0da093 )**: Disable timeoutMs argument ([#19703](https://github.com/facebook/react/pull/19703)) //<Andrew Clark>//
- **[60ba723bf](https://github.com/facebook/react/commit/60ba723bf )**: Add SuspenseList to devTools ([#19684](https://github.com/facebook/react/pull/19684)) //<Ben Pernick>//
- **[5564f2c95](https://github.com/facebook/react/commit/5564f2c95 )**: Add React.startTransition ([#19696](https://github.com/facebook/react/pull/19696)) //<Ricky>//
- **[c4e0768d7](https://github.com/facebook/react/commit/c4e0768d7 )**: Remove unused argument from `finishConcurrentRender` ([#19689](https://github.com/facebook/react/pull/19689)) //<inottn>//
- **[848bb2426](https://github.com/facebook/react/commit/848bb2426 )**: Attach Listeners Eagerly to Roots and Portal Containers ([#19659](https://github.com/facebook/react/pull/19659)) //<Dan Abramov>//
- **[d2e914ab4](https://github.com/facebook/react/commit/d2e914ab4 )**: Remove remaining references to effect list ([#19673](https://github.com/facebook/react/pull/19673)) //<Andrew Clark>//
- **[d6e433899](https://github.com/facebook/react/commit/d6e433899 )**: Use Global Render Timeout for CPU Suspense ([#19643](https://github.com/facebook/react/pull/19643)) //<Sebastian Markbåge>//
- **[64ddef44c](https://github.com/facebook/react/commit/64ddef44c )**: Revert "Remove onScroll bubbling flag ([#19535](https://github.com/facebook/react/pull/19535))" ([#19655](https://github.com/facebook/react/pull/19655)) //<Dan Abramov>//
- **[dd651df05](https://github.com/facebook/react/commit/dd651df05 )**: Keep onTouchStart, onTouchMove, and onWheel passive ([#19654](https://github.com/facebook/react/pull/19654)) //<Dan Abramov>//
- **[b8fa09e9e](https://github.com/facebook/react/commit/b8fa09e9e )**: provide profiling bundle for react-reconciler ([#19559](https://github.com/facebook/react/pull/19559)) //<Julien Gilli>//
- **[23595ff59](https://github.com/facebook/react/commit/23595ff59 )**: Add missing param to safelyCallDestroy() ([#19638](https://github.com/facebook/react/pull/19638)) //<Brian Vaughn>//
- **[ee409ea3b](https://github.com/facebook/react/commit/ee409ea3b )**: change destroy to safelyCallDestroy ([#19605](https://github.com/facebook/react/pull/19605)) //<Luna Ruan>//
- **[bcca5a6ca](https://github.com/facebook/react/commit/bcca5a6ca )**: Always skip unmounted/unmounting error boundaries ([#19627](https://github.com/facebook/react/pull/19627)) //<Brian Vaughn>//
- **[1a41a196b](https://github.com/facebook/react/commit/1a41a196b )**: Append text string to <Text> error message ([#19581](https://github.com/facebook/react/pull/19581)) //<Timothy Yung>//
- **[e4afb2fdd](https://github.com/facebook/react/commit/e4afb2fdd )**: eslint-plugin-react-hooks@4.1.0 //<Dan Abramov>//
- **[ced05c46c](https://github.com/facebook/react/commit/ced05c46c )**: Update CHANGELOG.md //<Dan Abramov>//
- **[702fad4b1](https://github.com/facebook/react/commit/702fad4b1 )**: refactor fb.me redirect link to reactjs.org/link ([#19598](https://github.com/facebook/react/pull/19598)) //<CY Lim>//
- **[49cd77d24](https://github.com/facebook/react/commit/49cd77d24 )**: fix: leak strict mode with UMD builds ([#19614](https://github.com/facebook/react/pull/19614)) //<Toru Kobayashi>//
- **[ffb749c95](https://github.com/facebook/react/commit/ffb749c95 )**: Improve error boundary handling for unmounted subtrees ([#19542](https://github.com/facebook/react/pull/19542)) //<Brian Vaughn>//
- **[9b35dd2fc](https://github.com/facebook/react/commit/9b35dd2fc )**: Permanently removed component stacks from scheduling profiler data ([#19615](https://github.com/facebook/react/pull/19615)) //<Brian Vaughn>//
- **[3f8115cdd](https://github.com/facebook/react/commit/3f8115cdd )**: Remove `didTimeout` check from work loop //<Andrew Clark>//
- **[9abc2785c](https://github.com/facebook/react/commit/9abc2785c )**: Remove wasteful checks from `shouldYield` //<Andrew Clark>//
- **[1d5e10f70](https://github.com/facebook/react/commit/1d5e10f70 )**: [eslint-plugin-react-hooks] Report constant constructions ([#19590](https://github.com/facebook/react/pull/19590)) //<Jordan Eldredge>//
- **[dab0854c5](https://github.com/facebook/react/commit/dab0854c5 )**: Move commit passive unmount/mount to CommitWork ([#19599](https://github.com/facebook/react/pull/19599)) //<Sebastian Markbåge>//
- **[ccb6c3945](https://github.com/facebook/react/commit/ccb6c3945 )**: Remove unused argument ([#19600](https://github.com/facebook/react/pull/19600)) //<inottn>//
- **[629125555](https://github.com/facebook/react/commit/629125555 )**: [Scheduler] Re-throw unhandled errors ([#19595](https://github.com/facebook/react/pull/19595)) //<Andrew Clark>//
- **[b8ed6a1aa](https://github.com/facebook/react/commit/b8ed6a1aa )**: [Scheduler] Call postTask directly ([#19551](https://github.com/facebook/react/pull/19551)) //<Andrew Clark>//
- **[ce37bfad5](https://github.com/facebook/react/commit/ce37bfad5 )**: Remove resolutions from test renderer package.json ([#19577](https://github.com/facebook/react/pull/19577)) //<Dan Abramov>//
- **[2704bb537](https://github.com/facebook/react/commit/2704bb537 )**: Add ReactVersion to SchedulingProfiler render scheduled marks ([#19553](https://github.com/facebook/react/pull/19553)) //<Kartik Choudhary>//
- **[0c52e24cb](https://github.com/facebook/react/commit/0c52e24cb )**: Support inner component _debugOwner in memo ([#19556](https://github.com/facebook/react/pull/19556)) //<Brian Vaughn>//
- **[0cd9a6de5](https://github.com/facebook/react/commit/0cd9a6de5 )**: Parallelize Jest in CI ([#19552](https://github.com/facebook/react/pull/19552)) //<Andrew Clark>//
- **[a63893ff3](https://github.com/facebook/react/commit/a63893ff3 )**: Warn about undefined return value for memo and forwardRef ([#19550](https://github.com/facebook/react/pull/19550)) //<Brian Vaughn>//
- **[32ff42868](https://github.com/facebook/react/commit/32ff42868 )**: Add feature flag for setting update lane priority ([#19401](https://github.com/facebook/react/pull/19401)) //<Ricky>//
- **[5bdd4c8c6](https://github.com/facebook/react/commit/5bdd4c8c6 )**: Remove unused argument from call to jest method ([#19546](https://github.com/facebook/react/pull/19546)) //<Gustavo Saiani>//
- **[a5fed98a9](https://github.com/facebook/react/commit/a5fed98a9 )**: Register more node types that are used later as JSXIdentifiers ([#19514](https://github.com/facebook/react/pull/19514)) //<Mateusz Burzyński>//
- **[f77c7b9d7](https://github.com/facebook/react/commit/f77c7b9d7 )**: Re-add discrete flushing timeStamp heuristic (behind flag) ([#19540](https://github.com/facebook/react/pull/19540)) //<Dominic Gannaway>//

Changelog: [general] [feature] Upgrade to React 17

Reviewed By: cpojer

Differential Revision: D24491201

fbshipit-source-id: c947da9dcccbd614e9dc58f3339b63e24829aca7
2020-10-26 20:28:00 -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
Héctor Ramos 6f78e16c01 iOS: Build react-native-codegen as part of RNTester pod install
Summary:
Ensure the react-native-codegen package is built before the codegen is invoked during RNTester's pod install.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24515852

fbshipit-source-id: eeb1237f601d83a79a5274261c374bb5fc5689eb
2020-10-26 11:31:08 -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
Ramanpreet Nara a68754f9b2 Disallow non-string literals in TurboModuleRegistry calls
Summary:
Our NativeModule spec parser parses the TurboModuleRegistry.get<Spec>(...) calls to figure out what the name of the NativeModule is. The parser assumes the argument is a string literal. Therefore, we should lint to validate this case.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24500412

fbshipit-source-id: 5aa5e9255db5a2e0cd86d6dd96e6787caa673fc4
2020-10-24 03:45:03 -07:00
Ramanpreet Nara 008596d42f Disallow more than one TurboModuleRegistry calls in NativeModule specs
Summary:
TurboModule specs should have exactly one TurboModuleRegistry.get or TurboModuleRegistry.getEnforcing call. When a JS file contains more than one call into TurboModuleRegistry, this lint rule will report an error on all calls.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24499286

fbshipit-source-id: 2c47185165a2a81c4b7b7ad9a7b8458e9aa8c018
2020-10-24 03:45:03 -07:00
Ramanpreet Nara ad5802cf91 Make RN Modules ESLint rule call into NativeModule spec parser
Summary:
This diff guts the React Native Modules ESLint rule, and makes it instead call into the NativeModule spec parser. After calling into the parser, the lint rule loops over all collected errors, and reports them.

## Benefits
- There is now one source of truth of what is a "correct" NativeModule spec: The NativeModule spec parser.
- Every change we make to the NativeModule spec parser will reflect in the lint rule. We have a number of changes planned for the NativeModule parser that will change what it means for a NativeModule spec to be correct. These changes now won't have to be duplicated in the ESLint rule.
- The linter will *never* show any false positive errors. If there's an error in the linter, you *need* to fix it. Otherwise, the codegen *will* fail. This is huge. Previously, people were used to ignoring the linter, because it over-reported errors. This behavior won't slide after this stack lands.

NOTE: This will run the NativeModules parser on all our NativeModule specs. We may have to check the specs, or the parser. Therefore, this could take some time to land.

## How does the lint rule work now?
In every JavaScript file, the ESLint rule looks for `CallExpression` AST Nodes. Once it detects a `CallExpression` that corresponds to a `TurboModuleRegistry.get` or `TurboModuleRegistry.getEnforcing`  it:
  1. Marks the file as a TurboModule spec
  2. Validates the `CallExpression` to verify that it is called with the <Spec> type parameters (i.e: like this: TurboModuleRegistry.get<Spec>(...)).

When we're done the visition for the JavaScript file (i.e: in `Program:exit`), if the JavaScript file was a TurboModule spec:
1. Report a lint error if the filename doesn't start with Native.
2. We parse the source using flow-parser, and run the NativeModule spec parser on it. We capture all ParserErrors and report them via ESLint.

## When can I start using this lint rule in VSCode?
I made the ESLint VSCode plugin use flow-node in D24454702. It'll take 3-4 weeks for this change to be shipped to everyone's VSCode. After the update, the linter will automatically start working in VSCode. Until then, we'll only get feedback on Sandcastle/Landcastle for lint rule violations.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24379783

fbshipit-source-id: 222778d8a84d7010eb7b3ad71b34a7fe1f52e509
2020-10-24 03:45:03 -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
Keith Melmon b5de89755d add testID, helps tests find items in the list (#30138)
Summary:
This change adds a testID to each item in the RNTester list.  This helps Appium find items in the list for automated tests.  The change was added in react-native-windows as part of end-to-end test infrastructure changes.    See https://github.com/microsoft/react-native-windows/pull/5555

We'd like to remove this forked file, upstreaming this change will enable us to do that.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[General] [Changed] - add testID to items in RNTester test list, helps test automation tools find the items

Pull Request resolved: https://github.com/facebook/react-native/pull/30138

Test Plan: Change is currently running in react-native-windows CI loop.

Reviewed By: cpojer

Differential Revision: D24434352

Pulled By: appden

fbshipit-source-id: 998916d8fe4e4e4cd6ac764baabb9fd5f2e312c7
2020-10-20 17:29:13 -07:00
Joshua Gross a17ff44adc Upgrade minsdkversion of RN OSS template to API level 21
Summary:
This diff updates the minsdkversion of RN OSS template to API level 21.

Changelog: [Android][Deprecated] Deprecate support of Android API levels 19 and 20. The new minSDK version will be 21+ moving forward.

Reviewed By: fkgozali

Differential Revision: D24379607

fbshipit-source-id: 6801cdcd363065807cdc11006bd94217f914fac7
2020-10-20 17:00:47 -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
Héctor Ramos d03c0f965e Generate FBReactNativeSpec ObjC++ source files using CocoaPods
Summary:
Move FBReactNativeSpec codegen invocation to shared `react_native_pods.rb` script and trigger codegen to run as part of `pod install` in both RNTester as well as React Native for iOS projects.

These files need to be generated before CocoaPods generates the Pods project, so the codegen is invoked as part of a `pre_install` hook during `pod install`.

The codegen hook can now take optional paths to allow it to run within different contexts (as part of a `react-native` repo checkout with access to the codegen source, or as part of a React Native iOS project that depends on the `react-native-codegen` npm package).

## Motivation

The FBReactNativeSpec ObjC++ source files (FBReactNativeSpec.h and FBReactNativeSpec-generated.mm) can be generated on demand from the native module specs in `Libraries/` using `react-native-codegen`. They can therefore be removed from the repository, but before we do so, we must ensure they get generated when a React Native iOS workspace is created or updated.

Invoking the codegen as part of the `pod install` step that creates a React Native iOS Xcode workspace ensures the specs are available in the following scenarios:
* Whenever a new React Native iOS project is created. The `react-native init` command invokes `pod install`.
* Whenever a React Native iOS project is upgraded. The `react-native upgrade` command invokes `pod install` as well.
* For contributors to the open source project running the RNTester application, the codegen will be invoked when the RNTester workspace is generated by CocoaPods using `pod install` in `packages/rn-tester`.

In any other case, the codegen can still be invoked directly via `scripts/generate-native-modules-specs.sh`.

> **Note:**
> The codegen will only process native modules in React Native's own Libraries directory.

Changelog:
[iOS][Changed] - Generate FBReactNativeSpec ObjC++ source files using CocoaPods.

Reviewed By: fkgozali

Differential Revision: D24348111

fbshipit-source-id: d62ae5c6f8ce6358bf96a2801c3cdb3d94dd868d
2020-10-20 13:17:00 -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
Kevin Gozali 3ed38df175 TurboModule Android: Remove RNTester module lookup override
Summary:
The manual lookup logic was needed before we properly parse the module names from the spec js files. This is no longer necessary after the commit stack starting with 3a75b376cc

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24370567

fbshipit-source-id: fc307d93cdda240a977e37dfe602502bd3f7c2a4
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
Ramanpreet Nara abeae870d4 Update Component generator fixtures 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: D24236502

fbshipit-source-id: 288c6d9588bde177732fe8165d3374eeacad999d
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 4ee65f66cf Update Module generator fixtures 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).

Changelog: [Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: PeteTheHeat

Differential Revision: D24236509

fbshipit-source-id: 1b603e8728d7be1e8bdede5878f57d6556b5c52f
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 3d0a626c87 Update NativeModule parser to generate new schema
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
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 8b1ae7a4ae Annotate Component parser's output with 'Component' type
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
2020-10-15 22:53:55 -07:00
Ramanpreet Nara 3a75b376cc Create NativeModuleSchema and 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).

## 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
2020-10-15 22:53:55 -07:00
Héctor Ramos 62518ba64f Bump react-native-codegen: 0.0.4
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
2020-10-15 06:16:22 -07:00
Lorenzo Sciandra fb14fd42b3 Chore: Upgrade Detox to 16.7.2 (#30084)
Summary:
With Xcode 12 being the latest, Detox 15.x has issues - in particular, it means that if you try to `yarn install` the dependencies for the repo, you'll be greeted by this error:

```bash
error /<stuff>/react-native/node_modules/detox: Command failed.
Exit code: 1
Command: node scripts/postinstall.js
Arguments:
Directory: /<stuff>/react-native/node_modules/detox
Output:
/<stuff>/Library/Detox/ios/5824c837515589f21c08f09b716a6eda088aa31f was found, but could not find Detox.framework inside it. This means that the Detox framework build process was interrupted.
         deleting /<stuff>/Library/Detox/ios/5824c837515589f21c08f09b716a6eda088aa31f and trying to rebuild.
Extracting Detox sources...
Building Detox.framework from /<stuff>/Developer/OSS/react-native/node_modules/detox/ios_src...
child_process.js:637
    throw err;
    ^
```

With the {emoji:1f44d} of hramos & alloy I've prep'd up a small defensive PR that can be quickly merged before cutting 0.64, that bumps the version of Detox from 15.4.4 to the highest version available within the reach of "no breaking changes" in changelog.

The main reason why with 16.x this error doesn't happen is that from [16.0.0](https://github.com/wix/Detox/releases/tag/16.0.0):

> Detox now comes as a prebuilt framework on iOS, thus lowering npm install times and saving some build issues that happen due to unexpected Xcode setups.

It would have been better to update directly to latest (at the time of writing 17.7.1) but there are at least two versions that had changelogs that seem to involve bigger changes:

* https://github.com/wix/Detox/releases/tag/17.4.7
* https://github.com/wix/Detox/releases/tag/16.8.0

Hopefully CI will will show that the bump doesn't break any test �

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Changed] - Bumped Detox in the repo to 16.7.2 for Xcode 12 compatibility

Pull Request resolved: https://github.com/facebook/react-native/pull/30084

Test Plan: Running yarn in the main repo with Node 14 & Xcode 12, without this change, will cause the error copy-pasted above. After upgrading to this version, the error disappear.

Reviewed By: cpojer

Differential Revision: D24293226

Pulled By: hramos

fbshipit-source-id: 2b4d23b033be621274966262ec19200bee44df58
2020-10-14 12:06:06 -07:00
Lulu Wu ea93151f21 Make RCTEventDispatcher TurboModule-compatible
Summary:
This diff ended up being a bit more complicated than I anticipated, since the source files in `ReactInternal` were depending on `RCTEventDispatcher`. I made the following changes:
1. Make `RCTEventDispatcher` a `protocol`, keep it in `ReactInternal`.
2. Rename the `RCTEventDispatcher` NativeModule to `RCTEventDispatcherModule`, make it conform to the `RCTEventEmitter` `protocol`, and move it to `CoreModules`.
3. Where necessary, replace categories of `RCTEventDispatcher` with functions.

Changelog:
[iOS][Added] - Make RCTEventDispatcher TurboModule-comaptible

Reviewed By: fkgozali

Differential Revision: D18439488

fbshipit-source-id: b3da15c29459fddf884519f33b0c3b8c036b5539
2020-10-14 02:40:10 -07:00
Peter Argany b05d90e8bb Remove type union in Picker.js
Summary:
Flow type unions don't play well with Fabric components. This diff removes a union in `Picker.js` and fixes all the flow errors.

Before this diff, all these surfaces would crash with the new Fabric Picker impl, because the impl asserts that this field is a string.

Reviewed By: sammy-SC

Differential Revision: D24236317

fbshipit-source-id: 6e646c84fcd16658aaabe5e93507f5f33b346a65
2020-10-13 11:19:29 -07:00
Nick Gerleman 4d247fe058 Avoid Repo Structure Assumptions in RNTester Imports (#30141)
Summary:
RNTester has some imports left over that operate on directory traversal, assuming it is contained within react-native sources. This change makes these imports relative to react-native, enabling usage outside of the RN repo.

Relates to https://github.com/microsoft/react-native-windows/issues/6210

## Changelog

[Internal] [Fixed] - Avoid File Structure Assumptions in RNTester Imports

Pull Request resolved: https://github.com/facebook/react-native/pull/30141

Test Plan: Validated we can bundle and flow-check both iOS + Android

Reviewed By: cpojer

Differential Revision: D24259628

Pulled By: appden

fbshipit-source-id: 0c21b5d354b01785d8402599da3b0a5be81b4c6d
2020-10-12 19:56:09 -07:00
simek b7167c23fc PlatformColors: add missing clearColor for iOS (#30054)
Summary:
This small PR adds missing [`clearColor`](https://developer.apple.com/documentation/uikit/uicolor/1621945-clearcolor?language=objc) to the avaiable PlatformColors on iOS.

**Please let me know** if you would like to see ["Fixed colors"](https://developer.apple.com/documentation/uikit/uicolor/standard_colors?language=objc) added to the `PlatformColors`. I can address this within this PR or create a separate one.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Added] - PlatformColors: add missing `clearColor`

Pull Request resolved: https://github.com/facebook/react-native/pull/30054

Test Plan:
[(I had to disable the Dark Mode to fix the RNTester readability problems)](https://user-images.githubusercontent.com/719641/94453196-b35cb000-01b0-11eb-8d7d-73d48ceecf53.PNG)

Transparent/clear color has been added to the RNTester PlatformColors API example:
![IMG_6782](https://user-images.githubusercontent.com/719641/94453172-ae97fc00-01b0-11eb-9bef-1a1a387ac009.PNG)

Reviewed By: shergin

Differential Revision: D24241160

Pulled By: sammy-SC

fbshipit-source-id: 41fb51677329cc3b3f915d5d08694c07b4ef2cf3
2020-10-12 02:14:42 -07:00
Janic Duplessis 6685aba462 Update template to xcode 12 (#30150)
Summary:
This makes a few change to the template xcodeproj

- Update to recommended settings for Xcode 12
- Remove the main.jsbundle file that doesn't exists, this file is included automatically in the app bundle and doesn't need to be in xcode (it won't even be at that path).
- Add -e to the bundle images script. It seems like Xcode doesn't fail the build on script errors anymore so this makes it so the build stop. If it doesn't stop the app will launch and crash because the bundle doesn't exist (note this is only if running the app in release mode since in debug we don't generate the bundle).

## Changelog

[iOS] [Added] - Update template to xcode 12

Pull Request resolved: https://github.com/facebook/react-native/pull/30150

Test Plan: Made the same changes in an app and made sure it ran well.

Reviewed By: cpojer

Differential Revision: D24237481

Pulled By: sammy-SC

fbshipit-source-id: 2b06a24c510c423eb45a1a840ea365b64506321b
2020-10-12 01:28:32 -07:00
Ramanpreet Nara 8e943d8f5a Remove reliance on util.inspect in snapshot tests
Summary:
According to Node's documentation: https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors

> The util.inspect() method returns a string representation of object that is intended for debugging. **The output of util.inspect may change at any time and should not be depended upon programmatically.**

Therefore, this diff switches over our RN Codegen snapshot tests to use a `JSON.stringify` call, followed by a replace of `"` with `'`. This gets the job done without compromising readability.

**Question:** Why do we not use `"`? A: Jest escapes all `"` in the snapshots, which makes reading the snapshots/using them in the console harder.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24157056

fbshipit-source-id: 2f1aa2df28ac3ed4aa17bcdbcd23846ddbf804cf
2020-10-07 14:28:20 -07:00
Héctor Ramos 4eb8bd5084 trivial: Remove whitespace in generated output
Summary:
Remove extraneous newlines before and after structs, before copyright headers, and other locations.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24117137

fbshipit-source-id: 194996019b4cadef9239a78334f31c0bc89e3901
2020-10-06 01:44:20 -07:00
Héctor Ramos d4937b925b Use correct var name for element when handling arrays of type aliases
Summary:
Fixes an issue where, if a spec uses an array of elements where the element is a type alias, the generated code would use the wrong variable name.

An example of such a spec can be found in `NativeExceptionsManager.js`:
```
  +reportSoftException: (
    message: string,
    stack: Array<StackFrame>,
    exceptionId: number,
  ) => void;
```

The fix ensures the local variable name is passed through, ensuring that either p or itemValue_N is used when appropriate.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D24116429

fbshipit-source-id: f39b75adb604c751d70a284a11a7fa6649b1344d
2020-10-05 12:57:34 -07:00
Christoph Nakazawa 43624dd193 Update Babel to 7.11.6
Summary: Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D24039996

fbshipit-source-id: 26ec2a988faadf24ea76d9124052d9397682787b
2020-10-05 05:46:31 -07:00
Ramanpreet Nara 3b6b039e85 Make JavaPoet JavaSpec Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24030728

fbshipit-source-id: b79f7dfa7304bfddc6333c641eadcaa55c0cb7a0
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 5122e33f4e Make ObjCPP Generator handle NullableTypeAnnotation
Summary:
See title.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027243

fbshipit-source-id: 4e03a14fd23c1f5f3d282fc14a760d7549cdd6b9
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 6d7e763e85 Make JniCpp Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027245

fbshipit-source-id: 73f9e7ec7ccb7627d2df63798a4269c860388dde
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 0a2228ae3f Make JavaSpec Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027248

fbshipit-source-id: 7ca0e04e8e2f19cffc9aea3d6db51f86703c06f7
2020-10-01 19:30:08 -07:00
Ramanpreet Nara d9dc9d5d0a Make H Generator handle NullableTypeAnnotation
Summary: Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027247

fbshipit-source-id: cc326f5db919de1f6c6b56603f420c87272da918
2020-10-01 19:30:08 -07:00
Ramanpreet Nara 1a90e1b471 Make Cpp Generator handle NullableTypeAnnotation
Summary:
See title.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027244

fbshipit-source-id: 4f967a7a72afd6aa7a886c16eeb683c52da2dc9c
2020-10-01 19:30:07 -07:00
Ramanpreet Nara 6fe06ca160 Update generator fixtures to use NullableTypeAnnotation
Summary:
This will make sure that the snapshot tests for the generators work with NullableTypeAnnotation.
Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24027246

fbshipit-source-id: cee93e40be7585ec527087d114f8326c2ecb9ddd
2020-10-01 19:30:07 -07:00
Ramanpreet Nara 8d807dfbc3 Introduce NullableTypeAnnotation for Flow Module Parser
Summary:
Previously, all our type annotations contained a `nullable` property. This diff removes that property from all our NativeModule type annotations, and instead introduces a `NullableTypeAnnotation`.

**Some Benefits:**
- In all our serialization functions, we use Flow exhaustive checking to ensure that all type-annotations can be serialized. Since nullability is now recorded as a type annotation, Flow will ensure we always explicitly handle nullability. Previously, with nullability as a property, we could ignore it without any feedback from flow.
- This aligns the NativeModule schema with the ESTree spec.
- After this diff, we're one step closer to sharing type annotations with Codegen's schema. Many NativeModule type annotations now have the same shape as their Codegen counterparts. They will be merged in a subsequent diff.

**Downsides:**
- If you want to check whether a type annotation is of type `T`, you have to remember to unwrap the type annotation *yourself*. Flow won't warn you if you forget to unwrap the type, which can lead to incomplete handling to nullable types in our generators.
- When you're creating type annotations in code, previously, you *had* to specify nullability, since it was a property on all type annotation objects. Now, it's very possible for you to forget to wrap the type annotation, which will just lead to nullability bugs.

**Notes:**
- In the scheam, exported type annotations are *always* required. They can be made nullable using the new `Nullable` genric type.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D24026887

fbshipit-source-id: 9e71e2c6102dc506824403dbb712488ca8507d08
2020-10-01 19:30:07 -07:00
Ramanpreet Nara 0a2e0f777b Make Flow Parser snapshots more readable
Summary:
The Flow Parser's snapshots, which are serializations of the CodegenSchema object, are extremely difficult to read. In this diff, I explicitly serialized the schema objects using Node's `util.inspect`.

**Benefits:**
- The snapshots are more readable now.
- You can copy-paste the objects from the snapshot files directly into the Chrome console, or into other JavaScript files. This is a very useful feature, when we're testing the generators, or other infra that depends on the codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24063112

fbshipit-source-id: 2c6ec3424aac8bab2688dc6ae286b73f90e4bef1
2020-10-01 19:30:07 -07:00
Frieder Bluemle 553fb8b28d Update Android Gradle plugin to 4.0.1 (#29013)
Summary:
This is a major version update that needs to be tested thoroughly.

Android Studio 4.0.1 is now available in the stable channel

https://androidstudio.googleblog.com/2020/05/android-studio-40-available-in-stable.html
https://developer.android.com/studio/releases/gradle-plugin#4.0.1

## Changelog

[Android] [Changed] - Update Android Gradle plugin to 4.0.1

Pull Request resolved: https://github.com/facebook/react-native/pull/29013

Test Plan:
Build project

Closes https://github.com/facebook/react-native/issues/29044

Reviewed By: shergin

Differential Revision: D24041233

Pulled By: fkgozali

fbshipit-source-id: 68ef0f313aa773866e65796e323ed0f19f41f834
2020-09-30 22:16:54 -07:00
Kevin Gozali 1d89ef87b6 TurboModule: exclude NativeSampleTurboModule in the schema
Summary:
The sample module is meant for demo only, but it lives alongside other core modules in react-native repo.

For now, exclude it in the Flow-type parsing, just like `NativeUIManager.js`

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D24005108

fbshipit-source-id: 9ef524bfe2778dd983c94d1701f9ce49da5e0a68
2020-09-29 18:41:14 -07:00
Kevin Gozali 94b198cfd5 TurboModule Android: install SampleTurboModule and the playground to RNTester
Summary:
This compiles SampleTurboModule into RNTester Android. It also adds the NativeModule playground to show case TurboModule system to RNTester examples, just like in iOS.

{F337854369}

Changelog: [Android][TurboModule] Added TurboModule example to RNTester when `USE_CODEGEN` is set

Reviewed By: hramos

Differential Revision: D24004711

fbshipit-source-id: b682dd51fa998ee2e60f8d6ffd8c39220d13a7fe
2020-09-29 18:41:14 -07:00
Kevin Gozali b9a1ea9e9e TurboModule Android: move SampleTurboModule impl and spec to OSS
Summary:
This is the Java/JNI impl of the NativeSampleTurboModule.js, just like on iOS. The files here are supposed to be generated by the react-native-codegen, but they are checked in to the repo for easier build integration with RNTester.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23985746

fbshipit-source-id: 46340d778f3d964efe5b538d15ebe0f2cab04862
2020-09-29 18:41:14 -07:00
Kevin Gozali b931bd33fe TurboModule Android: properly set up RNTester ndkBuild and cleanup dependencies
Summary:
Before RNTester compilation starts, it needs to wait for :ReactAndroid NDK build to finish, so that it knows where to find the exported .so files. This tells the `preBuild` task to depends on `:ReactAndroid:prepareReactNdkLibs` task. The .so files are now copied over to the local project build dir, instead of depending on :ReactAndroid's build dir.

For cleanup, the reverse ordering is needed: before `clean` removed our temp dir to store the copied .so files, make sure the ndkBuild cleanup tasks execute beforehand.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23982989

fbshipit-source-id: 955d7c9bccb5855b6b066fca89764df2ede89f63
2020-09-29 18:41:14 -07:00
Ramanpreet Nara 6e6443afd0 Remove header_namespace from module codegen target
Summary:
Making this change because I see this error when compiling Internationalization
```
➜  fbsource buck build //xplat/js/RKJSModules/Libraries/Internationalization:generated_objcpp_modules-InternationalizationApple
buck-out/gen/33fbdb84/xplat/js/RKJSModules/Libraries/Internationalization/generate_module_mm-Internationalization/FBReactNativeInternationalizationSpec-generated.mm:15:9: fatal error: 'FBReactNativeInternationalizationSpec.h' file not found
#import "FBReactNativeInternationalizationSpec.h"
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Command failed with exit code 1.

command: [/Applications/Xcode_11.6.0_fb.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++, @/Users/ramanpreet/fbsource/buck-out/bin/33fbdb84/xplat/js/RKJSModules/Libraries/Internationalization/generated_objcpp_modules-InternationalizationApple#compile-FBReactNativeInternationalizationSpec-generated.mm.o...
```

Since the header namespace is "FBReactNativeInternationalizationSpec", we can only import the header file via "FBReactNativeInternationalizationSpec/FBReactNativeInternationalizationSpec.h", according to this buck documentation: https://buck.build/rule/cxx_library.html#headers. Not entirely sure how this target compiled before.

The legacy codegen buck target also set the header namespace to "": https://fburl.com/diffusion/3p85qhf9.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23978436

fbshipit-source-id: c9cd7c710edf94df6df10778f8603870f92275a7
2020-09-29 14:39:42 -07:00
Ramanpreet Nara 6d6e04619f Fix ObjC++ structs and method mapping
Summary:
Adjust generated ObjC++ code to resolve a few build time and run time errors:

* Suppress CONSTANTS struct implementations
* Use type alias name as struct name when serializing arguments that involve a type alias
* Use actual number of arguments for a method when generating method map.

With these changes in place, RNTester can be built and run using the code that is generated by the new codegen.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23926500

fbshipit-source-id: 88fcbb795fd71dc8155eb26348db943975e13e84
2020-09-29 14:39:41 -07:00
Ramanpreet Nara 97d3e85c29 Fix ObjC++ module generator output
Summary:
* Removed extraneous closing brace.
* Fixed static method signature, replacing double colon with an underscore (`static facebook::jsi::Value __hostFunction_Native${moduleName}SpecJSI::${methodName}()` -> `static facebook::jsi::Value __hostFunction_Native${moduleName}SpecJSI_${methodName}()`).
* Wrap `getConstants` selector name with `selector()`.
* Pass through `getConstants` and `constantsToExport` to allow de-duping of `getConstants` method in generator output.

Note that the FBReactNativeSpec that is output by the generator still has some issues that need to be addressed before it can be used.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23910505

fbshipit-source-id: 37d884885b8878f38d40637377c2a74a728c3a13
2020-09-29 14:39:41 -07:00
Ramanpreet Nara 1b3dc1d9e3 Fix GenerateModuleJniCpp
Summary:
Just updated the generator to work with the new RN Codegen Flow Parser types.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23667253

fbshipit-source-id: ef94e75287d37dfd7b80f61455a1bfa34bddeb28
2020-09-29 14:39:41 -07:00
Ramanpreet Nara cedd628fc3 Fix GenerateModuleJniH
Summary:
Just updated the generator to work with the new RN Codegen Flow Parser types.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23667250

fbshipit-source-id: f36b5418101c40331964d1f9ede7c6bd7924383d
2020-09-29 14:39:41 -07:00
Ramanpreet Nara 560ac1a9fa Fix GenerateModuleJavaSpec
Summary:
Just updated the generator to work with the new RN Codegen Flow Parser types.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23667255

fbshipit-source-id: 40b7747aad89f6d5bbb9f42d59a4df9633060c66
2020-09-29 14:39:41 -07:00
Ramanpreet Nara 4ab7cc236a Fix GenerateModuleH
Summary:
Just updated the generator to work with the new RN Codegen Flow Parser types.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23667252

fbshipit-source-id: 34404a478ddd67446d82b5f98e1051300064e95c
2020-09-29 14:39:41 -07:00
Ramanpreet Nara c0408b56fc Fix GenerateModuleCpp
Summary:
Just updating this generator to understand the new RN Codegen Module parser flow types.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23667254

fbshipit-source-id: 558dd7ac5b4541edf40248b8ab8bb50d31fa8624
2020-09-29 14:39:40 -07:00
Ramanpreet Nara 1ac1255d63 E2E snapshot test ObjC++ generator
Summary:
NativeModule specs exist under `react-native-github/packages/react-native-codegen/src/__tests__/modules/fixtures`. `GenerateModuleObjCpp-test.js` runs the RN Codegen on those NativeModule specs, and saves the output inside a snapshot. For convenience, the folowing command runs the legacy codegen on the fixtures:

```
buck build fbsource//xplat/js/react-native-github/packages/react-native-codegen/src/__tests__/modules:RNCodegenModuleFixtures-flow-types-ios --show-output
```

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23637708

fbshipit-source-id: 3319f319515eca42b4499682313fea6e0bdc2a06
2020-09-29 14:39:40 -07:00
Ramanpreet Nara c267b8de72 Rewrite ObjC++ module generator
Summary:
## Misc. Improvements

* We now have 95%+ flow coverage in all generator files. Henceforth, we can make changes to these files with more confidence, and trust flow to catch more errors. This should also improve the DevX of working on these files.
* Better templates: Instead of doing string replace with RegExps, we instead use functions and leverage JS template literals to generate our code. A few benefits: (1) data dependencies of templates are clearly visible, and statically checked by flow, (2) the templates are more readable in VSCode.
* Merged the GenerateModuleHObjCpp.js and GenerateModuleMm.js generators. They can share a lot of logic, so it's not a good idea to keep them separate.
* The ObjC++ module generator no longer generates “dead” structs (i.e structs that aren’t used by type-safety infra). In fact, it explicitly only supports the types in our Wiki. (I know this wasn’t the case with the legacy codegen, because we were generating native code for enums in the legacy codegen). This is a mixed bag. The test to verify correctness will be more difficult to write. However, keeping structs in the codegen needlessly complicates the parsers + generators, and creates technical debt for us to clean up later.

## Abstractions
- **StructCollector:** As we serialize NativeModule methods, when we detect an ObjectTypeAnnotation in the return type of `getConstants()` or inside a method param, we must create a Struct JS object for it. When we detect a type-alias (also in the same locations), we must look up that type-alias and create a Struct from its RHS. A Struct is basically an ObjectTypeAnnotation with a context (i.e: used in getConstants() vs as a method param), that cannot contain other ObjectTypeAnnotations.
- **serializeMethod.js** Given a NativeModule method type annotation, output the protocol method, JS return type, selector, a record of which params were structs, and which structs. Basically, this is all the information necessary to generate the declaration and implementation codegen for a partiular NativeModule method.
- **serializeStruct/*.js**: After creating all these Structs, we need to loop over all of them, and tranform them into ObjC++ code.
  - **serializeStruct.js**: Depending on the struct context, calls either `serializeRegularStruct.js` or `serializeConstantsStruct.js`. Both of these files have the same layout/abstractions. They look very similar.
- **serializeModule.js:** Outputs RCTCxxConvert categories for transforming `NSDictionary *` into C++ structs. Outputs ObjCTurboModule subclass.

## Algorithm
```
for spec in NativeModuleSpecs
  structCollector = new StructCollector
  resolveAlias = (aliasName) => nullthrows(spec.aliases[aliasName])

  methodDatas = []
  for method in methods(spec)
    methodData.push(serializeMethod(method, structCollector, resolveAlias))
  end

  structs = structCollector.getStructs()

  output generateImplCodegen(methodDatas, structs)
  output generateHeaderCodegen(methodDatas, structs)
end
```

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23633940

fbshipit-source-id: 7c29f458b65434f4865ef1993061b0f0dc7d04ce
2020-09-29 14:39:40 -07:00
Ramanpreet Nara c300193853 Create utilities for module generators
Summary:
There are two operations we do in every NativeModule generator:
- We convert the `SchemaType` into a map of NativeModule schemas
- If the type-annotation is a TypeAliasTypeAnnotation, we resolve it by doing a lookup on the NativeModuleAliasMap. This is usually followed by an invariant to assert that the lookup didn't fail.

Both procedures have been translated into utilities for use across our generators. I also deleted `getTypeAliasTypeAnnotation` which will no longer be used.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23667249

fbshipit-source-id: 4e34078980e2caa4daed77c38b1168bfc161c31c
2020-09-29 14:39:40 -07:00
Ramanpreet Nara 5f5ccfcb2c Update generator fixtures to comply with Schema flow types
Summary:
In diffs below, we made several changes to the NativeModule schema. This diff just ensures that the input to our generator snapshot tests, which are module schemas, are valid.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D23633942

fbshipit-source-id: 444ccd60f6ec76e348a8e54b946260464ff3aeee
2020-09-29 14:39:40 -07:00
Ramanpreet Nara 91a7da087b Refactor: Make NativeModuleArrayTypeAnnotation elementType customizable
Summary:
In the future, we'll use `NativeModuleArrayTypeAnnotation` inside JS struct objects. Structs cannot contain `ObjectTypeAnnotations` anywhere. Therefore, we need the elementType of `NativeModuuleArrayTypeAnnotation`'s elementType customizable.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23645210

fbshipit-source-id: 97abb993d59536ebd68ec08b18ce7f2801c68a2d
2020-09-29 14:39:39 -07:00
Ramanpreet Nara 4927de6011 Rename GenericPromiseTypeAnnotation to PromiseTypeAnnotation
Summary:
We have first class support for Promises in our codegen. So, it's more appropriate to just call this PromiseTypeAnnotation, as opposed to GenericPromiseTypeAnnotation.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23645209

fbshipit-source-id: bfc0b909750e221e18be33acf197f342a2918aa9
2020-09-29 14:39:39 -07:00
Ramanpreet Nara 92a6722bf2 Refactor: Make NativeModuleAliasMap $ReadOnly
Summary:
We were using `$ReadOnly<NativeModuleAliasMap>` everywhere, so I figured we'd just make the type itself `$ReadOnly`.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23645207

fbshipit-source-id: 4e018d5768f4fcfd00492def7d840a5054cb2b73
2020-09-29 14:39:39 -07:00
Ramanpreet Nara 2e0fb69365 Refactor: Introduce Required<T> generic type
Summary:
This diff introduces a `Required<T>` generic type in CodegenSchema. Why? NativeModule aliase RHSs are basically ObjectTypeAnnotations but they have `nullable` fixed to `false`. This generic type reduces duplication in the schema flow types.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23645208

fbshipit-source-id: da984f64fa17d8533a3ea74b132ce10aae9aa7ed
2020-09-29 14:39:39 -07:00
Ramanpreet Nara 1194a36efa Export module type annotations from CodegenSchema
Summary:
This diff has a few changes:
- All type annotations are now declared top-level, and exported from `CodegenSchema.js`.

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D23616473

fbshipit-source-id: 1509c304305e56674bd76c44bc49f755dfeaa332
2020-09-29 14:39:39 -07:00
Ramanpreet Nara 572e1da889 Fix type alias nullability resolution in module parser
Summary:
Consider this case:

```
type Animal = ?{|
  name: string,
|};

type B = Animal

export interface Spec extends TurboModule {
  +greet: (animal: B) => void;
}
```

The generated output for this spec is:

```
namespace JS {
  namespace NativeSampleTurboModule {
    struct Animal {
      NSString *name() const;

      Animal(NSDictionary *const v) : _v(v) {}
    private:
      NSDictionary *_v;
    };
  }
}

protocol NativeSampleTurboModuleSpec <RCTBridgeModule, RCTTurboModule>
- (void)greet:(JS::NativeSampleTurboModule::Animal &)animal;
end
```

Observations:
  1. The codegen looks as though we wrote `+greet: (animal: ?Animal) => void;` as opposed to `+greet: (animal: B) => void;`
  2. The generated struct is called `Animal`, not `B`.

## After this diff
Whenever we detect a usage of a type alias, we recursively resolve it, keeping a track of whether the resolution will be nullable. In this example, we follow B to Animal, and then Animal to ?{|name: string|}.

Then, we:
  1. Replace the `B` in `+greet: (animal: B) => void;` with `?Animal`,
  2. Pretend that `Animal = {|name: string|}`.

Why do we make all type alias RHSs required?
 2. This design is simpler than managing nullability in both the type alias usage, and the type alias RHS.
 3. What does it mean for a C++ struct, which is what this type alias RHS will generate, to be nullable? ¯\_(ツ)_/¯. Nullability is a concept that only makes sense when talking about instances (i.e: usages) of the C++ structs. Hence, it's better to manage nullability within the actual TypeAliasTypeAnnotation nodes, and not the associated ObjectTypeAnnotations.

## Other Changes
- Whenever we use the `Animal` type-alias, the e2e jest tests validate that the type alias exists in the module schema.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23225934

fbshipit-source-id: 8316dea2ec6e2d50cad90e178963c6264044f7b7
2020-09-29 14:39:39 -07:00
Ramanpreet Nara aba4e87873 Add unit tests to validate module parser
Summary:
## Test Structure
- Parameter Parsing
  - For type in [optional, nullable, optional and nullable, required]:
    - Can parse Primitives
    - Can parse Object
    - Can parse Arrays
      - Can parse primitive element types
      - Can parse Object element types
      - Can parse Array element types
      - Can parse Reserved Type element types
      - Can parse Type alias element types
      - Can parse Object Literals
    - Can parse Function
    - Can parse Reserved Types (e.g: RootTag)
    - Can parse Type alias
    - Can parse Object Literals
      - For prop type in [optional, nullable, optional and nullable, required]:
        - Can parse primitive prop types
        - Can parse Object prop types
        - Can parse Array prop types
        - Can parse Reserved Type prop types
        - Can parse Type alias prop types
        - Can parse Object Literal prop types
- Return Parsing
  - For type in [nullable, required]:
    - Can parse Promises
    - Can parse Primitives
    - Can parse Object
    - Can parse Arrays
      - Can parse primitive element types
      - Can parse Object element types
      - Can parse Array element types
      - Can parse Reserved Type element types
      - Can parse Type alias element types
      - Can parse Object Literals
    - Can parse Function
    - Can parse Reserved Types (e.g: RootTag)
    - Can parse Type aliases
    - Can parse Object Literals
      - For prop type in [optional, nullable, optional and nullable, required]:
        - Can parse primitive prop types
        - Can parse Object prop types
        - Can parse Array prop types
        - Can parse Reserved Type prop types
        - Can parse Type alias prop types
        - Can parse Object Literal prop types

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23089925

fbshipit-source-id: 73c3b1ef33b402265c14f0ac9e364414a5d54dca
2020-09-29 14:39:38 -07:00
Ramanpreet Nara 2d19037041 Rewrite Flow module parser
Summary:
This diff:
1. Simplifies the NativeModule schema Flow types.
2. Simplifies the NativeModule Flow parser, to accomodate the modified schema, and to reduce code duplication.

**Notes:**
- If the parser detects an unrecognized type within the context of parsing an Array's element type, it'll omit the `elementType` property of the `ArrayTypeAnnotation`. Details: T72031674. **Rationale:** Basically, when an array element type is supported, we use it in our generators. When it's unsupported, we ignore it. In the unsupported case, there's no point in trying to parse the Array element type, which is why I decided to omit the `elementType` property. Ideally, our NativeModule specs would never use unsupported types, in any context. This would allow us to always parse and use the elementType. However, that seems like a it could be a hefty migration: we have > 400 specs. Since, this isn't a battle we need to fight right now, I left a TODO at the relevant lines instead.
- The legacy codegen would generate structs for each object literal type in the file. In this re-implementation of the parser, I only insert into the aliases array when we detect a usage of a type-alias to an ObjectLiteral type annotation. With this decision, we won't be able to generate these unnecessary structs. This is good because we get rid of dead code. It's bad because it might make our migration to this codegen bit more difficult.

[WARNING] This diff produces flow failures that will be addressed in subsequent diffs.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D23201387

fbshipit-source-id: 55ce0df925a8bae0e7d5bb2a9b63167607eba461
2020-09-29 14:39:38 -07:00
Ramanpreet Nara f9ea52574e Cleanup buildMethodSchema and introduce nullable methods
Summary:
## Changes
- Started doing cleanup under `/parsers/flow/modules/methods.js`
- Rename `NativeModuleMethodTypeShape` -> `NativeModulePropertyShape`
- Moved optional property from `FunctionTypeAnnotation` to the `NativeModulePropertyShape`
- Introduced a nullable property inside what was once `FunctionTypeAnnotation`.

Changelog: [Internal]

Reviewed By: PeteTheHeat

Differential Revision: D23146050

fbshipit-source-id: 2fe97bb9c0736242682133e4923131a54bbea54b
2020-09-29 14:39:38 -07:00