diff --git a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt index 918808a3bf0..f49259f4243 100644 --- a/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt +++ b/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt @@ -12,10 +12,12 @@ import org.gradle.api.artifacts.UnresolvedDependency import org.gradle.api.artifacts.component.ModuleComponentIdentifier import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.provider.Provider +import org.gradle.api.tasks.Copy import org.gradle.language.jvm.tasks.ProcessResources import org.jetbrains.compose.ComposeBuildConfig import org.jetbrains.compose.ComposeExtension import org.jetbrains.compose.internal.utils.detachedComposeDependency +import org.jetbrains.compose.internal.utils.file import org.jetbrains.compose.internal.utils.registerTask import org.jetbrains.compose.web.WebExtension import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask @@ -71,7 +73,8 @@ internal fun configureWebApplication( it.addLater(skikoJsWasmRuntimeDependency) } - val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-wasm") + val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-for-web-runtime") + val processedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-runtime-processed-wasmjs") val taskName = "unpackSkikoWasmRuntime" val unpackRuntime = project.registerTask(taskName) { @@ -83,6 +86,25 @@ internal fun configureWebApplication( outputDir.set(unpackedRuntimeDir) } + val processSkikoRuntimeForKWasm = project.registerTask("processSkikoRuntimeForKWasm") { + dependsOn(unpackRuntime) + from(unpackedRuntimeDir) + into(processedRuntimeDir) + + doLast { + // TODO: in the next versions we can simply filter skiko.js out for k/wasm target + processedRuntimeDir.file("skiko.js").get().apply { + asFile.appendText("\n\n// Warn about skiko.js redundancy in case of K/Wasm target:\n") + asFile.appendText( + """console.warn("Note: skiko.js is redundant in K/Wasm Compose for Web applications. + |Consider removing it from index.html, + |it will be removed from the distribution in next Compose Multiplatform versions"); + """.trimMargin().replace("\n", "") + ) + } + } + } + targets.forEach { target -> target.compilations.all { compilation -> // `wasmTargetType` is available starting with kotlin 1.9.2x @@ -92,8 +114,8 @@ internal fun configureWebApplication( // So that’s why we need to provide skiko.mjs and skiko.wasm only for webpack, but not in the final dist. compilation.binaries.all { it.linkSyncTask.configure { - it.dependsOn(unpackRuntime) - it.from.from(unpackedRuntimeDir) + it.dependsOn(processSkikoRuntimeForKWasm) + it.from.from(processedRuntimeDir) } } } else { diff --git a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt index 458468554ba..37b9c33978c 100644 --- a/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt +++ b/gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt @@ -46,6 +46,7 @@ class GradlePluginTest : GradlePluginTestBase() { jsCanvasEnabled(true) gradle(":build").checks { check.taskSuccessful(":unpackSkikoWasmRuntime") + check.taskSuccessful(":processSkikoRuntimeForKWasm") check.taskSuccessful(":compileKotlinJs") check.taskSuccessful(":compileKotlinWasmJs") check.taskSuccessful(":wasmJsBrowserDistribution") @@ -69,6 +70,7 @@ class GradlePluginTest : GradlePluginTestBase() { val distributionFiles = listFiles()!!.map { it.name }.toList() assertTrue(distributionFiles.contains("skiko.wasm")) assertTrue(distributionFiles.contains("skiko.js")) + assertFalse(this.resolve("skiko.js").readText().contains("skiko.js is redundant")) } } }