Skip to content

Commit

Permalink
BREAKING(semver): remove SemVerComparator (#4109)
Browse files Browse the repository at this point in the history
  • Loading branch information
iuioiua authored Jan 5, 2024
1 parent 98766d1 commit 5351ef3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 49 deletions.
4 changes: 2 additions & 2 deletions semver/comparator_format.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 { SemVerComparator } from "./types.ts";
import type { Comparator } from "./types.ts";
import { format } from "./format.ts";

/**
Expand All @@ -8,7 +8,7 @@ import { format } from "./format.ts";
* @param comparator
* @returns A string representation of the comparator
*/
export function comparatorFormat(comparator: SemVerComparator): string {
export function comparatorFormat(comparator: Comparator): string {
const { semver, operator } = comparator;
return `${operator}${format(semver)}`;
}
6 changes: 3 additions & 3 deletions semver/comparator_intersects.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 { SemVerComparator } from "./types.ts";
import type { Comparator } from "./types.ts";
import { gte } from "./gte.ts";
import { lte } from "./lte.ts";
import { comparatorMin } from "./comparator_min.ts";
Expand All @@ -11,8 +11,8 @@ import { comparatorMax } from "./comparator_max.ts";
* @returns True if any part of the comparators intersect
*/
export function comparatorIntersects(
c0: SemVerComparator,
c1: SemVerComparator,
c0: Comparator,
c1: Comparator,
): boolean {
const l0 = comparatorMin(c0.semver, c0.operator);
const l1 = comparatorMax(c0.semver, c0.operator);
Expand Down
10 changes: 3 additions & 7 deletions semver/constants.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 { SemVer, SemVerComparator } from "./types.ts";
import type { Comparator, SemVer } from "./types.ts";

/**
* MAX is a sentinel value used by some range calculations.
Expand Down Expand Up @@ -65,19 +65,15 @@ export const ANY: SemVer = {
/**
* A comparator which will span all valid semantic versions
*/
export const ALL: SemVerComparator = {
export const ALL: Comparator = {
operator: "",
semver: ANY,
min: MIN,
max: MAX,
};

/**
* A comparator which will not span any semantic versions
*/
export const NONE: SemVerComparator = {
export const NONE: Comparator = {
operator: "<",
semver: MIN,
min: MAX,
max: MIN,
};
6 changes: 3 additions & 3 deletions semver/outside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { gte } from "./gte.ts";
import { lte } from "./lte.ts";
import { lt } from "./lt.ts";
import { ALL, ANY } from "./constants.ts";
import type { SemVer, SemVerComparator, SemVerRange } from "./types.ts";
import type { Comparator, SemVer, SemVerRange } from "./types.ts";
import { testRange } from "./test_range.ts";

/**
Expand Down Expand Up @@ -40,8 +40,8 @@ export function outside(
}

for (const comparators of range.ranges) {
let high: SemVerComparator | undefined = undefined;
let low: SemVerComparator | undefined = undefined;
let high: Comparator | undefined = undefined;
let low: Comparator | undefined = undefined;
for (let comparator of comparators) {
if (comparator.semver === ANY) {
comparator = ALL;
Expand Down
15 changes: 5 additions & 10 deletions semver/parse_comparator.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 type { Operator, SemVerComparator } from "./types.ts";
import type { Comparator, Operator } from "./types.ts";
import {
COMPARATOR_REGEXP,
parseBuild,
parseNumber,
parsePrerelease,
} from "./_shared.ts";
import { comparatorMin } from "./comparator_min.ts";
import { comparatorMax } from "./comparator_max.ts";
import { ANY, NONE } from "./constants.ts";

type REGEXP_GROUPS = {
Expand All @@ -20,11 +18,11 @@ type REGEXP_GROUPS = {
};

/**
* Parses a comparator string into a valid SemVerComparator.
* Parses a comparator string into a valid Comparator.
* @param comparator
* @returns A valid SemVerComparator
* @returns A valid Comparator
*/
export function parseComparator(comparator: string): SemVerComparator {
export function parseComparator(comparator: string): Comparator {
const match = comparator.match(COMPARATOR_REGEXP);
const groups = match?.groups;

Expand All @@ -47,8 +45,5 @@ export function parseComparator(comparator: string): SemVerComparator {
}
: ANY;

const min = comparatorMin(semver, operator);
const max = comparatorMax(semver, operator);

return { operator, semver, min, max };
return { operator, semver };
}
4 changes: 2 additions & 2 deletions semver/range_intersects.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 { comparatorIntersects } from "./comparator_intersects.ts";
import type { SemVerComparator, SemVerRange } from "./types.ts";
import type { Comparator, SemVerRange } from "./types.ts";

function rangesSatisfiable(ranges: SemVerRange[]): boolean {
return ranges.every((r) => {
Expand All @@ -9,7 +9,7 @@ function rangesSatisfiable(ranges: SemVerRange[]): boolean {
});
}

function comparatorsSatisfiable(comparators: SemVerComparator[]): boolean {
function comparatorsSatisfiable(comparators: Comparator[]): boolean {
// Comparators are satisfiable if they all intersect with each other
for (let i = 0; i < comparators.length - 1; i++) {
const c0 = comparators[i];
Expand Down
4 changes: 2 additions & 2 deletions semver/test_comparator.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 { SemVer, SemVerComparator } from "./types.ts";
import type { Comparator, SemVer } from "./types.ts";
import { cmp } from "./cmp.ts";

/**
Expand All @@ -11,7 +11,7 @@ import { cmp } from "./cmp.ts";
*/
export function testComparator(
version: SemVer,
comparator: SemVerComparator,
comparator: Comparator,
): boolean {
return cmp(version, comparator.operator, comparator.semver);
}
8 changes: 4 additions & 4 deletions semver/try_parse_comparator.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { SemVerComparator } from "./types.ts";
import { Comparator } from "./types.ts";
import { parseComparator } from "./parse_comparator.ts";
/**
* Parses a comparator string into a valid SemVerComparator or returns undefined if not valid.
* Parses a comparator string into a valid Comparator or returns undefined if not valid.
* @param comparator
* @returns A valid SemVerComparator or undefined
* @returns A valid Comparator or undefined
*/
export function tryParseComparator(
comparator: string,
): SemVerComparator | undefined {
): Comparator | undefined {
try {
return parseComparator(comparator);
} catch {
Expand Down
17 changes: 1 addition & 16 deletions semver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,6 @@ export interface Comparator {
operator: Operator;
semver: SemVer;
}
/**
* @deprecated (will be removed in 0.212.0) Use {@linkcode Comparator} instead.
*/
export interface SemVerComparator {
operator: Operator;
semver: SemVer;
/**
* @deprecated (will be removed in 0.212.0) use {@linkcode comparatorMin} instead.
*/
min: SemVer;
/**
* @deprecated (will be removed in 0.212.0) use {@linkcode comparatorMin} instead.
*/
max: SemVer;
}

/**
* A SemVer object parsed into its constituent parts.
Expand All @@ -70,7 +55,7 @@ export interface SemVer {
build?: string[];
}

type SemVerRangeAnd = SemVerComparator[];
type SemVerRangeAnd = Comparator[];
type SemVerRangeOr = SemVerRangeAnd[];

/**
Expand Down

0 comments on commit 5351ef3

Please sign in to comment.