Skip to content

Commit c6c2304

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
iOS Codegen: bring back support for defining external libraries in react-native.config.js (#42771)
Summary: Pull Request resolved: #42771 This feature was first introduced here #34580 And then removed here #41654 The motivation for its removing was that Node resolver should handle all those cases for which `react-native.config.js` was used. But it turns out that it fails for the setup that `react-native-builder-bob` has. This diff brings back support for defining external libraries in `react-native.config.js`. Changelog: [iOS][Fixed] - Bring back support for defining external libraries in react-native.config.js Reviewed By: cipolleschi Differential Revision: D53267857 fbshipit-source-id: 7625dfe7b4a4651eb60eaec725f94f222a244e30
1 parent 7b36233 commit c6c2304

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,48 @@ function findExternalLibraries(pkgJson) {
227227
});
228228
}
229229

230+
function findLibrariesFromReactNativeConfig(projectRoot) {
231+
const rnConfigFileName = 'react-native.config.js';
232+
233+
console.log(
234+
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${rnConfigFileName}`,
235+
);
236+
237+
const rnConfigFilePath = path.resolve(projectRoot, rnConfigFileName);
238+
239+
if (!fs.existsSync(rnConfigFilePath)) {
240+
return [];
241+
}
242+
const rnConfig = require(rnConfigFilePath);
243+
244+
if (rnConfig.dependencies == null) {
245+
return [];
246+
}
247+
return Object.keys(rnConfig.dependencies).flatMap(name => {
248+
const dependencyConfig = rnConfig.dependencies[name];
249+
250+
if (!dependencyConfig.root) {
251+
return [];
252+
}
253+
const codegenConfigFileDir = path.resolve(
254+
projectRoot,
255+
dependencyConfig.root,
256+
);
257+
let configFile;
258+
try {
259+
configFile = readPkgJsonInDirectory(codegenConfigFileDir);
260+
} catch {
261+
return [];
262+
}
263+
264+
return extractLibrariesFromJSON(
265+
configFile,
266+
configFile.name,
267+
codegenConfigFileDir,
268+
);
269+
});
270+
}
271+
230272
function findProjectRootLibraries(pkgJson, projectRoot) {
231273
console.log('[Codegen] Searching for codegen-enabled libraries in the app.');
232274

@@ -447,7 +489,11 @@ function findCodegenEnabledLibraries(pkgJson, projectRoot) {
447489
if (pkgJsonIncludesGeneratedCode(pkgJson)) {
448490
return projectLibraries;
449491
} else {
450-
return [...projectLibraries, ...findExternalLibraries(pkgJson)];
492+
return [
493+
...projectLibraries,
494+
...findExternalLibraries(pkgJson),
495+
...findLibrariesFromReactNativeConfig(projectRoot),
496+
];
451497
}
452498
}
453499

0 commit comments

Comments
 (0)