From a1bad641bc5fb6ea9f092a4cbaeafd5dcc920452 Mon Sep 17 00:00:00 2001 From: Leevi Aattola Date: Fri, 6 Jun 2025 03:32:19 -0700 Subject: [PATCH] fix: exclusion of selectively disabled libraries from codegen generation (#51838) Summary: PR https://github.com/facebook/react-native/issues/51078 Implemented finding disabled libraries but the code (below) didn't actually filter any libraries out because destructured name is `undefined`. This pr adds the name to codegenEnabledLibraries so filtering would work. ```js const libraries = codegenEnabledLibraries.filter( ({name}) => !disabledLibraries.includes(name), ); ``` ## Changelog: [IOS] [FIXED] - Skip codegen for selectively disabled libraries in react-native.config.js Pull Request resolved: https://github.com/facebook/react-native/pull/51838 Test Plan: 1. Install a library that has the componentProvider field set in the codegen config (for example: react-native-safe-area-context and react-native-screens or see [reproducer](https://github.com/aattola/rn-codegen-exclude)) 2. Exclude library with react-native.config.js 3. install pods / run codegen 4. Check that codegen actually excluded the specified dependencies from: `ios/build/generated/ios/RCTThirdPartyComponentsProvider.mm` Rollback Plan: Reviewed By: cortinico Differential Revision: D76044622 Pulled By: cipolleschi fbshipit-source-id: 9e70c2a263c750edb1ea95305c9e5e178e2ce8d8 --- .../codegen/__tests__/generate-artifacts-executor-test.js | 5 +++++ .../scripts/codegen/generate-artifacts-executor/utils.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js index 67f597d5247..4503fb951e3 100644 --- a/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js +++ b/packages/react-native/scripts/codegen/__tests__/generate-artifacts-executor-test.js @@ -76,6 +76,7 @@ const packageJson = JSON.stringify({ jsSrcsDir: '.', }, libraryPath: '.', + name: undefined, }); }); @@ -96,6 +97,7 @@ const packageJson = JSON.stringify({ jsSrcsDir: '.', }, libraryPath: rootPath, + name: 'react-native', }); }); @@ -112,6 +114,7 @@ const packageJson = JSON.stringify({ jsSrcsDir: '.', }, libraryPath: myDependencyPath, + name: 'react-native', }); expect(libraries[1]).toEqual({ config: { @@ -120,6 +123,7 @@ const packageJson = JSON.stringify({ jsSrcsDir: 'component/js', }, libraryPath: myDependencyPath, + name: 'my-component', }); expect(libraries[2]).toEqual({ config: { @@ -128,6 +132,7 @@ const packageJson = JSON.stringify({ jsSrcsDir: 'module/js', }, libraryPath: myDependencyPath, + name: 'my-module', }); }); }); diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js index d78cd074878..32dbfc4102b 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor/utils.js @@ -216,6 +216,7 @@ function extractLibrariesFromJSON(configFile, dependencyPath) { const config = configFile.codegenConfig; return [ { + name: configFile.name, config, libraryPath: dependencyPath, }, @@ -267,6 +268,7 @@ function printDeprecationWarningIfNeeded(dependency) { function extractLibrariesFromConfigurationArray(configFile, dependencyPath) { return configFile.codegenConfig.libraries.map(config => { return { + name: config.name, config, libraryPath: dependencyPath, };