[Gradle, JS] Filter DCE candidates

We should process DCE only for:
- JARs
- JSs with neighbors meta.js
This commit is contained in:
Ilya Goncharov
2019-10-17 17:19:59 +03:00
parent faa5846252
commit 51f4dc5af0
@@ -67,7 +67,9 @@ open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJs
@TaskAction
fun performDce() {
val inputFiles = (listOf(source) + classpath.map { project.fileTree(it) })
val inputFiles = (listOf(source) + classpath
.filter { isDceCandidate(it) }
.map { project.fileTree(it) })
.reduce(FileTree::plus)
.files.map { it.path }
@@ -83,4 +85,16 @@ open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJs
)
throwGradleExceptionIfError(exitCode)
}
private fun isDceCandidate(file: File): Boolean {
if (file.extension == "jar") {
return true
}
if (file.extension != "js" || file.name.endsWith(".meta.js")) {
return false
}
return File("${file.nameWithoutExtension}.meta.js").exists()
}
}