@@ -325,22 +325,13 @@ function findExternalLibraries(pkgJson, projectRoot) {
325
325
} ) ;
326
326
}
327
327
328
- function findLibrariesFromReactNativeConfig ( projectRoot ) {
329
- const rnConfigFileName = 'react-native.config.js' ;
330
-
328
+ function findLibrariesFromReactNativeConfig ( projectRoot , rnConfig ) {
331
329
codegenLog (
332
- `Searching for codegen-enabled libraries in ${ rnConfigFileName } ` ,
330
+ `Searching for codegen-enabled libraries in react-native.config.js ` ,
333
331
true ,
334
332
) ;
335
333
336
- const rnConfigFilePath = path . resolve ( projectRoot , rnConfigFileName ) ;
337
-
338
- if ( ! fs . existsSync ( rnConfigFilePath ) ) {
339
- return [ ] ;
340
- }
341
- const rnConfig = require ( rnConfigFilePath ) ;
342
-
343
- if ( rnConfig . dependencies == null ) {
334
+ if ( ! rnConfig . dependencies ) {
344
335
return [ ] ;
345
336
}
346
337
return Object . keys ( rnConfig . dependencies ) . flatMap ( name => {
@@ -364,6 +355,19 @@ function findLibrariesFromReactNativeConfig(projectRoot) {
364
355
} ) ;
365
356
}
366
357
358
+ /**
359
+ * Finds all disabled libraries by platform based the react native config.
360
+ *
361
+ * This is needed when selectively disabling libraries in react-native.config.js since codegen should exclude those libraries as well.
362
+ */
363
+ function findDisabledLibrariesByPlatform ( reactNativeConfig , platform ) {
364
+ const dependencies = reactNativeConfig . dependencies ?? { } ;
365
+
366
+ return Object . keys ( dependencies ) . filter (
367
+ dependency => dependencies [ dependency ] . platforms ?. [ platform ] === null ,
368
+ ) ;
369
+ }
370
+
367
371
function findProjectRootLibraries ( pkgJson , projectRoot ) {
368
372
codegenLog ( 'Searching for codegen-enabled libraries in the app.' , true ) ;
369
373
@@ -592,19 +596,29 @@ function mustGenerateNativeCode(includeLibraryPath, schemaInfo) {
592
596
) ;
593
597
}
594
598
595
- function findCodegenEnabledLibraries ( pkgJson , projectRoot ) {
599
+ function findCodegenEnabledLibraries ( pkgJson , projectRoot , reactNativeConfig ) {
596
600
const projectLibraries = findProjectRootLibraries ( pkgJson , projectRoot ) ;
597
601
if ( pkgJsonIncludesGeneratedCode ( pkgJson ) ) {
598
602
return projectLibraries ;
599
603
} else {
600
604
return [
601
605
...projectLibraries ,
602
606
...findExternalLibraries ( pkgJson , projectRoot ) ,
603
- ...findLibrariesFromReactNativeConfig ( projectRoot ) ,
607
+ ...findLibrariesFromReactNativeConfig ( projectRoot , reactNativeConfig ) ,
604
608
] ;
605
609
}
606
610
}
607
611
612
+ function readReactNativeConfig ( projectRoot ) {
613
+ const rnConfigFilePath = path . resolve ( projectRoot , 'react-native.config.js' ) ; Add commentMore actions
614
+
615
+ if ( ! fs . existsSync ( rnConfigFilePath ) ) {
616
+ return { } ;
617
+ }
618
+
619
+ return require ( rnConfigFilePath ) ;
620
+ }
621
+
608
622
function generateCustomURLHandlers ( libraries , outputDir ) {
609
623
const customImageURLLoaderClasses = libraries
610
624
. flatMap (
@@ -1053,9 +1067,10 @@ function execute(projectRoot, targetPlatform, baseOutputPath, source) {
1053
1067
1054
1068
buildCodegenIfNeeded ( ) ;
1055
1069
1056
- const libraries = findCodegenEnabledLibraries ( pkgJson , projectRoot ) ;
1070
+ const reactNativeConfig = readReactNativeConfig ( projectRoot ) ;
1071
+ const codegenEnabledLibraries = findCodegenEnabledLibraries ( pkgJson , projectRoot , reactNativeConfig ) ;
1057
1072
1058
- if ( libraries . length === 0 ) {
1073
+ if ( codegenEnabledLibraries . length === 0 ) {
1059
1074
codegenLog ( 'No codegen-enabled libraries found.' , true ) ;
1060
1075
return ;
1061
1076
}
@@ -1064,6 +1079,19 @@ function execute(projectRoot, targetPlatform, baseOutputPath, source) {
1064
1079
targetPlatform === 'all' ? supportedPlatforms : [ targetPlatform ] ;
1065
1080
1066
1081
for ( const platform of platforms ) {
1082
+ const disabledLibraries = findDisabledLibrariesByPlatform ( Add commentMore actions
1083
+ reactNativeConfig ,
1084
+ platform ,
1085
+ ) ;
1086
+
1087
+ const libraries = codegenEnabledLibraries . filter (
1088
+ ( { name} ) => ! disabledLibraries . includes ( name ) ,
1089
+ ) ;
1090
+
1091
+ if ( ! libraries . length ) {
1092
+ continue ;
1093
+ }
1094
+
1067
1095
const outputPath = computeOutputPath (
1068
1096
projectRoot ,
1069
1097
baseOutputPath ,
0 commit comments