keep-a-changelog 2.0.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -2
- package/README.md +21 -6
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/bin.js +9 -4
- package/esm/deps/deno.land/std@0.173.0/_util/asserts.js +21 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/_util/os.js +4 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/flags/mod.js +145 -36
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.js +1 -0
- package/esm/deps/deno.land/std@0.173.0/path/_interface.js +3 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.js +1 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.js +1 -1
- package/esm/deps/deno.land/std@0.173.0/path/mod.js +32 -0
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.js +23 -16
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.js +1 -1
- package/esm/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.js +20 -15
- package/esm/deps/{deno_land/x/semver_v1.4.0 → deno.land/std@0.173.0/semver}/mod.js +227 -334
- package/esm/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.js +0 -0
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.js +1 -1
- package/esm/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.js +0 -0
- package/esm/mod.js +1 -0
- package/esm/src/Change.js +15 -15
- package/esm/src/Changelog.js +9 -1
- package/esm/src/Release.js +21 -4
- package/esm/src/deps.js +1 -1
- package/esm/src/parser.js +24 -5
- package/esm/test/changelog.custom.type.md +0 -1
- package/esm/test/changelog.expected.linted.md +208 -0
- package/esm/test/changelog.expected.md +6 -4
- package/esm/test/changelog.md +7 -3
- package/esm/test/empty.expected.md +0 -1
- package/package.json +13 -8
- package/script/_dnt.polyfills.js +16 -0
- package/script/_dnt.shims.js +66 -0
- package/script/bin.js +144 -0
- package/script/deps/deno.land/std@0.173.0/_util/asserts.js +27 -0
- package/script/deps/deno.land/std@0.173.0/_util/os.js +44 -0
- package/script/deps/deno.land/std@0.173.0/flags/mod.js +368 -0
- package/script/deps/deno.land/std@0.173.0/path/_constants.js +49 -0
- package/script/deps/deno.land/std@0.173.0/path/_interface.js +4 -0
- package/script/deps/deno.land/std@0.173.0/path/_util.js +125 -0
- package/script/deps/deno.land/std@0.173.0/path/common.js +40 -0
- package/script/deps/deno.land/std@0.173.0/path/glob.js +391 -0
- package/script/deps/deno.land/std@0.173.0/path/mod.js +63 -0
- package/script/deps/deno.land/std@0.173.0/path/posix.js +539 -0
- package/script/deps/deno.land/std@0.173.0/path/separator.js +8 -0
- package/script/deps/deno.land/std@0.173.0/path/win32.js +1007 -0
- package/script/deps/deno.land/std@0.173.0/semver/mod.js +1458 -0
- package/script/deps/deno.land/std@0.51.0/fs/eol.js +34 -0
- package/script/deps/deno.land/x/ini@v2.1.0/ini.js +256 -0
- package/script/deps/deno.land/x/ini@v2.1.0/mod.js +17 -0
- package/script/mod.js +15 -0
- package/{umd → script}/package.json +0 -0
- package/script/src/Change.js +51 -0
- package/script/src/Changelog.js +148 -0
- package/script/src/Release.js +227 -0
- package/script/src/deps.js +9 -0
- package/script/src/parser.js +184 -0
- package/{umd → script}/test/changelog.custom.type.md +0 -1
- package/script/test/changelog.expected.linted.md +208 -0
- package/{umd → script}/test/changelog.expected.md +6 -4
- package/{umd → script}/test/changelog.md +7 -3
- package/{umd → script}/test/empty.expected.md +0 -1
- package/types/_dnt.polyfills.d.ts +11 -0
- package/types/_dnt.shims.d.ts +0 -4
- package/types/bin.d.ts +1 -1
- package/types/deps/deno.land/std@0.173.0/_util/asserts.d.ts +10 -0
- package/types/deps/deno.land/std@0.173.0/_util/os.d.ts +4 -0
- package/types/deps/deno.land/std@0.173.0/flags/mod.d.ts +166 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_constants.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_interface.d.ts +1 -1
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/_util.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/common.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/glob.d.ts +10 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/mod.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/posix.d.ts +9 -5
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/separator.d.ts +0 -0
- package/types/deps/{deno_land/std_0.120.0 → deno.land/std@0.173.0}/path/win32.d.ts +7 -5
- package/types/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
- package/types/deps/{deno_land/std_0.51.0 → deno.land/std@0.51.0}/fs/eol.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/ini.d.ts +0 -0
- package/types/deps/{deno_land/x/ini_v2.1.0 → deno.land/x/ini@v2.1.0}/mod.d.ts +0 -0
- package/types/mod.d.ts +1 -0
- package/types/src/Changelog.d.ts +1 -0
- package/types/src/Release.d.ts +2 -0
- package/types/src/deps.d.ts +1 -1
- package/esm/deps/deno_land/std_0.120.0/_util/assert.js +0 -13
- package/esm/deps/deno_land/std_0.120.0/path/_interface.js +0 -3
- package/esm/deps/deno_land/std_0.120.0/path/mod.js +0 -14
- package/types/deps/deno_land/std_0.120.0/_util/assert.d.ts +0 -5
- package/types/deps/deno_land/std_0.120.0/_util/os.d.ts +0 -3
- package/types/deps/deno_land/std_0.120.0/flags/mod.d.ts +0 -50
- package/types/deps/deno_land/x/semver_v1.4.0/mod.d.ts +0 -116
- package/umd/_dnt.shims.js +0 -76
- package/umd/bin.js +0 -145
- package/umd/deps/deno_land/std_0.120.0/_util/assert.js +0 -28
- package/umd/deps/deno_land/std_0.120.0/_util/os.js +0 -47
- package/umd/deps/deno_land/std_0.120.0/flags/mod.js +0 -269
- package/umd/deps/deno_land/std_0.120.0/path/_constants.js +0 -58
- package/umd/deps/deno_land/std_0.120.0/path/_interface.js +0 -14
- package/umd/deps/deno_land/std_0.120.0/path/_util.js +0 -134
- package/umd/deps/deno_land/std_0.120.0/path/common.js +0 -50
- package/umd/deps/deno_land/std_0.120.0/path/glob.js +0 -397
- package/umd/deps/deno_land/std_0.120.0/path/mod.js +0 -51
- package/umd/deps/deno_land/std_0.120.0/path/posix.js +0 -538
- package/umd/deps/deno_land/std_0.120.0/path/separator.js +0 -18
- package/umd/deps/deno_land/std_0.120.0/path/win32.js +0 -1008
- package/umd/deps/deno_land/std_0.51.0/fs/eol.js +0 -44
- package/umd/deps/deno_land/x/ini_v2.1.0/ini.js +0 -262
- package/umd/deps/deno_land/x/ini_v2.1.0/mod.js +0 -23
- package/umd/deps/deno_land/x/semver_v1.4.0/mod.js +0 -1578
- package/umd/mod.js +0 -24
- package/umd/src/Change.js +0 -61
- package/umd/src/Changelog.js +0 -150
- package/umd/src/Release.js +0 -220
- package/umd/src/deps.js +0 -19
- package/umd/src/parser.js +0 -175
|
@@ -0,0 +1,1458 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.
|
|
3
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.intersects = exports.prerelease = exports.outside = exports.gtr = exports.ltr = exports.validRange = exports.minVersion = exports.minSatisfying = exports.maxSatisfying = exports.satisfies = exports.toComparators = exports.Range = exports.Comparator = exports.cmp = exports.lte = exports.gte = exports.neq = exports.eq = exports.lt = exports.gt = exports.rsort = exports.sort = exports.rcompare = exports.compareBuild = exports.compare = exports.patch = exports.minor = exports.major = exports.rcompareIdentifiers = exports.compareIdentifiers = exports.difference = exports.increment = exports.SemVer = exports.valid = exports.parse = exports.SEMVER_SPEC_VERSION = void 0;
|
|
6
|
+
// Note: this is the semver.org version of the spec that it implements
|
|
7
|
+
// Not necessarily the package version of this code.
|
|
8
|
+
exports.SEMVER_SPEC_VERSION = "2.0.0";
|
|
9
|
+
const MAX_LENGTH = 256;
|
|
10
|
+
// The actual regexps
|
|
11
|
+
const re = [];
|
|
12
|
+
const src = [];
|
|
13
|
+
let R = 0;
|
|
14
|
+
// The following Regular Expressions can be used for tokenizing,
|
|
15
|
+
// validating, and parsing SemVer version strings.
|
|
16
|
+
// ## Numeric Identifier
|
|
17
|
+
// A single `0`, or a non-zero digit followed by zero or more digits.
|
|
18
|
+
const NUMERICIDENTIFIER = R++;
|
|
19
|
+
src[NUMERICIDENTIFIER] = "0|[1-9]\\d*";
|
|
20
|
+
// ## Non-numeric Identifier
|
|
21
|
+
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
|
22
|
+
// more letters, digits, or hyphens.
|
|
23
|
+
const NONNUMERICIDENTIFIER = R++;
|
|
24
|
+
src[NONNUMERICIDENTIFIER] = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
|
|
25
|
+
// ## Main Version
|
|
26
|
+
// Three dot-separated numeric identifiers.
|
|
27
|
+
const MAINVERSION = R++;
|
|
28
|
+
const nid = src[NUMERICIDENTIFIER];
|
|
29
|
+
src[MAINVERSION] = `(${nid})\\.(${nid})\\.(${nid})`;
|
|
30
|
+
// ## Pre-release Version Identifier
|
|
31
|
+
// A numeric identifier, or a non-numeric identifier.
|
|
32
|
+
const PRERELEASEIDENTIFIER = R++;
|
|
33
|
+
src[PRERELEASEIDENTIFIER] = "(?:" + src[NUMERICIDENTIFIER] + "|" +
|
|
34
|
+
src[NONNUMERICIDENTIFIER] + ")";
|
|
35
|
+
// ## Pre-release Version
|
|
36
|
+
// Hyphen, followed by one or more dot-separated pre-release version
|
|
37
|
+
// identifiers.
|
|
38
|
+
const PRERELEASE = R++;
|
|
39
|
+
src[PRERELEASE] = "(?:-(" +
|
|
40
|
+
src[PRERELEASEIDENTIFIER] +
|
|
41
|
+
"(?:\\." +
|
|
42
|
+
src[PRERELEASEIDENTIFIER] +
|
|
43
|
+
")*))";
|
|
44
|
+
// ## Build Metadata Identifier
|
|
45
|
+
// Any combination of digits, letters, or hyphens.
|
|
46
|
+
const BUILDIDENTIFIER = R++;
|
|
47
|
+
src[BUILDIDENTIFIER] = "[0-9A-Za-z-]+";
|
|
48
|
+
// ## Build Metadata
|
|
49
|
+
// Plus sign, followed by one or more period-separated build metadata
|
|
50
|
+
// identifiers.
|
|
51
|
+
const BUILD = R++;
|
|
52
|
+
src[BUILD] = "(?:\\+(" + src[BUILDIDENTIFIER] + "(?:\\." +
|
|
53
|
+
src[BUILDIDENTIFIER] + ")*))";
|
|
54
|
+
// ## Full Version String
|
|
55
|
+
// A main version, followed optionally by a pre-release version and
|
|
56
|
+
// build metadata.
|
|
57
|
+
// Note that the only major, minor, patch, and pre-release sections of
|
|
58
|
+
// the version string are capturing groups. The build metadata is not a
|
|
59
|
+
// capturing group, because it should not ever be used in version
|
|
60
|
+
// comparison.
|
|
61
|
+
const FULL = R++;
|
|
62
|
+
const FULLPLAIN = "v?" + src[MAINVERSION] + src[PRERELEASE] + "?" + src[BUILD] +
|
|
63
|
+
"?";
|
|
64
|
+
src[FULL] = "^" + FULLPLAIN + "$";
|
|
65
|
+
const GTLT = R++;
|
|
66
|
+
src[GTLT] = "((?:<|>)?=?)";
|
|
67
|
+
// Something like "2.*" or "1.2.x".
|
|
68
|
+
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
|
69
|
+
// Only the first item is strictly required.
|
|
70
|
+
const XRANGEIDENTIFIER = R++;
|
|
71
|
+
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + "|x|X|\\*";
|
|
72
|
+
const XRANGEPLAIN = R++;
|
|
73
|
+
src[XRANGEPLAIN] = "[v=\\s]*(" +
|
|
74
|
+
src[XRANGEIDENTIFIER] +
|
|
75
|
+
")" +
|
|
76
|
+
"(?:\\.(" +
|
|
77
|
+
src[XRANGEIDENTIFIER] +
|
|
78
|
+
")" +
|
|
79
|
+
"(?:\\.(" +
|
|
80
|
+
src[XRANGEIDENTIFIER] +
|
|
81
|
+
")" +
|
|
82
|
+
"(?:" +
|
|
83
|
+
src[PRERELEASE] +
|
|
84
|
+
")?" +
|
|
85
|
+
src[BUILD] +
|
|
86
|
+
"?" +
|
|
87
|
+
")?)?";
|
|
88
|
+
const XRANGE = R++;
|
|
89
|
+
src[XRANGE] = "^" + src[GTLT] + "\\s*" + src[XRANGEPLAIN] + "$";
|
|
90
|
+
// Tilde ranges.
|
|
91
|
+
// Meaning is "reasonably at or greater than"
|
|
92
|
+
const LONETILDE = R++;
|
|
93
|
+
src[LONETILDE] = "(?:~>?)";
|
|
94
|
+
const TILDE = R++;
|
|
95
|
+
src[TILDE] = "^" + src[LONETILDE] + src[XRANGEPLAIN] + "$";
|
|
96
|
+
// Caret ranges.
|
|
97
|
+
// Meaning is "at least and backwards compatible with"
|
|
98
|
+
const LONECARET = R++;
|
|
99
|
+
src[LONECARET] = "(?:\\^)";
|
|
100
|
+
const CARET = R++;
|
|
101
|
+
src[CARET] = "^" + src[LONECARET] + src[XRANGEPLAIN] + "$";
|
|
102
|
+
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
|
103
|
+
const COMPARATOR = R++;
|
|
104
|
+
src[COMPARATOR] = "^" + src[GTLT] + "\\s*(" + FULLPLAIN + ")$|^$";
|
|
105
|
+
// Something like `1.2.3 - 1.2.4`
|
|
106
|
+
const HYPHENRANGE = R++;
|
|
107
|
+
src[HYPHENRANGE] = "^\\s*(" +
|
|
108
|
+
src[XRANGEPLAIN] +
|
|
109
|
+
")" +
|
|
110
|
+
"\\s+-\\s+" +
|
|
111
|
+
"(" +
|
|
112
|
+
src[XRANGEPLAIN] +
|
|
113
|
+
")" +
|
|
114
|
+
"\\s*$";
|
|
115
|
+
// Star ranges basically just allow anything at all.
|
|
116
|
+
const STAR = R++;
|
|
117
|
+
src[STAR] = "(<|>)?=?\\s*\\*";
|
|
118
|
+
// Compile to actual regexp objects.
|
|
119
|
+
// All are flag-free, unless they were created above with a flag.
|
|
120
|
+
for (let i = 0; i < R; i++) {
|
|
121
|
+
if (!re[i]) {
|
|
122
|
+
re[i] = new RegExp(src[i]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Attempt to parse a string as a semantic version, returning either a `SemVer`
|
|
127
|
+
* object or `null`.
|
|
128
|
+
*/
|
|
129
|
+
function parse(version, options) {
|
|
130
|
+
if (typeof options !== "object") {
|
|
131
|
+
options = {
|
|
132
|
+
includePrerelease: false,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (version instanceof SemVer) {
|
|
136
|
+
return version;
|
|
137
|
+
}
|
|
138
|
+
if (typeof version !== "string") {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (version.length > MAX_LENGTH) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const r = re[FULL];
|
|
145
|
+
if (!r.test(version)) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
return new SemVer(version, options);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.parse = parse;
|
|
156
|
+
/** Returns the parsed version, or null if it's not valid. */
|
|
157
|
+
function valid(version, options) {
|
|
158
|
+
if (version === null)
|
|
159
|
+
return null;
|
|
160
|
+
const v = parse(version, options);
|
|
161
|
+
return v ? v.version : null;
|
|
162
|
+
}
|
|
163
|
+
exports.valid = valid;
|
|
164
|
+
class SemVer {
|
|
165
|
+
constructor(version, options) {
|
|
166
|
+
Object.defineProperty(this, "raw", {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
configurable: true,
|
|
169
|
+
writable: true,
|
|
170
|
+
value: void 0
|
|
171
|
+
});
|
|
172
|
+
Object.defineProperty(this, "options", {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
configurable: true,
|
|
175
|
+
writable: true,
|
|
176
|
+
value: void 0
|
|
177
|
+
});
|
|
178
|
+
Object.defineProperty(this, "major", {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: true,
|
|
182
|
+
value: void 0
|
|
183
|
+
});
|
|
184
|
+
Object.defineProperty(this, "minor", {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
configurable: true,
|
|
187
|
+
writable: true,
|
|
188
|
+
value: void 0
|
|
189
|
+
});
|
|
190
|
+
Object.defineProperty(this, "patch", {
|
|
191
|
+
enumerable: true,
|
|
192
|
+
configurable: true,
|
|
193
|
+
writable: true,
|
|
194
|
+
value: void 0
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(this, "version", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
configurable: true,
|
|
199
|
+
writable: true,
|
|
200
|
+
value: void 0
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(this, "build", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
configurable: true,
|
|
205
|
+
writable: true,
|
|
206
|
+
value: void 0
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(this, "prerelease", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
configurable: true,
|
|
211
|
+
writable: true,
|
|
212
|
+
value: void 0
|
|
213
|
+
});
|
|
214
|
+
if (typeof options !== "object") {
|
|
215
|
+
options = {
|
|
216
|
+
includePrerelease: false,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (version instanceof SemVer) {
|
|
220
|
+
version = version.version;
|
|
221
|
+
}
|
|
222
|
+
else if (typeof version !== "string") {
|
|
223
|
+
throw new TypeError("Invalid Version: " + version);
|
|
224
|
+
}
|
|
225
|
+
if (version.length > MAX_LENGTH) {
|
|
226
|
+
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
|
|
227
|
+
}
|
|
228
|
+
if (!(this instanceof SemVer)) {
|
|
229
|
+
return new SemVer(version, options);
|
|
230
|
+
}
|
|
231
|
+
this.options = options;
|
|
232
|
+
const m = version.trim().match(re[FULL]);
|
|
233
|
+
if (!m) {
|
|
234
|
+
throw new TypeError("Invalid Version: " + version);
|
|
235
|
+
}
|
|
236
|
+
this.raw = version;
|
|
237
|
+
// these are actually numbers
|
|
238
|
+
this.major = +m[1];
|
|
239
|
+
this.minor = +m[2];
|
|
240
|
+
this.patch = +m[3];
|
|
241
|
+
if (this.major > Number.MAX_SAFE_INTEGER || this.major < 0) {
|
|
242
|
+
throw new TypeError("Invalid major version");
|
|
243
|
+
}
|
|
244
|
+
if (this.minor > Number.MAX_SAFE_INTEGER || this.minor < 0) {
|
|
245
|
+
throw new TypeError("Invalid minor version");
|
|
246
|
+
}
|
|
247
|
+
if (this.patch > Number.MAX_SAFE_INTEGER || this.patch < 0) {
|
|
248
|
+
throw new TypeError("Invalid patch version");
|
|
249
|
+
}
|
|
250
|
+
// numberify any prerelease numeric ids
|
|
251
|
+
if (!m[4]) {
|
|
252
|
+
this.prerelease = [];
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
this.prerelease = m[4].split(".").map((id) => {
|
|
256
|
+
if (/^[0-9]+$/.test(id)) {
|
|
257
|
+
const num = +id;
|
|
258
|
+
if (num >= 0 && num < Number.MAX_SAFE_INTEGER) {
|
|
259
|
+
return num;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return id;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
this.build = m[5] ? m[5].split(".") : [];
|
|
266
|
+
this.format();
|
|
267
|
+
}
|
|
268
|
+
format() {
|
|
269
|
+
this.version = this.major + "." + this.minor + "." + this.patch;
|
|
270
|
+
if (this.prerelease.length) {
|
|
271
|
+
this.version += "-" + this.prerelease.join(".");
|
|
272
|
+
}
|
|
273
|
+
return this.version;
|
|
274
|
+
}
|
|
275
|
+
compare(other) {
|
|
276
|
+
if (!(other instanceof SemVer)) {
|
|
277
|
+
other = new SemVer(other, this.options);
|
|
278
|
+
}
|
|
279
|
+
return this.compareMain(other) || this.comparePre(other);
|
|
280
|
+
}
|
|
281
|
+
compareMain(other) {
|
|
282
|
+
if (!(other instanceof SemVer)) {
|
|
283
|
+
other = new SemVer(other, this.options);
|
|
284
|
+
}
|
|
285
|
+
return (compareIdentifiers(this.major, other.major) ||
|
|
286
|
+
compareIdentifiers(this.minor, other.minor) ||
|
|
287
|
+
compareIdentifiers(this.patch, other.patch));
|
|
288
|
+
}
|
|
289
|
+
comparePre(other) {
|
|
290
|
+
if (!(other instanceof SemVer)) {
|
|
291
|
+
other = new SemVer(other, this.options);
|
|
292
|
+
}
|
|
293
|
+
// NOT having a prerelease is > having one
|
|
294
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
|
295
|
+
return -1;
|
|
296
|
+
}
|
|
297
|
+
else if (!this.prerelease.length && other.prerelease.length) {
|
|
298
|
+
return 1;
|
|
299
|
+
}
|
|
300
|
+
else if (!this.prerelease.length && !other.prerelease.length) {
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
let i = 0;
|
|
304
|
+
do {
|
|
305
|
+
const a = this.prerelease[i];
|
|
306
|
+
const b = other.prerelease[i];
|
|
307
|
+
if (a === undefined && b === undefined) {
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
else if (b === undefined) {
|
|
311
|
+
return 1;
|
|
312
|
+
}
|
|
313
|
+
else if (a === undefined) {
|
|
314
|
+
return -1;
|
|
315
|
+
}
|
|
316
|
+
else if (a === b) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
return compareIdentifiers(a, b);
|
|
321
|
+
}
|
|
322
|
+
} while (++i);
|
|
323
|
+
return 1;
|
|
324
|
+
}
|
|
325
|
+
compareBuild(other) {
|
|
326
|
+
if (!(other instanceof SemVer)) {
|
|
327
|
+
other = new SemVer(other, this.options);
|
|
328
|
+
}
|
|
329
|
+
let i = 0;
|
|
330
|
+
do {
|
|
331
|
+
const a = this.build[i];
|
|
332
|
+
const b = other.build[i];
|
|
333
|
+
if (a === undefined && b === undefined) {
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
else if (b === undefined) {
|
|
337
|
+
return 1;
|
|
338
|
+
}
|
|
339
|
+
else if (a === undefined) {
|
|
340
|
+
return -1;
|
|
341
|
+
}
|
|
342
|
+
else if (a === b) {
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
return compareIdentifiers(a, b);
|
|
347
|
+
}
|
|
348
|
+
} while (++i);
|
|
349
|
+
return 1;
|
|
350
|
+
}
|
|
351
|
+
increment(release, identifier) {
|
|
352
|
+
switch (release) {
|
|
353
|
+
case "premajor":
|
|
354
|
+
this.prerelease.length = 0;
|
|
355
|
+
this.patch = 0;
|
|
356
|
+
this.minor = 0;
|
|
357
|
+
this.major++;
|
|
358
|
+
this.increment("pre", identifier);
|
|
359
|
+
break;
|
|
360
|
+
case "preminor":
|
|
361
|
+
this.prerelease.length = 0;
|
|
362
|
+
this.patch = 0;
|
|
363
|
+
this.minor++;
|
|
364
|
+
this.increment("pre", identifier);
|
|
365
|
+
break;
|
|
366
|
+
case "prepatch":
|
|
367
|
+
// If this is already a prerelease, it will bump to the next version
|
|
368
|
+
// drop any prereleases that might already exist, since they are not
|
|
369
|
+
// relevant at this point.
|
|
370
|
+
this.prerelease.length = 0;
|
|
371
|
+
this.increment("patch", identifier);
|
|
372
|
+
this.increment("pre", identifier);
|
|
373
|
+
break;
|
|
374
|
+
// If the input is a non-prerelease version, this acts the same as
|
|
375
|
+
// prepatch.
|
|
376
|
+
case "prerelease":
|
|
377
|
+
if (this.prerelease.length === 0) {
|
|
378
|
+
this.increment("patch", identifier);
|
|
379
|
+
}
|
|
380
|
+
this.increment("pre", identifier);
|
|
381
|
+
break;
|
|
382
|
+
case "major":
|
|
383
|
+
// If this is a pre-major version, bump up to the same major version.
|
|
384
|
+
// Otherwise increment major.
|
|
385
|
+
// 1.0.0-5 bumps to 1.0.0
|
|
386
|
+
// 1.1.0 bumps to 2.0.0
|
|
387
|
+
if (this.minor !== 0 ||
|
|
388
|
+
this.patch !== 0 ||
|
|
389
|
+
this.prerelease.length === 0) {
|
|
390
|
+
this.major++;
|
|
391
|
+
}
|
|
392
|
+
this.minor = 0;
|
|
393
|
+
this.patch = 0;
|
|
394
|
+
this.prerelease = [];
|
|
395
|
+
break;
|
|
396
|
+
case "minor":
|
|
397
|
+
// If this is a pre-minor version, bump up to the same minor version.
|
|
398
|
+
// Otherwise increment minor.
|
|
399
|
+
// 1.2.0-5 bumps to 1.2.0
|
|
400
|
+
// 1.2.1 bumps to 1.3.0
|
|
401
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
402
|
+
this.minor++;
|
|
403
|
+
}
|
|
404
|
+
this.patch = 0;
|
|
405
|
+
this.prerelease = [];
|
|
406
|
+
break;
|
|
407
|
+
case "patch":
|
|
408
|
+
// If this is not a pre-release version, it will increment the patch.
|
|
409
|
+
// If it is a pre-release it will bump up to the same patch version.
|
|
410
|
+
// 1.2.0-5 patches to 1.2.0
|
|
411
|
+
// 1.2.0 patches to 1.2.1
|
|
412
|
+
if (this.prerelease.length === 0) {
|
|
413
|
+
this.patch++;
|
|
414
|
+
}
|
|
415
|
+
this.prerelease = [];
|
|
416
|
+
break;
|
|
417
|
+
// This probably shouldn't be used publicly.
|
|
418
|
+
// 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction.
|
|
419
|
+
case "pre":
|
|
420
|
+
if (this.prerelease.length === 0) {
|
|
421
|
+
this.prerelease = [0];
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
let i = this.prerelease.length;
|
|
425
|
+
while (--i >= 0) {
|
|
426
|
+
if (typeof this.prerelease[i] === "number") {
|
|
427
|
+
// deno-fmt-ignore
|
|
428
|
+
this.prerelease[i]++;
|
|
429
|
+
i = -2;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (i === -1) {
|
|
433
|
+
// didn't increment anything
|
|
434
|
+
this.prerelease.push(0);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (identifier) {
|
|
438
|
+
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
439
|
+
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
440
|
+
if (this.prerelease[0] === identifier) {
|
|
441
|
+
if (isNaN(this.prerelease[1])) {
|
|
442
|
+
this.prerelease = [identifier, 0];
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
this.prerelease = [identifier, 0];
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
break;
|
|
450
|
+
default:
|
|
451
|
+
throw new Error("invalid increment argument: " + release);
|
|
452
|
+
}
|
|
453
|
+
this.format();
|
|
454
|
+
this.raw = this.version;
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
toString() {
|
|
458
|
+
return this.version;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
exports.SemVer = SemVer;
|
|
462
|
+
/**
|
|
463
|
+
* Returns the version incremented by the release type
|
|
464
|
+
* (major, minor, patch, or prerelease), or null if it's not valid.
|
|
465
|
+
*
|
|
466
|
+
* `premajor` in one call will bump the version up to the next major version and
|
|
467
|
+
* down to a prerelease of that major version. `preminor`, and `prepatch` work
|
|
468
|
+
* the same way.
|
|
469
|
+
*
|
|
470
|
+
* If called from a non-prerelease version, the `prerelease` will work the same
|
|
471
|
+
* as `prepatch`. It increments the patch version, then makes a prerelease. If
|
|
472
|
+
* the input version is already a prerelease it simply increments it.
|
|
473
|
+
*/
|
|
474
|
+
function increment(version, release, options, identifier) {
|
|
475
|
+
if (typeof options === "string") {
|
|
476
|
+
identifier = options;
|
|
477
|
+
options = undefined;
|
|
478
|
+
}
|
|
479
|
+
try {
|
|
480
|
+
return new SemVer(version, options).increment(release, identifier).version;
|
|
481
|
+
}
|
|
482
|
+
catch {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
exports.increment = increment;
|
|
487
|
+
/**
|
|
488
|
+
* Returns difference between two versions by the release type (`major`,
|
|
489
|
+
* `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`), or
|
|
490
|
+
* null if the versions are the same.
|
|
491
|
+
*/
|
|
492
|
+
function difference(version1, version2, options) {
|
|
493
|
+
if (eq(version1, version2, options)) {
|
|
494
|
+
return null;
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
const v1 = parse(version1);
|
|
498
|
+
const v2 = parse(version2);
|
|
499
|
+
let prefix = "";
|
|
500
|
+
let defaultResult = null;
|
|
501
|
+
if (v1 && v2) {
|
|
502
|
+
if (v1.prerelease.length || v2.prerelease.length) {
|
|
503
|
+
prefix = "pre";
|
|
504
|
+
defaultResult = "prerelease";
|
|
505
|
+
}
|
|
506
|
+
for (const key in v1) {
|
|
507
|
+
if (key === "major" || key === "minor" || key === "patch") {
|
|
508
|
+
if (v1[key] !== v2[key]) {
|
|
509
|
+
return (prefix + key);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return defaultResult; // may be undefined
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
exports.difference = difference;
|
|
518
|
+
const numeric = /^[0-9]+$/;
|
|
519
|
+
function compareIdentifiers(a, b) {
|
|
520
|
+
const anum = numeric.test(a);
|
|
521
|
+
const bnum = numeric.test(b);
|
|
522
|
+
if (a === null || b === null)
|
|
523
|
+
throw "Comparison against null invalid";
|
|
524
|
+
if (anum && bnum) {
|
|
525
|
+
a = +a;
|
|
526
|
+
b = +b;
|
|
527
|
+
}
|
|
528
|
+
return a === b ? 0 : anum && !bnum ? -1 : bnum && !anum ? 1 : a < b ? -1 : 1;
|
|
529
|
+
}
|
|
530
|
+
exports.compareIdentifiers = compareIdentifiers;
|
|
531
|
+
function rcompareIdentifiers(a, b) {
|
|
532
|
+
return compareIdentifiers(b, a);
|
|
533
|
+
}
|
|
534
|
+
exports.rcompareIdentifiers = rcompareIdentifiers;
|
|
535
|
+
/** Returns the major version number. */
|
|
536
|
+
function major(v, options) {
|
|
537
|
+
return new SemVer(v, options).major;
|
|
538
|
+
}
|
|
539
|
+
exports.major = major;
|
|
540
|
+
/** Returns the minor version number. */
|
|
541
|
+
function minor(v, options) {
|
|
542
|
+
return new SemVer(v, options).minor;
|
|
543
|
+
}
|
|
544
|
+
exports.minor = minor;
|
|
545
|
+
/** Returns the patch version number. */
|
|
546
|
+
function patch(v, options) {
|
|
547
|
+
return new SemVer(v, options).patch;
|
|
548
|
+
}
|
|
549
|
+
exports.patch = patch;
|
|
550
|
+
/**
|
|
551
|
+
* Returns `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if `v2` is
|
|
552
|
+
* greater. Sorts in ascending order if passed to `Array.sort()`,
|
|
553
|
+
*/
|
|
554
|
+
function compare(v1, v2, options) {
|
|
555
|
+
return new SemVer(v1, options).compare(new SemVer(v2, options));
|
|
556
|
+
}
|
|
557
|
+
exports.compare = compare;
|
|
558
|
+
/**
|
|
559
|
+
* The same as {@linkcode compare} but considers `build` when two versions are
|
|
560
|
+
* equal. Sorts in ascending order if passed to `Array.sort()`.
|
|
561
|
+
*/
|
|
562
|
+
function compareBuild(a, b, options) {
|
|
563
|
+
const versionA = new SemVer(a, options);
|
|
564
|
+
const versionB = new SemVer(b, options);
|
|
565
|
+
return versionA.compare(versionB) || versionA.compareBuild(versionB);
|
|
566
|
+
}
|
|
567
|
+
exports.compareBuild = compareBuild;
|
|
568
|
+
/**
|
|
569
|
+
* Returns `0` if `v1 == v2`, or `-1` if `v1` is greater, or `1` if `v2` is
|
|
570
|
+
* greater. Sorts in descending order if passed to `Array.sort()`,
|
|
571
|
+
*/
|
|
572
|
+
function rcompare(v1, v2, options) {
|
|
573
|
+
return compare(v2, v1, options);
|
|
574
|
+
}
|
|
575
|
+
exports.rcompare = rcompare;
|
|
576
|
+
function sort(list, options) {
|
|
577
|
+
return list.sort((a, b) => {
|
|
578
|
+
return compareBuild(a, b, options);
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
exports.sort = sort;
|
|
582
|
+
function rsort(list, options) {
|
|
583
|
+
return list.sort((a, b) => {
|
|
584
|
+
return compareBuild(b, a, options);
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
exports.rsort = rsort;
|
|
588
|
+
/** Greater than comparison */
|
|
589
|
+
function gt(v1, v2, options) {
|
|
590
|
+
return compare(v1, v2, options) > 0;
|
|
591
|
+
}
|
|
592
|
+
exports.gt = gt;
|
|
593
|
+
/** Less than comparison */
|
|
594
|
+
function lt(v1, v2, options) {
|
|
595
|
+
return compare(v1, v2, options) < 0;
|
|
596
|
+
}
|
|
597
|
+
exports.lt = lt;
|
|
598
|
+
/**
|
|
599
|
+
* This is true if they're logically equivalent, even if they're not the exact
|
|
600
|
+
* same string.
|
|
601
|
+
*/
|
|
602
|
+
function eq(v1, v2, options) {
|
|
603
|
+
return compare(v1, v2, options) === 0;
|
|
604
|
+
}
|
|
605
|
+
exports.eq = eq;
|
|
606
|
+
/**
|
|
607
|
+
* This is true if they're not logically equivalent, even if they're the exact
|
|
608
|
+
* same string.
|
|
609
|
+
*/
|
|
610
|
+
function neq(v1, v2, options) {
|
|
611
|
+
return compare(v1, v2, options) !== 0;
|
|
612
|
+
}
|
|
613
|
+
exports.neq = neq;
|
|
614
|
+
/** Greater than or equal comparison */
|
|
615
|
+
function gte(v1, v2, options) {
|
|
616
|
+
return compare(v1, v2, options) >= 0;
|
|
617
|
+
}
|
|
618
|
+
exports.gte = gte;
|
|
619
|
+
/** Less than or equal comparison */
|
|
620
|
+
function lte(v1, v2, options) {
|
|
621
|
+
return compare(v1, v2, options) <= 0;
|
|
622
|
+
}
|
|
623
|
+
exports.lte = lte;
|
|
624
|
+
/**
|
|
625
|
+
* Pass in a comparison string, and it'll call the corresponding comparison
|
|
626
|
+
* function. `"==="` and `"!=="` do simple string comparison, but are included
|
|
627
|
+
* for completeness. Throws if an invalid comparison string is provided.
|
|
628
|
+
*/
|
|
629
|
+
function cmp(v1, operator, v2, options) {
|
|
630
|
+
switch (operator) {
|
|
631
|
+
case "===":
|
|
632
|
+
if (typeof v1 === "object")
|
|
633
|
+
v1 = v1.version;
|
|
634
|
+
if (typeof v2 === "object")
|
|
635
|
+
v2 = v2.version;
|
|
636
|
+
return v1 === v2;
|
|
637
|
+
case "!==":
|
|
638
|
+
if (typeof v1 === "object")
|
|
639
|
+
v1 = v1.version;
|
|
640
|
+
if (typeof v2 === "object")
|
|
641
|
+
v2 = v2.version;
|
|
642
|
+
return v1 !== v2;
|
|
643
|
+
case "":
|
|
644
|
+
case "=":
|
|
645
|
+
case "==":
|
|
646
|
+
return eq(v1, v2, options);
|
|
647
|
+
case "!=":
|
|
648
|
+
return neq(v1, v2, options);
|
|
649
|
+
case ">":
|
|
650
|
+
return gt(v1, v2, options);
|
|
651
|
+
case ">=":
|
|
652
|
+
return gte(v1, v2, options);
|
|
653
|
+
case "<":
|
|
654
|
+
return lt(v1, v2, options);
|
|
655
|
+
case "<=":
|
|
656
|
+
return lte(v1, v2, options);
|
|
657
|
+
default:
|
|
658
|
+
throw new TypeError("Invalid operator: " + operator);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
exports.cmp = cmp;
|
|
662
|
+
const ANY = {};
|
|
663
|
+
class Comparator {
|
|
664
|
+
constructor(comp, options) {
|
|
665
|
+
Object.defineProperty(this, "semver", {
|
|
666
|
+
enumerable: true,
|
|
667
|
+
configurable: true,
|
|
668
|
+
writable: true,
|
|
669
|
+
value: void 0
|
|
670
|
+
});
|
|
671
|
+
Object.defineProperty(this, "operator", {
|
|
672
|
+
enumerable: true,
|
|
673
|
+
configurable: true,
|
|
674
|
+
writable: true,
|
|
675
|
+
value: void 0
|
|
676
|
+
});
|
|
677
|
+
Object.defineProperty(this, "value", {
|
|
678
|
+
enumerable: true,
|
|
679
|
+
configurable: true,
|
|
680
|
+
writable: true,
|
|
681
|
+
value: void 0
|
|
682
|
+
});
|
|
683
|
+
Object.defineProperty(this, "options", {
|
|
684
|
+
enumerable: true,
|
|
685
|
+
configurable: true,
|
|
686
|
+
writable: true,
|
|
687
|
+
value: void 0
|
|
688
|
+
});
|
|
689
|
+
if (typeof options !== "object") {
|
|
690
|
+
options = {
|
|
691
|
+
includePrerelease: false,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
if (comp instanceof Comparator) {
|
|
695
|
+
return comp;
|
|
696
|
+
}
|
|
697
|
+
if (!(this instanceof Comparator)) {
|
|
698
|
+
return new Comparator(comp, options);
|
|
699
|
+
}
|
|
700
|
+
this.options = options;
|
|
701
|
+
this.parse(comp);
|
|
702
|
+
if (this.semver === ANY) {
|
|
703
|
+
this.value = "";
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
this.value = this.operator + this.semver.version;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
parse(comp) {
|
|
710
|
+
const r = re[COMPARATOR];
|
|
711
|
+
const m = comp.match(r);
|
|
712
|
+
if (!m) {
|
|
713
|
+
throw new TypeError("Invalid comparator: " + comp);
|
|
714
|
+
}
|
|
715
|
+
const m1 = m[1];
|
|
716
|
+
this.operator = m1 !== undefined ? m1 : "";
|
|
717
|
+
if (this.operator === "=") {
|
|
718
|
+
this.operator = "";
|
|
719
|
+
}
|
|
720
|
+
// if it literally is just '>' or '' then allow anything.
|
|
721
|
+
if (!m[2]) {
|
|
722
|
+
this.semver = ANY;
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
this.semver = new SemVer(m[2], this.options);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
test(version) {
|
|
729
|
+
if (this.semver === ANY || version === ANY) {
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
if (typeof version === "string") {
|
|
733
|
+
version = new SemVer(version, this.options);
|
|
734
|
+
}
|
|
735
|
+
return cmp(version, this.operator, this.semver, this.options);
|
|
736
|
+
}
|
|
737
|
+
intersects(comp, options) {
|
|
738
|
+
if (!(comp instanceof Comparator)) {
|
|
739
|
+
throw new TypeError("a Comparator is required");
|
|
740
|
+
}
|
|
741
|
+
if (typeof options !== "object") {
|
|
742
|
+
options = {
|
|
743
|
+
includePrerelease: false,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
let rangeTmp;
|
|
747
|
+
if (this.operator === "") {
|
|
748
|
+
if (this.value === "") {
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
rangeTmp = new Range(comp.value, options);
|
|
752
|
+
return satisfies(this.value, rangeTmp, options);
|
|
753
|
+
}
|
|
754
|
+
else if (comp.operator === "") {
|
|
755
|
+
if (comp.value === "") {
|
|
756
|
+
return true;
|
|
757
|
+
}
|
|
758
|
+
rangeTmp = new Range(this.value, options);
|
|
759
|
+
return satisfies(comp.semver, rangeTmp, options);
|
|
760
|
+
}
|
|
761
|
+
const sameDirectionIncreasing = (this.operator === ">=" || this.operator === ">") &&
|
|
762
|
+
(comp.operator === ">=" || comp.operator === ">");
|
|
763
|
+
const sameDirectionDecreasing = (this.operator === "<=" || this.operator === "<") &&
|
|
764
|
+
(comp.operator === "<=" || comp.operator === "<");
|
|
765
|
+
const sameSemVer = this.semver.version === comp.semver.version;
|
|
766
|
+
const differentDirectionsInclusive = (this.operator === ">=" || this.operator === "<=") &&
|
|
767
|
+
(comp.operator === ">=" || comp.operator === "<=");
|
|
768
|
+
const oppositeDirectionsLessThan = cmp(this.semver, "<", comp.semver, options) &&
|
|
769
|
+
(this.operator === ">=" || this.operator === ">") &&
|
|
770
|
+
(comp.operator === "<=" || comp.operator === "<");
|
|
771
|
+
const oppositeDirectionsGreaterThan = cmp(this.semver, ">", comp.semver, options) &&
|
|
772
|
+
(this.operator === "<=" || this.operator === "<") &&
|
|
773
|
+
(comp.operator === ">=" || comp.operator === ">");
|
|
774
|
+
return (sameDirectionIncreasing ||
|
|
775
|
+
sameDirectionDecreasing ||
|
|
776
|
+
(sameSemVer && differentDirectionsInclusive) ||
|
|
777
|
+
oppositeDirectionsLessThan ||
|
|
778
|
+
oppositeDirectionsGreaterThan);
|
|
779
|
+
}
|
|
780
|
+
toString() {
|
|
781
|
+
return this.value;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
exports.Comparator = Comparator;
|
|
785
|
+
class Range {
|
|
786
|
+
constructor(range, options) {
|
|
787
|
+
Object.defineProperty(this, "range", {
|
|
788
|
+
enumerable: true,
|
|
789
|
+
configurable: true,
|
|
790
|
+
writable: true,
|
|
791
|
+
value: void 0
|
|
792
|
+
});
|
|
793
|
+
Object.defineProperty(this, "raw", {
|
|
794
|
+
enumerable: true,
|
|
795
|
+
configurable: true,
|
|
796
|
+
writable: true,
|
|
797
|
+
value: void 0
|
|
798
|
+
});
|
|
799
|
+
Object.defineProperty(this, "options", {
|
|
800
|
+
enumerable: true,
|
|
801
|
+
configurable: true,
|
|
802
|
+
writable: true,
|
|
803
|
+
value: void 0
|
|
804
|
+
});
|
|
805
|
+
Object.defineProperty(this, "includePrerelease", {
|
|
806
|
+
enumerable: true,
|
|
807
|
+
configurable: true,
|
|
808
|
+
writable: true,
|
|
809
|
+
value: void 0
|
|
810
|
+
});
|
|
811
|
+
Object.defineProperty(this, "set", {
|
|
812
|
+
enumerable: true,
|
|
813
|
+
configurable: true,
|
|
814
|
+
writable: true,
|
|
815
|
+
value: void 0
|
|
816
|
+
});
|
|
817
|
+
if (typeof options !== "object") {
|
|
818
|
+
options = {
|
|
819
|
+
includePrerelease: false,
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
if (range instanceof Range) {
|
|
823
|
+
if (range.includePrerelease === !!options.includePrerelease) {
|
|
824
|
+
return range;
|
|
825
|
+
}
|
|
826
|
+
else {
|
|
827
|
+
return new Range(range.raw, options);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
if (range instanceof Comparator) {
|
|
831
|
+
return new Range(range.value, options);
|
|
832
|
+
}
|
|
833
|
+
if (!(this instanceof Range)) {
|
|
834
|
+
return new Range(range, options);
|
|
835
|
+
}
|
|
836
|
+
this.options = options;
|
|
837
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
838
|
+
// First, split based on boolean or ||
|
|
839
|
+
this.raw = range;
|
|
840
|
+
this.set = range
|
|
841
|
+
.split(/\s*\|\|\s*/)
|
|
842
|
+
.map((range) => this.parseRange(range.trim()))
|
|
843
|
+
.filter((c) => {
|
|
844
|
+
// throw out any that are not relevant for whatever reason
|
|
845
|
+
return c.length;
|
|
846
|
+
});
|
|
847
|
+
if (!this.set.length) {
|
|
848
|
+
throw new TypeError("Invalid SemVer Range: " + range);
|
|
849
|
+
}
|
|
850
|
+
this.format();
|
|
851
|
+
}
|
|
852
|
+
format() {
|
|
853
|
+
this.range = this.set
|
|
854
|
+
.map((comps) => comps.join(" ").trim())
|
|
855
|
+
.join("||")
|
|
856
|
+
.trim();
|
|
857
|
+
return this.range;
|
|
858
|
+
}
|
|
859
|
+
parseRange(range) {
|
|
860
|
+
range = range.trim();
|
|
861
|
+
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
862
|
+
const hr = re[HYPHENRANGE];
|
|
863
|
+
range = range.replace(hr, hyphenReplace);
|
|
864
|
+
// normalize spaces
|
|
865
|
+
range = range.split(/\s+/).join(" ");
|
|
866
|
+
// At this point, the range is completely trimmed and
|
|
867
|
+
// ready to be split into comparators.
|
|
868
|
+
const set = range
|
|
869
|
+
.split(" ")
|
|
870
|
+
.map((comp) => parseComparator(comp, this.options))
|
|
871
|
+
.join(" ")
|
|
872
|
+
.split(/\s+/);
|
|
873
|
+
return set.map((comp) => new Comparator(comp, this.options));
|
|
874
|
+
}
|
|
875
|
+
test(version) {
|
|
876
|
+
if (typeof version === "string") {
|
|
877
|
+
version = new SemVer(version, this.options);
|
|
878
|
+
}
|
|
879
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
880
|
+
if (testSet(this.set[i], version, this.options)) {
|
|
881
|
+
return true;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
return false;
|
|
885
|
+
}
|
|
886
|
+
intersects(range, options) {
|
|
887
|
+
if (!(range instanceof Range)) {
|
|
888
|
+
throw new TypeError("a Range is required");
|
|
889
|
+
}
|
|
890
|
+
return this.set.some((thisComparators) => {
|
|
891
|
+
return (isSatisfiable(thisComparators, options) &&
|
|
892
|
+
range.set.some((rangeComparators) => {
|
|
893
|
+
return (isSatisfiable(rangeComparators, options) &&
|
|
894
|
+
thisComparators.every((thisComparator) => {
|
|
895
|
+
return rangeComparators.every((rangeComparator) => {
|
|
896
|
+
return thisComparator.intersects(rangeComparator, options);
|
|
897
|
+
});
|
|
898
|
+
}));
|
|
899
|
+
}));
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
toString() {
|
|
903
|
+
return this.range;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
exports.Range = Range;
|
|
907
|
+
function testSet(set, version, options) {
|
|
908
|
+
for (let i = 0; i < set.length; i++) {
|
|
909
|
+
if (!set[i].test(version)) {
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
|
914
|
+
// Find the set of versions that are allowed to have prereleases
|
|
915
|
+
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
|
916
|
+
// That should allow `1.2.3-pr.2` to pass.
|
|
917
|
+
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
|
918
|
+
// even though it's within the range set by the comparators.
|
|
919
|
+
for (let i = 0; i < set.length; i++) {
|
|
920
|
+
if (set[i].semver === ANY) {
|
|
921
|
+
continue;
|
|
922
|
+
}
|
|
923
|
+
if (set[i].semver.prerelease.length > 0) {
|
|
924
|
+
const allowed = set[i].semver;
|
|
925
|
+
if (allowed.major === version.major &&
|
|
926
|
+
allowed.minor === version.minor &&
|
|
927
|
+
allowed.patch === version.patch) {
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
// Version has a -pre, but it's not one of the ones we like.
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
return true;
|
|
936
|
+
}
|
|
937
|
+
// take a set of comparators and determine whether there
|
|
938
|
+
// exists a version which can satisfy it
|
|
939
|
+
function isSatisfiable(comparators, options) {
|
|
940
|
+
let result = true;
|
|
941
|
+
const remainingComparators = comparators.slice();
|
|
942
|
+
let testComparator = remainingComparators.pop();
|
|
943
|
+
while (result && remainingComparators.length) {
|
|
944
|
+
result = remainingComparators.every((otherComparator) => {
|
|
945
|
+
return testComparator?.intersects(otherComparator, options);
|
|
946
|
+
});
|
|
947
|
+
testComparator = remainingComparators.pop();
|
|
948
|
+
}
|
|
949
|
+
return result;
|
|
950
|
+
}
|
|
951
|
+
// Mostly just for testing and legacy API reasons
|
|
952
|
+
function toComparators(range, options) {
|
|
953
|
+
return new Range(range, options).set.map((comp) => {
|
|
954
|
+
return comp
|
|
955
|
+
.map((c) => c.value)
|
|
956
|
+
.join(" ")
|
|
957
|
+
.trim()
|
|
958
|
+
.split(" ");
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
exports.toComparators = toComparators;
|
|
962
|
+
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
|
963
|
+
// already replaced the hyphen ranges
|
|
964
|
+
// turn into a set of JUST comparators.
|
|
965
|
+
function parseComparator(comp, options) {
|
|
966
|
+
comp = replaceCarets(comp, options);
|
|
967
|
+
comp = replaceTildes(comp, options);
|
|
968
|
+
comp = replaceXRanges(comp, options);
|
|
969
|
+
comp = replaceStars(comp, options);
|
|
970
|
+
return comp;
|
|
971
|
+
}
|
|
972
|
+
function isX(id) {
|
|
973
|
+
return !id || id.toLowerCase() === "x" || id === "*";
|
|
974
|
+
}
|
|
975
|
+
// ~, ~> --> * (any, kinda silly)
|
|
976
|
+
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
|
|
977
|
+
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
|
|
978
|
+
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
|
|
979
|
+
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
|
|
980
|
+
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
|
|
981
|
+
function replaceTildes(comp, options) {
|
|
982
|
+
return comp
|
|
983
|
+
.trim()
|
|
984
|
+
.split(/\s+/)
|
|
985
|
+
.map((comp) => replaceTilde(comp, options))
|
|
986
|
+
.join(" ");
|
|
987
|
+
}
|
|
988
|
+
function replaceTilde(comp, _options) {
|
|
989
|
+
const r = re[TILDE];
|
|
990
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
991
|
+
let ret;
|
|
992
|
+
if (isX(M)) {
|
|
993
|
+
ret = "";
|
|
994
|
+
}
|
|
995
|
+
else if (isX(m)) {
|
|
996
|
+
ret = ">=" + M + ".0.0 <" + (+M + 1) + ".0.0";
|
|
997
|
+
}
|
|
998
|
+
else if (isX(p)) {
|
|
999
|
+
// ~1.2 == >=1.2.0 <1.3.0
|
|
1000
|
+
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
1001
|
+
}
|
|
1002
|
+
else if (pr) {
|
|
1003
|
+
ret = ">=" +
|
|
1004
|
+
M +
|
|
1005
|
+
"." +
|
|
1006
|
+
m +
|
|
1007
|
+
"." +
|
|
1008
|
+
p +
|
|
1009
|
+
"-" +
|
|
1010
|
+
pr +
|
|
1011
|
+
" <" +
|
|
1012
|
+
M +
|
|
1013
|
+
"." +
|
|
1014
|
+
(+m + 1) +
|
|
1015
|
+
".0";
|
|
1016
|
+
}
|
|
1017
|
+
else {
|
|
1018
|
+
// ~1.2.3 == >=1.2.3 <1.3.0
|
|
1019
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
|
|
1020
|
+
}
|
|
1021
|
+
return ret;
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
// ^ --> * (any, kinda silly)
|
|
1025
|
+
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
|
|
1026
|
+
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
|
|
1027
|
+
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
|
|
1028
|
+
// ^1.2.3 --> >=1.2.3 <2.0.0
|
|
1029
|
+
// ^1.2.0 --> >=1.2.0 <2.0.0
|
|
1030
|
+
function replaceCarets(comp, options) {
|
|
1031
|
+
return comp
|
|
1032
|
+
.trim()
|
|
1033
|
+
.split(/\s+/)
|
|
1034
|
+
.map((comp) => replaceCaret(comp, options))
|
|
1035
|
+
.join(" ");
|
|
1036
|
+
}
|
|
1037
|
+
function replaceCaret(comp, _options) {
|
|
1038
|
+
const r = re[CARET];
|
|
1039
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1040
|
+
let ret;
|
|
1041
|
+
if (isX(M)) {
|
|
1042
|
+
ret = "";
|
|
1043
|
+
}
|
|
1044
|
+
else if (isX(m)) {
|
|
1045
|
+
ret = ">=" + M + ".0.0 <" + (+M + 1) + ".0.0";
|
|
1046
|
+
}
|
|
1047
|
+
else if (isX(p)) {
|
|
1048
|
+
if (M === "0") {
|
|
1049
|
+
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
1050
|
+
}
|
|
1051
|
+
else {
|
|
1052
|
+
ret = ">=" + M + "." + m + ".0 <" + (+M + 1) + ".0.0";
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
else if (pr) {
|
|
1056
|
+
if (M === "0") {
|
|
1057
|
+
if (m === "0") {
|
|
1058
|
+
ret = ">=" +
|
|
1059
|
+
M +
|
|
1060
|
+
"." +
|
|
1061
|
+
m +
|
|
1062
|
+
"." +
|
|
1063
|
+
p +
|
|
1064
|
+
"-" +
|
|
1065
|
+
pr +
|
|
1066
|
+
" <" +
|
|
1067
|
+
M +
|
|
1068
|
+
"." +
|
|
1069
|
+
m +
|
|
1070
|
+
"." +
|
|
1071
|
+
(+p + 1);
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
ret = ">=" +
|
|
1075
|
+
M +
|
|
1076
|
+
"." +
|
|
1077
|
+
m +
|
|
1078
|
+
"." +
|
|
1079
|
+
p +
|
|
1080
|
+
"-" +
|
|
1081
|
+
pr +
|
|
1082
|
+
" <" +
|
|
1083
|
+
M +
|
|
1084
|
+
"." +
|
|
1085
|
+
(+m + 1) +
|
|
1086
|
+
".0";
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + (+M + 1) +
|
|
1091
|
+
".0.0";
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
else {
|
|
1095
|
+
if (M === "0") {
|
|
1096
|
+
if (m === "0") {
|
|
1097
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." +
|
|
1098
|
+
(+p + 1);
|
|
1099
|
+
}
|
|
1100
|
+
else {
|
|
1101
|
+
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
else {
|
|
1105
|
+
ret = ">=" + M + "." + m + "." + p + " <" + (+M + 1) + ".0.0";
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
return ret;
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
function replaceXRanges(comp, options) {
|
|
1112
|
+
return comp
|
|
1113
|
+
.split(/\s+/)
|
|
1114
|
+
.map((comp) => replaceXRange(comp, options))
|
|
1115
|
+
.join(" ");
|
|
1116
|
+
}
|
|
1117
|
+
function replaceXRange(comp, _options) {
|
|
1118
|
+
comp = comp.trim();
|
|
1119
|
+
const r = re[XRANGE];
|
|
1120
|
+
return comp.replace(r, (ret, gtlt, M, m, p, _pr) => {
|
|
1121
|
+
const xM = isX(M);
|
|
1122
|
+
const xm = xM || isX(m);
|
|
1123
|
+
const xp = xm || isX(p);
|
|
1124
|
+
const anyX = xp;
|
|
1125
|
+
if (gtlt === "=" && anyX) {
|
|
1126
|
+
gtlt = "";
|
|
1127
|
+
}
|
|
1128
|
+
if (xM) {
|
|
1129
|
+
if (gtlt === ">" || gtlt === "<") {
|
|
1130
|
+
// nothing is allowed
|
|
1131
|
+
ret = "<0.0.0";
|
|
1132
|
+
}
|
|
1133
|
+
else {
|
|
1134
|
+
// nothing is forbidden
|
|
1135
|
+
ret = "*";
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
else if (gtlt && anyX) {
|
|
1139
|
+
// we know patch is an x, because we have any x at all.
|
|
1140
|
+
// replace X with 0
|
|
1141
|
+
if (xm) {
|
|
1142
|
+
m = 0;
|
|
1143
|
+
}
|
|
1144
|
+
p = 0;
|
|
1145
|
+
if (gtlt === ">") {
|
|
1146
|
+
// >1 => >=2.0.0
|
|
1147
|
+
// >1.2 => >=1.3.0
|
|
1148
|
+
// >1.2.3 => >= 1.2.4
|
|
1149
|
+
gtlt = ">=";
|
|
1150
|
+
if (xm) {
|
|
1151
|
+
M = +M + 1;
|
|
1152
|
+
m = 0;
|
|
1153
|
+
p = 0;
|
|
1154
|
+
}
|
|
1155
|
+
else {
|
|
1156
|
+
m = +m + 1;
|
|
1157
|
+
p = 0;
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
else if (gtlt === "<=") {
|
|
1161
|
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
|
1162
|
+
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
|
1163
|
+
gtlt = "<";
|
|
1164
|
+
if (xm) {
|
|
1165
|
+
M = +M + 1;
|
|
1166
|
+
}
|
|
1167
|
+
else {
|
|
1168
|
+
m = +m + 1;
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
ret = gtlt + M + "." + m + "." + p;
|
|
1172
|
+
}
|
|
1173
|
+
else if (xm) {
|
|
1174
|
+
ret = ">=" + M + ".0.0 <" + (+M + 1) + ".0.0";
|
|
1175
|
+
}
|
|
1176
|
+
else if (xp) {
|
|
1177
|
+
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
1178
|
+
}
|
|
1179
|
+
return ret;
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
// Because * is AND-ed with everything else in the comparator,
|
|
1183
|
+
// and '' means "any version", just remove the *s entirely.
|
|
1184
|
+
function replaceStars(comp, _options) {
|
|
1185
|
+
return comp.trim().replace(re[STAR], "");
|
|
1186
|
+
}
|
|
1187
|
+
// This function is passed to string.replace(re[HYPHENRANGE])
|
|
1188
|
+
// M, m, patch, prerelease, build
|
|
1189
|
+
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
1190
|
+
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
|
1191
|
+
// 1.2 - 3.4 => >=1.2.0 <3.5.0
|
|
1192
|
+
function hyphenReplace(_$0, from, fM, fm, fp, _fpr, _fb, to, tM, tm, tp, tpr, _tb) {
|
|
1193
|
+
if (isX(fM)) {
|
|
1194
|
+
from = "";
|
|
1195
|
+
}
|
|
1196
|
+
else if (isX(fm)) {
|
|
1197
|
+
from = ">=" + fM + ".0.0";
|
|
1198
|
+
}
|
|
1199
|
+
else if (isX(fp)) {
|
|
1200
|
+
from = ">=" + fM + "." + fm + ".0";
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
from = ">=" + from;
|
|
1204
|
+
}
|
|
1205
|
+
if (isX(tM)) {
|
|
1206
|
+
to = "";
|
|
1207
|
+
}
|
|
1208
|
+
else if (isX(tm)) {
|
|
1209
|
+
to = "<" + (+tM + 1) + ".0.0";
|
|
1210
|
+
}
|
|
1211
|
+
else if (isX(tp)) {
|
|
1212
|
+
to = "<" + tM + "." + (+tm + 1) + ".0";
|
|
1213
|
+
}
|
|
1214
|
+
else if (tpr) {
|
|
1215
|
+
to = "<=" + tM + "." + tm + "." + tp + "-" + tpr;
|
|
1216
|
+
}
|
|
1217
|
+
else {
|
|
1218
|
+
to = "<=" + to;
|
|
1219
|
+
}
|
|
1220
|
+
return (from + " " + to).trim();
|
|
1221
|
+
}
|
|
1222
|
+
/** Returns true if the version satisfies the range. */
|
|
1223
|
+
function satisfies(version, range, options) {
|
|
1224
|
+
try {
|
|
1225
|
+
range = new Range(range, options);
|
|
1226
|
+
}
|
|
1227
|
+
catch {
|
|
1228
|
+
return false;
|
|
1229
|
+
}
|
|
1230
|
+
return range.test(version);
|
|
1231
|
+
}
|
|
1232
|
+
exports.satisfies = satisfies;
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns the highest version in the list that satisfies the range, or `null`
|
|
1235
|
+
* if none of them do.
|
|
1236
|
+
*/
|
|
1237
|
+
function maxSatisfying(versions, range, options) {
|
|
1238
|
+
//todo
|
|
1239
|
+
let max = null;
|
|
1240
|
+
let maxSV = null;
|
|
1241
|
+
let rangeObj;
|
|
1242
|
+
try {
|
|
1243
|
+
rangeObj = new Range(range, options);
|
|
1244
|
+
}
|
|
1245
|
+
catch {
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
versions.forEach((v) => {
|
|
1249
|
+
if (rangeObj.test(v)) {
|
|
1250
|
+
// satisfies(v, range, options)
|
|
1251
|
+
if (!max || (maxSV && maxSV.compare(v) === -1)) {
|
|
1252
|
+
// compare(max, v, true)
|
|
1253
|
+
max = v;
|
|
1254
|
+
maxSV = new SemVer(max, options);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
return max;
|
|
1259
|
+
}
|
|
1260
|
+
exports.maxSatisfying = maxSatisfying;
|
|
1261
|
+
/**
|
|
1262
|
+
* Returns the lowest version in the list that satisfies the range, or `null` if
|
|
1263
|
+
* none of them do.
|
|
1264
|
+
*/
|
|
1265
|
+
function minSatisfying(versions, range, options) {
|
|
1266
|
+
//todo
|
|
1267
|
+
let min = null;
|
|
1268
|
+
let minSV = null;
|
|
1269
|
+
let rangeObj;
|
|
1270
|
+
try {
|
|
1271
|
+
rangeObj = new Range(range, options);
|
|
1272
|
+
}
|
|
1273
|
+
catch {
|
|
1274
|
+
return null;
|
|
1275
|
+
}
|
|
1276
|
+
versions.forEach((v) => {
|
|
1277
|
+
if (rangeObj.test(v)) {
|
|
1278
|
+
// satisfies(v, range, options)
|
|
1279
|
+
if (!min || minSV.compare(v) === 1) {
|
|
1280
|
+
// compare(min, v, true)
|
|
1281
|
+
min = v;
|
|
1282
|
+
minSV = new SemVer(min, options);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
});
|
|
1286
|
+
return min;
|
|
1287
|
+
}
|
|
1288
|
+
exports.minSatisfying = minSatisfying;
|
|
1289
|
+
/** Returns the lowest version that can possibly match the given range. */
|
|
1290
|
+
function minVersion(range, options) {
|
|
1291
|
+
range = new Range(range, options);
|
|
1292
|
+
let minver = new SemVer("0.0.0");
|
|
1293
|
+
if (range.test(minver)) {
|
|
1294
|
+
return minver;
|
|
1295
|
+
}
|
|
1296
|
+
minver = new SemVer("0.0.0-0");
|
|
1297
|
+
if (range.test(minver)) {
|
|
1298
|
+
return minver;
|
|
1299
|
+
}
|
|
1300
|
+
minver = null;
|
|
1301
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
1302
|
+
const comparators = range.set[i];
|
|
1303
|
+
comparators.forEach((comparator) => {
|
|
1304
|
+
// Clone to avoid manipulating the comparator's semver object.
|
|
1305
|
+
const compver = new SemVer(comparator.semver.version);
|
|
1306
|
+
switch (comparator.operator) {
|
|
1307
|
+
case ">":
|
|
1308
|
+
if (compver.prerelease.length === 0) {
|
|
1309
|
+
compver.patch++;
|
|
1310
|
+
}
|
|
1311
|
+
else {
|
|
1312
|
+
compver.prerelease.push(0);
|
|
1313
|
+
}
|
|
1314
|
+
compver.raw = compver.format();
|
|
1315
|
+
/* fallthrough */
|
|
1316
|
+
case "":
|
|
1317
|
+
case ">=":
|
|
1318
|
+
if (!minver || gt(minver, compver)) {
|
|
1319
|
+
minver = compver;
|
|
1320
|
+
}
|
|
1321
|
+
break;
|
|
1322
|
+
case "<":
|
|
1323
|
+
case "<=":
|
|
1324
|
+
/* Ignore maximum versions */
|
|
1325
|
+
break;
|
|
1326
|
+
/* istanbul ignore next */
|
|
1327
|
+
default:
|
|
1328
|
+
throw new Error("Unexpected operation: " + comparator.operator);
|
|
1329
|
+
}
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
if (minver && range.test(minver)) {
|
|
1333
|
+
return minver;
|
|
1334
|
+
}
|
|
1335
|
+
return null;
|
|
1336
|
+
}
|
|
1337
|
+
exports.minVersion = minVersion;
|
|
1338
|
+
/** Returns the valid range or null if it's not valid. */
|
|
1339
|
+
function validRange(range, options) {
|
|
1340
|
+
try {
|
|
1341
|
+
if (range === null)
|
|
1342
|
+
return null;
|
|
1343
|
+
// Return '*' instead of '' so that truthiness works.
|
|
1344
|
+
// This will throw if it's invalid anyway
|
|
1345
|
+
return new Range(range, options).range || "*";
|
|
1346
|
+
}
|
|
1347
|
+
catch {
|
|
1348
|
+
return null;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
exports.validRange = validRange;
|
|
1352
|
+
/**
|
|
1353
|
+
* Returns true if version is less than all the versions possible in the range.
|
|
1354
|
+
*/
|
|
1355
|
+
function ltr(version, range, options) {
|
|
1356
|
+
return outside(version, range, "<", options);
|
|
1357
|
+
}
|
|
1358
|
+
exports.ltr = ltr;
|
|
1359
|
+
/**
|
|
1360
|
+
* Returns true if version is greater than all the versions possible in the range.
|
|
1361
|
+
*/
|
|
1362
|
+
function gtr(version, range, options) {
|
|
1363
|
+
return outside(version, range, ">", options);
|
|
1364
|
+
}
|
|
1365
|
+
exports.gtr = gtr;
|
|
1366
|
+
/**
|
|
1367
|
+
* Returns true if the version is outside the bounds of the range in either the
|
|
1368
|
+
* high or low direction. The hilo argument must be either the string '>' or
|
|
1369
|
+
* '<'. (This is the function called by {@linkcode gtr} and {@linkcode ltr}.)
|
|
1370
|
+
*/
|
|
1371
|
+
function outside(version, range, hilo, options) {
|
|
1372
|
+
version = new SemVer(version, options);
|
|
1373
|
+
range = new Range(range, options);
|
|
1374
|
+
let gtfn;
|
|
1375
|
+
let ltefn;
|
|
1376
|
+
let ltfn;
|
|
1377
|
+
let comp;
|
|
1378
|
+
let ecomp;
|
|
1379
|
+
switch (hilo) {
|
|
1380
|
+
case ">":
|
|
1381
|
+
gtfn = gt;
|
|
1382
|
+
ltefn = lte;
|
|
1383
|
+
ltfn = lt;
|
|
1384
|
+
comp = ">";
|
|
1385
|
+
ecomp = ">=";
|
|
1386
|
+
break;
|
|
1387
|
+
case "<":
|
|
1388
|
+
gtfn = lt;
|
|
1389
|
+
ltefn = gte;
|
|
1390
|
+
ltfn = gt;
|
|
1391
|
+
comp = "<";
|
|
1392
|
+
ecomp = "<=";
|
|
1393
|
+
break;
|
|
1394
|
+
default:
|
|
1395
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"');
|
|
1396
|
+
}
|
|
1397
|
+
// If it satisifes the range it is not outside
|
|
1398
|
+
if (satisfies(version, range, options)) {
|
|
1399
|
+
return false;
|
|
1400
|
+
}
|
|
1401
|
+
// From now on, variable terms are as if we're in "gtr" mode.
|
|
1402
|
+
// but note that everything is flipped for the "ltr" function.
|
|
1403
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
1404
|
+
const comparators = range.set[i];
|
|
1405
|
+
let high = null;
|
|
1406
|
+
let low = null;
|
|
1407
|
+
for (let comparator of comparators) {
|
|
1408
|
+
if (comparator.semver === ANY) {
|
|
1409
|
+
comparator = new Comparator(">=0.0.0");
|
|
1410
|
+
}
|
|
1411
|
+
high = high || comparator;
|
|
1412
|
+
low = low || comparator;
|
|
1413
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
1414
|
+
high = comparator;
|
|
1415
|
+
}
|
|
1416
|
+
else if (ltfn(comparator.semver, low.semver, options)) {
|
|
1417
|
+
low = comparator;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
if (high === null || low === null)
|
|
1421
|
+
return true;
|
|
1422
|
+
// If the edge version comparator has a operator then our version
|
|
1423
|
+
// isn't outside it
|
|
1424
|
+
if (high.operator === comp || high.operator === ecomp) {
|
|
1425
|
+
return false;
|
|
1426
|
+
}
|
|
1427
|
+
// If the lowest version comparator has an operator and our version
|
|
1428
|
+
// is less than it then it isn't higher than the range
|
|
1429
|
+
if ((!low.operator || low.operator === comp) &&
|
|
1430
|
+
ltefn(version, low.semver)) {
|
|
1431
|
+
return false;
|
|
1432
|
+
}
|
|
1433
|
+
else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
1434
|
+
return false;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return true;
|
|
1438
|
+
}
|
|
1439
|
+
exports.outside = outside;
|
|
1440
|
+
/**
|
|
1441
|
+
* Returns an array of prerelease components, or null if none exist.
|
|
1442
|
+
*
|
|
1443
|
+
* @example
|
|
1444
|
+
* `prerelease("1.2.3-alpha.1") -> ["alpha", 1]`
|
|
1445
|
+
*/
|
|
1446
|
+
function prerelease(version, options) {
|
|
1447
|
+
const parsed = parse(version, options);
|
|
1448
|
+
return parsed && parsed.prerelease.length ? parsed.prerelease : null;
|
|
1449
|
+
}
|
|
1450
|
+
exports.prerelease = prerelease;
|
|
1451
|
+
/** Returns true if the two supplied ranges or comparators intersect. */
|
|
1452
|
+
function intersects(range1, range2, options) {
|
|
1453
|
+
range1 = new Range(range1, options);
|
|
1454
|
+
range2 = new Range(range2, options);
|
|
1455
|
+
return range1.intersects(range2);
|
|
1456
|
+
}
|
|
1457
|
+
exports.intersects = intersects;
|
|
1458
|
+
exports.default = SemVer;
|