Browse Source

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.
move-tutorials-to-kmp-portal
Oleksandr Karpovich 2 months ago committed by GitHub
parent
commit
8b56020c81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 28
      gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
  2. 2
      gradle-plugins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt

28
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.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.provider.Provider import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Copy
import org.gradle.language.jvm.tasks.ProcessResources import org.gradle.language.jvm.tasks.ProcessResources
import org.jetbrains.compose.ComposeBuildConfig import org.jetbrains.compose.ComposeBuildConfig
import org.jetbrains.compose.ComposeExtension import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.internal.utils.detachedComposeDependency 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.internal.utils.registerTask
import org.jetbrains.compose.web.WebExtension import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask import org.jetbrains.compose.web.tasks.UnpackSkikoWasmRuntimeTask
@ -71,7 +73,8 @@ internal fun configureWebApplication(
it.addLater(skikoJsWasmRuntimeDependency) 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 taskName = "unpackSkikoWasmRuntime"
val unpackRuntime = project.registerTask<UnpackSkikoWasmRuntimeTask>(taskName) { val unpackRuntime = project.registerTask<UnpackSkikoWasmRuntimeTask>(taskName) {
@ -83,6 +86,25 @@ internal fun configureWebApplication(
outputDir.set(unpackedRuntimeDir) outputDir.set(unpackedRuntimeDir)
} }
val processSkikoRuntimeForKWasm = project.registerTask<Copy>("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 -> targets.forEach { target ->
target.compilations.all { compilation -> target.compilations.all { compilation ->
// `wasmTargetType` is available starting with kotlin 1.9.2x // `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. // 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 { compilation.binaries.all {
it.linkSyncTask.configure { it.linkSyncTask.configure {
it.dependsOn(unpackRuntime) it.dependsOn(processSkikoRuntimeForKWasm)
it.from.from(unpackedRuntimeDir) it.from.from(processedRuntimeDir)
} }
} }
} else { } else {

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

@ -46,6 +46,7 @@ class GradlePluginTest : GradlePluginTestBase() {
jsCanvasEnabled(true) jsCanvasEnabled(true)
gradle(":build").checks { gradle(":build").checks {
check.taskSuccessful(":unpackSkikoWasmRuntime") check.taskSuccessful(":unpackSkikoWasmRuntime")
check.taskSuccessful(":processSkikoRuntimeForKWasm")
check.taskSuccessful(":compileKotlinJs") check.taskSuccessful(":compileKotlinJs")
check.taskSuccessful(":compileKotlinWasmJs") check.taskSuccessful(":compileKotlinWasmJs")
check.taskSuccessful(":wasmJsBrowserDistribution") check.taskSuccessful(":wasmJsBrowserDistribution")
@ -69,6 +70,7 @@ class GradlePluginTest : GradlePluginTestBase() {
val distributionFiles = listFiles()!!.map { it.name }.toList() val distributionFiles = listFiles()!!.map { it.name }.toList()
assertTrue(distributionFiles.contains("skiko.wasm")) assertTrue(distributionFiles.contains("skiko.wasm"))
assertTrue(distributionFiles.contains("skiko.js")) assertTrue(distributionFiles.contains("skiko.js"))
assertFalse(this.resolve("skiko.js").readText().contains("skiko.js is redundant"))
} }
} }
} }

Loading…
Cancel
Save