[Gradle, JS] Use NpmVersionConstraint
^KT-41054 fixed
This commit is contained in:
+3
-3
@@ -23,7 +23,7 @@ class NpmDependencyConstraint(
|
|||||||
|
|
||||||
private var reason: String? = null
|
private var reason: String? = null
|
||||||
|
|
||||||
private val versionConstraint = DefaultMutableVersionConstraint(version)
|
private val versionConstraint = NpmVersionConstraint(version)
|
||||||
|
|
||||||
override fun getGroup(): String? = null
|
override fun getGroup(): String? = null
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class NpmDependencyConstraint(
|
|||||||
override fun version(configureAction: Action<in MutableVersionConstraint>) {
|
override fun version(configureAction: Action<in MutableVersionConstraint>) {
|
||||||
configureAction.execute(versionConstraint)
|
configureAction.execute(versionConstraint)
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
nodeJs.npmResolutionManager.putNpmResolution(path, version)
|
nodeJs.npmResolutionManager.putNpmResolution(path, versionConstraint.toSemVer())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getReason(): String? {
|
override fun getReason(): String? {
|
||||||
@@ -75,7 +75,7 @@ class NpmDependencyConstraint(
|
|||||||
|
|
||||||
override fun getVersionConstraint(): VersionConstraint {
|
override fun getVersionConstraint(): VersionConstraint {
|
||||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||||
nodeJs.npmResolutionManager.putNpmResolution(path, version)
|
nodeJs.npmResolutionManager.putNpmResolution(path, versionConstraint.toSemVer())
|
||||||
return versionConstraint
|
return versionConstraint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* 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.npm
|
||||||
|
|
||||||
|
import com.github.gundy.semver4j.SemVer
|
||||||
|
import org.gradle.api.internal.artifacts.dependencies.DefaultMutableVersionConstraint
|
||||||
|
|
||||||
|
class NpmVersionConstraint(
|
||||||
|
version: String
|
||||||
|
) : DefaultMutableVersionConstraint(version) {
|
||||||
|
override fun rejectAll() {
|
||||||
|
super.rejectAll()
|
||||||
|
reject("0.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toSemVer(): String {
|
||||||
|
if (requiredVersion.isEmpty()) {
|
||||||
|
return preferredVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strictVersion.isNotEmpty()) {
|
||||||
|
return strictVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
val requiredRange = "^$requiredVersion"
|
||||||
|
return if (SemVer.valid(requiredRange) && SemVer.satisfies(requiredVersion, requiredRange)) {
|
||||||
|
requiredRange
|
||||||
|
} else {
|
||||||
|
requiredVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user