Skip to content

Commit 5945a9e

Browse files
committed
Handle npm caret range expression
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 0113d67 commit 5945a9e

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/univers/version_range.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,26 @@ def from_native(cls, string):
357357
VersionConstraint(comparator=comparator, version=vrc(constraint))
358358
)
359359
else:
360-
if (
361-
constraint.endswith(".x")
362-
or constraint.startswith("~")
363-
or constraint.startswith("^")
364-
):
360+
# Handle caret range expression.
361+
if constraint.startswith("^"):
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+
lower = base_version
373+
constraints.extend(
374+
[
375+
VersionConstraint(comparator=">=", version=lower),
376+
VersionConstraint(comparator="<", version=high),
377+
]
378+
)
379+
elif constraint.endswith(".x") or constraint.startswith("~"):
365380
constraints.extend(
366381
get_npm_version_constraints_from_semver_npm_spec(
367382
string=constraint, cls=cls

0 commit comments

Comments
 (0)