[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>>
|
val byTask: Map<String, Set<RequiredKotlinJsDependency>>
|
||||||
get() = _byTask
|
get() = _byTask
|
||||||
|
|
||||||
internal fun getCompilationNpmRequirements(compilationName: String): Set<NpmDependencyDeclaration> =
|
internal fun getCompilationNpmRequirements(projectPath: String, compilationName: String): Set<NpmDependencyDeclaration> =
|
||||||
byCompilation[compilationName]
|
byCompilation["$projectPath:$compilationName"]
|
||||||
?: setOf()
|
?: setOf()
|
||||||
|
|
||||||
fun addTaskRequirements(task: RequiresNpmDependencies) {
|
fun addTaskRequirements(task: RequiresNpmDependencies) {
|
||||||
@@ -34,11 +34,12 @@ class TasksRequirements : Serializable {
|
|||||||
.filterIsInstance<NpmDependency>()
|
.filterIsInstance<NpmDependency>()
|
||||||
.toMutableSet()
|
.toMutableSet()
|
||||||
|
|
||||||
val compilation = task.compilation.disambiguatedName
|
val projectPath = task.compilation.target.project.path
|
||||||
if (compilation in byCompilation) {
|
val compilationPath = "$projectPath:${task.compilation.disambiguatedName}"
|
||||||
byCompilation[compilation]!!.addAll(requiredNpmDependencies.map { it.toDeclaration() })
|
if (compilationPath in byCompilation) {
|
||||||
|
byCompilation[compilationPath]!!.addAll(requiredNpmDependencies.map { it.toDeclaration() })
|
||||||
} else {
|
} 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() },
|
externalNpmDependencies.map { it.toDeclaration() },
|
||||||
fileCollectionDependencies
|
fileCollectionDependencies,
|
||||||
|
projectPath
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,7 +401,8 @@ internal class KotlinCompilationNpmResolver(
|
|||||||
var internalCompositeDependencies: Collection<CompositeDependency>,
|
var internalCompositeDependencies: Collection<CompositeDependency>,
|
||||||
var externalGradleDependencies: Collection<FileExternalGradleDependency>,
|
var externalGradleDependencies: Collection<FileExternalGradleDependency>,
|
||||||
var externalNpmDependencies: Collection<NpmDependencyDeclaration>,
|
var externalNpmDependencies: Collection<NpmDependencyDeclaration>,
|
||||||
var fileCollectionDependencies: Collection<FileCollectionExternalGradleDependency>
|
var fileCollectionDependencies: Collection<FileCollectionExternalGradleDependency>,
|
||||||
|
val projectPath: String
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
private val projectPackagesDir by lazy { compilationResolver.nodeJs.projectPackagesDir }
|
private val projectPackagesDir by lazy { compilationResolver.nodeJs.projectPackagesDir }
|
||||||
private val rootDir by lazy { compilationResolver.nodeJs.rootProject.rootDir }
|
private val rootDir by lazy { compilationResolver.nodeJs.rootProject.rootDir }
|
||||||
@@ -454,7 +456,7 @@ internal class KotlinCompilationNpmResolver(
|
|||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
|
|
||||||
val toolsNpmDependencies = compilationResolver.rootResolver.nodeJs.taskRequirements
|
val toolsNpmDependencies = compilationResolver.rootResolver.nodeJs.taskRequirements
|
||||||
.getCompilationNpmRequirements(compilationResolver.compilationDisambiguatedName)
|
.getCompilationNpmRequirements(projectPath, compilationResolver.compilationDisambiguatedName)
|
||||||
|
|
||||||
val dukatIfNecessary = if (externalNpmDependencies.any { it.generateExternals }) {
|
val dukatIfNecessary = if (externalNpmDependencies.any { it.generateExternals }) {
|
||||||
setOf(
|
setOf(
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ open class KotlinPackageJsonTask : DefaultTask() {
|
|||||||
@get:Input
|
@get:Input
|
||||||
internal val toolsNpmDependencies: List<String> by lazy {
|
internal val toolsNpmDependencies: List<String> by lazy {
|
||||||
nodeJs.taskRequirements
|
nodeJs.taskRequirements
|
||||||
.getCompilationNpmRequirements(compilationDisambiguatedName)
|
.getCompilationNpmRequirements(projectPath, compilationDisambiguatedName)
|
||||||
.map { it.toString() }
|
.map { it.toString() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user