-
Notifications
You must be signed in to change notification settings - Fork 24.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix codegen not finding all third-party libraries #42943
Conversation
Base commit: 6974697 |
@tido64 I've been experimenting with This part causes the issues for me: function handleThirdPartyLibraries(
libraries,
baseCodegenConfigFileDir,
dependencies,
codegenConfigFilename,
codegenConfigKey,
) {
// Determine which of these are codegen-enabled libraries
const configDir =
baseCodegenConfigFileDir ||
path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, '..');
console.log(
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${configDir}`,
); to fix it, I've used this: const configDir =
baseCodegenConfigFileDir ||
path.join(process.argv[1], '..', '..', '..');
|
I wasn't paying attention, but now that you mention it, this is also an issue. I fixed it like this: diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js
index 5980da20893..3c1dbed7c15 100644
--- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js
+++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js
@@ -197,7 +197,7 @@ function handleThirdPartyLibraries(
// Determine which of these are codegen-enabled libraries
const configDir =
baseCodegenConfigFileDir ||
- path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, '..');
+ path.join(process.cwd(), 'node_modules');
console.log(
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${configDir}`,
); But I'm not sure if this is sufficient. With a pnpm setup (pnpm or Yarn + pnpm), all dependencies are always present under FWIW, autolinking parses |
Will let one of the releases folks merge this since it's going into release branch, but change lgtm. Re structure, it seems like this is organized like a single app/library will depend on a single RN, then that RN dictates the association to version of codegen package? Is that right? |
Yes, that sounds right. On However, an issue still remains that it's looking for third-party libraries in the wrong place: react-native/packages/react-native/scripts/codegen/generate-artifacts-executor.js Lines 192 to 194 in 36a4a24
It looks like it was addressed on Edit: I've updated the patch from above. I think this should be more or less correct: diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js
index 5980da20893..23faf9ca370 100644
--- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js
+++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js
@@ -195,33 +195,34 @@ function handleThirdPartyLibraries(
codegenConfigKey,
) {
// Determine which of these are codegen-enabled libraries
- const configDir =
- baseCodegenConfigFileDir ||
- path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, '..');
+ const configDir = baseCodegenConfigFileDir || process.cwd();
console.log(
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${configDir}`,
);
// Handle third-party libraries
+ const resolveOptions = {paths: [configDir]};
Object.keys(dependencies).forEach(dependency => {
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) {
// react-native should already be added.
return;
}
- const codegenConfigFileDir = path.join(configDir, dependency);
- const configFilePath = path.join(
- codegenConfigFileDir,
- codegenConfigFilename,
- );
- if (fs.existsSync(configFilePath)) {
+
+ try {
+ const configFilePath = require.resolve(
+ `${dependency}/${codegenConfigFilename}`,
+ resolveOptions,
+ );
const configFile = JSON.parse(fs.readFileSync(configFilePath));
extractLibrariesFromJSON(
configFile,
libraries,
codegenConfigKey,
dependency,
- codegenConfigFileDir,
+ path.dirname(configFilePath),
);
+ } catch (_) {
+ // ignore
}
});
} |
@dmytrorykun: What do you think of the patch here: #42943 (comment). Should it be included or should I open a new PR? |
@tido64 it looks like these changes belong to this PR, yeah, let's include them. |
Summary:
pod install
(and probably Android build as well) fails when New Architecture is enabled because the path to@react-native/codegen
is hardcoded.Changelog:
[GENERAL] [FIXED] - Fix codegen not finding all third-party libraries
Test Plan: