From d0f28664e26faeff453a9795aaabab215e877cb5 Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Date: Wed, 21 Jan 2026 23:30:51 -0300 Subject: [PATCH] fix(codegen): fix react-native modules/components duplication --- .../generate-artifacts-executor/utils.js | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index db611c8db17f7a..9f3ac741dc36c1 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -329,7 +329,7 @@ function parseiOSAnnotations( ) /*: {[string]: $FlowFixMe} */ { const mLibraryMap = {} /*:: as {[string]: $FlowFixMe} */; const cLibraryMap = {} /*:: as {[string]: $FlowFixMe} */; - const map = {}; + const map = {} /*:: as {[string]: $FlowFixMe} */; // [macOS] for (const library of libraries) { const iosConfig = library?.config?.ios; @@ -363,6 +363,40 @@ function parseiOSAnnotations( } } } + // [macOS + // Allow react-native-macos to override react-native modules/components + const isAllowedOverride = (libraryNames /*: Set */) => { + const names = Array.from(libraryNames); + return ( + names.length === 2 && + names.includes('react-native') && + names.includes('react-native-macos') + ); + }; + + // Merge entries with react-native-macos taking precedence over react-native + for (const [moduleName, libraryNames] of Object.entries(mLibraryMap)) { + if (isAllowedOverride(libraryNames)) { + // Remove the module from react-native, keep only react-native-macos + if (map['react-native']?.modules?.[moduleName]) { + delete map['react-native'].modules[moduleName]; + } + // Update the library map to only contain react-native-macos + mLibraryMap[moduleName] = new Set(['react-native-macos']); + } + } + + for (const [componentName, libraryNames] of Object.entries(cLibraryMap)) { + if (isAllowedOverride(libraryNames)) { + // Remove the component from react-native, keep only react-native-macos + if (map['react-native']?.components?.[componentName]) { + delete map['react-native'].components[componentName]; + } + // Update the library map to only contain react-native-macos + cLibraryMap[componentName] = new Set(['react-native-macos']); + } + } + // macOS] const moduleConflicts = Object.entries(mLibraryMap) .filter(([_, libraryNames]) => libraryNames.size > 1)