From fae9a8df5a4dba7f70d4e2c2af2ff8f231ebaa82 Mon Sep 17 00:00:00 2001 From: Arushi Kesarwani Date: Mon, 2 Jun 2025 13:41:36 -0700 Subject: [PATCH] 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 --- .../cli/combine/combine-js-to-schema-cli.js | 15 +++ .../src/cli/combine/combine-js-to-schema.js | 127 ++++++++++++++---- 2 files changed, 118 insertions(+), 24 deletions(-) diff --git a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js index 5049b34f8a94..7f715afd7a6d 100644 --- a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js +++ b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js @@ -28,6 +28,17 @@ const argv = yargs alias: 'exclude', default: null, }) + .option('exclude-interface-only', { + describe: 'Exclude components with interfaceOnly: true', + type: 'boolean', + default: false, + }) + .option('exclude-unimplemented', { + describe: + 'Exclude component named UnimplementedNativeViewNativeComponent.js', + type: 'boolean', + default: false, + }) .parseSync(); const [outfile, ...fileList] = argv._; @@ -35,10 +46,14 @@ const platform: ?string = argv.platform; const exclude: string = argv.exclude; const excludeRegExp: ?RegExp = exclude != null && exclude !== '' ? new RegExp(exclude) : null; +const excludeInterfaceOnly: boolean = argv['exclude-interface-only']; +const excludeUnimplemented: boolean = argv['exclude-unimplemented']; combineSchemasInFileListAndWriteToFile( fileList, platform != null ? platform.toLowerCase() : platform, outfile, excludeRegExp, + excludeInterfaceOnly, + excludeUnimplemented, ); diff --git a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js index c47e3a765559..1d0123d82d96 100644 --- a/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js +++ b/packages/react-native-codegen/src/cli/combine/combine-js-to-schema.js @@ -21,31 +21,69 @@ const path = require('path'); const flowParser = new FlowParser(); const typescriptParser = new TypeScriptParser(); -function combineSchemas(files: Array): SchemaType { - return files.reduce( - (merged, filename) => { - const contents = fs.readFileSync(filename, 'utf8'); +function combineSchemas( + files: Array, + excludeInterfaceOnly?: boolean, + excludeUnimplemented?: boolean, +): { + interfaceOnly: SchemaType, + unimplemented: SchemaType, + everythingElse: SchemaType, +} { + let interfaceOnly: SchemaType = {modules: {}}; + let unimplemented: SchemaType = {modules: {}}; + let everythingElse: SchemaType = {modules: {}}; - if ( - contents && - (/export\s+default\s+\(?codegenNativeComponent { + const contents = fs.readFileSync(filename, 'utf8'); - const parser = isTypeScript ? typescriptParser : flowParser; + if ( + contents && + (/export\s+default\s+\(?codegenNativeComponent, platform: ?string, exclude: ?RegExp, -): SchemaType { + excludeInterfaceOnly: boolean, + excludeUnimplemented: boolean, +): { + interfaceOnly: SchemaType, + unimplemented: SchemaType, + everythingElse: SchemaType, +} { const expandedFileList = expandDirectoriesIntoFiles( fileList, platform, exclude, ); - const combined = combineSchemas(expandedFileList); - if (Object.keys(combined.modules).length === 0) { + const combined = combineSchemas( + expandedFileList, + excludeInterfaceOnly, + excludeUnimplemented, + ); + if ( + Object.keys(combined.interfaceOnly.modules).length === 0 && + Object.keys(combined.unimplemented.modules).length === 0 && + Object.keys(combined.everythingElse.modules).length === 0 + ) { 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.', ); @@ -94,9 +146,36 @@ function combineSchemasInFileListAndWriteToFile( platform: ?string, outfile: string, exclude: ?RegExp, + excludeInterfaceOnly: boolean, + excludeUnimplemented: boolean, ): void { - const combined = combineSchemasInFileList(fileList, platform, exclude); - const formattedSchema = JSON.stringify(combined); + const combined = combineSchemasInFileList( + fileList, + platform, + exclude, + excludeInterfaceOnly, + excludeUnimplemented, + ); + + // Determine which schema to write based on flags + let schemaToWrite; + if (excludeInterfaceOnly && excludeUnimplemented) { + schemaToWrite = combined.everythingElse; + } else if (excludeInterfaceOnly) { + schemaToWrite = combined.unimplemented; + } else if (excludeUnimplemented) { + schemaToWrite = combined.interfaceOnly; + } else { + // If no exclusions, combine all schemas + schemaToWrite = { + modules: { + ...combined.interfaceOnly.modules, + ...combined.unimplemented.modules, + ...combined.everythingElse.modules, + }, + }; + } + const formattedSchema = JSON.stringify(schemaToWrite); fs.writeFileSync(outfile, formattedSchema); }