@@ -97,15 +97,40 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) {
9797 }
9898}
9999
100- function readReactNativeConfig ( projectRoot /*: string */ ) /*: $FlowFixMe */ {
101- const rnConfigFilePath = path . resolve ( projectRoot , 'react-native.config.js' ) ;
100+ function readGeneratedReactNativeConfig (
101+ baseOutputPath /*: string */ ,
102+ ) /*: $FlowFixMe */ {
103+ // NOTE: Generated by scripts/cocoapods/autolinking.rb in list_native_modules (called by use_native_modules)
104+ const rnConfigGeneratedPath = path . resolve (
105+ baseOutputPath ,
106+ 'build/generated/autolinking/autolinking.json' ,
107+ ) ;
108+ if ( fs . existsSync ( rnConfigGeneratedPath ) ) {
109+ // $FlowIgnore
110+ return require ( rnConfigGeneratedPath ) ;
111+ } else {
112+ console . warn (
113+ `Could not find generated React Native config output at: ${ rnConfigGeneratedPath } ` ,
114+ ) ;
115+ return null ;
116+ }
117+ }
102118
103- if ( ! fs . existsSync ( rnConfigFilePath ) ) {
119+ function readReactNativeConfig (
120+ projectRoot /*: string */ ,
121+ baseOutputPath /*: string */ ,
122+ ) /*: $FlowFixMe */ {
123+ const rnGeneratedConfig = readGeneratedReactNativeConfig ( baseOutputPath ) ;
124+ const rnConfigFilePath = path . resolve ( projectRoot , 'react-native.config.js' ) ;
125+ if ( rnGeneratedConfig ) {
126+ return rnGeneratedConfig ;
127+ } else if ( fs . existsSync ( rnConfigFilePath ) ) {
128+ // $FlowIgnore
129+ return require ( rnConfigFilePath ) ;
130+ } else {
131+ console . warn ( `Could not find React Native config at: ${ rnConfigFilePath } ` ) ;
104132 return { } ;
105133 }
106-
107- // $FlowFixMe[unsupported-syntax]
108- return require ( rnConfigFilePath ) ;
109134}
110135
111136/**
@@ -114,8 +139,14 @@ function readReactNativeConfig(projectRoot /*: string */) /*: $FlowFixMe */ {
114139function findCodegenEnabledLibraries (
115140 pkgJson /*: $FlowFixMe */ ,
116141 projectRoot /*: string */ ,
142+ baseOutputPath /*: string */ ,
117143 reactNativeConfig /*: $FlowFixMe */ ,
118144) /*: Array<$FlowFixMe> */ {
145+ if ( ! ! readGeneratedReactNativeConfig ( baseOutputPath ) ) {
146+ // If we ran autolinking, we shouldn't try to run our own "autolinking-like"
147+ // library discovery
148+ return findLibrariesFromReactNativeConfig ( projectRoot , reactNativeConfig ) ;
149+ }
119150 const projectLibraries = findProjectRootLibraries ( pkgJson , projectRoot ) ;
120151 if ( pkgJsonIncludesGeneratedCode ( pkgJson ) ) {
121152 return projectLibraries ;
0 commit comments