Skip to content

Commit

Permalink
fix: fix codegen not finding all third-party libraries (#42943)
Browse files Browse the repository at this point in the history
* fix: fix codegen failing in pnpm setups

* fix third-party libs not being detected
  • Loading branch information
tido64 committed Feb 19, 2024
1 parent af224d7 commit 67e2bb4
Showing 1 changed file with 18 additions and 11 deletions.
Expand Up @@ -32,7 +32,13 @@ const REACT_NATIVE_PACKAGE_ROOT_FOLDER = path.join(__dirname, '..', '..');

const CODEGEN_DEPENDENCY_NAME = '@react-native/codegen';
const CODEGEN_REPO_PATH = `${REACT_NATIVE_REPOSITORY_ROOT}/packages/react-native-codegen`;
const CODEGEN_NPM_PATH = `${REACT_NATIVE_PACKAGE_ROOT_FOLDER}/../${CODEGEN_DEPENDENCY_NAME}`;
// This is a change for 0.73-stable only since this piece of code was replaced:
// https://github.com/facebook/react-native/commit/9071a3a0b0e11ad711927651bcb2412f553b6fe9
const CODEGEN_NPM_PATH = path.dirname(
require.resolve(path.join(CODEGEN_DEPENDENCY_NAME, 'package.json'), {
paths: [REACT_NATIVE_PACKAGE_ROOT_FOLDER],
}),
);
const CORE_LIBRARIES_WITH_OUTPUT_FOLDER = {
rncore: path.join(REACT_NATIVE_PACKAGE_ROOT_FOLDER, 'ReactCommon'),
FBReactNativeSpec: null,
Expand Down Expand Up @@ -189,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
}
});
}
Expand Down

0 comments on commit 67e2bb4

Please sign in to comment.