[Gradle, JS] Optimize JS tasks serialized size
Tasks are serialized by Gradle's configurations cache. Each referenced object by task is also serialized. Reduce task's size by narrowing referenced objects. #KT-45294 In Progress
This commit is contained in:
+1
-1
@@ -107,7 +107,7 @@ internal class DukatCompilationResolverPlugin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
DukatExecutor(
|
DukatExecutor(
|
||||||
nodeJs,
|
nodeJs.versions,
|
||||||
DtsResolver(npmProject).getAllDts(externalNpmDependencies),
|
DtsResolver(npmProject).getAllDts(externalNpmDependencies),
|
||||||
externalsOutputFormat,
|
externalsOutputFormat,
|
||||||
npmProject,
|
npmProject,
|
||||||
|
|||||||
+3
-3
@@ -6,11 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
package org.jetbrains.kotlin.gradle.targets.js.dukat
|
||||||
|
|
||||||
import org.gradle.internal.service.ServiceRegistry
|
import org.gradle.internal.service.ServiceRegistry
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
|
import org.jetbrains.kotlin.gradle.targets.js.NpmVersions
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
|
||||||
|
|
||||||
class DukatExecutor(
|
class DukatExecutor(
|
||||||
val nodeJs: NodeJsRootExtension,
|
val npmVersions: NpmVersions,
|
||||||
val typeDefinitions: List<DtsResolver.Dts>,
|
val typeDefinitions: List<DtsResolver.Dts>,
|
||||||
val externalsOutputFormat: ExternalsOutputFormat,
|
val externalsOutputFormat: ExternalsOutputFormat,
|
||||||
val npmProject: NpmProject,
|
val npmProject: NpmProject,
|
||||||
@@ -23,7 +23,7 @@ class DukatExecutor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val versionFile = npmProject.externalsDirRoot.resolve("version.txt")
|
val versionFile = npmProject.externalsDirRoot.resolve("version.txt")
|
||||||
val version = DukatCompilationResolverPlugin.VERSION + ", " + nodeJs.versions.dukat.version
|
val version = DukatCompilationResolverPlugin.VERSION + ", " + npmVersions.dukat.version
|
||||||
val prevVersion = if (versionFile.exists()) versionFile.readText() else null
|
val prevVersion = if (versionFile.exists()) versionFile.readText() else null
|
||||||
|
|
||||||
val inputsFile = npmProject.externalsDirRoot.resolve("inputs.txt")
|
val inputsFile = npmProject.externalsDirRoot.resolve("inputs.txt")
|
||||||
|
|||||||
+11
-8
@@ -19,8 +19,11 @@ abstract class DukatTask(
|
|||||||
override val compilation: KotlinJsCompilation
|
override val compilation: KotlinJsCompilation
|
||||||
) : DefaultTask(), RequiresNpmDependencies {
|
) : DefaultTask(), RequiresNpmDependencies {
|
||||||
@get:Internal
|
@get:Internal
|
||||||
|
@Transient
|
||||||
protected val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
protected val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
|
||||||
|
private val resolutionManager = nodeJs.npmResolutionManager
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
val compilationName by lazy {
|
val compilationName by lazy {
|
||||||
compilation.disambiguatedName
|
compilation.disambiguatedName
|
||||||
@@ -31,8 +34,9 @@ abstract class DukatTask(
|
|||||||
get() = true
|
get() = true
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency>
|
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
||||||
get() = setOf(nodeJs.versions.dukat)
|
setOf(nodeJs.versions.dukat)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [ExternalsOutputFormat] what to generate, sources or binaries
|
* [ExternalsOutputFormat] what to generate, sources or binaries
|
||||||
@@ -43,11 +47,10 @@ abstract class DukatTask(
|
|||||||
private val projectPath = project.path
|
private val projectPath = project.path
|
||||||
|
|
||||||
private val compilationResolution
|
private val compilationResolution
|
||||||
get() =
|
get() = resolutionManager.requireInstalled(
|
||||||
nodeJs.npmResolutionManager.requireInstalled(
|
services,
|
||||||
services,
|
logger
|
||||||
logger
|
)[projectPath][compilationName]
|
||||||
)[projectPath][compilationName]
|
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
val dts: List<DtsResolver.Dts>
|
val dts: List<DtsResolver.Dts>
|
||||||
@@ -91,7 +94,7 @@ abstract class DukatTask(
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
open fun run() {
|
open fun run() {
|
||||||
nodeJs.npmResolutionManager.checkRequiredDependencies(this, services, logger, projectPath)
|
resolutionManager.checkRequiredDependencies(this, services, logger, projectPath)
|
||||||
|
|
||||||
destinationDir.deleteRecursively()
|
destinationDir.deleteRecursively()
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -22,6 +22,10 @@ constructor(
|
|||||||
|
|
||||||
private val npmProject = compilation.npmProject
|
private val npmProject = compilation.npmProject
|
||||||
|
|
||||||
|
private val versions by lazy {
|
||||||
|
nodeJs.versions
|
||||||
|
}
|
||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
override val destinationDir: File by lazy {
|
override val destinationDir: File by lazy {
|
||||||
npmProject.externalsDir
|
npmProject.externalsDir
|
||||||
@@ -29,7 +33,7 @@ constructor(
|
|||||||
|
|
||||||
private val executor
|
private val executor
|
||||||
get() = DukatExecutor(
|
get() = DukatExecutor(
|
||||||
nodeJs,
|
versions,
|
||||||
dts,
|
dts,
|
||||||
externalsOutputFormat,
|
externalsOutputFormat,
|
||||||
npmProject,
|
npmProject,
|
||||||
|
|||||||
+4
-2
@@ -21,6 +21,7 @@ constructor(
|
|||||||
@Internal
|
@Internal
|
||||||
override val compilation: KotlinJsCompilation
|
override val compilation: KotlinJsCompilation
|
||||||
) : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
) : AbstractExecTask<NodeJsExec>(NodeJsExec::class.java), RequiresNpmDependencies {
|
||||||
|
@Transient
|
||||||
@get:Internal
|
@get:Internal
|
||||||
lateinit var nodeJs: NodeJsRootExtension
|
lateinit var nodeJs: NodeJsRootExtension
|
||||||
|
|
||||||
@@ -48,12 +49,13 @@ constructor(
|
|||||||
get() = true
|
get() = true
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency>
|
override val requiredNpmDependencies: Set<RequiredKotlinJsDependency> by lazy {
|
||||||
get() = mutableSetOf<RequiredKotlinJsDependency>().also {
|
mutableSetOf<RequiredKotlinJsDependency>().also {
|
||||||
if (sourceMapStackTraces) {
|
if (sourceMapStackTraces) {
|
||||||
it.add(nodeJs.versions.sourceMapSupport)
|
it.add(nodeJs.versions.sourceMapSupport)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun exec() {
|
override fun exec() {
|
||||||
val newArgs = mutableListOf<String>()
|
val newArgs = mutableListOf<String>()
|
||||||
|
|||||||
+3
-1
@@ -14,10 +14,12 @@ import java.net.URI
|
|||||||
|
|
||||||
@CacheableTask
|
@CacheableTask
|
||||||
open class NodeJsSetupTask : DefaultTask() {
|
open class NodeJsSetupTask : DefaultTask() {
|
||||||
|
@Transient
|
||||||
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
private val settings = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val env by lazy { settings.requireConfigured() }
|
private val env by lazy { settings.requireConfigured() }
|
||||||
private val fs = FileSystemOperationsCompat(project)
|
private val fs = FileSystemOperationsCompat(project)
|
||||||
private val archiveOperations = ArchiveOperationsCompat(project)
|
private val archiveOperations = ArchiveOperationsCompat(project)
|
||||||
|
private val shouldDownload = settings.download
|
||||||
|
|
||||||
val ivyDependency: String
|
val ivyDependency: String
|
||||||
@Input get() = env.ivyDependency
|
@Input get() = env.ivyDependency
|
||||||
@@ -63,7 +65,7 @@ open class NodeJsSetupTask : DefaultTask() {
|
|||||||
init {
|
init {
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
onlyIf {
|
onlyIf {
|
||||||
settings.download && !File(env.nodeExecutable).isFile
|
shouldDownload && !File(env.nodeExecutable).isFile
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-8
@@ -31,12 +31,12 @@ open class NpmProject(@Transient val compilation: KotlinJsCompilation) {
|
|||||||
buildNpmProjectName()
|
buildNpmProjectName()
|
||||||
}
|
}
|
||||||
|
|
||||||
val nodeJs by lazy {
|
@Transient
|
||||||
NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
}
|
|
||||||
|
|
||||||
val dir: File
|
val dir: File by lazy {
|
||||||
get() = nodeJs.projectPackagesDir.resolve(name)
|
nodeJs.projectPackagesDir.resolve(name)
|
||||||
|
}
|
||||||
|
|
||||||
val target: KotlinJsTargetDsl
|
val target: KotlinJsTargetDsl
|
||||||
get() = compilation.target as KotlinJsTargetDsl
|
get() = compilation.target as KotlinJsTargetDsl
|
||||||
@@ -77,8 +77,9 @@ open class NpmProject(@Transient val compilation: KotlinJsCompilation) {
|
|||||||
|
|
||||||
internal val modules = NpmProjectModules(dir)
|
internal val modules = NpmProjectModules(dir)
|
||||||
|
|
||||||
private val rootNodeModules: NpmProjectModules?
|
private val nodeExecutable by lazy {
|
||||||
get() = NpmProjectModules(nodeJs.rootPackageDir)
|
nodeJs.requireConfigured().nodeExecutable
|
||||||
|
}
|
||||||
|
|
||||||
fun useTool(
|
fun useTool(
|
||||||
exec: ExecSpec,
|
exec: ExecSpec,
|
||||||
@@ -87,7 +88,7 @@ open class NpmProject(@Transient val compilation: KotlinJsCompilation) {
|
|||||||
args: List<String>
|
args: List<String>
|
||||||
) {
|
) {
|
||||||
exec.workingDir = dir
|
exec.workingDir = dir
|
||||||
exec.executable = nodeJs.requireConfigured().nodeExecutable
|
exec.executable = nodeExecutable
|
||||||
exec.args = nodeArgs + require(tool) + args
|
exec.args = nodeArgs + require(tool) + args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -24,16 +24,19 @@ constructor(
|
|||||||
private val compilation: KotlinJsCompilation
|
private val compilation: KotlinJsCompilation
|
||||||
) : DefaultTask() {
|
) : DefaultTask() {
|
||||||
private val npmProject = compilation.npmProject
|
private val npmProject = compilation.npmProject
|
||||||
|
|
||||||
|
@Transient
|
||||||
private val nodeJs = npmProject.nodeJs
|
private val nodeJs = npmProject.nodeJs
|
||||||
|
private val resolutionManager = nodeJs.npmResolutionManager
|
||||||
|
|
||||||
private val compilationName = compilation.disambiguatedName
|
private val compilationName = compilation.disambiguatedName
|
||||||
private val projectPath = project.path
|
private val projectPath = project.path
|
||||||
|
|
||||||
private val compilationResolution
|
private val compilationResolution
|
||||||
get() = nodeJs.npmResolutionManager.requireInstalled(
|
get() = resolutionManager.requireInstalled(
|
||||||
services,
|
services,
|
||||||
logger
|
logger
|
||||||
)[projectPath][compilationName]
|
)[projectPath][compilationName]
|
||||||
|
|
||||||
private val packageJsonHandlers = compilation.packageJsonHandlers
|
private val packageJsonHandlers = compilation.packageJsonHandlers
|
||||||
|
|
||||||
|
|||||||
+8
-5
@@ -26,8 +26,9 @@ open class KotlinNpmInstallTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val resolutionManager get() = nodeJs.npmResolutionManager
|
private val resolutionManager = nodeJs.npmResolutionManager
|
||||||
|
|
||||||
@Input
|
@Input
|
||||||
val args: MutableList<String> = mutableListOf()
|
val args: MutableList<String> = mutableListOf()
|
||||||
@@ -47,12 +48,14 @@ open class KotlinNpmInstallTask : DefaultTask() {
|
|||||||
|
|
||||||
// avoid using node_modules as output directory, as it is significantly slows down build
|
// avoid using node_modules as output directory, as it is significantly slows down build
|
||||||
@get:OutputFile
|
@get:OutputFile
|
||||||
val nodeModulesState: File
|
val nodeModulesState: File by lazy {
|
||||||
get() = nodeJs.rootNodeModulesStateFile
|
nodeJs.rootNodeModulesStateFile
|
||||||
|
}
|
||||||
|
|
||||||
@get:OutputFile
|
@get:OutputFile
|
||||||
val yarnLock: File
|
val yarnLock: File by lazy {
|
||||||
get() = nodeJs.rootPackageDir.resolve("yarn.lock")
|
nodeJs.rootPackageDir.resolve("yarn.lock")
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun resolve() {
|
fun resolve() {
|
||||||
|
|||||||
+6
-2
@@ -18,18 +18,22 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.KotlinCompilationNpmR
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.PACKAGE_JSON_UMBRELLA_TASK_NAME
|
import org.jetbrains.kotlin.gradle.targets.js.npm.resolver.PACKAGE_JSON_UMBRELLA_TASK_NAME
|
||||||
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
import org.jetbrains.kotlin.gradle.tasks.dependsOn
|
||||||
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
import org.jetbrains.kotlin.gradle.tasks.registerTask
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
open class KotlinPackageJsonTask : DefaultTask() {
|
open class KotlinPackageJsonTask : DefaultTask() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
onlyIf {
|
onlyIf {
|
||||||
nodeJs.npmResolutionManager.isConfiguringState()
|
npmResolutionManager.isConfiguringState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
private lateinit var nodeJs: NodeJsRootExtension
|
private lateinit var nodeJs: NodeJsRootExtension
|
||||||
|
|
||||||
|
private val npmResolutionManager by project.provider { nodeJs.npmResolutionManager }
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private lateinit var compilation: KotlinJsCompilation
|
private lateinit var compilation: KotlinJsCompilation
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
|
|||||||
val projectPath = project.path
|
val projectPath = project.path
|
||||||
|
|
||||||
private val compilationResolver
|
private val compilationResolver
|
||||||
get() = nodeJs.npmResolutionManager.resolver[projectPath][compilationDisambiguatedName]
|
get() = npmResolutionManager.resolver[projectPath][compilationDisambiguatedName]
|
||||||
|
|
||||||
private val producer: KotlinCompilationNpmResolver.PackageJsonProducer
|
private val producer: KotlinCompilationNpmResolver.PackageJsonProducer
|
||||||
get() = compilationResolver.packageJsonProducer
|
get() = compilationResolver.packageJsonProducer
|
||||||
|
|||||||
+5
-3
@@ -25,12 +25,14 @@ open class RootPackageJsonTask : DefaultTask() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transient
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val resolutionManager get() = nodeJs.npmResolutionManager
|
private val resolutionManager = nodeJs.npmResolutionManager
|
||||||
|
|
||||||
@get:OutputFile
|
@get:OutputFile
|
||||||
val rootPackageJson: File
|
val rootPackageJson: File by lazy {
|
||||||
get() = nodeJs.rootPackageDir.resolve(NpmProject.PACKAGE_JSON)
|
nodeJs.rootPackageDir.resolve(NpmProject.PACKAGE_JSON)
|
||||||
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun resolve() {
|
fun resolve() {
|
||||||
|
|||||||
+3
-1
@@ -49,7 +49,9 @@ class KotlinKarma(
|
|||||||
@Transient
|
@Transient
|
||||||
private val project: Project = compilation.target.project
|
private val project: Project = compilation.target.project
|
||||||
private val npmProject = compilation.npmProject
|
private val npmProject = compilation.npmProject
|
||||||
|
@Transient
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
|
private val nodeRootPackageDir by lazy { nodeJs.rootPackageDir }
|
||||||
private val versions = nodeJs.versions
|
private val versions = nodeJs.versions
|
||||||
|
|
||||||
private val config: KarmaConfig = KarmaConfig()
|
private val config: KarmaConfig = KarmaConfig()
|
||||||
@@ -87,7 +89,7 @@ class KotlinKarma(
|
|||||||
devtool = null,
|
devtool = null,
|
||||||
export = false,
|
export = false,
|
||||||
progressReporter = true,
|
progressReporter = true,
|
||||||
progressReporterPathFilter = nodeJs.rootPackageDir.absolutePath,
|
progressReporterPathFilter = nodeRootPackageDir.absolutePath,
|
||||||
webpackMajorVersion = webpackMajorVersion
|
webpackMajorVersion = webpackMajorVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -27,8 +27,7 @@ class KotlinMocha(@Transient override val compilation: KotlinJsCompilation, priv
|
|||||||
@Transient
|
@Transient
|
||||||
private val project: Project = compilation.target.project
|
private val project: Project = compilation.target.project
|
||||||
private val npmProject = compilation.npmProject
|
private val npmProject = compilation.npmProject
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val versions = NodeJsRootPlugin.apply(project.rootProject).versions
|
||||||
private val versions = nodeJs.versions
|
|
||||||
private val isTeamCity by lazy {
|
private val isTeamCity by lazy {
|
||||||
if (isConfigurationCacheAvailable(project.gradle)) {
|
if (isConfigurationCacheAvailable(project.gradle)) {
|
||||||
project.providers.gradleProperty(TC_PROJECT_PROPERTY).forUseAtConfigurationTime().isPresent
|
project.providers.gradleProperty(TC_PROJECT_PROPERTY).forUseAtConfigurationTime().isPresent
|
||||||
|
|||||||
+5
-2
@@ -39,8 +39,11 @@ constructor(
|
|||||||
@Transient
|
@Transient
|
||||||
override val compilation: KotlinJsCompilation
|
override val compilation: KotlinJsCompilation
|
||||||
) : DefaultTask(), RequiresNpmDependencies {
|
) : DefaultTask(), RequiresNpmDependencies {
|
||||||
|
@Transient
|
||||||
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
private val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
private val versions = nodeJs.versions
|
private val versions = nodeJs.versions
|
||||||
|
private val resolutionManager = nodeJs.npmResolutionManager
|
||||||
|
private val rootPackageDir by lazy { nodeJs.rootPackageDir }
|
||||||
|
|
||||||
private val npmProject = compilation.npmProject
|
private val npmProject = compilation.npmProject
|
||||||
|
|
||||||
@@ -260,7 +263,7 @@ constructor(
|
|||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun doExecute() {
|
fun doExecute() {
|
||||||
nodeJs.npmResolutionManager.checkRequiredDependencies(task = this, services = services, logger = logger, projectPath = projectPath)
|
resolutionManager.checkRequiredDependencies(task = this, services = services, logger = logger, projectPath = projectPath)
|
||||||
|
|
||||||
val runner = createRunner()
|
val runner = createRunner()
|
||||||
|
|
||||||
@@ -279,7 +282,7 @@ constructor(
|
|||||||
runner.copy(
|
runner.copy(
|
||||||
config = runner.config.copy(
|
config = runner.config.copy(
|
||||||
progressReporter = true,
|
progressReporter = true,
|
||||||
progressReporterPathFilter = nodeJs.rootPackageDir.absolutePath
|
progressReporterPathFilter = rootPackageDir.absolutePath
|
||||||
)
|
)
|
||||||
).execute(services)
|
).execute(services)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user