Skip to content

Commit

Permalink
Make web.application non-experimental (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyTsvetkov authored Feb 21, 2022
1 parent 91fdcb8 commit ea778fb
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 90 deletions.
2 changes: 1 addition & 1 deletion experimental/examples/falling-balls-mpp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ compose.desktop {
}
}

compose.experimental {
compose {
web.application {}
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/examples/minesweeper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ compose.desktop {
}
}

compose.experimental {
compose {
web.application {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ import org.jetbrains.compose.desktop.application.internal.ComposeProperties
import org.jetbrains.compose.desktop.application.internal.configureApplicationImpl
import org.jetbrains.compose.desktop.application.internal.currentTarget
import org.jetbrains.compose.desktop.preview.internal.initializePreview
import org.jetbrains.compose.experimental.dsl.ExperimentalExtension
import org.jetbrains.compose.experimental.internal.configureExperimental
import org.jetbrains.compose.internal.COMPOSE_PLUGIN_ID
import org.jetbrains.compose.internal.KOTLIN_JS_PLUGIN_ID
import org.jetbrains.compose.internal.KOTLIN_MPP_PLUGIN_ID
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.web.internal.configureWebApplication
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

Expand All @@ -39,14 +35,13 @@ class ComposePlugin : Plugin<Project> {
val composeExtension = project.extensions.create("compose", ComposeExtension::class.java)
val desktopExtension = composeExtension.extensions.create("desktop", DesktopExtension::class.java)
val androidExtension = composeExtension.extensions.create("android", AndroidExtension::class.java)
val experimentalExtension = composeExtension.extensions.create("experimental", ExperimentalExtension::class.java)
val webExtension = composeExtension.extensions.create("web", WebExtension::class.java)

if (!project.buildFile.endsWith(".gradle.kts")) {
setUpGroovyDslExtensions(project)
}

project.initializePreview()
composeExtension.extensions.create("web", WebExtension::class.java)

project.plugins.apply(ComposeCompilerKotlinSupportPlugin::class.java)

Expand All @@ -57,7 +52,7 @@ class ComposePlugin : Plugin<Project> {
configureApplicationImpl(project, desktopExtension.application)
}

project.configureExperimental(composeExtension, experimentalExtension)
configureWebApplication(project, webExtension)

if (androidExtension.useAndroidX) {
project.logger.warn("useAndroidX is an experimental feature at the moment!")
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@

package org.jetbrains.compose.web

import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.model.ObjectFactory
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.compose.web.dsl.WebApplication
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import javax.inject.Inject

abstract class WebExtension : ExtensionAware {
@get:Inject
internal abstract val objects: ObjectFactory

internal var _isApplicationInitialized = false
private set

val application: WebApplication by lazy {
_isApplicationInitialized = true
objects.newInstance(WebApplication::class.java, "main")
}

fun application(fn: Action<WebApplication>) {
fn.execute(application)
}

private var requestedTargets: Set<KotlinJsIrTarget>? = null
private var targetsToConfigure: Set<KotlinJsIrTarget>? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

package org.jetbrains.compose.experimental.dsl
package org.jetbrains.compose.web.dsl

import javax.inject.Inject

abstract class ExperimentalWebApplication @Inject constructor(
abstract class WebApplication @Inject constructor(
@Suppress("unused")
val name: String,
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

package org.jetbrains.compose.experimental.web.internal
package org.jetbrains.compose.web.internal

import org.jetbrains.compose.experimental.dsl.ExperimentalWebApplication
import org.gradle.api.Project
import org.jetbrains.compose.internal.registerTask
import org.jetbrains.compose.experimental.web.tasks.ExperimentalUnpackSkikoWasmRuntimeTask
import org.jetbrains.compose.web.WebExtension
import org.jetbrains.compose.web.dsl.WebApplication
import org.jetbrains.compose.web.tasks.AbstractUnpackSkikoWasmRuntimeTask
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget

internal fun KotlinJsIrTarget.configureExperimentalWebApplication(app: ExperimentalWebApplication) {
internal fun configureWebApplication(project: Project, webExtension: WebExtension) {
if (webExtension._isApplicationInitialized) {
for (jsTarget in webExtension.targetsToConfigure(project)) {
jsTarget.configureWebApplication(webExtension.application)
}
}
}

private fun KotlinJsIrTarget.configureWebApplication(app: WebApplication) {
val mainCompilation = compilations.getByName("main")
val unpackedRuntimeDir = project.layout.buildDirectory.dir("compose/skiko-wasm/$targetName")
val taskName = "unpackSkikoWasmRuntime${targetName.capitalize()}"
mainCompilation.defaultSourceSet.resources.srcDir(unpackedRuntimeDir)
val unpackRuntime = project.registerTask<ExperimentalUnpackSkikoWasmRuntimeTask>(taskName) {
val unpackRuntime = project.registerTask<AbstractUnpackSkikoWasmRuntimeTask>(taskName) {
runtimeClasspath = project.configurations.getByName(mainCompilation.runtimeDependencyConfigurationName)
outputDir.set(unpackedRuntimeDir)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/

package org.jetbrains.compose.experimental.web.tasks
package org.jetbrains.compose.web.tasks

import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.Configuration
Expand All @@ -14,7 +14,7 @@ import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.jetbrains.compose.internal.debug

abstract class ExperimentalUnpackSkikoWasmRuntimeTask : DefaultTask() {
abstract class AbstractUnpackSkikoWasmRuntimeTask : DefaultTask() {
@get:InputFiles
lateinit var runtimeClasspath: Configuration

Expand Down

0 comments on commit ea778fb

Please sign in to comment.