JS sources in Kotlin/JS projects

Hello everybody.

In my Kotlin/JS project I’m in need of adding some bare .js sources to the project and I also need to write some Kotlin code exploiting the classes written in JavaScript.
What is the most adequate way of doing so according to your experience?

My solution (publicly available here: parser-js · feature/parser · PIKA-lab / tuProlog / 2P-Kt · GitLab) is based on some custom Gradle tasks aimed at copying all .js files next to the ones compiled by kotlin, upon compilation.
What do you think? Is there any better way?

Sadly, rewriting the code in Kotlin is NOT an option: the .js code is indeed generated by ANTLR (i.e. a parser generator)—which does not support Kotlin code generation ATM.

2 Likes

Hi!

Unfortunately we haven’t this possibility in Gradle plugin yet.
In fact it is some kind of resources. But these resources you need in runtime, and nodejs should know, how to find these modules. So you can’t put it in the resources until we don’t process it specially.
You have good solution for your case. And until we have no this feature in gradle plugin, I think that there is no better way for nodejs.

Feel free to create issue (https://kotl.in/issue) with your use case.

1 Like

https://youtrack.jetbrains.com/issue/KT-36259