Skip to content

Commit e5bc12c

Browse files
committed
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 <img width="856" alt="Screenshot 2024-09-10 at 15 34 41" src="https://github.com/user-attachments/assets/9ad9b790-d3fa-4907-b9ee-f5e682f38858"> ## 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. (cherry picked from commit 8b56020)
1 parent d2b934a commit e5bc12c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import org.gradle.api.artifacts.UnresolvedDependency
1212
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
1313
import org.gradle.api.file.DuplicatesStrategy
1414
import org.gradle.api.provider.Provider
15+
import org.gradle.api.tasks.Copy
1516
import org.gradle.language.jvm.tasks.ProcessResources
1617
import org.jetbrains.compose.ComposeBuildConfig
1718
import org.jetbrains.compose.ComposeExtension
1819
import org.jetbrains.compose.internal.utils.detachedComposeDependency
20+
import org.jetbrains.compose.internal.utils.file
1921
import org.jetbrains.compose.internal.utils.registerTask
2022
import org.jetbrains.compose.web.WebExtension
2123
import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask
@@ -71,7 +73,8 @@ internal fun configureWebApplication(
7173
it.addLater(skikoJsWasmRuntimeDependency)
7274
}
7375

74-
val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-wasm")
76+
val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-for-web-runtime")
77+
val processedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-runtime-processed-wasmjs")
7578
val taskName = "unpackSkikoWasmRuntime"
7679

7780
val unpackRuntime = project.registerTask<UnpackSkikoWasmRuntimeTask>(taskName) {
@@ -83,6 +86,25 @@ internal fun configureWebApplication(
8386
outputDir.set(unpackedRuntimeDir)
8487
}
8588

89+
val processSkikoRuntimeForKWasm = project.registerTask<Copy>("processSkikoRuntimeForKWasm") {
90+
dependsOn(unpackRuntime)
91+
from(unpackedRuntimeDir)
92+
into(processedRuntimeDir)
93+
94+
doLast {
95+
// TODO: in the next versions we can simply filter skiko.js out for k/wasm target
96+
processedRuntimeDir.file("skiko.js").get().apply {
97+
asFile.appendText("\n\n// Warn about skiko.js redundancy in case of K/Wasm target:\n")
98+
asFile.appendText(
99+
"""console.warn("Note: skiko.js is redundant in K/Wasm Compose for Web applications.
100+
|Consider removing it from index.html,
101+
|it will be removed from the distribution in next Compose Multiplatform versions");
102+
""".trimMargin().replace("\n", "")
103+
)
104+
}
105+
}
106+
}
107+
86108
targets.forEach { target ->
87109
target.compilations.all { compilation ->
88110
// `wasmTargetType` is available starting with kotlin 1.9.2x
@@ -92,8 +114,8 @@ internal fun configureWebApplication(
92114
// So that’s why we need to provide skiko.mjs and skiko.wasm only for webpack, but not in the final dist.
93115
compilation.binaries.all {
94116
it.linkSyncTask.configure {
95-
it.dependsOn(unpackRuntime)
96-
it.from.from(unpackedRuntimeDir)
117+
it.dependsOn(processSkikoRuntimeForKWasm)
118+
it.from.from(processedRuntimeDir)
97119
}
98120
}
99121
} else {

gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class GradlePluginTest : GradlePluginTestBase() {
4646
jsCanvasEnabled(true)
4747
gradle(":build").checks {
4848
check.taskSuccessful(":unpackSkikoWasmRuntime")
49+
check.taskSuccessful(":processSkikoRuntimeForKWasm")
4950
check.taskSuccessful(":compileKotlinJs")
5051
check.taskSuccessful(":compileKotlinWasmJs")
5152
check.taskSuccessful(":wasmJsBrowserDistribution")
@@ -69,6 +70,7 @@ class GradlePluginTest : GradlePluginTestBase() {
6970
val distributionFiles = listFiles()!!.map { it.name }.toList()
7071
assertTrue(distributionFiles.contains("skiko.wasm"))
7172
assertTrue(distributionFiles.contains("skiko.js"))
73+
assertFalse(this.resolve("skiko.js").readText().contains("skiko.js is redundant"))
7274
}
7375
}
7476
}

0 commit comments

Comments
 (0)