Ignore 'v' and 'V' prefixes in plugin versions

This commit is contained in:
Him188 2020-08-23 02:31:27 +08:00
parent 775b888273
commit 367b17ad7f
2 changed files with 7 additions and 4 deletions

View File

@ -17,11 +17,15 @@ import kotlinx.serialization.builtins.serializer
@Serializer(forClass = Semver::class)
internal object SemverAsStringSerializerLoose : KSerializer<Semver> by String.serializer().map(
serializer = { it.toString() },
deserializer = { Semver(it, Semver.SemverType.LOOSE) }
deserializer = {
Semver(it.removePrefix("v").removePrefix("V"), Semver.SemverType.LOOSE)
}
)
@Serializer(forClass = Semver::class)
internal object SemverAsStringSerializerIvy : KSerializer<Semver> by String.serializer().map(
serializer = { it.toString() },
deserializer = { Semver(it, Semver.SemverType.IVY) }
deserializer = {
Semver(it.removePrefix("v").removePrefix("V"), Semver.SemverType.IVY)
}
)

View File

@ -14,7 +14,6 @@ import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.encodeToString
import net.mamoe.mirai.console.internal.data.SemverAsStringSerializerIvy
import net.mamoe.mirai.console.internal.data.map
import net.mamoe.yamlkt.Yaml
import net.mamoe.yamlkt.YamlDynamicSerializer
@ -49,7 +48,7 @@ public interface PluginDescription {
*
* 语法参考: ([语义化版本 2.0.0](https://semver.org/lang/zh-CN/))
*
* @see Semver 语义化版本
* @see Semver 语义化版本. 允许 [宽松][Semver.SemverType.LOOSE] 类型版本.
*/
public val version: Semver