Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.jetbrains.compose.resources.ResourcesExtension
import org.jetbrains.compose.resources.configureComposeResources
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.web.internal.configureWeb
import org.jetbrains.compose.web.tasks.configureWebCompatibility
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler

internal val composeVersion get() = ComposeBuildConfig.composeVersion
Expand All @@ -50,13 +49,12 @@ abstract class ComposePlugin : Plugin<Project> {

project.configureComposeResources(resourcesExtension)

project.configureWebCompatibility()
project.configureWeb()

project.configureRuntimeLibrariesCompatibilityCheck()

project.afterEvaluate {
configureDesktop(project, desktopExtension)
project.configureWeb(composeExtension)
project.plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
val mppExt = project.mppExt
project.configureExperimentalTargetsFlagsCheck(mppExt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,75 +5,6 @@

package org.jetbrains.compose.web

import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.jetbrains.compose.internal.kotlinJsExtOrNull
import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.mppExtOrNull
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget

abstract class WebExtension : ExtensionAware {
private var requestedTargets: Set<KotlinJsIrTarget>? = null
private var targetsToConfigure: Set<KotlinJsIrTarget>? = null

// public api
@Suppress("unused")
@Deprecated(
"""By default, Compose is applied to all declared K/JS-IR targets.
If you need to not apply Compose for K/JS, please exclude `KotlinPlatformType.js` from `compose.platformTypes`"""
)
fun targets(vararg targets: KotlinTarget) {
check(requestedTargets == null) {
"compose.web.targets() was already set!"
}

val jsIrTargets = linkedSetOf<KotlinJsIrTarget>()
for (target in targets) {
check(target is KotlinJsIrTarget) {
"""|'${target.name}' is not a JS(IR) target:
|* add `kotlin.js.compiler=ir` to gradle properties;
|* define target as `kotlin { js(IR) { ... } }`
""".trimMargin()
}
jsIrTargets.add(target)
}
requestedTargets = jsIrTargets
}

internal fun targetsToConfigure(project: Project): Set<KotlinJsIrTarget> {
targetsToConfigure =
targetsToConfigure
?: requestedTargets
?: defaultJsTargetsToConfigure(project)

return targetsToConfigure!!
}

private fun defaultJsTargetsToConfigure(project: Project): Set<KotlinJsIrTarget> {
val mppExt = project.mppExtOrNull

if (mppExt != null) {
val mppTargets = mppExt.targets.asMap.values
val jsIRTargets = mppTargets.filterIsInstanceTo(LinkedHashSet<KotlinJsIrTarget>())
return jsIRTargets
}

val jsExt = project.kotlinJsExtOrNull
if (jsExt != null) {
val target = jsExt.js()
return if (target is KotlinJsIrTarget) {
setOf(target)
} else {
project.logger.error(
"w: Default configuration for Compose for Web is disabled: " +
"Compose for Web does not support legacy (non-IR) JS targets"
)
emptySet()
}
}

return emptySet()
}
}
abstract class WebExtension : ExtensionAware
Comment thread
MatkovIvan marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,32 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.language.jvm.tasks.ProcessResources
import org.gradle.work.DisableCachingByDefault
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.internal.mppExt
import org.jetbrains.compose.internal.utils.provider
import org.jetbrains.compose.internal.utils.registerTask
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.reload.gradle.files
import org.jetbrains.compose.web.tasks.registerWebCompatibilityTask
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.targets.js.ir.Executable
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
import org.jetbrains.kotlin.org.apache.commons.compress.harmony.pack200.NewAttributeBands

internal fun Project.configureWeb(
composeExt: ComposeExtension,
) {
val webExt = composeExt.extensions.getByType(WebExtension::class.java)

val targets = webExt.targetsToConfigure(project)
targets.forEach { target ->
configureSkikoWebRuntime(project, target)
configureComposeUiTestExecutableCheck(project, target)
internal fun Project.configureWeb() {
plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
mppExt.targets.withType(KotlinJsIrTarget::class.java).all { target ->
target.configureSkikoWebRuntime()
target.configureComposeUiTestExecutableCheck()
}
registerWebCompatibilityTask(mppExt)
}
}

private fun configureSkikoWebRuntime(
project: Project,
target: KotlinJsIrTarget,
) {
private fun KotlinJsIrTarget.configureSkikoWebRuntime() {
val target = this
val titledTargetName = target.name.replaceFirstChar { it.titlecase() }
val mainCompilation = target.compilations.findByName(KotlinCompilation.MAIN_COMPILATION_NAME)!!
val runtimeDepsConfig = project.configurations.findByName(mainCompilation.runtimeDependencyConfigurationName)!!
Expand Down Expand Up @@ -91,10 +94,8 @@ private fun configureSkikoWebRuntime(
}
}

private fun configureComposeUiTestExecutableCheck(
project: Project,
target: KotlinJsIrTarget,
) {
private fun KotlinJsIrTarget.configureComposeUiTestExecutableCheck() {
val target = this
val titledTargetName = target.name.replaceFirstChar { it.titlecase() }
val checkTask = project.registerTask<CheckComposeUiTestExecutableTask>(
"checkComposeUiTestConfigurationFor$titledTargetName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ abstract class WebCompatibilityTask : DefaultTask() {
}
}

private fun Project.registerWebCompatibilityTask(mppPlugin: KotlinMultiplatformExtension) =
internal fun Project.registerWebCompatibilityTask(mppPlugin: KotlinMultiplatformExtension) =
registerTask<WebCompatibilityTask>("composeCompatibilityBrowserDistribution") {
group = "compose"
description =
Expand Down Expand Up @@ -180,9 +180,3 @@ private fun Project.registerWebCompatibilityTask(mppPlugin: KotlinMultiplatformE

}
}

internal fun Project.configureWebCompatibility() {
plugins.withId(KOTLIN_MPP_PLUGIN_ID) {
project.registerWebCompatibilityTask(mppExt)
}
}
Loading