Skip to content

Commit

Permalink
Add extra parameter to define whether codegen is invoked by lib or app
Browse files Browse the repository at this point in the history
Summary:
This change adds an extra parameter to the codegen script that allow our users to trigger codegen for Apps or for Libraries.

When running codegen for Apps, we have to generate some extra files that are not needed by the Libraries. This is causing issues to our library maintainers and this change will provide more flexibility in the DevX of libraries.

The default value is App, so if the new parameter is not passed, nothing will change in the current behavior.

## Changelog:
[iOS][Added] - Add the `source` parameter to generate-codegen-artifacts to avoid generating files not needed by libraries.

Differential Revision: D68765478
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Jan 28, 2025
1 parent 7016225 commit 892e8bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions packages/react-native/react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,18 @@ const codegenCommand = {
name: '--outputPath <path>',
description: 'Path where generated artifacts will be output to.',
},
{
name: '--source <string>',
description: 'Whether the script is invoked from an `app` or a `library`',
default: 'app',
},
],
func: (argv, config, args) =>
require('./scripts/codegen/generate-artifacts-executor').execute(
args.path,
args.platform,
args.outputPath,
args.source,
),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,11 +971,12 @@ SCRIPT`;
* @parameter projectRoot: the directory with the app source code, where the package.json lives.
* @parameter baseOutputPath: the base output path for the CodeGen.
* @parameter targetPlatform: the target platform. Supported values: 'android', 'ios', 'all'.
* @parameter source: the source that is invoking codegen. Supported values: 'app', 'library'.
* @throws If it can't find a config file for react-native.
* @throws If it can't find a CodeGen configuration in the file.
* @throws If it can't find a cli for the CodeGen.
*/
function execute(projectRoot, targetPlatform, baseOutputPath) {
function execute(projectRoot, targetPlatform, baseOutputPath, source) {
try {
codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);

Expand Down Expand Up @@ -1023,9 +1024,12 @@ function execute(projectRoot, targetPlatform, baseOutputPath) {
platform,
);

generateRCTThirdPartyComponents(libraries, outputPath);
generateCustomURLHandlers(libraries, outputPath);
generateAppDependencyProvider(outputPath);
if (source === 'app') {
// These components are only required by apps, not by libraries
generateRCTThirdPartyComponents(libraries, outputPath);
generateCustomURLHandlers(libraries, outputPath);
generateAppDependencyProvider(outputPath);
}
generateReactCodegenPodspec(
projectRoot,
pkgJson,
Expand Down
7 changes: 6 additions & 1 deletion packages/react-native/scripts/generate-codegen-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ const argv = yargs
alias: 'outputPath',
description: 'Path where generated artifacts will be output to.',
})
.option('s', {
alias: 'source',
description: 'Whether the script is invoked from an `app` or a `library`',
default: 'app',
})
.usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]')
.demandOption(['p', 't']).argv;

executor.execute(argv.path, argv.targetPlatform, argv.outputPath);
executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source);

0 comments on commit 892e8bf

Please sign in to comment.