From 3a75b376cc3c44f9693d99b33046cf76d6fafa89 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Thu, 15 Oct 2020 22:50:19 -0700 Subject: [PATCH] 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)?('moduleName')`. Hence, the shape looks like: ``` type NativeModuleSchema = { type: 'NativeModule', aliases: NativeModuleAliasMap, // nothing new spec: NativeModuleSpec, moduleNames: $ReadOnlyArray } type NativeModuleSpec = { properties: $ReadOnlyArray<...>, } ``` ## Major Notes 1. We now parse the NativeModule requires (TurboModuleRegistry.get(Enforcing)? 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 --- .../react-native-codegen/src/CodegenSchema.js | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index a341f1757d3..84a2d5e2fd9 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -244,24 +244,29 @@ export type ComponentShape = $ReadOnly<{| |}>; export type SchemaType = $ReadOnly<{| - modules: $ReadOnly<{ - [module: string]: $ReadOnly<{| - components?: $ReadOnly<{[component: string]: ComponentShape, ...}>, - nativeModules?: $ReadOnly<{ - [nativeModule: string]: NativeModuleSchema, - ..., - }>, - |}>, - ..., - }>, + modules: $ReadOnly<{| + [moduleName: string]: ComponentSchema | NativeModuleSchema, + |}>, +|}>; + +export type ComponentSchema = $ReadOnly<{| + type: 'Component', + components: $ReadOnly<{| + [componentName: string]: ComponentShape, + |}>, |}>; /** * NativeModule Types */ export type NativeModuleSchema = $ReadOnly<{| - // We only support aliases to Objects + type: 'NativeModule', aliases: NativeModuleAliasMap, + spec: NativeModuleSpec, + moduleNames: $ReadOnlyArray, +|}>; + +type NativeModuleSpec = $ReadOnly<{| properties: $ReadOnlyArray, |}>;