Skip to content

Commit 67e2bb4

Browse files
authored
fix: fix codegen not finding all third-party libraries (#42943)
* fix: fix codegen failing in pnpm setups * fix third-party libs not being detected
1 parent af224d7 commit 67e2bb4

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

+18-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');
3232

3333
const CODEGEN_DEPENDENCY_NAME = '@react-native/codegen';
3434
const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
35-
const CODEGEN_NPM_PATH = `${REACT_NATIVE_PACKAGE_ROOT_FOLDER}/../${CODEGEN_DEPENDENCY_NAME}`;
35+
// This is a change for 0.73-stable only since this piece of code was replaced:
36+
// https://github.com/facebook/react-native/commit/9071a3a0b0e11ad711927651bcb2412f553b6fe9
37+
const CODEGEN_NPM_PATH = path.dirname(
38+
require.resolve(path.join(CODEGEN_DEPENDENCY_NAME, 'package.json'), {
39+
paths: [REACT_NATIVE_PACKAGE_ROOT_FOLDER],
40+
}),
41+
);
3642
const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
3743
rncore: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
3844
FBReactNativeSpec: null,
@@ -189,33 +195,34 @@ function handleThirdPartyLibraries(
189195
codegenConfigKey,
190196
) {
191197
// Determine which of these are codegen-enabled libraries
192-
const configDir =
193-
baseCodegenConfigFileDir ||
194-
path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, '..');
198+
const configDir = baseCodegenConfigFileDir || process.cwd();
195199
console.log(
196200
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${configDir}`,
197201
);
198202

199203
// Handle third-party libraries
204+
const resolveOptions = {paths: [configDir]};
200205
Object.keys(dependencies).forEach(dependency => {
201206
if (dependency === REACT_NATIVE_DEPENDENCY_NAME) {
202207
// react-native should already be added.
203208
return;
204209
}
205-
const codegenConfigFileDir = path.join(configDir, dependency);
206-
const configFilePath = path.join(
207-
codegenConfigFileDir,
208-
codegenConfigFilename,
209-
);
210-
if (fs.existsSync(configFilePath)) {
210+
211+
try {
212+
const configFilePath = require.resolve(
213+
`${dependency}/${codegenConfigFilename}`,
214+
resolveOptions,
215+
);
211216
const configFile = JSON.parse(fs.readFileSync(configFilePath));
212217
extractLibrariesFromJSON(
213218
configFile,
214219
libraries,
215220
codegenConfigKey,
216221
dependency,
217-
codegenConfigFileDir,
222+
path.dirname(configFilePath),
218223
);
224+
} catch (_) {
225+
// ignore
219226
}
220227
});
221228
}

0 commit comments

Comments
 (0)