[Gradle, JS] Process quoted value in yarn.lock
#KT-38990 fixed
This commit is contained in:
+34
-10
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
package org.jetbrains.kotlin.gradle.targets.js.yarn
|
||||||
@@ -68,15 +68,36 @@ data class YarnLock(val entries: List<Entry>) {
|
|||||||
} else line
|
} else line
|
||||||
|
|
||||||
if (line1.isNotEmpty()) {
|
if (line1.isNotEmpty()) {
|
||||||
val values = line1.substring(indentPos).split(" ").map { value ->
|
var line2: String = line1
|
||||||
val value1 = value.removeSuffix(",")
|
val quotedValues = QUOTED_VALUE.findAll(line1)
|
||||||
if (value1.startsWith("\""))
|
.flatMap { it.groupValues.drop(1).asSequence() }
|
||||||
try {
|
.toList()
|
||||||
JsonReader(StringReader(value1)).nextString()
|
.apply {
|
||||||
} catch (e: Throwable) {
|
forEachIndexed { index, item ->
|
||||||
value1.removePrefix("\"").removeSuffix("\"")
|
line2 = line2.replace(
|
||||||
|
"""
|
||||||
|
"$item"
|
||||||
|
""".trimIndent(),
|
||||||
|
"""
|
||||||
|
"$$index"
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else value1
|
}
|
||||||
|
|
||||||
|
val values = line2.substring(indentPos).split(" ").map { value ->
|
||||||
|
val value1 = value.removeSuffix(",")
|
||||||
|
if (value1.startsWith("\"")) {
|
||||||
|
val (index) = QUOTED_PLACEHOLDER.find(value1)!!.destructured
|
||||||
|
val value2 = """
|
||||||
|
"${quotedValues[index.toInt()]}"
|
||||||
|
""".trimIndent()
|
||||||
|
try {
|
||||||
|
JsonReader(StringReader(value2)).nextString()
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
value2.removePrefix("\"").removeSuffix("\"")
|
||||||
|
}
|
||||||
|
} else value1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onNewLevel) {
|
if (onNewLevel) {
|
||||||
@@ -106,3 +127,6 @@ data class YarnLock(val entries: List<Entry>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val QUOTED_VALUE = """"(.+?)"""".toRegex()
|
||||||
|
private val QUOTED_PLACEHOLDER = """\$(\d+)""".toRegex()
|
||||||
Reference in New Issue
Block a user