1

If I download a Kotlin/JS JAR-files manually from https://search.maven.org/artifact/org.jetbrains.kotlinx/kotlinx-serialization-core/1.3.3/pom or https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-wrappers-bom/1.0.0-pre.501 then the compiled JS-files are not present in the JAR-files. However, if I get them through Gradle and check out the contents of the external libraries then compiled JS-files are present.

I had assumed it was the same JAR-file but apparently not. Is the JAR-file dynamically created due to a specific request from Gradle? Maybe so, since the JS-files downloaded by Gradle only contains the LEGACY output, and that fits with my project still compiling with LEGACY.

I ask because Kotlin/JS can compile with two compilers "simultaneously" (IR and LEGACY by using BOTH), and I wanted to see how the compiled JS-files are structured in third-party libraries when using this.

Jarl
  • 57
  • 8

1 Answers1

1

You're probably looking at the multiplatform module publications instead of the actual JS publication.

The multiplatform modules make use of Gradle variants mechanism in order to find the actual artifacts that need to be downloaded (based on a set of attributes). Following your first link, and browsing the actual files, you'll see a .module file in there. This file is a JSON file which describes a list of artifacts with their attributes, and Gradle will look at this to know what to download.

For example, somewhere in the .module file you'll see:

{
  "name": "jsLegacyApiElements-published",
  "attributes": {
    "org.gradle.category": "library",
    "org.gradle.usage": "kotlin-api",
    "org.jetbrains.kotlin.js.compiler": "legacy",
    "org.jetbrains.kotlin.platform.type": "js"
  },
  "available-at": {
    "url": "../../kotlinx-serialization-core-js/1.3.3/kotlinx-serialization-core-js-1.3.3.module",
    "group": "org.jetbrains.kotlinx",
    "module": "kotlinx-serialization-core-js",
    "version": "1.3.3"
  }
}

So if you actually go to that -js suffixed artifact (where the url field points) instead of the module artifact, you'll find the jars containing the JS code: https://repo1.maven.org/maven2/org/jetbrains/kotlinx/kotlinx-serialization-core-js/1.3.3/

Joffrey
  • 32,348
  • 6
  • 68
  • 100
  • I see that the kotlinx-serialization-core-js-1.3.3.klib file (the one for the IR-version) doesn't contain any JavaScript. With Kotlin-to-JVM-LEGACY-Compiler and Kotlin-to-JS-Legacy-Compiler the JAR-files for libraries contain java-bytecode or JavaScript. But from this I conclude that with Kotlin-to-JS-IR-Compiler the KLIB-files for libraries does not contain JavaScript and that this is generated when the main project is compiled. – Jarl Feb 23 '23 at 14:03
  • 1
    I'm not well versed in the Kotlin/JS internals, but yeah maybe with the IR backend only the IR (intermediate representation) is published as klib, and the final JS is produced when compiling the main project. I can't say for sure, though, that's a question for the Kotlin team – Joffrey Feb 23 '23 at 14:19