Codegen and Libraries which are not inside node_modules #69
-
Hey folks, I have been working on a template for using Turbo modules with The generated project includes an library
src (JS code)
android
ios
example (react native app which links to the library) But I run into an issue with Codegen on iOS. If the library uses codegen, then this fails because the library isn't located inside Currently, I have this patch that reads diff --git a/node_modules/react-native/scripts/generate-artifacts.js b/node_modules/react-native/scripts/generate-artifacts.js
index d0d8a00..f0cc68d 100644
--- a/node_modules/react-native/scripts/generate-artifacts.js
+++ b/node_modules/react-native/scripts/generate-artifacts.js
@@ -121,6 +121,44 @@ function main(appRootDir, outputPath) {
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${confifDir}`,
);
+ let rnConfig;
+
+ try {
+ rnConfig = require(path.join(appRootDir, 'react-native.config.js'));
+ } catch (e) {
+ // Ignore
+ }
+
+ if (rnConfig && rnConfig.dependencies) {
+ Object.keys(rnConfig.dependencies).forEach(name => {
+ const dependency = rnConfig.dependencies[name];
+
+ if (dependency.root) {
+ const configFilePath = path.join(
+ dependency.root,
+ CODEGEN_CONFIG_FILENAME,
+ );
+ if (fs.existsSync(configFilePath)) {
+ const configFile = JSON.parse(fs.readFileSync(configFilePath));
+ if (
+ configFile[CODEGEN_CONFIG_KEY] != null &&
+ configFile[CODEGEN_CONFIG_KEY].libraries != null
+ ) {
+ console.log(`[Codegen] Found ${name} in 'react-native-config.js'`);
+ configFile[CODEGEN_CONFIG_KEY].libraries.forEach(config => {
+ const libraryConfig = {
+ library: { name, path: dependency.root },
+ config,
+ libraryPath: dependency.root,
+ };
+ libraries.push(libraryConfig);
+ });
+ }
+ }
+ }
+ });
+ }
+
// Handle third-party libraries
Object.keys(dependencies).forEach(dependency => {
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) { Example const path = require('path');
module.exports = {
dependencies: {
'react-native-library-name': {
root: path.join(__dirname, '..'),
},
},
}; Do you think it's possible to support including dependencies that are not in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I'm not entirely sure if this issue falls between the domain of our codegen setup or the CLI. For our setup, the That would allow you to specify another As for the CLI, you can open an issue here: https://github.com/react-native-community/cli |
Beta Was this translation helpful? Give feedback.
-
Hi @satya164, Thanks for looking into this. However I don't think we want to support that setup. IIRC, in that setup you have an external module (the library) which is forced as a dependency manually adding a line like: This is a development setup, which I don't think we would want in production. For that development purposes, I think that the best solution should be to consider the component as part of the My suggestion is to prepare the template with a copy of the |
Beta Was this translation helpful? Give feedback.
Hi @satya164, Thanks for looking into this. However I don't think we want to support that setup.
IIRC, in that setup you have an external module (the library) which is forced as a dependency manually adding a line like:
pod <your library>, path <path to the folder that contains the podspec>
This is a development setup, which I don't think we would want in production.
For that development purposes, I think that the best solution should be to consider the component as part of the
Example
app, like we do with the component ofpackages/rn-tester
.This is a set up that we actually already support in the
generate-artifact-executor,js
file. This function reads the libraries from the app configur…