@@ -97,15 +97,40 @@ function cleanupEmptyFilesAndFolders(filepath /*: string */) {
97
97
}
98
98
}
99
99
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
+ /* $FlowFixMe */
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
+ }
102
118
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
+ /* $FlowFixMe */
129
+ return require ( rnConfigFilePath ) ;
130
+ } else {
131
+ console . warn ( `Could not find React Native config at: ${ rnConfigFilePath } ` ) ;
104
132
return { } ;
105
133
}
106
-
107
- // $FlowFixMe[unsupported-syntax]
108
- return require ( rnConfigFilePath ) ;
109
134
}
110
135
111
136
/**
@@ -114,8 +139,14 @@ function readReactNativeConfig(projectRoot /*: string */) /*: $FlowFixMe */ {
114
139
function findCodegenEnabledLibraries (
115
140
pkgJson /*: $FlowFixMe */ ,
116
141
projectRoot /*: string */ ,
142
+ baseOutputPath /*: string */ ,
117
143
reactNativeConfig /*: $FlowFixMe */ ,
118
144
) /*: 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
+ }
119
150
const projectLibraries = findProjectRootLibraries ( pkgJson , projectRoot ) ;
120
151
if ( pkgJsonIncludesGeneratedCode ( pkgJson ) ) {
121
152
return projectLibraries ;
0 commit comments