[Gradle, JS] Fix naming for webpack tasks
- while webpack is actual only for executable it is not necessary to add executable part
This commit is contained in:
+16
-15
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsBinaryContainer.Companion.generateBinaryName
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
sealed class JsBinary(
|
||||
internal val target: KotlinTarget,
|
||||
internal val compilation: KotlinJsCompilation,
|
||||
internal val name: String,
|
||||
internal val type: BuildVariantKind
|
||||
) {
|
||||
@@ -26,32 +28,31 @@ sealed class JsBinary(
|
||||
private fun linkTaskName(): String =
|
||||
lowerCamelCaseName(
|
||||
"compile",
|
||||
type.name.toLowerCase(),
|
||||
name,
|
||||
"Kotlin",
|
||||
target.targetName
|
||||
)
|
||||
|
||||
val target: KotlinTarget
|
||||
get() = compilation.target
|
||||
|
||||
val project: Project
|
||||
get() = target.project
|
||||
}
|
||||
|
||||
class Executable(
|
||||
target: KotlinTarget,
|
||||
compilation: KotlinJsCompilation,
|
||||
name: String,
|
||||
type: BuildVariantKind
|
||||
) : JsBinary(
|
||||
target,
|
||||
compilation,
|
||||
name,
|
||||
type
|
||||
)
|
||||
|
||||
class TestExecutable(
|
||||
target: KotlinTarget,
|
||||
name: String,
|
||||
type: BuildVariantKind
|
||||
) : JsBinary(
|
||||
target,
|
||||
name,
|
||||
type
|
||||
)
|
||||
) {
|
||||
val executeTaskBaseName: String =
|
||||
generateBinaryName(
|
||||
compilation,
|
||||
type,
|
||||
null
|
||||
)
|
||||
}
|
||||
+1
-2
@@ -6,6 +6,5 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
enum class JsBinaryType {
|
||||
EXECUTABLE,
|
||||
TEST
|
||||
EXECUTABLE
|
||||
}
|
||||
+73
-65
@@ -64,47 +64,51 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
|
||||
val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {}
|
||||
|
||||
compilation.binaries.all { binary ->
|
||||
val type = binary.type
|
||||
compilation.binaries
|
||||
.matching { it is Executable }
|
||||
.all { binary ->
|
||||
binary as Executable
|
||||
|
||||
val runTask = project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
binary.name,
|
||||
RUN_TASK_NAME
|
||||
)
|
||||
) {
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
binary.linkTask,
|
||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||
)
|
||||
val type = binary.type
|
||||
|
||||
it.configureOptimization(type)
|
||||
val runTask = project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
RUN_TASK_NAME
|
||||
)
|
||||
) {
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
binary.linkTask,
|
||||
target.project.tasks.getByName(compilation.processResourcesTaskName)
|
||||
)
|
||||
|
||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||
it.compilation = compilation
|
||||
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||
it.configureOptimization(type)
|
||||
|
||||
it.devServer = KotlinWebpackConfig.DevServer(
|
||||
open = true,
|
||||
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
||||
)
|
||||
it.bin = "webpack-dev-server/bin/webpack-dev-server.js"
|
||||
it.compilation = compilation
|
||||
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||
it.description = "start ${type.name.toLowerCase()} webpack dev server"
|
||||
|
||||
it.outputs.upToDateWhen { false }
|
||||
it.devServer = KotlinWebpackConfig.DevServer(
|
||||
open = true,
|
||||
contentBase = listOf(compilation.output.resourcesDir.canonicalPath)
|
||||
)
|
||||
|
||||
commonRunConfigurations.forEach { configure ->
|
||||
it.configure()
|
||||
it.outputs.upToDateWhen { false }
|
||||
|
||||
commonRunConfigurations.forEach { configure ->
|
||||
it.configure()
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BuildVariantKind.DEVELOPMENT) {
|
||||
target.runTask.dependsOn(runTask)
|
||||
commonRunTask.configure {
|
||||
it.dependsOn(runTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BuildVariantKind.DEVELOPMENT) {
|
||||
target.runTask.dependsOn(runTask)
|
||||
commonRunTask.configure {
|
||||
it.dependsOn(runTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureBuild(
|
||||
@@ -132,43 +136,47 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||
assembleTask.dependsOn(distributeResourcesTask)
|
||||
|
||||
compilation.binaries.all { binary ->
|
||||
val type = binary.type
|
||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
binary.name,
|
||||
WEBPACK_TASK_NAME
|
||||
)
|
||||
) {
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
binary.linkTask,
|
||||
distributeResourcesTask
|
||||
)
|
||||
compilation.binaries
|
||||
.matching { it is Executable }
|
||||
.all { binary ->
|
||||
binary as Executable
|
||||
|
||||
it.configureOptimization(type)
|
||||
val type = binary.type
|
||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
binary.executeTaskBaseName,
|
||||
WEBPACK_TASK_NAME
|
||||
)
|
||||
) {
|
||||
it.dependsOn(
|
||||
nodeJs.npmInstallTask,
|
||||
binary.linkTask,
|
||||
distributeResourcesTask
|
||||
)
|
||||
|
||||
it.compilation = compilation
|
||||
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||
it.destinationDirectory = distribution.directory
|
||||
it.configureOptimization(type)
|
||||
|
||||
commonWebpackConfigurations.forEach { configure ->
|
||||
it.configure()
|
||||
it.compilation = compilation
|
||||
it.entry = binary.linkTask.map { it.outputFile }.get()
|
||||
it.description = "build webpack ${type.name.toLowerCase()} bundle"
|
||||
it.destinationDirectory = distribution.directory
|
||||
|
||||
commonWebpackConfigurations.forEach { configure ->
|
||||
it.configure()
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BuildVariantKind.PRODUCTION) {
|
||||
assembleTask.dependsOn(webpackTask)
|
||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
||||
it.dependsOn(webpackTask)
|
||||
}
|
||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||
it.dependsOn(webpackCommonTask)
|
||||
it.dependsOn(distributeResourcesTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BuildVariantKind.PRODUCTION) {
|
||||
assembleTask.dependsOn(webpackTask)
|
||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
||||
it.dependsOn(webpackTask)
|
||||
}
|
||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||
it.dependsOn(webpackCommonTask)
|
||||
it.dependsOn(distributeResourcesTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinWebpack.configureOptimization(kind: BuildVariantKind) {
|
||||
|
||||
+8
-7
@@ -9,7 +9,6 @@ import org.gradle.api.DomainObjectSet
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinTargetWithBinaries
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
@@ -38,9 +37,11 @@ constructor(
|
||||
compilation: KotlinJsCompilation = defaultCompilation
|
||||
) {
|
||||
if (compilation !is KotlinJsIrCompilation) {
|
||||
throw IllegalArgumentException(
|
||||
"Unable to create executable for $compilation. Use IR compiler (kotlin.js.compiler=true) instead."
|
||||
project.logger.warn(
|
||||
"binaries.executable configuration is useless with IR compiler." +
|
||||
"Use produceExecutable() instead"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
(target as KotlinJsSubTargetContainerDsl).whenBrowserConfigured {
|
||||
@@ -70,7 +71,7 @@ constructor(
|
||||
compilation: KotlinJsCompilation,
|
||||
buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT),
|
||||
jsBinaryType: JsBinaryType,
|
||||
create: (target: KotlinTarget, name: String, buildVariantKind: BuildVariantKind) -> T
|
||||
create: (compilation: KotlinJsCompilation, name: String, buildVariantKind: BuildVariantKind) -> T
|
||||
) {
|
||||
buildVariantKinds.forEach { buildVariantKind ->
|
||||
val name = generateBinaryName(
|
||||
@@ -83,7 +84,7 @@ constructor(
|
||||
"Cannot create binary $name: binary with such a name already exists"
|
||||
}
|
||||
|
||||
val binary = create(target, name, buildVariantKind)
|
||||
val binary = create(compilation, name, buildVariantKind)
|
||||
add(binary)
|
||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||
if (this is ExtensionAware) {
|
||||
@@ -96,12 +97,12 @@ constructor(
|
||||
internal fun generateBinaryName(
|
||||
compilation: KotlinJsCompilation,
|
||||
buildVariantKind: BuildVariantKind,
|
||||
jsBinaryType: JsBinaryType
|
||||
jsBinaryType: JsBinaryType?
|
||||
) =
|
||||
lowerCamelCaseName(
|
||||
compilation.name.let { if (it == KotlinCompilation.MAIN_COMPILATION_NAME) null else it },
|
||||
buildVariantKind.name.toLowerCase(),
|
||||
jsBinaryType.name.toLowerCase()
|
||||
jsBinaryType?.name?.toLowerCase()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user