Hey! It looks like `kotlin.js.compilerOptions.sour...
# javascript
d
Hey! It looks like
kotlin.js.compilerOptions.sourceMapEmbedSources
is not correctly taken in account. I have to directly use
-source-map-embed-sources
option the
freeCompilerArgs
. Details in 🧵. (Kotlin 2.4)
I don't get the sources embedded in the source maps if I do:
Copy code
kotlin {
    js {
        useEsModules()

        compilerOptions {
            target = "es2015"
            freeCompilerArgs.add("-Xes-long-as-bigint")

            sourceMapEmbedSources = JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_ALWAYS
        }
        generateTypeScriptDefinitions()

        binaries.library()
    }
}
And if I explicitly set the
-source-map-embed-sources always
, then the sources are embedded but I get a warning telling me the argument is passed multiple times (values being: never, always).
Copy code
kotlin {
    js {
        useEsModules()

        compilerOptions {
            target = "es2015"
            freeCompilerArgs.add("-Xes-long-as-bigint")

            sourceMapEmbedSources = JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_ALWAYS
            freeCompilerArgs.addAll("-source-map-embed-sources", "always")
        }
        generateTypeScriptDefinitions()

        binaries.library()
    }
}
This produces the following warnings:
Copy code
> Task :xyz:compileKotlinJs
w: Argument '-source-map-embed-sources' is passed multiple times: 'never', 'always'. The last value will be used.

> Task :xyz:compileProductionLibraryKotlinJs
w: Argument '-source-map-embed-sources' is passed multiple times: 'never', 'always'. The last value will be used.
It is as if the
sourceMapEmbedSources
was ignored and the compiler option was incorrectly initialized somewhere.
It looks like if I set the
sourceMapEmbedSources
directly in the sub target the compiler option is correctly initialized.
But then how can I configure this for any of the defined sub-targets in convention plugins? Scratch that. The behavior is the same.
sourceMapEmbedSources
is simply ignored whether it is defined in
kotlin.js.compilerOptions
or
kotlin.js.nodeJs.compilerOptions
. And using
freeCompilerArgs.addAll("-source-map-embed-sources", "always")
is the only way to force the source embedding (though it produces the above warnings). @Artem Kobzar is this a known bug?
e
Try this.
Copy code
tasks.withTypeKotlin2JsCompile().configureEach {
  compilerOptions {
    sourceMap.set(true)
    sourceMapEmbedSources.set(JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_ALWAYS)
  }
}
a
@Didier Villevalois oh, I don't think it's something known. Could you please also try to configure it as @Edoardo Luppi proposed? If it works, please let me know so we will create a ticket that compilerOptions aren't provided to the link task(
d
@Artem Kobzar yeah, I confirm that configuring at the task level works as expected. So indeed it seems that only the extension compilerOptions to task compilerOptions wiring is failing.
Do you want me to create a ticket?
a
@Didier Villevalois it would be awesome, thank you 🙏
👍 1
d