TopGit tracks deezer/KustomExport on GitHub. The project has 69 stars. DEPRECATED : A JS facade generator for KotlinJS / KMP
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This tool was helpful with Kotlin 1.5 especially. Since then, Kotlin javascript support has evolved and this tool is not so relevant anymore:
the added cost doesn't deliver enough value (generated code impacts total bundle size).
the extra dependency to this tool is too risky for most projects
as the only developer on it, I'm not using it for years and don't plan to maintain it anymore.
KustomExport: a KSP generator of JS facade
Status: Experimental
At Deezer, we develop KMP libraries, this tool help us provide nicer API for Typescript since November 2021.
The generated code will change to support more features and/or stop supporting features provided by KotlinJS directly, so you may expect breaking changes when upgrading.
Motivation
Providing a nice Typescript API can sometimes be complex/verbose from a Kotlin Multiplatform Project.
A simple example:
// @JsExport // Cannot be annotated in Kotlin 1.6.10 and before
enum class StateEnum { IDLE, RUNNING }
@JsExport
data class SomeDataObject(
val timestamp: Long,
val state: StateEnum,
val idList: List<String>
)
Long will not produce a number but a kotlin.Long behing a any (doc), but web developers usually use number to store timestamp.
Enums are not handled yet (KT-37916) and so exported as any
List could be used in a majority of cases if it was exported in Arrays
Lots of Kotlin methods like componentX, copy, hashCode or equals coming from data class are not really relevant or unusable (copy() should define all fields in typescript anyway)
comments in the Typescript generated code is helpful but only comment and doesn't fail build when type changes
There are some good reasons why it's not supported by KotlinJs right now, but it's not practical to provide a clean Typescript API.
KustomExport wants to be the bridge to provide a nice Typescript API until KotlinJS produces an equivalent export.
Technical approach
A manual way to approach this problem is to write a facade in Kotlin and only @JsExport the facade.
// jsMain/StateEnumJs.kt
// Export the enum in a class, so it's providing a real class in JS instead of 'any'
@JsExport
class StateEnumJs internal constructor(internal val stateEnum: StateEnum) {
val name: String = stateEnum.name
}
fun StateEnumJs.import(): StateEnum = value
fun StateEnum.export(): StateEnumJs = Encoding(this)
// Object that exposes all possible values of the enum (note the 's')
@JsExport
object StateEnumsJs {
val IDLE: StateEnumJs = StateEnumJs(StateEnum.IDLE)
val RUNNING: StateEnumJs = StateEnumJs(StateEnum.RUNNING)
}
// And more methods like values(), valueOf()...
It doesn't scale easily: lots of boilerplate code to maintain.
New feature can be invisible when changes are non-breaking with the facade. A dangerous behaviour for library providers.
It requires calling import()/export() method in many places, leading to a "specific to web" code in your common code.
If you write similar facades yourself, this generator could help you avoid writing them manually. Please open issues with your needs!
Note that it's adding code to your existing codebase, so it will increase your JS bundle size.
Current status
The current project uses Typescript integration tests, feel free to check what's covered in Samples.
What is supported today:
Long to number (by using toLong/toDouble, so be careful with precision issues here!) (doc)
List<...> to Array<...> and it's ready to support more collections, please open a ticket with your needs. (doc)
enum classes (doc)
class / data class (equals/toString/componentX methods are removed) (doc)
functions and dynamic properties are wrapped (ex val rand: Long get() = Random.nextLong() will be wrapped and called again each time the exposed object is called in Typescript)
interfaces (doc)
sealed class
suspend methods with cooperative cancellation (via AbortController)
removing the namespace (optional) (doc)
mixing @JsExport with @KustomExport (experimental)
What is not supported yet:
generics (partially supported, you can generate a list of facades from a single generic class)
Feel free to open issues for more features!
You can have a look to the Samples to have a feel of how it can be used.
Setup
KustomExport use KSP (Kotlin Symbol Processor), and you need to install it in your build.gradle.kts
plugins {
kotlin("multiplatform")
id("com.google.devtools.ksp") version "1.6.21-1.0.5"
}
Then you need to define the dependency to the library
repositories {
mavenCentral()
maven(url = "https://raw.githubusercontent.com/Deezer/KustomExport/mvn-repo")
}
kotlin {
// jvm(), js() and other platforms...
sourceSets {
val commonMain by getting {
dependencies {
implementation("deezer.kustomexport:lib:<version>")
implementation("deezer.kustomexport:lib-coroutines:<version>")
}
}
}
}
/*
* Copyright 2021 Deezer.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
No homepage URL was recorded for deezer/KustomExport in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
Does deezer/KustomExport have any tags?
TopGit's last sync did not record any GitHub topics for deezer/KustomExport. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on deezer/KustomExport?
The most recent commit recorded on deezer/KustomExport was 1.6 years ago, based on the GitHub push timestamp. The repository has 9 forks — one of the better signals of community interest.
How many stars does deezer/KustomExport have?
deezer/KustomExport has 69 GitHub stars — refresh the page for the live number, or check github.com/deezer/KustomExport. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is deezer/KustomExport open source?
Yes — deezer/KustomExport ships under the Apache-2.0 license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/deezer/KustomExport.
Where do I read more about deezer/KustomExport?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/deezer/KustomExport is the definitive source.
Read full README in the tab above.
Is KustomExport worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of KustomExport.