Skip to content

Commit

Permalink
Start looking for codegen-enabled dependencies from the project root (#…
Browse files Browse the repository at this point in the history
…46229)

Summary:
Pull Request resolved: #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 #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
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Aug 27, 2024
1 parent 773fc8d commit 46d17ef
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function extractSupportedApplePlatforms(dependency, dependencyPath) {
return supportedPlatformsMap;
}

function findExternalLibraries(pkgJson) {
function findExternalLibraries(pkgJson, projectRoot) {
const dependencies = {
...pkgJson.dependencies,
...pkgJson.devDependencies,
Expand All @@ -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);
Expand Down Expand Up @@ -533,7 +534,7 @@ function findCodegenEnabledLibraries(pkgJson, projectRoot) {
} else {
return [
...projectLibraries,
...findExternalLibraries(pkgJson),
...findExternalLibraries(pkgJson, projectRoot),
...findLibrariesFromReactNativeConfig(projectRoot),
];
}
Expand Down

0 comments on commit 46d17ef

Please sign in to comment.