Skip to content

Commit

Permalink
Add a redundancy warning to skiko.js for k/wasm target (#5134)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eymar committed Sep 11, 2024
1 parent 4e6f4ce commit 8b56020
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<UnpackSkikoWasmRuntimeTask>(taskName) {
Expand All @@ -83,6 +86,25 @@ internal fun configureWebApplication(
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 ->
target.compilations.all { compilation ->
// `wasmTargetType` is available starting with kotlin 1.9.2x
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))
}
}
}
Expand Down

0 comments on commit 8b56020

Please sign in to comment.