Skip to content

Commit 98b8f17

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Add extra parameter to define whether codegen is invoked by lib or app (#48995)
Summary: Pull Request resolved: #48995 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. Reviewed By: cortinico Differential Revision: D68765478 fbshipit-source-id: 8030b4472ad4f5058e58b1c91089de5122a4f60a
1 parent 08ddc11 commit 98b8f17

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

packages/react-native/react-native.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ const codegenCommand = {
8484
name: '--outputPath <path>',
8585
description: 'Path where generated artifacts will be output to.',
8686
},
87+
{
88+
name: '--source <string>',
89+
description: 'Whether the script is invoked from an `app` or a `library`',
90+
default: 'app',
91+
},
8792
],
8893
func: (argv, config, args) =>
8994
require('./scripts/codegen/generate-artifacts-executor').execute(
9095
args.path,
9196
args.platform,
9297
args.outputPath,
98+
args.source,
9399
),
94100
};
95101

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,11 +971,12 @@ SCRIPT`;
971971
* @parameter projectRoot: the directory with the app source code, where the package.json lives.
972972
* @parameter baseOutputPath: the base output path for the CodeGen.
973973
* @parameter targetPlatform: the target platform. Supported values: 'android', 'ios', 'all'.
974+
* @parameter source: the source that is invoking codegen. Supported values: 'app', 'library'.
974975
* @throws If it can't find a config file for react-native.
975976
* @throws If it can't find a CodeGen configuration in the file.
976977
* @throws If it can't find a cli for the CodeGen.
977978
*/
978-
function execute(projectRoot, targetPlatform, baseOutputPath) {
979+
function execute(projectRoot, targetPlatform, baseOutputPath, source) {
979980
try {
980981
codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);
981982

@@ -1023,9 +1024,12 @@ function execute(projectRoot, targetPlatform, baseOutputPath) {
10231024
platform,
10241025
);
10251026

1026-
generateRCTThirdPartyComponents(libraries, outputPath);
1027-
generateCustomURLHandlers(libraries, outputPath);
1028-
generateAppDependencyProvider(outputPath);
1027+
if (source === 'app') {
1028+
// These components are only required by apps, not by libraries
1029+
generateRCTThirdPartyComponents(libraries, outputPath);
1030+
generateCustomURLHandlers(libraries, outputPath);
1031+
generateAppDependencyProvider(outputPath);
1032+
}
10291033
generateReactCodegenPodspec(
10301034
projectRoot,
10311035
pkgJson,

packages/react-native/scripts/generate-codegen-artifacts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const argv = yargs
2525
alias: 'outputPath',
2626
description: 'Path where generated artifacts will be output to.',
2727
})
28+
.option('s', {
29+
alias: 'source',
30+
description: 'Whether the script is invoked from an `app` or a `library`',
31+
default: 'app',
32+
})
2833
.usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]')
2934
.demandOption(['p', 't']).argv;
3035

31-
executor.execute(argv.path, argv.targetPlatform, argv.outputPath);
36+
executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source);

0 commit comments

Comments
 (0)