[Gradle, JS] Define compilation on constructor of RequiresNpmDepends
This commit is contained in:
+4
-4
@@ -13,12 +13,12 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractDukatTask : AbstractTask(), RequiresNpmDependencies {
|
||||
abstract class AbstractDukatTask(
|
||||
@Internal
|
||||
override val compilation: KotlinJsCompilation
|
||||
) : AbstractTask(), RequiresNpmDependencies {
|
||||
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
@get:Internal
|
||||
override lateinit var compilation: KotlinJsCompilation
|
||||
|
||||
@get:Internal
|
||||
override val nodeModulesRequired: Boolean
|
||||
get() = true
|
||||
|
||||
+4
-2
@@ -25,8 +25,10 @@ internal class DukatCompilationResolverPlugin(
|
||||
init {
|
||||
compilation.defaultSourceSet.kotlin.srcDir(npmProject.externalsDir)
|
||||
|
||||
val task = project.registerTask<DukatTask>(taskName) {
|
||||
it.compilation = compilation
|
||||
val task = project.registerTask<DukatTask>(
|
||||
taskName,
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.group = NodeJsRootPlugin.TASKS_GROUP_NAME
|
||||
it.description = "Generate Kotlin/JS external declarations for .d.ts files in ${compilation}"
|
||||
it.dependsOn(nodeJs.npmInstallTask, npmProject.packageJsonTask)
|
||||
|
||||
+7
-1
@@ -8,11 +8,17 @@ package org.jetbrains.kotlin.gradle.targets.js.dukat
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
open class DukatTask : AbstractDukatTask() {
|
||||
open class DukatTask
|
||||
@Inject
|
||||
constructor(
|
||||
compilation: KotlinJsCompilation
|
||||
) : AbstractDukatTask(compilation) {
|
||||
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
@get:Internal
|
||||
|
||||
+4
-4
@@ -76,7 +76,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
RUN_TASK_NAME
|
||||
)
|
||||
),
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.commonConfigure(
|
||||
compilation = compilation,
|
||||
@@ -85,7 +86,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
)
|
||||
|
||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||
it.compilation = compilation
|
||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||
|
||||
it.devServer = KotlinWebpackConfig.DevServer(
|
||||
@@ -135,7 +135,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
WEBPACK_TASK_NAME
|
||||
)
|
||||
),
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.commonConfigure(
|
||||
compilation = compilation,
|
||||
@@ -147,7 +148,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
distributeResourcesTask
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||
it._destinationDirectory = distribution.directory
|
||||
}
|
||||
|
||||
+6
-3
@@ -99,7 +99,10 @@ abstract class KotlinJsIrSubTarget(
|
||||
)
|
||||
)
|
||||
|
||||
val testJs = project.registerTask<KotlinJsTest>(testRun.subtargetTestTaskName()) { testJs ->
|
||||
val testJs = project.registerTask<KotlinJsTest>(
|
||||
testRun.subtargetTestTaskName(),
|
||||
listOf(compilation)
|
||||
) { testJs ->
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
testJs.description = testTaskDescription
|
||||
|
||||
@@ -120,7 +123,6 @@ abstract class KotlinJsIrSubTarget(
|
||||
.get()
|
||||
}
|
||||
|
||||
testJs.compilation = compilation
|
||||
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.joinToString()
|
||||
@@ -171,9 +173,10 @@ abstract class KotlinJsIrSubTarget(
|
||||
|
||||
internal inline fun <reified T : Task> registerSubTargetTask(
|
||||
name: String,
|
||||
args: List<Any> = emptyList(),
|
||||
noinline body: (T) -> (Unit)
|
||||
): TaskProvider<T> =
|
||||
project.registerTask(name) {
|
||||
project.registerTask(name, args) {
|
||||
it.group = taskGroupName
|
||||
body(it)
|
||||
}
|
||||
|
||||
+11
-6
@@ -13,14 +13,17 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
import javax.inject.Inject
|
||||
|
||||
open class NodeJsExec : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
||||
open class NodeJsExec
|
||||
@Inject
|
||||
constructor(
|
||||
@Internal
|
||||
override val compilation: KotlinJsCompilation
|
||||
) : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
||||
@get:Internal
|
||||
lateinit var nodeJs: NodeJsRootExtension
|
||||
|
||||
@get:Internal
|
||||
override lateinit var compilation: KotlinJsCompilation
|
||||
|
||||
init {
|
||||
onlyIf {
|
||||
!inputFileProperty.isPresent || inputFileProperty.asFile.map {
|
||||
@@ -77,9 +80,11 @@ open class NodeJsExec : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), Re
|
||||
val project = target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
return project.registerTask(name) {
|
||||
return project.registerTask(
|
||||
name,
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.nodeJs = nodeJs
|
||||
it.compilation = compilation
|
||||
it.executable = nodeJs.requireConfigured().nodeExecutable
|
||||
it.dependsOn(nodeJs.npmInstallTask)
|
||||
|
||||
|
||||
+4
-4
@@ -107,7 +107,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
RUN_TASK_NAME
|
||||
)
|
||||
),
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.commonConfigure(
|
||||
compilation = compilation,
|
||||
@@ -118,7 +119,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
)
|
||||
|
||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||
it.compilation = compilation
|
||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||
|
||||
it.devServer = KotlinWebpackConfig.DevServer(
|
||||
@@ -169,7 +169,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
binary.executeTaskBaseName,
|
||||
WEBPACK_TASK_NAME
|
||||
|
||||
)
|
||||
),
|
||||
listOf(compilation)
|
||||
) {
|
||||
it.commonConfigure(
|
||||
compilation = compilation,
|
||||
@@ -185,7 +186,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
||||
|
||||
it.configureOptimization(type)
|
||||
|
||||
it.compilation = compilation
|
||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||
it._destinationDirectory = distribution.directory
|
||||
}
|
||||
|
||||
+6
-3
@@ -94,7 +94,10 @@ abstract class KotlinJsSubTarget(
|
||||
)
|
||||
)
|
||||
|
||||
val testJs = project.registerTask<KotlinJsTest>(testRun.subtargetTestTaskName()) { testJs ->
|
||||
val testJs = project.registerTask<KotlinJsTest>(
|
||||
testRun.subtargetTestTaskName(),
|
||||
listOf(compilation)
|
||||
) { testJs ->
|
||||
val compileTask = compilation.compileKotlinTask
|
||||
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
@@ -110,7 +113,6 @@ abstract class KotlinJsSubTarget(
|
||||
compileTask.outputFile.exists()
|
||||
}
|
||||
|
||||
testJs.compilation = compilation
|
||||
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.joinToString()
|
||||
@@ -154,9 +156,10 @@ abstract class KotlinJsSubTarget(
|
||||
|
||||
internal inline fun <reified T : Task> registerSubTargetTask(
|
||||
name: String,
|
||||
args: List<Any> = emptyList(),
|
||||
noinline body: (T) -> (Unit)
|
||||
): TaskProvider<T> =
|
||||
project.registerTask(name) {
|
||||
project.registerTask(name, args) {
|
||||
it.group = taskGroupName
|
||||
body(it)
|
||||
}
|
||||
|
||||
+7
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -24,8 +24,13 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.karma.KotlinKarma
|
||||
import org.jetbrains.kotlin.gradle.targets.js.testing.mocha.KotlinMocha
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinJsTest :
|
||||
open class KotlinJsTest
|
||||
@Inject
|
||||
constructor(
|
||||
@Internal override var compilation: KotlinJsCompilation
|
||||
) :
|
||||
KotlinTest(),
|
||||
RequiresNpmDependencies {
|
||||
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||
@@ -43,9 +48,6 @@ open class KotlinJsTest :
|
||||
@Input
|
||||
var debug: Boolean = false
|
||||
|
||||
@Internal
|
||||
override lateinit var compilation: KotlinJsCompilation
|
||||
|
||||
@Suppress("unused")
|
||||
val runtimeClasspath: FileCollection
|
||||
@InputFiles get() = compilation.runtimeDependencyFiles
|
||||
|
||||
+6
-4
@@ -31,7 +31,12 @@ import org.jetbrains.kotlin.gradle.utils.property
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
open class KotlinWebpack
|
||||
@Inject
|
||||
constructor(
|
||||
@Internal
|
||||
override val compilation: KotlinJsCompilation
|
||||
) : DefaultTask(), RequiresNpmDependencies {
|
||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
private val versions = nodeJs.versions
|
||||
|
||||
@@ -43,9 +48,6 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
||||
open val execHandleFactory: ExecHandleFactory
|
||||
get() = injected
|
||||
|
||||
@Internal
|
||||
override lateinit var compilation: KotlinJsCompilation
|
||||
|
||||
@Suppress("unused")
|
||||
val compilationId: String
|
||||
@Input get() = compilation.let {
|
||||
|
||||
Reference in New Issue
Block a user