Sargun Vohra
07/01/2025, 5:16 PMconst { PokeApi } = require('pokekotlin').co.pokeapi.pokekotlin
Is there any way to override that namespacing so JS users can use my library like:
const { PokeApi } = require('pokekotlin')
Or alternatively, is there a way to include some custom js and .d.ts in my Kotlin/JS library export? So I can define an index.js myself that re-exports my declarations from the root
My goal is to have a single KMP library with an idiomatic API for Kotlin, Java, JS/TS, and Swift/ObjC, but the package name being exposed to JS is awkward there. It’s more than just the import syntax; LSP tooling like automatic imports and stuff don’t work well when the importable declarations are buried under a package hierarchy.Edoardo Luppi
07/01/2025, 7:02 PMSargun Vohra
07/01/2025, 7:36 PMkotlin {
js(IR) {
browser()
nodejs()
useEsModules()
binaries.library()
generateTypeScriptDefinitions()
}
}
and it seems to work in both browser and nodejs. I don’t care too much about losing commonjs support; many libraries have moved on to ESM-only so I have no problem doing that tooEdoardo Luppi
07/01/2025, 7:45 PM