Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce "codegenConfig.isLibrary" property #41655

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const REACT_NATIVE = 'react-native';

// HELPERS

function isLibrary(pkgJson) {
return pkgJson.codegenConfig && pkgJson.codegenConfig.isLibrary;
}

function isReactNativeCoreLibrary(libraryName) {
return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
}
Expand Down Expand Up @@ -195,7 +199,12 @@ function computeOutputPath(projectRoot, baseOutputPath, pkgJson) {
baseOutputPath = projectRoot;
}
}
return path.join(baseOutputPath, 'build', 'generated', 'ios');
if (isLibrary(pkgJson)) {
// Don't create nested directories for libraries to make importing generated headers easier.
return baseOutputPath;
} else {
return path.join(baseOutputPath, 'build', 'generated', 'ios');
}
}

function generateSchemaInfo(library) {
Expand Down Expand Up @@ -260,6 +269,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 @@ -281,10 +300,12 @@ function createComponentProvider(schemas) {
}

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

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

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

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