[Gradle, JS] Use separate task class for good configuration caching
^KT-34014 fixed ^KT-49505 fixed
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
||||||
|
|
||||||
|
import org.gradle.api.DefaultTask
|
||||||
|
import org.gradle.api.file.FileSystemOperations
|
||||||
|
import org.gradle.api.file.RegularFileProperty
|
||||||
|
import org.gradle.api.provider.Property
|
||||||
|
import org.gradle.api.provider.Provider
|
||||||
|
import org.gradle.api.tasks.*
|
||||||
|
import java.io.File
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
abstract class YarnLockCopyTask : DefaultTask() {
|
||||||
|
@get:InputFile
|
||||||
|
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||||
|
abstract val inputFile: RegularFileProperty
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
abstract val outputDirectory: RegularFileProperty
|
||||||
|
|
||||||
|
@get:Internal
|
||||||
|
abstract val fileName: Property<String>
|
||||||
|
|
||||||
|
@get:OutputFile
|
||||||
|
val outputFile: Provider<File>
|
||||||
|
get() = outputDirectory.map { regularFile ->
|
||||||
|
regularFile.asFile.resolve(fileName.get())
|
||||||
|
}
|
||||||
|
|
||||||
|
@get:Inject
|
||||||
|
abstract val fs: FileSystemOperations
|
||||||
|
|
||||||
|
@TaskAction
|
||||||
|
fun copy() {
|
||||||
|
fs.copy { copy ->
|
||||||
|
copy.from(inputFile)
|
||||||
|
copy.rename { fileName.get() }
|
||||||
|
copy.into(outputDirectory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-24
@@ -79,37 +79,21 @@ open class YarnPlugin : Plugin<Project> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val storeYarnLock = tasks.register("kotlinStoreYarnLock") {
|
val storeYarnLock = tasks.register("kotlinStoreYarnLock", YarnLockCopyTask::class.java) {
|
||||||
it.dependsOn(kotlinNpmInstall)
|
it.dependsOn(kotlinNpmInstall)
|
||||||
val yarnLock = nodeJs.rootPackageDir.resolve("yarn.lock")
|
it.inputFile.set(nodeJs.rootPackageDir.resolve("yarn.lock"))
|
||||||
|
it.outputDirectory.set(yarnRootExtension.lockFileDirectory)
|
||||||
it.doLast {
|
it.fileName.set(yarnRootExtension.lockFileName)
|
||||||
copy { copy ->
|
|
||||||
copy.from(yarnLock)
|
|
||||||
copy.rename { yarnRootExtension.lockFileName }
|
|
||||||
copy.into(yarnRootExtension.lockFileDirectory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it.inputs.file(yarnLock).withPropertyName("inputFile")
|
|
||||||
it.outputs.file(yarnRootExtension.lockFileDirectory.resolve(yarnRootExtension.lockFileName)).withPropertyName("outputFile")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val restoreYarnLock = tasks.register("kotlinRestoreYarnLock") {
|
val restoreYarnLock = tasks.register("kotlinRestoreYarnLock", YarnLockCopyTask::class.java) {
|
||||||
val lockFile = yarnRootExtension.lockFileDirectory.resolve(yarnRootExtension.lockFileName)
|
val lockFile = yarnRootExtension.lockFileDirectory.resolve(yarnRootExtension.lockFileName)
|
||||||
|
it.inputFile.set(yarnRootExtension.lockFileDirectory.resolve(yarnRootExtension.lockFileName))
|
||||||
|
it.outputDirectory.set(nodeJs.rootPackageDir)
|
||||||
|
it.fileName.set("yarn.lock")
|
||||||
it.onlyIf {
|
it.onlyIf {
|
||||||
lockFile.exists()
|
lockFile.exists()
|
||||||
}
|
}
|
||||||
it.doLast {
|
|
||||||
copy { copy ->
|
|
||||||
copy.from(lockFile)
|
|
||||||
copy.rename { "yarn.lock" }
|
|
||||||
copy.into(nodeJs.rootPackageDir)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
it.inputs.file(lockFile).withPropertyName("inputFile")
|
|
||||||
it.outputs.file(nodeJs.rootPackageDir.resolve("yarn.lock")).withPropertyName("outputFile")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinNpmInstall.configure {
|
kotlinNpmInstall.configure {
|
||||||
|
|||||||
Reference in New Issue
Block a user