mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
deprecation(semver): deprecate ==
, ===
, !==
, and ""
operators (#4271)
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
parent
24abc640f7
commit
dd89077f99
@ -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)
|
||||
}`;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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 "==":
|
||||
|
@ -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 = [
|
||||
"",
|
||||
"=",
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
@ -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 };
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user