KT-34468 Yarn. Support dependency GitHub version
This commit is contained in:
committed by
Ilya Goncharov
parent
afb8ff1dd5
commit
c2b3dd8b33
+5
-4
@@ -11,6 +11,7 @@ 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 {
|
||||
@@ -99,7 +100,7 @@ abstract class YarnBasics : NpmApi {
|
||||
) {
|
||||
val yarnLock = nodeWorkDir.resolve("yarn.lock")
|
||||
if (yarnLock.isFile) {
|
||||
val byKey = YarnLock.parse(yarnLock).entries.associateBy { it.key }
|
||||
val byKey = YarnLock.parse(yarnLock).entries.associateBy { it.dependencyKey }
|
||||
val visited = mutableMapOf<NpmDependency, NpmDependency>()
|
||||
|
||||
fun resolveRecursively(src: NpmDependency): NpmDependency {
|
||||
@@ -112,10 +113,10 @@ abstract class YarnBasics : NpmApi {
|
||||
}
|
||||
visited[src] = src
|
||||
|
||||
val key = YarnLock.key(src.key, src.version)
|
||||
val key = dependencyKey(src.key, src.version)
|
||||
val deps = byKey[key]
|
||||
?: if (src.version == "*") byKey.entries
|
||||
.firstOrNull { it.key.startsWith(YarnLock.key(src.key, "")) }
|
||||
.firstOrNull { it.key.startsWith(dependencyKey(src.key, "")) }
|
||||
?.value
|
||||
else null
|
||||
|
||||
@@ -147,4 +148,4 @@ abstract class YarnBasics : NpmApi {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,10 @@ data class YarnLock(val entries: List<Entry>) {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun key(packageKey: String, version: String) = "$packageKey@$version"
|
||||
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) {
|
||||
var indent: String? = null
|
||||
@@ -105,4 +108,4 @@ data class YarnLock(val entries: List<Entry>) {
|
||||
return root
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user