Hey, I was wondering if it is possible to publish ...
# javascript
m
Hey, I was wondering if it is possible to publish have Kotlin/Js project for node so it's accessible through Typescript, the usage is simple, I have serializable classes in the backend and being able to re-use it in the frontend (react) without needing to re-make them in Typescript would be awesome.
e
Yes, it is possible with a combination of
binaries.library()
and
generateTypeScriptDefinitions()
. To publish to npm, in case you need to do it, using Gradle refer to https://github.com/DanySK/npm-publish
m
Hey, I gave this a try but for some reason it doesn't seem to include any of the code from commonMain, the final d.ts is empty (has like 4 lines of default code and that's it). Not really sure what I am doing wrong.
Copy code
plugins {
    id("backend.multiplatform")
    id("org.danilopianini.npm.publish") version "4.0.7"
}

kotlin {
    jvm()
    js(IR) {
        nodejs()
        binaries.library()
        generateTypeScriptDefinitions()
    }

    sourceSets {
        commonMain {
            dependencies {
                api(libs.serialization.json)
            }
        }
    }
}

npmPublish {
    registries {
        // For registries expecting an authentiation token, use authToken
        register("npmjs") {
            uri.set("<https://registry.npmjs.org>")
            authToken.set("redacted")
        }

        packages {
            named("js") {
                packageName.set("my-package-name")
                scope.set("my-scope")
                version.set(project.version.toString())
            }
        }
    }
}
Figured it out, was missing the
@JsExport
annotation sorry 😅