[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 org.jetbrains.kotlin.gradle.targets.js.npm.RequiresNpmDependencies
|
||||||
import java.io.File
|
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)
|
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
override lateinit var compilation: KotlinJsCompilation
|
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
override val nodeModulesRequired: Boolean
|
override val nodeModulesRequired: Boolean
|
||||||
get() = true
|
get() = true
|
||||||
|
|||||||
+4
-2
@@ -25,8 +25,10 @@ internal class DukatCompilationResolverPlugin(
|
|||||||
init {
|
init {
|
||||||
compilation.defaultSourceSet.kotlin.srcDir(npmProject.externalsDir)
|
compilation.defaultSourceSet.kotlin.srcDir(npmProject.externalsDir)
|
||||||
|
|
||||||
val task = project.registerTask<DukatTask>(taskName) {
|
val task = project.registerTask<DukatTask>(
|
||||||
it.compilation = compilation
|
taskName,
|
||||||
|
listOf(compilation)
|
||||||
|
) {
|
||||||
it.group = NodeJsRootPlugin.TASKS_GROUP_NAME
|
it.group = NodeJsRootPlugin.TASKS_GROUP_NAME
|
||||||
it.description = "Generate Kotlin/JS external declarations for .d.ts files in ${compilation}"
|
it.description = "Generate Kotlin/JS external declarations for .d.ts files in ${compilation}"
|
||||||
it.dependsOn(nodeJs.npmInstallTask, npmProject.packageJsonTask)
|
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.Input
|
||||||
import org.gradle.api.tasks.Internal
|
import org.gradle.api.tasks.Internal
|
||||||
import org.gradle.api.tasks.OutputDirectory
|
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.nodejs.NodeJsRootPlugin
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.npmProject
|
||||||
import java.io.File
|
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)
|
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
|
|||||||
+4
-4
@@ -76,7 +76,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
binary.executeTaskBaseName,
|
binary.executeTaskBaseName,
|
||||||
RUN_TASK_NAME
|
RUN_TASK_NAME
|
||||||
)
|
),
|
||||||
|
listOf(compilation)
|
||||||
) {
|
) {
|
||||||
it.commonConfigure(
|
it.commonConfigure(
|
||||||
compilation = compilation,
|
compilation = compilation,
|
||||||
@@ -85,7 +86,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
)
|
)
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
@@ -135,7 +135,8 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
binary.executeTaskBaseName,
|
binary.executeTaskBaseName,
|
||||||
WEBPACK_TASK_NAME
|
WEBPACK_TASK_NAME
|
||||||
)
|
),
|
||||||
|
listOf(compilation)
|
||||||
) {
|
) {
|
||||||
it.commonConfigure(
|
it.commonConfigure(
|
||||||
compilation = compilation,
|
compilation = compilation,
|
||||||
@@ -147,7 +148,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
distributeResourcesTask
|
distributeResourcesTask
|
||||||
)
|
)
|
||||||
|
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||||
it._destinationDirectory = distribution.directory
|
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.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
testJs.description = testTaskDescription
|
testJs.description = testTaskDescription
|
||||||
|
|
||||||
@@ -120,7 +123,6 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
.get()
|
.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
testJs.compilation = compilation
|
|
||||||
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
||||||
.takeIf { it.isNotEmpty() }
|
.takeIf { it.isNotEmpty() }
|
||||||
?.joinToString()
|
?.joinToString()
|
||||||
@@ -171,9 +173,10 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
|
|
||||||
internal inline fun <reified T : Task> registerSubTargetTask(
|
internal inline fun <reified T : Task> registerSubTargetTask(
|
||||||
name: String,
|
name: String,
|
||||||
|
args: List<Any> = emptyList(),
|
||||||
noinline body: (T) -> (Unit)
|
noinline body: (T) -> (Unit)
|
||||||
): TaskProvider<T> =
|
): TaskProvider<T> =
|
||||||
project.registerTask(name) {
|
project.registerTask(name, args) {
|
||||||
it.group = taskGroupName
|
it.group = taskGroupName
|
||||||
body(it)
|
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.targets.js.npm.npmProject
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
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
|
@get:Internal
|
||||||
lateinit var nodeJs: NodeJsRootExtension
|
lateinit var nodeJs: NodeJsRootExtension
|
||||||
|
|
||||||
@get:Internal
|
|
||||||
override lateinit var compilation: KotlinJsCompilation
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onlyIf {
|
onlyIf {
|
||||||
!inputFileProperty.isPresent || inputFileProperty.asFile.map {
|
!inputFileProperty.isPresent || inputFileProperty.asFile.map {
|
||||||
@@ -77,9 +80,11 @@ open class NodeJsExec : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), Re
|
|||||||
val project = target.project
|
val project = target.project
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
return project.registerTask(name) {
|
return project.registerTask(
|
||||||
|
name,
|
||||||
|
listOf(compilation)
|
||||||
|
) {
|
||||||
it.nodeJs = nodeJs
|
it.nodeJs = nodeJs
|
||||||
it.compilation = compilation
|
|
||||||
it.executable = nodeJs.requireConfigured().nodeExecutable
|
it.executable = nodeJs.requireConfigured().nodeExecutable
|
||||||
it.dependsOn(nodeJs.npmInstallTask)
|
it.dependsOn(nodeJs.npmInstallTask)
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -107,7 +107,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
binary.executeTaskBaseName,
|
binary.executeTaskBaseName,
|
||||||
RUN_TASK_NAME
|
RUN_TASK_NAME
|
||||||
)
|
),
|
||||||
|
listOf(compilation)
|
||||||
) {
|
) {
|
||||||
it.commonConfigure(
|
it.commonConfigure(
|
||||||
compilation = compilation,
|
compilation = compilation,
|
||||||
@@ -118,7 +119,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
)
|
)
|
||||||
|
|
||||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||||
|
|
||||||
it.devServer = KotlinWebpackConfig.DevServer(
|
it.devServer = KotlinWebpackConfig.DevServer(
|
||||||
@@ -169,7 +169,8 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
binary.executeTaskBaseName,
|
binary.executeTaskBaseName,
|
||||||
WEBPACK_TASK_NAME
|
WEBPACK_TASK_NAME
|
||||||
|
|
||||||
)
|
),
|
||||||
|
listOf(compilation)
|
||||||
) {
|
) {
|
||||||
it.commonConfigure(
|
it.commonConfigure(
|
||||||
compilation = compilation,
|
compilation = compilation,
|
||||||
@@ -185,7 +186,6 @@ open class KotlinBrowserJs @Inject constructor(target: KotlinJsTarget) :
|
|||||||
|
|
||||||
it.configureOptimization(type)
|
it.configureOptimization(type)
|
||||||
|
|
||||||
it.compilation = compilation
|
|
||||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||||
it._destinationDirectory = distribution.directory
|
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
|
val compileTask = compilation.compileKotlinTask
|
||||||
|
|
||||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
@@ -110,7 +113,6 @@ abstract class KotlinJsSubTarget(
|
|||||||
compileTask.outputFile.exists()
|
compileTask.outputFile.exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
testJs.compilation = compilation
|
|
||||||
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
testJs.targetName = listOfNotNull(target.disambiguationClassifier, disambiguationClassifier)
|
||||||
.takeIf { it.isNotEmpty() }
|
.takeIf { it.isNotEmpty() }
|
||||||
?.joinToString()
|
?.joinToString()
|
||||||
@@ -154,9 +156,10 @@ abstract class KotlinJsSubTarget(
|
|||||||
|
|
||||||
internal inline fun <reified T : Task> registerSubTargetTask(
|
internal inline fun <reified T : Task> registerSubTargetTask(
|
||||||
name: String,
|
name: String,
|
||||||
|
args: List<Any> = emptyList(),
|
||||||
noinline body: (T) -> (Unit)
|
noinline body: (T) -> (Unit)
|
||||||
): TaskProvider<T> =
|
): TaskProvider<T> =
|
||||||
project.registerTask(name) {
|
project.registerTask(name, args) {
|
||||||
it.group = taskGroupName
|
it.group = taskGroupName
|
||||||
body(it)
|
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.
|
* 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.targets.js.testing.mocha.KotlinMocha
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
|
||||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
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(),
|
KotlinTest(),
|
||||||
RequiresNpmDependencies {
|
RequiresNpmDependencies {
|
||||||
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs get() = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
@@ -43,9 +48,6 @@ open class KotlinJsTest :
|
|||||||
@Input
|
@Input
|
||||||
var debug: Boolean = false
|
var debug: Boolean = false
|
||||||
|
|
||||||
@Internal
|
|
||||||
override lateinit var compilation: KotlinJsCompilation
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val runtimeClasspath: FileCollection
|
val runtimeClasspath: FileCollection
|
||||||
@InputFiles get() = compilation.runtimeDependencyFiles
|
@InputFiles get() = compilation.runtimeDependencyFiles
|
||||||
|
|||||||
+6
-4
@@ -31,7 +31,12 @@ import org.jetbrains.kotlin.gradle.utils.property
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
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 nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val versions = nodeJs.versions
|
private val versions = nodeJs.versions
|
||||||
|
|
||||||
@@ -43,9 +48,6 @@ open class KotlinWebpack : DefaultTask(), RequiresNpmDependencies {
|
|||||||
open val execHandleFactory: ExecHandleFactory
|
open val execHandleFactory: ExecHandleFactory
|
||||||
get() = injected
|
get() = injected
|
||||||
|
|
||||||
@Internal
|
|
||||||
override lateinit var compilation: KotlinJsCompilation
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
val compilationId: String
|
val compilationId: String
|
||||||
@Input get() = compilation.let {
|
@Input get() = compilation.let {
|
||||||
|
|||||||
Reference in New Issue
Block a user