Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING(semver): remove SemVerRange and isSemVerRange() #4295

Merged
merged 2 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
63 changes: 0 additions & 63 deletions semver/_comparator_intersects_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,6 @@ import { parseComparator } from "./_parse_comparator.ts";
import { comparatorIntersects } from "./_comparator_intersects.ts";
import { rangeIntersects } from "./range_intersects.ts";

Deno.test("comparatorIntersects() handles deprecated SemVerRange.ranges property", async (t) => {
const versions: [string, string, boolean][] = [
// One is a Version
["1.3.0", ">=1.3.0", true],
["1.3.0", ">1.3.0", false],
[">=1.3.0", "1.3.0", true],
[">1.3.0", "1.3.0", false],

// Same direction increasing
[">1.3.0", ">1.2.0", true],
[">1.2.0", ">1.3.0", true],
[">=1.2.0", ">1.3.0", true],
[">1.2.0", ">=1.3.0", true],

// Same direction decreasing
["<1.3.0", "<1.2.0", true],
["<1.2.0", "<1.3.0", true],
["<=1.2.0", "<1.3.0", true],
["<1.2.0", "<=1.3.0", true],

// Different directions, same semver and inclusive operator
[">=1.3.0", "<=1.3.0", true],
[">=v1.3.0", "<=1.3.0", true],
[">=1.3.0", ">=1.3.0", true],
["<=1.3.0", "<=1.3.0", true],
["<=1.3.0", "<=v1.3.0", true],
[">1.3.0", "<=1.3.0", false],
[">=1.3.0", "<1.3.0", false],

// Opposite matching directions
[">1.0.0", "<2.0.0", true],
[">=1.0.0", "<2.0.0", true],
[">=1.0.0", "<=2.0.0", true],
[">1.0.0", "<=2.0.0", true],
["<=2.0.0", ">1.0.0", true],
["<=1.0.0", ">=2.0.0", false],
];
for (const v of versions) {
const comparator1 = parseComparator(v[0]);
const comparator2 = parseComparator(v[1]);
const expect = v[2];
await t.step({
name: `${v[0]} ${expect ? "∩" : "∁"} ${v[1]}`,
fn: () => {
const actual1 = comparatorIntersects(comparator1, comparator2);
const actual2 = comparatorIntersects(comparator2, comparator1);
const actual3 = rangeIntersects(
{ ranges: [[comparator1]] },
{ ranges: [[comparator2]] },
);
const actual4 = rangeIntersects(
{ ranges: [[comparator2]] },
{ ranges: [[comparator1]] },
);
assertEquals(actual1, expect);
assertEquals(actual2, expect);
assertEquals(actual3, expect);
assertEquals(actual4, expect);
},
});
}
});

Deno.test("comparatorIntersects()", async (t) => {
const versions: [string, string, boolean][] = [
// One is a Version
Expand Down
8 changes: 3 additions & 5 deletions semver/format_range.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { Range, SemVerRange } from "./types.ts";
import type { Range } from "./types.ts";
import { comparatorFormat } from "./_comparator_format.ts";

/**
Expand All @@ -8,9 +8,7 @@ import { comparatorFormat } from "./_comparator_format.ts";
* @param range The range to format
* @returns A string representation of the range
*/
export function formatRange(range: SemVerRange | Range): string {
return (Array.isArray(range) ? range : range.ranges).map((c) =>
c.map((c) => comparatorFormat(c)).join(" ")
)
export function formatRange(range: Range): string {
return range.map((c) => c.map((c) => comparatorFormat(c)).join(" "))
.join("||");
}
68 changes: 0 additions & 68 deletions semver/format_range_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,71 +71,3 @@ Deno.test({
}
},
});

Deno.test({
name: "formatRange() handles deprecated SemVerRange.ranges property",
fn: async (t) => {
const versions: [string, string][] = [
["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"],
["1.0.0", "1.0.0"],
[">=*", "*"],
["", "*"],
["*", "*"],
[">=1.0.0", ">=1.0.0"],
[">1.0.0", ">1.0.0"],
["<=2.0.0", "<=2.0.0"],
["1", ">=1.0.0 <2.0.0"],
["<=2.0.0", "<=2.0.0"],
["<=2.0.0", "<=2.0.0"],
["<2.0.0", "<2.0.0"],
["<2.0.0", "<2.0.0"],
[">=0.1.97", ">=0.1.97"],
[">=0.1.97", ">=0.1.97"],
["0.1.20 || 1.2.4", "0.1.20||1.2.4"],
[">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"],
[">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"],
[">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"],
["||", "*||*"],
["2.x.x", ">=2.0.0 <3.0.0"],
["1.2.x", ">=1.2.0 <1.3.0"],
["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"],
["1.2.x || 2.x", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"],
["x", "*"],
["2.*.*", ">=2.0.0 <3.0.0"],
["1.2.*", ">=1.2.0 <1.3.0"],
["1.2.* || 2.*", ">=1.2.0 <1.3.0||>=2.0.0 <3.0.0"],
["2", ">=2.0.0 <3.0.0"],
["2.3", ">=2.3.0 <2.4.0"],
["~2.4", ">=2.4.0 <2.5.0"],
["~2.4", ">=2.4.0 <2.5.0"],
["~>3.2.1", ">=3.2.1 <3.3.0"],
["~1", ">=1.0.0 <2.0.0"],
["~>1", ">=1.0.0 <2.0.0"],
["~1.0", ">=1.0.0 <1.1.0"],
["^0", ">=0.0.0 <1.0.0"],
["^0.1", ">=0.1.0 <0.2.0"],
["^1.0", ">=1.0.0 <2.0.0"],
["^1.2", ">=1.2.0 <2.0.0"],
["^0.0.1", ">=0.0.1 <0.0.2"],
["^0.0.1-beta", ">=0.0.1-beta <0.0.2"],
["^0.1.2", ">=0.1.2 <0.2.0"],
["^1.2.3", ">=1.2.3 <2.0.0"],
["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"],
["<1", "<1.0.0"],
[">=1", ">=1.0.0"],
["<1.2", "<1.2.0"],
["1", ">=1.0.0 <2.0.0"],
];

for (const [r, expected] of versions) {
await t.step({
name: `${r} -> ${expected}`,
fn: () => {
const range = parseRange(r);
const actual = formatRange({ ranges: range.ranges });
assertEquals(actual, expected);
},
});
}
},
});
4 changes: 2 additions & 2 deletions semver/gtr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { Range, SemVer, SemVerRange } from "./types.ts";
import type { Range, SemVer } from "./types.ts";
import { rangeMax } from "./range_max.ts";
import { greaterThan } from "./greater_than.ts";

Expand All @@ -11,7 +11,7 @@ import { greaterThan } from "./greater_than.ts";
*/
export function gtr(
version: SemVer,
range: SemVerRange | Range,
range: Range,
): boolean {
return greaterThan(version, rangeMax(range));
}
26 changes: 0 additions & 26 deletions semver/is_semver_range.ts

This file was deleted.

24 changes: 0 additions & 24 deletions semver/is_semver_range_test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions semver/ltr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { Range, SemVer, SemVerRange } from "./types.ts";
import type { Range, SemVer } from "./types.ts";
import { lessThan } from "./less_than.ts";
import { rangeMin } from "./range_min.ts";

Expand All @@ -11,7 +11,7 @@ import { rangeMin } from "./range_min.ts";
*/
export function ltr(
version: SemVer,
range: SemVerRange | Range,
range: Range,
): boolean {
return lessThan(version, rangeMin(range));
}
4 changes: 2 additions & 2 deletions semver/max_satisfying.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { Range, SemVer, SemVerRange } from "./types.ts";
import type { Range, SemVer } from "./types.ts";
import { testRange } from "./test_range.ts";
import { greaterThan } from "./greater_than.ts";

Expand All @@ -12,7 +12,7 @@ import { greaterThan } from "./greater_than.ts";
*/
export function maxSatisfying(
versions: SemVer[],
range: SemVerRange | Range,
range: Range,
): SemVer | undefined {
let max;
for (const version of versions) {
Expand Down
4 changes: 2 additions & 2 deletions semver/min_satisfying.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import type { Range, SemVer, SemVerRange } from "./types.ts";
import type { Range, SemVer } from "./types.ts";
import { testRange } from "./test_range.ts";
import { lessThan } from "./less_than.ts";

Expand All @@ -12,7 +12,7 @@ import { lessThan } from "./less_than.ts";
*/
export function minSatisfying(
versions: SemVer[],
range: SemVerRange | Range,
range: Range,
): SemVer | undefined {
let min;
for (const version of versions) {
Expand Down
1 change: 0 additions & 1 deletion semver/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ export * from "./gte.ts";
export * from "./gtr.ts";
export * from "./test_range.ts";
export * from "./increment.ts";
export * from "./is_semver_range.ts";
export * from "./is_semver.ts";
export * from "./lt.ts";
export * from "./lte.ts";
Expand Down
8 changes: 4 additions & 4 deletions semver/parse_range.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { ALL } from "./constants.ts";
import type { Comparator, Range, SemVerRange } from "./types.ts";
import type { Comparator, Range } from "./types.ts";
import { OPERATOR_XRANGE_REGEXP, XRANGE } from "./_shared.ts";
import { parseComparator } from "./_parse_comparator.ts";
import { parseBuild, parsePrerelease } from "./_shared.ts";
Expand Down Expand Up @@ -273,14 +273,14 @@ function parseRangeString(string: string) {
}

/**
* Parses a range string into a SemVerRange object or throws a TypeError.
* Parses a range string into a Range object or throws a TypeError.
* @param range The range set string
* @returns A valid semantic range
*/
export function parseRange(range: string): SemVerRange & Range {
export function parseRange(range: string): Range {
const ranges = range
.split(/\s*\|\|\s*/)
.map((range) => parseHyphenRange(range).flatMap(parseRangeString));
Object.defineProperty(ranges, "ranges", { value: ranges });
return ranges as SemVerRange & Range;
return ranges as Range;
}
16 changes: 7 additions & 9 deletions semver/range_intersects.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { comparatorIntersects } from "./_comparator_intersects.ts";
import type { Comparator, Range, SemVerRange } from "./types.ts";
import type { Comparator, Range } from "./types.ts";

function rangesSatisfiable(ranges: (SemVerRange | Range)[]): boolean {
function rangesSatisfiable(ranges: Range[]): boolean {
return ranges.every((r) => {
// For each OR at least one AND must be satisfiable
return (Array.isArray(r) ? r : r.ranges).some((comparators) =>
comparatorsSatisfiable(comparators)
);
return r.some((comparators) => comparatorsSatisfiable(comparators));
});
}

Expand All @@ -31,12 +29,12 @@ function comparatorsSatisfiable(comparators: Comparator[]): boolean {
* @returns returns true if any
*/
export function rangeIntersects(
r0: SemVerRange | Range,
r1: SemVerRange | Range,
r0: Range,
r1: Range,
): boolean {
return rangesSatisfiable([r0, r1]) &&
(Array.isArray(r0) ? r0 : r0.ranges).some((r00) => {
return (Array.isArray(r1) ? r1 : r1.ranges).some((r11) => {
r0.some((r00) => {
return r1.some((r11) => {
return r00.every((c0) => {
return r11.every((c1) => comparatorIntersects(c0, c1));
});
Expand Down
Loading
Loading