Skip to content

Commit fae9a8d

Browse files
Splitting RN Core into 3
Summary: In order to avoid the duplicate dependency caused by FAC due to including core components twice, splitting the RN Core into 3 groups: 1. interfaceOnly: true components 2. UnimplementedNativeViewNativeComponent.js 3. Everything Else Changelog: [General][Added] Splitting RN Core to interfaceOnly:true, UnimplementedNativeViewNativeComponent.js and everything else Differential Revision: D75796413
1 parent 5f0d508 commit fae9a8d

2 files changed

Lines changed: 118 additions & 24 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,32 @@ const argv = yargs
2828
alias: 'exclude',
2929
default: null,
3030
})
31+
.option('exclude-interface-only', {
32+
describe: 'Exclude components with interfaceOnly: true',
33+
type: 'boolean',
34+
default: false,
35+
})
36+
.option('exclude-unimplemented', {
37+
describe:
38+
'Exclude component named UnimplementedNativeViewNativeComponent.js',
39+
type: 'boolean',
40+
default: false,
41+
})
3142
.parseSync();
3243

3344
const [outfile, ...fileList] = argv._;
3445
const platform: ?string = argv.platform;
3546
const exclude: string = argv.exclude;
3647
const excludeRegExp: ?RegExp =
3748
exclude != null && exclude !== '' ? new RegExp(exclude) : null;
49+
const excludeInterfaceOnly: boolean = argv['exclude-interface-only'];
50+
const excludeUnimplemented: boolean = argv['exclude-unimplemented'];
3851

3952
combineSchemasInFileListAndWriteToFile(
4053
fileList,
4154
platform != null ? platform.toLowerCase() : platform,
4255
outfile,
4356
excludeRegExp,
57+
excludeInterfaceOnly,
58+
excludeUnimplemented,
4459
);

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

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,69 @@ 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(
26-
(merged, filename) => {
27-
const contents = fs.readFileSync(filename, 'utf8');
24+
function combineSchemas(
25+
files: Array<string>,
26+
excludeInterfaceOnly?: boolean,
27+
excludeUnimplemented?: boolean,
28+
): {
29+
interfaceOnly: SchemaType,
30+
unimplemented: SchemaType,
31+
everythingElse: SchemaType,
32+
} {
33+
let interfaceOnly: SchemaType = {modules: {}};
34+
let unimplemented: SchemaType = {modules: {}};
35+
let everythingElse: SchemaType = {modules: {}};
2836

29-
if (
30-
contents &&
31-
(/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
32-
/extends TurboModule/.test(contents))
33-
) {
34-
const isTypeScript =
35-
path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
37+
files.forEach(filename => {
38+
const contents = fs.readFileSync(filename, 'utf8');
3639

37-
const parser = isTypeScript ? typescriptParser : flowParser;
40+
if (
41+
contents &&
42+
(/export\s+default\s+\(?codegenNativeComponent</.test(contents) ||
43+
/extends TurboModule/.test(contents))
44+
) {
45+
const isTypeScript =
46+
path.extname(filename) === '.ts' || path.extname(filename) === '.tsx';
47+
const parser = isTypeScript ? typescriptParser : flowParser;
48+
const schema = parser.parseFile(filename);
3849

39-
const schema = parser.parseFile(filename);
50+
if (!schema || !schema.modules) {
51+
return;
52+
}
53+
54+
const isInterfaceOnly = /interfaceOnly:\s*true/.test(contents);
55+
const isUnimplemented =
56+
/UnimplementedNativeViewNativeComponent\.js$/.test(filename);
4057

41-
if (schema && schema.modules) {
42-
merged.modules = {...merged.modules, ...schema.modules};
58+
if (isInterfaceOnly) {
59+
if (excludeInterfaceOnly !== true) {
60+
interfaceOnly = {
61+
modules: {...interfaceOnly.modules, ...schema.modules},
62+
};
63+
} else {
64+
console.log(`Excluding interfaceOnly component: ${filename}`);
65+
}
66+
} else if (isUnimplemented) {
67+
if (excludeUnimplemented !== true) {
68+
unimplemented = {
69+
modules: {...unimplemented.modules, ...schema.modules},
70+
};
71+
} else {
72+
console.log(`Excluding unimplemented component: ${filename}`);
4373
}
74+
} else {
75+
everythingElse = {
76+
modules: {...everythingElse.modules, ...schema.modules},
77+
};
4478
}
45-
return merged;
46-
},
47-
{modules: {}},
48-
);
79+
}
80+
});
81+
82+
return {
83+
interfaceOnly,
84+
unimplemented,
85+
everythingElse,
86+
};
4987
}
5088

5189
function expandDirectoriesIntoFiles(
@@ -74,14 +112,28 @@ function combineSchemasInFileList(
74112
fileList: Array<string>,
75113
platform: ?string,
76114
exclude: ?RegExp,
77-
): SchemaType {
115+
excludeInterfaceOnly: boolean,
116+
excludeUnimplemented: boolean,
117+
): {
118+
interfaceOnly: SchemaType,
119+
unimplemented: SchemaType,
120+
everythingElse: SchemaType,
121+
} {
78122
const expandedFileList = expandDirectoriesIntoFiles(
79123
fileList,
80124
platform,
81125
exclude,
82126
);
83-
const combined = combineSchemas(expandedFileList);
84-
if (Object.keys(combined.modules).length === 0) {
127+
const combined = combineSchemas(
128+
expandedFileList,
129+
excludeInterfaceOnly,
130+
excludeUnimplemented,
131+
);
132+
if (
133+
Object.keys(combined.interfaceOnly.modules).length === 0 &&
134+
Object.keys(combined.unimplemented.modules).length === 0 &&
135+
Object.keys(combined.everythingElse.modules).length === 0
136+
) {
85137
console.error(
86138
'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.',
87139
);
@@ -94,9 +146,36 @@ function combineSchemasInFileListAndWriteToFile(
94146
platform: ?string,
95147
outfile: string,
96148
exclude: ?RegExp,
149+
excludeInterfaceOnly: boolean,
150+
excludeUnimplemented: boolean,
97151
): void {
98-
const combined = combineSchemasInFileList(fileList, platform, exclude);
99-
const formattedSchema = JSON.stringify(combined);
152+
const combined = combineSchemasInFileList(
153+
fileList,
154+
platform,
155+
exclude,
156+
excludeInterfaceOnly,
157+
excludeUnimplemented,
158+
);
159+
160+
// Determine which schema to write based on flags
161+
let schemaToWrite;
162+
if (excludeInterfaceOnly && excludeUnimplemented) {
163+
schemaToWrite = combined.everythingElse;
164+
} else if (excludeInterfaceOnly) {
165+
schemaToWrite = combined.unimplemented;
166+
} else if (excludeUnimplemented) {
167+
schemaToWrite = combined.interfaceOnly;
168+
} else {
169+
// If no exclusions, combine all schemas
170+
schemaToWrite = {
171+
modules: {
172+
...combined.interfaceOnly.modules,
173+
...combined.unimplemented.modules,
174+
...combined.everythingElse.modules,
175+
},
176+
};
177+
}
178+
const formattedSchema = JSON.stringify(schemaToWrite);
100179
fs.writeFileSync(outfile, formattedSchema);
101180
}
102181

0 commit comments

Comments
 (0)