@@ -256,57 +256,62 @@ function computeIOSOutputDir(outputPath, appRootDir) {
256
256
return path . join ( outputPath ? outputPath : appRootDir , 'build/generated/ios' ) ;
257
257
}
258
258
259
- function generateSchema ( library ) {
259
+ function generateSchemaInfo ( library ) {
260
260
const pathToJavaScriptSources = path . join (
261
261
library . libraryPath ,
262
262
library . config . jsSrcsDir ,
263
263
) ;
264
264
console . log ( `\n\n[Codegen] >>>>> Processing ${ library . config . name } ` ) ;
265
265
// Generate one schema for the entire library...
266
- return utils
267
- . getCombineJSToSchema ( )
268
- . combineSchemasInFileList ( [ pathToJavaScriptSources ] , 'ios' ) ;
266
+ return {
267
+ library : library ,
268
+ schema : utils
269
+ . getCombineJSToSchema ( )
270
+ . combineSchemasInFileList ( [ pathToJavaScriptSources ] , 'ios' ) ,
271
+ } ;
269
272
}
270
273
271
- function generateCode ( iosOutputDir , library , tmpDir , schema ) {
272
- // ...then generate native code artifacts.
273
- const libraryTypeArg = library . config . type ? ` ${ library . config . type } ` : '' ;
274
-
274
+ function generateCode ( iosOutputDir , schemaInfo ) {
275
+ const tmpDir = fs . mkdtempSync (
276
+ path . join ( os . tmpdir ( ) , schemaInfo . library . config . name ) ,
277
+ ) ;
275
278
const tmpOutputDir = path . join ( tmpDir , 'out' ) ;
276
279
fs . mkdirSync ( tmpOutputDir , { recursive : true } ) ;
277
280
278
281
generateSpecsCLIExecutor . generateSpecFromInMemorySchema (
279
282
'ios' ,
280
- schema ,
283
+ schemaInfo . schema ,
281
284
tmpOutputDir ,
282
- library . config . name ,
285
+ schemaInfo . library . config . name ,
283
286
'com.facebook.fbreact.specs' ,
284
- libraryTypeArg ,
287
+ schemaInfo . library . config . type ,
285
288
) ;
286
289
287
290
// Finally, copy artifacts to the final output directory.
288
291
const outputDir =
289
- CORE_LIBRARIES_WITH_OUTPUT_FOLDER [ library . config . name ] ?? iosOutputDir ;
292
+ CORE_LIBRARIES_WITH_OUTPUT_FOLDER [ schemaInfo . library . config . name ] ??
293
+ iosOutputDir ;
290
294
fs . mkdirSync ( outputDir , { recursive : true } ) ;
295
+ // TODO: Fix this. This will not work on Windows.
291
296
execSync ( `cp -R ${ tmpOutputDir } /* "${ outputDir } "` ) ;
292
- console . log ( `[Codegen] Generated artifacts: ${ iosOutputDir } ` ) ;
297
+ console . log ( `[Codegen] Generated artifacts: ${ outputDir } ` ) ;
293
298
}
294
299
295
- function generateNativeCodegenFiles ( libraries , iosOutputDir ) {
296
- const schemas = { } ;
297
- libraries . forEach ( library => {
298
- const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , library . config . name ) ) ;
299
- const schema = generateSchema ( library ) ;
300
- generateCode ( iosOutputDir , library , tmpDir , schema ) ;
301
-
302
- // Filter the react native core library out.
303
- // In the future, core library and third party library should
304
- // use the same way to generate/register the fabric components.
305
- if ( ! isReactNativeCoreLibrary ( library . config . name ) ) {
306
- schemas [ library . config . name ] = schema ;
307
- }
300
+ function generateSchemaInfos ( libraries ) {
301
+ return libraries . map ( generateSchemaInfo ) ;
302
+ }
303
+
304
+ function generateNativeCode ( iosOutputDir , schemaInfos ) {
305
+ return schemaInfos . map ( schemaInfo => {
306
+ generateCode ( iosOutputDir , schemaInfo ) ;
308
307
} ) ;
309
- return schemas ;
308
+ }
309
+
310
+ function needsThirdPartyComponentProvider ( schemaInfo ) {
311
+ // Filter the react native core library out.
312
+ // In the future, core library and third party library should
313
+ // use the same way to generate/register the fabric components.
314
+ return ! isReactNativeCoreLibrary ( schemaInfo . library . config . name ) ;
310
315
}
311
316
312
317
function createComponentProvider ( schemas ) {
@@ -409,8 +414,12 @@ function execute(appRootDir, outputPath, baseCodegenConfigFileDir) {
409
414
410
415
const iosOutputDir = computeIOSOutputDir ( outputPath , appRootDir ) ;
411
416
412
- const schemas = generateNativeCodegenFiles ( libraries , iosOutputDir ) ;
417
+ const schemaInfos = generateSchemaInfos ( libraries ) ;
418
+ generateNativeCode ( iosOutputDir , schemaInfos ) ;
413
419
420
+ const schemas = schemaInfos
421
+ . filter ( needsThirdPartyComponentProvider )
422
+ . map ( schemaInfo => schemaInfo . schema ) ;
414
423
createComponentProvider ( schemas ) ;
415
424
cleanupEmptyFilesAndFolders ( iosOutputDir ) ;
416
425
} catch ( err ) {
0 commit comments