From 8b56020c81a75bc751d9c66ac46f98f583359536 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Wed, 11 Sep 2024 13:48:27 +0200 Subject: [PATCH] Add a redundancy warning to skiko.js for k/wasm target (#5134) skiko.js used to be required for k/wasm projects. But some time ago it was refactored to use skiko.mjs, so skiko.js is not needed anymore (for k/wasm, still needed for k/js). But there are k/wasm projects still including skiko.js in index.html which leads to extra loading time. The intention is to notify them without causing 404 errors for now. ## Testing - updated a test - tested manually Screenshot 2024-09-10 at 15 34 41 ## Release Notes ### Highlights - Web - `skiko.js` is redundant in case of K/Wasm Compose for Web applications and it can be removed from index.html files to not load redundant files. We are going to remove `skiko.js` from the k/wasm distribution in the future releases. `skiko.js` is still needed in case of K/JS Compose for Web apps. --- .../web/internal/configureWebApplication.kt | 28 +++++++++++++++++-- .../tests/integration/GradlePluginTest.kt | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) 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")) } } }