[Gradle, JS] Distribution is copy task, webpack targeting to separate directory
^KT-63040 fixed
This commit is contained in:
committed by
Space Team
parent
dd219cb6e6
commit
87e81d8562
+3
-3
@@ -617,7 +617,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build("browserProductionWebpack") {
|
build("browserDistribution") {
|
||||||
assertTasksExecuted(":app:browserProductionWebpack")
|
assertTasksExecuted(":app:browserProductionWebpack")
|
||||||
assertFileExists(subProject("app").projectPath.resolve("build/${Distribution.DIST}/js/productionExecutable/app.js"))
|
assertFileExists(subProject("app").projectPath.resolve("build/${Distribution.DIST}/js/productionExecutable/app.js"))
|
||||||
}
|
}
|
||||||
@@ -730,7 +730,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build("browserProductionWebpack") {
|
build("browserDistribution") {
|
||||||
assertTasksExecuted(":browserProductionWebpack")
|
assertTasksExecuted(":browserProductionWebpack")
|
||||||
assertFileExists(projectPath.resolve("build/${Distribution.DIST}/js/productionExecutable/CORRECT_NAME.js"))
|
assertFileExists(projectPath.resolve("build/${Distribution.DIST}/js/productionExecutable/CORRECT_NAME.js"))
|
||||||
}
|
}
|
||||||
@@ -1142,7 +1142,7 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
build("clean", "browserDistribution") {
|
build("clean", "browserDistribution") {
|
||||||
assertTasksExecuted(
|
assertTasksExecuted(
|
||||||
":app:processResources",
|
":app:processResources",
|
||||||
":app:browserProductionExecutableDistributeResources"
|
":app:browserDistribution"
|
||||||
)
|
)
|
||||||
|
|
||||||
assertFileInProjectExists("app/build/${Distribution.DIST}/js/productionExecutable/index.html")
|
assertFileInProjectExists("app/build/${Distribution.DIST}/js/productionExecutable/index.html")
|
||||||
|
|||||||
+2
-2
@@ -22,11 +22,11 @@ kotlin {
|
|||||||
|
|
||||||
// We need it for suppress warnings of Gradle 7.0
|
// We need it for suppress warnings of Gradle 7.0
|
||||||
// We need to think about it, when we will support multiple binaries
|
// We need to think about it, when we will support multiple binaries
|
||||||
tasks.named("nodeProductionLibraryPrepare") {
|
tasks.named("nodeProductionLibraryDistribution") {
|
||||||
mustRunAfter("productionExecutableCompileSync")
|
mustRunAfter("productionExecutableCompileSync")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("browserProductionLibraryPrepare") {
|
tasks.named("browserProductionLibraryDistribution") {
|
||||||
mustRunAfter("productionExecutableCompileSync")
|
mustRunAfter("productionExecutableCompileSync")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -19,9 +19,8 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// We need it for suppress warnings of Gradle 7.0
|
// We need it for suppress warnings of Gradle 7.0
|
||||||
// We need to think about it, when we will support multiple binaries
|
// We need to think about it, when we will support multiple binaries
|
||||||
tasks.named("nodeProductionLibraryPrepare") {
|
tasks.named("nodeProductionLibraryDistribution") {
|
||||||
mustRunAfter("productionExecutableCompileSync")
|
mustRunAfter("productionExecutableCompileSync")
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-43
@@ -187,13 +187,43 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
val mode = binary.mode
|
val mode = binary.mode
|
||||||
val archivesName = project.archivesName
|
val archivesName = project.archivesName
|
||||||
|
|
||||||
val distributeResourcesTask = registerSubTargetTask<Copy>(
|
val webpackTask = registerSubTargetTask<KotlinWebpack>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
binary.name,
|
binary.executeTaskBaseName,
|
||||||
DISTRIBUTE_RESOURCES_TASK_NAME
|
WEBPACK_TASK_NAME
|
||||||
|
),
|
||||||
|
listOf(compilation)
|
||||||
|
) { task ->
|
||||||
|
task.description = "build webpack ${mode.name.toLowerCaseAsciiOnly()} bundle"
|
||||||
|
val buildDirectory = project.layout.buildDirectory
|
||||||
|
val targetName = target.name
|
||||||
|
task.outputDirectory.convention(
|
||||||
|
binary.distribution.distributionName.flatMap {
|
||||||
|
buildDirectory.dir("kotlin-webpack/$targetName/$it")
|
||||||
|
}
|
||||||
|
).finalizeValueOnRead()
|
||||||
|
|
||||||
|
task.dependsOn(binary.linkSyncTask)
|
||||||
|
|
||||||
|
task.commonConfigure(
|
||||||
|
binary = binary,
|
||||||
|
mode = mode,
|
||||||
|
inputFilesDirectory = task.project.provider { binary.linkSyncTask.get().destinationDirectory.get() },
|
||||||
|
entryModuleName = binary.linkTask.flatMap { it.compilerOptions.moduleName },
|
||||||
|
configurationActions = webpackTaskConfigurations,
|
||||||
|
nodeJs = nodeJs,
|
||||||
|
defaultArchivesName = archivesName,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val distributionTask = registerSubTargetTask<Copy>(
|
||||||
|
disambiguateCamelCased(
|
||||||
|
if (binary.mode == KotlinJsBinaryMode.PRODUCTION) "" else binary.name,
|
||||||
|
DISTRIBUTION_TASK_NAME
|
||||||
)
|
)
|
||||||
) { copy ->
|
) { copy ->
|
||||||
copy.from(processResourcesTask)
|
copy.from(processResourcesTask)
|
||||||
|
copy.from(webpackTask.flatMap { it.outputDirectory })
|
||||||
|
|
||||||
if (binary.compilation.platformType == KotlinPlatformType.wasm) {
|
if (binary.compilation.platformType == KotlinPlatformType.wasm) {
|
||||||
copy.from(
|
copy.from(
|
||||||
@@ -212,46 +242,6 @@ abstract class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
|||||||
copy.into(binary.distribution.directory)
|
copy.into(binary.distribution.directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
val webpackTask = registerSubTargetTask<KotlinWebpack>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
binary.executeTaskBaseName,
|
|
||||||
WEBPACK_TASK_NAME
|
|
||||||
),
|
|
||||||
listOf(compilation)
|
|
||||||
) { task ->
|
|
||||||
task.description = "build webpack ${mode.name.toLowerCaseAsciiOnly()} bundle"
|
|
||||||
task.outputDirectory.fileValue(binary.distribution.directory).finalizeValueOnRead()
|
|
||||||
|
|
||||||
|
|
||||||
task.dependsOn(
|
|
||||||
distributeResourcesTask
|
|
||||||
)
|
|
||||||
|
|
||||||
task.dependsOn(binary.linkSyncTask)
|
|
||||||
|
|
||||||
task.commonConfigure(
|
|
||||||
binary = binary,
|
|
||||||
mode = mode,
|
|
||||||
inputFilesDirectory = task.project.provider { binary.linkSyncTask.get().destinationDirectory.get() },
|
|
||||||
entryModuleName = binary.linkTask.flatMap { it.compilerOptions.moduleName },
|
|
||||||
configurationActions = webpackTaskConfigurations,
|
|
||||||
nodeJs = nodeJs,
|
|
||||||
defaultArchivesName = archivesName,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val distributionTask = registerSubTargetTask<Task>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
if (binary.mode == KotlinJsBinaryMode.PRODUCTION) "" else binary.name,
|
|
||||||
DISTRIBUTION_TASK_NAME
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
it.dependsOn(webpackTask)
|
|
||||||
it.dependsOn(distributeResourcesTask)
|
|
||||||
|
|
||||||
it.outputs.dir(project.newFileProperty { binary.distribution.directory })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
||||||
assembleTaskProvider.dependsOn(distributionTask)
|
assembleTaskProvider.dependsOn(distributionTask)
|
||||||
registerSubTargetTask<Task>(
|
registerSubTargetTask<Task>(
|
||||||
|
|||||||
+2
-16
@@ -223,10 +223,10 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
|
|
||||||
val mode = binary.mode
|
val mode = binary.mode
|
||||||
|
|
||||||
val prepareJsLibrary = registerSubTargetTask<Copy>(
|
val distributionTask = registerSubTargetTask<Copy>(
|
||||||
disambiguateCamelCased(
|
disambiguateCamelCased(
|
||||||
binary.name,
|
binary.name,
|
||||||
PREPARE_JS_LIBRARY_TASK_NAME
|
DISTRIBUTION_TASK_NAME
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
it.from(project.tasks.named(npmProject.publicPackageJsonTaskName))
|
it.from(project.tasks.named(npmProject.publicPackageJsonTaskName))
|
||||||
@@ -235,17 +235,6 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
it.into(binary.distribution.directory)
|
it.into(binary.distribution.directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
val distributionTask = registerSubTargetTask<Task>(
|
|
||||||
disambiguateCamelCased(
|
|
||||||
binary.name,
|
|
||||||
DISTRIBUTION_TASK_NAME
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
it.dependsOn(prepareJsLibrary)
|
|
||||||
|
|
||||||
it.outputs.dir(project.newFileProperty { binary.distribution.directory })
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
if (mode == KotlinJsBinaryMode.PRODUCTION) {
|
||||||
assembleTaskProvider.dependsOn(distributionTask)
|
assembleTaskProvider.dependsOn(distributionTask)
|
||||||
}
|
}
|
||||||
@@ -265,9 +254,6 @@ abstract class KotlinJsIrSubTarget(
|
|||||||
companion object {
|
companion object {
|
||||||
const val RUN_TASK_NAME = "run"
|
const val RUN_TASK_NAME = "run"
|
||||||
|
|
||||||
const val DISTRIBUTE_RESOURCES_TASK_NAME = "distributeResources"
|
|
||||||
const val DISTRIBUTION_TASK_NAME = "distribution"
|
const val DISTRIBUTION_TASK_NAME = "distribution"
|
||||||
|
|
||||||
const val PREPARE_JS_LIBRARY_TASK_NAME = "prepare"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user