-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Introduce wasmJsBrowserDistribution task #5375
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
Conversation
...lugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
Outdated
Show resolved
Hide resolved
...lugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
Outdated
Show resolved
Hide resolved
Just in case, if it is not already planned, please, fix the PR description before merging (better also before review, if not agreed beforehand):
|
Unfortunately, without contracts onlyIf is not enough
val jsTargetModuleName = jsDistTask.outputModuleName | ||
val wasmTargetModuleName = wasmDistTask.outputModuleName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do both outputModuleName
have some default value when a user doesn't explicitly specify it in the DSL?
When would this be false
?
onlyIf {
jsTargetModuleName != null && wasmTargetModuleName != null
}
} | ||
} | ||
|
||
private fun Project.introduceComposeWebCompatibilityTask(targets: Collection<KotlinJsIrTarget>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some gradle plugin tests in the project.
Would you like to add some tests?
For example:
- a task is created when the condition match and it's not created otherwise
- Run the task and check the output directory exists. And the output directory contains the must-have files (index.html, .js file, wasm file, etc)
...ins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
Outdated
Show resolved
Hide resolved
...ins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
Outdated
Show resolved
Hide resolved
...lugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
Outdated
Show resolved
Hide resolved
...lugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
Outdated
Show resolved
Hide resolved
...lugins/compose/src/main/kotlin/org/jetbrains/compose/web/internal/configureWebApplication.kt
Outdated
Show resolved
Hide resolved
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: Oleksandr Karpovich <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a test with a custom target name wasmJs("myStrangeTarget")
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
wasmDistFiles = tasks.named("wasmJsBrowserDistribution").get().outputs.files | ||
} | ||
|
||
internal fun Project.configureWebCompatibility() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a description what's going here
...ins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
Outdated
Show resolved
Hide resolved
} | ||
|
||
kotlin { | ||
js(IR) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I know, we already don't need IR
here
|
||
kotlin { | ||
js(IR) { | ||
outputModuleName.set("composeApp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to test a custom name here, then you need a different name, because "composeApp" is a name of the module already
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
wasmJs { | ||
outputModuleName.set("composeApp") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what will happen if there is a different name?
...ins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
Outdated
Show resolved
Hide resolved
…/frequent configurations less possible
|
||
copySpec.from(jsDistFiles) { | ||
copySpec.rename { name -> | ||
val moduleName = jsOutputName.get() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Since jsOutputName
and wasmOutputName
are annotated with @Optional
, calling .get()
directly could throw an IllegalStateException
if they're unset.
Would it make sense to either:
- Use
orNull ?: return@rename name
here, or - Remove
@Optional
if these properties are guaranteed to be set by the time the task runs?
This keeps the annotation and implementation consistent 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the task is not expected to run when either of them is not set. There is onlyIf { ... }
checking it.
So yes, they seem to be not Optional
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, that was my point. Since the properties aren't actually optional, removing @Optional
would make it clearer 👍
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
outputDir.file("${jsOutputName.get()}.js").get().asFile.writeText( | ||
fallbackResolverCode | ||
) | ||
|
||
outputDir.file("${wasmOutputName.get()}.js").get().asFile.writeText( | ||
fallbackResolverCode | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val outputDir = outputDir.get().asFile
File(outputDir, jsAppFileName).writeText(fallbackResolverCode)
File(outputDir, wasmAppFileName).writeText(fallbackResolverCode)
...ins/compose/src/test/kotlin/org/jetbrains/compose/test/tests/integration/GradlePluginTest.kt
Outdated
Show resolved
Hide resolved
if (!hasBothDistributions) { | ||
logger.lifecycle("Task ${this.name} skipped: no js and wasm distributions found, both are required for compatibility") | ||
} else if (!hasBothOutputs) { | ||
logger.lifecycle("Task ${this.name} skipped: no js and wasm output names specified") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add tests for this logic too, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add a log check into one of existed tests for other cases with only one of the web targets
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/web/tasks/WebCompatibilityTask.kt
Outdated
Show resolved
Hide resolved
## Testing Clone https://github.com/Schahen/ComposeWebApp and run ``` ./gradlew :composeApp: composeCompatibilityBrowserDistribution ``` ## Release Notes ### Features - Web - Introduce composeCompatibilityBrowserDistribution task. This task combines two prod distributions - for js and for wasm in such way so that if modern require features are not supported by the consumer browser, application switch to js mode. --------- Co-authored-by: Oleksandr Karpovich <[email protected]> Co-authored-by: Konstantin Tskhovrebov <[email protected]>
Testing
Clone https://github.com/Schahen/ComposeWebApp and run
Release Notes
Features - Web
composeCompatibilityBrowserDistribution
task. This task combines two prod distributions - for js and for wasm in such way so that if modern required features are not supported by the consumer browser, application switch to js mode.