[Gradle, JS] Union of Npm Ranges

^KT-41054 fixed
This commit is contained in:
Ilya Goncharov
2020-08-04 17:58:25 +03:00
parent 14fac83e2b
commit 9bb49ac370
@@ -19,7 +19,9 @@ val NONE_RANGE = NpmRange(
.toSemVer() .toSemVer()
) )
infix fun NpmRange.or(other: NpmRange): List<NpmRange> { infix fun NpmRange.union(other: NpmRange): List<NpmRange> {
if (!isIntersect(other)) return listOf(this, other)
val startVersion = min(this.startVersion, other.startVersion) val startVersion = min(this.startVersion, other.startVersion)
val endVersion = max(this.endVersion, other.endVersion) val endVersion = max(this.endVersion, other.endVersion)
@@ -29,7 +31,9 @@ infix fun NpmRange.or(other: NpmRange): List<NpmRange> {
startInclusive = if (startVersion == other.startVersion) other.startInclusive else this.startInclusive, startInclusive = if (startVersion == other.startVersion) other.startInclusive else this.startInclusive,
endVersion = endVersion, endVersion = endVersion,
endInclusive = if (startVersion == other.startVersion) other.startInclusive else this.startInclusive endInclusive = if (startVersion == other.startVersion) other.startInclusive else this.startInclusive
) ).let {
listOf(it)
}
} }
infix fun NpmRange.intersect(other: NpmRange): NpmRange? { infix fun NpmRange.intersect(other: NpmRange): NpmRange? {