From 46d17efa626cd546e839648e1a95f43a3802051c Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Tue, 27 Aug 2024 07:58:39 -0700 Subject: [PATCH] Start looking for codegen-enabled dependencies from the project root (#46229) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46229 When running codegen from `pod install`, something affects `require.resolve`, and it starts looking for codegen-enabled dependencies from the workspace root, not the current RN project root. This is bad if we have different versions of same dependency across multiple workspaces. One of them will be hoisted to the workspace root, and will be used for all the workspaces. This issue is described in details here https://github.com/facebook/react-native/issues/46196 This diff is supposed to fix this by adding the project root path to the `require.resolve` call. Changelog: [iOS][Fixed] - Codegen will start looking for codegen-enabled dependencies from the project root. Reviewed By: cipolleschi Differential Revision: D61850219 fbshipit-source-id: d60a0e72e9c60e862c0d64e227ea3652d1be5a90 --- .../scripts/codegen/generate-artifacts-executor.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 074a397bf38ad2..50717a825e1ab5 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -225,7 +225,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) { return supportedPlatformsMap; } -function findExternalLibraries(pkgJson) { +function findExternalLibraries(pkgJson, projectRoot) { const dependencies = { ...pkgJson.dependencies, ...pkgJson.devDependencies, @@ -240,6 +240,7 @@ function findExternalLibraries(pkgJson) { try { const configFilePath = require.resolve( path.join(dependency, 'package.json'), + {paths: [projectRoot]}, ); const configFile = JSON.parse(fs.readFileSync(configFilePath)); const codegenConfigFileDir = path.dirname(configFilePath); @@ -533,7 +534,7 @@ function findCodegenEnabledLibraries(pkgJson, projectRoot) { } else { return [ ...projectLibraries, - ...findExternalLibraries(pkgJson), + ...findExternalLibraries(pkgJson, projectRoot), ...findLibrariesFromReactNativeConfig(projectRoot), ]; }