Skip to content

Commit

Permalink
Add a redundancy warning to skiko.js for k/wasm target
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 some k/wasm  projects still include skiko.js in index.html which leads to extra loading time. The intention is to notify them without causing 404 errors for now.
  • Loading branch information
eymar committed Sep 10, 2024
1 parent d2b934a commit 483e225
Showing 1 changed file with 25 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

0 comments on commit 483e225

Please sign in to comment.