https://kotlinlang.org logo
j

James

07/28/2023, 2:23 AM
I want to release a Kotlin/JS module that can be used by other Kotlin projects. One of my worries is that I will have to be declaring external functions for each of the projects using the kotlin library. How should I go on about this?
h

hfhbd

07/28/2023, 6:35 AM
You don't need to mark your functions if you only want to consume it from other Kotlin/JS modules, beside change the visibility to
public
of course.
j

James

08/01/2023, 7:32 AM
How would I go on about publishing a js package to npm to be consumed by other Kotlin (js) projects without having to declare externals?
a

andylamax

08/03/2023, 10:55 PM
you just have to export them by marking hem with
@JsExport
annotation
j

James

08/05/2023, 1:57 PM
How would I import this without having to declare externals in another project?
a

andylamax

08/05/2023, 4:05 PM
import is
kotlin.js.JsExport
h

hfhbd

08/05/2023, 9:19 PM
You want to write a Kotlin/JS library, export it as JS (via npm) and consume the npm package by another Kotlin/JS project? This is technically possibly using JsExport, but the JS export lacks many Kotlin types and feature, like kotlin.Long, so you need many workarounds. To consume a Kotlin/JS library you should depend on the published jar file instead.
j

James

08/10/2023, 1:19 PM
Thank you @hfhbd! Will it produce a jar file that can be consumed by another Kotlin.js project?
h

hfhbd

08/10/2023, 3:09 PM
Yes
👀 1