[Gradle, JS] Prevent adding unintended implicit dependencies
The way JS compilations are mapped to task requirements were changed from `compilation` objects to compilations's `disambiguatedName` in order to support Gradle configuration cache. This may lead to implicitly adding unwanted dependencies in multi-module projects since compilation's `disambiguatedName` is unique within a module, not within a whole multi-module project. #KT-47045 Fixed
This commit is contained in:
+7
-6
@@ -19,8 +19,8 @@ class TasksRequirements : Serializable {
|
||||
val byTask: Map<String, Set<RequiredKotlinJsDependency>>
|
||||
get() = _byTask
|
||||
|
||||
internal fun getCompilationNpmRequirements(compilationName: String): Set<NpmDependencyDeclaration> =
|
||||
byCompilation[compilationName]
|
||||
internal fun getCompilationNpmRequirements(projectPath: String, compilationName: String): Set<NpmDependencyDeclaration> =
|
||||
byCompilation["$projectPath:$compilationName"]
|
||||
?: setOf()
|
||||
|
||||
fun addTaskRequirements(task: RequiresNpmDependencies) {
|
||||
@@ -34,11 +34,12 @@ class TasksRequirements : Serializable {
|
||||
.filterIsInstance<NpmDependency>()
|
||||
.toMutableSet()
|
||||
|
||||
val compilation = task.compilation.disambiguatedName
|
||||
if (compilation in byCompilation) {
|
||||
byCompilation[compilation]!!.addAll(requiredNpmDependencies.map { it.toDeclaration() })
|
||||
val projectPath = task.compilation.target.project.path
|
||||
val compilationPath = "$projectPath:${task.compilation.disambiguatedName}"
|
||||
if (compilationPath in byCompilation) {
|
||||
byCompilation[compilationPath]!!.addAll(requiredNpmDependencies.map { it.toDeclaration() })
|
||||
} else {
|
||||
byCompilation[compilation] = requiredNpmDependencies.map { it.toDeclaration() }.toMutableSet()
|
||||
byCompilation[compilationPath] = requiredNpmDependencies.map { it.toDeclaration() }.toMutableSet()
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -371,7 +371,8 @@ internal class KotlinCompilationNpmResolver(
|
||||
)
|
||||
},
|
||||
externalNpmDependencies.map { it.toDeclaration() },
|
||||
fileCollectionDependencies
|
||||
fileCollectionDependencies,
|
||||
projectPath
|
||||
)
|
||||
}
|
||||
|
||||
@@ -400,7 +401,8 @@ internal class KotlinCompilationNpmResolver(
|
||||
var internalCompositeDependencies: Collection<CompositeDependency>,
|
||||
var externalGradleDependencies: Collection<FileExternalGradleDependency>,
|
||||
var externalNpmDependencies: Collection<NpmDependencyDeclaration>,
|
||||
var fileCollectionDependencies: Collection<FileCollectionExternalGradleDependency>
|
||||
var fileCollectionDependencies: Collection<FileCollectionExternalGradleDependency>,
|
||||
val projectPath: String
|
||||
) : Serializable {
|
||||
private val projectPackagesDir by lazy { compilationResolver.nodeJs.projectPackagesDir }
|
||||
private val rootDir by lazy { compilationResolver.nodeJs.rootProject.rootDir }
|
||||
@@ -454,7 +456,7 @@ internal class KotlinCompilationNpmResolver(
|
||||
.filterNotNull()
|
||||
|
||||
val toolsNpmDependencies = compilationResolver.rootResolver.nodeJs.taskRequirements
|
||||
.getCompilationNpmRequirements(compilationResolver.compilationDisambiguatedName)
|
||||
.getCompilationNpmRequirements(projectPath, compilationResolver.compilationDisambiguatedName)
|
||||
|
||||
val dukatIfNecessary = if (externalNpmDependencies.any { it.generateExternals }) {
|
||||
setOf(
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
|
||||
@get:Input
|
||||
internal val toolsNpmDependencies: List<String> by lazy {
|
||||
nodeJs.taskRequirements
|
||||
.getCompilationNpmRequirements(compilationDisambiguatedName)
|
||||
.getCompilationNpmRequirements(projectPath, compilationDisambiguatedName)
|
||||
.map { it.toString() }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user