andylamax
12/01/2023, 7:57 PMkotlin-wrappers:kotlin-react-core
is an amazing library filled with very well described externals for react. I like how it is separated from kotlin-react
which brings convenience functions to be used from kotlin. However, I have faced some challenges using these wrappers on our own kotlin/react library that has got to be consumed from typescript
When we publish our kotlin/react library, it ends up having a react dependency in it's package.json
which forces our consumers to update to the react version from kotlin-wrappers:kotlin-react
and kotlin-wrappers:kotlin-react-core
as bundled by our kotlin/react library.
This can be challenging and problematic. My request to @turansky is can we add react
as an peerDependency
to kotlin-wrappers:kotlin-react
and kotlin-wrappers:kkotlin-react-core
so that our users won't be forced to use react
that comes from these amazing libraryturansky
12/01/2023, 8:58 PMpackage.json
via special Gradle taskandylamax
12/02/2023, 12:17 AMjsMainApi(npm("react"))
into
jsMainApi(npmPeer("react"))
be the best solution and benefit all consumers???turansky
12/02/2023, 2:44 AMbe the best solution and benefit all consumers???And as result we will receive random React version in application 😞 It's not what I expect.
What if you will declare peer dependency in library? Will it work?Copy codejsMainApi(npmPeer("react"))
andylamax
12/02/2023, 8:03 AMAnd as a result we will receive random react version
this can be mitigated by explicitly adding the react dependency you need to use your final appllication (not library code)
jsMainApi(wrappers.react.core)
jsMainApi(npm("react","x.x.x"))
and library authors can let the consumers pick their own react versionsandylamax
12/02/2023, 8:05 AMwhat if you will declare peer dependency in library??
I honestly haven't tried that, is this the best long term solution?? shouldn't a library like this (like many react libraries) have react as a peer dependency instead of it being a direct dependency??
andylamax
12/02/2023, 8:40 AMjsMainApi(peerNpm("react"))
does seem to move react from core dependency into peerDependencies. That's a huge plus. this does solve my issue with forcing users onto a specific react depedency
Though my problem has been fully solved, My question still remains though.
is it the best solution to define react as a core dependency in a library??andylamax
12/02/2023, 8:52 AM@tanstack/react-table
defines react as a peerDependency, kotlin-tanstack-react-table
has react as a depedency
• react-router
defines react as a peer and dev dependency, kotlin-react-router
defines it as a core dependency
• react-select
defines react as a peer dependency, kotlin-react-select
defines it as a core dependency
I can keep going on this, but the the general takeaway is that, these libraries should really not force the consumer into the version they are developed on.
The libraries themselves can however enforce the version of react they are targeting using devNpm
, but allowing users to pick their own react versions.
BTW, This whole logic applies beyond reactturansky
12/02/2023, 9:24 AMpackage.json
and you can describe your library rules and versions.
For application developers we fix versions which we support in wrappers. They receive dependencies by default and it's what we want.
If you wanna have all NPM dependencies as peer dependencies - you have extension point.andylamax
12/02/2023, 10:56 AMFor application developers we fix versions which we support in wrappersBut
kotlin-react
and kotlin-react-core
is not an application but a library, don't you think it'd be wise to follow the guidelines of a library.
This is same as gradle's enforcePlatform
. I'll advised for a library, but a good option for an applicationturansky
12/02/2023, 11:04 AMturansky
12/02/2023, 11:25 AMMy question still remains though.
is it the best solution to define react as a core dependency in a library??As you see - you have full control inside your project. Application developers have synchronized Gradle and NPM dependencies by default. Library developers can move some dependencies (all or some of them) in "peer" section if they want.