@@ -32,7 +32,13 @@ const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');
32
32
33
33
const CODEGEN_DEPENDENCY_NAME = '@react-native/codegen' ;
34
34
const CODEGEN_REPO_PATH = `${ REACT_NATIVE_REPOSITORY_ROOT } /packages/react-native-codegen` ;
35
- const CODEGEN_NPM_PATH = `${ REACT_NATIVE_PACKAGE_ROOT_FOLDER } /../${ CODEGEN_DEPENDENCY_NAME } ` ;
35
+ // This is a change for 0.73-stable only since this piece of code was replaced:
36
+ // https://github.com/facebook/react-native/commit/9071a3a0b0e11ad711927651bcb2412f553b6fe9
37
+ const CODEGEN_NPM_PATH = path . dirname (
38
+ require . resolve ( path . join ( CODEGEN_DEPENDENCY_NAME , 'package.json' ) , {
39
+ paths : [ REACT_NATIVE_PACKAGE_ROOT_FOLDER ] ,
40
+ } ) ,
41
+ ) ;
36
42
const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
37
43
rncore : path . join ( REACT_NATIVE_PACKAGE_ROOT_FOLDER , 'ReactCommon' ) ,
38
44
FBReactNativeSpec : null ,
@@ -189,33 +195,34 @@ function handleThirdPartyLibraries(
189
195
codegenConfigKey ,
190
196
) {
191
197
// Determine which of these are codegen-enabled libraries
192
- const configDir =
193
- baseCodegenConfigFileDir ||
194
- path . join ( REACT_NATIVE_PACKAGE_ROOT_FOLDER , '..' ) ;
198
+ const configDir = baseCodegenConfigFileDir || process . cwd ( ) ;
195
199
console . log (
196
200
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${ configDir } ` ,
197
201
) ;
198
202
199
203
// Handle third-party libraries
204
+ const resolveOptions = { paths : [ configDir ] } ;
200
205
Object . keys ( dependencies ) . forEach ( dependency => {
201
206
if ( dependency === REACT_NATIVE_DEPENDENCY_NAME ) {
202
207
// react-native should already be added.
203
208
return ;
204
209
}
205
- const codegenConfigFileDir = path . join ( configDir , dependency ) ;
206
- const configFilePath = path . join (
207
- codegenConfigFileDir ,
208
- codegenConfigFilename ,
209
- ) ;
210
- if ( fs . existsSync ( configFilePath ) ) {
210
+
211
+ try {
212
+ const configFilePath = require . resolve (
213
+ ` ${ dependency } / ${ codegenConfigFilename } ` ,
214
+ resolveOptions ,
215
+ ) ;
211
216
const configFile = JSON . parse ( fs . readFileSync ( configFilePath ) ) ;
212
217
extractLibrariesFromJSON (
213
218
configFile ,
214
219
libraries ,
215
220
codegenConfigKey ,
216
221
dependency ,
217
- codegenConfigFileDir ,
222
+ path . dirname ( configFilePath ) ,
218
223
) ;
224
+ } catch ( _ ) {
225
+ // ignore
219
226
}
220
227
} ) ;
221
228
}
0 commit comments