Incremental migration of typescript projects to Kotlin

Is there a way to incrementally migrate a TS code base to Kotlin/JS?

A bit of context. I have a Gradle multi-project build which consists of:

  • a Spring Boot server (in Kotlin)
  • a React app (in typescript) built using Create React App and the Gradle node plugin on top of it

I have recently extracted the API client code from the TS subproject into a Kotlin common (multiplatform) subproject of its own.

Now, I’d like to setup a Gradle build for the React app that can depend on the local multiplatform subproject, and that can compile the existing TS files. Is this possible?

(In the end, the goal is to migrate little by little the whole React app to Kotlin)

1 Like

I’m chiming in as I have a very similar need: We have a JavaScript project (that gets build via Gradle) which shares the data model with some Kotlin code. We currently have duplicated the data model classes in Kotlin and JavaScript code. Instead of doing that, we’d like to rewrite the JavaScript code in Kotlin file-by-file.

Is there a way to setup the kotlin-js plugin in a Gradle project so that if there is JavaScript code present it is taken as-is, and if there is Kotlin code present it is transpiled to JavaScript (via TypeScript), and in the end a single web app out of both sources is build?

Indeed, that’s basically what I’m asking as well.

I’d love to be able to have src/main/kotlin alongside src/main/js and setup Gradle to use both.

Did you guys find a solution?

Unfortunately no, I gave up and migrated the whole react application in one go.

You can see my whole project here, if it’s any help:

The sw-ui subproject is the react UI.

Is it not possible to create an intermediate kotlin-JS lib ? Make your current TS/React app depend on it, and slowly convert components to it ?

I do not know how JS/React projects work, so maybe it’s impossible, or involves too many complexities, but I am curious :slight_smile:

Yes and no, the problem lies in “make your current TS/React app depend on it”.

Yes, it is possible to publish a Kotlin/JS lib (especially since the .d.ts generation support was added), BUT my specific problem is that I can’t publish such a library because it’s a local subproject, on which I depend via Gradle’s mechanim: implementation(project("...")).

I wanted modification to the source code of the common module to affect the UI module, without having to publish a new version at every code change, especially when working locally.

Is it possible to achieve in some way? Maybe we could use a yarn- or npm-specific mechanism to depend on a local built file, and from Gradle we could ensure that the library module is compiled first, so that the distribution files are there for npm/yarn to depend on.

Thanks for the details !

I know this is old, but that sounds like a job for yarn link (or npm link) which allow you to use local/dev versions of packages