Skip to content

Commit

Permalink
BREAKING(semver): make invalid SemVer constants private (#5168)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jun 27, 2024
1 parent 410053b commit 04b7229
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 90 deletions.
65 changes: 65 additions & 0 deletions semver/_constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import type { Comparator, SemVer } from "./types.ts";

/**
* MAX is a sentinel value used by some range calculations.
* It is equivalent to `∞.∞.∞`.
*/
export const MAX: SemVer = {
major: Number.POSITIVE_INFINITY,
minor: Number.POSITIVE_INFINITY,
patch: Number.POSITIVE_INFINITY,
prerelease: [],
build: [],
};

/**
* The minimum valid SemVer object. Equivalent to `0.0.0`.
*/
export const MIN: SemVer = {
major: 0,
minor: 0,
patch: 0,
prerelease: [],
build: [],
};

/**
* A sentinel value used to denote an invalid SemVer object
* which may be the result of impossible ranges or comparator operations.
*/
export const INVALID: SemVer = {
major: Number.NEGATIVE_INFINITY,
minor: Number.POSITIVE_INFINITY,
patch: Number.POSITIVE_INFINITY,
prerelease: [],
build: [],
};

/**
* ANY is a sentinel value used by some range calculations. It is not a valid
* SemVer object and should not be used directly.
*/
export const ANY: SemVer = {
major: Number.NaN,
minor: Number.NaN,
patch: Number.NaN,
prerelease: [],
build: [],
};

/**
* A comparator which will span all valid semantic versions
*/
export const ALL: Comparator = {
operator: undefined,
...ANY,
};

/**
* A comparator which will not span any semantic versions
*/
export const NONE: Comparator = {
operator: "<",
...MIN,
};

export const OPERATORS = [
undefined,
"=",
Expand Down
80 changes: 0 additions & 80 deletions semver/constants.ts

This file was deleted.

1 change: 0 additions & 1 deletion semver/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
".": "./mod.ts",
"./can-parse": "./can_parse.ts",
"./compare": "./compare.ts",
"./constants": "./constants.ts",
"./difference": "./difference.ts",
"./equals": "./equals.ts",
"./format": "./format.ts",
Expand Down
2 changes: 1 addition & 1 deletion semver/format_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { assertEquals } from "@std/assert";
import { format } from "./format.ts";
import { parse } from "./parse.ts";
import { INVALID, MAX, MIN } from "./constants.ts";
import { INVALID, MAX, MIN } from "./_constants.ts";
import type { SemVer } from "./types.ts";

Deno.test("format()", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion semver/is_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This module is browser compatible.
import type { Comparator, Range } from "./types.ts";
import { OPERATORS } from "./_constants.ts";
import { ALL, NONE } from "./constants.ts";
import { ALL, NONE } from "./_constants.ts";
import { isSemVer } from "./is_semver.ts";

function isComparator(value: unknown): value is Comparator {
Expand Down
2 changes: 1 addition & 1 deletion semver/is_range_test.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 { assert } from "@std/assert";
import { ALL, MIN } from "./constants.ts";
import { ALL, MIN } from "./_constants.ts";
import { formatRange } from "./format_range.ts";
import { isRange } from "./is_range.ts";
import type { Range } from "./types.ts";
Expand Down
2 changes: 1 addition & 1 deletion semver/is_semver.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.
// This module is browser compatible.
import { ANY, INVALID } from "./constants.ts";
import { ANY, INVALID } from "./_constants.ts";
import type { SemVer } from "./types.ts";
import { isValidNumber, isValidString } from "./_shared.ts";

Expand Down
2 changes: 1 addition & 1 deletion semver/is_semver_test.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 { assert } from "@std/assert";
import { MAX, MIN } from "./constants.ts";
import { MAX, MIN } from "./_constants.ts";
import { isSemVer } from "./is_semver.ts";

Deno.test({
Expand Down
2 changes: 1 addition & 1 deletion semver/max_satisfying_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assertEquals } from "@std/assert";
import { parse } from "./parse.ts";
import { parseRange } from "./parse_range.ts";
import { maxSatisfying } from "./max_satisfying.ts";
import { MAX, MIN } from "./constants.ts";
import { MAX, MIN } from "./_constants.ts";

Deno.test({
name: "maxSatisfying()",
Expand Down
2 changes: 1 addition & 1 deletion semver/min_satisfying_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { assertEquals } from "@std/assert";
import { parse } from "./parse.ts";
import { parseRange } from "./parse_range.ts";
import { minSatisfying } from "./min_satisfying.ts";
import { MAX, MIN } from "./constants.ts";
import { MAX, MIN } from "./_constants.ts";

Deno.test("minSatisfying()", async (t) => {
const versions: [string[], string, string][] = [
Expand Down
1 change: 0 additions & 1 deletion semver/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@
* @module
*/
export * from "./compare.ts";
export * from "./constants.ts";
export * from "./difference.ts";
export * from "./format.ts";
export * from "./satisfies.ts";
Expand Down
2 changes: 1 addition & 1 deletion semver/parse_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
parsePrerelease,
XRANGE,
} from "./_shared.ts";
import { ALL, ANY, NONE } from "./constants.ts";
import { ALL, ANY, NONE } from "./_constants.ts";
import type { Comparator, Operator, Range } from "./types.ts";

type ComparatorRegExpGroup = {
Expand Down

0 comments on commit 04b7229

Please sign in to comment.