deprecation(semver): deprecate ==, ===, !==, and "" operators (#4271)

Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
Tim Reichen 2024-02-18 07:43:09 +01:00 committed by GitHub
parent 24abc640f7
commit dd89077f99
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 16 additions and 12 deletions

View File

@ -10,5 +10,7 @@ import { format } from "./format.ts";
*/
export function comparatorFormat(comparator: Comparator): string {
const { semver, operator } = comparator;
return `${operator}${format(semver ?? comparator)}`;
return `${operator === undefined ? "" : operator}${
format(semver ?? comparator)
}`;
}

View File

@ -19,9 +19,10 @@ export function comparatorMax(comparator: Comparator): SemVer {
case ">=":
return MAX;
case "":
case "=":
case "==":
case "===":
case undefined:
case "=":
case "<=":
return {
major: semver.major,

View File

@ -25,6 +25,7 @@ export function comparatorMin(comparator: Comparator): SemVer {
// The min(<0.0.0) is MAX
return greaterThan(semver, MIN) ? MIN : MAX;
case ">=":
case undefined:
case "":
case "=":
case "==":

View File

@ -1,5 +1,8 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
/**
* @deprecated (will be removed in 0.219.0) `"=="`, `"==="`, `"!=="` and `""` operators are deprecated. Use `"="`, `"!="` or `undefined` instead.
*/
export const OPERATORS = [
"",
"=",

View File

@ -22,7 +22,8 @@ export function isComparator(value: unknown): value is Comparator {
if (value === NONE || value === ALL) return true;
const { operator, semver } = value as Comparator;
return (
OPERATORS.includes(operator) &&
(operator === undefined ||
OPERATORS.includes(operator)) &&
isSemVer(semver)
);
}

View File

@ -28,12 +28,7 @@ export function parseComparator(comparator: string): Comparator {
if (!groups) return NONE;
const {
operator = "",
prerelease,
buildmetadata,
} = groups as REGEXP_GROUPS;
const { operator, prerelease, buildmetadata } = groups as REGEXP_GROUPS;
const semver = groups.major
? {
@ -45,5 +40,5 @@ export function parseComparator(comparator: string): Comparator {
}
: ANY;
return { operator, ...semver, semver };
return { operator: operator || undefined, ...semver, semver };
}

View File

@ -241,7 +241,7 @@ function handleEqualOperator(groups: RegExpGroups): Comparator[] {
}
const prerelease = parsePrerelease(groups.prerelease ?? "");
const build = parseBuild(groups.build ?? "");
return [{ operator: "", major, minor, patch, prerelease, build }];
return [{ operator: undefined, major, minor, patch, prerelease, build }];
}
function parseRangeString(string: string) {

View File

@ -18,6 +18,7 @@ export type ReleaseType =
/**
* SemVer comparison operators.
* @deprecated (will be removed in 0.219.0) `"=="`, `"==="`, `"!=="` and `""` operators are deprecated. Use `"="`, `"!="` or `undefined` instead.
*/
export type Operator = typeof OPERATORS[number];
@ -26,7 +27,7 @@ export type Operator = typeof OPERATORS[number];
* @example >=0.0.0
*/
export interface Comparator extends SemVer {
operator: Operator;
operator?: Operator;
/**
* @deprecated (will be removed after 0.217.0) {@linkcode Comparator} extends {@linkcode SemVer}. Use `major`, `minor`, `patch`, `prerelease`, and `build` properties instead.
*/