[Gradle, JS] Support file npm dependencies

#KT-37207 fixed
This commit is contained in:
Ilya Goncharov
2020-03-25 11:27:28 +03:00
parent ad20deb0b3
commit e8df15ac27
2 changed files with 19 additions and 5 deletions
@@ -12,7 +12,6 @@ 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.NpmDependency
import org.jetbrains.kotlin.gradle.targets.js.npm.resolved.KotlinCompilationNpmResolution
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLock.Companion.dependencyKey
import java.io.File
abstract class YarnBasics : NpmApi {
@@ -145,7 +144,7 @@ abstract class YarnBasics : NpmApi {
}
}
private class YarnEntryRegistry(lockFile: File) {
private class YarnEntryRegistry(private val lockFile: File) {
val entryMap = YarnLock.parse(lockFile)
.entries
.associateBy { it.dependencyKey }
@@ -168,4 +167,22 @@ private class YarnEntryRegistry(lockFile: File) {
"Cannot find $key in yarn.lock"
}
}
val YarnLock.Entry.dependencyKey: String
get() = key.correctDependencyKey()
private fun dependencyKey(packageKey: String, version: String) =
YarnLock.dependencyKey(packageKey, version).correctDependencyKey()
private fun String.correctDependencyKey(): String {
var correctedKey = replace("@github:", "@")
if ("@file:" in correctedKey) {
val location = correctedKey.substringAfter("@file:")
val path = lockFile.parentFile.resolve(location).canonicalPath
correctedKey = correctedKey.replaceAfter("@file:", path)
}
return correctedKey
}
}
@@ -25,9 +25,6 @@ data class YarnLock(val entries: List<Entry>) {
}
companion object {
val Entry.dependencyKey: String
get() = key.replace("@github:", "@")
fun dependencyKey(packageKey: String, version: String) = "$packageKey@$version"
private class Node(val parent: Node?, val value: String? = null) {