[Gradle, JS] Remove redundant caching infrastructure

This commit is contained in:
Ilya Goncharov
2021-04-08 21:32:51 +03:00
committed by TeamCityServer
parent 4d2376ac4c
commit 3fc2a77281
8 changed files with 1 additions and 150 deletions
@@ -77,9 +77,6 @@ open class NodeJsRootExtension(@Transient val rootProject: Project) : Configurat
rootProject.buildDir.resolve("js") rootProject.buildDir.resolve("js")
} }
internal val rootNodeModulesStateFile: File
get() = rootPackageDir.resolve("node_modules.state")
val projectPackagesDir: File val projectPackagesDir: File
get() = rootPackageDir.resolve("packages") get() = rootPackageDir.resolve("packages")
@@ -18,8 +18,6 @@ import java.io.File
interface NpmApi { interface NpmApi {
fun setup(project: Project) fun setup(project: Project)
fun resolveProject(resolvedNpmProject: KotlinCompilationNpmResolution)
fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File>
fun prepareRootProject( fun prepareRootProject(
@@ -38,7 +36,6 @@ interface NpmApi {
nodeJs: NodeJsRootExtension, nodeJs: NodeJsRootExtension,
yarnHome: File, yarnHome: File,
npmProjects: Collection<KotlinCompilationNpmResolution>, npmProjects: Collection<KotlinCompilationNpmResolution>,
skipExecution: Boolean,
cliArgs: List<String> cliArgs: List<String>
) )
@@ -1,52 +0,0 @@
/*
* Copyright 2010-2019 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.npm
import org.gradle.api.Project
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.internal.hash.FileHasher
import org.gradle.internal.service.ServiceRegistry
import org.jetbrains.kotlin.daemon.common.toHexString
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import java.io.File
class PackageJsonUpToDateCheck(val services: ServiceRegistry, val npmProject: NpmProject) {
private val NpmProject.packageJsonHashFile: File
get() = dir.resolve("package.json.hash")
private val prevHash by lazy {
val packageJsonHashFile = npmProject.packageJsonHashFile
if (packageJsonHashFile.exists()) packageJsonHashFile.readText() else null
}
private val packageJsonFile = npmProject.packageJsonFile
private val hash by lazy {
val hasher = services.get(FileHasher::class.java)
hasher.hash(packageJsonFile).toByteArray().toHexString()
}
val upToDate: Boolean
get() = packageJsonFile.exists() &&
npmProject.nodeModulesDir.isDirectory &&
prevHash == hash
fun commit() {
if (!upToDate) {
val packageJsonHashFile = npmProject.packageJsonHashFile
packageJsonHashFile.ensureParentDirsCreated()
packageJsonHashFile.writeText(hash)
}
}
inline fun updateIfNeeded(body: () -> Unit) {
if (!upToDate) {
body()
commit()
}
}
}
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.npm.CompositeNodeModulesCache import org.jetbrains.kotlin.gradle.targets.js.npm.CompositeNodeModulesCache
import org.jetbrains.kotlin.gradle.targets.js.npm.GradleNodeModulesCache import org.jetbrains.kotlin.gradle.targets.js.npm.GradleNodeModulesCache
import org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager import org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJsonUpToDateCheck
import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin import org.jetbrains.kotlin.gradle.targets.js.npm.plugins.RootResolverPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinProjectNpmResolution
@@ -229,27 +228,15 @@ internal class KotlinRootNpmResolver internal constructor(
.values .values
.flatMap { it.npmProjects } .flatMap { it.npmProjects }
// we need manual up-to-date checking to avoid call package manager during
// idea import if nothing was changed
// we should call it even kotlinNpmInstall task is up-to-date (skipPackageManager is true)
// because our upToDateChecks saves state for next execution
val upToDateChecks = allNpmPackages.map {
PackageJsonUpToDateCheck(services, it.npmProject)
}
val upToDate = forceUpToDate || upToDateChecks.all { it.upToDate }
nodeJs.packageManager.resolveRootProject( nodeJs.packageManager.resolveRootProject(
services, services,
logger, logger,
nodeJs, nodeJs,
yarn.requireConfigured().home, yarn.requireConfigured().home,
allNpmPackages, allNpmPackages,
upToDate,
args args
) )
upToDateChecks.forEach { it.commit() }
return KotlinRootNpmResolution(rootProject, projectResolutions) return KotlinRootNpmResolution(rootProject, projectResolutions)
} }
} }
@@ -46,12 +46,6 @@ open class KotlinNpmInstallTask : DefaultTask() {
nodeJs.packageManager.preparedFiles(nodeJs) nodeJs.packageManager.preparedFiles(nodeJs)
} }
// avoid using node_modules as output directory, as it is significantly slows down build
@get:OutputFile
val nodeModulesState: File by lazy {
nodeJs.rootNodeModulesStateFile
}
@get:OutputFile @get:OutputFile
val yarnLock: File by lazy { val yarnLock: File by lazy {
nodeJs.rootPackageDir.resolve("yarn.lock") nodeJs.rootPackageDir.resolve("yarn.lock")
@@ -16,18 +16,13 @@ import java.io.File
class Yarn : NpmApi { class Yarn : NpmApi {
private val yarnWorkspaces = YarnWorkspaces() private val yarnWorkspaces = YarnWorkspaces()
private val yarnSimple = YarnSimple()
private fun getDelegate(project: Project): NpmApi = private fun getDelegate(project: Project): NpmApi =
if (project.yarn.useWorkspaces) yarnWorkspaces yarnWorkspaces
else yarnSimple
override fun setup(project: Project) = override fun setup(project: Project) =
getDelegate(project.rootProject).setup(project) getDelegate(project.rootProject).setup(project)
override fun resolveProject(resolvedNpmProject: KotlinCompilationNpmResolution) =
getDelegate(resolvedNpmProject.project).resolveProject(resolvedNpmProject)
override fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> = override fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> =
yarnWorkspaces.preparedFiles(nodeJs) yarnWorkspaces.preparedFiles(nodeJs)
@@ -56,7 +51,6 @@ class Yarn : NpmApi {
nodeJs: NodeJsRootExtension, nodeJs: NodeJsRootExtension,
yarnHome: File, yarnHome: File,
npmProjects: Collection<KotlinCompilationNpmResolution>, npmProjects: Collection<KotlinCompilationNpmResolution>,
skipExecution: Boolean,
cliArgs: List<String> cliArgs: List<String>
) { ) {
yarnWorkspaces yarnWorkspaces
@@ -66,7 +60,6 @@ class Yarn : NpmApi {
nodeJs, nodeJs,
yarnHome, yarnHome,
npmProjects, npmProjects,
skipExecution,
cliArgs cliArgs
) )
} }
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2020 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.Project
import org.gradle.api.internal.project.ProjectInternal
import org.gradle.api.logging.Logger
import org.gradle.internal.service.ServiceRegistry
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmApi
import org.jetbrains.kotlin.gradle.targets.js.npm.PackageJsonUpToDateCheck
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
import java.io.File
class YarnSimple : YarnBasics() {
override fun resolveProject(resolvedNpmProject: KotlinCompilationNpmResolution) {
setup(resolvedNpmProject.project.rootProject)
// val project = resolvedNpmProject.project
//
// PackageJsonUpToDateCheck(resolvedNpmProject.npmProject).updateIfNeeded {
// yarnExec(
// (project as ProjectInternal).services,
// project.logger,
// NodeJsRootPlugin.apply(project),
// YarnPlugin.apply(project).requireConfigured().home,
// resolvedNpmProject.npmProject.dir,
// NpmApi.resolveOperationDescription("yarn for ${project.path}"),
// emptyList()
// )
// yarnLockReadTransitiveDependencies(resolvedNpmProject.npmProject.dir, resolvedNpmProject.externalNpmDependencies)
// }
}
override fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> =
emptyList()
override fun prepareRootProject(
rootProject: Project?,
nodeJs: NodeJsRootExtension,
rootProjectName: String,
rootProjectVersion: String,
logger: Logger,
subProjects: Collection<KotlinCompilationNpmResolution>,
resolutions: Map<String, String>
) = Unit
override fun resolveRootProject(
services: ServiceRegistry,
logger: Logger,
nodeJs: NodeJsRootExtension,
yarnHome: File,
npmProjects: Collection<KotlinCompilationNpmResolution>,
skipExecution: Boolean,
cliArgs: List<String>
) = Unit
}
@@ -17,8 +17,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmR
import java.io.File import java.io.File
class YarnWorkspaces : YarnBasics() { class YarnWorkspaces : YarnBasics() {
override fun resolveProject(resolvedNpmProject: KotlinCompilationNpmResolution) = Unit
override fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> { override fun preparedFiles(nodeJs: NodeJsRootExtension): Collection<File> {
return listOf( return listOf(
nodeJs nodeJs
@@ -74,7 +72,6 @@ class YarnWorkspaces : YarnBasics() {
nodeJs: NodeJsRootExtension, nodeJs: NodeJsRootExtension,
yarnHome: File, yarnHome: File,
npmProjects: Collection<KotlinCompilationNpmResolution>, npmProjects: Collection<KotlinCompilationNpmResolution>,
skipExecution: Boolean,
cliArgs: List<String> cliArgs: List<String>
) { ) {
val nodeJsWorldDir = nodeJs.rootPackageDir val nodeJsWorldDir = nodeJs.rootPackageDir
@@ -88,7 +85,6 @@ class YarnWorkspaces : YarnBasics() {
NpmApi.resolveOperationDescription("yarn"), NpmApi.resolveOperationDescription("yarn"),
cliArgs cliArgs
) )
nodeJs.rootNodeModulesStateFile.writeText(System.currentTimeMillis().toString())
yarnLockReadTransitiveDependencies(nodeJsWorldDir, npmProjects.flatMap { it.externalNpmDependencies }) yarnLockReadTransitiveDependencies(nodeJsWorldDir, npmProjects.flatMap { it.externalNpmDependencies })
} }