Skip to content

Commit

Permalink
Introduce "codegenConfig.isLibrary" property (#41655)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #41655

This diff adds support for checked-in codegen artifacts for libraries.
It introduces a new property to `coegenConfig`, called `isLibrary`. If codegen sees `isLibrary: true` in a project's dependency, it assumes that the library has codegen artifacts in it, and will not generate any code.

Changelog: [General][Added] - Introduce "codegenConfig.isLibrary" property.

Differential Revision: D51207265

fbshipit-source-id: 938cf998331a7841731dfcf24e2a3e6ed8bcf8dc
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Nov 27, 2023
1 parent c18ba52 commit f8cf068
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ function needsThirdPartyComponentProvider(schemaInfo) {
return !isReactNativeCoreLibrary(schemaInfo.library.config.name);
}

function mustGenerateNativeCode(includeLibraryPath, schemaInfo) {
// If library's 'codegenConfig' sets 'isLibrary' to 'true',
// then we assume that native code is shipped with the library,
// and we don't need to generate it.
return (
schemaInfo.library.libraryPath === includeLibraryPath ||
!schemaInfo.library.config.isLibrary
);
}

function createComponentProvider(schemas) {
console.log('\n\n>>>>> Creating component provider');
const outputDir = path.join(
Expand All @@ -262,10 +272,12 @@ function createComponentProvider(schemas) {
}

function findCodegenEnabledLibraries(pkgJson, projectRoot) {
return [
...findExternalLibraries(pkgJson),
...findProjectRootLibraries(pkgJson, projectRoot),
];
const projectLibraries = findProjectRootLibraries(pkgJson, projectRoot);
if (pkgJson.codegenConfig.isLibrary) {
return projectLibraries;
} else {
return [...projectLibraries, ...findExternalLibraries(pkgJson)];
}
}

// It removes all the empty files and empty folders
Expand Down Expand Up @@ -343,12 +355,19 @@ function execute(projectRoot, outputPath) {
const iosOutputDir = computeIOSOutputDir(outputPath);

const schemaInfos = generateSchemaInfos(libraries);
generateNativeCode(iosOutputDir, schemaInfos);
generateNativeCode(
iosOutputDir,
schemaInfos.filter(schemaInfo =>
mustGenerateNativeCode(projectRoot, schemaInfo),
),
);

const schemas = schemaInfos
.filter(needsThirdPartyComponentProvider)
.map(schemaInfo => schemaInfo.schema);
createComponentProvider(schemas);
if (!pkgJson.codegenConfig.isLibrary) {
const schemas = schemaInfos
.filter(needsThirdPartyComponentProvider)
.map(schemaInfo => schemaInfo.schema);
createComponentProvider(schemas);
}
cleanupEmptyFilesAndFolders(iosOutputDir);
} catch (err) {
console.error(err);
Expand Down

0 comments on commit f8cf068

Please sign in to comment.