Skip to content

Commit 9ebb2fc

Browse files
committed
Handle NPM prerelease caret range expression
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 53af957 commit 9ebb2fc

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/univers/version_range.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,26 @@ def from_native(cls, string):
357357
VersionConstraint(comparator=comparator, version=vrc(constraint))
358358
)
359359
else:
360-
if (
360+
# Handle the prerelease caret range expression.
361+
if constraint.startswith("^") and vrc(constraint.lstrip("^")).is_prerelease():
362+
base_version = vrc(constraint.lstrip("^"))
363+
prerelease = base_version.value.prerelease
364+
base_version.value.prerelease = ()
365+
if base_version.major:
366+
high = base_version.next_major()
367+
elif base_version.minor:
368+
high = base_version.next_minor()
369+
else:
370+
high = base_version.next_patch()
371+
base_version.value.prerelease = prerelease
372+
prerelease_version = base_version
373+
constraints.extend(
374+
[
375+
VersionConstraint(comparator=">=", version=prerelease_version),
376+
VersionConstraint(comparator="<", version=high),
377+
]
378+
)
379+
elif (
361380
constraint.endswith(".x")
362381
or constraint.startswith("~")
363382
or constraint.startswith("^")

0 commit comments

Comments
 (0)