[Gradle, JS] NodeJs on binaries
This commit is contained in:
+15
-11
@@ -27,7 +27,8 @@ constructor(
|
||||
val project: Project
|
||||
get() = target.project
|
||||
|
||||
private val nameToBinary = mutableMapOf<String, JsBinary>()
|
||||
private val binaryNames = mutableSetOf<String>()
|
||||
private val compilationToBinaries = mutableMapOf<KotlinJsCompilation, MutableSet<JsBinary>>()
|
||||
|
||||
private val defaultCompilation: KotlinJsCompilation
|
||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
@@ -50,15 +51,12 @@ constructor(
|
||||
)
|
||||
|
||||
internal fun getBinary(
|
||||
buildVariantKind: BuildVariantKind,
|
||||
jsBinaryType: JsBinaryType
|
||||
compilation: KotlinJsCompilation,
|
||||
buildVariantKind: BuildVariantKind
|
||||
): JsBinary =
|
||||
nameToBinary.getValue(
|
||||
generateBinaryName(
|
||||
buildVariantKind,
|
||||
jsBinaryType
|
||||
)
|
||||
)
|
||||
compilationToBinaries.getValue(
|
||||
compilation
|
||||
).single { it.type == buildVariantKind }
|
||||
|
||||
|
||||
private fun <T : JsBinary> createBinaries(
|
||||
@@ -73,13 +71,19 @@ constructor(
|
||||
jsBinaryType
|
||||
)
|
||||
|
||||
require(name !in nameToBinary) {
|
||||
require(name !in binaryNames) {
|
||||
"Cannot create binary $name: binary with such a name already exists"
|
||||
}
|
||||
|
||||
val binary = create(name, buildVariantKind, compilation)
|
||||
add(binary)
|
||||
nameToBinary[binary.name] = binary
|
||||
with(compilationToBinaries[compilation]) {
|
||||
if (this != null) {
|
||||
add(binary)
|
||||
} else {
|
||||
compilationToBinaries[compilation] = mutableSetOf<JsBinary>(binary)
|
||||
}
|
||||
}
|
||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||
if (this is ExtensionAware) {
|
||||
extensions.add(binary.name, binary)
|
||||
|
||||
+10
-12
@@ -36,6 +36,9 @@ abstract class KotlinJsIrSubTarget(
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
protected val binaries: KotlinJsBinaryContainer
|
||||
get() = target.binaries
|
||||
|
||||
internal fun configure() {
|
||||
target.binaries.testExecutable()
|
||||
|
||||
@@ -44,15 +47,10 @@ abstract class KotlinJsIrSubTarget(
|
||||
configureBuildVariants()
|
||||
configureTests()
|
||||
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
listOf(
|
||||
it.productionLinkTask,
|
||||
it.developmentLinkTask
|
||||
).forEach { taskProvider ->
|
||||
taskProvider.configure {
|
||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||
}
|
||||
binaries.all { binary ->
|
||||
val npmProject = binary.compilation.npmProject
|
||||
binary.linkTask.configure {
|
||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,9 +95,9 @@ abstract class KotlinJsIrSubTarget(
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
testJs.description = testTaskDescription
|
||||
|
||||
val testExecutableTask = target.binaries.getBinary(
|
||||
BuildVariantKind.DEVELOPMENT,
|
||||
JsBinaryType.TEST
|
||||
val testExecutableTask = binaries.getBinary(
|
||||
compilation,
|
||||
BuildVariantKind.DEVELOPMENT
|
||||
).linkTask
|
||||
|
||||
testJs.inputFileProperty.set(
|
||||
|
||||
+7
-2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsNodeDsl
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
|
||||
@@ -30,8 +31,10 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override fun configureRun(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) {
|
||||
val developmentExecutable = binaries.getBinary(compilation, BuildVariantKind.DEVELOPMENT)
|
||||
|
||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
||||
inputFileProperty.set(compilation.developmentLinkTask.map { it.outputFileProperty.get() })
|
||||
inputFileProperty.set(developmentExecutable.linkTask.map { it.outputFileProperty.get() })
|
||||
}
|
||||
target.runTask.dependsOn(runTaskHolder)
|
||||
}
|
||||
@@ -39,8 +42,10 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override fun configureBuild(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) {
|
||||
val productionExecutable = binaries.getBinary(compilation, BuildVariantKind.PRODUCTION)
|
||||
|
||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||
assembleTask.dependsOn(compilation.productionLinkTask)
|
||||
assembleTask.dependsOn(productionExecutable.linkTask)
|
||||
}
|
||||
|
||||
override fun configureBuildVariants() {
|
||||
|
||||
Reference in New Issue
Block a user