@react-native/codegen 0.72.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/lib/CodegenSchema.js +11 -0
- package/lib/CodegenSchema.js.flow +351 -0
- package/lib/SchemaValidator.js +54 -0
- package/lib/SchemaValidator.js.flow +67 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js +50 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +49 -0
- package/lib/cli/combine/combine-js-to-schema.js +110 -0
- package/lib/cli/combine/combine-js-to-schema.js.flow +48 -0
- package/lib/cli/combine/combine-utils.js +118 -0
- package/lib/cli/combine/combine-utils.js.flow +85 -0
- package/lib/cli/generators/generate-all.js +65 -0
- package/lib/cli/generators/generate-all.js.flow +66 -0
- package/lib/cli/parser/parser-cli.js +55 -0
- package/lib/cli/parser/parser-cli.js.flow +18 -0
- package/lib/cli/parser/parser.js +35 -0
- package/lib/cli/parser/parser.js.flow +37 -0
- package/lib/cli/parser/parser.sh +15 -0
- package/lib/generators/RNCodegen.js +207 -0
- package/lib/generators/RNCodegen.js.flow +284 -0
- package/lib/generators/Utils.js +31 -0
- package/lib/generators/Utils.js.flow +33 -0
- package/lib/generators/__test_fixtures__/fixtures.js +79 -0
- package/lib/generators/__test_fixtures__/fixtures.js.flow +82 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js +217 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +304 -0
- package/lib/generators/components/CppHelpers.js +188 -0
- package/lib/generators/components/CppHelpers.js.flow +228 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js +75 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js.flow +95 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js +327 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js.flow +418 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +199 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +273 -0
- package/lib/generators/components/GenerateEventEmitterH.js +224 -0
- package/lib/generators/components/GenerateEventEmitterH.js.flow +315 -0
- package/lib/generators/components/GeneratePropsCpp.js +126 -0
- package/lib/generators/components/GeneratePropsCpp.js.flow +161 -0
- package/lib/generators/components/GeneratePropsH.js +606 -0
- package/lib/generators/components/GeneratePropsH.js.flow +778 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +287 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +348 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +237 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +288 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +157 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +187 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js +66 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +80 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +273 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +296 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js +73 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js.flow +95 -0
- package/lib/generators/components/GenerateShadowNodeH.js +91 -0
- package/lib/generators/components/GenerateShadowNodeH.js.flow +124 -0
- package/lib/generators/components/GenerateStateCpp.js +70 -0
- package/lib/generators/components/GenerateStateCpp.js.flow +92 -0
- package/lib/generators/components/GenerateStateH.js +93 -0
- package/lib/generators/components/GenerateStateH.js.flow +111 -0
- package/lib/generators/components/GenerateTests.js +165 -0
- package/lib/generators/components/GenerateTests.js.flow +219 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +91 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +107 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +89 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +105 -0
- package/lib/generators/components/GenerateViewConfigJs.js +410 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +484 -0
- package/lib/generators/components/JavaHelpers.js +87 -0
- package/lib/generators/components/JavaHelpers.js.flow +119 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +1641 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +1672 -0
- package/lib/generators/modules/GenerateModuleCpp.js +299 -0
- package/lib/generators/modules/GenerateModuleCpp.js.flow +278 -0
- package/lib/generators/modules/GenerateModuleH.js +373 -0
- package/lib/generators/modules/GenerateModuleH.js.flow +355 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js +571 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +553 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js +505 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +523 -0
- package/lib/generators/modules/GenerateModuleJniH.js +138 -0
- package/lib/generators/modules/GenerateModuleJniH.js.flow +148 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +262 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +208 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js.flow +32 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +337 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +288 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +330 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +279 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js.flow +35 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +185 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +219 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +529 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +510 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +96 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +121 -0
- package/lib/generators/modules/Utils.js +34 -0
- package/lib/generators/modules/Utils.js.flow +53 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +1658 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +1669 -0
- package/lib/parsers/consistency/compareSnaps.js +84 -0
- package/lib/parsers/error-utils.js +284 -0
- package/lib/parsers/error-utils.js.flow +295 -0
- package/lib/parsers/errors.js +350 -0
- package/lib/parsers/errors.js.flow +439 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js +583 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js.flow +600 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +1001 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +1016 -0
- package/lib/parsers/flow/components/commands.js +104 -0
- package/lib/parsers/flow/components/commands.js.flow +123 -0
- package/lib/parsers/flow/components/componentsUtils.js +446 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +496 -0
- package/lib/parsers/flow/components/events.js +233 -0
- package/lib/parsers/flow/components/events.js.flow +262 -0
- package/lib/parsers/flow/components/extends.js +52 -0
- package/lib/parsers/flow/components/extends.js.flow +66 -0
- package/lib/parsers/flow/components/index.js +267 -0
- package/lib/parsers/flow/components/index.js.flow +226 -0
- package/lib/parsers/flow/components/options.js +72 -0
- package/lib/parsers/flow/components/options.js.flow +87 -0
- package/lib/parsers/flow/components/props.js +47 -0
- package/lib/parsers/flow/components/props.js.flow +60 -0
- package/lib/parsers/flow/components/schema.js +106 -0
- package/lib/parsers/flow/components/schema.js.flow +62 -0
- package/lib/parsers/flow/index.js +80 -0
- package/lib/parsers/flow/index.js.flow +85 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +215 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +223 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +724 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +747 -0
- package/lib/parsers/flow/modules/index.js +528 -0
- package/lib/parsers/flow/modules/index.js.flow +420 -0
- package/lib/parsers/flow/parser.js +109 -0
- package/lib/parsers/flow/parser.js.flow +83 -0
- package/lib/parsers/flow/utils.js +108 -0
- package/lib/parsers/flow/utils.js.flow +123 -0
- package/lib/parsers/parser.js +11 -0
- package/lib/parsers/parser.js.flow +70 -0
- package/lib/parsers/parserMock.js +96 -0
- package/lib/parsers/parserMock.js.flow +68 -0
- package/lib/parsers/parsers-commons.js +448 -0
- package/lib/parsers/parsers-commons.js.flow +447 -0
- package/lib/parsers/parsers-primitives.js +387 -0
- package/lib/parsers/parsers-primitives.js.flow +383 -0
- package/lib/parsers/parsers-utils.js +18 -0
- package/lib/parsers/parsers-utils.js.flow +19 -0
- package/lib/parsers/schema/index.js +23 -0
- package/lib/parsers/schema/index.js.flow +26 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js +489 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js.flow +505 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +1151 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +1168 -0
- package/lib/parsers/typescript/components/commands.js +132 -0
- package/lib/parsers/typescript/components/commands.js.flow +151 -0
- package/lib/parsers/typescript/components/componentsUtils.js +471 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +521 -0
- package/lib/parsers/typescript/components/events.js +240 -0
- package/lib/parsers/typescript/components/events.js.flow +262 -0
- package/lib/parsers/typescript/components/extends.js +88 -0
- package/lib/parsers/typescript/components/extends.js.flow +103 -0
- package/lib/parsers/typescript/components/index.js +277 -0
- package/lib/parsers/typescript/components/index.js.flow +239 -0
- package/lib/parsers/typescript/components/options.js +72 -0
- package/lib/parsers/typescript/components/options.js.flow +87 -0
- package/lib/parsers/typescript/components/props.js +39 -0
- package/lib/parsers/typescript/components/props.js.flow +48 -0
- package/lib/parsers/typescript/components/schema.js +106 -0
- package/lib/parsers/typescript/components/schema.js.flow +62 -0
- package/lib/parsers/typescript/index.js +85 -0
- package/lib/parsers/typescript/index.js.flow +94 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +160 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +167 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +701 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +727 -0
- package/lib/parsers/typescript/modules/index.js +543 -0
- package/lib/parsers/typescript/modules/index.js.flow +435 -0
- package/lib/parsers/typescript/parseTopLevelType.js +203 -0
- package/lib/parsers/typescript/parseTopLevelType.js.flow +243 -0
- package/lib/parsers/typescript/parser.js +105 -0
- package/lib/parsers/typescript/parser.js.flow +87 -0
- package/lib/parsers/typescript/utils.js +101 -0
- package/lib/parsers/typescript/utils.js.flow +115 -0
- package/lib/parsers/utils.js +273 -0
- package/lib/parsers/utils.js.flow +266 -0
- package/package.json +45 -0
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# @react-native/codegen
|
|
2
|
+
|
|
3
|
+
[![Version][version-badge]][package]
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
yarn add --dev @react-native/codegen
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
*Note: We're using `yarn` to install deps. Feel free to change commands to use `npm` 3+ and `npx` if you like*
|
|
12
|
+
|
|
13
|
+
[version-badge]: https://img.shields.io/npm/v/@react-native/codegen?style=flat-square
|
|
14
|
+
[package]: https://www.npmjs.com/package/@react-native/codegen
|
|
15
|
+
|
|
16
|
+
## Testing
|
|
17
|
+
|
|
18
|
+
To run the tests in this package, run the following commands from the react Native root folder:
|
|
19
|
+
|
|
20
|
+
1. `yarn` to install the dependencies. You just need to run this once
|
|
21
|
+
2. `yarn jest react-native-codegen`.
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
export type PlatformType = 'iOS' | 'android';
|
|
14
|
+
|
|
15
|
+
export type SchemaType = $ReadOnly<{
|
|
16
|
+
modules: $ReadOnly<{
|
|
17
|
+
[hasteModuleName: string]: ComponentSchema | NativeModuleSchema,
|
|
18
|
+
}>,
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Component Type Annotations
|
|
23
|
+
*/
|
|
24
|
+
export type DoubleTypeAnnotation = $ReadOnly<{
|
|
25
|
+
type: 'DoubleTypeAnnotation',
|
|
26
|
+
}>;
|
|
27
|
+
|
|
28
|
+
export type FloatTypeAnnotation = $ReadOnly<{
|
|
29
|
+
type: 'FloatTypeAnnotation',
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
export type BooleanTypeAnnotation = $ReadOnly<{
|
|
33
|
+
type: 'BooleanTypeAnnotation',
|
|
34
|
+
}>;
|
|
35
|
+
|
|
36
|
+
export type Int32TypeAnnotation = $ReadOnly<{
|
|
37
|
+
type: 'Int32TypeAnnotation',
|
|
38
|
+
}>;
|
|
39
|
+
|
|
40
|
+
export type StringTypeAnnotation = $ReadOnly<{
|
|
41
|
+
type: 'StringTypeAnnotation',
|
|
42
|
+
}>;
|
|
43
|
+
|
|
44
|
+
export type StringEnumTypeAnnotation = $ReadOnly<{
|
|
45
|
+
type: 'StringEnumTypeAnnotation',
|
|
46
|
+
options: $ReadOnlyArray<string>,
|
|
47
|
+
}>;
|
|
48
|
+
|
|
49
|
+
export type VoidTypeAnnotation = $ReadOnly<{
|
|
50
|
+
type: 'VoidTypeAnnotation',
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
export type ObjectTypeAnnotation<+T> = $ReadOnly<{
|
|
54
|
+
type: 'ObjectTypeAnnotation',
|
|
55
|
+
properties: $ReadOnlyArray<NamedShape<T>>,
|
|
56
|
+
}>;
|
|
57
|
+
|
|
58
|
+
type FunctionTypeAnnotation<+P, +R> = $ReadOnly<{
|
|
59
|
+
type: 'FunctionTypeAnnotation',
|
|
60
|
+
params: $ReadOnlyArray<NamedShape<P>>,
|
|
61
|
+
returnTypeAnnotation: R,
|
|
62
|
+
}>;
|
|
63
|
+
|
|
64
|
+
export type NamedShape<+T> = $ReadOnly<{
|
|
65
|
+
name: string,
|
|
66
|
+
optional: boolean,
|
|
67
|
+
typeAnnotation: T,
|
|
68
|
+
}>;
|
|
69
|
+
|
|
70
|
+
export type ComponentSchema = $ReadOnly<{
|
|
71
|
+
type: 'Component',
|
|
72
|
+
components: $ReadOnly<{
|
|
73
|
+
[componentName: string]: ComponentShape,
|
|
74
|
+
}>,
|
|
75
|
+
}>;
|
|
76
|
+
|
|
77
|
+
export type ComponentShape = $ReadOnly<{
|
|
78
|
+
...OptionsShape,
|
|
79
|
+
extendsProps: $ReadOnlyArray<ExtendsPropsShape>,
|
|
80
|
+
events: $ReadOnlyArray<EventTypeShape>,
|
|
81
|
+
props: $ReadOnlyArray<NamedShape<PropTypeAnnotation>>,
|
|
82
|
+
commands: $ReadOnlyArray<NamedShape<CommandTypeAnnotation>>,
|
|
83
|
+
}>;
|
|
84
|
+
|
|
85
|
+
export type OptionsShape = $ReadOnly<{
|
|
86
|
+
interfaceOnly?: boolean,
|
|
87
|
+
|
|
88
|
+
// Use for components with no current paper rename in progress
|
|
89
|
+
// Does not check for new name
|
|
90
|
+
paperComponentName?: string,
|
|
91
|
+
|
|
92
|
+
// Use for components that are not used on other platforms.
|
|
93
|
+
excludedPlatforms?: $ReadOnlyArray<PlatformType>,
|
|
94
|
+
|
|
95
|
+
// Use for components currently being renamed in paper
|
|
96
|
+
// Will use new name if it is available and fallback to this name
|
|
97
|
+
paperComponentNameDeprecated?: string,
|
|
98
|
+
}>;
|
|
99
|
+
|
|
100
|
+
export type ExtendsPropsShape = $ReadOnly<{
|
|
101
|
+
type: 'ReactNativeBuiltInType',
|
|
102
|
+
knownTypeName: 'ReactNativeCoreViewProps',
|
|
103
|
+
}>;
|
|
104
|
+
|
|
105
|
+
export type EventTypeShape = $ReadOnly<{
|
|
106
|
+
name: string,
|
|
107
|
+
bubblingType: 'direct' | 'bubble',
|
|
108
|
+
optional: boolean,
|
|
109
|
+
paperTopLevelNameDeprecated?: string,
|
|
110
|
+
typeAnnotation: $ReadOnly<{
|
|
111
|
+
type: 'EventTypeAnnotation',
|
|
112
|
+
argument?: ObjectTypeAnnotation<EventTypeAnnotation>,
|
|
113
|
+
}>,
|
|
114
|
+
}>;
|
|
115
|
+
|
|
116
|
+
export type EventTypeAnnotation =
|
|
117
|
+
| BooleanTypeAnnotation
|
|
118
|
+
| StringTypeAnnotation
|
|
119
|
+
| DoubleTypeAnnotation
|
|
120
|
+
| FloatTypeAnnotation
|
|
121
|
+
| Int32TypeAnnotation
|
|
122
|
+
| StringEnumTypeAnnotation
|
|
123
|
+
| ObjectTypeAnnotation<EventTypeAnnotation>;
|
|
124
|
+
|
|
125
|
+
export type PropTypeAnnotation =
|
|
126
|
+
| $ReadOnly<{
|
|
127
|
+
type: 'BooleanTypeAnnotation',
|
|
128
|
+
default: boolean | null,
|
|
129
|
+
}>
|
|
130
|
+
| $ReadOnly<{
|
|
131
|
+
type: 'StringTypeAnnotation',
|
|
132
|
+
default: string | null,
|
|
133
|
+
}>
|
|
134
|
+
| $ReadOnly<{
|
|
135
|
+
type: 'DoubleTypeAnnotation',
|
|
136
|
+
default: number,
|
|
137
|
+
}>
|
|
138
|
+
| $ReadOnly<{
|
|
139
|
+
type: 'FloatTypeAnnotation',
|
|
140
|
+
default: number | null,
|
|
141
|
+
}>
|
|
142
|
+
| $ReadOnly<{
|
|
143
|
+
type: 'Int32TypeAnnotation',
|
|
144
|
+
default: number,
|
|
145
|
+
}>
|
|
146
|
+
| $ReadOnly<{
|
|
147
|
+
type: 'StringEnumTypeAnnotation',
|
|
148
|
+
default: string,
|
|
149
|
+
options: $ReadOnlyArray<string>,
|
|
150
|
+
}>
|
|
151
|
+
| $ReadOnly<{
|
|
152
|
+
type: 'Int32EnumTypeAnnotation',
|
|
153
|
+
default: number,
|
|
154
|
+
options: $ReadOnlyArray<number>,
|
|
155
|
+
}>
|
|
156
|
+
| ReservedPropTypeAnnotation
|
|
157
|
+
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
158
|
+
| $ReadOnly<{
|
|
159
|
+
type: 'ArrayTypeAnnotation',
|
|
160
|
+
elementType:
|
|
161
|
+
| BooleanTypeAnnotation
|
|
162
|
+
| StringTypeAnnotation
|
|
163
|
+
| DoubleTypeAnnotation
|
|
164
|
+
| FloatTypeAnnotation
|
|
165
|
+
| Int32TypeAnnotation
|
|
166
|
+
| $ReadOnly<{
|
|
167
|
+
type: 'StringEnumTypeAnnotation',
|
|
168
|
+
default: string,
|
|
169
|
+
options: $ReadOnlyArray<string>,
|
|
170
|
+
}>
|
|
171
|
+
| ObjectTypeAnnotation<PropTypeAnnotation>
|
|
172
|
+
| ReservedPropTypeAnnotation
|
|
173
|
+
| $ReadOnly<{
|
|
174
|
+
type: 'ArrayTypeAnnotation',
|
|
175
|
+
elementType: ObjectTypeAnnotation<PropTypeAnnotation>,
|
|
176
|
+
}>,
|
|
177
|
+
}>;
|
|
178
|
+
|
|
179
|
+
export type ReservedPropTypeAnnotation = $ReadOnly<{
|
|
180
|
+
type: 'ReservedPropTypeAnnotation',
|
|
181
|
+
name:
|
|
182
|
+
| 'ColorPrimitive'
|
|
183
|
+
| 'ImageSourcePrimitive'
|
|
184
|
+
| 'PointPrimitive'
|
|
185
|
+
| 'EdgeInsetsPrimitive'
|
|
186
|
+
| 'ImageRequestPrimitive',
|
|
187
|
+
}>;
|
|
188
|
+
|
|
189
|
+
export type CommandTypeAnnotation = FunctionTypeAnnotation<
|
|
190
|
+
CommandParamTypeAnnotation,
|
|
191
|
+
VoidTypeAnnotation,
|
|
192
|
+
>;
|
|
193
|
+
|
|
194
|
+
export type CommandParamTypeAnnotation =
|
|
195
|
+
| ReservedTypeAnnotation
|
|
196
|
+
| BooleanTypeAnnotation
|
|
197
|
+
| Int32TypeAnnotation
|
|
198
|
+
| DoubleTypeAnnotation
|
|
199
|
+
| FloatTypeAnnotation
|
|
200
|
+
| StringTypeAnnotation;
|
|
201
|
+
|
|
202
|
+
export type ReservedTypeAnnotation = $ReadOnly<{
|
|
203
|
+
type: 'ReservedTypeAnnotation',
|
|
204
|
+
name: 'RootTag', // Union with more custom types.
|
|
205
|
+
}>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* NativeModule Types
|
|
209
|
+
*/
|
|
210
|
+
export type Nullable<+T: NativeModuleTypeAnnotation> =
|
|
211
|
+
| NullableTypeAnnotation<T>
|
|
212
|
+
| T;
|
|
213
|
+
|
|
214
|
+
export type NullableTypeAnnotation<+T: NativeModuleTypeAnnotation> = $ReadOnly<{
|
|
215
|
+
type: 'NullableTypeAnnotation',
|
|
216
|
+
typeAnnotation: T,
|
|
217
|
+
}>;
|
|
218
|
+
|
|
219
|
+
export type NativeModuleSchema = $ReadOnly<{
|
|
220
|
+
type: 'NativeModule',
|
|
221
|
+
aliases: NativeModuleAliasMap,
|
|
222
|
+
spec: NativeModuleSpec,
|
|
223
|
+
moduleName: string,
|
|
224
|
+
// Use for modules that are not used on other platforms.
|
|
225
|
+
// TODO: It's clearer to define `restrictedToPlatforms` instead, but
|
|
226
|
+
// `excludedPlatforms` is used here to be consistent with ComponentSchema.
|
|
227
|
+
excludedPlatforms?: $ReadOnlyArray<PlatformType>,
|
|
228
|
+
}>;
|
|
229
|
+
|
|
230
|
+
type NativeModuleSpec = $ReadOnly<{
|
|
231
|
+
properties: $ReadOnlyArray<NativeModulePropertyShape>,
|
|
232
|
+
}>;
|
|
233
|
+
|
|
234
|
+
export type NativeModulePropertyShape = NamedShape<
|
|
235
|
+
Nullable<NativeModuleFunctionTypeAnnotation>,
|
|
236
|
+
>;
|
|
237
|
+
|
|
238
|
+
export type NativeModuleAliasMap = $ReadOnly<{
|
|
239
|
+
[aliasName: string]: NativeModuleObjectTypeAnnotation,
|
|
240
|
+
}>;
|
|
241
|
+
|
|
242
|
+
export type NativeModuleFunctionTypeAnnotation = FunctionTypeAnnotation<
|
|
243
|
+
Nullable<NativeModuleParamTypeAnnotation>,
|
|
244
|
+
Nullable<NativeModuleReturnTypeAnnotation>,
|
|
245
|
+
>;
|
|
246
|
+
|
|
247
|
+
export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation<
|
|
248
|
+
Nullable<NativeModuleBaseTypeAnnotation>,
|
|
249
|
+
>;
|
|
250
|
+
|
|
251
|
+
export type NativeModuleArrayTypeAnnotation<
|
|
252
|
+
+T: Nullable<NativeModuleBaseTypeAnnotation>,
|
|
253
|
+
> = $ReadOnly<{
|
|
254
|
+
type: 'ArrayTypeAnnotation',
|
|
255
|
+
/**
|
|
256
|
+
* TODO(T72031674): Migrate all our NativeModule specs to not use
|
|
257
|
+
* invalid Array ElementTypes. Then, make the elementType required.
|
|
258
|
+
*/
|
|
259
|
+
elementType?: T,
|
|
260
|
+
}>;
|
|
261
|
+
|
|
262
|
+
export type NativeModuleStringTypeAnnotation = $ReadOnly<{
|
|
263
|
+
type: 'StringTypeAnnotation',
|
|
264
|
+
}>;
|
|
265
|
+
|
|
266
|
+
export type NativeModuleNumberTypeAnnotation = $ReadOnly<{
|
|
267
|
+
type: 'NumberTypeAnnotation',
|
|
268
|
+
}>;
|
|
269
|
+
|
|
270
|
+
export type NativeModuleInt32TypeAnnotation = $ReadOnly<{
|
|
271
|
+
type: 'Int32TypeAnnotation',
|
|
272
|
+
}>;
|
|
273
|
+
|
|
274
|
+
export type NativeModuleDoubleTypeAnnotation = $ReadOnly<{
|
|
275
|
+
type: 'DoubleTypeAnnotation',
|
|
276
|
+
}>;
|
|
277
|
+
|
|
278
|
+
export type NativeModuleFloatTypeAnnotation = $ReadOnly<{
|
|
279
|
+
type: 'FloatTypeAnnotation',
|
|
280
|
+
}>;
|
|
281
|
+
|
|
282
|
+
export type NativeModuleBooleanTypeAnnotation = $ReadOnly<{
|
|
283
|
+
type: 'BooleanTypeAnnotation',
|
|
284
|
+
}>;
|
|
285
|
+
|
|
286
|
+
export type NativeModuleEnumDeclaration = $ReadOnly<{
|
|
287
|
+
type: 'EnumDeclaration',
|
|
288
|
+
memberType: 'NumberTypeAnnotation' | 'StringTypeAnnotation',
|
|
289
|
+
}>;
|
|
290
|
+
|
|
291
|
+
export type NativeModuleGenericObjectTypeAnnotation = $ReadOnly<{
|
|
292
|
+
type: 'GenericObjectTypeAnnotation',
|
|
293
|
+
}>;
|
|
294
|
+
|
|
295
|
+
export type NativeModuleTypeAliasTypeAnnotation = $ReadOnly<{
|
|
296
|
+
type: 'TypeAliasTypeAnnotation',
|
|
297
|
+
name: string,
|
|
298
|
+
}>;
|
|
299
|
+
|
|
300
|
+
export type NativeModulePromiseTypeAnnotation = $ReadOnly<{
|
|
301
|
+
type: 'PromiseTypeAnnotation',
|
|
302
|
+
elementType?: Nullable<NativeModuleBaseTypeAnnotation>,
|
|
303
|
+
}>;
|
|
304
|
+
|
|
305
|
+
export type UnionTypeAnnotationMemberType =
|
|
306
|
+
| 'NumberTypeAnnotation'
|
|
307
|
+
| 'ObjectTypeAnnotation'
|
|
308
|
+
| 'StringTypeAnnotation';
|
|
309
|
+
|
|
310
|
+
export type NativeModuleUnionTypeAnnotation = $ReadOnly<{
|
|
311
|
+
type: 'UnionTypeAnnotation',
|
|
312
|
+
memberType: UnionTypeAnnotationMemberType,
|
|
313
|
+
}>;
|
|
314
|
+
|
|
315
|
+
export type NativeModuleMixedTypeAnnotation = $ReadOnly<{
|
|
316
|
+
type: 'MixedTypeAnnotation',
|
|
317
|
+
}>;
|
|
318
|
+
|
|
319
|
+
export type NativeModuleBaseTypeAnnotation =
|
|
320
|
+
| NativeModuleStringTypeAnnotation
|
|
321
|
+
| NativeModuleNumberTypeAnnotation
|
|
322
|
+
| NativeModuleInt32TypeAnnotation
|
|
323
|
+
| NativeModuleDoubleTypeAnnotation
|
|
324
|
+
| NativeModuleFloatTypeAnnotation
|
|
325
|
+
| NativeModuleBooleanTypeAnnotation
|
|
326
|
+
| NativeModuleEnumDeclaration
|
|
327
|
+
| NativeModuleGenericObjectTypeAnnotation
|
|
328
|
+
| ReservedTypeAnnotation
|
|
329
|
+
| NativeModuleTypeAliasTypeAnnotation
|
|
330
|
+
| NativeModuleArrayTypeAnnotation<Nullable<NativeModuleBaseTypeAnnotation>>
|
|
331
|
+
| NativeModuleObjectTypeAnnotation
|
|
332
|
+
| NativeModuleUnionTypeAnnotation
|
|
333
|
+
| NativeModuleMixedTypeAnnotation;
|
|
334
|
+
|
|
335
|
+
export type NativeModuleParamTypeAnnotation =
|
|
336
|
+
| NativeModuleBaseTypeAnnotation
|
|
337
|
+
| NativeModuleParamOnlyTypeAnnotation;
|
|
338
|
+
|
|
339
|
+
export type NativeModuleReturnTypeAnnotation =
|
|
340
|
+
| NativeModuleBaseTypeAnnotation
|
|
341
|
+
| NativeModuleReturnOnlyTypeAnnotation;
|
|
342
|
+
|
|
343
|
+
export type NativeModuleTypeAnnotation =
|
|
344
|
+
| NativeModuleBaseTypeAnnotation
|
|
345
|
+
| NativeModuleParamOnlyTypeAnnotation
|
|
346
|
+
| NativeModuleReturnOnlyTypeAnnotation;
|
|
347
|
+
|
|
348
|
+
type NativeModuleParamOnlyTypeAnnotation = NativeModuleFunctionTypeAnnotation;
|
|
349
|
+
type NativeModuleReturnOnlyTypeAnnotation =
|
|
350
|
+
| NativeModulePromiseTypeAnnotation
|
|
351
|
+
| VoidTypeAnnotation;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const nullthrows = require('nullthrows');
|
|
14
|
+
function getErrors(schema) {
|
|
15
|
+
const errors = new Set();
|
|
16
|
+
|
|
17
|
+
// Map of component name -> Array of module names
|
|
18
|
+
const componentModules = new Map();
|
|
19
|
+
Object.keys(schema.modules).forEach(moduleName => {
|
|
20
|
+
const module = schema.modules[moduleName];
|
|
21
|
+
if (module.components == null) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
Object.keys(module.components).forEach(componentName => {
|
|
25
|
+
if (module.components == null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!componentModules.has(componentName)) {
|
|
29
|
+
componentModules.set(componentName, []);
|
|
30
|
+
}
|
|
31
|
+
nullthrows(componentModules.get(componentName)).push(moduleName);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
componentModules.forEach((modules, componentName) => {
|
|
35
|
+
if (modules.length > 1) {
|
|
36
|
+
errors.add(
|
|
37
|
+
`Duplicate components found with name ${componentName}. Found in modules ${modules.join(
|
|
38
|
+
', ',
|
|
39
|
+
)}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return Array.from(errors).sort();
|
|
44
|
+
}
|
|
45
|
+
function validate(schema) {
|
|
46
|
+
const errors = getErrors(schema);
|
|
47
|
+
if (errors.length !== 0) {
|
|
48
|
+
throw new Error('Errors found validating schema:\n' + errors.join('\n'));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
module.exports = {
|
|
52
|
+
getErrors,
|
|
53
|
+
validate,
|
|
54
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
const nullthrows = require('nullthrows');
|
|
14
|
+
|
|
15
|
+
import type {SchemaType} from './CodegenSchema';
|
|
16
|
+
|
|
17
|
+
function getErrors(schema: SchemaType): $ReadOnlyArray<string> {
|
|
18
|
+
const errors = new Set<string>();
|
|
19
|
+
|
|
20
|
+
// Map of component name -> Array of module names
|
|
21
|
+
const componentModules: Map<string, Array<string>> = new Map();
|
|
22
|
+
|
|
23
|
+
Object.keys(schema.modules).forEach(moduleName => {
|
|
24
|
+
const module = schema.modules[moduleName];
|
|
25
|
+
|
|
26
|
+
if (module.components == null) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Object.keys(module.components).forEach(componentName => {
|
|
31
|
+
if (module.components == null) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!componentModules.has(componentName)) {
|
|
36
|
+
componentModules.set(componentName, []);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
nullthrows(componentModules.get(componentName)).push(moduleName);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
componentModules.forEach((modules, componentName) => {
|
|
44
|
+
if (modules.length > 1) {
|
|
45
|
+
errors.add(
|
|
46
|
+
`Duplicate components found with name ${componentName}. Found in modules ${modules.join(
|
|
47
|
+
', ',
|
|
48
|
+
)}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return Array.from(errors).sort();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function validate(schema: SchemaType) {
|
|
57
|
+
const errors = getErrors(schema);
|
|
58
|
+
|
|
59
|
+
if (errors.length !== 0) {
|
|
60
|
+
throw new Error('Errors found validating schema:\n' + errors.join('\n'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = {
|
|
65
|
+
getErrors,
|
|
66
|
+
validate,
|
|
67
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const combine = require('./combine-js-to-schema');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const glob = require('glob');
|
|
17
|
+
const _require = require('./combine-utils'),
|
|
18
|
+
parseArgs = _require.parseArgs,
|
|
19
|
+
filterJSFile = _require.filterJSFile;
|
|
20
|
+
const _parseArgs = parseArgs(process.argv),
|
|
21
|
+
platform = _parseArgs.platform,
|
|
22
|
+
outfile = _parseArgs.outfile,
|
|
23
|
+
fileList = _parseArgs.fileList;
|
|
24
|
+
const allFiles = [];
|
|
25
|
+
fileList.forEach(file => {
|
|
26
|
+
if (fs.lstatSync(file).isDirectory()) {
|
|
27
|
+
const dirFiles = glob
|
|
28
|
+
.sync(`${file}/**/*.{js,ts,tsx}`, {
|
|
29
|
+
nodir: true,
|
|
30
|
+
})
|
|
31
|
+
.filter(element => filterJSFile(element, platform));
|
|
32
|
+
allFiles.push(...dirFiles);
|
|
33
|
+
} else if (filterJSFile(file)) {
|
|
34
|
+
allFiles.push(file);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const combined = combine(allFiles);
|
|
38
|
+
|
|
39
|
+
// Warn users if there is no modules to process
|
|
40
|
+
if (Object.keys(combined.modules).length === 0) {
|
|
41
|
+
console.error(
|
|
42
|
+
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.',
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const formattedSchema = JSON.stringify(combined, null, 2);
|
|
46
|
+
if (outfile != null) {
|
|
47
|
+
fs.writeFileSync(outfile, formattedSchema);
|
|
48
|
+
} else {
|
|
49
|
+
console.log(formattedSchema);
|
|
50
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall react_native
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const combine = require('./combine-js-to-schema');
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const glob = require('glob');
|
|
17
|
+
const {parseArgs, filterJSFile} = require('./combine-utils');
|
|
18
|
+
|
|
19
|
+
const {platform, outfile, fileList} = parseArgs(process.argv);
|
|
20
|
+
|
|
21
|
+
const allFiles = [];
|
|
22
|
+
fileList.forEach(file => {
|
|
23
|
+
if (fs.lstatSync(file).isDirectory()) {
|
|
24
|
+
const dirFiles = glob
|
|
25
|
+
.sync(`${file}/**/*.{js,ts,tsx}`, {
|
|
26
|
+
nodir: true,
|
|
27
|
+
})
|
|
28
|
+
.filter(element => filterJSFile(element, platform));
|
|
29
|
+
allFiles.push(...dirFiles);
|
|
30
|
+
} else if (filterJSFile(file)) {
|
|
31
|
+
allFiles.push(file);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const combined = combine(allFiles);
|
|
36
|
+
|
|
37
|
+
// Warn users if there is no modules to process
|
|
38
|
+
if (Object.keys(combined.modules).length === 0) {
|
|
39
|
+
console.error(
|
|
40
|
+
'No modules to process in combine-js-to-schema-cli. If this is unexpected, please check if you set up your NativeComponent correctly. See combine-js-to-schema.js for how codegen finds modules.',
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
const formattedSchema = JSON.stringify(combined, null, 2);
|
|
44
|
+
|
|
45
|
+
if (outfile != null) {
|
|
46
|
+
fs.writeFileSync(outfile, formattedSchema);
|
|
47
|
+
} else {
|
|
48
|
+
console.log(formattedSchema);
|
|
49
|
+
}
|