From fcbcf80d1c080af42b5277fc8a153059194efb95 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Mon, 9 Dec 2024 14:39:29 +0000 Subject: [PATCH] [RN][Codegen] Better support filtering out non linked platforms (#48183) --- .../codegen/generate-artifacts-executor.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 7725250921d86c..9c4448e0dcfdec 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -311,12 +311,27 @@ function findNotLinkedLibraries(projectRoot) { Object.keys(rnConfig.dependencies).forEach(name => { const dependency = rnConfig.dependencies[name]; let notLinkedPlatforms = []; - Object.keys(dependency.platforms).forEach(platform => { + + // dependency.platforms might not be defined, as the format + // { + // "dependencies": { + // "dependency-name": { + // "root": "path/to/dependency", + // } + // } + // } + // is also supported. + // In this case, we assume that the library is linked to all platforms. + // We don't consider the case were `dependency-name.root` is equal to `null`, because that + // means that the library is not linked to the app at all, and in that case the dependency + // should be removed by the user. + dependency.platforms && Object.keys(dependency.platforms).forEach(platform => { if (dependency.platforms[platform] == null) { notLinkedPlatforms.push(platform); } }); notLinkedLibraries[name] = notLinkedPlatforms; + }); return notLinkedLibraries; }