@react-native/codegen 0.86.0-nightly-20260310-621592d1f → 0.86.0-nightly-20260313-972a30db4
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/lib/CodegenSchema.js +1 -11
- package/lib/CodegenSchema.js.flow +7 -6
- package/lib/SchemaValidator.js +3 -17
- package/lib/cli/combine/combine-js-to-schema-cli.js +16 -39
- package/lib/cli/combine/combine-js-to-schema.js +46 -75
- package/lib/cli/combine/combine-schemas-cli.js +22 -64
- package/lib/cli/combine/combine-utils.js +4 -37
- package/lib/cli/generators/generate-all.js +13 -43
- package/lib/cli/parser/parser-cli.js +1 -11
- package/lib/cli/parser/parser.js +8 -15
- package/lib/generators/RNCodegen.js +52 -128
- package/lib/generators/TypeUtils/Cxx/index.js +2 -12
- package/lib/generators/TypeUtils/Java/index.js +4 -17
- package/lib/generators/TypeUtils/Objective-C/index.js +2 -12
- package/lib/generators/Utils.js +12 -37
- package/lib/generators/components/ComponentsGeneratorUtils.js +33 -68
- package/lib/generators/components/ComponentsProviderUtils.js +11 -36
- package/lib/generators/components/CppHelpers.js +44 -69
- package/lib/generators/components/GenerateComponentDescriptorCpp.js +34 -52
- package/lib/generators/components/GenerateComponentDescriptorH.js +34 -52
- package/lib/generators/components/GenerateComponentHObjCpp.js +66 -105
- package/lib/generators/components/GenerateEventEmitterCpp.js +93 -243
- package/lib/generators/components/GenerateEventEmitterH.js +89 -164
- package/lib/generators/components/GeneratePropsCpp.js +134 -209
- package/lib/generators/components/GeneratePropsH.js +183 -391
- package/lib/generators/components/GeneratePropsJavaDelegate.js +73 -116
- package/lib/generators/components/GeneratePropsJavaInterface.js +65 -101
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +56 -92
- package/lib/generators/components/GeneratePropsJavaPojo/index.js +29 -46
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +162 -223
- package/lib/generators/components/GenerateShadowNodeCpp.js +34 -53
- package/lib/generators/components/GenerateShadowNodeH.js +40 -58
- package/lib/generators/components/GenerateStateCpp.js +34 -53
- package/lib/generators/components/GenerateStateH.js +30 -51
- package/lib/generators/components/GenerateTests.js +62 -78
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +37 -62
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +39 -62
- package/lib/generators/components/GenerateViewConfigJs.js +96 -260
- package/lib/generators/components/JavaHelpers.js +4 -19
- package/lib/generators/modules/GenerateModuleH.js +122 -286
- package/lib/generators/modules/GenerateModuleJavaSpec.js +66 -152
- package/lib/generators/modules/GenerateModuleJniCpp.js +112 -170
- package/lib/generators/modules/GenerateModuleJniH.js +29 -54
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +45 -101
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +2 -12
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +63 -103
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +65 -117
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +8 -14
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +55 -83
- package/lib/generators/modules/GenerateModuleObjCpp/serializeEventEmitter.js +9 -21
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +105 -219
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +41 -72
- package/lib/generators/modules/Utils.js +8 -29
- package/lib/parsers/consistency/compareSnaps.js +10 -51
- package/lib/parsers/error-utils.js +47 -238
- package/lib/parsers/errors.js +36 -216
- package/lib/parsers/flow/components/commands.js +32 -81
- package/lib/parsers/flow/components/componentsUtils.js +92 -235
- package/lib/parsers/flow/components/events.js +39 -123
- package/lib/parsers/flow/components/index.js +19 -23
- package/lib/parsers/flow/modules/index.js +105 -267
- package/lib/parsers/flow/parseFlowAndThrowErrors.js +5 -19
- package/lib/parsers/flow/parser.js +83 -258
- package/lib/parsers/flow/utils.js +2 -12
- package/lib/parsers/parser.js +1 -11
- package/lib/parsers/parserMock.js +111 -208
- package/lib/parsers/parsers-commons.js +236 -779
- package/lib/parsers/parsers-commons.js.flow +32 -20
- package/lib/parsers/parsers-primitives.js +89 -347
- package/lib/parsers/parsers-utils.js +2 -12
- package/lib/parsers/schema/index.js +3 -16
- package/lib/parsers/schema.js +8 -18
- package/lib/parsers/typescript/components/commands.js +27 -107
- package/lib/parsers/typescript/components/componentsUtils.js +85 -284
- package/lib/parsers/typescript/components/events.js +43 -127
- package/lib/parsers/typescript/components/extends.js +6 -22
- package/lib/parsers/typescript/components/index.js +22 -26
- package/lib/parsers/typescript/modules/index.js +132 -386
- package/lib/parsers/typescript/parseTopLevelType.js +45 -100
- package/lib/parsers/typescript/parser.js +103 -326
- package/lib/parsers/utils.js +20 -63
- package/package.json +2 -1
package/lib/CodegenSchema.js
CHANGED
|
@@ -265,14 +265,15 @@ export type ReservedTypeAnnotation = Readonly<{
|
|
|
265
265
|
/**
|
|
266
266
|
* NativeModule Types
|
|
267
267
|
*/
|
|
268
|
-
export type Nullable<+T
|
|
268
|
+
export type Nullable<+T extends NativeModuleTypeAnnotation> =
|
|
269
269
|
| NullableTypeAnnotation<T>
|
|
270
270
|
| T;
|
|
271
271
|
|
|
272
|
-
export type NullableTypeAnnotation<+T
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
272
|
+
export type NullableTypeAnnotation<+T extends NativeModuleTypeAnnotation> =
|
|
273
|
+
Readonly<{
|
|
274
|
+
type: 'NullableTypeAnnotation',
|
|
275
|
+
typeAnnotation: T,
|
|
276
|
+
}>;
|
|
276
277
|
|
|
277
278
|
export type NativeModuleSchema = Readonly<{
|
|
278
279
|
type: 'NativeModule',
|
|
@@ -316,7 +317,7 @@ export type NativeModuleObjectTypeAnnotation = ObjectTypeAnnotation<
|
|
|
316
317
|
>;
|
|
317
318
|
|
|
318
319
|
export type NativeModuleArrayTypeAnnotation<
|
|
319
|
-
+T
|
|
320
|
+
+T extends Nullable<NativeModuleBaseTypeAnnotation>,
|
|
320
321
|
> = ArrayTypeAnnotation<
|
|
321
322
|
| T
|
|
322
323
|
/**
|
package/lib/SchemaValidator.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
3
|
const nullthrows = require('nullthrows');
|
|
14
4
|
function getErrors(schema) {
|
|
15
5
|
const errors = new Set();
|
|
16
|
-
|
|
17
|
-
// Map of component name -> Array of module names
|
|
18
6
|
const componentModules = new Map();
|
|
19
7
|
Object.keys(schema.modules).forEach(moduleName => {
|
|
20
8
|
const module = schema.modules[moduleName];
|
|
@@ -33,9 +21,7 @@ function getErrors(schema) {
|
|
|
33
21
|
});
|
|
34
22
|
componentModules.forEach((modules, componentName) => {
|
|
35
23
|
if (modules.length > 1) {
|
|
36
|
-
errors.add(
|
|
37
|
-
`Duplicate components found with name ${componentName}. Found in modules ${modules.join(', ')}`,
|
|
38
|
-
);
|
|
24
|
+
errors.add(`Duplicate components found with name ${componentName}. Found in modules ${modules.join(', ')}`);
|
|
39
25
|
}
|
|
40
26
|
});
|
|
41
27
|
return Array.from(errors).sort();
|
|
@@ -48,5 +34,5 @@ function validate(schema) {
|
|
|
48
34
|
}
|
|
49
35
|
module.exports = {
|
|
50
36
|
getErrors,
|
|
51
|
-
validate
|
|
52
|
-
};
|
|
37
|
+
validate
|
|
38
|
+
};
|
|
@@ -1,48 +1,25 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
3
|
const {
|
|
14
|
-
combineSchemasInFileListAndWriteToFile
|
|
4
|
+
combineSchemasInFileListAndWriteToFile
|
|
15
5
|
} = require('./combine-js-to-schema');
|
|
16
6
|
const yargs = require('yargs');
|
|
17
|
-
const argv = yargs
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.option('l', {
|
|
31
|
-
describe: 'Library name to use for schema generation',
|
|
32
|
-
alias: 'libraryName',
|
|
33
|
-
default: null,
|
|
34
|
-
})
|
|
35
|
-
.parseSync();
|
|
7
|
+
const argv = yargs.usage('Usage: $0 <outfile> <file1> [<file2> ...]').option('p', {
|
|
8
|
+
describe: 'Platforms to generate schema for, this works on filenames: <filename>[.<platform>].(js|tsx?)',
|
|
9
|
+
alias: 'platform',
|
|
10
|
+
default: null
|
|
11
|
+
}).option('e', {
|
|
12
|
+
describe: 'Regular expression to exclude files from schema generation',
|
|
13
|
+
alias: 'exclude',
|
|
14
|
+
default: null
|
|
15
|
+
}).option('l', {
|
|
16
|
+
describe: 'Library name to use for schema generation',
|
|
17
|
+
alias: 'libraryName',
|
|
18
|
+
default: null
|
|
19
|
+
}).parseSync();
|
|
36
20
|
const [outfile, ...fileList] = argv._;
|
|
37
21
|
const platform = argv.platform;
|
|
38
22
|
const exclude = argv.exclude;
|
|
39
|
-
const excludeRegExp =
|
|
40
|
-
exclude != null && exclude !== '' ? new RegExp(exclude) : null;
|
|
23
|
+
const excludeRegExp = exclude != null && exclude !== '' ? new RegExp(exclude) : null;
|
|
41
24
|
const libraryName = argv.libraryName;
|
|
42
|
-
combineSchemasInFileListAndWriteToFile(
|
|
43
|
-
fileList,
|
|
44
|
-
platform != null ? platform.toLowerCase() : platform,
|
|
45
|
-
outfile,
|
|
46
|
-
excludeRegExp,
|
|
47
|
-
libraryName,
|
|
48
|
-
);
|
|
25
|
+
combineSchemasInFileListAndWriteToFile(fileList, platform != null ? platform.toLowerCase() : platform, outfile, excludeRegExp, libraryName);
|
|
@@ -1,101 +1,72 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const {
|
|
4
|
+
FlowParser
|
|
5
|
+
} = require('../../parsers/flow/parser');
|
|
6
|
+
const {
|
|
7
|
+
TypeScriptParser
|
|
8
|
+
} = require('../../parsers/typescript/parser');
|
|
9
|
+
const {
|
|
10
|
+
filterJSFile
|
|
11
|
+
} = require('./combine-utils');
|
|
16
12
|
const fs = require('fs');
|
|
17
13
|
const path = require('path');
|
|
18
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
globSync
|
|
16
|
+
} = require('tinyglobby');
|
|
19
17
|
const flowParser = new FlowParser();
|
|
20
18
|
const typescriptParser = new TypeScriptParser();
|
|
21
19
|
function combineSchemas(files, libraryName) {
|
|
22
|
-
const combined = files.reduce(
|
|
23
|
-
(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const schema = parser.parseFile(filename);
|
|
34
|
-
if (schema && schema.modules) {
|
|
35
|
-
merged.modules = {
|
|
36
|
-
...merged.modules,
|
|
37
|
-
...schema.modules,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
20
|
+
const combined = files.reduce((merged, filename) => {
|
|
21
|
+
const contents = fs.readFileSync(filename, 'utf8');
|
|
22
|
+
if (contents && (/export\s+default\s+\(?codegenNativeComponent</.test(contents) || /extends TurboModule/.test(contents))) {
|
|
23
|
+
const isTypeScript = path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
|
|
24
|
+
const parser = isTypeScript ? typescriptParser : flowParser;
|
|
25
|
+
const schema = parser.parseFile(filename);
|
|
26
|
+
if (schema && schema.modules) {
|
|
27
|
+
merged.modules = {
|
|
28
|
+
...merged.modules,
|
|
29
|
+
...schema.modules
|
|
30
|
+
};
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
32
|
+
}
|
|
33
|
+
return merged;
|
|
34
|
+
}, {
|
|
35
|
+
modules: {}
|
|
36
|
+
});
|
|
47
37
|
return {
|
|
48
38
|
libraryName: libraryName || '',
|
|
49
|
-
modules: combined.modules
|
|
39
|
+
modules: combined.modules
|
|
50
40
|
};
|
|
51
41
|
}
|
|
52
42
|
function expandDirectoriesIntoFiles(fileList, platform, exclude) {
|
|
53
|
-
return fileList
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
.filter(element => filterJSFile(element, platform, exclude));
|
|
43
|
+
return fileList.flatMap(file => {
|
|
44
|
+
if (!fs.lstatSync(file).isDirectory()) {
|
|
45
|
+
return [file];
|
|
46
|
+
}
|
|
47
|
+
return globSync('**/*{,.fb}.{js,ts,tsx}', {
|
|
48
|
+
expandDirectories: false,
|
|
49
|
+
onlyFiles: true,
|
|
50
|
+
absolute: true,
|
|
51
|
+
cwd: file
|
|
52
|
+
});
|
|
53
|
+
}).filter(element => filterJSFile(element, platform, exclude));
|
|
66
54
|
}
|
|
67
55
|
function combineSchemasInFileList(fileList, platform, exclude, libraryName) {
|
|
68
|
-
const expandedFileList = expandDirectoriesIntoFiles(
|
|
69
|
-
fileList,
|
|
70
|
-
platform,
|
|
71
|
-
exclude,
|
|
72
|
-
);
|
|
56
|
+
const expandedFileList = expandDirectoriesIntoFiles(fileList, platform, exclude);
|
|
73
57
|
const combined = combineSchemas(expandedFileList, libraryName);
|
|
74
58
|
if (Object.keys(combined.modules).length === 0) {
|
|
75
|
-
console.error(
|
|
76
|
-
'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.',
|
|
77
|
-
);
|
|
59
|
+
console.error('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.');
|
|
78
60
|
}
|
|
79
61
|
return combined;
|
|
80
62
|
}
|
|
81
|
-
function combineSchemasInFileListAndWriteToFile(
|
|
82
|
-
fileList,
|
|
83
|
-
platform,
|
|
84
|
-
outfile,
|
|
85
|
-
exclude,
|
|
86
|
-
libraryName,
|
|
87
|
-
) {
|
|
88
|
-
const combined = combineSchemasInFileList(
|
|
89
|
-
fileList,
|
|
90
|
-
platform,
|
|
91
|
-
exclude,
|
|
92
|
-
libraryName,
|
|
93
|
-
);
|
|
63
|
+
function combineSchemasInFileListAndWriteToFile(fileList, platform, outfile, exclude, libraryName) {
|
|
64
|
+
const combined = combineSchemasInFileList(fileList, platform, exclude, libraryName);
|
|
94
65
|
const formattedSchema = JSON.stringify(combined);
|
|
95
66
|
fs.writeFileSync(outfile, formattedSchema);
|
|
96
67
|
}
|
|
97
68
|
module.exports = {
|
|
98
69
|
combineSchemas,
|
|
99
70
|
combineSchemasInFileList,
|
|
100
|
-
combineSchemasInFileListAndWriteToFile
|
|
101
|
-
};
|
|
71
|
+
combineSchemasInFileListAndWriteToFile
|
|
72
|
+
};
|
|
@@ -1,31 +1,17 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
3
|
const assert = require('assert');
|
|
14
4
|
const fs = require('fs');
|
|
15
5
|
const yargs = require('yargs');
|
|
16
|
-
const argv = yargs
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.option('s', {
|
|
26
|
-
alias: 'schema-query',
|
|
27
|
-
})
|
|
28
|
-
.parseSync();
|
|
6
|
+
const argv = yargs.option('p', {
|
|
7
|
+
alias: 'platform',
|
|
8
|
+
type: 'string',
|
|
9
|
+
demandOption: true
|
|
10
|
+
}).option('o', {
|
|
11
|
+
alias: 'output'
|
|
12
|
+
}).option('s', {
|
|
13
|
+
alias: 'schema-query'
|
|
14
|
+
}).parseSync();
|
|
29
15
|
const platform = argv.platform.toLowerCase();
|
|
30
16
|
const output = argv.output;
|
|
31
17
|
const schemaQuery = argv.s;
|
|
@@ -33,16 +19,13 @@ if (!['ios', 'android'].includes(platform)) {
|
|
|
33
19
|
throw new Error(`Invalid platform ${platform}`);
|
|
34
20
|
}
|
|
35
21
|
if (!schemaQuery.startsWith('@')) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
"The argument provided to --schema-query must be a filename that starts with '@'.",
|
|
38
|
-
);
|
|
22
|
+
throw new Error("The argument provided to --schema-query must be a filename that starts with '@'.");
|
|
39
23
|
}
|
|
40
24
|
const schemaQueryOutputFile = schemaQuery.replace(/^@/, '');
|
|
41
25
|
const schemaQueryOutput = fs.readFileSync(schemaQueryOutputFile, 'utf8');
|
|
42
26
|
const modules = {};
|
|
43
27
|
const specNameToFile = {};
|
|
44
|
-
const schemaFiles =
|
|
45
|
-
schemaQueryOutput.length > 0 ? schemaQueryOutput.split(' ') : [];
|
|
28
|
+
const schemaFiles = schemaQueryOutput.length > 0 ? schemaQueryOutput.split(' ') : [];
|
|
46
29
|
for (const file of schemaFiles) {
|
|
47
30
|
const schema = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
48
31
|
if (schema.modules) {
|
|
@@ -50,48 +33,26 @@ for (const file of schemaFiles) {
|
|
|
50
33
|
var _module$excludedPlatf;
|
|
51
34
|
const module = schema.modules[specName];
|
|
52
35
|
if (modules[specName]) {
|
|
53
|
-
assert.deepEqual(
|
|
54
|
-
module,
|
|
55
|
-
modules[specName],
|
|
56
|
-
`App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`,
|
|
57
|
-
);
|
|
36
|
+
assert.deepEqual(module, modules[specName], `App contained two specs with the same file name '${specName}'. Schemas: ${specNameToFile[specName]}, ${file}. Please rename one of the specs.`);
|
|
58
37
|
}
|
|
59
|
-
const excludedPlatforms =
|
|
60
|
-
(_module$excludedPlatf = module.excludedPlatforms) === null ||
|
|
61
|
-
_module$excludedPlatf === void 0
|
|
62
|
-
? void 0
|
|
63
|
-
: _module$excludedPlatf.map(excludedPlatform =>
|
|
64
|
-
excludedPlatform.toLowerCase(),
|
|
65
|
-
);
|
|
38
|
+
const excludedPlatforms = (_module$excludedPlatf = module.excludedPlatforms) === null || _module$excludedPlatf === void 0 ? void 0 : _module$excludedPlatf.map(excludedPlatform => excludedPlatform.toLowerCase());
|
|
66
39
|
if (excludedPlatforms != null) {
|
|
67
|
-
const cxxOnlyModule =
|
|
68
|
-
excludedPlatforms.includes('ios') &&
|
|
69
|
-
excludedPlatforms.includes('android');
|
|
40
|
+
const cxxOnlyModule = excludedPlatforms.includes('ios') && excludedPlatforms.includes('android');
|
|
70
41
|
if (!cxxOnlyModule && excludedPlatforms.includes(platform)) {
|
|
71
42
|
continue;
|
|
72
43
|
}
|
|
73
44
|
}
|
|
74
45
|
if (module.type === 'Component') {
|
|
75
46
|
const components = module.components || {};
|
|
76
|
-
const isExcludedForPlatform = Object.values(components).some(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
null || _component$excludedPl === void 0
|
|
81
|
-
? void 0
|
|
82
|
-
: _component$excludedPl
|
|
83
|
-
.map(p => p.toLowerCase())
|
|
84
|
-
.includes(platform);
|
|
85
|
-
},
|
|
86
|
-
);
|
|
47
|
+
const isExcludedForPlatform = Object.values(components).some(component => {
|
|
48
|
+
var _component$excludedPl;
|
|
49
|
+
return (_component$excludedPl = component.excludedPlatforms) === null || _component$excludedPl === void 0 ? void 0 : _component$excludedPl.map(p => p.toLowerCase()).includes(platform);
|
|
50
|
+
});
|
|
87
51
|
if (isExcludedForPlatform) {
|
|
88
52
|
continue;
|
|
89
53
|
}
|
|
90
54
|
}
|
|
91
|
-
if (
|
|
92
|
-
module.type === 'Component' &&
|
|
93
|
-
schema.libraryName === 'FBReactNativeSpec'
|
|
94
|
-
) {
|
|
55
|
+
if (module.type === 'Component' && schema.libraryName === 'FBReactNativeSpec') {
|
|
95
56
|
continue;
|
|
96
57
|
} else {
|
|
97
58
|
modules[specName] = module;
|
|
@@ -100,9 +61,6 @@ for (const file of schemaFiles) {
|
|
|
100
61
|
}
|
|
101
62
|
}
|
|
102
63
|
}
|
|
103
|
-
fs.writeFileSync(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
modules,
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
64
|
+
fs.writeFileSync(output, JSON.stringify({
|
|
65
|
+
modules
|
|
66
|
+
}));
|
|
@@ -1,28 +1,7 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
3
|
const path = require('path');
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This function is used by the CLI to decide whether a JS/TS file has to be
|
|
17
|
-
* processed or not by the Codegen.
|
|
18
|
-
*
|
|
19
|
-
* Parameters:
|
|
20
|
-
* - originalFilePath: the path to the file
|
|
21
|
-
* - currentPlatform: the platform for which we are creating the specs
|
|
22
|
-
* Returns: `true` if the file can be used to generate code; `false` otherwise
|
|
23
|
-
*/
|
|
24
4
|
function filterJSFile(originalFilePath, currentPlatform, excludeRegExp) {
|
|
25
|
-
// Remove `.fb` if it exists (see `react-native.cconf`).
|
|
26
5
|
const filePath = originalFilePath.replace(/\.fb(\.|$)/, '$1');
|
|
27
6
|
const basename = path.basename(filePath);
|
|
28
7
|
const isSpecFile = /^(Native.+|.+NativeComponent)/.test(basename);
|
|
@@ -30,30 +9,18 @@ function filterJSFile(originalFilePath, currentPlatform, excludeRegExp) {
|
|
|
30
9
|
const isNotTest = !filePath.includes('__tests');
|
|
31
10
|
const isNotExcluded = excludeRegExp == null || !excludeRegExp.test(filePath);
|
|
32
11
|
const isNotTSTypeDefinition = !filePath.endsWith('.d.ts');
|
|
33
|
-
const isValidCandidate =
|
|
34
|
-
isSpecFile &&
|
|
35
|
-
isNotNativeUIManager &&
|
|
36
|
-
isNotExcluded &&
|
|
37
|
-
isNotTest &&
|
|
38
|
-
isNotTSTypeDefinition;
|
|
12
|
+
const isValidCandidate = isSpecFile && isNotNativeUIManager && isNotExcluded && isNotTest && isNotTSTypeDefinition;
|
|
39
13
|
const filenameComponents = basename.split('.');
|
|
40
14
|
const isPlatformAgnostic = filenameComponents.length === 2;
|
|
41
15
|
if (currentPlatform == null) {
|
|
42
|
-
// need to accept only files that are platform agnostic
|
|
43
16
|
return isValidCandidate && isPlatformAgnostic;
|
|
44
17
|
}
|
|
45
|
-
|
|
46
|
-
// If a platform is passed, accept both platform agnostic specs...
|
|
47
18
|
if (isPlatformAgnostic) {
|
|
48
19
|
return isValidCandidate;
|
|
49
20
|
}
|
|
50
|
-
|
|
51
|
-
// ...and specs that share the same platform as the one passed.
|
|
52
|
-
// specfiles must follow the pattern: <filename>[.<platform>].(js|ts|tsx)
|
|
53
|
-
const filePlatform =
|
|
54
|
-
filenameComponents.length > 2 ? filenameComponents[1] : 'unknown';
|
|
21
|
+
const filePlatform = filenameComponents.length > 2 ? filenameComponents[1] : 'unknown';
|
|
55
22
|
return isValidCandidate && currentPlatform === filePlatform;
|
|
56
23
|
}
|
|
57
24
|
module.exports = {
|
|
58
|
-
filterJSFile
|
|
59
|
-
};
|
|
25
|
+
filterJSFile
|
|
26
|
+
};
|
|
@@ -1,26 +1,10 @@
|
|
|
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
|
-
/**
|
|
12
|
-
* This generates all possible outputs by executing all available generators.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
1
|
'use strict';
|
|
16
2
|
|
|
17
3
|
const RNCodegen = require('../../generators/RNCodegen.js');
|
|
18
4
|
const fs = require('fs');
|
|
19
5
|
const args = process.argv.slice(2);
|
|
20
6
|
if (args.length < 3) {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(', ')}`,
|
|
23
|
-
);
|
|
7
|
+
throw new Error(`Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(', ')}`);
|
|
24
8
|
}
|
|
25
9
|
const schemaPath = args[0];
|
|
26
10
|
const libraryName = args[1];
|
|
@@ -32,7 +16,7 @@ if (schemaText == null) {
|
|
|
32
16
|
throw new Error(`Can't find schema at ${schemaPath}`);
|
|
33
17
|
}
|
|
34
18
|
fs.mkdirSync(outputDirectory, {
|
|
35
|
-
recursive: true
|
|
19
|
+
recursive: true
|
|
36
20
|
});
|
|
37
21
|
let schema;
|
|
38
22
|
try {
|
|
@@ -40,28 +24,14 @@ try {
|
|
|
40
24
|
} catch (err) {
|
|
41
25
|
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
|
|
42
26
|
}
|
|
43
|
-
const includeGetDebugPropsImplementation =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
generators: [
|
|
56
|
-
'descriptors',
|
|
57
|
-
'events',
|
|
58
|
-
'props',
|
|
59
|
-
'states',
|
|
60
|
-
'tests',
|
|
61
|
-
'shadow-nodes',
|
|
62
|
-
'modulesAndroid',
|
|
63
|
-
'modulesCxx',
|
|
64
|
-
'modulesIOS',
|
|
65
|
-
],
|
|
66
|
-
},
|
|
67
|
-
);
|
|
27
|
+
const includeGetDebugPropsImplementation = libraryName.includes('FBReactNativeSpec');
|
|
28
|
+
RNCodegen.generate({
|
|
29
|
+
libraryName,
|
|
30
|
+
schema,
|
|
31
|
+
outputDirectory,
|
|
32
|
+
packageName,
|
|
33
|
+
assumeNonnull,
|
|
34
|
+
includeGetDebugPropsImplementation
|
|
35
|
+
}, {
|
|
36
|
+
generators: ['descriptors', 'events', 'props', 'states', 'tests', 'shadow-nodes', 'modulesAndroid', 'modulesCxx', 'modulesIOS']
|
|
37
|
+
});
|
|
@@ -1,15 +1,5 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
3
|
const parseFiles = require('./parser.js');
|
|
14
4
|
const [...fileList] = process.argv.slice(2);
|
|
15
|
-
parseFiles(fileList);
|
|
5
|
+
parseFiles(fileList);
|
package/lib/cli/parser/parser.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
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
1
|
'use strict';
|
|
12
2
|
|
|
13
|
-
const {
|
|
14
|
-
|
|
3
|
+
const {
|
|
4
|
+
FlowParser
|
|
5
|
+
} = require('../../parsers/flow/parser');
|
|
6
|
+
const {
|
|
7
|
+
TypeScriptParser
|
|
8
|
+
} = require('../../parsers/typescript/parser');
|
|
15
9
|
const path = require('path');
|
|
16
10
|
const flowParser = new FlowParser();
|
|
17
11
|
const typescriptParser = new TypeScriptParser();
|
|
18
12
|
function parseFiles(files) {
|
|
19
13
|
files.forEach(filename => {
|
|
20
|
-
const isTypeScript =
|
|
21
|
-
path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
|
|
14
|
+
const isTypeScript = path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
|
|
22
15
|
const parser = isTypeScript ? typescriptParser : flowParser;
|
|
23
16
|
console.log(filename, JSON.stringify(parser.parseFile(filename), null, 2));
|
|
24
17
|
});
|
|
25
18
|
}
|
|
26
|
-
module.exports = parseFiles;
|
|
19
|
+
module.exports = parseFiles;
|