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