keep-a-changelog 2.1.0 → 2.3.0
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 +23 -6
- package/esm/_dnt.test_shims.d.ts +5 -0
- package/esm/bin.js +11 -2
- package/esm/deps/deno.land/std@0.133.0/fmt/colors.d.ts +270 -0
- package/esm/deps/deno.land/std@0.133.0/testing/_diff.d.ts +23 -0
- package/esm/deps/deno.land/std@0.133.0/testing/asserts.d.ts +167 -0
- package/esm/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
- package/esm/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +227 -334
- package/esm/deps/deno.land/std@0.189.0/_util/asserts.d.ts +10 -0
- package/esm/deps/deno.land/std@0.189.0/_util/asserts.js +21 -0
- package/esm/deps/deno.land/std@0.189.0/_util/os.d.ts +4 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/_util/os.js +3 -2
- package/esm/deps/deno.land/std@0.189.0/flags/mod.d.ts +166 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/flags/mod.js +146 -36
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_constants.js +1 -0
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_interface.d.ts +1 -1
- package/esm/deps/deno.land/std@0.189.0/path/_interface.js +3 -0
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_util.d.ts +3 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_util.js +47 -0
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/common.js +1 -1
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/glob.d.ts +10 -5
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/glob.js +1 -1
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/mod.d.ts +3 -1
- package/esm/deps/deno.land/std@0.189.0/path/mod.js +35 -0
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/posix.d.ts +15 -9
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/posix.js +58 -112
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/separator.js +1 -1
- package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/win32.d.ts +13 -9
- package/esm/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/win32.js +30 -87
- package/esm/src/Change.js +15 -15
- package/{types → esm}/src/Changelog.d.ts +1 -0
- package/esm/src/Changelog.js +9 -1
- package/{types → esm}/src/Release.d.ts +1 -0
- package/esm/src/Release.js +10 -0
- package/esm/src/deps.d.ts +1 -0
- package/esm/src/deps.js +1 -1
- package/esm/src/parser.js +19 -3
- package/esm/test/Change.test.d.ts +1 -0
- package/esm/test/changelog.custom.type.md +0 -1
- package/esm/test/changelog.expected.linted.md +208 -0
- package/esm/test/changelog.expected.md +3 -1
- package/esm/test/changelog.md +4 -0
- package/esm/test/deps.d.ts +1 -0
- package/esm/test/empty.expected.md +0 -1
- package/esm/test/fixture/CustomRelease.d.ts +8 -0
- package/esm/test/parser.test.d.ts +1 -0
- package/esm/test/test.d.ts +1 -0
- package/package.json +6 -8
- package/script/_dnt.polyfills.d.ts +11 -0
- package/script/_dnt.shims.d.ts +5 -0
- package/script/_dnt.test_shims.d.ts +5 -0
- package/script/bin.d.ts +2 -0
- package/script/bin.js +11 -2
- package/script/deps/deno.land/std@0.133.0/fmt/colors.d.ts +270 -0
- package/script/deps/deno.land/std@0.133.0/testing/_diff.d.ts +23 -0
- package/script/deps/deno.land/std@0.133.0/testing/asserts.d.ts +167 -0
- package/script/deps/deno.land/std@0.173.0/semver/mod.d.ts +398 -0
- package/script/deps/deno.land/{x/semver@v1.4.0 → std@0.173.0/semver}/mod.js +232 -342
- package/script/deps/deno.land/std@0.189.0/_util/asserts.d.ts +10 -0
- package/script/deps/deno.land/std@0.189.0/_util/asserts.js +27 -0
- package/script/deps/deno.land/std@0.189.0/_util/os.d.ts +4 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/_util/os.js +4 -3
- package/script/deps/deno.land/std@0.189.0/flags/mod.d.ts +166 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/flags/mod.js +150 -40
- package/script/deps/deno.land/std@0.189.0/path/_constants.d.ts +39 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_constants.js +1 -0
- package/script/deps/deno.land/std@0.189.0/path/_interface.d.ts +26 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_interface.js +1 -1
- package/script/deps/deno.land/std@0.189.0/path/_util.d.ts +11 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/_util.js +51 -1
- package/script/deps/deno.land/std@0.189.0/path/common.d.ts +13 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/common.js +1 -1
- package/script/deps/deno.land/std@0.189.0/path/glob.d.ts +83 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/glob.js +1 -1
- package/script/deps/deno.land/std@0.189.0/path/mod.d.ts +11 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/mod.js +23 -2
- package/script/deps/deno.land/std@0.189.0/path/posix.d.ts +86 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/posix.js +56 -110
- package/script/deps/deno.land/std@0.189.0/path/separator.d.ts +2 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/separator.js +1 -1
- package/script/deps/deno.land/std@0.189.0/path/win32.d.ts +91 -0
- package/script/deps/deno.land/{std@0.120.0 → std@0.189.0}/path/win32.js +30 -87
- package/script/deps/deno.land/std@0.51.0/fs/eol.d.ts +12 -0
- package/script/deps/deno.land/x/ini@v2.1.0/ini.d.ts +53 -0
- package/script/deps/deno.land/x/ini@v2.1.0/mod.d.ts +1 -0
- package/script/mod.d.ts +6 -0
- package/script/src/Change.d.ts +8 -0
- package/script/src/Change.js +15 -15
- package/script/src/Changelog.d.ts +19 -0
- package/script/src/Changelog.js +9 -1
- package/script/src/Release.d.ts +27 -0
- package/script/src/Release.js +10 -0
- package/script/src/deps.d.ts +1 -0
- package/script/src/deps.js +1 -1
- package/script/src/parser.d.ts +11 -0
- package/script/src/parser.js +19 -3
- package/script/test/Change.test.d.ts +1 -0
- package/script/test/changelog.custom.type.md +0 -1
- package/script/test/changelog.expected.linted.md +208 -0
- package/script/test/changelog.expected.md +3 -1
- package/script/test/changelog.md +4 -0
- package/script/test/deps.d.ts +1 -0
- package/script/test/empty.expected.md +0 -1
- package/script/test/fixture/CustomRelease.d.ts +8 -0
- package/script/test/parser.test.d.ts +1 -0
- package/script/test/test.d.ts +1 -0
- 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/script/deps/deno.land/std@0.120.0/_util/assert.js +0 -18
- 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/types/src/deps.d.ts +0 -1
- /package/{types → esm}/_dnt.polyfills.d.ts +0 -0
- /package/{types → esm}/_dnt.shims.d.ts +0 -0
- /package/{types → esm}/bin.d.ts +0 -0
- /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/_constants.d.ts +0 -0
- /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/common.d.ts +0 -0
- /package/{types/deps/deno.land/std@0.120.0 → esm/deps/deno.land/std@0.189.0}/path/separator.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/std@0.51.0/fs/eol.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/x/ini@v2.1.0/ini.d.ts +0 -0
- /package/{types → esm}/deps/deno.land/x/ini@v2.1.0/mod.d.ts +0 -0
- /package/{types → esm}/mod.d.ts +0 -0
- /package/{types → esm}/src/Change.d.ts +0 -0
- /package/{types → esm}/src/parser.d.ts +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
1
3
|
// Note: this is the semver.org version of the spec that it implements
|
|
2
4
|
// Not necessarily the package version of this code.
|
|
3
5
|
export const SEMVER_SPEC_VERSION = "2.0.0";
|
|
4
6
|
const MAX_LENGTH = 256;
|
|
5
|
-
// Max safe segment length for coercion.
|
|
6
|
-
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
7
7
|
// The actual regexps
|
|
8
8
|
const re = [];
|
|
9
9
|
const src = [];
|
|
@@ -14,8 +14,6 @@ let R = 0;
|
|
|
14
14
|
// A single `0`, or a non-zero digit followed by zero or more digits.
|
|
15
15
|
const NUMERICIDENTIFIER = R++;
|
|
16
16
|
src[NUMERICIDENTIFIER] = "0|[1-9]\\d*";
|
|
17
|
-
const NUMERICIDENTIFIERLOOSE = R++;
|
|
18
|
-
src[NUMERICIDENTIFIERLOOSE] = "[0-9]+";
|
|
19
17
|
// ## Non-numeric Identifier
|
|
20
18
|
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
|
21
19
|
// more letters, digits, or hyphens.
|
|
@@ -26,17 +24,11 @@ src[NONNUMERICIDENTIFIER] = "\\d*[a-zA-Z-][a-zA-Z0-9-]*";
|
|
|
26
24
|
const MAINVERSION = R++;
|
|
27
25
|
const nid = src[NUMERICIDENTIFIER];
|
|
28
26
|
src[MAINVERSION] = `(${nid})\\.(${nid})\\.(${nid})`;
|
|
29
|
-
const MAINVERSIONLOOSE = R++;
|
|
30
|
-
const nidl = src[NUMERICIDENTIFIERLOOSE];
|
|
31
|
-
src[MAINVERSIONLOOSE] = `(${nidl})\\.(${nidl})\\.(${nidl})`;
|
|
32
27
|
// ## Pre-release Version Identifier
|
|
33
28
|
// A numeric identifier, or a non-numeric identifier.
|
|
34
29
|
const PRERELEASEIDENTIFIER = R++;
|
|
35
30
|
src[PRERELEASEIDENTIFIER] = "(?:" + src[NUMERICIDENTIFIER] + "|" +
|
|
36
31
|
src[NONNUMERICIDENTIFIER] + ")";
|
|
37
|
-
const PRERELEASEIDENTIFIERLOOSE = R++;
|
|
38
|
-
src[PRERELEASEIDENTIFIERLOOSE] = "(?:" + src[NUMERICIDENTIFIERLOOSE] + "|" +
|
|
39
|
-
src[NONNUMERICIDENTIFIER] + ")";
|
|
40
32
|
// ## Pre-release Version
|
|
41
33
|
// Hyphen, followed by one or more dot-separated pre-release version
|
|
42
34
|
// identifiers.
|
|
@@ -46,12 +38,6 @@ src[PRERELEASE] = "(?:-(" +
|
|
|
46
38
|
"(?:\\." +
|
|
47
39
|
src[PRERELEASEIDENTIFIER] +
|
|
48
40
|
")*))";
|
|
49
|
-
const PRERELEASELOOSE = R++;
|
|
50
|
-
src[PRERELEASELOOSE] = "(?:-?(" +
|
|
51
|
-
src[PRERELEASEIDENTIFIERLOOSE] +
|
|
52
|
-
"(?:\\." +
|
|
53
|
-
src[PRERELEASEIDENTIFIERLOOSE] +
|
|
54
|
-
")*))";
|
|
55
41
|
// ## Build Metadata Identifier
|
|
56
42
|
// Any combination of digits, letters, or hyphens.
|
|
57
43
|
const BUILDIDENTIFIER = R++;
|
|
@@ -73,24 +59,11 @@ const FULL = R++;
|
|
|
73
59
|
const FULLPLAIN = "v?" + src[MAINVERSION] + src[PRERELEASE] + "?" + src[BUILD] +
|
|
74
60
|
"?";
|
|
75
61
|
src[FULL] = "^" + FULLPLAIN + "$";
|
|
76
|
-
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
|
77
|
-
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
|
78
|
-
// common in the npm registry.
|
|
79
|
-
const LOOSEPLAIN = "[v=\\s]*" +
|
|
80
|
-
src[MAINVERSIONLOOSE] +
|
|
81
|
-
src[PRERELEASELOOSE] +
|
|
82
|
-
"?" +
|
|
83
|
-
src[BUILD] +
|
|
84
|
-
"?";
|
|
85
|
-
const LOOSE = R++;
|
|
86
|
-
src[LOOSE] = "^" + LOOSEPLAIN + "$";
|
|
87
62
|
const GTLT = R++;
|
|
88
63
|
src[GTLT] = "((?:<|>)?=?)";
|
|
89
64
|
// Something like "2.*" or "1.2.x".
|
|
90
65
|
// Note that "x.x" is a valid xRange identifer, meaning "any version"
|
|
91
66
|
// Only the first item is strictly required.
|
|
92
|
-
const XRANGEIDENTIFIERLOOSE = R++;
|
|
93
|
-
src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + "|x|X|\\*";
|
|
94
67
|
const XRANGEIDENTIFIER = R++;
|
|
95
68
|
src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + "|x|X|\\*";
|
|
96
69
|
const XRANGEPLAIN = R++;
|
|
@@ -109,81 +82,24 @@ src[XRANGEPLAIN] = "[v=\\s]*(" +
|
|
|
109
82
|
src[BUILD] +
|
|
110
83
|
"?" +
|
|
111
84
|
")?)?";
|
|
112
|
-
const XRANGEPLAINLOOSE = R++;
|
|
113
|
-
src[XRANGEPLAINLOOSE] = "[v=\\s]*(" +
|
|
114
|
-
src[XRANGEIDENTIFIERLOOSE] +
|
|
115
|
-
")" +
|
|
116
|
-
"(?:\\.(" +
|
|
117
|
-
src[XRANGEIDENTIFIERLOOSE] +
|
|
118
|
-
")" +
|
|
119
|
-
"(?:\\.(" +
|
|
120
|
-
src[XRANGEIDENTIFIERLOOSE] +
|
|
121
|
-
")" +
|
|
122
|
-
"(?:" +
|
|
123
|
-
src[PRERELEASELOOSE] +
|
|
124
|
-
")?" +
|
|
125
|
-
src[BUILD] +
|
|
126
|
-
"?" +
|
|
127
|
-
")?)?";
|
|
128
85
|
const XRANGE = R++;
|
|
129
86
|
src[XRANGE] = "^" + src[GTLT] + "\\s*" + src[XRANGEPLAIN] + "$";
|
|
130
|
-
const XRANGELOOSE = R++;
|
|
131
|
-
src[XRANGELOOSE] = "^" + src[GTLT] + "\\s*" + src[XRANGEPLAINLOOSE] + "$";
|
|
132
|
-
// Coercion.
|
|
133
|
-
// Extract anything that could conceivably be a part of a valid semver
|
|
134
|
-
const COERCE = R++;
|
|
135
|
-
src[COERCE] = "(?:^|[^\\d])" +
|
|
136
|
-
"(\\d{1," +
|
|
137
|
-
MAX_SAFE_COMPONENT_LENGTH +
|
|
138
|
-
"})" +
|
|
139
|
-
"(?:\\.(\\d{1," +
|
|
140
|
-
MAX_SAFE_COMPONENT_LENGTH +
|
|
141
|
-
"}))?" +
|
|
142
|
-
"(?:\\.(\\d{1," +
|
|
143
|
-
MAX_SAFE_COMPONENT_LENGTH +
|
|
144
|
-
"}))?" +
|
|
145
|
-
"(?:$|[^\\d])";
|
|
146
87
|
// Tilde ranges.
|
|
147
88
|
// Meaning is "reasonably at or greater than"
|
|
148
89
|
const LONETILDE = R++;
|
|
149
90
|
src[LONETILDE] = "(?:~>?)";
|
|
150
|
-
const TILDETRIM = R++;
|
|
151
|
-
src[TILDETRIM] = "(\\s*)" + src[LONETILDE] + "\\s+";
|
|
152
|
-
re[TILDETRIM] = new RegExp(src[TILDETRIM], "g");
|
|
153
|
-
const tildeTrimReplace = "$1~";
|
|
154
91
|
const TILDE = R++;
|
|
155
92
|
src[TILDE] = "^" + src[LONETILDE] + src[XRANGEPLAIN] + "$";
|
|
156
|
-
const TILDELOOSE = R++;
|
|
157
|
-
src[TILDELOOSE] = "^" + src[LONETILDE] + src[XRANGEPLAINLOOSE] + "$";
|
|
158
93
|
// Caret ranges.
|
|
159
94
|
// Meaning is "at least and backwards compatible with"
|
|
160
95
|
const LONECARET = R++;
|
|
161
96
|
src[LONECARET] = "(?:\\^)";
|
|
162
|
-
const CARETTRIM = R++;
|
|
163
|
-
src[CARETTRIM] = "(\\s*)" + src[LONECARET] + "\\s+";
|
|
164
|
-
re[CARETTRIM] = new RegExp(src[CARETTRIM], "g");
|
|
165
|
-
const caretTrimReplace = "$1^";
|
|
166
97
|
const CARET = R++;
|
|
167
98
|
src[CARET] = "^" + src[LONECARET] + src[XRANGEPLAIN] + "$";
|
|
168
|
-
const CARETLOOSE = R++;
|
|
169
|
-
src[CARETLOOSE] = "^" + src[LONECARET] + src[XRANGEPLAINLOOSE] + "$";
|
|
170
99
|
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
|
171
|
-
const COMPARATORLOOSE = R++;
|
|
172
|
-
src[COMPARATORLOOSE] = "^" + src[GTLT] + "\\s*(" + LOOSEPLAIN + ")$|^$";
|
|
173
100
|
const COMPARATOR = R++;
|
|
174
101
|
src[COMPARATOR] = "^" + src[GTLT] + "\\s*(" + FULLPLAIN + ")$|^$";
|
|
175
|
-
// An expression to strip any whitespace between the gtlt and the thing
|
|
176
|
-
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
177
|
-
const COMPARATORTRIM = R++;
|
|
178
|
-
src[COMPARATORTRIM] = "(\\s*)" + src[GTLT] + "\\s*(" + LOOSEPLAIN + "|" +
|
|
179
|
-
src[XRANGEPLAIN] + ")";
|
|
180
|
-
// this one has to use the /g flag
|
|
181
|
-
re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], "g");
|
|
182
|
-
const comparatorTrimReplace = "$1$2$3";
|
|
183
102
|
// Something like `1.2.3 - 1.2.4`
|
|
184
|
-
// Note that these all use the loose form, because they'll be
|
|
185
|
-
// checked against either the strict or loose comparator form
|
|
186
|
-
// later.
|
|
187
103
|
const HYPHENRANGE = R++;
|
|
188
104
|
src[HYPHENRANGE] = "^\\s*(" +
|
|
189
105
|
src[XRANGEPLAIN] +
|
|
@@ -193,15 +109,6 @@ src[HYPHENRANGE] = "^\\s*(" +
|
|
|
193
109
|
src[XRANGEPLAIN] +
|
|
194
110
|
")" +
|
|
195
111
|
"\\s*$";
|
|
196
|
-
const HYPHENRANGELOOSE = R++;
|
|
197
|
-
src[HYPHENRANGELOOSE] = "^\\s*(" +
|
|
198
|
-
src[XRANGEPLAINLOOSE] +
|
|
199
|
-
")" +
|
|
200
|
-
"\\s+-\\s+" +
|
|
201
|
-
"(" +
|
|
202
|
-
src[XRANGEPLAINLOOSE] +
|
|
203
|
-
")" +
|
|
204
|
-
"\\s*$";
|
|
205
112
|
// Star ranges basically just allow anything at all.
|
|
206
113
|
const STAR = R++;
|
|
207
114
|
src[STAR] = "(<|>)?=?\\s*\\*";
|
|
@@ -212,10 +119,13 @@ for (let i = 0; i < R; i++) {
|
|
|
212
119
|
re[i] = new RegExp(src[i]);
|
|
213
120
|
}
|
|
214
121
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Attempt to parse a string as a semantic version, returning either a `SemVer`
|
|
124
|
+
* object or `null`.
|
|
125
|
+
*/
|
|
126
|
+
export function parse(version, options) {
|
|
127
|
+
if (typeof options !== "object") {
|
|
128
|
+
options = {
|
|
219
129
|
includePrerelease: false,
|
|
220
130
|
};
|
|
221
131
|
}
|
|
@@ -228,41 +138,32 @@ export function parse(version, optionsOrLoose) {
|
|
|
228
138
|
if (version.length > MAX_LENGTH) {
|
|
229
139
|
return null;
|
|
230
140
|
}
|
|
231
|
-
const r =
|
|
141
|
+
const r = re[FULL];
|
|
232
142
|
if (!r.test(version)) {
|
|
233
143
|
return null;
|
|
234
144
|
}
|
|
235
145
|
try {
|
|
236
|
-
return new SemVer(version,
|
|
146
|
+
return new SemVer(version, options);
|
|
237
147
|
}
|
|
238
|
-
catch
|
|
148
|
+
catch {
|
|
239
149
|
return null;
|
|
240
150
|
}
|
|
241
151
|
}
|
|
242
|
-
|
|
152
|
+
/** Returns the parsed version, or null if it's not valid. */
|
|
153
|
+
export function valid(version, options) {
|
|
243
154
|
if (version === null)
|
|
244
155
|
return null;
|
|
245
|
-
const v = parse(version,
|
|
156
|
+
const v = parse(version, options);
|
|
246
157
|
return v ? v.version : null;
|
|
247
158
|
}
|
|
248
|
-
export function clean(version, optionsOrLoose) {
|
|
249
|
-
const s = parse(version.trim().replace(/^[=v]+/, ""), optionsOrLoose);
|
|
250
|
-
return s ? s.version : null;
|
|
251
|
-
}
|
|
252
159
|
export class SemVer {
|
|
253
|
-
constructor(version,
|
|
160
|
+
constructor(version, options) {
|
|
254
161
|
Object.defineProperty(this, "raw", {
|
|
255
162
|
enumerable: true,
|
|
256
163
|
configurable: true,
|
|
257
164
|
writable: true,
|
|
258
165
|
value: void 0
|
|
259
166
|
});
|
|
260
|
-
Object.defineProperty(this, "loose", {
|
|
261
|
-
enumerable: true,
|
|
262
|
-
configurable: true,
|
|
263
|
-
writable: true,
|
|
264
|
-
value: void 0
|
|
265
|
-
});
|
|
266
167
|
Object.defineProperty(this, "options", {
|
|
267
168
|
enumerable: true,
|
|
268
169
|
configurable: true,
|
|
@@ -305,19 +206,13 @@ export class SemVer {
|
|
|
305
206
|
writable: true,
|
|
306
207
|
value: void 0
|
|
307
208
|
});
|
|
308
|
-
if (
|
|
309
|
-
|
|
310
|
-
loose: !!optionsOrLoose,
|
|
209
|
+
if (typeof options !== "object") {
|
|
210
|
+
options = {
|
|
311
211
|
includePrerelease: false,
|
|
312
212
|
};
|
|
313
213
|
}
|
|
314
214
|
if (version instanceof SemVer) {
|
|
315
|
-
|
|
316
|
-
return version;
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
version = version.version;
|
|
320
|
-
}
|
|
215
|
+
version = version.version;
|
|
321
216
|
}
|
|
322
217
|
else if (typeof version !== "string") {
|
|
323
218
|
throw new TypeError("Invalid Version: " + version);
|
|
@@ -326,11 +221,10 @@ export class SemVer {
|
|
|
326
221
|
throw new TypeError("version is longer than " + MAX_LENGTH + " characters");
|
|
327
222
|
}
|
|
328
223
|
if (!(this instanceof SemVer)) {
|
|
329
|
-
return new SemVer(version,
|
|
224
|
+
return new SemVer(version, options);
|
|
330
225
|
}
|
|
331
|
-
this.options =
|
|
332
|
-
|
|
333
|
-
const m = version.trim().match(optionsOrLoose.loose ? re[LOOSE] : re[FULL]);
|
|
226
|
+
this.options = options;
|
|
227
|
+
const m = version.trim().match(re[FULL]);
|
|
334
228
|
if (!m) {
|
|
335
229
|
throw new TypeError("Invalid Version: " + version);
|
|
336
230
|
}
|
|
@@ -449,36 +343,36 @@ export class SemVer {
|
|
|
449
343
|
} while (++i);
|
|
450
344
|
return 1;
|
|
451
345
|
}
|
|
452
|
-
|
|
346
|
+
increment(release, identifier) {
|
|
453
347
|
switch (release) {
|
|
454
348
|
case "premajor":
|
|
455
349
|
this.prerelease.length = 0;
|
|
456
350
|
this.patch = 0;
|
|
457
351
|
this.minor = 0;
|
|
458
352
|
this.major++;
|
|
459
|
-
this.
|
|
353
|
+
this.increment("pre", identifier);
|
|
460
354
|
break;
|
|
461
355
|
case "preminor":
|
|
462
356
|
this.prerelease.length = 0;
|
|
463
357
|
this.patch = 0;
|
|
464
358
|
this.minor++;
|
|
465
|
-
this.
|
|
359
|
+
this.increment("pre", identifier);
|
|
466
360
|
break;
|
|
467
361
|
case "prepatch":
|
|
468
362
|
// If this is already a prerelease, it will bump to the next version
|
|
469
363
|
// drop any prereleases that might already exist, since they are not
|
|
470
364
|
// relevant at this point.
|
|
471
365
|
this.prerelease.length = 0;
|
|
472
|
-
this.
|
|
473
|
-
this.
|
|
366
|
+
this.increment("patch", identifier);
|
|
367
|
+
this.increment("pre", identifier);
|
|
474
368
|
break;
|
|
475
369
|
// If the input is a non-prerelease version, this acts the same as
|
|
476
370
|
// prepatch.
|
|
477
371
|
case "prerelease":
|
|
478
372
|
if (this.prerelease.length === 0) {
|
|
479
|
-
this.
|
|
373
|
+
this.increment("patch", identifier);
|
|
480
374
|
}
|
|
481
|
-
this.
|
|
375
|
+
this.increment("pre", identifier);
|
|
482
376
|
break;
|
|
483
377
|
case "major":
|
|
484
378
|
// If this is a pre-major version, bump up to the same major version.
|
|
@@ -525,6 +419,7 @@ export class SemVer {
|
|
|
525
419
|
let i = this.prerelease.length;
|
|
526
420
|
while (--i >= 0) {
|
|
527
421
|
if (typeof this.prerelease[i] === "number") {
|
|
422
|
+
// deno-fmt-ignore
|
|
528
423
|
this.prerelease[i]++;
|
|
529
424
|
i = -2;
|
|
530
425
|
}
|
|
@@ -559,22 +454,36 @@ export class SemVer {
|
|
|
559
454
|
}
|
|
560
455
|
}
|
|
561
456
|
/**
|
|
562
|
-
*
|
|
457
|
+
* Returns the version incremented by the release type
|
|
458
|
+
* (major, minor, patch, or prerelease), or null if it's not valid.
|
|
459
|
+
*
|
|
460
|
+
* `premajor` in one call will bump the version up to the next major version and
|
|
461
|
+
* down to a prerelease of that major version. `preminor`, and `prepatch` work
|
|
462
|
+
* the same way.
|
|
463
|
+
*
|
|
464
|
+
* If called from a non-prerelease version, the `prerelease` will work the same
|
|
465
|
+
* as `prepatch`. It increments the patch version, then makes a prerelease. If
|
|
466
|
+
* the input version is already a prerelease it simply increments it.
|
|
563
467
|
*/
|
|
564
|
-
export function
|
|
565
|
-
if (typeof
|
|
566
|
-
identifier =
|
|
567
|
-
|
|
468
|
+
export function increment(version, release, options, identifier) {
|
|
469
|
+
if (typeof options === "string") {
|
|
470
|
+
identifier = options;
|
|
471
|
+
options = undefined;
|
|
568
472
|
}
|
|
569
473
|
try {
|
|
570
|
-
return new SemVer(version,
|
|
474
|
+
return new SemVer(version, options).increment(release, identifier).version;
|
|
571
475
|
}
|
|
572
|
-
catch
|
|
476
|
+
catch {
|
|
573
477
|
return null;
|
|
574
478
|
}
|
|
575
479
|
}
|
|
576
|
-
|
|
577
|
-
|
|
480
|
+
/**
|
|
481
|
+
* Returns difference between two versions by the release type (`major`,
|
|
482
|
+
* `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`), or
|
|
483
|
+
* null if the versions are the same.
|
|
484
|
+
*/
|
|
485
|
+
export function difference(version1, version2, options) {
|
|
486
|
+
if (eq(version1, version2, options)) {
|
|
578
487
|
return null;
|
|
579
488
|
}
|
|
580
489
|
else {
|
|
@@ -613,67 +522,87 @@ export function compareIdentifiers(a, b) {
|
|
|
613
522
|
export function rcompareIdentifiers(a, b) {
|
|
614
523
|
return compareIdentifiers(b, a);
|
|
615
524
|
}
|
|
616
|
-
/**
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
525
|
+
/** Returns the major version number. */
|
|
526
|
+
export function major(v, options) {
|
|
527
|
+
return new SemVer(v, options).major;
|
|
528
|
+
}
|
|
529
|
+
/** Returns the minor version number. */
|
|
530
|
+
export function minor(v, options) {
|
|
531
|
+
return new SemVer(v, options).minor;
|
|
532
|
+
}
|
|
533
|
+
/** Returns the patch version number. */
|
|
534
|
+
export function patch(v, options) {
|
|
535
|
+
return new SemVer(v, options).patch;
|
|
621
536
|
}
|
|
622
537
|
/**
|
|
623
|
-
*
|
|
538
|
+
* Returns `0` if `v1 == v2`, or `1` if `v1` is greater, or `-1` if `v2` is
|
|
539
|
+
* greater. Sorts in ascending order if passed to `Array.sort()`,
|
|
624
540
|
*/
|
|
625
|
-
export function
|
|
626
|
-
return new SemVer(
|
|
541
|
+
export function compare(v1, v2, options) {
|
|
542
|
+
return new SemVer(v1, options).compare(new SemVer(v2, options));
|
|
627
543
|
}
|
|
628
544
|
/**
|
|
629
|
-
*
|
|
545
|
+
* The same as {@linkcode compare} but considers `build` when two versions are
|
|
546
|
+
* equal. Sorts in ascending order if passed to `Array.sort()`.
|
|
630
547
|
*/
|
|
631
|
-
export function
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
export function compare(v1, v2, optionsOrLoose) {
|
|
635
|
-
return new SemVer(v1, optionsOrLoose).compare(new SemVer(v2, optionsOrLoose));
|
|
636
|
-
}
|
|
637
|
-
export function compareLoose(a, b) {
|
|
638
|
-
return compare(a, b, true);
|
|
639
|
-
}
|
|
640
|
-
export function compareBuild(a, b, loose) {
|
|
641
|
-
var versionA = new SemVer(a, loose);
|
|
642
|
-
var versionB = new SemVer(b, loose);
|
|
548
|
+
export function compareBuild(a, b, options) {
|
|
549
|
+
const versionA = new SemVer(a, options);
|
|
550
|
+
const versionB = new SemVer(b, options);
|
|
643
551
|
return versionA.compare(versionB) || versionA.compareBuild(versionB);
|
|
644
552
|
}
|
|
645
|
-
|
|
646
|
-
|
|
553
|
+
/**
|
|
554
|
+
* Returns `0` if `v1 == v2`, or `-1` if `v1` is greater, or `1` if `v2` is
|
|
555
|
+
* greater. Sorts in descending order if passed to `Array.sort()`,
|
|
556
|
+
*/
|
|
557
|
+
export function rcompare(v1, v2, options) {
|
|
558
|
+
return compare(v2, v1, options);
|
|
647
559
|
}
|
|
648
|
-
export function sort(list,
|
|
560
|
+
export function sort(list, options) {
|
|
649
561
|
return list.sort((a, b) => {
|
|
650
|
-
return compareBuild(a, b,
|
|
562
|
+
return compareBuild(a, b, options);
|
|
651
563
|
});
|
|
652
564
|
}
|
|
653
|
-
export function rsort(list,
|
|
565
|
+
export function rsort(list, options) {
|
|
654
566
|
return list.sort((a, b) => {
|
|
655
|
-
return compareBuild(b, a,
|
|
567
|
+
return compareBuild(b, a, options);
|
|
656
568
|
});
|
|
657
569
|
}
|
|
658
|
-
|
|
659
|
-
|
|
570
|
+
/** Greater than comparison */
|
|
571
|
+
export function gt(v1, v2, options) {
|
|
572
|
+
return compare(v1, v2, options) > 0;
|
|
660
573
|
}
|
|
661
|
-
|
|
662
|
-
|
|
574
|
+
/** Less than comparison */
|
|
575
|
+
export function lt(v1, v2, options) {
|
|
576
|
+
return compare(v1, v2, options) < 0;
|
|
663
577
|
}
|
|
664
|
-
|
|
665
|
-
|
|
578
|
+
/**
|
|
579
|
+
* This is true if they're logically equivalent, even if they're not the exact
|
|
580
|
+
* same string.
|
|
581
|
+
*/
|
|
582
|
+
export function eq(v1, v2, options) {
|
|
583
|
+
return compare(v1, v2, options) === 0;
|
|
666
584
|
}
|
|
667
|
-
|
|
668
|
-
|
|
585
|
+
/**
|
|
586
|
+
* This is true if they're not logically equivalent, even if they're the exact
|
|
587
|
+
* same string.
|
|
588
|
+
*/
|
|
589
|
+
export function neq(v1, v2, options) {
|
|
590
|
+
return compare(v1, v2, options) !== 0;
|
|
669
591
|
}
|
|
670
|
-
|
|
671
|
-
|
|
592
|
+
/** Greater than or equal comparison */
|
|
593
|
+
export function gte(v1, v2, options) {
|
|
594
|
+
return compare(v1, v2, options) >= 0;
|
|
672
595
|
}
|
|
673
|
-
|
|
674
|
-
|
|
596
|
+
/** Less than or equal comparison */
|
|
597
|
+
export function lte(v1, v2, options) {
|
|
598
|
+
return compare(v1, v2, options) <= 0;
|
|
675
599
|
}
|
|
676
|
-
|
|
600
|
+
/**
|
|
601
|
+
* Pass in a comparison string, and it'll call the corresponding comparison
|
|
602
|
+
* function. `"==="` and `"!=="` do simple string comparison, but are included
|
|
603
|
+
* for completeness. Throws if an invalid comparison string is provided.
|
|
604
|
+
*/
|
|
605
|
+
export function cmp(v1, operator, v2, options) {
|
|
677
606
|
switch (operator) {
|
|
678
607
|
case "===":
|
|
679
608
|
if (typeof v1 === "object")
|
|
@@ -690,24 +619,24 @@ export function cmp(v1, operator, v2, optionsOrLoose) {
|
|
|
690
619
|
case "":
|
|
691
620
|
case "=":
|
|
692
621
|
case "==":
|
|
693
|
-
return eq(v1, v2,
|
|
622
|
+
return eq(v1, v2, options);
|
|
694
623
|
case "!=":
|
|
695
|
-
return neq(v1, v2,
|
|
624
|
+
return neq(v1, v2, options);
|
|
696
625
|
case ">":
|
|
697
|
-
return gt(v1, v2,
|
|
626
|
+
return gt(v1, v2, options);
|
|
698
627
|
case ">=":
|
|
699
|
-
return gte(v1, v2,
|
|
628
|
+
return gte(v1, v2, options);
|
|
700
629
|
case "<":
|
|
701
|
-
return lt(v1, v2,
|
|
630
|
+
return lt(v1, v2, options);
|
|
702
631
|
case "<=":
|
|
703
|
-
return lte(v1, v2,
|
|
632
|
+
return lte(v1, v2, options);
|
|
704
633
|
default:
|
|
705
634
|
throw new TypeError("Invalid operator: " + operator);
|
|
706
635
|
}
|
|
707
636
|
}
|
|
708
637
|
const ANY = {};
|
|
709
638
|
export class Comparator {
|
|
710
|
-
constructor(comp,
|
|
639
|
+
constructor(comp, options) {
|
|
711
640
|
Object.defineProperty(this, "semver", {
|
|
712
641
|
enumerable: true,
|
|
713
642
|
configurable: true,
|
|
@@ -726,37 +655,24 @@ export class Comparator {
|
|
|
726
655
|
writable: true,
|
|
727
656
|
value: void 0
|
|
728
657
|
});
|
|
729
|
-
Object.defineProperty(this, "loose", {
|
|
730
|
-
enumerable: true,
|
|
731
|
-
configurable: true,
|
|
732
|
-
writable: true,
|
|
733
|
-
value: void 0
|
|
734
|
-
});
|
|
735
658
|
Object.defineProperty(this, "options", {
|
|
736
659
|
enumerable: true,
|
|
737
660
|
configurable: true,
|
|
738
661
|
writable: true,
|
|
739
662
|
value: void 0
|
|
740
663
|
});
|
|
741
|
-
if (
|
|
742
|
-
|
|
743
|
-
loose: !!optionsOrLoose,
|
|
664
|
+
if (typeof options !== "object") {
|
|
665
|
+
options = {
|
|
744
666
|
includePrerelease: false,
|
|
745
667
|
};
|
|
746
668
|
}
|
|
747
669
|
if (comp instanceof Comparator) {
|
|
748
|
-
|
|
749
|
-
return comp;
|
|
750
|
-
}
|
|
751
|
-
else {
|
|
752
|
-
comp = comp.value;
|
|
753
|
-
}
|
|
670
|
+
return comp;
|
|
754
671
|
}
|
|
755
672
|
if (!(this instanceof Comparator)) {
|
|
756
|
-
return new Comparator(comp,
|
|
673
|
+
return new Comparator(comp, options);
|
|
757
674
|
}
|
|
758
|
-
this.options =
|
|
759
|
-
this.loose = !!optionsOrLoose.loose;
|
|
675
|
+
this.options = options;
|
|
760
676
|
this.parse(comp);
|
|
761
677
|
if (this.semver === ANY) {
|
|
762
678
|
this.value = "";
|
|
@@ -766,7 +682,7 @@ export class Comparator {
|
|
|
766
682
|
}
|
|
767
683
|
}
|
|
768
684
|
parse(comp) {
|
|
769
|
-
const r =
|
|
685
|
+
const r = re[COMPARATOR];
|
|
770
686
|
const m = comp.match(r);
|
|
771
687
|
if (!m) {
|
|
772
688
|
throw new TypeError("Invalid comparator: " + comp);
|
|
@@ -781,7 +697,7 @@ export class Comparator {
|
|
|
781
697
|
this.semver = ANY;
|
|
782
698
|
}
|
|
783
699
|
else {
|
|
784
|
-
this.semver = new SemVer(m[2], this.options
|
|
700
|
+
this.semver = new SemVer(m[2], this.options);
|
|
785
701
|
}
|
|
786
702
|
}
|
|
787
703
|
test(version) {
|
|
@@ -793,13 +709,12 @@ export class Comparator {
|
|
|
793
709
|
}
|
|
794
710
|
return cmp(version, this.operator, this.semver, this.options);
|
|
795
711
|
}
|
|
796
|
-
intersects(comp,
|
|
712
|
+
intersects(comp, options) {
|
|
797
713
|
if (!(comp instanceof Comparator)) {
|
|
798
714
|
throw new TypeError("a Comparator is required");
|
|
799
715
|
}
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
loose: !!optionsOrLoose,
|
|
716
|
+
if (typeof options !== "object") {
|
|
717
|
+
options = {
|
|
803
718
|
includePrerelease: false,
|
|
804
719
|
};
|
|
805
720
|
}
|
|
@@ -808,15 +723,15 @@ export class Comparator {
|
|
|
808
723
|
if (this.value === "") {
|
|
809
724
|
return true;
|
|
810
725
|
}
|
|
811
|
-
rangeTmp = new Range(comp.value,
|
|
812
|
-
return satisfies(this.value, rangeTmp,
|
|
726
|
+
rangeTmp = new Range(comp.value, options);
|
|
727
|
+
return satisfies(this.value, rangeTmp, options);
|
|
813
728
|
}
|
|
814
729
|
else if (comp.operator === "") {
|
|
815
730
|
if (comp.value === "") {
|
|
816
731
|
return true;
|
|
817
732
|
}
|
|
818
|
-
rangeTmp = new Range(this.value,
|
|
819
|
-
return satisfies(comp.semver, rangeTmp,
|
|
733
|
+
rangeTmp = new Range(this.value, options);
|
|
734
|
+
return satisfies(comp.semver, rangeTmp, options);
|
|
820
735
|
}
|
|
821
736
|
const sameDirectionIncreasing = (this.operator === ">=" || this.operator === ">") &&
|
|
822
737
|
(comp.operator === ">=" || comp.operator === ">");
|
|
@@ -825,10 +740,10 @@ export class Comparator {
|
|
|
825
740
|
const sameSemVer = this.semver.version === comp.semver.version;
|
|
826
741
|
const differentDirectionsInclusive = (this.operator === ">=" || this.operator === "<=") &&
|
|
827
742
|
(comp.operator === ">=" || comp.operator === "<=");
|
|
828
|
-
const oppositeDirectionsLessThan = cmp(this.semver, "<", comp.semver,
|
|
743
|
+
const oppositeDirectionsLessThan = cmp(this.semver, "<", comp.semver, options) &&
|
|
829
744
|
(this.operator === ">=" || this.operator === ">") &&
|
|
830
745
|
(comp.operator === "<=" || comp.operator === "<");
|
|
831
|
-
const oppositeDirectionsGreaterThan = cmp(this.semver, ">", comp.semver,
|
|
746
|
+
const oppositeDirectionsGreaterThan = cmp(this.semver, ">", comp.semver, options) &&
|
|
832
747
|
(this.operator === "<=" || this.operator === "<") &&
|
|
833
748
|
(comp.operator === ">=" || comp.operator === ">");
|
|
834
749
|
return (sameDirectionIncreasing ||
|
|
@@ -842,7 +757,7 @@ export class Comparator {
|
|
|
842
757
|
}
|
|
843
758
|
}
|
|
844
759
|
export class Range {
|
|
845
|
-
constructor(range,
|
|
760
|
+
constructor(range, options) {
|
|
846
761
|
Object.defineProperty(this, "range", {
|
|
847
762
|
enumerable: true,
|
|
848
763
|
configurable: true,
|
|
@@ -855,12 +770,6 @@ export class Range {
|
|
|
855
770
|
writable: true,
|
|
856
771
|
value: void 0
|
|
857
772
|
});
|
|
858
|
-
Object.defineProperty(this, "loose", {
|
|
859
|
-
enumerable: true,
|
|
860
|
-
configurable: true,
|
|
861
|
-
writable: true,
|
|
862
|
-
value: void 0
|
|
863
|
-
});
|
|
864
773
|
Object.defineProperty(this, "options", {
|
|
865
774
|
enumerable: true,
|
|
866
775
|
configurable: true,
|
|
@@ -879,30 +788,27 @@ export class Range {
|
|
|
879
788
|
writable: true,
|
|
880
789
|
value: void 0
|
|
881
790
|
});
|
|
882
|
-
if (
|
|
883
|
-
|
|
884
|
-
loose: !!optionsOrLoose,
|
|
791
|
+
if (typeof options !== "object") {
|
|
792
|
+
options = {
|
|
885
793
|
includePrerelease: false,
|
|
886
794
|
};
|
|
887
795
|
}
|
|
888
796
|
if (range instanceof Range) {
|
|
889
|
-
if (range.
|
|
890
|
-
range.includePrerelease === !!optionsOrLoose.includePrerelease) {
|
|
797
|
+
if (range.includePrerelease === !!options.includePrerelease) {
|
|
891
798
|
return range;
|
|
892
799
|
}
|
|
893
800
|
else {
|
|
894
|
-
return new Range(range.raw,
|
|
801
|
+
return new Range(range.raw, options);
|
|
895
802
|
}
|
|
896
803
|
}
|
|
897
804
|
if (range instanceof Comparator) {
|
|
898
|
-
return new Range(range.value,
|
|
805
|
+
return new Range(range.value, options);
|
|
899
806
|
}
|
|
900
807
|
if (!(this instanceof Range)) {
|
|
901
|
-
return new Range(range,
|
|
808
|
+
return new Range(range, options);
|
|
902
809
|
}
|
|
903
|
-
this.options =
|
|
904
|
-
this.
|
|
905
|
-
this.includePrerelease = !!optionsOrLoose.includePrerelease;
|
|
810
|
+
this.options = options;
|
|
811
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
906
812
|
// First, split based on boolean or ||
|
|
907
813
|
this.raw = range;
|
|
908
814
|
this.set = range
|
|
@@ -925,57 +831,43 @@ export class Range {
|
|
|
925
831
|
return this.range;
|
|
926
832
|
}
|
|
927
833
|
parseRange(range) {
|
|
928
|
-
const loose = this.options.loose;
|
|
929
834
|
range = range.trim();
|
|
930
835
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
931
|
-
const hr =
|
|
836
|
+
const hr = re[HYPHENRANGE];
|
|
932
837
|
range = range.replace(hr, hyphenReplace);
|
|
933
|
-
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
934
|
-
range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
|
|
935
|
-
// `~ 1.2.3` => `~1.2.3`
|
|
936
|
-
range = range.replace(re[TILDETRIM], tildeTrimReplace);
|
|
937
|
-
// `^ 1.2.3` => `^1.2.3`
|
|
938
|
-
range = range.replace(re[CARETTRIM], caretTrimReplace);
|
|
939
838
|
// normalize spaces
|
|
940
839
|
range = range.split(/\s+/).join(" ");
|
|
941
840
|
// At this point, the range is completely trimmed and
|
|
942
841
|
// ready to be split into comparators.
|
|
943
|
-
const
|
|
944
|
-
let set = range
|
|
842
|
+
const set = range
|
|
945
843
|
.split(" ")
|
|
946
844
|
.map((comp) => parseComparator(comp, this.options))
|
|
947
845
|
.join(" ")
|
|
948
846
|
.split(/\s+/);
|
|
949
|
-
if (this.options.loose) {
|
|
950
|
-
// in loose mode, throw out any that are not valid comparators
|
|
951
|
-
set = set.filter((comp) => {
|
|
952
|
-
return !!comp.match(compRe);
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
847
|
return set.map((comp) => new Comparator(comp, this.options));
|
|
956
848
|
}
|
|
957
849
|
test(version) {
|
|
958
850
|
if (typeof version === "string") {
|
|
959
851
|
version = new SemVer(version, this.options);
|
|
960
852
|
}
|
|
961
|
-
for (
|
|
853
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
962
854
|
if (testSet(this.set[i], version, this.options)) {
|
|
963
855
|
return true;
|
|
964
856
|
}
|
|
965
857
|
}
|
|
966
858
|
return false;
|
|
967
859
|
}
|
|
968
|
-
intersects(range,
|
|
860
|
+
intersects(range, options) {
|
|
969
861
|
if (!(range instanceof Range)) {
|
|
970
862
|
throw new TypeError("a Range is required");
|
|
971
863
|
}
|
|
972
864
|
return this.set.some((thisComparators) => {
|
|
973
|
-
return (isSatisfiable(thisComparators,
|
|
865
|
+
return (isSatisfiable(thisComparators, options) &&
|
|
974
866
|
range.set.some((rangeComparators) => {
|
|
975
|
-
return (isSatisfiable(rangeComparators,
|
|
867
|
+
return (isSatisfiable(rangeComparators, options) &&
|
|
976
868
|
thisComparators.every((thisComparator) => {
|
|
977
869
|
return rangeComparators.every((rangeComparator) => {
|
|
978
|
-
return thisComparator.intersects(rangeComparator,
|
|
870
|
+
return thisComparator.intersects(rangeComparator, options);
|
|
979
871
|
});
|
|
980
872
|
}));
|
|
981
873
|
}));
|
|
@@ -1030,8 +922,8 @@ function isSatisfiable(comparators, options) {
|
|
|
1030
922
|
return result;
|
|
1031
923
|
}
|
|
1032
924
|
// Mostly just for testing and legacy API reasons
|
|
1033
|
-
export function toComparators(range,
|
|
1034
|
-
return new Range(range,
|
|
925
|
+
export function toComparators(range, options) {
|
|
926
|
+
return new Range(range, options).set.map((comp) => {
|
|
1035
927
|
return comp
|
|
1036
928
|
.map((c) => c.value)
|
|
1037
929
|
.join(" ")
|
|
@@ -1065,8 +957,8 @@ function replaceTildes(comp, options) {
|
|
|
1065
957
|
.map((comp) => replaceTilde(comp, options))
|
|
1066
958
|
.join(" ");
|
|
1067
959
|
}
|
|
1068
|
-
function replaceTilde(comp,
|
|
1069
|
-
const r =
|
|
960
|
+
function replaceTilde(comp, _options) {
|
|
961
|
+
const r = re[TILDE];
|
|
1070
962
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1071
963
|
let ret;
|
|
1072
964
|
if (isX(M)) {
|
|
@@ -1114,8 +1006,8 @@ function replaceCarets(comp, options) {
|
|
|
1114
1006
|
.map((comp) => replaceCaret(comp, options))
|
|
1115
1007
|
.join(" ");
|
|
1116
1008
|
}
|
|
1117
|
-
function replaceCaret(comp,
|
|
1118
|
-
const r =
|
|
1009
|
+
function replaceCaret(comp, _options) {
|
|
1010
|
+
const r = re[CARET];
|
|
1119
1011
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1120
1012
|
let ret;
|
|
1121
1013
|
if (isX(M)) {
|
|
@@ -1194,10 +1086,10 @@ function replaceXRanges(comp, options) {
|
|
|
1194
1086
|
.map((comp) => replaceXRange(comp, options))
|
|
1195
1087
|
.join(" ");
|
|
1196
1088
|
}
|
|
1197
|
-
function replaceXRange(comp,
|
|
1089
|
+
function replaceXRange(comp, _options) {
|
|
1198
1090
|
comp = comp.trim();
|
|
1199
|
-
const r =
|
|
1200
|
-
return comp.replace(r, (ret, gtlt, M, m, p,
|
|
1091
|
+
const r = re[XRANGE];
|
|
1092
|
+
return comp.replace(r, (ret, gtlt, M, m, p, _pr) => {
|
|
1201
1093
|
const xM = isX(M);
|
|
1202
1094
|
const xm = xM || isX(m);
|
|
1203
1095
|
const xp = xm || isX(p);
|
|
@@ -1261,8 +1153,7 @@ function replaceXRange(comp, options) {
|
|
|
1261
1153
|
}
|
|
1262
1154
|
// Because * is AND-ed with everything else in the comparator,
|
|
1263
1155
|
// and '' means "any version", just remove the *s entirely.
|
|
1264
|
-
function replaceStars(comp,
|
|
1265
|
-
// Looseness is ignored here. star is always as loose as it gets!
|
|
1156
|
+
function replaceStars(comp, _options) {
|
|
1266
1157
|
return comp.trim().replace(re[STAR], "");
|
|
1267
1158
|
}
|
|
1268
1159
|
// This function is passed to string.replace(re[HYPHENRANGE])
|
|
@@ -1270,7 +1161,7 @@ function replaceStars(comp, options) {
|
|
|
1270
1161
|
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
1271
1162
|
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
|
1272
1163
|
// 1.2 - 3.4 => >=1.2.0 <3.5.0
|
|
1273
|
-
function hyphenReplace($0, from, fM, fm, fp,
|
|
1164
|
+
function hyphenReplace(_$0, from, fM, fm, fp, _fpr, _fb, to, tM, tm, tp, tpr, _tb) {
|
|
1274
1165
|
if (isX(fM)) {
|
|
1275
1166
|
from = "";
|
|
1276
1167
|
}
|
|
@@ -1300,23 +1191,29 @@ function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
|
|
|
1300
1191
|
}
|
|
1301
1192
|
return (from + " " + to).trim();
|
|
1302
1193
|
}
|
|
1303
|
-
|
|
1194
|
+
/** Returns true if the version satisfies the range. */
|
|
1195
|
+
export function satisfies(version, range, options) {
|
|
1304
1196
|
try {
|
|
1305
|
-
range = new Range(range,
|
|
1197
|
+
range = new Range(range, options);
|
|
1306
1198
|
}
|
|
1307
|
-
catch
|
|
1199
|
+
catch {
|
|
1308
1200
|
return false;
|
|
1309
1201
|
}
|
|
1310
1202
|
return range.test(version);
|
|
1311
1203
|
}
|
|
1312
|
-
|
|
1204
|
+
/**
|
|
1205
|
+
* Returns the highest version in the list that satisfies the range, or `null`
|
|
1206
|
+
* if none of them do.
|
|
1207
|
+
*/
|
|
1208
|
+
export function maxSatisfying(versions, range, options) {
|
|
1313
1209
|
//todo
|
|
1314
|
-
|
|
1315
|
-
|
|
1210
|
+
let max = null;
|
|
1211
|
+
let maxSV = null;
|
|
1212
|
+
let rangeObj;
|
|
1316
1213
|
try {
|
|
1317
|
-
|
|
1214
|
+
rangeObj = new Range(range, options);
|
|
1318
1215
|
}
|
|
1319
|
-
catch
|
|
1216
|
+
catch {
|
|
1320
1217
|
return null;
|
|
1321
1218
|
}
|
|
1322
1219
|
versions.forEach((v) => {
|
|
@@ -1325,20 +1222,25 @@ export function maxSatisfying(versions, range, optionsOrLoose) {
|
|
|
1325
1222
|
if (!max || (maxSV && maxSV.compare(v) === -1)) {
|
|
1326
1223
|
// compare(max, v, true)
|
|
1327
1224
|
max = v;
|
|
1328
|
-
maxSV = new SemVer(max,
|
|
1225
|
+
maxSV = new SemVer(max, options);
|
|
1329
1226
|
}
|
|
1330
1227
|
}
|
|
1331
1228
|
});
|
|
1332
1229
|
return max;
|
|
1333
1230
|
}
|
|
1334
|
-
|
|
1231
|
+
/**
|
|
1232
|
+
* Returns the lowest version in the list that satisfies the range, or `null` if
|
|
1233
|
+
* none of them do.
|
|
1234
|
+
*/
|
|
1235
|
+
export function minSatisfying(versions, range, options) {
|
|
1335
1236
|
//todo
|
|
1336
|
-
|
|
1337
|
-
|
|
1237
|
+
let min = null;
|
|
1238
|
+
let minSV = null;
|
|
1239
|
+
let rangeObj;
|
|
1338
1240
|
try {
|
|
1339
|
-
|
|
1241
|
+
rangeObj = new Range(range, options);
|
|
1340
1242
|
}
|
|
1341
|
-
catch
|
|
1243
|
+
catch {
|
|
1342
1244
|
return null;
|
|
1343
1245
|
}
|
|
1344
1246
|
versions.forEach((v) => {
|
|
@@ -1347,15 +1249,16 @@ export function minSatisfying(versions, range, optionsOrLoose) {
|
|
|
1347
1249
|
if (!min || minSV.compare(v) === 1) {
|
|
1348
1250
|
// compare(min, v, true)
|
|
1349
1251
|
min = v;
|
|
1350
|
-
minSV = new SemVer(min,
|
|
1252
|
+
minSV = new SemVer(min, options);
|
|
1351
1253
|
}
|
|
1352
1254
|
}
|
|
1353
1255
|
});
|
|
1354
1256
|
return min;
|
|
1355
1257
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1258
|
+
/** Returns the lowest version that can possibly match the given range. */
|
|
1259
|
+
export function minVersion(range, options) {
|
|
1260
|
+
range = new Range(range, options);
|
|
1261
|
+
let minver = new SemVer("0.0.0");
|
|
1359
1262
|
if (range.test(minver)) {
|
|
1360
1263
|
return minver;
|
|
1361
1264
|
}
|
|
@@ -1364,11 +1267,11 @@ export function minVersion(range, optionsOrLoose) {
|
|
|
1364
1267
|
return minver;
|
|
1365
1268
|
}
|
|
1366
1269
|
minver = null;
|
|
1367
|
-
for (
|
|
1368
|
-
|
|
1270
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
1271
|
+
const comparators = range.set[i];
|
|
1369
1272
|
comparators.forEach((comparator) => {
|
|
1370
1273
|
// Clone to avoid manipulating the comparator's semver object.
|
|
1371
|
-
|
|
1274
|
+
const compver = new SemVer(comparator.semver.version);
|
|
1372
1275
|
switch (comparator.operator) {
|
|
1373
1276
|
case ">":
|
|
1374
1277
|
if (compver.prerelease.length === 0) {
|
|
@@ -1400,37 +1303,39 @@ export function minVersion(range, optionsOrLoose) {
|
|
|
1400
1303
|
}
|
|
1401
1304
|
return null;
|
|
1402
1305
|
}
|
|
1403
|
-
|
|
1306
|
+
/** Returns the valid range or null if it's not valid. */
|
|
1307
|
+
export function validRange(range, options) {
|
|
1404
1308
|
try {
|
|
1405
1309
|
if (range === null)
|
|
1406
1310
|
return null;
|
|
1407
1311
|
// Return '*' instead of '' so that truthiness works.
|
|
1408
1312
|
// This will throw if it's invalid anyway
|
|
1409
|
-
return new Range(range,
|
|
1313
|
+
return new Range(range, options).range || "*";
|
|
1410
1314
|
}
|
|
1411
|
-
catch
|
|
1315
|
+
catch {
|
|
1412
1316
|
return null;
|
|
1413
1317
|
}
|
|
1414
1318
|
}
|
|
1415
1319
|
/**
|
|
1416
|
-
*
|
|
1320
|
+
* Returns true if version is less than all the versions possible in the range.
|
|
1417
1321
|
*/
|
|
1418
|
-
export function ltr(version, range,
|
|
1419
|
-
return outside(version, range, "<",
|
|
1322
|
+
export function ltr(version, range, options) {
|
|
1323
|
+
return outside(version, range, "<", options);
|
|
1420
1324
|
}
|
|
1421
1325
|
/**
|
|
1422
|
-
*
|
|
1326
|
+
* Returns true if version is greater than all the versions possible in the range.
|
|
1423
1327
|
*/
|
|
1424
|
-
export function gtr(version, range,
|
|
1425
|
-
return outside(version, range, ">",
|
|
1328
|
+
export function gtr(version, range, options) {
|
|
1329
|
+
return outside(version, range, ">", options);
|
|
1426
1330
|
}
|
|
1427
1331
|
/**
|
|
1428
|
-
*
|
|
1429
|
-
* The hilo argument must be either the string '>' or
|
|
1332
|
+
* Returns true if the version is outside the bounds of the range in either the
|
|
1333
|
+
* high or low direction. The hilo argument must be either the string '>' or
|
|
1334
|
+
* '<'. (This is the function called by {@linkcode gtr} and {@linkcode ltr}.)
|
|
1430
1335
|
*/
|
|
1431
|
-
export function outside(version, range, hilo,
|
|
1432
|
-
version = new SemVer(version,
|
|
1433
|
-
range = new Range(range,
|
|
1336
|
+
export function outside(version, range, hilo, options) {
|
|
1337
|
+
version = new SemVer(version, options);
|
|
1338
|
+
range = new Range(range, options);
|
|
1434
1339
|
let gtfn;
|
|
1435
1340
|
let ltefn;
|
|
1436
1341
|
let ltfn;
|
|
@@ -1455,7 +1360,7 @@ export function outside(version, range, hilo, optionsOrLoose) {
|
|
|
1455
1360
|
throw new TypeError('Must provide a hilo val of "<" or ">"');
|
|
1456
1361
|
}
|
|
1457
1362
|
// If it satisifes the range it is not outside
|
|
1458
|
-
if (satisfies(version, range,
|
|
1363
|
+
if (satisfies(version, range, options)) {
|
|
1459
1364
|
return false;
|
|
1460
1365
|
}
|
|
1461
1366
|
// From now on, variable terms are as if we're in "gtr" mode.
|
|
@@ -1470,10 +1375,10 @@ export function outside(version, range, hilo, optionsOrLoose) {
|
|
|
1470
1375
|
}
|
|
1471
1376
|
high = high || comparator;
|
|
1472
1377
|
low = low || comparator;
|
|
1473
|
-
if (gtfn(comparator.semver, high.semver,
|
|
1378
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
1474
1379
|
high = comparator;
|
|
1475
1380
|
}
|
|
1476
|
-
else if (ltfn(comparator.semver, low.semver,
|
|
1381
|
+
else if (ltfn(comparator.semver, low.semver, options)) {
|
|
1477
1382
|
low = comparator;
|
|
1478
1383
|
}
|
|
1479
1384
|
}
|
|
@@ -1496,32 +1401,20 @@ export function outside(version, range, hilo, optionsOrLoose) {
|
|
|
1496
1401
|
}
|
|
1497
1402
|
return true;
|
|
1498
1403
|
}
|
|
1499
|
-
export function prerelease(version, optionsOrLoose) {
|
|
1500
|
-
var parsed = parse(version, optionsOrLoose);
|
|
1501
|
-
return parsed && parsed.prerelease.length ? parsed.prerelease : null;
|
|
1502
|
-
}
|
|
1503
1404
|
/**
|
|
1504
|
-
*
|
|
1405
|
+
* Returns an array of prerelease components, or null if none exist.
|
|
1406
|
+
*
|
|
1407
|
+
* @example
|
|
1408
|
+
* `prerelease("1.2.3-alpha.1") -> ["alpha", 1]`
|
|
1505
1409
|
*/
|
|
1506
|
-
export function
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
return range1.intersects(range2);
|
|
1410
|
+
export function prerelease(version, options) {
|
|
1411
|
+
const parsed = parse(version, options);
|
|
1412
|
+
return parsed && parsed.prerelease.length ? parsed.prerelease : null;
|
|
1510
1413
|
}
|
|
1511
|
-
/**
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
return version;
|
|
1517
|
-
}
|
|
1518
|
-
if (typeof version !== "string") {
|
|
1519
|
-
return null;
|
|
1520
|
-
}
|
|
1521
|
-
const match = version.match(re[COERCE]);
|
|
1522
|
-
if (match == null) {
|
|
1523
|
-
return null;
|
|
1524
|
-
}
|
|
1525
|
-
return parse(match[1] + "." + (match[2] || "0") + "." + (match[3] || "0"), optionsOrLoose);
|
|
1414
|
+
/** Returns true if the two supplied ranges or comparators intersect. */
|
|
1415
|
+
export function intersects(range1, range2, options) {
|
|
1416
|
+
range1 = new Range(range1, options);
|
|
1417
|
+
range2 = new Range(range2, options);
|
|
1418
|
+
return range1.intersects(range2);
|
|
1526
1419
|
}
|
|
1527
1420
|
export default SemVer;
|