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
Summary:
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 facebook#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.

Differential Revision: D61850219
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Aug 27, 2024
1 parent 3596019 commit e18dff1
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 e18dff1

Please sign in to comment.