Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support org.jetbrains.kotlin.js plugin #1851

Merged
merged 1 commit into from Feb 16, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -137,17 +137,6 @@ class ComposePlugin : Plugin<Project> {
}
}
}

checkAndWarnAboutUsingJsPlugin(project)
}

private fun checkAndWarnAboutUsingJsPlugin(project: Project) {
val msg = "'$COMPOSE_PLUGIN_ID' plugin is not compatible with '$KOTLIN_JS_PLUGIN_ID' plugin. " +
"Use '$KOTLIN_MPP_PLUGIN_ID' instead"

project.plugins.withId(KOTLIN_JS_PLUGIN_ID) {
project.logger.error(msg)
}
}

class RedirectAndroidVariants : ComponentMetadataRule {
Expand Down
Expand Up @@ -12,6 +12,7 @@ import org.gradle.api.tasks.SourceSetContainer
import org.gradle.util.GradleVersion
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJsProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

internal val Project.composeExt: ComposeExtension?
Expand All @@ -26,6 +27,9 @@ internal val Project.mppExt: KotlinMultiplatformExtension
internal val Project.mppExtOrNull: KotlinMultiplatformExtension?
get() = extensions.findByType(KotlinMultiplatformExtension::class.java)

internal val Project.kotlinJsExtOrNull: KotlinJsProjectExtension?
get() = extensions.findByType(KotlinJsProjectExtension::class.java)

internal val Project.javaSourceSets: SourceSetContainer
get() = if (GradleVersion.current() < GradleVersion.version("7.1")) {
convention.getPlugin(JavaPluginConvention::class.java).sourceSets
Expand Down
Expand Up @@ -7,8 +7,10 @@ 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

Expand Down Expand Up @@ -46,16 +48,36 @@ abstract class WebExtension : ExtensionAware {
}

private fun defaultJsTargetsToConfigure(project: Project): Set<KotlinJsIrTarget> {
val mppTargets = project.mppExtOrNull?.targets?.asMap?.values ?: emptySet()
val jsIRTargets = mppTargets.filterIsInstanceTo(LinkedHashSet<KotlinJsIrTarget>())

return if (jsIRTargets.size > 1) {
project.logger.error(
"w: Default configuration for Compose Web is disabled: " +
"multiple Kotlin JS IR targets are defined. " +
"Specify Compose Web Kotlin targets by using `compose.web.targets()`"
)
emptySet()
} else jsIRTargets
val mppExt = project.mppExtOrNull

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

return if (jsIRTargets.size > 1) {
project.logger.error(
"w: Default configuration for Compose for Web is disabled: " +
"multiple Kotlin JS IR targets are defined. " +
"Specify Compose for Web Kotlin targets by using `compose.web.targets()`"
)
emptySet()
} else jsIRTargets
}

val jsExt = project.kotlinJsExtOrNull
if (jsExt != null) {
val target = jsExt.target
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()
}
}