Skip to content

Commit

Permalink
Fixed wrong usage of require when resolving supportsCodegenConfig in …
Browse files Browse the repository at this point in the history
…react-native.config.js (#657)

* Fixed wrong usage of require when resolving supportsCodegenConfig

When resolving the version inside `react-native-config` which is used by the autolinking gradle tasks, the wrong use of require was used.

This fix changes from using `require.main.require` -> `require`.

The difference is that require.main.require resolves from the entry point (main script), while require resolves from the location of the current file.

* Codereview: Removed test for code gen alltogether
  • Loading branch information
chrfalch authored Oct 11, 2024
1 parent e870106 commit b528795
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions package/react-native.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
let supportsCodegenConfig = false;
try {
const rnCliAndroidVersion = require.main.require(
'@react-native-community/cli-platform-android/package.json',
).version;
const [major] = rnCliAndroidVersion.split('.');
supportsCodegenConfig = major >= 9;
} catch (e) {
// ignore
}

module.exports = {
dependency: {
platforms: {
android: supportsCodegenConfig
? {
libraryName: 'RNCSlider',
componentDescriptors: ["RNCSliderComponentDescriptor"],
cmakeListsPath: 'src/main/jni/CMakeLists.txt',
}
: {},
android: {
libraryName: 'RNCSlider',
componentDescriptors: ['RNCSliderComponentDescriptor'],
cmakeListsPath: 'src/main/jni/CMakeLists.txt',
},
},
},
};

0 comments on commit b528795

Please sign in to comment.