Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/install/PackageManager/PackageManagerEnqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ pub fn enqueue_dependency_with_main_and_success_fn(
while let Some(queries) = curr_list {
let mut curr: Option<&Semver::Query> = Some(&queries.head);
while let Some(query) = curr {
if group.satisfies(query.range.left.version, buf, buf)
|| group.satisfies(query.range.right.version, buf, buf)
if group.satisfies(query.range.left.boundary_version(), buf, buf)
|| group.satisfies(query.range.right.boundary_version(), buf, buf)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{
name = aliased.npm().name;
name_hash =
Expand Down
44 changes: 11 additions & 33 deletions src/semver/SemverQuery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bun_collections::IntegerBitSet;
use bun_core::strings;

use crate::range::{Comparator, Op as RangeOp};
use crate::version::Tag;
use crate::{Range, SlicedString, Version, version};

// Re-export sub-namespace so
Expand Down Expand Up @@ -728,6 +729,7 @@ impl Token {
major: version.major.unwrap_or(0),
minor: 0,
patch: 0,
tag: Tag::zero_pre(),
..Default::default()
},
},
Expand Down Expand Up @@ -779,6 +781,7 @@ impl Token {
major: version.major.unwrap_or(0),
minor: version.minor.unwrap_or(0),
patch: 0,
tag: Tag::zero_pre(),
..Default::default()
},
},
Expand Down Expand Up @@ -997,7 +1000,7 @@ pub fn parse(input: &[u8], sliced: SlicedString) -> Result<Group, AllocError> {

if hyphenate {
let second_parsed = Version::parse(sliced.sub(&input[i..]));
let mut second_version = second_parsed.version.min();
let second_version = second_parsed.version.min();
if second_version.tag.has_build() {
list.flags.set(Flags::BUILD);
}
Expand All @@ -1016,51 +1019,26 @@ pub fn parse(input: &[u8], sliced: SlicedString) -> Result<Group, AllocError> {
}
}
Wildcard::Minor => {
// "1.0.0 - 1.x" --> ">=1.0.0 < 2.0.0"
let right = match second_version.major.checked_add(1) {
Some(m) => {
second_version.major = m;
second_version.minor = 0;
second_version.patch = 0;
Comparator {
op: RangeOp::Lt,
version: second_version,
}
}
None => Comparator::lt_next_major(second_version.major),
};

// "1.0.0 - 1.x" --> ">=1.0.0 <2.0.0-0"
Range {
left: Comparator {
op: RangeOp::Gte,
version,
},
right,
right: Comparator::lt_next_major(second_version.major),
}
}
Wildcard::Patch => {
// "1.0.0 - 1.0.x" --> ">=1.0.0 <1.1.0"
let right = match second_version.minor.checked_add(1) {
Some(m) => {
second_version.minor = m;
second_version.patch = 0;
Comparator {
op: RangeOp::Lt,
version: second_version,
}
}
None => Comparator::lt_next_minor(
second_version.major,
second_version.minor,
),
};

// "1.0.0 - 1.0.x" --> ">=1.0.0 <1.1.0-0"
Range {
left: Comparator {
op: RangeOp::Gte,
version,
},
right,
right: Comparator::lt_next_minor(
second_version.major,
second_version.minor,
),
}
}
Wildcard::None => Range {
Expand Down
21 changes: 18 additions & 3 deletions src/semver/SemverRange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::fmt;

use crate::Version;
use crate::query::token::Wildcard;
use crate::version::Tag;

#[repr(u8)]
#[derive(Copy, Clone, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -183,14 +184,15 @@ pub struct Comparator {
}

impl Comparator {
/// `< {major+1}.0.0`, or `<= u64::MAX.u64::MAX.u64::MAX` when `major+1`
/// `< {major+1}.0.0-0`, or `<= u64::MAX.u64::MAX.u64::MAX` when `major+1`
/// would overflow so the desugared range stays non-empty at the ceiling.
pub(crate) fn lt_next_major(major: u64) -> Comparator {
match major.checked_add(1) {
Some(m) => Comparator {
op: Op::Lt,
version: Version {
major: m,
tag: Tag::zero_pre(),
..Default::default()
},
},
Expand All @@ -206,14 +208,15 @@ impl Comparator {
}
}

/// `< {major}.{minor+1}.0`, or `<= {major}.u64::MAX.u64::MAX` on overflow.
/// `< {major}.{minor+1}.0-0`, or `<= {major}.u64::MAX.u64::MAX` on overflow.
pub(crate) fn lt_next_minor(major: u64, minor: u64) -> Comparator {
match minor.checked_add(1) {
Some(m) => Comparator {
op: Op::Lt,
version: Version {
major,
minor: m,
tag: Tag::zero_pre(),
..Default::default()
},
},
Expand All @@ -229,7 +232,7 @@ impl Comparator {
}
}

/// `< {major}.{minor}.{patch+1}`, or `<= {major}.{minor}.u64::MAX` on overflow.
/// `< {major}.{minor}.{patch+1}-0`, or `<= {major}.{minor}.u64::MAX` on overflow.
pub(crate) fn lt_next_patch(major: u64, minor: u64, patch: u64) -> Comparator {
match patch.checked_add(1) {
Some(p) => Comparator {
Expand All @@ -238,6 +241,7 @@ impl Comparator {
major,
minor,
patch: p,
tag: Tag::zero_pre(),
..Default::default()
},
},
Expand All @@ -253,6 +257,17 @@ impl Comparator {
}
}

/// The boundary as a version to test against another range. A `<X.Y.Z-0` bound stands
/// for "below X.Y.Z", so it yields the release `X.Y.Z`: `Group::satisfies` would apply
/// its prerelease rule to `X.Y.Z-0`.
Comment thread
robobun marked this conversation as resolved.
Resolved
pub fn boundary_version(self) -> Version {
let mut version = self.version;
if self.op == Op::Lt && version.tag.eql(Tag::zero_pre()) {
version.tag = Tag::default();
}
version
}

#[inline]
pub(crate) fn eql(self, rhs: Comparator) -> bool {
self.op == rhs.op && self.version.eql(rhs.version)
Expand Down
10 changes: 10 additions & 0 deletions src/semver/Version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,16 @@ pub struct Tag {
// TODO: support multiple tags

impl Tag {
/// `-0`, the lowest prerelease. node-semver puts it on every exclusive upper bound it
/// derives (`^1.2.3` is `>=1.2.3 <2.0.0-0`) so no prerelease of that bound is below it.
Comment thread
robobun marked this conversation as resolved.
Resolved
pub(crate) fn zero_pre() -> Tag {
let zero: &[u8] = b"0";
Tag {
pre: SlicedString::init(zero, zero).external(),
build: ExternalString::default(),
}
}

pub(crate) fn order_pre(self, rhs: Tag, lhs_buf: &[u8], rhs_buf: &[u8]) -> Ordering {
let lhs_str = self.pre.slice(lhs_buf);
let rhs_str = rhs.pre.slice(rhs_buf);
Expand Down
6 changes: 3 additions & 3 deletions test/cli/install/__snapshots__/bun-workspaces.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ exports[`dependency on workspace without version in package.json: version: 1 1`]
"literal": "1",
"npm": {
"name": "no-deps",
"version": "<2.0.0 >=1.0.0"
"version": "<2.0.0-0 >=1.0.0"
},
"package_id": 3,
"behavior": {
Expand Down Expand Up @@ -963,7 +963,7 @@ exports[`dependency on workspace without version in package.json: version: 1.* 1
"literal": "1.*",
"npm": {
"name": "no-deps",
"version": "<2.0.0 >=1.0.0"
"version": "<2.0.0-0 >=1.0.0"
},
"package_id": 3,
"behavior": {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ exports[`dependency on workspace without version in package.json: version: 1.1.*
"literal": "1.1.*",
"npm": {
"name": "no-deps",
"version": "<1.2.0 >=1.1.0"
"version": "<1.2.0-0 >=1.1.0"
},
"package_id": 3,
"behavior": {
Expand Down
Loading
Loading