diff --git a/semver/constants.ts b/semver/constants.ts index 8b0a669949ba..681d60accb34 100644 --- a/semver/constants.ts +++ b/semver/constants.ts @@ -68,7 +68,6 @@ export const ANY: SemVer = { export const ALL: Comparator = { operator: undefined, ...ANY, - semver: ANY, }; /** @@ -77,5 +76,4 @@ export const ALL: Comparator = { export const NONE: Comparator = { operator: "<", ...MIN, - semver: MIN, }; diff --git a/semver/format.ts b/semver/format.ts index 6704a3c52f5f..371266a89dac 100644 --- a/semver/format.ts +++ b/semver/format.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { ANY } from "./constants.ts"; import type { SemVer } from "./types.ts"; +import { isWildcardComparator } from "./_shared.ts"; function formatNumber(value: number) { if (value === Number.POSITIVE_INFINITY) { @@ -23,7 +23,7 @@ function formatNumber(value: number) { * @returns The string representation of a semantic version. */ export function format(semver: SemVer): string { - if (semver === ANY) { + if (isWildcardComparator(semver)) { return "*"; } diff --git a/semver/format_range.ts b/semver/format_range.ts index fa1a83d557f0..2c537edbdf73 100644 --- a/semver/format_range.ts +++ b/semver/format_range.ts @@ -3,10 +3,8 @@ import { format } from "./format.ts"; import type { Comparator, Range } from "./types.ts"; function formatComparator(comparator: Comparator): string { - const { semver, operator } = comparator; - return `${operator === undefined ? "" : operator}${ - format(semver ?? comparator) - }`; + const { operator } = comparator; + return `${operator === undefined ? "" : operator}${format(comparator)}`; } /** diff --git a/semver/is_range.ts b/semver/is_range.ts index 89d1f922da01..9452e21a855c 100644 --- a/semver/is_range.ts +++ b/semver/is_range.ts @@ -10,11 +10,11 @@ function isComparator(value: unknown): value is Comparator { typeof value !== "object" ) return false; if (value === NONE || value === ALL) return true; - const { operator, semver } = value as Comparator; + const { operator } = value as Comparator; return ( (operator === undefined || OPERATORS.includes(operator)) && - isSemVer(semver) + isSemVer(value) ); } diff --git a/semver/is_range_test.ts b/semver/is_range_test.ts index 7e35ba3e1db8..3ae3f9206a02 100644 --- a/semver/is_range_test.ts +++ b/semver/is_range_test.ts @@ -13,7 +13,6 @@ Deno.test({ ], [ [{ operator: ">=", - semver: { major: 0, minor: 0, patch: 0, prerelease: [], build: [] }, major: 0, minor: 0, patch: 0, @@ -21,7 +20,6 @@ Deno.test({ build: [], }, { operator: "<", - semver: MIN, ...MIN, }], ]]; diff --git a/semver/parse_range.ts b/semver/parse_range.ts index 97fb58a1e948..69f6f3258eaa 100644 --- a/semver/parse_range.ts +++ b/semver/parse_range.ts @@ -45,7 +45,7 @@ function parseComparator(comparator: string): Comparator { } : ANY; - return { operator: operator || undefined, ...semver, semver }; + return { operator: operator || undefined, ...semver }; } function isWildcard(id?: string): boolean { diff --git a/semver/parse_range_test.ts b/semver/parse_range_test.ts index 1da3f3cbd8d6..121167114212 100644 --- a/semver/parse_range_test.ts +++ b/semver/parse_range_test.ts @@ -360,7 +360,6 @@ Deno.test("parseRange() parse ranges of different kinds", () => { patch: 0, prerelease: [], build: [], - semver: { major: 0, minor: 0, patch: 0, prerelease: [], build: [] }, }, ], ]], @@ -479,13 +478,6 @@ Deno.test("parseRange() parses ranges with x", () => { patch: NaN, prerelease: [], build: [], - semver: { - major: NaN, - minor: NaN, - patch: NaN, - prerelease: [], - build: [], - }, }, ], ]], @@ -510,13 +502,6 @@ Deno.test("parseRange() parses ranges with x", () => { patch: NaN, prerelease: [], build: [], - semver: { - major: NaN, - minor: NaN, - patch: NaN, - prerelease: [], - build: [], - }, }, ], ]], diff --git a/semver/range_max.ts b/semver/range_max.ts index 20b82a48b025..e4b9d68a046b 100644 --- a/semver/range_max.ts +++ b/semver/range_max.ts @@ -1,12 +1,13 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { ANY, INVALID, MAX } from "./constants.ts"; +import { INVALID, MAX } from "./constants.ts"; import type { Comparator, Range, SemVer } from "./types.ts"; import { testRange } from "./test_range.ts"; import { greaterThan } from "./greater_than.ts"; +import { isWildcardComparator } from "./_shared.ts"; function comparatorMax(comparator: Comparator): SemVer { - const semver = comparator.semver ?? comparator; - if (semver === ANY) return MAX; + const semver = comparator; + if (isWildcardComparator(comparator)) return MAX; switch (comparator.operator) { case "!=": case ">": diff --git a/semver/range_min.ts b/semver/range_min.ts index 1af14dbe47b2..cca69789d3f5 100644 --- a/semver/range_min.ts +++ b/semver/range_min.ts @@ -1,14 +1,15 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { ANY, INVALID, MAX, MIN } from "./constants.ts"; +import { INVALID, MAX, MIN } from "./constants.ts"; import type { Comparator, Range, SemVer } from "./types.ts"; import { testRange } from "./test_range.ts"; import { lessThan } from "./less_than.ts"; import { greaterThan } from "./greater_than.ts"; import { increment } from "./increment.ts"; +import { isWildcardComparator } from "./_shared.ts"; function comparatorMin(comparator: Comparator): SemVer { - const semver = comparator.semver ?? comparator; - if (semver === ANY) return MIN; + const semver = comparator; + if (isWildcardComparator(semver)) return MIN; switch (comparator.operator) { case ">": return semver.prerelease && semver.prerelease.length > 0 diff --git a/semver/test_range.ts b/semver/test_range.ts index 6070e3742d8d..341cd3486ee3 100644 --- a/semver/test_range.ts +++ b/semver/test_range.ts @@ -7,7 +7,7 @@ function testComparator(version: SemVer, comparator: Comparator): boolean { if (isWildcardComparator(comparator)) { return true; } - const cmp = compare(version, comparator.semver ?? comparator); + const cmp = compare(version, comparator); switch (comparator.operator) { case "=": case undefined: { @@ -50,11 +50,8 @@ function testComparatorSet( if (isWildcardComparator(comparator)) { continue; } - const { prerelease } = comparator.semver ?? comparator; + const { major, minor, patch, prerelease } = comparator; if (prerelease && prerelease.length > 0) { - const major = comparator.semver?.major ?? comparator.major; - const minor = comparator.semver?.minor ?? comparator.minor; - const patch = comparator.semver?.patch ?? comparator.patch; if ( version.major === major && version.minor === minor && version.patch === patch diff --git a/semver/types.ts b/semver/types.ts index 94ddd037a971..e38b10e82597 100644 --- a/semver/types.ts +++ b/semver/types.ts @@ -27,10 +27,6 @@ export type Operator = typeof OPERATORS[number]; */ export interface Comparator extends SemVer { operator?: Operator; - /** - * @deprecated (will be removed in 0.219.0) {@linkcode Comparator} extends {@linkcode SemVer}. Use `major`, `minor`, `patch`, `prerelease`, and `build` properties instead. - */ - semver?: SemVer; } /**