From b26605a58f18423aca98655feaa455ab50f532f1 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 9 Feb 2024 11:10:23 +1100 Subject: [PATCH] BREAKING(semver): remove `SemVerRange` and `isSemVerRange()` --- semver/_comparator_intersects_test.ts | 63 ------------------- semver/format_range.ts | 8 +-- semver/format_range_test.ts | 68 --------------------- semver/gtr.ts | 4 +- semver/is_semver_range.ts | 26 -------- semver/is_semver_range_test.ts | 24 -------- semver/ltr.ts | 4 +- semver/max_satisfying.ts | 4 +- semver/min_satisfying.ts | 4 +- semver/mod.ts | 1 - semver/outside.ts | 4 +- semver/parse_range.ts | 8 +-- semver/range_intersects.ts | 16 +++-- semver/range_intersects_test.ts | 87 --------------------------- semver/range_max.ts | 6 +- semver/range_min.ts | 6 +- semver/range_min_test.ts | 76 ----------------------- semver/test_range.ts | 6 +- semver/try_parse_range.ts | 8 +-- semver/types.ts | 12 ---- 20 files changed, 37 insertions(+), 398 deletions(-) delete mode 100644 semver/is_semver_range.ts delete mode 100644 semver/is_semver_range_test.ts diff --git a/semver/_comparator_intersects_test.ts b/semver/_comparator_intersects_test.ts index e49c6cdefc45..7bd461751ebe 100644 --- a/semver/_comparator_intersects_test.ts +++ b/semver/_comparator_intersects_test.ts @@ -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 diff --git a/semver/format_range.ts b/semver/format_range.ts index d8cfed6207cb..837c3e3b4c97 100644 --- a/semver/format_range.ts +++ b/semver/format_range.ts @@ -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"; /** @@ -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("||"); } diff --git a/semver/format_range_test.ts b/semver/format_range_test.ts index 786810a3452a..f6757e8f9d3a 100644 --- a/semver/format_range_test.ts +++ b/semver/format_range_test.ts @@ -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); - }, - }); - } - }, -}); diff --git a/semver/gtr.ts b/semver/gtr.ts index f4ec3f3ecadd..9342ee8ac989 100644 --- a/semver/gtr.ts +++ b/semver/gtr.ts @@ -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"; @@ -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)); } diff --git a/semver/is_semver_range.ts b/semver/is_semver_range.ts deleted file mode 100644 index 8573e74cc6e9..000000000000 --- a/semver/is_semver_range.ts +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import type { SemVerRange } from "./types.ts"; -import { isComparator } from "./_is_comparator.ts"; - -/** - * Does a deep check on the object to determine if its a valid range. - * - * Objects with extra fields are still considered valid if they have at - * least the correct fields. - * - * Adds a type assertion if true. - * @param value The value to check if its a valid SemVerRange - * @returns True if its a valid SemVerRange otherwise false. - * - * @deprecated (will be removed in 0.216.0) Use {@linkcode isRange} instead. - */ -export function isSemVerRange(value: unknown): value is SemVerRange { - if (value === null || value === undefined) return false; - if (Array.isArray(value)) return false; - if (typeof value !== "object") return false; - const { ranges } = value as SemVerRange; - return ( - Array.isArray(ranges) && - ranges.every((r) => Array.isArray(r) && r.every((c) => isComparator(c))) - ); -} diff --git a/semver/is_semver_range_test.ts b/semver/is_semver_range_test.ts deleted file mode 100644 index 3fc005bf648c..000000000000 --- a/semver/is_semver_range_test.ts +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assert } from "../assert/mod.ts"; -import { ALL } from "./constants.ts"; -import { isSemVerRange } from "./is_semver_range.ts"; - -Deno.test({ - name: "valid_range", - fn: async (t) => { - let i = 0; - const ranges: unknown[] = [ - { - ranges: [ - [ALL], - ], - }, - ]; - for (const r of ranges) { - await t.step(`valid_range_${(i++).toString().padStart(2, "0")}`, () => { - const actual = isSemVerRange(r); - assert(actual); - }); - } - }, -}); diff --git a/semver/ltr.ts b/semver/ltr.ts index b076c9ccfcf2..ef3fdf7ffae3 100644 --- a/semver/ltr.ts +++ b/semver/ltr.ts @@ -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"; @@ -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)); } diff --git a/semver/max_satisfying.ts b/semver/max_satisfying.ts index ecbc2f8e60f4..bd7b4aa03e27 100644 --- a/semver/max_satisfying.ts +++ b/semver/max_satisfying.ts @@ -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"; @@ -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) { diff --git a/semver/min_satisfying.ts b/semver/min_satisfying.ts index acfe66f879f9..3b74391cb11b 100644 --- a/semver/min_satisfying.ts +++ b/semver/min_satisfying.ts @@ -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"; @@ -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) { diff --git a/semver/mod.ts b/semver/mod.ts index aaa5111af1ac..9d088fb9aa01 100644 --- a/semver/mod.ts +++ b/semver/mod.ts @@ -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"; diff --git a/semver/outside.ts b/semver/outside.ts index ae079bf12e50..3bbcd7290ed2 100644 --- a/semver/outside.ts +++ b/semver/outside.ts @@ -1,7 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { greaterThan } from "./greater_than.ts"; import { lessThan } from "./less_than.ts"; -import type { Range, SemVer, SemVerRange } from "./types.ts"; +import type { Range, SemVer } from "./types.ts"; import { rangeMax } from "./range_max.ts"; import { rangeMin } from "./range_min.ts"; @@ -18,7 +18,7 @@ import { rangeMin } from "./range_min.ts"; */ export function outside( version: SemVer, - range: SemVerRange | Range, + range: Range, hilo?: ">" | "<", ): boolean { switch (hilo) { diff --git a/semver/parse_range.ts b/semver/parse_range.ts index 55baa406b603..c491c95d991f 100644 --- a/semver/parse_range.ts +++ b/semver/parse_range.ts @@ -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"; @@ -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; } diff --git a/semver/range_intersects.ts b/semver/range_intersects.ts index 7085922a40ee..9dc802c40f70 100644 --- a/semver/range_intersects.ts +++ b/semver/range_intersects.ts @@ -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)); }); } @@ -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)); }); diff --git a/semver/range_intersects_test.ts b/semver/range_intersects_test.ts index a8afb928844f..dd24b55459bf 100644 --- a/semver/range_intersects_test.ts +++ b/semver/range_intersects_test.ts @@ -86,90 +86,3 @@ Deno.test({ } }, }); - -Deno.test({ - name: "rangesIntersects() handles deprecated SemVerRange.ranges property", - fn: async (t) => { - const versions: [string, string, boolean][] = [ - ["1.3.0 || <1.0.0 >2.0.0", "1.3.0 || <1.0.0 >2.0.0", true], - [">0.0.0", "<1.0.0 >2.0.0", false], - ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0", false], - ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], - [">1.0.0 <=2.0.0", "2.0.0", true], - ["<1.0.0 >=2.0.0", "2.1.0", false], - ["<1.0.0 >=2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], - ["1.5.x", "<1.5.0 || >=1.6.0", false], - ["<1.5.0 || >=1.6.0", "1.5.x", false], - [ - "<1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", - ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", - false, - ], - [ - "<=1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", - ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", - true, - ], - [">=1.0.0", "<=1.0.0", true], - [">1.0.0 <1.0.0", "<=0.0.0", false], - ["*", "0.0.1", true], - ["*", ">=1.0.0", true], - ["*", ">1.0.0", true], - ["*", "~1.0.0", true], - ["*", "<1.6.0", true], - ["*", "<=1.6.0", true], - ["1.*", "0.0.1", false], - ["1.*", "2.0.0", false], - ["1.*", "1.0.0", true], - ["1.*", "<2.0.0", true], - ["1.*", ">1.0.0", true], - ["1.*", "<=1.0.0", true], - ["1.*", "^1.0.0", true], - ["1.0.*", "0.0.1", false], - ["1.0.*", "<0.0.1", false], - ["1.0.*", ">0.0.1", true], - ["*", "1.3.0 || <1.0.0 >2.0.0", true], - ["1.3.0 || <1.0.0 >2.0.0", "*", true], - ["1.*", "1.3.0 || <1.0.0 >2.0.0", true], - ["x", "0.0.1", true], - ["x", ">=1.0.0", true], - ["x", ">1.0.0", true], - ["x", "~1.0.0", true], - ["x", "<1.6.0", true], - ["x", "<=1.6.0", true], - ["1.x", "0.0.1", false], - ["1.x", "2.0.0", false], - ["1.x", "1.0.0", true], - ["1.x", "<2.0.0", true], - ["1.x", ">1.0.0", true], - ["1.x", "<=1.0.0", true], - ["1.x", "^1.0.0", true], - ["1.0.x", "0.0.1", false], - ["1.0.x", "<0.0.1", false], - ["1.0.x", ">0.0.1", true], - ["x", "1.3.0 || <1.0.0 >2.0.0", true], - ["1.3.0 || <1.0.0 >2.0.0", "x", true], - ["1.x", "1.3.0 || <1.0.0 >2.0.0", true], - ["*", "*", true], - ["x", "", true], - ]; - - for (const [r1, r2, expected] of versions) { - await t.step({ - name: `${r1} ∩ ${r2}`, - fn: () => { - const range1 = parseRange(r1); - const range2 = parseRange(r2); - const actual1 = rangeIntersects({ ranges: range1.ranges }, { - ranges: range2.ranges, - }); - const actual2 = rangeIntersects({ ranges: range2.ranges }, { - ranges: range1.ranges, - }); - assertEquals(actual1, expected); - assertEquals(actual2, expected); - }, - }); - } - }, -}); diff --git a/semver/range_max.ts b/semver/range_max.ts index 58c402ae469e..40677a796e73 100644 --- a/semver/range_max.ts +++ b/semver/range_max.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { INVALID } from "./constants.ts"; -import type { Range, SemVer, SemVerRange } from "./types.ts"; +import type { Range, SemVer } from "./types.ts"; import { testRange } from "./test_range.ts"; import { comparatorMax } from "./_comparator_max.ts"; import { greaterThan } from "./greater_than.ts"; @@ -10,9 +10,9 @@ import { greaterThan } from "./greater_than.ts"; * @param range The range to calculate the max for * @returns A valid SemVer or INVALID */ -export function rangeMax(range: SemVerRange | Range): SemVer { +export function rangeMax(range: Range): SemVer { let max; - for (const comparators of (Array.isArray(range) ? range : range.ranges)) { + for (const comparators of range) { for (const comparator of comparators) { const candidate = comparatorMax( comparator.semver ?? comparator, diff --git a/semver/range_min.ts b/semver/range_min.ts index 3d47262853d9..653b78fd3b69 100644 --- a/semver/range_min.ts +++ b/semver/range_min.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. import { INVALID } from "./constants.ts"; -import type { Range, SemVer, SemVerRange } from "./types.ts"; +import type { Range, SemVer } from "./types.ts"; import { testRange } from "./test_range.ts"; import { comparatorMin } from "./_comparator_min.ts"; import { lessThan } from "./less_than.ts"; @@ -10,9 +10,9 @@ import { lessThan } from "./less_than.ts"; * @param range The range to calculate the min for * @returns A valid SemVer or INVALID */ -export function rangeMin(range: SemVerRange | Range): SemVer { +export function rangeMin(range: Range): SemVer { let min; - for (const comparators of (Array.isArray(range) ? range : range.ranges)) { + for (const comparators of range) { for (const comparator of comparators) { const candidate = comparatorMin( comparator.semver ?? comparator, diff --git a/semver/range_min_test.ts b/semver/range_min_test.ts index e6deead93add..c71c257dc9a3 100644 --- a/semver/range_min_test.ts +++ b/semver/range_min_test.ts @@ -84,79 +84,3 @@ Deno.test({ } }, }); - -Deno.test({ - name: "rangeMin() handles deprecated SemVerRange.ranges property", - fn: async (t) => { - const versions: [string, string | SemVer][] = [ - // Stars - ["*", "0.0.0"], - ["* || >=2", "0.0.0"], - [">=2 || *", "0.0.0"], - [">2 || *", "0.0.0"], - - // equal - ["1.0.0", "1.0.0"], - ["1.0", "1.0.0"], - ["1.0.x", "1.0.0"], - ["1.0.*", "1.0.0"], - ["1", "1.0.0"], - ["1.x.x", "1.0.0"], - ["1.x.x", "1.0.0"], - ["1.*.x", "1.0.0"], - ["1.x.*", "1.0.0"], - ["1.x", "1.0.0"], - ["1.*", "1.0.0"], - ["=1.0.0", "1.0.0"], - - // Tilde - ["~1.1.1", "1.1.1"], - ["~1.1.1-beta", "1.1.1-beta"], - ["~1.1.1 || >=2", "1.1.1"], - - // Caret - ["^1.1.1", "1.1.1"], - ["^1.1.1-beta", "1.1.1-beta"], - ["^1.1.1 || >=2", "1.1.1"], - - // '-' operator - ["1.1.1 - 1.8.0", "1.1.1"], - ["1.1 - 1.8.0", "1.1.0"], - - // Less / less or equal - ["<2", "0.0.0"], - ["<0.0.0-beta", INVALID], - ["<0.0.1-beta", "0.0.0"], - ["<2 || >4", "0.0.0"], - [">4 || <2", "0.0.0"], - ["<=2 || >=4", "0.0.0"], - [">=4 || <=2", "0.0.0"], - ["<0.0.0-beta >0.0.0-alpha", INVALID], - [">0.0.0-alpha <0.0.0-beta", INVALID], - - // Greater than or equal - [">=1.1.1 <2 || >=2.2.2 <2", "1.1.1"], - [">=2.2.2 <2 || >=1.1.1 <2", "1.1.1"], - - // Greater than but not equal - [">1.0.0", "1.0.1"], - [">1.0.0-0", "1.0.0-1"], - [">1.0.0-beta", "1.0.0-beta.0"], - [">2 || >1.0.0", "1.0.1"], - [">2 || >1.0.0-0", "1.0.0-1"], - [">2 || >1.0.0-beta", "1.0.0-beta.0"], - - // Impossible range - [">4 <3", INVALID], - ]; - - for (const [a, b] of versions) { - await t.step(a, () => { - const range = parseRange(a); - const version = typeof b === "string" ? parse(b) : b; - const min = rangeMin({ ranges: range.ranges }); - assert(equals(min, version), `${format(min)} != ${format(version)}`); - }); - } - }, -}); diff --git a/semver/test_range.ts b/semver/test_range.ts index 3c876ca68f20..3188d435dd95 100644 --- a/semver/test_range.ts +++ b/semver/test_range.ts @@ -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 { greaterOrEqual } from "./greater_or_equal.ts"; import { lessOrEqual } from "./less_or_equal.ts"; import { comparatorMin } from "./_comparator_min.ts"; @@ -13,9 +13,9 @@ import { comparatorMax } from "./_comparator_max.ts"; */ export function testRange( version: SemVer, - range: SemVerRange | Range, + range: Range, ): boolean { - for (const r of (Array.isArray(range) ? range : range.ranges)) { + for (const r of range) { if ( r.every((c) => greaterOrEqual(version, comparatorMin(c.semver ?? c, c.operator)) && diff --git a/semver/try_parse_range.ts b/semver/try_parse_range.ts index d1c9e33629f9..010580629e3d 100644 --- a/semver/try_parse_range.ts +++ b/semver/try_parse_range.ts @@ -1,16 +1,16 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { Range, SemVerRange } from "./types.ts"; +import { Range } from "./types.ts"; import { parseRange } from "./parse_range.ts"; /** - * A tries to parse a valid SemVerRange string or returns undefined + * A tries to parse a valid Range string or returns undefined * @param range The range string - * @returns A SemVerRange object if valid otherwise `undefined` + * @returns A Range object if valid otherwise `undefined` */ export function tryParseRange( range: string, -): SemVerRange & Range | undefined { +): Range | undefined { try { // Return '*' instead of '' so that truthiness works. // This will throw if it's invalid anyway diff --git a/semver/types.ts b/semver/types.ts index b1a1c10f4431..7db09669a03d 100644 --- a/semver/types.ts +++ b/semver/types.ts @@ -50,15 +50,3 @@ export interface SemVer { * inner array represents AND comparisons. */ export type Range = Comparator[][]; - -/** - * A type representing a semantic version range. The ranges consist of - * a nested array, which represents a set of OR comparisons while the - * inner array represents AND comparisons. - * - * @deprecated (will be removed in 0.216.0) Use {@linkcode Range} instead. - */ -export interface SemVerRange { - // The outer array is OR while each inner array is AND - ranges: Comparator[][]; -}