Skip to content

Commit b417b0c

Browse files
Extract out FBReactNativeSpec's core components including Unimplemented from auto-generated registry (facebook#51941)
Summary: Pull Request resolved: facebook#51941 Changelog: [Android][Fixed] - Extract out FBReactNativeSpec's core components including Unimplemented from auto-generated registry Extracting out `FBReactNativeSpec`'s core components including `UnimplementedNativeView` from auto-generated registry. Using this `libraryName` to skip merging those modules Reviewed By: RSNara Differential Revision: D76371796 fbshipit-source-id: 4cfee0fe80a661f159a5f17e0d4abc60f601ea74
1 parent 7ec2839 commit b417b0c

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

packages/react-native-codegen/src/CodegenSchema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
export type PlatformType = 'iOS' | 'android';
1414

1515
export type SchemaType = $ReadOnly<{
16+
libraryName?: string,
1617
modules: $ReadOnly<{
1718
[hasteModuleName: string]: ComponentSchema | NativeModuleSchema,
1819
}>,

packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,24 @@ const argv = yargs
2828
alias: 'exclude',
2929
default: null,
3030
})
31+
.option('l', {
32+
describe: 'Library name to use for schema generation',
33+
alias: 'libraryName',
34+
default: null,
35+
})
3136
.parseSync();
3237

3338
const [outfile, ...fileList] = argv._;
3439
const platform: ?string = argv.platform;
3540
const exclude: string = argv.exclude;
3641
const excludeRegExp: ?RegExp =
3742
exclude != null && exclude !== '' ? new RegExp(exclude) : null;
43+
const libraryName: ?string = argv.libraryName;
3844

3945
combineSchemasInFileListAndWriteToFile(
4046
fileList,
4147
platform != null ? platform.toLowerCase() : platform,
4248
outfile,
4349
excludeRegExp,
50+
libraryName,
4451
);

packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ const path = require('path');
2121
const flowParser = new FlowParser();
2222
const typescriptParser = new TypeScriptParser();
2323

24-
function combineSchemas(files: Array<string>): SchemaType {
25-
return files.reduce(
24+
function combineSchemas(
25+
files: Array<string>,
26+
libraryName: ?string,
27+
): SchemaType {
28+
const combined = files.reduce(
2629
(merged, filename) => {
2730
const contents = fs.readFileSync(filename, 'utf8');
2831

@@ -46,6 +49,11 @@ function combineSchemas(files: Array<string>): SchemaType {
4649
},
4750
{modules: {}},
4851
);
52+
53+
return {
54+
libraryName: libraryName || '',
55+
modules: combined.modules,
56+
};
4957
}
5058

5159
function expandDirectoriesIntoFiles(
@@ -74,13 +82,14 @@ function combineSchemasInFileList(
7482
fileList: Array<string>,
7583
platform: ?string,
7684
exclude: ?RegExp,
85+
libraryName: ?string,
7786
): SchemaType {
7887
const expandedFileList = expandDirectoriesIntoFiles(
7988
fileList,
8089
platform,
8190
exclude,
8291
);
83-
const combined = combineSchemas(expandedFileList);
92+
const combined = combineSchemas(expandedFileList, libraryName);
8493
if (Object.keys(combined.modules).length === 0) {
8594
console.error(
8695
'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.',
@@ -94,8 +103,14 @@ function combineSchemasInFileListAndWriteToFile(
94103
platform: ?string,
95104
outfile: string,
96105
exclude: ?RegExp,
106+
libraryName: ?string,
97107
): void {
98-
const combined = combineSchemasInFileList(fileList, platform, exclude);
108+
const combined = combineSchemasInFileList(
109+
fileList,
110+
platform,
111+
exclude,
112+
libraryName,
113+
);
99114
const formattedSchema = JSON.stringify(combined);
100115
fs.writeFileSync(outfile, formattedSchema);
101116
}

packages/react-native-codegen/src/cli/combine/combine-schemas-cli.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ for (const file of schemaFiles) {
9999
}
100100
}
101101

102-
modules[specName] = module;
103-
specNameToFile[specName] = file;
102+
if (
103+
module.type === 'Component' &&
104+
schema.libraryName === 'FBReactNativeSpec'
105+
) {
106+
continue;
107+
} else {
108+
modules[specName] = module;
109+
specNameToFile[specName] = file;
110+
}
104111
}
105112
}
106113
}

0 commit comments

Comments
 (0)