Edoardo Luppi
03/02/2024, 2:32 PMnode
or browser
?
Example:
compilations.configureEach {
binaries.forEach {
// Here I can get jsDevelopmentLibraryDistribution, but I'm missing the Node or Browser disambiguation
val distributionTaskName = distributionTaskName(it)
jw
03/02/2024, 2:44 PMEdoardo Luppi
03/02/2024, 2:52 PMKotlinJsIrSubTarget
uses:
val distributionTask = registerSubTargetTask<Task>(
disambiguateCamelCased(
binary.name,
DISTRIBUTION_TASK_NAME
)
)
Where disambiguateCamelCased
is
lowerCamelCaseName(
target.disambiguationClassifier /* js */,
disambiguationClassifier /* node | browser */,
*names
)
So you end up with two distribution tasks for Node and browser, e.g.:
jsNodeDevelopmentLibraryDistribution
and jsBrowserDevelopmentLibraryDistribution
Those are the names I need to getEdoardo Luppi
03/02/2024, 4:40 PMinternal fun KotlinJsCompilation.distributionTaskNames(binary: JsBinary): List<String> {
val tasks = ArrayList<String>(2)
if (isNodeCompilation()) {
tasks.add(lowerCamelCaseName(target.disambiguationClassifier, "node", binary.name, "distribution"))
}
if (isBrowserCompilation()) {
tasks.add(lowerCamelCaseName(target.disambiguationClassifier, "browser", binary.name, "distribution"))
}
return tasks
}
internal fun KotlinJsCompilation.isNodeCompilation(): Boolean {
val target = target
return target is KotlinJsSubTargetContainerDsl && target.isNodejsConfigured
}
internal fun KotlinJsCompilation.isBrowserCompilation(): Boolean {
val target = target
return target is KotlinJsSubTargetContainerDsl && target.isBrowserConfigured
}
Not sure if there is a better way.Artem Kobzar
03/04/2024, 9:30 AMIlya Goncharov [JB]
03/04/2024, 10:04 AMKotlinJsTarget
indeed, and now all related properties about disambiguation classifier are privateEdoardo Luppi
03/04/2024, 10:14 AMnodejs()
and browser()
activations.
However I'm stuck in how to do the same thing with test compilations, for example, how do I get to build this task name?
jsTestTestDevelopmentExecutableCompileSync
Edoardo Luppi
03/04/2024, 10:15 AMcompilations.configureEach {
val isTestCompilation = compilationName.startsWith("test")
val distributionTaskNames = mutableListOf<String>()
binaries.forEach {
val taskNames = if (isTestCompilation) {
listOf("jsTestTestDevelopmentExecutableCompileSync")
} else {
it.distributionTaskNames()
}
distributionTaskNames.addAll(taskNames)
// Register a task to allow starting a debug session.
// Obviously we want it only for development purposes.
if (it.mode == KotlinJsBinaryMode.DEVELOPMENT && target.isNodeConfigured()) {
VSCodeExecTask.create(compilation = this) {
dependsOn(taskNames.first())
debug.set(true)
}
}
}