Skip to content

Commit

Permalink
[unstable] BREAKING(semver): remove comparator.semver field (#4533)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Mar 28, 2024
1 parent bcfc7e0 commit b8c110d
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 43 deletions.
2 changes: 0 additions & 2 deletions semver/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export const ANY: SemVer = {
export const ALL: Comparator = {
operator: undefined,
...ANY,
semver: ANY,
};

/**
Expand All @@ -77,5 +76,4 @@ export const ALL: Comparator = {
export const NONE: Comparator = {
operator: "<",
...MIN,
semver: MIN,
};
4 changes: 2 additions & 2 deletions semver/format.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 { ANY } from "./constants.ts";
import type { SemVer } from "./types.ts";
import { isWildcardComparator } from "./_shared.ts";

function formatNumber(value: number) {
if (value === Number.POSITIVE_INFINITY) {
Expand All @@ -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 "*";
}

Expand Down
6 changes: 2 additions & 4 deletions semver/format_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions semver/is_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
2 changes: 0 additions & 2 deletions semver/is_range_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ Deno.test({
], [
[{
operator: ">=",
semver: { major: 0, minor: 0, patch: 0, prerelease: [], build: [] },
major: 0,
minor: 0,
patch: 0,
prerelease: [],
build: [],
}, {
operator: "<",
semver: MIN,
...MIN,
}],
]];
Expand Down
2 changes: 1 addition & 1 deletion semver/parse_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 0 additions & 15 deletions semver/parse_range_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] },
},
],
]],
Expand Down Expand Up @@ -479,13 +478,6 @@ Deno.test("parseRange() parses ranges with x", () => {
patch: NaN,
prerelease: [],
build: [],
semver: {
major: NaN,
minor: NaN,
patch: NaN,
prerelease: [],
build: [],
},
},
],
]],
Expand All @@ -510,13 +502,6 @@ Deno.test("parseRange() parses ranges with x", () => {
patch: NaN,
prerelease: [],
build: [],
semver: {
major: NaN,
minor: NaN,
patch: NaN,
prerelease: [],
build: [],
},
},
],
]],
Expand Down
7 changes: 4 additions & 3 deletions semver/range_max.ts
Original file line number Diff line number Diff line change
@@ -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 ">":
Expand Down
7 changes: 4 additions & 3 deletions semver/range_min.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 2 additions & 5 deletions semver/test_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions semver/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit b8c110d

Please sign in to comment.