Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: configure cli for Android only when RNCLI version >= 9.0.0 #1615

Merged
merged 1 commit into from Oct 12, 2022

Conversation

kkafar
Copy link
Member

@kkafar kkafar commented Oct 12, 2022

Description

Fixes #1614

#1611 added react-native.config.js file to the library which uses features supported since @react-native-cli@9.0.0 thus causing library fail to link while on Paper with React Native < 0.70.

This fix is borrowed from react-native-safe-area-context.

Changes

Added check for @react-native-community/cli-platform-android version in react-native.config.js.

Test code and steps to reproduce

--

Checklist

  • Ensured that CI passes

@kkafar kkafar merged commit 0f684a7 into main Oct 12, 2022
@kkafar kkafar deleted the @kkafar/fix-1614 branch October 12, 2022 14:18
kkafar added a commit that referenced this pull request Oct 24, 2022
….js` (#1624)

## Description

#1615 introduced a check for RNCLI version inside library, to avoid
crashes when client project uses version < 9.0.0, however due to [how
node resolution algorithm
works](https://nodejs.org/api/modules.html#loading-from-node_modules-folders),
when launching example Fabric applications [the
line](https://github.com/software-mansion/react-native-screens/blob/49cc61e1fa9926a671d32bbb634a2c43c999e122/react-native.config.js#L4)]:

```js
require('@react-native-community/cli-platform-android/package.json').version;
```

resolved version from library's `node_modules` instead of that of
application. This to our custom component descriptors not being
registered, as `react-native-screens` still depends on
`react-native@0.63`, thus resolved RNCLI version is 4.x.x

I've tried writing custom module resolver for metro, but it is bypassed
as the `react-native.config.js` [is evaluated directly via
`node`](https://github.com/react-native-community/cli/blob/aed2572ccf03552d5ad82e104682f86291255f8a/packages/cli-platform-android/native_modules.gradle#L425-L451)
- I was not able to intercept this `require` call in custom metro module
resolver.

Hence I decided to add direct **`devDependency`** (it should not impact
client applications) and override any other version by using [yarn
"resolutions"
mechanism](https://classic.yarnpkg.com/lang/en/docs/selective-version-resolutions/).

## Changes

Added direct dev dependency on:

```json
"@react-native-community/cli": "^9.0.0",
"@react-native-community/cli-platform-android": "^9.0.0",
"@react-native-community/cli-platform-ios": "^9.0.0",
```

and overrided any other version with resolutions mechanism.


## Test code and steps to reproduce

Build & run `FabricTestExample`.

I tested the change on `FabricTestExample` & fresh RN applications
(0.68, 0.69, 0.70)

## Checklist

- [ ] Ensured that CI passes
grahammendick added a commit to grahammendick/navigation that referenced this pull request Oct 29, 2022
Copied this from react-native-screens, which copied it from react-native-safe-area-context (software-mansion/react-native-screens#1615). Don't use the new codegen features on React Native < 0.70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3.18.1] requireNativeComponent: "RNSScreenStackHeaderConfig" was not found in the UIManager
1 participant