@heybox/hb-sdk 0.3.3 → 0.4.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/README.md +63 -28
- package/dist/cli-chunks/browser-RAy8e8cV.cjs +635 -0
- package/dist/cli-chunks/create-D1j9UnM7.cjs +1376 -0
- package/dist/cli-chunks/deploy-CknDDoS_.cjs +3730 -0
- package/dist/cli-chunks/dev-BS9h09yG.cjs +955 -0
- package/dist/cli-chunks/doctor-WTl1HCW0.cjs +186 -0
- package/dist/cli-chunks/index-io4h3kr-.cjs +13348 -0
- package/dist/cli-chunks/index-yjJgBEBF.cjs +64023 -0
- package/dist/cli-chunks/login-B-A53Sta.cjs +193 -0
- package/dist/cli-chunks/session-CMBN3o9z.cjs +3040 -0
- package/dist/cli.cjs +19 -77707
- package/dist/devtools/mock-host/index.html +62 -2
- package/dist/devtools/mock-host/main.js +3246 -20
- package/dist/index.cjs.js +20 -0
- package/dist/index.esm.js +20 -0
- package/dist/miniapp-publish.cjs.js +2810 -4
- package/dist/miniapp-publish.esm.js +2809 -4
- package/dist/protocol.cjs.js +15 -0
- package/dist/protocol.esm.js +15 -1
- package/dist/templates/vue3-vite-ts/README.md.ejs +2 -2
- package/dist/vite.cjs.js +2814 -14
- package/dist/vite.esm.js +2814 -14
- package/package.json +6 -1
- package/skill/SKILL.md +19 -13
- package/skill/references/api-protocol.md +7 -2
- package/skill/references/api-root.md +24 -13
- package/skill/references/cli.md +335 -104
- package/skill/scripts/sync-references.mjs +17 -1
- package/skill/skill.json +4 -4
- package/types/index.d.ts +1 -1
- package/types/miniapp-manifest/schema.d.ts +2 -1
- package/types/miniapp-publish/index.d.ts +2 -1
- package/types/modules/viewport/index.d.ts +33 -0
- package/types/protocol/capabilities.d.ts +17 -2
- package/types/protocol.d.ts +2 -2
|
@@ -0,0 +1,3730 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var childProcess = require('node:child_process');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
|
+
var fs$1 = require('node:fs/promises');
|
|
6
|
+
var path = require('node:path');
|
|
7
|
+
var promises = require('node:readline/promises');
|
|
8
|
+
var session = require('./session-CMBN3o9z.cjs');
|
|
9
|
+
var index = require('./index-io4h3kr-.cjs');
|
|
10
|
+
var node_crypto = require('node:crypto');
|
|
11
|
+
|
|
12
|
+
var re = {exports: {}};
|
|
13
|
+
|
|
14
|
+
var constants;
|
|
15
|
+
var hasRequiredConstants;
|
|
16
|
+
|
|
17
|
+
function requireConstants () {
|
|
18
|
+
if (hasRequiredConstants) return constants;
|
|
19
|
+
hasRequiredConstants = 1;
|
|
20
|
+
|
|
21
|
+
// Note: this is the semver.org version of the spec that it implements
|
|
22
|
+
// Not necessarily the package version of this code.
|
|
23
|
+
const SEMVER_SPEC_VERSION = '2.0.0';
|
|
24
|
+
|
|
25
|
+
const MAX_LENGTH = 256;
|
|
26
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
|
27
|
+
/* istanbul ignore next */ 9007199254740991;
|
|
28
|
+
|
|
29
|
+
// Max safe segment length for coercion.
|
|
30
|
+
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
31
|
+
|
|
32
|
+
// Max safe length for a build identifier. The max length minus 6 characters for
|
|
33
|
+
// the shortest version with a build 0.0.0+BUILD.
|
|
34
|
+
const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
35
|
+
|
|
36
|
+
const RELEASE_TYPES = [
|
|
37
|
+
'major',
|
|
38
|
+
'premajor',
|
|
39
|
+
'minor',
|
|
40
|
+
'preminor',
|
|
41
|
+
'patch',
|
|
42
|
+
'prepatch',
|
|
43
|
+
'prerelease',
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
constants = {
|
|
47
|
+
MAX_LENGTH,
|
|
48
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
49
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
50
|
+
MAX_SAFE_INTEGER,
|
|
51
|
+
RELEASE_TYPES,
|
|
52
|
+
SEMVER_SPEC_VERSION,
|
|
53
|
+
FLAG_INCLUDE_PRERELEASE: 0b001,
|
|
54
|
+
FLAG_LOOSE: 0b010,
|
|
55
|
+
};
|
|
56
|
+
return constants;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var debug_1;
|
|
60
|
+
var hasRequiredDebug;
|
|
61
|
+
|
|
62
|
+
function requireDebug () {
|
|
63
|
+
if (hasRequiredDebug) return debug_1;
|
|
64
|
+
hasRequiredDebug = 1;
|
|
65
|
+
|
|
66
|
+
const debug = (
|
|
67
|
+
typeof process === 'object' &&
|
|
68
|
+
process.env &&
|
|
69
|
+
process.env.NODE_DEBUG &&
|
|
70
|
+
/\bsemver\b/i.test(process.env.NODE_DEBUG)
|
|
71
|
+
) ? (...args) => console.error('SEMVER', ...args)
|
|
72
|
+
: () => {};
|
|
73
|
+
|
|
74
|
+
debug_1 = debug;
|
|
75
|
+
return debug_1;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var hasRequiredRe;
|
|
79
|
+
|
|
80
|
+
function requireRe () {
|
|
81
|
+
if (hasRequiredRe) return re.exports;
|
|
82
|
+
hasRequiredRe = 1;
|
|
83
|
+
(function (module, exports) {
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
87
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
88
|
+
MAX_LENGTH,
|
|
89
|
+
} = requireConstants();
|
|
90
|
+
const debug = requireDebug();
|
|
91
|
+
exports = module.exports = {};
|
|
92
|
+
|
|
93
|
+
// The actual regexps go on exports.re
|
|
94
|
+
const re = exports.re = [];
|
|
95
|
+
const safeRe = exports.safeRe = [];
|
|
96
|
+
const src = exports.src = [];
|
|
97
|
+
const safeSrc = exports.safeSrc = [];
|
|
98
|
+
const t = exports.t = {};
|
|
99
|
+
let R = 0;
|
|
100
|
+
|
|
101
|
+
const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
|
|
102
|
+
|
|
103
|
+
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
|
|
104
|
+
// used internally via the safeRe object since all inputs in this library get
|
|
105
|
+
// normalized first to trim and collapse all extra whitespace. The original
|
|
106
|
+
// regexes are exported for userland consumption and lower level usage. A
|
|
107
|
+
// future breaking change could export the safer regex only with a note that
|
|
108
|
+
// all input should have extra whitespace removed.
|
|
109
|
+
const safeRegexReplacements = [
|
|
110
|
+
['\\s', 1],
|
|
111
|
+
['\\d', MAX_LENGTH],
|
|
112
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
const makeSafeRegex = (value) => {
|
|
116
|
+
for (const [token, max] of safeRegexReplacements) {
|
|
117
|
+
value = value
|
|
118
|
+
.split(`${token}*`).join(`${token}{0,${max}}`)
|
|
119
|
+
.split(`${token}+`).join(`${token}{1,${max}}`);
|
|
120
|
+
}
|
|
121
|
+
return value
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const createToken = (name, value, isGlobal) => {
|
|
125
|
+
const safe = makeSafeRegex(value);
|
|
126
|
+
const index = R++;
|
|
127
|
+
debug(name, index, value);
|
|
128
|
+
t[name] = index;
|
|
129
|
+
src[index] = value;
|
|
130
|
+
safeSrc[index] = safe;
|
|
131
|
+
re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
|
|
132
|
+
safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// The following Regular Expressions can be used for tokenizing,
|
|
136
|
+
// validating, and parsing SemVer version strings.
|
|
137
|
+
|
|
138
|
+
// ## Numeric Identifier
|
|
139
|
+
// A single `0`, or a non-zero digit followed by zero or more digits.
|
|
140
|
+
|
|
141
|
+
createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
|
|
142
|
+
createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
|
|
143
|
+
|
|
144
|
+
// ## Non-numeric Identifier
|
|
145
|
+
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
|
146
|
+
// more letters, digits, or hyphens.
|
|
147
|
+
|
|
148
|
+
createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
149
|
+
|
|
150
|
+
// ## Main Version
|
|
151
|
+
// Three dot-separated numeric identifiers.
|
|
152
|
+
|
|
153
|
+
createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
154
|
+
`(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
155
|
+
`(${src[t.NUMERICIDENTIFIER]})`);
|
|
156
|
+
|
|
157
|
+
createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
158
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
159
|
+
`(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
160
|
+
|
|
161
|
+
// ## Pre-release Version Identifier
|
|
162
|
+
// A numeric identifier, or a non-numeric identifier.
|
|
163
|
+
// Non-numeric identifiers include numeric identifiers but can be longer.
|
|
164
|
+
// Therefore non-numeric identifiers must go first.
|
|
165
|
+
|
|
166
|
+
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
167
|
+
}|${src[t.NUMERICIDENTIFIER]})`);
|
|
168
|
+
|
|
169
|
+
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
170
|
+
}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
171
|
+
|
|
172
|
+
// ## Pre-release Version
|
|
173
|
+
// Hyphen, followed by one or more dot-separated pre-release version
|
|
174
|
+
// identifiers.
|
|
175
|
+
|
|
176
|
+
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
|
|
177
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
178
|
+
|
|
179
|
+
createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
|
|
180
|
+
}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
181
|
+
|
|
182
|
+
// ## Build Metadata Identifier
|
|
183
|
+
// Any combination of digits, letters, or hyphens.
|
|
184
|
+
|
|
185
|
+
createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
|
|
186
|
+
|
|
187
|
+
// ## Build Metadata
|
|
188
|
+
// Plus sign, followed by one or more period-separated build metadata
|
|
189
|
+
// identifiers.
|
|
190
|
+
|
|
191
|
+
createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
|
|
192
|
+
}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
193
|
+
|
|
194
|
+
// ## Full Version String
|
|
195
|
+
// A main version, followed optionally by a pre-release version and
|
|
196
|
+
// build metadata.
|
|
197
|
+
|
|
198
|
+
// Note that the only major, minor, patch, and pre-release sections of
|
|
199
|
+
// the version string are capturing groups. The build metadata is not a
|
|
200
|
+
// capturing group, because it should not ever be used in version
|
|
201
|
+
// comparison.
|
|
202
|
+
|
|
203
|
+
createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
|
|
204
|
+
}${src[t.PRERELEASE]}?${
|
|
205
|
+
src[t.BUILD]}?`);
|
|
206
|
+
|
|
207
|
+
createToken('FULL', `^${src[t.FULLPLAIN]}$`);
|
|
208
|
+
|
|
209
|
+
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
|
210
|
+
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
|
211
|
+
// common in the npm registry.
|
|
212
|
+
createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
|
|
213
|
+
}${src[t.PRERELEASELOOSE]}?${
|
|
214
|
+
src[t.BUILD]}?`);
|
|
215
|
+
|
|
216
|
+
createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
|
|
217
|
+
|
|
218
|
+
createToken('GTLT', '((?:<|>)?=?)');
|
|
219
|
+
|
|
220
|
+
// Something like "2.*" or "1.2.x".
|
|
221
|
+
// Note that "x.x" is a valid xRange identifier, meaning "any version"
|
|
222
|
+
// Only the first item is strictly required.
|
|
223
|
+
createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
224
|
+
createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
225
|
+
|
|
226
|
+
createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
|
|
227
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
228
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
229
|
+
`(?:${src[t.PRERELEASE]})?${
|
|
230
|
+
src[t.BUILD]}?` +
|
|
231
|
+
`)?)?`);
|
|
232
|
+
|
|
233
|
+
createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
234
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
235
|
+
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
236
|
+
`(?:${src[t.PRERELEASELOOSE]})?${
|
|
237
|
+
src[t.BUILD]}?` +
|
|
238
|
+
`)?)?`);
|
|
239
|
+
|
|
240
|
+
createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
241
|
+
createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
242
|
+
|
|
243
|
+
// Coercion.
|
|
244
|
+
// Extract anything that could conceivably be a part of a valid semver
|
|
245
|
+
createToken('COERCEPLAIN', `${'(^|[^\\d])' +
|
|
246
|
+
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
|
|
247
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
|
248
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
249
|
+
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
250
|
+
createToken('COERCEFULL', src[t.COERCEPLAIN] +
|
|
251
|
+
`(?:${src[t.PRERELEASE]})?` +
|
|
252
|
+
`(?:${src[t.BUILD]})?` +
|
|
253
|
+
`(?:$|[^\\d])`);
|
|
254
|
+
createToken('COERCERTL', src[t.COERCE], true);
|
|
255
|
+
createToken('COERCERTLFULL', src[t.COERCEFULL], true);
|
|
256
|
+
|
|
257
|
+
// Tilde ranges.
|
|
258
|
+
// Meaning is "reasonably at or greater than"
|
|
259
|
+
createToken('LONETILDE', '(?:~>?)');
|
|
260
|
+
|
|
261
|
+
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
262
|
+
exports.tildeTrimReplace = '$1~';
|
|
263
|
+
|
|
264
|
+
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
265
|
+
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
266
|
+
|
|
267
|
+
// Caret ranges.
|
|
268
|
+
// Meaning is "at least and backwards compatible with"
|
|
269
|
+
createToken('LONECARET', '(?:\\^)');
|
|
270
|
+
|
|
271
|
+
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
272
|
+
exports.caretTrimReplace = '$1^';
|
|
273
|
+
|
|
274
|
+
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
275
|
+
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
276
|
+
|
|
277
|
+
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
|
278
|
+
createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
279
|
+
createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
280
|
+
|
|
281
|
+
// An expression to strip any whitespace between the gtlt and the thing
|
|
282
|
+
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
283
|
+
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
|
284
|
+
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
285
|
+
exports.comparatorTrimReplace = '$1$2$3';
|
|
286
|
+
|
|
287
|
+
// Something like `1.2.3 - 1.2.4`
|
|
288
|
+
// Note that these all use the loose form, because they'll be
|
|
289
|
+
// checked against either the strict or loose comparator form
|
|
290
|
+
// later.
|
|
291
|
+
createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
|
|
292
|
+
`\\s+-\\s+` +
|
|
293
|
+
`(${src[t.XRANGEPLAIN]})` +
|
|
294
|
+
`\\s*$`);
|
|
295
|
+
|
|
296
|
+
createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
|
|
297
|
+
`\\s+-\\s+` +
|
|
298
|
+
`(${src[t.XRANGEPLAINLOOSE]})` +
|
|
299
|
+
`\\s*$`);
|
|
300
|
+
|
|
301
|
+
// Star ranges basically just allow anything at all.
|
|
302
|
+
createToken('STAR', '(<|>)?=?\\s*\\*');
|
|
303
|
+
// >=0.0.0 is like a star
|
|
304
|
+
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
|
|
305
|
+
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
|
|
306
|
+
} (re, re.exports));
|
|
307
|
+
return re.exports;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var parseOptions_1;
|
|
311
|
+
var hasRequiredParseOptions;
|
|
312
|
+
|
|
313
|
+
function requireParseOptions () {
|
|
314
|
+
if (hasRequiredParseOptions) return parseOptions_1;
|
|
315
|
+
hasRequiredParseOptions = 1;
|
|
316
|
+
|
|
317
|
+
// parse out just the options we care about
|
|
318
|
+
const looseOption = Object.freeze({ loose: true });
|
|
319
|
+
const emptyOpts = Object.freeze({ });
|
|
320
|
+
const parseOptions = options => {
|
|
321
|
+
if (!options) {
|
|
322
|
+
return emptyOpts
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (typeof options !== 'object') {
|
|
326
|
+
return looseOption
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return options
|
|
330
|
+
};
|
|
331
|
+
parseOptions_1 = parseOptions;
|
|
332
|
+
return parseOptions_1;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
var identifiers;
|
|
336
|
+
var hasRequiredIdentifiers;
|
|
337
|
+
|
|
338
|
+
function requireIdentifiers () {
|
|
339
|
+
if (hasRequiredIdentifiers) return identifiers;
|
|
340
|
+
hasRequiredIdentifiers = 1;
|
|
341
|
+
|
|
342
|
+
const numeric = /^[0-9]+$/;
|
|
343
|
+
const compareIdentifiers = (a, b) => {
|
|
344
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
345
|
+
return a === b ? 0 : a < b ? -1 : 1
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const anum = numeric.test(a);
|
|
349
|
+
const bnum = numeric.test(b);
|
|
350
|
+
|
|
351
|
+
if (anum && bnum) {
|
|
352
|
+
a = +a;
|
|
353
|
+
b = +b;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return a === b ? 0
|
|
357
|
+
: (anum && !bnum) ? -1
|
|
358
|
+
: (bnum && !anum) ? 1
|
|
359
|
+
: a < b ? -1
|
|
360
|
+
: 1
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
|
364
|
+
|
|
365
|
+
identifiers = {
|
|
366
|
+
compareIdentifiers,
|
|
367
|
+
rcompareIdentifiers,
|
|
368
|
+
};
|
|
369
|
+
return identifiers;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
var semver$1;
|
|
373
|
+
var hasRequiredSemver$1;
|
|
374
|
+
|
|
375
|
+
function requireSemver$1 () {
|
|
376
|
+
if (hasRequiredSemver$1) return semver$1;
|
|
377
|
+
hasRequiredSemver$1 = 1;
|
|
378
|
+
|
|
379
|
+
const debug = requireDebug();
|
|
380
|
+
const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
|
|
381
|
+
const { safeRe: re, t } = requireRe();
|
|
382
|
+
|
|
383
|
+
const parseOptions = requireParseOptions();
|
|
384
|
+
const { compareIdentifiers } = requireIdentifiers();
|
|
385
|
+
class SemVer {
|
|
386
|
+
constructor (version, options) {
|
|
387
|
+
options = parseOptions(options);
|
|
388
|
+
|
|
389
|
+
if (version instanceof SemVer) {
|
|
390
|
+
if (version.loose === !!options.loose &&
|
|
391
|
+
version.includePrerelease === !!options.includePrerelease) {
|
|
392
|
+
return version
|
|
393
|
+
} else {
|
|
394
|
+
version = version.version;
|
|
395
|
+
}
|
|
396
|
+
} else if (typeof version !== 'string') {
|
|
397
|
+
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (version.length > MAX_LENGTH) {
|
|
401
|
+
throw new TypeError(
|
|
402
|
+
`version is longer than ${MAX_LENGTH} characters`
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
debug('SemVer', version, options);
|
|
407
|
+
this.options = options;
|
|
408
|
+
this.loose = !!options.loose;
|
|
409
|
+
// this isn't actually relevant for versions, but keep it so that we
|
|
410
|
+
// don't run into trouble passing this.options around.
|
|
411
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
412
|
+
|
|
413
|
+
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
|
414
|
+
|
|
415
|
+
if (!m) {
|
|
416
|
+
throw new TypeError(`Invalid Version: ${version}`)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
this.raw = version;
|
|
420
|
+
|
|
421
|
+
// these are actually numbers
|
|
422
|
+
this.major = +m[1];
|
|
423
|
+
this.minor = +m[2];
|
|
424
|
+
this.patch = +m[3];
|
|
425
|
+
|
|
426
|
+
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
427
|
+
throw new TypeError('Invalid major version')
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
431
|
+
throw new TypeError('Invalid minor version')
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
435
|
+
throw new TypeError('Invalid patch version')
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// numberify any prerelease numeric ids
|
|
439
|
+
if (!m[4]) {
|
|
440
|
+
this.prerelease = [];
|
|
441
|
+
} else {
|
|
442
|
+
this.prerelease = m[4].split('.').map((id) => {
|
|
443
|
+
if (/^[0-9]+$/.test(id)) {
|
|
444
|
+
const num = +id;
|
|
445
|
+
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
446
|
+
return num
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return id
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
this.build = m[5] ? m[5].split('.') : [];
|
|
454
|
+
this.format();
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
format () {
|
|
458
|
+
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
|
459
|
+
if (this.prerelease.length) {
|
|
460
|
+
this.version += `-${this.prerelease.join('.')}`;
|
|
461
|
+
}
|
|
462
|
+
return this.version
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
toString () {
|
|
466
|
+
return this.version
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
compare (other) {
|
|
470
|
+
debug('SemVer.compare', this.version, this.options, other);
|
|
471
|
+
if (!(other instanceof SemVer)) {
|
|
472
|
+
if (typeof other === 'string' && other === this.version) {
|
|
473
|
+
return 0
|
|
474
|
+
}
|
|
475
|
+
other = new SemVer(other, this.options);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (other.version === this.version) {
|
|
479
|
+
return 0
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return this.compareMain(other) || this.comparePre(other)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
compareMain (other) {
|
|
486
|
+
if (!(other instanceof SemVer)) {
|
|
487
|
+
other = new SemVer(other, this.options);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
if (this.major < other.major) {
|
|
491
|
+
return -1
|
|
492
|
+
}
|
|
493
|
+
if (this.major > other.major) {
|
|
494
|
+
return 1
|
|
495
|
+
}
|
|
496
|
+
if (this.minor < other.minor) {
|
|
497
|
+
return -1
|
|
498
|
+
}
|
|
499
|
+
if (this.minor > other.minor) {
|
|
500
|
+
return 1
|
|
501
|
+
}
|
|
502
|
+
if (this.patch < other.patch) {
|
|
503
|
+
return -1
|
|
504
|
+
}
|
|
505
|
+
if (this.patch > other.patch) {
|
|
506
|
+
return 1
|
|
507
|
+
}
|
|
508
|
+
return 0
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
comparePre (other) {
|
|
512
|
+
if (!(other instanceof SemVer)) {
|
|
513
|
+
other = new SemVer(other, this.options);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// NOT having a prerelease is > having one
|
|
517
|
+
if (this.prerelease.length && !other.prerelease.length) {
|
|
518
|
+
return -1
|
|
519
|
+
} else if (!this.prerelease.length && other.prerelease.length) {
|
|
520
|
+
return 1
|
|
521
|
+
} else if (!this.prerelease.length && !other.prerelease.length) {
|
|
522
|
+
return 0
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
let i = 0;
|
|
526
|
+
do {
|
|
527
|
+
const a = this.prerelease[i];
|
|
528
|
+
const b = other.prerelease[i];
|
|
529
|
+
debug('prerelease compare', i, a, b);
|
|
530
|
+
if (a === undefined && b === undefined) {
|
|
531
|
+
return 0
|
|
532
|
+
} else if (b === undefined) {
|
|
533
|
+
return 1
|
|
534
|
+
} else if (a === undefined) {
|
|
535
|
+
return -1
|
|
536
|
+
} else if (a === b) {
|
|
537
|
+
continue
|
|
538
|
+
} else {
|
|
539
|
+
return compareIdentifiers(a, b)
|
|
540
|
+
}
|
|
541
|
+
} while (++i)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
compareBuild (other) {
|
|
545
|
+
if (!(other instanceof SemVer)) {
|
|
546
|
+
other = new SemVer(other, this.options);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
let i = 0;
|
|
550
|
+
do {
|
|
551
|
+
const a = this.build[i];
|
|
552
|
+
const b = other.build[i];
|
|
553
|
+
debug('build compare', i, a, b);
|
|
554
|
+
if (a === undefined && b === undefined) {
|
|
555
|
+
return 0
|
|
556
|
+
} else if (b === undefined) {
|
|
557
|
+
return 1
|
|
558
|
+
} else if (a === undefined) {
|
|
559
|
+
return -1
|
|
560
|
+
} else if (a === b) {
|
|
561
|
+
continue
|
|
562
|
+
} else {
|
|
563
|
+
return compareIdentifiers(a, b)
|
|
564
|
+
}
|
|
565
|
+
} while (++i)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// preminor will bump the version up to the next minor release, and immediately
|
|
569
|
+
// down to pre-release. premajor and prepatch work the same way.
|
|
570
|
+
inc (release, identifier, identifierBase) {
|
|
571
|
+
if (release.startsWith('pre')) {
|
|
572
|
+
if (!identifier && identifierBase === false) {
|
|
573
|
+
throw new Error('invalid increment argument: identifier is empty')
|
|
574
|
+
}
|
|
575
|
+
// Avoid an invalid semver results
|
|
576
|
+
if (identifier) {
|
|
577
|
+
const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
|
|
578
|
+
if (!match || match[1] !== identifier) {
|
|
579
|
+
throw new Error(`invalid identifier: ${identifier}`)
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
switch (release) {
|
|
585
|
+
case 'premajor':
|
|
586
|
+
this.prerelease.length = 0;
|
|
587
|
+
this.patch = 0;
|
|
588
|
+
this.minor = 0;
|
|
589
|
+
this.major++;
|
|
590
|
+
this.inc('pre', identifier, identifierBase);
|
|
591
|
+
break
|
|
592
|
+
case 'preminor':
|
|
593
|
+
this.prerelease.length = 0;
|
|
594
|
+
this.patch = 0;
|
|
595
|
+
this.minor++;
|
|
596
|
+
this.inc('pre', identifier, identifierBase);
|
|
597
|
+
break
|
|
598
|
+
case 'prepatch':
|
|
599
|
+
// If this is already a prerelease, it will bump to the next version
|
|
600
|
+
// drop any prereleases that might already exist, since they are not
|
|
601
|
+
// relevant at this point.
|
|
602
|
+
this.prerelease.length = 0;
|
|
603
|
+
this.inc('patch', identifier, identifierBase);
|
|
604
|
+
this.inc('pre', identifier, identifierBase);
|
|
605
|
+
break
|
|
606
|
+
// If the input is a non-prerelease version, this acts the same as
|
|
607
|
+
// prepatch.
|
|
608
|
+
case 'prerelease':
|
|
609
|
+
if (this.prerelease.length === 0) {
|
|
610
|
+
this.inc('patch', identifier, identifierBase);
|
|
611
|
+
}
|
|
612
|
+
this.inc('pre', identifier, identifierBase);
|
|
613
|
+
break
|
|
614
|
+
case 'release':
|
|
615
|
+
if (this.prerelease.length === 0) {
|
|
616
|
+
throw new Error(`version ${this.raw} is not a prerelease`)
|
|
617
|
+
}
|
|
618
|
+
this.prerelease.length = 0;
|
|
619
|
+
break
|
|
620
|
+
|
|
621
|
+
case 'major':
|
|
622
|
+
// If this is a pre-major version, bump up to the same major version.
|
|
623
|
+
// Otherwise increment major.
|
|
624
|
+
// 1.0.0-5 bumps to 1.0.0
|
|
625
|
+
// 1.1.0 bumps to 2.0.0
|
|
626
|
+
if (
|
|
627
|
+
this.minor !== 0 ||
|
|
628
|
+
this.patch !== 0 ||
|
|
629
|
+
this.prerelease.length === 0
|
|
630
|
+
) {
|
|
631
|
+
this.major++;
|
|
632
|
+
}
|
|
633
|
+
this.minor = 0;
|
|
634
|
+
this.patch = 0;
|
|
635
|
+
this.prerelease = [];
|
|
636
|
+
break
|
|
637
|
+
case 'minor':
|
|
638
|
+
// If this is a pre-minor version, bump up to the same minor version.
|
|
639
|
+
// Otherwise increment minor.
|
|
640
|
+
// 1.2.0-5 bumps to 1.2.0
|
|
641
|
+
// 1.2.1 bumps to 1.3.0
|
|
642
|
+
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
643
|
+
this.minor++;
|
|
644
|
+
}
|
|
645
|
+
this.patch = 0;
|
|
646
|
+
this.prerelease = [];
|
|
647
|
+
break
|
|
648
|
+
case 'patch':
|
|
649
|
+
// If this is not a pre-release version, it will increment the patch.
|
|
650
|
+
// If it is a pre-release it will bump up to the same patch version.
|
|
651
|
+
// 1.2.0-5 patches to 1.2.0
|
|
652
|
+
// 1.2.0 patches to 1.2.1
|
|
653
|
+
if (this.prerelease.length === 0) {
|
|
654
|
+
this.patch++;
|
|
655
|
+
}
|
|
656
|
+
this.prerelease = [];
|
|
657
|
+
break
|
|
658
|
+
// This probably shouldn't be used publicly.
|
|
659
|
+
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
|
660
|
+
case 'pre': {
|
|
661
|
+
const base = Number(identifierBase) ? 1 : 0;
|
|
662
|
+
|
|
663
|
+
if (this.prerelease.length === 0) {
|
|
664
|
+
this.prerelease = [base];
|
|
665
|
+
} else {
|
|
666
|
+
let i = this.prerelease.length;
|
|
667
|
+
while (--i >= 0) {
|
|
668
|
+
if (typeof this.prerelease[i] === 'number') {
|
|
669
|
+
this.prerelease[i]++;
|
|
670
|
+
i = -2;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (i === -1) {
|
|
674
|
+
// didn't increment anything
|
|
675
|
+
if (identifier === this.prerelease.join('.') && identifierBase === false) {
|
|
676
|
+
throw new Error('invalid increment argument: identifier already exists')
|
|
677
|
+
}
|
|
678
|
+
this.prerelease.push(base);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (identifier) {
|
|
682
|
+
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
683
|
+
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
684
|
+
let prerelease = [identifier, base];
|
|
685
|
+
if (identifierBase === false) {
|
|
686
|
+
prerelease = [identifier];
|
|
687
|
+
}
|
|
688
|
+
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
689
|
+
if (isNaN(this.prerelease[1])) {
|
|
690
|
+
this.prerelease = prerelease;
|
|
691
|
+
}
|
|
692
|
+
} else {
|
|
693
|
+
this.prerelease = prerelease;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
break
|
|
697
|
+
}
|
|
698
|
+
default:
|
|
699
|
+
throw new Error(`invalid increment argument: ${release}`)
|
|
700
|
+
}
|
|
701
|
+
this.raw = this.format();
|
|
702
|
+
if (this.build.length) {
|
|
703
|
+
this.raw += `+${this.build.join('.')}`;
|
|
704
|
+
}
|
|
705
|
+
return this
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
semver$1 = SemVer;
|
|
710
|
+
return semver$1;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
var parse_1;
|
|
714
|
+
var hasRequiredParse;
|
|
715
|
+
|
|
716
|
+
function requireParse () {
|
|
717
|
+
if (hasRequiredParse) return parse_1;
|
|
718
|
+
hasRequiredParse = 1;
|
|
719
|
+
|
|
720
|
+
const SemVer = requireSemver$1();
|
|
721
|
+
const parse = (version, options, throwErrors = false) => {
|
|
722
|
+
if (version instanceof SemVer) {
|
|
723
|
+
return version
|
|
724
|
+
}
|
|
725
|
+
try {
|
|
726
|
+
return new SemVer(version, options)
|
|
727
|
+
} catch (er) {
|
|
728
|
+
if (!throwErrors) {
|
|
729
|
+
return null
|
|
730
|
+
}
|
|
731
|
+
throw er
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
parse_1 = parse;
|
|
736
|
+
return parse_1;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
var valid_1;
|
|
740
|
+
var hasRequiredValid$1;
|
|
741
|
+
|
|
742
|
+
function requireValid$1 () {
|
|
743
|
+
if (hasRequiredValid$1) return valid_1;
|
|
744
|
+
hasRequiredValid$1 = 1;
|
|
745
|
+
|
|
746
|
+
const parse = requireParse();
|
|
747
|
+
const valid = (version, options) => {
|
|
748
|
+
const v = parse(version, options);
|
|
749
|
+
return v ? v.version : null
|
|
750
|
+
};
|
|
751
|
+
valid_1 = valid;
|
|
752
|
+
return valid_1;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
var clean_1;
|
|
756
|
+
var hasRequiredClean;
|
|
757
|
+
|
|
758
|
+
function requireClean () {
|
|
759
|
+
if (hasRequiredClean) return clean_1;
|
|
760
|
+
hasRequiredClean = 1;
|
|
761
|
+
|
|
762
|
+
const parse = requireParse();
|
|
763
|
+
const clean = (version, options) => {
|
|
764
|
+
const s = parse(version.trim().replace(/^[=v]+/, ''), options);
|
|
765
|
+
return s ? s.version : null
|
|
766
|
+
};
|
|
767
|
+
clean_1 = clean;
|
|
768
|
+
return clean_1;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
var inc_1;
|
|
772
|
+
var hasRequiredInc;
|
|
773
|
+
|
|
774
|
+
function requireInc () {
|
|
775
|
+
if (hasRequiredInc) return inc_1;
|
|
776
|
+
hasRequiredInc = 1;
|
|
777
|
+
|
|
778
|
+
const SemVer = requireSemver$1();
|
|
779
|
+
|
|
780
|
+
const inc = (version, release, options, identifier, identifierBase) => {
|
|
781
|
+
if (typeof (options) === 'string') {
|
|
782
|
+
identifierBase = identifier;
|
|
783
|
+
identifier = options;
|
|
784
|
+
options = undefined;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
try {
|
|
788
|
+
return new SemVer(
|
|
789
|
+
version instanceof SemVer ? version.version : version,
|
|
790
|
+
options
|
|
791
|
+
).inc(release, identifier, identifierBase).version
|
|
792
|
+
} catch (er) {
|
|
793
|
+
return null
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
inc_1 = inc;
|
|
797
|
+
return inc_1;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
var diff_1;
|
|
801
|
+
var hasRequiredDiff;
|
|
802
|
+
|
|
803
|
+
function requireDiff () {
|
|
804
|
+
if (hasRequiredDiff) return diff_1;
|
|
805
|
+
hasRequiredDiff = 1;
|
|
806
|
+
|
|
807
|
+
const parse = requireParse();
|
|
808
|
+
|
|
809
|
+
const diff = (version1, version2) => {
|
|
810
|
+
const v1 = parse(version1, null, true);
|
|
811
|
+
const v2 = parse(version2, null, true);
|
|
812
|
+
const comparison = v1.compare(v2);
|
|
813
|
+
|
|
814
|
+
if (comparison === 0) {
|
|
815
|
+
return null
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
const v1Higher = comparison > 0;
|
|
819
|
+
const highVersion = v1Higher ? v1 : v2;
|
|
820
|
+
const lowVersion = v1Higher ? v2 : v1;
|
|
821
|
+
const highHasPre = !!highVersion.prerelease.length;
|
|
822
|
+
const lowHasPre = !!lowVersion.prerelease.length;
|
|
823
|
+
|
|
824
|
+
if (lowHasPre && !highHasPre) {
|
|
825
|
+
// Going from prerelease -> no prerelease requires some special casing
|
|
826
|
+
|
|
827
|
+
// If the low version has only a major, then it will always be a major
|
|
828
|
+
// Some examples:
|
|
829
|
+
// 1.0.0-1 -> 1.0.0
|
|
830
|
+
// 1.0.0-1 -> 1.1.1
|
|
831
|
+
// 1.0.0-1 -> 2.0.0
|
|
832
|
+
if (!lowVersion.patch && !lowVersion.minor) {
|
|
833
|
+
return 'major'
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
// If the main part has no difference
|
|
837
|
+
if (lowVersion.compareMain(highVersion) === 0) {
|
|
838
|
+
if (lowVersion.minor && !lowVersion.patch) {
|
|
839
|
+
return 'minor'
|
|
840
|
+
}
|
|
841
|
+
return 'patch'
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// add the `pre` prefix if we are going to a prerelease version
|
|
846
|
+
const prefix = highHasPre ? 'pre' : '';
|
|
847
|
+
|
|
848
|
+
if (v1.major !== v2.major) {
|
|
849
|
+
return prefix + 'major'
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (v1.minor !== v2.minor) {
|
|
853
|
+
return prefix + 'minor'
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
if (v1.patch !== v2.patch) {
|
|
857
|
+
return prefix + 'patch'
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// high and low are prereleases
|
|
861
|
+
return 'prerelease'
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
diff_1 = diff;
|
|
865
|
+
return diff_1;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
var major_1;
|
|
869
|
+
var hasRequiredMajor;
|
|
870
|
+
|
|
871
|
+
function requireMajor () {
|
|
872
|
+
if (hasRequiredMajor) return major_1;
|
|
873
|
+
hasRequiredMajor = 1;
|
|
874
|
+
|
|
875
|
+
const SemVer = requireSemver$1();
|
|
876
|
+
const major = (a, loose) => new SemVer(a, loose).major;
|
|
877
|
+
major_1 = major;
|
|
878
|
+
return major_1;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
var minor_1;
|
|
882
|
+
var hasRequiredMinor;
|
|
883
|
+
|
|
884
|
+
function requireMinor () {
|
|
885
|
+
if (hasRequiredMinor) return minor_1;
|
|
886
|
+
hasRequiredMinor = 1;
|
|
887
|
+
|
|
888
|
+
const SemVer = requireSemver$1();
|
|
889
|
+
const minor = (a, loose) => new SemVer(a, loose).minor;
|
|
890
|
+
minor_1 = minor;
|
|
891
|
+
return minor_1;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
var patch_1;
|
|
895
|
+
var hasRequiredPatch;
|
|
896
|
+
|
|
897
|
+
function requirePatch () {
|
|
898
|
+
if (hasRequiredPatch) return patch_1;
|
|
899
|
+
hasRequiredPatch = 1;
|
|
900
|
+
|
|
901
|
+
const SemVer = requireSemver$1();
|
|
902
|
+
const patch = (a, loose) => new SemVer(a, loose).patch;
|
|
903
|
+
patch_1 = patch;
|
|
904
|
+
return patch_1;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
var prerelease_1;
|
|
908
|
+
var hasRequiredPrerelease;
|
|
909
|
+
|
|
910
|
+
function requirePrerelease () {
|
|
911
|
+
if (hasRequiredPrerelease) return prerelease_1;
|
|
912
|
+
hasRequiredPrerelease = 1;
|
|
913
|
+
|
|
914
|
+
const parse = requireParse();
|
|
915
|
+
const prerelease = (version, options) => {
|
|
916
|
+
const parsed = parse(version, options);
|
|
917
|
+
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
|
918
|
+
};
|
|
919
|
+
prerelease_1 = prerelease;
|
|
920
|
+
return prerelease_1;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
var compare_1;
|
|
924
|
+
var hasRequiredCompare;
|
|
925
|
+
|
|
926
|
+
function requireCompare () {
|
|
927
|
+
if (hasRequiredCompare) return compare_1;
|
|
928
|
+
hasRequiredCompare = 1;
|
|
929
|
+
|
|
930
|
+
const SemVer = requireSemver$1();
|
|
931
|
+
const compare = (a, b, loose) =>
|
|
932
|
+
new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
933
|
+
|
|
934
|
+
compare_1 = compare;
|
|
935
|
+
return compare_1;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
var rcompare_1;
|
|
939
|
+
var hasRequiredRcompare;
|
|
940
|
+
|
|
941
|
+
function requireRcompare () {
|
|
942
|
+
if (hasRequiredRcompare) return rcompare_1;
|
|
943
|
+
hasRequiredRcompare = 1;
|
|
944
|
+
|
|
945
|
+
const compare = requireCompare();
|
|
946
|
+
const rcompare = (a, b, loose) => compare(b, a, loose);
|
|
947
|
+
rcompare_1 = rcompare;
|
|
948
|
+
return rcompare_1;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
var compareLoose_1;
|
|
952
|
+
var hasRequiredCompareLoose;
|
|
953
|
+
|
|
954
|
+
function requireCompareLoose () {
|
|
955
|
+
if (hasRequiredCompareLoose) return compareLoose_1;
|
|
956
|
+
hasRequiredCompareLoose = 1;
|
|
957
|
+
|
|
958
|
+
const compare = requireCompare();
|
|
959
|
+
const compareLoose = (a, b) => compare(a, b, true);
|
|
960
|
+
compareLoose_1 = compareLoose;
|
|
961
|
+
return compareLoose_1;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
var compareBuild_1;
|
|
965
|
+
var hasRequiredCompareBuild;
|
|
966
|
+
|
|
967
|
+
function requireCompareBuild () {
|
|
968
|
+
if (hasRequiredCompareBuild) return compareBuild_1;
|
|
969
|
+
hasRequiredCompareBuild = 1;
|
|
970
|
+
|
|
971
|
+
const SemVer = requireSemver$1();
|
|
972
|
+
const compareBuild = (a, b, loose) => {
|
|
973
|
+
const versionA = new SemVer(a, loose);
|
|
974
|
+
const versionB = new SemVer(b, loose);
|
|
975
|
+
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
|
976
|
+
};
|
|
977
|
+
compareBuild_1 = compareBuild;
|
|
978
|
+
return compareBuild_1;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
var sort_1;
|
|
982
|
+
var hasRequiredSort;
|
|
983
|
+
|
|
984
|
+
function requireSort () {
|
|
985
|
+
if (hasRequiredSort) return sort_1;
|
|
986
|
+
hasRequiredSort = 1;
|
|
987
|
+
|
|
988
|
+
const compareBuild = requireCompareBuild();
|
|
989
|
+
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
|
|
990
|
+
sort_1 = sort;
|
|
991
|
+
return sort_1;
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
var rsort_1;
|
|
995
|
+
var hasRequiredRsort;
|
|
996
|
+
|
|
997
|
+
function requireRsort () {
|
|
998
|
+
if (hasRequiredRsort) return rsort_1;
|
|
999
|
+
hasRequiredRsort = 1;
|
|
1000
|
+
|
|
1001
|
+
const compareBuild = requireCompareBuild();
|
|
1002
|
+
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
|
|
1003
|
+
rsort_1 = rsort;
|
|
1004
|
+
return rsort_1;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
var gt_1;
|
|
1008
|
+
var hasRequiredGt;
|
|
1009
|
+
|
|
1010
|
+
function requireGt () {
|
|
1011
|
+
if (hasRequiredGt) return gt_1;
|
|
1012
|
+
hasRequiredGt = 1;
|
|
1013
|
+
|
|
1014
|
+
const compare = requireCompare();
|
|
1015
|
+
const gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
1016
|
+
gt_1 = gt;
|
|
1017
|
+
return gt_1;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
var lt_1;
|
|
1021
|
+
var hasRequiredLt;
|
|
1022
|
+
|
|
1023
|
+
function requireLt () {
|
|
1024
|
+
if (hasRequiredLt) return lt_1;
|
|
1025
|
+
hasRequiredLt = 1;
|
|
1026
|
+
|
|
1027
|
+
const compare = requireCompare();
|
|
1028
|
+
const lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
1029
|
+
lt_1 = lt;
|
|
1030
|
+
return lt_1;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
var eq_1;
|
|
1034
|
+
var hasRequiredEq;
|
|
1035
|
+
|
|
1036
|
+
function requireEq () {
|
|
1037
|
+
if (hasRequiredEq) return eq_1;
|
|
1038
|
+
hasRequiredEq = 1;
|
|
1039
|
+
|
|
1040
|
+
const compare = requireCompare();
|
|
1041
|
+
const eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
1042
|
+
eq_1 = eq;
|
|
1043
|
+
return eq_1;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
var neq_1;
|
|
1047
|
+
var hasRequiredNeq;
|
|
1048
|
+
|
|
1049
|
+
function requireNeq () {
|
|
1050
|
+
if (hasRequiredNeq) return neq_1;
|
|
1051
|
+
hasRequiredNeq = 1;
|
|
1052
|
+
|
|
1053
|
+
const compare = requireCompare();
|
|
1054
|
+
const neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
1055
|
+
neq_1 = neq;
|
|
1056
|
+
return neq_1;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
var gte_1;
|
|
1060
|
+
var hasRequiredGte;
|
|
1061
|
+
|
|
1062
|
+
function requireGte () {
|
|
1063
|
+
if (hasRequiredGte) return gte_1;
|
|
1064
|
+
hasRequiredGte = 1;
|
|
1065
|
+
|
|
1066
|
+
const compare = requireCompare();
|
|
1067
|
+
const gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
1068
|
+
gte_1 = gte;
|
|
1069
|
+
return gte_1;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
var lte_1;
|
|
1073
|
+
var hasRequiredLte;
|
|
1074
|
+
|
|
1075
|
+
function requireLte () {
|
|
1076
|
+
if (hasRequiredLte) return lte_1;
|
|
1077
|
+
hasRequiredLte = 1;
|
|
1078
|
+
|
|
1079
|
+
const compare = requireCompare();
|
|
1080
|
+
const lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
1081
|
+
lte_1 = lte;
|
|
1082
|
+
return lte_1;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
var cmp_1;
|
|
1086
|
+
var hasRequiredCmp;
|
|
1087
|
+
|
|
1088
|
+
function requireCmp () {
|
|
1089
|
+
if (hasRequiredCmp) return cmp_1;
|
|
1090
|
+
hasRequiredCmp = 1;
|
|
1091
|
+
|
|
1092
|
+
const eq = requireEq();
|
|
1093
|
+
const neq = requireNeq();
|
|
1094
|
+
const gt = requireGt();
|
|
1095
|
+
const gte = requireGte();
|
|
1096
|
+
const lt = requireLt();
|
|
1097
|
+
const lte = requireLte();
|
|
1098
|
+
|
|
1099
|
+
const cmp = (a, op, b, loose) => {
|
|
1100
|
+
switch (op) {
|
|
1101
|
+
case '===':
|
|
1102
|
+
if (typeof a === 'object') {
|
|
1103
|
+
a = a.version;
|
|
1104
|
+
}
|
|
1105
|
+
if (typeof b === 'object') {
|
|
1106
|
+
b = b.version;
|
|
1107
|
+
}
|
|
1108
|
+
return a === b
|
|
1109
|
+
|
|
1110
|
+
case '!==':
|
|
1111
|
+
if (typeof a === 'object') {
|
|
1112
|
+
a = a.version;
|
|
1113
|
+
}
|
|
1114
|
+
if (typeof b === 'object') {
|
|
1115
|
+
b = b.version;
|
|
1116
|
+
}
|
|
1117
|
+
return a !== b
|
|
1118
|
+
|
|
1119
|
+
case '':
|
|
1120
|
+
case '=':
|
|
1121
|
+
case '==':
|
|
1122
|
+
return eq(a, b, loose)
|
|
1123
|
+
|
|
1124
|
+
case '!=':
|
|
1125
|
+
return neq(a, b, loose)
|
|
1126
|
+
|
|
1127
|
+
case '>':
|
|
1128
|
+
return gt(a, b, loose)
|
|
1129
|
+
|
|
1130
|
+
case '>=':
|
|
1131
|
+
return gte(a, b, loose)
|
|
1132
|
+
|
|
1133
|
+
case '<':
|
|
1134
|
+
return lt(a, b, loose)
|
|
1135
|
+
|
|
1136
|
+
case '<=':
|
|
1137
|
+
return lte(a, b, loose)
|
|
1138
|
+
|
|
1139
|
+
default:
|
|
1140
|
+
throw new TypeError(`Invalid operator: ${op}`)
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
cmp_1 = cmp;
|
|
1144
|
+
return cmp_1;
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
var coerce_1;
|
|
1148
|
+
var hasRequiredCoerce;
|
|
1149
|
+
|
|
1150
|
+
function requireCoerce () {
|
|
1151
|
+
if (hasRequiredCoerce) return coerce_1;
|
|
1152
|
+
hasRequiredCoerce = 1;
|
|
1153
|
+
|
|
1154
|
+
const SemVer = requireSemver$1();
|
|
1155
|
+
const parse = requireParse();
|
|
1156
|
+
const { safeRe: re, t } = requireRe();
|
|
1157
|
+
|
|
1158
|
+
const coerce = (version, options) => {
|
|
1159
|
+
if (version instanceof SemVer) {
|
|
1160
|
+
return version
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
if (typeof version === 'number') {
|
|
1164
|
+
version = String(version);
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
if (typeof version !== 'string') {
|
|
1168
|
+
return null
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
options = options || {};
|
|
1172
|
+
|
|
1173
|
+
let match = null;
|
|
1174
|
+
if (!options.rtl) {
|
|
1175
|
+
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
|
|
1176
|
+
} else {
|
|
1177
|
+
// Find the right-most coercible string that does not share
|
|
1178
|
+
// a terminus with a more left-ward coercible string.
|
|
1179
|
+
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
|
1180
|
+
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
|
|
1181
|
+
//
|
|
1182
|
+
// Walk through the string checking with a /g regexp
|
|
1183
|
+
// Manually set the index so as to pick up overlapping matches.
|
|
1184
|
+
// Stop when we get a match that ends at the string end, since no
|
|
1185
|
+
// coercible string can be more right-ward without the same terminus.
|
|
1186
|
+
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
|
|
1187
|
+
let next;
|
|
1188
|
+
while ((next = coerceRtlRegex.exec(version)) &&
|
|
1189
|
+
(!match || match.index + match[0].length !== version.length)
|
|
1190
|
+
) {
|
|
1191
|
+
if (!match ||
|
|
1192
|
+
next.index + next[0].length !== match.index + match[0].length) {
|
|
1193
|
+
match = next;
|
|
1194
|
+
}
|
|
1195
|
+
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
|
|
1196
|
+
}
|
|
1197
|
+
// leave it in a clean state
|
|
1198
|
+
coerceRtlRegex.lastIndex = -1;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
if (match === null) {
|
|
1202
|
+
return null
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
const major = match[2];
|
|
1206
|
+
const minor = match[3] || '0';
|
|
1207
|
+
const patch = match[4] || '0';
|
|
1208
|
+
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
|
|
1209
|
+
const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
|
|
1210
|
+
|
|
1211
|
+
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
|
|
1212
|
+
};
|
|
1213
|
+
coerce_1 = coerce;
|
|
1214
|
+
return coerce_1;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
var truncate_1;
|
|
1218
|
+
var hasRequiredTruncate;
|
|
1219
|
+
|
|
1220
|
+
function requireTruncate () {
|
|
1221
|
+
if (hasRequiredTruncate) return truncate_1;
|
|
1222
|
+
hasRequiredTruncate = 1;
|
|
1223
|
+
|
|
1224
|
+
const parse = requireParse();
|
|
1225
|
+
const constants = requireConstants();
|
|
1226
|
+
const SemVer = requireSemver$1();
|
|
1227
|
+
|
|
1228
|
+
const truncate = (version, truncation, options) => {
|
|
1229
|
+
if (!constants.RELEASE_TYPES.includes(truncation)) {
|
|
1230
|
+
return null
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
const clonedVersion = cloneInputVersion(version, options);
|
|
1234
|
+
return clonedVersion && doTruncation(clonedVersion, truncation)
|
|
1235
|
+
};
|
|
1236
|
+
|
|
1237
|
+
const cloneInputVersion = (version, options) => {
|
|
1238
|
+
const versionStringToParse = (
|
|
1239
|
+
version instanceof SemVer ? version.version : version
|
|
1240
|
+
);
|
|
1241
|
+
|
|
1242
|
+
return parse(versionStringToParse, options)
|
|
1243
|
+
};
|
|
1244
|
+
|
|
1245
|
+
const doTruncation = (version, truncation) => {
|
|
1246
|
+
if (isPrerelease(truncation)) {
|
|
1247
|
+
return version.version
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
version.prerelease = [];
|
|
1251
|
+
|
|
1252
|
+
switch (truncation) {
|
|
1253
|
+
case 'major':
|
|
1254
|
+
version.minor = 0;
|
|
1255
|
+
version.patch = 0;
|
|
1256
|
+
break
|
|
1257
|
+
case 'minor':
|
|
1258
|
+
version.patch = 0;
|
|
1259
|
+
break
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
return version.format()
|
|
1263
|
+
};
|
|
1264
|
+
|
|
1265
|
+
const isPrerelease = (type) => {
|
|
1266
|
+
return type.startsWith('pre')
|
|
1267
|
+
};
|
|
1268
|
+
|
|
1269
|
+
truncate_1 = truncate;
|
|
1270
|
+
return truncate_1;
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
var lrucache;
|
|
1274
|
+
var hasRequiredLrucache;
|
|
1275
|
+
|
|
1276
|
+
function requireLrucache () {
|
|
1277
|
+
if (hasRequiredLrucache) return lrucache;
|
|
1278
|
+
hasRequiredLrucache = 1;
|
|
1279
|
+
|
|
1280
|
+
class LRUCache {
|
|
1281
|
+
constructor () {
|
|
1282
|
+
this.max = 1000;
|
|
1283
|
+
this.map = new Map();
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
get (key) {
|
|
1287
|
+
const value = this.map.get(key);
|
|
1288
|
+
if (value === undefined) {
|
|
1289
|
+
return undefined
|
|
1290
|
+
} else {
|
|
1291
|
+
// Remove the key from the map and add it to the end
|
|
1292
|
+
this.map.delete(key);
|
|
1293
|
+
this.map.set(key, value);
|
|
1294
|
+
return value
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
delete (key) {
|
|
1299
|
+
return this.map.delete(key)
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
set (key, value) {
|
|
1303
|
+
const deleted = this.delete(key);
|
|
1304
|
+
|
|
1305
|
+
if (!deleted && value !== undefined) {
|
|
1306
|
+
// If cache is full, delete the least recently used item
|
|
1307
|
+
if (this.map.size >= this.max) {
|
|
1308
|
+
const firstKey = this.map.keys().next().value;
|
|
1309
|
+
this.delete(firstKey);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
this.map.set(key, value);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
return this
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
lrucache = LRUCache;
|
|
1320
|
+
return lrucache;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
var range;
|
|
1324
|
+
var hasRequiredRange;
|
|
1325
|
+
|
|
1326
|
+
function requireRange () {
|
|
1327
|
+
if (hasRequiredRange) return range;
|
|
1328
|
+
hasRequiredRange = 1;
|
|
1329
|
+
|
|
1330
|
+
const SPACE_CHARACTERS = /\s+/g;
|
|
1331
|
+
|
|
1332
|
+
// hoisted class for cyclic dependency
|
|
1333
|
+
class Range {
|
|
1334
|
+
constructor (range, options) {
|
|
1335
|
+
options = parseOptions(options);
|
|
1336
|
+
|
|
1337
|
+
if (range instanceof Range) {
|
|
1338
|
+
if (
|
|
1339
|
+
range.loose === !!options.loose &&
|
|
1340
|
+
range.includePrerelease === !!options.includePrerelease
|
|
1341
|
+
) {
|
|
1342
|
+
return range
|
|
1343
|
+
} else {
|
|
1344
|
+
return new Range(range.raw, options)
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
if (range instanceof Comparator) {
|
|
1349
|
+
// just put it in the set and return
|
|
1350
|
+
this.raw = range.value;
|
|
1351
|
+
this.set = [[range]];
|
|
1352
|
+
this.formatted = undefined;
|
|
1353
|
+
return this
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
this.options = options;
|
|
1357
|
+
this.loose = !!options.loose;
|
|
1358
|
+
this.includePrerelease = !!options.includePrerelease;
|
|
1359
|
+
|
|
1360
|
+
// First reduce all whitespace as much as possible so we do not have to rely
|
|
1361
|
+
// on potentially slow regexes like \s*. This is then stored and used for
|
|
1362
|
+
// future error messages as well.
|
|
1363
|
+
this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
|
|
1364
|
+
|
|
1365
|
+
// First, split on ||
|
|
1366
|
+
this.set = this.raw
|
|
1367
|
+
.split('||')
|
|
1368
|
+
// map the range to a 2d array of comparators
|
|
1369
|
+
.map(r => this.parseRange(r.trim()))
|
|
1370
|
+
// throw out any comparator lists that are empty
|
|
1371
|
+
// this generally means that it was not a valid range, which is allowed
|
|
1372
|
+
// in loose mode, but will still throw if the WHOLE range is invalid.
|
|
1373
|
+
.filter(c => c.length);
|
|
1374
|
+
|
|
1375
|
+
if (!this.set.length) {
|
|
1376
|
+
throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// if we have any that are not the null set, throw out null sets.
|
|
1380
|
+
if (this.set.length > 1) {
|
|
1381
|
+
// keep the first one, in case they're all null sets
|
|
1382
|
+
const first = this.set[0];
|
|
1383
|
+
this.set = this.set.filter(c => !isNullSet(c[0]));
|
|
1384
|
+
if (this.set.length === 0) {
|
|
1385
|
+
this.set = [first];
|
|
1386
|
+
} else if (this.set.length > 1) {
|
|
1387
|
+
// if we have any that are *, then the range is just *
|
|
1388
|
+
for (const c of this.set) {
|
|
1389
|
+
if (c.length === 1 && isAny(c[0])) {
|
|
1390
|
+
this.set = [c];
|
|
1391
|
+
break
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
this.formatted = undefined;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
get range () {
|
|
1401
|
+
if (this.formatted === undefined) {
|
|
1402
|
+
this.formatted = '';
|
|
1403
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1404
|
+
if (i > 0) {
|
|
1405
|
+
this.formatted += '||';
|
|
1406
|
+
}
|
|
1407
|
+
const comps = this.set[i];
|
|
1408
|
+
for (let k = 0; k < comps.length; k++) {
|
|
1409
|
+
if (k > 0) {
|
|
1410
|
+
this.formatted += ' ';
|
|
1411
|
+
}
|
|
1412
|
+
this.formatted += comps[k].toString().trim();
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
return this.formatted
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
format () {
|
|
1420
|
+
return this.range
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
toString () {
|
|
1424
|
+
return this.range
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
parseRange (range) {
|
|
1428
|
+
// strip build metadata so it can't bleed into the version
|
|
1429
|
+
range = range.replace(BUILDSTRIPRE, '');
|
|
1430
|
+
|
|
1431
|
+
// memoize range parsing for performance.
|
|
1432
|
+
// this is a very hot path, and fully deterministic.
|
|
1433
|
+
const memoOpts =
|
|
1434
|
+
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
|
|
1435
|
+
(this.options.loose && FLAG_LOOSE);
|
|
1436
|
+
const memoKey = memoOpts + ':' + range;
|
|
1437
|
+
const cached = cache.get(memoKey);
|
|
1438
|
+
if (cached) {
|
|
1439
|
+
return cached
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
const loose = this.options.loose;
|
|
1443
|
+
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
1444
|
+
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
|
1445
|
+
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
1446
|
+
debug('hyphen replace', range);
|
|
1447
|
+
|
|
1448
|
+
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
1449
|
+
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
1450
|
+
debug('comparator trim', range);
|
|
1451
|
+
|
|
1452
|
+
// `~ 1.2.3` => `~1.2.3`
|
|
1453
|
+
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
1454
|
+
debug('tilde trim', range);
|
|
1455
|
+
|
|
1456
|
+
// `^ 1.2.3` => `^1.2.3`
|
|
1457
|
+
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
|
1458
|
+
debug('caret trim', range);
|
|
1459
|
+
|
|
1460
|
+
// At this point, the range is completely trimmed and
|
|
1461
|
+
// ready to be split into comparators.
|
|
1462
|
+
|
|
1463
|
+
let rangeList = range
|
|
1464
|
+
.split(' ')
|
|
1465
|
+
.map(comp => parseComparator(comp, this.options))
|
|
1466
|
+
.join(' ')
|
|
1467
|
+
.split(/\s+/)
|
|
1468
|
+
// >=0.0.0 is equivalent to *
|
|
1469
|
+
.map(comp => replaceGTE0(comp, this.options));
|
|
1470
|
+
|
|
1471
|
+
if (loose) {
|
|
1472
|
+
// in loose mode, throw out any that are not valid comparators
|
|
1473
|
+
rangeList = rangeList.filter(comp => {
|
|
1474
|
+
debug('loose invalid filter', comp, this.options);
|
|
1475
|
+
return !!comp.match(re[t.COMPARATORLOOSE])
|
|
1476
|
+
});
|
|
1477
|
+
}
|
|
1478
|
+
debug('range list', rangeList);
|
|
1479
|
+
|
|
1480
|
+
// if any comparators are the null set, then replace with JUST null set
|
|
1481
|
+
// if more than one comparator, remove any * comparators
|
|
1482
|
+
// also, don't include the same comparator more than once
|
|
1483
|
+
const rangeMap = new Map();
|
|
1484
|
+
const comparators = rangeList.map(comp => new Comparator(comp, this.options));
|
|
1485
|
+
for (const comp of comparators) {
|
|
1486
|
+
if (isNullSet(comp)) {
|
|
1487
|
+
return [comp]
|
|
1488
|
+
}
|
|
1489
|
+
rangeMap.set(comp.value, comp);
|
|
1490
|
+
}
|
|
1491
|
+
if (rangeMap.size > 1 && rangeMap.has('')) {
|
|
1492
|
+
rangeMap.delete('');
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
const result = [...rangeMap.values()];
|
|
1496
|
+
cache.set(memoKey, result);
|
|
1497
|
+
return result
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
intersects (range, options) {
|
|
1501
|
+
if (!(range instanceof Range)) {
|
|
1502
|
+
throw new TypeError('a Range is required')
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
return this.set.some((thisComparators) => {
|
|
1506
|
+
return (
|
|
1507
|
+
isSatisfiable(thisComparators, options) &&
|
|
1508
|
+
range.set.some((rangeComparators) => {
|
|
1509
|
+
return (
|
|
1510
|
+
isSatisfiable(rangeComparators, options) &&
|
|
1511
|
+
thisComparators.every((thisComparator) => {
|
|
1512
|
+
return rangeComparators.every((rangeComparator) => {
|
|
1513
|
+
return thisComparator.intersects(rangeComparator, options)
|
|
1514
|
+
})
|
|
1515
|
+
})
|
|
1516
|
+
)
|
|
1517
|
+
})
|
|
1518
|
+
)
|
|
1519
|
+
})
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
// if ANY of the sets match ALL of its comparators, then pass
|
|
1523
|
+
test (version) {
|
|
1524
|
+
if (!version) {
|
|
1525
|
+
return false
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
if (typeof version === 'string') {
|
|
1529
|
+
try {
|
|
1530
|
+
version = new SemVer(version, this.options);
|
|
1531
|
+
} catch (er) {
|
|
1532
|
+
return false
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
for (let i = 0; i < this.set.length; i++) {
|
|
1537
|
+
if (testSet(this.set[i], version, this.options)) {
|
|
1538
|
+
return true
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return false
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
range = Range;
|
|
1546
|
+
|
|
1547
|
+
const LRU = requireLrucache();
|
|
1548
|
+
const cache = new LRU();
|
|
1549
|
+
|
|
1550
|
+
const parseOptions = requireParseOptions();
|
|
1551
|
+
const Comparator = requireComparator();
|
|
1552
|
+
const debug = requireDebug();
|
|
1553
|
+
const SemVer = requireSemver$1();
|
|
1554
|
+
const {
|
|
1555
|
+
safeRe: re,
|
|
1556
|
+
src,
|
|
1557
|
+
t,
|
|
1558
|
+
comparatorTrimReplace,
|
|
1559
|
+
tildeTrimReplace,
|
|
1560
|
+
caretTrimReplace,
|
|
1561
|
+
} = requireRe();
|
|
1562
|
+
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = requireConstants();
|
|
1563
|
+
|
|
1564
|
+
// unbounded global build-metadata stripper used by parseRange
|
|
1565
|
+
const BUILDSTRIPRE = new RegExp(src[t.BUILD], 'g');
|
|
1566
|
+
|
|
1567
|
+
const isNullSet = c => c.value === '<0.0.0-0';
|
|
1568
|
+
const isAny = c => c.value === '';
|
|
1569
|
+
|
|
1570
|
+
// take a set of comparators and determine whether there
|
|
1571
|
+
// exists a version which can satisfy it
|
|
1572
|
+
const isSatisfiable = (comparators, options) => {
|
|
1573
|
+
let result = true;
|
|
1574
|
+
const remainingComparators = comparators.slice();
|
|
1575
|
+
let testComparator = remainingComparators.pop();
|
|
1576
|
+
|
|
1577
|
+
while (result && remainingComparators.length) {
|
|
1578
|
+
result = remainingComparators.every((otherComparator) => {
|
|
1579
|
+
return testComparator.intersects(otherComparator, options)
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1582
|
+
testComparator = remainingComparators.pop();
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
return result
|
|
1586
|
+
};
|
|
1587
|
+
|
|
1588
|
+
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
|
1589
|
+
// already replaced the hyphen ranges
|
|
1590
|
+
// turn into a set of JUST comparators.
|
|
1591
|
+
const parseComparator = (comp, options) => {
|
|
1592
|
+
comp = comp.replace(re[t.BUILD], '');
|
|
1593
|
+
debug('comp', comp, options);
|
|
1594
|
+
comp = replaceCarets(comp, options);
|
|
1595
|
+
debug('caret', comp);
|
|
1596
|
+
comp = replaceTildes(comp, options);
|
|
1597
|
+
debug('tildes', comp);
|
|
1598
|
+
comp = replaceXRanges(comp, options);
|
|
1599
|
+
debug('xrange', comp);
|
|
1600
|
+
comp = replaceStars(comp, options);
|
|
1601
|
+
debug('stars', comp);
|
|
1602
|
+
return comp
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
|
1606
|
+
|
|
1607
|
+
// ~, ~> --> * (any, kinda silly)
|
|
1608
|
+
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
1609
|
+
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
1610
|
+
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
|
|
1611
|
+
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
1612
|
+
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
1613
|
+
// ~0.0.1 --> >=0.0.1 <0.1.0-0
|
|
1614
|
+
const replaceTildes = (comp, options) => {
|
|
1615
|
+
return comp
|
|
1616
|
+
.trim()
|
|
1617
|
+
.split(/\s+/)
|
|
1618
|
+
.map((c) => replaceTilde(c, options))
|
|
1619
|
+
.join(' ')
|
|
1620
|
+
};
|
|
1621
|
+
|
|
1622
|
+
const replaceTilde = (comp, options) => {
|
|
1623
|
+
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
1624
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1625
|
+
debug('tilde', comp, _, M, m, p, pr);
|
|
1626
|
+
let ret;
|
|
1627
|
+
|
|
1628
|
+
if (isX(M)) {
|
|
1629
|
+
ret = '';
|
|
1630
|
+
} else if (isX(m)) {
|
|
1631
|
+
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
1632
|
+
} else if (isX(p)) {
|
|
1633
|
+
// ~1.2 == >=1.2.0 <1.3.0-0
|
|
1634
|
+
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
1635
|
+
} else if (pr) {
|
|
1636
|
+
debug('replaceTilde pr', pr);
|
|
1637
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1638
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1639
|
+
} else {
|
|
1640
|
+
// ~1.2.3 == >=1.2.3 <1.3.0-0
|
|
1641
|
+
ret = `>=${M}.${m}.${p
|
|
1642
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
debug('tilde return', ret);
|
|
1646
|
+
return ret
|
|
1647
|
+
})
|
|
1648
|
+
};
|
|
1649
|
+
|
|
1650
|
+
// ^ --> * (any, kinda silly)
|
|
1651
|
+
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
|
1652
|
+
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
|
1653
|
+
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
|
1654
|
+
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
1655
|
+
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
1656
|
+
// ^0.0.1 --> >=0.0.1 <0.0.2-0
|
|
1657
|
+
// ^0.1.0 --> >=0.1.0 <0.2.0-0
|
|
1658
|
+
const replaceCarets = (comp, options) => {
|
|
1659
|
+
return comp
|
|
1660
|
+
.trim()
|
|
1661
|
+
.split(/\s+/)
|
|
1662
|
+
.map((c) => replaceCaret(c, options))
|
|
1663
|
+
.join(' ')
|
|
1664
|
+
};
|
|
1665
|
+
|
|
1666
|
+
const replaceCaret = (comp, options) => {
|
|
1667
|
+
debug('caret', comp, options);
|
|
1668
|
+
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
1669
|
+
const z = options.includePrerelease ? '-0' : '';
|
|
1670
|
+
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1671
|
+
debug('caret', comp, _, M, m, p, pr);
|
|
1672
|
+
let ret;
|
|
1673
|
+
|
|
1674
|
+
if (isX(M)) {
|
|
1675
|
+
ret = '';
|
|
1676
|
+
} else if (isX(m)) {
|
|
1677
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
1678
|
+
} else if (isX(p)) {
|
|
1679
|
+
if (M === '0') {
|
|
1680
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
1681
|
+
} else {
|
|
1682
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
1683
|
+
}
|
|
1684
|
+
} else if (pr) {
|
|
1685
|
+
debug('replaceCaret pr', pr);
|
|
1686
|
+
if (M === '0') {
|
|
1687
|
+
if (m === '0') {
|
|
1688
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1689
|
+
} <${M}.${m}.${+p + 1}-0`;
|
|
1690
|
+
} else {
|
|
1691
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1692
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1693
|
+
}
|
|
1694
|
+
} else {
|
|
1695
|
+
ret = `>=${M}.${m}.${p}-${pr
|
|
1696
|
+
} <${+M + 1}.0.0-0`;
|
|
1697
|
+
}
|
|
1698
|
+
} else {
|
|
1699
|
+
debug('no pr');
|
|
1700
|
+
if (M === '0') {
|
|
1701
|
+
if (m === '0') {
|
|
1702
|
+
ret = `>=${M}.${m}.${p
|
|
1703
|
+
}${z} <${M}.${m}.${+p + 1}-0`;
|
|
1704
|
+
} else {
|
|
1705
|
+
ret = `>=${M}.${m}.${p
|
|
1706
|
+
}${z} <${M}.${+m + 1}.0-0`;
|
|
1707
|
+
}
|
|
1708
|
+
} else {
|
|
1709
|
+
ret = `>=${M}.${m}.${p
|
|
1710
|
+
} <${+M + 1}.0.0-0`;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
|
|
1714
|
+
debug('caret return', ret);
|
|
1715
|
+
return ret
|
|
1716
|
+
})
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1719
|
+
const replaceXRanges = (comp, options) => {
|
|
1720
|
+
debug('replaceXRanges', comp, options);
|
|
1721
|
+
return comp
|
|
1722
|
+
.split(/\s+/)
|
|
1723
|
+
.map((c) => replaceXRange(c, options))
|
|
1724
|
+
.join(' ')
|
|
1725
|
+
};
|
|
1726
|
+
|
|
1727
|
+
const replaceXRange = (comp, options) => {
|
|
1728
|
+
comp = comp.trim();
|
|
1729
|
+
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
1730
|
+
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
1731
|
+
debug('xRange', comp, ret, gtlt, M, m, p, pr);
|
|
1732
|
+
const xM = isX(M);
|
|
1733
|
+
const xm = xM || isX(m);
|
|
1734
|
+
const xp = xm || isX(p);
|
|
1735
|
+
const anyX = xp;
|
|
1736
|
+
|
|
1737
|
+
if (gtlt === '=' && anyX) {
|
|
1738
|
+
gtlt = '';
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// if we're including prereleases in the match, then we need
|
|
1742
|
+
// to fix this to -0, the lowest possible prerelease value
|
|
1743
|
+
pr = options.includePrerelease ? '-0' : '';
|
|
1744
|
+
|
|
1745
|
+
if (xM) {
|
|
1746
|
+
if (gtlt === '>' || gtlt === '<') {
|
|
1747
|
+
// nothing is allowed
|
|
1748
|
+
ret = '<0.0.0-0';
|
|
1749
|
+
} else {
|
|
1750
|
+
// nothing is forbidden
|
|
1751
|
+
ret = '*';
|
|
1752
|
+
}
|
|
1753
|
+
} else if (gtlt && anyX) {
|
|
1754
|
+
// we know patch is an x, because we have any x at all.
|
|
1755
|
+
// replace X with 0
|
|
1756
|
+
if (xm) {
|
|
1757
|
+
m = 0;
|
|
1758
|
+
}
|
|
1759
|
+
p = 0;
|
|
1760
|
+
|
|
1761
|
+
if (gtlt === '>') {
|
|
1762
|
+
// >1 => >=2.0.0
|
|
1763
|
+
// >1.2 => >=1.3.0
|
|
1764
|
+
gtlt = '>=';
|
|
1765
|
+
if (xm) {
|
|
1766
|
+
M = +M + 1;
|
|
1767
|
+
m = 0;
|
|
1768
|
+
p = 0;
|
|
1769
|
+
} else {
|
|
1770
|
+
m = +m + 1;
|
|
1771
|
+
p = 0;
|
|
1772
|
+
}
|
|
1773
|
+
} else if (gtlt === '<=') {
|
|
1774
|
+
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
|
1775
|
+
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
|
1776
|
+
gtlt = '<';
|
|
1777
|
+
if (xm) {
|
|
1778
|
+
M = +M + 1;
|
|
1779
|
+
} else {
|
|
1780
|
+
m = +m + 1;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
if (gtlt === '<') {
|
|
1785
|
+
pr = '-0';
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
|
1789
|
+
} else if (xm) {
|
|
1790
|
+
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
1791
|
+
} else if (xp) {
|
|
1792
|
+
ret = `>=${M}.${m}.0${pr
|
|
1793
|
+
} <${M}.${+m + 1}.0-0`;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
debug('xRange return', ret);
|
|
1797
|
+
|
|
1798
|
+
return ret
|
|
1799
|
+
})
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
// Because * is AND-ed with everything else in the comparator,
|
|
1803
|
+
// and '' means "any version", just remove the *s entirely.
|
|
1804
|
+
const replaceStars = (comp, options) => {
|
|
1805
|
+
debug('replaceStars', comp, options);
|
|
1806
|
+
// Looseness is ignored here. star is always as loose as it gets!
|
|
1807
|
+
return comp
|
|
1808
|
+
.trim()
|
|
1809
|
+
.replace(re[t.STAR], '')
|
|
1810
|
+
};
|
|
1811
|
+
|
|
1812
|
+
const replaceGTE0 = (comp, options) => {
|
|
1813
|
+
debug('replaceGTE0', comp, options);
|
|
1814
|
+
return comp
|
|
1815
|
+
.trim()
|
|
1816
|
+
.replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
|
1820
|
+
// M, m, patch, prerelease, build
|
|
1821
|
+
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
1822
|
+
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
|
|
1823
|
+
// 1.2 - 3.4 => >=1.2.0 <3.5.0-0
|
|
1824
|
+
// TODO build?
|
|
1825
|
+
const hyphenReplace = incPr => ($0,
|
|
1826
|
+
from, fM, fm, fp, fpr, fb,
|
|
1827
|
+
to, tM, tm, tp, tpr) => {
|
|
1828
|
+
if (isX(fM)) {
|
|
1829
|
+
from = '';
|
|
1830
|
+
} else if (isX(fm)) {
|
|
1831
|
+
from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
|
|
1832
|
+
} else if (isX(fp)) {
|
|
1833
|
+
from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
|
|
1834
|
+
} else if (fpr) {
|
|
1835
|
+
from = `>=${from}`;
|
|
1836
|
+
} else {
|
|
1837
|
+
from = `>=${from}${incPr ? '-0' : ''}`;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
if (isX(tM)) {
|
|
1841
|
+
to = '';
|
|
1842
|
+
} else if (isX(tm)) {
|
|
1843
|
+
to = `<${+tM + 1}.0.0-0`;
|
|
1844
|
+
} else if (isX(tp)) {
|
|
1845
|
+
to = `<${tM}.${+tm + 1}.0-0`;
|
|
1846
|
+
} else if (tpr) {
|
|
1847
|
+
to = `<=${tM}.${tm}.${tp}-${tpr}`;
|
|
1848
|
+
} else if (incPr) {
|
|
1849
|
+
to = `<${tM}.${tm}.${+tp + 1}-0`;
|
|
1850
|
+
} else {
|
|
1851
|
+
to = `<=${to}`;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
return `${from} ${to}`.trim()
|
|
1855
|
+
};
|
|
1856
|
+
|
|
1857
|
+
const testSet = (set, version, options) => {
|
|
1858
|
+
for (let i = 0; i < set.length; i++) {
|
|
1859
|
+
if (!set[i].test(version)) {
|
|
1860
|
+
return false
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
if (version.prerelease.length && !options.includePrerelease) {
|
|
1865
|
+
// Find the set of versions that are allowed to have prereleases
|
|
1866
|
+
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
|
1867
|
+
// That should allow `1.2.3-pr.2` to pass.
|
|
1868
|
+
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
|
1869
|
+
// even though it's within the range set by the comparators.
|
|
1870
|
+
for (let i = 0; i < set.length; i++) {
|
|
1871
|
+
debug(set[i].semver);
|
|
1872
|
+
if (set[i].semver === Comparator.ANY) {
|
|
1873
|
+
continue
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
if (set[i].semver.prerelease.length > 0) {
|
|
1877
|
+
const allowed = set[i].semver;
|
|
1878
|
+
if (allowed.major === version.major &&
|
|
1879
|
+
allowed.minor === version.minor &&
|
|
1880
|
+
allowed.patch === version.patch) {
|
|
1881
|
+
return true
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
// Version has a -pre, but it's not one of the ones we like.
|
|
1887
|
+
return false
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
return true
|
|
1891
|
+
};
|
|
1892
|
+
return range;
|
|
1893
|
+
}
|
|
1894
|
+
|
|
1895
|
+
var comparator;
|
|
1896
|
+
var hasRequiredComparator;
|
|
1897
|
+
|
|
1898
|
+
function requireComparator () {
|
|
1899
|
+
if (hasRequiredComparator) return comparator;
|
|
1900
|
+
hasRequiredComparator = 1;
|
|
1901
|
+
|
|
1902
|
+
const ANY = Symbol('SemVer ANY');
|
|
1903
|
+
// hoisted class for cyclic dependency
|
|
1904
|
+
class Comparator {
|
|
1905
|
+
static get ANY () {
|
|
1906
|
+
return ANY
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
constructor (comp, options) {
|
|
1910
|
+
options = parseOptions(options);
|
|
1911
|
+
|
|
1912
|
+
if (comp instanceof Comparator) {
|
|
1913
|
+
if (comp.loose === !!options.loose) {
|
|
1914
|
+
return comp
|
|
1915
|
+
} else {
|
|
1916
|
+
comp = comp.value;
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
comp = comp.trim().split(/\s+/).join(' ');
|
|
1921
|
+
debug('comparator', comp, options);
|
|
1922
|
+
this.options = options;
|
|
1923
|
+
this.loose = !!options.loose;
|
|
1924
|
+
this.parse(comp);
|
|
1925
|
+
|
|
1926
|
+
if (this.semver === ANY) {
|
|
1927
|
+
this.value = '';
|
|
1928
|
+
} else {
|
|
1929
|
+
this.value = this.operator + this.semver.version;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
debug('comp', this);
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
parse (comp) {
|
|
1936
|
+
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
|
1937
|
+
const m = comp.match(r);
|
|
1938
|
+
|
|
1939
|
+
if (!m) {
|
|
1940
|
+
throw new TypeError(`Invalid comparator: ${comp}`)
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
this.operator = m[1] !== undefined ? m[1] : '';
|
|
1944
|
+
if (this.operator === '=') {
|
|
1945
|
+
this.operator = '';
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
// if it literally is just '>' or '' then allow anything.
|
|
1949
|
+
if (!m[2]) {
|
|
1950
|
+
this.semver = ANY;
|
|
1951
|
+
} else {
|
|
1952
|
+
this.semver = new SemVer(m[2], this.options.loose);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
toString () {
|
|
1957
|
+
return this.value
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
test (version) {
|
|
1961
|
+
debug('Comparator.test', version, this.options.loose);
|
|
1962
|
+
|
|
1963
|
+
if (this.semver === ANY || version === ANY) {
|
|
1964
|
+
return true
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
if (typeof version === 'string') {
|
|
1968
|
+
try {
|
|
1969
|
+
version = new SemVer(version, this.options);
|
|
1970
|
+
} catch (er) {
|
|
1971
|
+
return false
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
return cmp(version, this.operator, this.semver, this.options)
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
intersects (comp, options) {
|
|
1979
|
+
if (!(comp instanceof Comparator)) {
|
|
1980
|
+
throw new TypeError('a Comparator is required')
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
if (this.operator === '') {
|
|
1984
|
+
if (this.value === '') {
|
|
1985
|
+
return true
|
|
1986
|
+
}
|
|
1987
|
+
return new Range(comp.value, options).test(this.value)
|
|
1988
|
+
} else if (comp.operator === '') {
|
|
1989
|
+
if (comp.value === '') {
|
|
1990
|
+
return true
|
|
1991
|
+
}
|
|
1992
|
+
return new Range(this.value, options).test(comp.semver)
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
options = parseOptions(options);
|
|
1996
|
+
|
|
1997
|
+
// Special cases where nothing can possibly be lower
|
|
1998
|
+
if (options.includePrerelease &&
|
|
1999
|
+
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
|
|
2000
|
+
return false
|
|
2001
|
+
}
|
|
2002
|
+
if (!options.includePrerelease &&
|
|
2003
|
+
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
|
|
2004
|
+
return false
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
// Same direction increasing (> or >=)
|
|
2008
|
+
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
|
|
2009
|
+
return true
|
|
2010
|
+
}
|
|
2011
|
+
// Same direction decreasing (< or <=)
|
|
2012
|
+
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
|
|
2013
|
+
return true
|
|
2014
|
+
}
|
|
2015
|
+
// same SemVer and both sides are inclusive (<= or >=)
|
|
2016
|
+
if (
|
|
2017
|
+
(this.semver.version === comp.semver.version) &&
|
|
2018
|
+
this.operator.includes('=') && comp.operator.includes('=')) {
|
|
2019
|
+
return true
|
|
2020
|
+
}
|
|
2021
|
+
// opposite directions less than
|
|
2022
|
+
if (cmp(this.semver, '<', comp.semver, options) &&
|
|
2023
|
+
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
|
|
2024
|
+
return true
|
|
2025
|
+
}
|
|
2026
|
+
// opposite directions greater than
|
|
2027
|
+
if (cmp(this.semver, '>', comp.semver, options) &&
|
|
2028
|
+
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
|
|
2029
|
+
return true
|
|
2030
|
+
}
|
|
2031
|
+
return false
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
comparator = Comparator;
|
|
2036
|
+
|
|
2037
|
+
const parseOptions = requireParseOptions();
|
|
2038
|
+
const { safeRe: re, t } = requireRe();
|
|
2039
|
+
const cmp = requireCmp();
|
|
2040
|
+
const debug = requireDebug();
|
|
2041
|
+
const SemVer = requireSemver$1();
|
|
2042
|
+
const Range = requireRange();
|
|
2043
|
+
return comparator;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
var satisfies_1;
|
|
2047
|
+
var hasRequiredSatisfies;
|
|
2048
|
+
|
|
2049
|
+
function requireSatisfies () {
|
|
2050
|
+
if (hasRequiredSatisfies) return satisfies_1;
|
|
2051
|
+
hasRequiredSatisfies = 1;
|
|
2052
|
+
|
|
2053
|
+
const Range = requireRange();
|
|
2054
|
+
const satisfies = (version, range, options) => {
|
|
2055
|
+
try {
|
|
2056
|
+
range = new Range(range, options);
|
|
2057
|
+
} catch (er) {
|
|
2058
|
+
return false
|
|
2059
|
+
}
|
|
2060
|
+
return range.test(version)
|
|
2061
|
+
};
|
|
2062
|
+
satisfies_1 = satisfies;
|
|
2063
|
+
return satisfies_1;
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
var toComparators_1;
|
|
2067
|
+
var hasRequiredToComparators;
|
|
2068
|
+
|
|
2069
|
+
function requireToComparators () {
|
|
2070
|
+
if (hasRequiredToComparators) return toComparators_1;
|
|
2071
|
+
hasRequiredToComparators = 1;
|
|
2072
|
+
|
|
2073
|
+
const Range = requireRange();
|
|
2074
|
+
|
|
2075
|
+
// Mostly just for testing and legacy API reasons
|
|
2076
|
+
const toComparators = (range, options) =>
|
|
2077
|
+
new Range(range, options).set
|
|
2078
|
+
.map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
|
|
2079
|
+
|
|
2080
|
+
toComparators_1 = toComparators;
|
|
2081
|
+
return toComparators_1;
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
var maxSatisfying_1;
|
|
2085
|
+
var hasRequiredMaxSatisfying;
|
|
2086
|
+
|
|
2087
|
+
function requireMaxSatisfying () {
|
|
2088
|
+
if (hasRequiredMaxSatisfying) return maxSatisfying_1;
|
|
2089
|
+
hasRequiredMaxSatisfying = 1;
|
|
2090
|
+
|
|
2091
|
+
const SemVer = requireSemver$1();
|
|
2092
|
+
const Range = requireRange();
|
|
2093
|
+
|
|
2094
|
+
const maxSatisfying = (versions, range, options) => {
|
|
2095
|
+
let max = null;
|
|
2096
|
+
let maxSV = null;
|
|
2097
|
+
let rangeObj = null;
|
|
2098
|
+
try {
|
|
2099
|
+
rangeObj = new Range(range, options);
|
|
2100
|
+
} catch (er) {
|
|
2101
|
+
return null
|
|
2102
|
+
}
|
|
2103
|
+
versions.forEach((v) => {
|
|
2104
|
+
if (rangeObj.test(v)) {
|
|
2105
|
+
// satisfies(v, range, options)
|
|
2106
|
+
if (!max || maxSV.compare(v) === -1) {
|
|
2107
|
+
// compare(max, v, true)
|
|
2108
|
+
max = v;
|
|
2109
|
+
maxSV = new SemVer(max, options);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
});
|
|
2113
|
+
return max
|
|
2114
|
+
};
|
|
2115
|
+
maxSatisfying_1 = maxSatisfying;
|
|
2116
|
+
return maxSatisfying_1;
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
var minSatisfying_1;
|
|
2120
|
+
var hasRequiredMinSatisfying;
|
|
2121
|
+
|
|
2122
|
+
function requireMinSatisfying () {
|
|
2123
|
+
if (hasRequiredMinSatisfying) return minSatisfying_1;
|
|
2124
|
+
hasRequiredMinSatisfying = 1;
|
|
2125
|
+
|
|
2126
|
+
const SemVer = requireSemver$1();
|
|
2127
|
+
const Range = requireRange();
|
|
2128
|
+
const minSatisfying = (versions, range, options) => {
|
|
2129
|
+
let min = null;
|
|
2130
|
+
let minSV = null;
|
|
2131
|
+
let rangeObj = null;
|
|
2132
|
+
try {
|
|
2133
|
+
rangeObj = new Range(range, options);
|
|
2134
|
+
} catch (er) {
|
|
2135
|
+
return null
|
|
2136
|
+
}
|
|
2137
|
+
versions.forEach((v) => {
|
|
2138
|
+
if (rangeObj.test(v)) {
|
|
2139
|
+
// satisfies(v, range, options)
|
|
2140
|
+
if (!min || minSV.compare(v) === 1) {
|
|
2141
|
+
// compare(min, v, true)
|
|
2142
|
+
min = v;
|
|
2143
|
+
minSV = new SemVer(min, options);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
});
|
|
2147
|
+
return min
|
|
2148
|
+
};
|
|
2149
|
+
minSatisfying_1 = minSatisfying;
|
|
2150
|
+
return minSatisfying_1;
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
var minVersion_1;
|
|
2154
|
+
var hasRequiredMinVersion;
|
|
2155
|
+
|
|
2156
|
+
function requireMinVersion () {
|
|
2157
|
+
if (hasRequiredMinVersion) return minVersion_1;
|
|
2158
|
+
hasRequiredMinVersion = 1;
|
|
2159
|
+
|
|
2160
|
+
const SemVer = requireSemver$1();
|
|
2161
|
+
const Range = requireRange();
|
|
2162
|
+
const gt = requireGt();
|
|
2163
|
+
|
|
2164
|
+
const minVersion = (range, loose) => {
|
|
2165
|
+
range = new Range(range, loose);
|
|
2166
|
+
|
|
2167
|
+
let minver = new SemVer('0.0.0');
|
|
2168
|
+
if (range.test(minver)) {
|
|
2169
|
+
return minver
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
minver = new SemVer('0.0.0-0');
|
|
2173
|
+
if (range.test(minver)) {
|
|
2174
|
+
return minver
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
minver = null;
|
|
2178
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
2179
|
+
const comparators = range.set[i];
|
|
2180
|
+
|
|
2181
|
+
let setMin = null;
|
|
2182
|
+
comparators.forEach((comparator) => {
|
|
2183
|
+
// Clone to avoid manipulating the comparator's semver object.
|
|
2184
|
+
const compver = new SemVer(comparator.semver.version);
|
|
2185
|
+
switch (comparator.operator) {
|
|
2186
|
+
case '>':
|
|
2187
|
+
if (compver.prerelease.length === 0) {
|
|
2188
|
+
compver.patch++;
|
|
2189
|
+
} else {
|
|
2190
|
+
compver.prerelease.push(0);
|
|
2191
|
+
}
|
|
2192
|
+
compver.raw = compver.format();
|
|
2193
|
+
/* fallthrough */
|
|
2194
|
+
case '':
|
|
2195
|
+
case '>=':
|
|
2196
|
+
if (!setMin || gt(compver, setMin)) {
|
|
2197
|
+
setMin = compver;
|
|
2198
|
+
}
|
|
2199
|
+
break
|
|
2200
|
+
case '<':
|
|
2201
|
+
case '<=':
|
|
2202
|
+
/* Ignore maximum versions */
|
|
2203
|
+
break
|
|
2204
|
+
/* istanbul ignore next */
|
|
2205
|
+
default:
|
|
2206
|
+
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
|
2207
|
+
}
|
|
2208
|
+
});
|
|
2209
|
+
if (setMin && (!minver || gt(minver, setMin))) {
|
|
2210
|
+
minver = setMin;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
if (minver && range.test(minver)) {
|
|
2215
|
+
return minver
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
return null
|
|
2219
|
+
};
|
|
2220
|
+
minVersion_1 = minVersion;
|
|
2221
|
+
return minVersion_1;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
var valid;
|
|
2225
|
+
var hasRequiredValid;
|
|
2226
|
+
|
|
2227
|
+
function requireValid () {
|
|
2228
|
+
if (hasRequiredValid) return valid;
|
|
2229
|
+
hasRequiredValid = 1;
|
|
2230
|
+
|
|
2231
|
+
const Range = requireRange();
|
|
2232
|
+
const validRange = (range, options) => {
|
|
2233
|
+
try {
|
|
2234
|
+
// Return '*' instead of '' so that truthiness works.
|
|
2235
|
+
// This will throw if it's invalid anyway
|
|
2236
|
+
return new Range(range, options).range || '*'
|
|
2237
|
+
} catch (er) {
|
|
2238
|
+
return null
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
valid = validRange;
|
|
2242
|
+
return valid;
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
var outside_1;
|
|
2246
|
+
var hasRequiredOutside;
|
|
2247
|
+
|
|
2248
|
+
function requireOutside () {
|
|
2249
|
+
if (hasRequiredOutside) return outside_1;
|
|
2250
|
+
hasRequiredOutside = 1;
|
|
2251
|
+
|
|
2252
|
+
const SemVer = requireSemver$1();
|
|
2253
|
+
const Comparator = requireComparator();
|
|
2254
|
+
const { ANY } = Comparator;
|
|
2255
|
+
const Range = requireRange();
|
|
2256
|
+
const satisfies = requireSatisfies();
|
|
2257
|
+
const gt = requireGt();
|
|
2258
|
+
const lt = requireLt();
|
|
2259
|
+
const lte = requireLte();
|
|
2260
|
+
const gte = requireGte();
|
|
2261
|
+
|
|
2262
|
+
const outside = (version, range, hilo, options) => {
|
|
2263
|
+
version = new SemVer(version, options);
|
|
2264
|
+
range = new Range(range, options);
|
|
2265
|
+
|
|
2266
|
+
let gtfn, ltefn, ltfn, comp, ecomp;
|
|
2267
|
+
switch (hilo) {
|
|
2268
|
+
case '>':
|
|
2269
|
+
gtfn = gt;
|
|
2270
|
+
ltefn = lte;
|
|
2271
|
+
ltfn = lt;
|
|
2272
|
+
comp = '>';
|
|
2273
|
+
ecomp = '>=';
|
|
2274
|
+
break
|
|
2275
|
+
case '<':
|
|
2276
|
+
gtfn = lt;
|
|
2277
|
+
ltefn = gte;
|
|
2278
|
+
ltfn = gt;
|
|
2279
|
+
comp = '<';
|
|
2280
|
+
ecomp = '<=';
|
|
2281
|
+
break
|
|
2282
|
+
default:
|
|
2283
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
// If it satisfies the range it is not outside
|
|
2287
|
+
if (satisfies(version, range, options)) {
|
|
2288
|
+
return false
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// From now on, variable terms are as if we're in "gtr" mode.
|
|
2292
|
+
// but note that everything is flipped for the "ltr" function.
|
|
2293
|
+
|
|
2294
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
2295
|
+
const comparators = range.set[i];
|
|
2296
|
+
|
|
2297
|
+
let high = null;
|
|
2298
|
+
let low = null;
|
|
2299
|
+
|
|
2300
|
+
comparators.forEach((comparator) => {
|
|
2301
|
+
if (comparator.semver === ANY) {
|
|
2302
|
+
comparator = new Comparator('>=0.0.0');
|
|
2303
|
+
}
|
|
2304
|
+
high = high || comparator;
|
|
2305
|
+
low = low || comparator;
|
|
2306
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
2307
|
+
high = comparator;
|
|
2308
|
+
} else if (ltfn(comparator.semver, low.semver, options)) {
|
|
2309
|
+
low = comparator;
|
|
2310
|
+
}
|
|
2311
|
+
});
|
|
2312
|
+
|
|
2313
|
+
// If the edge version comparator has a operator then our version
|
|
2314
|
+
// isn't outside it
|
|
2315
|
+
if (high.operator === comp || high.operator === ecomp) {
|
|
2316
|
+
return false
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
// If the lowest version comparator has an operator and our version
|
|
2320
|
+
// is less than it then it isn't higher than the range
|
|
2321
|
+
if ((!low.operator || low.operator === comp) &&
|
|
2322
|
+
ltefn(version, low.semver)) {
|
|
2323
|
+
return false
|
|
2324
|
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
2325
|
+
return false
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
return true
|
|
2329
|
+
};
|
|
2330
|
+
|
|
2331
|
+
outside_1 = outside;
|
|
2332
|
+
return outside_1;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
var gtr_1;
|
|
2336
|
+
var hasRequiredGtr;
|
|
2337
|
+
|
|
2338
|
+
function requireGtr () {
|
|
2339
|
+
if (hasRequiredGtr) return gtr_1;
|
|
2340
|
+
hasRequiredGtr = 1;
|
|
2341
|
+
|
|
2342
|
+
// Determine if version is greater than all the versions possible in the range.
|
|
2343
|
+
const outside = requireOutside();
|
|
2344
|
+
const gtr = (version, range, options) => outside(version, range, '>', options);
|
|
2345
|
+
gtr_1 = gtr;
|
|
2346
|
+
return gtr_1;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
var ltr_1;
|
|
2350
|
+
var hasRequiredLtr;
|
|
2351
|
+
|
|
2352
|
+
function requireLtr () {
|
|
2353
|
+
if (hasRequiredLtr) return ltr_1;
|
|
2354
|
+
hasRequiredLtr = 1;
|
|
2355
|
+
|
|
2356
|
+
const outside = requireOutside();
|
|
2357
|
+
// Determine if version is less than all the versions possible in the range
|
|
2358
|
+
const ltr = (version, range, options) => outside(version, range, '<', options);
|
|
2359
|
+
ltr_1 = ltr;
|
|
2360
|
+
return ltr_1;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
var intersects_1;
|
|
2364
|
+
var hasRequiredIntersects;
|
|
2365
|
+
|
|
2366
|
+
function requireIntersects () {
|
|
2367
|
+
if (hasRequiredIntersects) return intersects_1;
|
|
2368
|
+
hasRequiredIntersects = 1;
|
|
2369
|
+
|
|
2370
|
+
const Range = requireRange();
|
|
2371
|
+
const intersects = (r1, r2, options) => {
|
|
2372
|
+
r1 = new Range(r1, options);
|
|
2373
|
+
r2 = new Range(r2, options);
|
|
2374
|
+
return r1.intersects(r2, options)
|
|
2375
|
+
};
|
|
2376
|
+
intersects_1 = intersects;
|
|
2377
|
+
return intersects_1;
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
var simplify;
|
|
2381
|
+
var hasRequiredSimplify;
|
|
2382
|
+
|
|
2383
|
+
function requireSimplify () {
|
|
2384
|
+
if (hasRequiredSimplify) return simplify;
|
|
2385
|
+
hasRequiredSimplify = 1;
|
|
2386
|
+
|
|
2387
|
+
// given a set of versions and a range, create a "simplified" range
|
|
2388
|
+
// that includes the same versions that the original range does
|
|
2389
|
+
// If the original range is shorter than the simplified one, return that.
|
|
2390
|
+
const satisfies = requireSatisfies();
|
|
2391
|
+
const compare = requireCompare();
|
|
2392
|
+
simplify = (versions, range, options) => {
|
|
2393
|
+
const set = [];
|
|
2394
|
+
let first = null;
|
|
2395
|
+
let prev = null;
|
|
2396
|
+
const v = versions.sort((a, b) => compare(a, b, options));
|
|
2397
|
+
for (const version of v) {
|
|
2398
|
+
const included = satisfies(version, range, options);
|
|
2399
|
+
if (included) {
|
|
2400
|
+
prev = version;
|
|
2401
|
+
if (!first) {
|
|
2402
|
+
first = version;
|
|
2403
|
+
}
|
|
2404
|
+
} else {
|
|
2405
|
+
if (prev) {
|
|
2406
|
+
set.push([first, prev]);
|
|
2407
|
+
}
|
|
2408
|
+
prev = null;
|
|
2409
|
+
first = null;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
if (first) {
|
|
2413
|
+
set.push([first, null]);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
const ranges = [];
|
|
2417
|
+
for (const [min, max] of set) {
|
|
2418
|
+
if (min === max) {
|
|
2419
|
+
ranges.push(min);
|
|
2420
|
+
} else if (!max && min === v[0]) {
|
|
2421
|
+
ranges.push('*');
|
|
2422
|
+
} else if (!max) {
|
|
2423
|
+
ranges.push(`>=${min}`);
|
|
2424
|
+
} else if (min === v[0]) {
|
|
2425
|
+
ranges.push(`<=${max}`);
|
|
2426
|
+
} else {
|
|
2427
|
+
ranges.push(`${min} - ${max}`);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
const simplified = ranges.join(' || ');
|
|
2431
|
+
const original = typeof range.raw === 'string' ? range.raw : String(range);
|
|
2432
|
+
return simplified.length < original.length ? simplified : range
|
|
2433
|
+
};
|
|
2434
|
+
return simplify;
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
var subset_1;
|
|
2438
|
+
var hasRequiredSubset;
|
|
2439
|
+
|
|
2440
|
+
function requireSubset () {
|
|
2441
|
+
if (hasRequiredSubset) return subset_1;
|
|
2442
|
+
hasRequiredSubset = 1;
|
|
2443
|
+
|
|
2444
|
+
const Range = requireRange();
|
|
2445
|
+
const Comparator = requireComparator();
|
|
2446
|
+
const { ANY } = Comparator;
|
|
2447
|
+
const satisfies = requireSatisfies();
|
|
2448
|
+
const compare = requireCompare();
|
|
2449
|
+
|
|
2450
|
+
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
|
2451
|
+
// - Every simple range `r1, r2, ...` is a null set, OR
|
|
2452
|
+
// - Every simple range `r1, r2, ...` which is not a null set is a subset of
|
|
2453
|
+
// some `R1, R2, ...`
|
|
2454
|
+
//
|
|
2455
|
+
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
|
2456
|
+
// - If c is only the ANY comparator
|
|
2457
|
+
// - If C is only the ANY comparator, return true
|
|
2458
|
+
// - Else if in prerelease mode, return false
|
|
2459
|
+
// - else replace c with `[>=0.0.0]`
|
|
2460
|
+
// - If C is only the ANY comparator
|
|
2461
|
+
// - if in prerelease mode, return true
|
|
2462
|
+
// - else replace C with `[>=0.0.0]`
|
|
2463
|
+
// - Let EQ be the set of = comparators in c
|
|
2464
|
+
// - If EQ is more than one, return true (null set)
|
|
2465
|
+
// - Let GT be the highest > or >= comparator in c
|
|
2466
|
+
// - Let LT be the lowest < or <= comparator in c
|
|
2467
|
+
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
|
2468
|
+
// - If any C is a = range, and GT or LT are set, return false
|
|
2469
|
+
// - If EQ
|
|
2470
|
+
// - If GT, and EQ does not satisfy GT, return true (null set)
|
|
2471
|
+
// - If LT, and EQ does not satisfy LT, return true (null set)
|
|
2472
|
+
// - If EQ satisfies every C, return true
|
|
2473
|
+
// - Else return false
|
|
2474
|
+
// - If GT
|
|
2475
|
+
// - If GT.semver is lower than any > or >= comp in C, return false
|
|
2476
|
+
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
|
2477
|
+
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
2478
|
+
// - If no C has a prerelease and the GT.semver tuple, return false
|
|
2479
|
+
// - If LT
|
|
2480
|
+
// - If LT.semver is greater than any < or <= comp in C, return false
|
|
2481
|
+
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
|
2482
|
+
// - If LT.semver has a prerelease, and not in prerelease mode
|
|
2483
|
+
// - If no C has a prerelease and the LT.semver tuple, return false
|
|
2484
|
+
// - Else return true
|
|
2485
|
+
|
|
2486
|
+
const subset = (sub, dom, options = {}) => {
|
|
2487
|
+
if (sub === dom) {
|
|
2488
|
+
return true
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
sub = new Range(sub, options);
|
|
2492
|
+
dom = new Range(dom, options);
|
|
2493
|
+
let sawNonNull = false;
|
|
2494
|
+
|
|
2495
|
+
OUTER: for (const simpleSub of sub.set) {
|
|
2496
|
+
for (const simpleDom of dom.set) {
|
|
2497
|
+
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
|
2498
|
+
sawNonNull = sawNonNull || isSub !== null;
|
|
2499
|
+
if (isSub) {
|
|
2500
|
+
continue OUTER
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
// the null set is a subset of everything, but null simple ranges in
|
|
2504
|
+
// a complex range should be ignored. so if we saw a non-null range,
|
|
2505
|
+
// then we know this isn't a subset, but if EVERY simple range was null,
|
|
2506
|
+
// then it is a subset.
|
|
2507
|
+
if (sawNonNull) {
|
|
2508
|
+
return false
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
return true
|
|
2512
|
+
};
|
|
2513
|
+
|
|
2514
|
+
const minimumVersionWithPreRelease = [new Comparator('>=0.0.0-0')];
|
|
2515
|
+
const minimumVersion = [new Comparator('>=0.0.0')];
|
|
2516
|
+
|
|
2517
|
+
const simpleSubset = (sub, dom, options) => {
|
|
2518
|
+
if (sub === dom) {
|
|
2519
|
+
return true
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
2523
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2524
|
+
return true
|
|
2525
|
+
} else if (options.includePrerelease) {
|
|
2526
|
+
sub = minimumVersionWithPreRelease;
|
|
2527
|
+
} else {
|
|
2528
|
+
sub = minimumVersion;
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2533
|
+
if (options.includePrerelease) {
|
|
2534
|
+
return true
|
|
2535
|
+
} else {
|
|
2536
|
+
dom = minimumVersion;
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
const eqSet = new Set();
|
|
2541
|
+
let gt, lt;
|
|
2542
|
+
for (const c of sub) {
|
|
2543
|
+
if (c.operator === '>' || c.operator === '>=') {
|
|
2544
|
+
gt = higherGT(gt, c, options);
|
|
2545
|
+
} else if (c.operator === '<' || c.operator === '<=') {
|
|
2546
|
+
lt = lowerLT(lt, c, options);
|
|
2547
|
+
} else {
|
|
2548
|
+
eqSet.add(c.semver);
|
|
2549
|
+
}
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
if (eqSet.size > 1) {
|
|
2553
|
+
return null
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
let gtltComp;
|
|
2557
|
+
if (gt && lt) {
|
|
2558
|
+
gtltComp = compare(gt.semver, lt.semver, options);
|
|
2559
|
+
if (gtltComp > 0) {
|
|
2560
|
+
return null
|
|
2561
|
+
} else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
|
|
2562
|
+
return null
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
// will iterate one or zero times
|
|
2567
|
+
for (const eq of eqSet) {
|
|
2568
|
+
if (gt && !satisfies(eq, String(gt), options)) {
|
|
2569
|
+
return null
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
if (lt && !satisfies(eq, String(lt), options)) {
|
|
2573
|
+
return null
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
for (const c of dom) {
|
|
2577
|
+
if (!satisfies(eq, String(c), options)) {
|
|
2578
|
+
return false
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
return true
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
let higher, lower;
|
|
2586
|
+
let hasDomLT, hasDomGT;
|
|
2587
|
+
// if the subset has a prerelease, we need a comparator in the superset
|
|
2588
|
+
// with the same tuple and a prerelease, or it's not a subset
|
|
2589
|
+
let needDomLTPre = lt &&
|
|
2590
|
+
!options.includePrerelease &&
|
|
2591
|
+
lt.semver.prerelease.length ? lt.semver : false;
|
|
2592
|
+
let needDomGTPre = gt &&
|
|
2593
|
+
!options.includePrerelease &&
|
|
2594
|
+
gt.semver.prerelease.length ? gt.semver : false;
|
|
2595
|
+
// exception: <1.2.3-0 is the same as <1.2.3
|
|
2596
|
+
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
|
2597
|
+
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
|
2598
|
+
needDomLTPre = false;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
for (const c of dom) {
|
|
2602
|
+
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
|
|
2603
|
+
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
|
|
2604
|
+
if (gt) {
|
|
2605
|
+
if (needDomGTPre) {
|
|
2606
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2607
|
+
c.semver.major === needDomGTPre.major &&
|
|
2608
|
+
c.semver.minor === needDomGTPre.minor &&
|
|
2609
|
+
c.semver.patch === needDomGTPre.patch) {
|
|
2610
|
+
needDomGTPre = false;
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
if (c.operator === '>' || c.operator === '>=') {
|
|
2614
|
+
higher = higherGT(gt, c, options);
|
|
2615
|
+
if (higher === c && higher !== gt) {
|
|
2616
|
+
return false
|
|
2617
|
+
}
|
|
2618
|
+
} else if (gt.operator === '>=' && !c.test(gt.semver)) {
|
|
2619
|
+
return false
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
if (lt) {
|
|
2623
|
+
if (needDomLTPre) {
|
|
2624
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2625
|
+
c.semver.major === needDomLTPre.major &&
|
|
2626
|
+
c.semver.minor === needDomLTPre.minor &&
|
|
2627
|
+
c.semver.patch === needDomLTPre.patch) {
|
|
2628
|
+
needDomLTPre = false;
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
if (c.operator === '<' || c.operator === '<=') {
|
|
2632
|
+
lower = lowerLT(lt, c, options);
|
|
2633
|
+
if (lower === c && lower !== lt) {
|
|
2634
|
+
return false
|
|
2635
|
+
}
|
|
2636
|
+
} else if (lt.operator === '<=' && !c.test(lt.semver)) {
|
|
2637
|
+
return false
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
2641
|
+
return false
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
// if there was a < or >, and nothing in the dom, then must be false
|
|
2646
|
+
// UNLESS it was limited by another range in the other direction.
|
|
2647
|
+
// Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
|
|
2648
|
+
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
|
2649
|
+
return false
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
|
2653
|
+
return false
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
// we needed a prerelease range in a specific tuple, but didn't get one
|
|
2657
|
+
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
|
2658
|
+
// because it includes prereleases in the 1.2.3 tuple
|
|
2659
|
+
if (needDomGTPre || needDomLTPre) {
|
|
2660
|
+
return false
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
return true
|
|
2664
|
+
};
|
|
2665
|
+
|
|
2666
|
+
// >=1.2.3 is lower than >1.2.3
|
|
2667
|
+
const higherGT = (a, b, options) => {
|
|
2668
|
+
if (!a) {
|
|
2669
|
+
return b
|
|
2670
|
+
}
|
|
2671
|
+
const comp = compare(a.semver, b.semver, options);
|
|
2672
|
+
return comp > 0 ? a
|
|
2673
|
+
: comp < 0 ? b
|
|
2674
|
+
: b.operator === '>' && a.operator === '>=' ? b
|
|
2675
|
+
: a
|
|
2676
|
+
};
|
|
2677
|
+
|
|
2678
|
+
// <=1.2.3 is higher than <1.2.3
|
|
2679
|
+
const lowerLT = (a, b, options) => {
|
|
2680
|
+
if (!a) {
|
|
2681
|
+
return b
|
|
2682
|
+
}
|
|
2683
|
+
const comp = compare(a.semver, b.semver, options);
|
|
2684
|
+
return comp < 0 ? a
|
|
2685
|
+
: comp > 0 ? b
|
|
2686
|
+
: b.operator === '<' && a.operator === '<=' ? b
|
|
2687
|
+
: a
|
|
2688
|
+
};
|
|
2689
|
+
|
|
2690
|
+
subset_1 = subset;
|
|
2691
|
+
return subset_1;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
var semver;
|
|
2695
|
+
var hasRequiredSemver;
|
|
2696
|
+
|
|
2697
|
+
function requireSemver () {
|
|
2698
|
+
if (hasRequiredSemver) return semver;
|
|
2699
|
+
hasRequiredSemver = 1;
|
|
2700
|
+
|
|
2701
|
+
// just pre-load all the stuff that index.js lazily exports
|
|
2702
|
+
const internalRe = requireRe();
|
|
2703
|
+
const constants = requireConstants();
|
|
2704
|
+
const SemVer = requireSemver$1();
|
|
2705
|
+
const identifiers = requireIdentifiers();
|
|
2706
|
+
const parse = requireParse();
|
|
2707
|
+
const valid = requireValid$1();
|
|
2708
|
+
const clean = requireClean();
|
|
2709
|
+
const inc = requireInc();
|
|
2710
|
+
const diff = requireDiff();
|
|
2711
|
+
const major = requireMajor();
|
|
2712
|
+
const minor = requireMinor();
|
|
2713
|
+
const patch = requirePatch();
|
|
2714
|
+
const prerelease = requirePrerelease();
|
|
2715
|
+
const compare = requireCompare();
|
|
2716
|
+
const rcompare = requireRcompare();
|
|
2717
|
+
const compareLoose = requireCompareLoose();
|
|
2718
|
+
const compareBuild = requireCompareBuild();
|
|
2719
|
+
const sort = requireSort();
|
|
2720
|
+
const rsort = requireRsort();
|
|
2721
|
+
const gt = requireGt();
|
|
2722
|
+
const lt = requireLt();
|
|
2723
|
+
const eq = requireEq();
|
|
2724
|
+
const neq = requireNeq();
|
|
2725
|
+
const gte = requireGte();
|
|
2726
|
+
const lte = requireLte();
|
|
2727
|
+
const cmp = requireCmp();
|
|
2728
|
+
const coerce = requireCoerce();
|
|
2729
|
+
const truncate = requireTruncate();
|
|
2730
|
+
const Comparator = requireComparator();
|
|
2731
|
+
const Range = requireRange();
|
|
2732
|
+
const satisfies = requireSatisfies();
|
|
2733
|
+
const toComparators = requireToComparators();
|
|
2734
|
+
const maxSatisfying = requireMaxSatisfying();
|
|
2735
|
+
const minSatisfying = requireMinSatisfying();
|
|
2736
|
+
const minVersion = requireMinVersion();
|
|
2737
|
+
const validRange = requireValid();
|
|
2738
|
+
const outside = requireOutside();
|
|
2739
|
+
const gtr = requireGtr();
|
|
2740
|
+
const ltr = requireLtr();
|
|
2741
|
+
const intersects = requireIntersects();
|
|
2742
|
+
const simplifyRange = requireSimplify();
|
|
2743
|
+
const subset = requireSubset();
|
|
2744
|
+
semver = {
|
|
2745
|
+
parse,
|
|
2746
|
+
valid,
|
|
2747
|
+
clean,
|
|
2748
|
+
inc,
|
|
2749
|
+
diff,
|
|
2750
|
+
major,
|
|
2751
|
+
minor,
|
|
2752
|
+
patch,
|
|
2753
|
+
prerelease,
|
|
2754
|
+
compare,
|
|
2755
|
+
rcompare,
|
|
2756
|
+
compareLoose,
|
|
2757
|
+
compareBuild,
|
|
2758
|
+
sort,
|
|
2759
|
+
rsort,
|
|
2760
|
+
gt,
|
|
2761
|
+
lt,
|
|
2762
|
+
eq,
|
|
2763
|
+
neq,
|
|
2764
|
+
gte,
|
|
2765
|
+
lte,
|
|
2766
|
+
cmp,
|
|
2767
|
+
coerce,
|
|
2768
|
+
truncate,
|
|
2769
|
+
Comparator,
|
|
2770
|
+
Range,
|
|
2771
|
+
satisfies,
|
|
2772
|
+
toComparators,
|
|
2773
|
+
maxSatisfying,
|
|
2774
|
+
minSatisfying,
|
|
2775
|
+
minVersion,
|
|
2776
|
+
validRange,
|
|
2777
|
+
outside,
|
|
2778
|
+
gtr,
|
|
2779
|
+
ltr,
|
|
2780
|
+
intersects,
|
|
2781
|
+
simplifyRange,
|
|
2782
|
+
subset,
|
|
2783
|
+
SemVer,
|
|
2784
|
+
re: internalRe.re,
|
|
2785
|
+
src: internalRe.src,
|
|
2786
|
+
tokens: internalRe.t,
|
|
2787
|
+
SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
|
|
2788
|
+
RELEASE_TYPES: constants.RELEASE_TYPES,
|
|
2789
|
+
compareIdentifiers: identifiers.compareIdentifiers,
|
|
2790
|
+
rcompareIdentifiers: identifiers.rcompareIdentifiers,
|
|
2791
|
+
};
|
|
2792
|
+
return semver;
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
var semverExports = requireSemver();
|
|
2796
|
+
|
|
2797
|
+
function isValidMiniappManifestVersion(version) {
|
|
2798
|
+
return getMiniappManifestVersionError(version) === undefined;
|
|
2799
|
+
}
|
|
2800
|
+
function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version') {
|
|
2801
|
+
const error = getMiniappManifestVersionError(version);
|
|
2802
|
+
if (error) {
|
|
2803
|
+
throw new Error(`${sourceLabel} ${error}`);
|
|
2804
|
+
}
|
|
2805
|
+
return String(version).trim();
|
|
2806
|
+
}
|
|
2807
|
+
function parseMiniappManifestJson(raw, sourceLabel = 'manifest.json') {
|
|
2808
|
+
const hadBom = raw.charCodeAt(0) === 0xfeff;
|
|
2809
|
+
const text = hadBom ? raw.slice(1) : raw;
|
|
2810
|
+
let parsed;
|
|
2811
|
+
try {
|
|
2812
|
+
parsed = JSON.parse(text);
|
|
2813
|
+
}
|
|
2814
|
+
catch (error) {
|
|
2815
|
+
throw new Error(`${sourceLabel} 不是合法 JSON:${formatReason(error)}`);
|
|
2816
|
+
}
|
|
2817
|
+
if (!isManifestRecord(parsed)) {
|
|
2818
|
+
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
2819
|
+
}
|
|
2820
|
+
return {
|
|
2821
|
+
manifest: {
|
|
2822
|
+
version: parsed.version,
|
|
2823
|
+
},
|
|
2824
|
+
hadBom,
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
function validateMiniappManifestForDeploy(manifest) {
|
|
2828
|
+
return validateMiniappManifestVersion(manifest.version, 'manifest.version');
|
|
2829
|
+
}
|
|
2830
|
+
function isManifestRecord(value) {
|
|
2831
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2832
|
+
}
|
|
2833
|
+
function getMiniappManifestVersionError(version) {
|
|
2834
|
+
if (typeof version !== 'string' || version.trim() === '') {
|
|
2835
|
+
return `必须是合法 SemVer:${String(version)}`;
|
|
2836
|
+
}
|
|
2837
|
+
const normalized = version.trim();
|
|
2838
|
+
const parsed = semverExports.parse(normalized);
|
|
2839
|
+
if (!parsed) {
|
|
2840
|
+
return `必须是合法 SemVer:${normalized}`;
|
|
2841
|
+
}
|
|
2842
|
+
if (parsed.build.length > 0) {
|
|
2843
|
+
return `不能包含 build metadata:${normalized}`;
|
|
2844
|
+
}
|
|
2845
|
+
if (parsed.version !== normalized) {
|
|
2846
|
+
return `必须是合法 SemVer:${normalized}`;
|
|
2847
|
+
}
|
|
2848
|
+
if (parsed.major === 0 && parsed.minor === 0 && parsed.patch === 0) {
|
|
2849
|
+
return '不能是模板默认版本 0.0.0';
|
|
2850
|
+
}
|
|
2851
|
+
return undefined;
|
|
2852
|
+
}
|
|
2853
|
+
function formatReason(error) {
|
|
2854
|
+
if (error instanceof Error && error.message) {
|
|
2855
|
+
return error.message;
|
|
2856
|
+
}
|
|
2857
|
+
return String(error);
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
2861
|
+
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
2862
|
+
const PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = '/mall/developer/user_miniprogram/version/precheck';
|
|
2863
|
+
const SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH = '/mall/developer/user_miniprogram/version/submit_audit';
|
|
2864
|
+
const FNV_OFFSET = 0x811c9dc5;
|
|
2865
|
+
const FNV_PRIME = 0x01000193;
|
|
2866
|
+
function normalizeRelativePath(relativePath) {
|
|
2867
|
+
return String(relativePath || '')
|
|
2868
|
+
.replace(/\\/g, '/')
|
|
2869
|
+
.replace(/^\/+/, '')
|
|
2870
|
+
.replace(/\/+/g, '/');
|
|
2871
|
+
}
|
|
2872
|
+
function relativePathContainsNodeModulesSegment(relativePath) {
|
|
2873
|
+
return normalizeRelativePath(relativePath)
|
|
2874
|
+
.split('/')
|
|
2875
|
+
.some((segment) => segment.length > 0 && segment.toLowerCase() === 'node_modules');
|
|
2876
|
+
}
|
|
2877
|
+
function getMiniProgramUploadAlias(miniProgramId) {
|
|
2878
|
+
let hash = FNV_OFFSET;
|
|
2879
|
+
const input = String(miniProgramId || '');
|
|
2880
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
2881
|
+
hash ^= input.charCodeAt(i);
|
|
2882
|
+
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
2883
|
+
}
|
|
2884
|
+
return hash.toString(36);
|
|
2885
|
+
}
|
|
2886
|
+
function getMiniappUploadKey(input) {
|
|
2887
|
+
const alias = getMiniProgramUploadAlias(input.miniProgramId);
|
|
2888
|
+
const normalized = normalizeRelativePath(input.relativePath);
|
|
2889
|
+
return `/u/${alias}/${input.version}/${normalized}`;
|
|
2890
|
+
}
|
|
2891
|
+
function validateUploadPaths(items, options) {
|
|
2892
|
+
const limit = options.maxLength;
|
|
2893
|
+
for (const item of items) {
|
|
2894
|
+
const key = getMiniappUploadKey({
|
|
2895
|
+
miniProgramId: options.miniProgramId,
|
|
2896
|
+
version: options.version,
|
|
2897
|
+
relativePath: item.relativePath,
|
|
2898
|
+
});
|
|
2899
|
+
if (key.length > limit) {
|
|
2900
|
+
return `文件路径过长,请缩短构建产物文件名或目录层级:${item.relativePath}`;
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
return undefined;
|
|
2904
|
+
}
|
|
2905
|
+
function shouldUploadDistFile(relativePath) {
|
|
2906
|
+
const normalized = normalizeRelativePath(relativePath);
|
|
2907
|
+
if (!normalized) {
|
|
2908
|
+
return false;
|
|
2909
|
+
}
|
|
2910
|
+
if (normalized === 'manifest.json') {
|
|
2911
|
+
return false;
|
|
2912
|
+
}
|
|
2913
|
+
if (normalized === '.DS_Store' || normalized.endsWith('/.DS_Store')) {
|
|
2914
|
+
return false;
|
|
2915
|
+
}
|
|
2916
|
+
if (normalized.toLowerCase().endsWith('.map')) {
|
|
2917
|
+
return false;
|
|
2918
|
+
}
|
|
2919
|
+
return true;
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
const globalHeyboxCliRequestConfig = {};
|
|
2923
|
+
function readHeyboxCliRequestConfig() {
|
|
2924
|
+
return normalizeHeyboxRylaiServiceTagConfig(globalHeyboxCliRequestConfig);
|
|
2925
|
+
}
|
|
2926
|
+
function resolveHeyboxRylaiServiceTag(pathWithQuery, config = readHeyboxCliRequestConfig()) {
|
|
2927
|
+
const normalized = normalizeHeyboxRylaiServiceTagConfig(config);
|
|
2928
|
+
const pathname = pathWithQuery ? getPathname(pathWithQuery) : '';
|
|
2929
|
+
const specialTag = normalized.special_tag;
|
|
2930
|
+
if (pathname && specialTag?.path_prefix_list.some((prefix) => pathname.startsWith(prefix))) {
|
|
2931
|
+
return specialTag.tag_name;
|
|
2932
|
+
}
|
|
2933
|
+
return normalized.default_tag;
|
|
2934
|
+
}
|
|
2935
|
+
function normalizeHeyboxRylaiServiceTagConfig(config) {
|
|
2936
|
+
const defaultTag = normalizeHeyboxRylaiServiceTag(config.default_tag);
|
|
2937
|
+
const specialTagName = normalizeHeyboxRylaiServiceTag(config.special_tag?.tag_name);
|
|
2938
|
+
const pathPrefixList = config.special_tag?.path_prefix_list?.filter(isValidPathPrefix) || [];
|
|
2939
|
+
return {
|
|
2940
|
+
...(defaultTag ? { default_tag: defaultTag } : {}),
|
|
2941
|
+
...(specialTagName && pathPrefixList.length
|
|
2942
|
+
? {
|
|
2943
|
+
special_tag: {
|
|
2944
|
+
tag_name: specialTagName,
|
|
2945
|
+
path_prefix_list: pathPrefixList,
|
|
2946
|
+
},
|
|
2947
|
+
}
|
|
2948
|
+
: {}),
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
function normalizeHeyboxRylaiServiceTag(value) {
|
|
2952
|
+
const tag = String(value ?? '').trim();
|
|
2953
|
+
if (!tag) {
|
|
2954
|
+
return undefined;
|
|
2955
|
+
}
|
|
2956
|
+
if (/[\r\n]/.test(tag)) {
|
|
2957
|
+
throw new Error('x-rylai-service-tag 不允许包含换行符');
|
|
2958
|
+
}
|
|
2959
|
+
return tag;
|
|
2960
|
+
}
|
|
2961
|
+
function isValidPathPrefix(value) {
|
|
2962
|
+
return typeof value === 'string' && value.startsWith('/') && !/[\r\n]/.test(value);
|
|
2963
|
+
}
|
|
2964
|
+
function getPathname(pathWithQuery) {
|
|
2965
|
+
try {
|
|
2966
|
+
return new URL(pathWithQuery, 'https://api.xiaoheihe.cn').pathname;
|
|
2967
|
+
}
|
|
2968
|
+
catch {
|
|
2969
|
+
return '';
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
const SIGN_VERSION = '999.0.4';
|
|
2974
|
+
const SIGN_CHARSET = 'AB45STUVWZEFGJ6CH01D237IXYPQRKLMN89';
|
|
2975
|
+
function createHeyboxOpenPlatformSignParams(pathname, options = {}) {
|
|
2976
|
+
const now = options.now ?? new Date();
|
|
2977
|
+
const time = Math.trunc(now.getTime() / 1000);
|
|
2978
|
+
const nonce = options.nonce ?? md5(`${time}${Date.now()}${node_crypto.randomBytes(16).toString('hex')}`).toUpperCase();
|
|
2979
|
+
return {
|
|
2980
|
+
version: SIGN_VERSION,
|
|
2981
|
+
hkey: generateSignature(pathname, time + 1, nonce),
|
|
2982
|
+
_time: time,
|
|
2983
|
+
nonce,
|
|
2984
|
+
};
|
|
2985
|
+
}
|
|
2986
|
+
function generateSignature(path, time, nonce) {
|
|
2987
|
+
const normalizedPath = `/${path
|
|
2988
|
+
.split('/')
|
|
2989
|
+
.filter(Boolean)
|
|
2990
|
+
.join('/')}/`;
|
|
2991
|
+
const transformedTime = transformWithOffset(String(time), SIGN_CHARSET, -2);
|
|
2992
|
+
const transformedPath = transform(normalizedPath, SIGN_CHARSET);
|
|
2993
|
+
const transformedNonce = transform(nonce, SIGN_CHARSET);
|
|
2994
|
+
const combined = interleave([transformedTime, transformedPath, transformedNonce]).slice(0, 20);
|
|
2995
|
+
const hash = md5(combined);
|
|
2996
|
+
let sign = `${mixColumns(hash.slice(-6).split('').map((char) => char.charCodeAt(0))).reduce((sum, value) => sum + value, 0) % 100}`;
|
|
2997
|
+
sign = sign.length < 2 ? `0${sign}` : sign;
|
|
2998
|
+
return `${transformWithOffset(hash.substring(0, 5), SIGN_CHARSET, -4)}${sign}`;
|
|
2999
|
+
}
|
|
3000
|
+
function transformWithOffset(str, charset, offset) {
|
|
3001
|
+
return transform(str, charset.slice(0, offset));
|
|
3002
|
+
}
|
|
3003
|
+
function transform(str, charset) {
|
|
3004
|
+
let output = '';
|
|
3005
|
+
for (let index = 0; index < str.length; index += 1) {
|
|
3006
|
+
output += charset[str.charCodeAt(index) % charset.length];
|
|
3007
|
+
}
|
|
3008
|
+
return output;
|
|
3009
|
+
}
|
|
3010
|
+
function interleave(strings) {
|
|
3011
|
+
let output = '';
|
|
3012
|
+
const maxLength = Math.max(...strings.map((str) => str.length));
|
|
3013
|
+
for (let index = 0; index < maxLength; index += 1) {
|
|
3014
|
+
for (const str of strings) {
|
|
3015
|
+
if (index < str.length) {
|
|
3016
|
+
output += str[index];
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
return output;
|
|
3021
|
+
}
|
|
3022
|
+
function mixColumns(column) {
|
|
3023
|
+
const output = [...column];
|
|
3024
|
+
output[0] = multiplyE(column[0]) ^ multiply4(column[1]) ^ multiply3(column[2]) ^ multiply2(column[3]);
|
|
3025
|
+
output[1] = multiply2(column[0]) ^ multiplyE(column[1]) ^ multiply4(column[2]) ^ multiply3(column[3]);
|
|
3026
|
+
output[2] = multiply3(column[0]) ^ multiply2(column[1]) ^ multiplyE(column[2]) ^ multiply4(column[3]);
|
|
3027
|
+
output[3] = multiply4(column[0]) ^ multiply3(column[1]) ^ multiply2(column[2]) ^ multiplyE(column[3]);
|
|
3028
|
+
return output;
|
|
3029
|
+
}
|
|
3030
|
+
function multiply1(value) {
|
|
3031
|
+
if (value & 0x80) {
|
|
3032
|
+
return ((value << 1) ^ 0x1b) & 0xff;
|
|
3033
|
+
}
|
|
3034
|
+
return value << 1;
|
|
3035
|
+
}
|
|
3036
|
+
function multiply2(value) {
|
|
3037
|
+
return multiply1(value) ^ value;
|
|
3038
|
+
}
|
|
3039
|
+
function multiply3(value) {
|
|
3040
|
+
return multiply2(multiply1(value));
|
|
3041
|
+
}
|
|
3042
|
+
function multiply4(value) {
|
|
3043
|
+
return multiply3(multiply2(multiply1(value)));
|
|
3044
|
+
}
|
|
3045
|
+
function multiplyE(value) {
|
|
3046
|
+
return multiply4(value) ^ multiply3(value) ^ multiply2(value);
|
|
3047
|
+
}
|
|
3048
|
+
function md5(input) {
|
|
3049
|
+
return node_crypto.createHash('md5').update(input).digest('hex');
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
const DEFAULT_PLATFORM_PARAMS = {
|
|
3053
|
+
os_type: 'web',
|
|
3054
|
+
app: 'heybox',
|
|
3055
|
+
x_client_type: 'web',
|
|
3056
|
+
x_os_type: 'Mac',
|
|
3057
|
+
x_app: 'heybox',
|
|
3058
|
+
x_client_version: '999.999.999',
|
|
3059
|
+
};
|
|
3060
|
+
const HEYBOX_WEB_REFERER = 'https://www.xiaoheihe.cn/';
|
|
3061
|
+
function resolveHeyboxId(session) {
|
|
3062
|
+
if (session.heyboxId.trim()) {
|
|
3063
|
+
return session.heyboxId.trim();
|
|
3064
|
+
}
|
|
3065
|
+
return session.cookieHeader
|
|
3066
|
+
.split(';')
|
|
3067
|
+
.map((part) => part.trim())
|
|
3068
|
+
.find((part) => part.startsWith('heybox_id='))
|
|
3069
|
+
?.slice('heybox_id='.length);
|
|
3070
|
+
}
|
|
3071
|
+
function createHeyboxAuthHeaders(session, options = {}) {
|
|
3072
|
+
const serviceTag = resolveHeyboxRylaiServiceTag(options.pathWithQuery);
|
|
3073
|
+
return {
|
|
3074
|
+
Cookie: session.cookieHeader,
|
|
3075
|
+
Referer: HEYBOX_WEB_REFERER,
|
|
3076
|
+
...(options.contentType ? { 'Content-Type': options.contentType } : {}),
|
|
3077
|
+
...(serviceTag ? { 'x-rylai-service-tag': serviceTag } : {}),
|
|
3078
|
+
};
|
|
3079
|
+
}
|
|
3080
|
+
function createHeyboxRequestContext(session$1, options = {}) {
|
|
3081
|
+
const heyboxId = resolveHeyboxId(session$1);
|
|
3082
|
+
const serviceTag = resolveHeyboxRylaiServiceTag(options.pathWithQuery);
|
|
3083
|
+
return {
|
|
3084
|
+
baseUrl: session.HEYBOX_API_BASE_URL,
|
|
3085
|
+
headers: createHeyboxAuthHeaders(session$1, options),
|
|
3086
|
+
platformParams: {
|
|
3087
|
+
...DEFAULT_PLATFORM_PARAMS,
|
|
3088
|
+
...options.platformParams,
|
|
3089
|
+
...(heyboxId ? { heybox_id: heyboxId } : {}),
|
|
3090
|
+
...(serviceTag ? { special_tag: serviceTag } : {}),
|
|
3091
|
+
},
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
3094
|
+
function createHeyboxOpenPlatformRequestContext(session, pathWithQuery, options = {}) {
|
|
3095
|
+
return createHeyboxRequestContext(session, {
|
|
3096
|
+
...options,
|
|
3097
|
+
pathWithQuery,
|
|
3098
|
+
platformParams: {
|
|
3099
|
+
x_app: 'heybox_website',
|
|
3100
|
+
...createHeyboxOpenPlatformSignParams(getApiPathname(pathWithQuery)),
|
|
3101
|
+
...options.platformParams,
|
|
3102
|
+
},
|
|
3103
|
+
});
|
|
3104
|
+
}
|
|
3105
|
+
function createHeyboxApiUrl(baseUrl, pathWithQuery, params) {
|
|
3106
|
+
const url = new URL(pathWithQuery, baseUrl);
|
|
3107
|
+
for (const [key, value] of Object.entries(params)) {
|
|
3108
|
+
if (value !== '') {
|
|
3109
|
+
url.searchParams.set(key, String(value));
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
return url.toString();
|
|
3113
|
+
}
|
|
3114
|
+
function getApiPathname(pathWithQuery) {
|
|
3115
|
+
return new URL(pathWithQuery, session.HEYBOX_API_BASE_URL).pathname;
|
|
3116
|
+
}
|
|
3117
|
+
const ENVELOPE_BODY_PREVIEW_LENGTH = 1000;
|
|
3118
|
+
async function readHeyboxApiEnvelope(response, options) {
|
|
3119
|
+
const rawBody = await response.text();
|
|
3120
|
+
let envelope = null;
|
|
3121
|
+
let parseError = null;
|
|
3122
|
+
if (rawBody) {
|
|
3123
|
+
try {
|
|
3124
|
+
envelope = JSON.parse(rawBody);
|
|
3125
|
+
}
|
|
3126
|
+
catch (error) {
|
|
3127
|
+
parseError = error;
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
const envelopeOk = envelope?.status === 'ok' && (!options.requireResult || envelope?.result !== undefined);
|
|
3131
|
+
if (response.ok && envelopeOk) {
|
|
3132
|
+
return envelope.result;
|
|
3133
|
+
}
|
|
3134
|
+
const { message, verboseMessage } = formatHeyboxEnvelopeError({
|
|
3135
|
+
response,
|
|
3136
|
+
envelope,
|
|
3137
|
+
parseError,
|
|
3138
|
+
rawBody,
|
|
3139
|
+
pathWithQuery: options.pathWithQuery,
|
|
3140
|
+
});
|
|
3141
|
+
throw new index.CliError(message, verboseMessage);
|
|
3142
|
+
}
|
|
3143
|
+
function formatHeyboxEnvelopeError(input) {
|
|
3144
|
+
const parts = [`Heybox API ${input.pathWithQuery} failed`, `HTTP ${input.response.status}`];
|
|
3145
|
+
if (input.envelope) {
|
|
3146
|
+
const msg = typeof input.envelope.msg === 'string' ? input.envelope.msg.trim() : '';
|
|
3147
|
+
const sbeUserMessage = readSbeUserMessage(input.envelope.result);
|
|
3148
|
+
parts.push(`msg=${msg || '(empty)'}`);
|
|
3149
|
+
if (typeof input.envelope.status === 'string') {
|
|
3150
|
+
parts.push(`envelope.status=${input.envelope.status}`);
|
|
3151
|
+
}
|
|
3152
|
+
const { status: _s, msg: _m, result: _r, ...extras } = input.envelope;
|
|
3153
|
+
if (Object.keys(extras).length > 0) {
|
|
3154
|
+
parts.push(`extras=${truncate(safeJsonStringify(extras), ENVELOPE_BODY_PREVIEW_LENGTH)}`);
|
|
3155
|
+
}
|
|
3156
|
+
if (input.envelope.result !== undefined) {
|
|
3157
|
+
parts.push(`result=${truncate(safeJsonStringify(input.envelope.result), ENVELOPE_BODY_PREVIEW_LENGTH)}`);
|
|
3158
|
+
}
|
|
3159
|
+
return {
|
|
3160
|
+
message: sbeUserMessage || msg || `Heybox API ${input.pathWithQuery} 请求失败`,
|
|
3161
|
+
verboseMessage: parts.join(' '),
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
if (input.parseError) {
|
|
3165
|
+
const parseMsg = input.parseError instanceof Error ? input.parseError.message : String(input.parseError);
|
|
3166
|
+
parts.push(`parseError=${parseMsg}`);
|
|
3167
|
+
}
|
|
3168
|
+
parts.push(input.rawBody ? `body=${truncate(input.rawBody, ENVELOPE_BODY_PREVIEW_LENGTH)}` : 'body=(empty)');
|
|
3169
|
+
return {
|
|
3170
|
+
message: `Heybox API ${input.pathWithQuery} 请求失败`,
|
|
3171
|
+
verboseMessage: parts.join(' '),
|
|
3172
|
+
};
|
|
3173
|
+
}
|
|
3174
|
+
function readSbeUserMessage(result) {
|
|
3175
|
+
if (!result || typeof result !== 'object') {
|
|
3176
|
+
return '';
|
|
3177
|
+
}
|
|
3178
|
+
const sbe = result.sbe;
|
|
3179
|
+
if (!sbe || typeof sbe !== 'object') {
|
|
3180
|
+
return '';
|
|
3181
|
+
}
|
|
3182
|
+
const userMessage = sbe.user_message;
|
|
3183
|
+
return typeof userMessage === 'string' ? userMessage.trim() : '';
|
|
3184
|
+
}
|
|
3185
|
+
function truncate(value, max) {
|
|
3186
|
+
return value.length > max ? `${value.slice(0, max)}...(+${value.length - max} chars)` : value;
|
|
3187
|
+
}
|
|
3188
|
+
function safeJsonStringify(value) {
|
|
3189
|
+
try {
|
|
3190
|
+
return JSON.stringify(value);
|
|
3191
|
+
}
|
|
3192
|
+
catch {
|
|
3193
|
+
return String(value);
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
async function getCDNUploadInfo(options, runtime = {}) {
|
|
3198
|
+
const body = new URLSearchParams();
|
|
3199
|
+
body.set('file_infos', JSON.stringify(options.fileInfos));
|
|
3200
|
+
body.set('scope', options.scope);
|
|
3201
|
+
body.set('need_cache', options.needCache ? '1' : '0');
|
|
3202
|
+
return postHeyboxApi('/bbs/app/api/qcloud/cos/upload/info/v2', body, options.session, runtime);
|
|
3203
|
+
}
|
|
3204
|
+
async function getCDNUploadToken(options, runtime = {}) {
|
|
3205
|
+
const body = new URLSearchParams();
|
|
3206
|
+
body.set('bucket', options.bucket);
|
|
3207
|
+
body.set('keys', JSON.stringify(options.keys));
|
|
3208
|
+
body.set('mimetypes', JSON.stringify(options.mimetypes));
|
|
3209
|
+
body.set('is_multipart_upload', String(options.isMultipartUpload));
|
|
3210
|
+
return postHeyboxApi('/bbs/app/api/qcloud/cos/upload/token/v2', body, options.session, runtime);
|
|
3211
|
+
}
|
|
3212
|
+
async function postCDNUploadCallback(options, runtime = {}) {
|
|
3213
|
+
const body = new URLSearchParams();
|
|
3214
|
+
body.set('keys', JSON.stringify(options.keys));
|
|
3215
|
+
const query = options.isFinished ? '?is_finished=true' : '';
|
|
3216
|
+
return postHeyboxApi(`/bbs/app/api/qcloud/cos/upload/callback/v2${query}`, body, options.session, runtime);
|
|
3217
|
+
}
|
|
3218
|
+
async function postHeyboxApi(pathWithQuery, body, session, runtime) {
|
|
3219
|
+
const fetchImpl = runtime.fetchImpl ?? fetch;
|
|
3220
|
+
const context = createHeyboxOpenPlatformRequestContext(session, pathWithQuery, {
|
|
3221
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
3222
|
+
});
|
|
3223
|
+
const response = await fetchImpl(createHeyboxApiUrl(runtime.baseUrl ?? context.baseUrl, pathWithQuery, context.platformParams), {
|
|
3224
|
+
method: 'POST',
|
|
3225
|
+
headers: context.headers,
|
|
3226
|
+
body: body.toString(),
|
|
3227
|
+
});
|
|
3228
|
+
const result = await readHeyboxApiEnvelope(response, { pathWithQuery, requireResult: true });
|
|
3229
|
+
return result;
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
const DEFAULT_CONCURRENCY = 4;
|
|
3233
|
+
async function runUpload(options, runtime = {}) {
|
|
3234
|
+
const logger = runtime.logger ?? index.createCliLogger();
|
|
3235
|
+
const concurrency = runtime.concurrency ?? DEFAULT_CONCURRENCY;
|
|
3236
|
+
const fetchImpl = runtime.fetchImpl ?? fetch;
|
|
3237
|
+
const getCDNUploadInfo$1 = runtime.getCDNUploadInfo ?? getCDNUploadInfo;
|
|
3238
|
+
const getCDNUploadToken$1 = runtime.getCDNUploadToken ?? getCDNUploadToken;
|
|
3239
|
+
const postCDNUploadCallback$1 = runtime.postCDNUploadCallback ?? postCDNUploadCallback;
|
|
3240
|
+
const createReadStream = runtime.createReadStream ?? fs.createReadStream;
|
|
3241
|
+
const orderedFiles = [...options.files].sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
3242
|
+
const fileInfos = orderedFiles.map((file) => ({
|
|
3243
|
+
name: file.relativePath.split('/').pop() ?? file.relativePath,
|
|
3244
|
+
mimetype: file.mimeType,
|
|
3245
|
+
fsize: file.size,
|
|
3246
|
+
path: getMiniappUploadKey({
|
|
3247
|
+
miniProgramId: options.miniProgramId,
|
|
3248
|
+
version: options.version,
|
|
3249
|
+
relativePath: file.relativePath,
|
|
3250
|
+
}),
|
|
3251
|
+
}));
|
|
3252
|
+
await logger.task(`正在上传 ${orderedFiles.length} 个文件`, async (taskContext) => {
|
|
3253
|
+
logger.debug(`上传并发数: ${concurrency}`);
|
|
3254
|
+
logger.debug('正在获取 CDN 上传信息');
|
|
3255
|
+
const uploadInfo = await getCDNUploadInfo$1({ session: options.session, scope: MINIAPP_UPLOAD_SCOPE, fileInfos, needCache: false }, { baseUrl: runtime.baseUrl, fetchImpl });
|
|
3256
|
+
logger.debug(`CDN bucket: ${uploadInfo.bucket}`);
|
|
3257
|
+
logger.debug(`CDN region: ${uploadInfo.region}`);
|
|
3258
|
+
const indexedFiles = orderedFiles.map((file, index) => ({ file, key: uploadInfo.keys[index] }));
|
|
3259
|
+
logger.debug('正在获取 CDN 上传凭证');
|
|
3260
|
+
const cos = runtime.createCosClient
|
|
3261
|
+
? runtime.createCosClient({ session: options.session })
|
|
3262
|
+
: await createDefaultCosClient(await getCDNUploadToken$1({
|
|
3263
|
+
session: options.session,
|
|
3264
|
+
bucket: uploadInfo.bucket,
|
|
3265
|
+
keys: indexedFiles.map(({ key }) => key),
|
|
3266
|
+
mimetypes: indexedFiles.map(({ file }) => file.mimeType),
|
|
3267
|
+
isMultipartUpload: 0,
|
|
3268
|
+
}, { baseUrl: runtime.baseUrl, fetchImpl }));
|
|
3269
|
+
const queue = indexedFiles.slice();
|
|
3270
|
+
let completed = 0;
|
|
3271
|
+
const workers = Array.from({ length: Math.min(concurrency, indexedFiles.length) }, async () => {
|
|
3272
|
+
while (queue.length > 0) {
|
|
3273
|
+
const uploadTask = queue.shift();
|
|
3274
|
+
if (!uploadTask) {
|
|
3275
|
+
return;
|
|
3276
|
+
}
|
|
3277
|
+
try {
|
|
3278
|
+
await cos.putObject({
|
|
3279
|
+
Bucket: uploadInfo.bucket,
|
|
3280
|
+
Region: uploadInfo.region,
|
|
3281
|
+
Key: uploadTask.key,
|
|
3282
|
+
Body: createReadStream(uploadTask.file.absolutePath),
|
|
3283
|
+
ContentLength: uploadTask.file.size,
|
|
3284
|
+
ContentType: uploadTask.file.mimeType,
|
|
3285
|
+
});
|
|
3286
|
+
completed += 1;
|
|
3287
|
+
taskContext.update(`正在上传 ${completed}/${indexedFiles.length} 个文件`);
|
|
3288
|
+
logger.debug(`[${String(completed).padStart(2)}/${indexedFiles.length}] ok ${uploadTask.file.relativePath} (${formatSize(uploadTask.file.size)})`);
|
|
3289
|
+
}
|
|
3290
|
+
catch (error) {
|
|
3291
|
+
completed += 1;
|
|
3292
|
+
const message = readErrorMessage(error);
|
|
3293
|
+
logger.debug(`[${String(completed).padStart(2)}/${indexedFiles.length}] error ${uploadTask.file.relativePath} -> ${message}`);
|
|
3294
|
+
throw new index.CliError(`上传文件失败:${uploadTask.file.relativePath} -> ${message}`, readVerboseUploadError(uploadTask.file.relativePath, error));
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
});
|
|
3298
|
+
await Promise.all(workers);
|
|
3299
|
+
logger.debug('正在确认 CDN 上传结果');
|
|
3300
|
+
await postCDNUploadCallback$1({ session: options.session, keys: uploadInfo.keys, isFinished: true }, { baseUrl: runtime.baseUrl, fetchImpl });
|
|
3301
|
+
}, { successText: `已上传 ${orderedFiles.length} 个文件` });
|
|
3302
|
+
}
|
|
3303
|
+
async function createDefaultCosClient(uploadToken) {
|
|
3304
|
+
const COS = await loadCosConstructor();
|
|
3305
|
+
const cos = new COS({
|
|
3306
|
+
getAuthorization(_input, callback) {
|
|
3307
|
+
callback({
|
|
3308
|
+
TmpSecretId: uploadToken.credentials.tmpSecretId,
|
|
3309
|
+
TmpSecretKey: uploadToken.credentials.tmpSecretKey,
|
|
3310
|
+
XCosSecurityToken: uploadToken.credentials.sessionToken,
|
|
3311
|
+
StartTime: uploadToken.startTime,
|
|
3312
|
+
ExpiredTime: uploadToken.expiredTime,
|
|
3313
|
+
});
|
|
3314
|
+
},
|
|
3315
|
+
});
|
|
3316
|
+
return {
|
|
3317
|
+
putObject(params) {
|
|
3318
|
+
return new Promise((resolve, reject) => {
|
|
3319
|
+
cos.putObject(params, (err, result) => {
|
|
3320
|
+
if (err) {
|
|
3321
|
+
reject(err instanceof Error ? err : new Error(readErrorMessage(err)));
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
resolve(result);
|
|
3325
|
+
});
|
|
3326
|
+
});
|
|
3327
|
+
},
|
|
3328
|
+
};
|
|
3329
|
+
}
|
|
3330
|
+
async function loadCosConstructor() {
|
|
3331
|
+
const cosModule = await Promise.resolve().then(function () { return require('./index-yjJgBEBF.cjs'); }).then(function (n) { return n.index; });
|
|
3332
|
+
return cosModule.default;
|
|
3333
|
+
}
|
|
3334
|
+
function formatSize(bytes) {
|
|
3335
|
+
if (bytes < 1024) {
|
|
3336
|
+
return `${bytes} B`;
|
|
3337
|
+
}
|
|
3338
|
+
if (bytes < 1024 * 1024) {
|
|
3339
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
3340
|
+
}
|
|
3341
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
3342
|
+
}
|
|
3343
|
+
function readErrorMessage(error) {
|
|
3344
|
+
if (error instanceof Error && error.message) {
|
|
3345
|
+
return error.message;
|
|
3346
|
+
}
|
|
3347
|
+
if (isRecord(error)) {
|
|
3348
|
+
const primary = readStringField(error, ['message', 'Message', 'errorMessage', 'msg']);
|
|
3349
|
+
const code = readStringField(error, ['code', 'Code', 'errorCode', 'name']);
|
|
3350
|
+
const statusCode = readStringField(error, ['statusCode']);
|
|
3351
|
+
return [code, statusCode, primary].filter(Boolean).join(' ') || JSON.stringify(error);
|
|
3352
|
+
}
|
|
3353
|
+
return String(error);
|
|
3354
|
+
}
|
|
3355
|
+
function readVerboseUploadError(relativePath, error) {
|
|
3356
|
+
return [`上传文件失败:${relativePath}`, `原始错误:${readErrorMessage(error)}`].join('\n');
|
|
3357
|
+
}
|
|
3358
|
+
function readStringField(record, fields) {
|
|
3359
|
+
for (const field of fields) {
|
|
3360
|
+
const value = record[field];
|
|
3361
|
+
if (typeof value === 'string' && value.trim()) {
|
|
3362
|
+
return value.trim();
|
|
3363
|
+
}
|
|
3364
|
+
if (typeof value === 'number') {
|
|
3365
|
+
return String(value);
|
|
3366
|
+
}
|
|
3367
|
+
}
|
|
3368
|
+
return '';
|
|
3369
|
+
}
|
|
3370
|
+
function isRecord(value) {
|
|
3371
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
3372
|
+
}
|
|
3373
|
+
|
|
3374
|
+
async function precheckUserMiniprogramVersion(options, runtime = {}) {
|
|
3375
|
+
return postUserMiniprogramVersionForm(PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, {
|
|
3376
|
+
version: options.version,
|
|
3377
|
+
release_note: options.releaseNote,
|
|
3378
|
+
auto_publish: String(options.autoPublish),
|
|
3379
|
+
}, runtime);
|
|
3380
|
+
}
|
|
3381
|
+
async function submitUserMiniprogramAudit(options, runtime = {}) {
|
|
3382
|
+
return postUserMiniprogramVersionForm(SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, options, {
|
|
3383
|
+
manifest: JSON.stringify(options.manifest),
|
|
3384
|
+
release_note: options.releaseNote,
|
|
3385
|
+
auto_publish: String(options.autoPublish),
|
|
3386
|
+
}, runtime);
|
|
3387
|
+
}
|
|
3388
|
+
async function postUserMiniprogramVersionForm(path, options, fields, runtime) {
|
|
3389
|
+
const fetchImpl = runtime.fetchImpl ?? fetch;
|
|
3390
|
+
const context = createHeyboxOpenPlatformRequestContext(options.session, path, {
|
|
3391
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
3392
|
+
});
|
|
3393
|
+
const body = new URLSearchParams();
|
|
3394
|
+
body.set('mini_program_id', options.miniProgramId);
|
|
3395
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
3396
|
+
body.set(key, value);
|
|
3397
|
+
}
|
|
3398
|
+
const response = await fetchImpl(createHeyboxApiUrl(runtime.baseUrl ?? context.baseUrl, path, context.platformParams), {
|
|
3399
|
+
method: 'POST',
|
|
3400
|
+
headers: context.headers,
|
|
3401
|
+
body: body.toString(),
|
|
3402
|
+
});
|
|
3403
|
+
const result = await readHeyboxApiEnvelope(response, {
|
|
3404
|
+
pathWithQuery: path,
|
|
3405
|
+
});
|
|
3406
|
+
return result ?? {};
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
const SUPPORTED_PACKAGE_MANAGERS = [
|
|
3410
|
+
{ name: 'pnpm', lockfile: 'pnpm-lock.yaml' },
|
|
3411
|
+
{ name: 'yarn', lockfile: 'yarn.lock' },
|
|
3412
|
+
{ name: 'npm', lockfile: 'package-lock.json' },
|
|
3413
|
+
];
|
|
3414
|
+
const MIME_BY_EXT = {
|
|
3415
|
+
'.css': 'text/css',
|
|
3416
|
+
'.gif': 'image/gif',
|
|
3417
|
+
'.html': 'text/html',
|
|
3418
|
+
'.jpeg': 'image/jpeg',
|
|
3419
|
+
'.jpg': 'image/jpeg',
|
|
3420
|
+
'.js': 'application/javascript',
|
|
3421
|
+
'.json': 'application/json',
|
|
3422
|
+
'.png': 'image/png',
|
|
3423
|
+
'.svg': 'image/svg+xml',
|
|
3424
|
+
'.ttf': 'font/ttf',
|
|
3425
|
+
'.txt': 'text/plain',
|
|
3426
|
+
'.wasm': 'application/wasm',
|
|
3427
|
+
'.webp': 'image/webp',
|
|
3428
|
+
'.woff': 'font/woff',
|
|
3429
|
+
'.woff2': 'font/woff2',
|
|
3430
|
+
};
|
|
3431
|
+
async function runDeployCommand(options, runtime = {}) {
|
|
3432
|
+
const logger = runtime.logger ?? index.createCliLogger();
|
|
3433
|
+
const cwd = runtime.cwd ?? process.cwd();
|
|
3434
|
+
const projectRoot = findProjectRoot(cwd);
|
|
3435
|
+
const packageJson = await readPackageJson(projectRoot);
|
|
3436
|
+
const miniProgramId = packageJson.heybox?.miniProgramId;
|
|
3437
|
+
const autoPublish = Boolean(options.autoPublish);
|
|
3438
|
+
const env = options.env ?? process.env;
|
|
3439
|
+
const apiBaseUrl = session.resolveHeyboxApiBaseUrl({ ...options, env });
|
|
3440
|
+
const loginBaseUrl = session.resolveHeyboxLoginBaseUrl({ ...options, env });
|
|
3441
|
+
if (typeof miniProgramId !== 'string' || !miniProgramId.trim()) {
|
|
3442
|
+
throw new Error('未在 package.json 中找到 heybox.miniProgramId,请先配置 mini program id');
|
|
3443
|
+
}
|
|
3444
|
+
const releaseNote = await resolveDeployReleaseNote(options, runtime);
|
|
3445
|
+
const session$1 = await logger.task('正在校验 Heybox 登录态', () => (runtime.requireAuthSession ?? session.requireHeyboxAuthSession)({ loginBaseUrl }), { successText: 'Heybox 登录态有效' });
|
|
3446
|
+
logger.debug(`Heybox API: ${apiBaseUrl}`);
|
|
3447
|
+
let precheckVersion;
|
|
3448
|
+
let parsedManifest;
|
|
3449
|
+
if (!options.skipBuild) {
|
|
3450
|
+
if (typeof packageJson.scripts?.build !== 'string') {
|
|
3451
|
+
throw new Error('package.json scripts.build 未定义,请添加 build 脚本或使用 --skip-build 跳过构建');
|
|
3452
|
+
}
|
|
3453
|
+
precheckVersion = validateVersionForDeploy(packageJson.version, 'package.json.version');
|
|
3454
|
+
await runVersionPrecheck({
|
|
3455
|
+
session: session$1,
|
|
3456
|
+
miniProgramId,
|
|
3457
|
+
version: precheckVersion,
|
|
3458
|
+
releaseNote,
|
|
3459
|
+
autoPublish,
|
|
3460
|
+
}, runtime, apiBaseUrl, projectRoot, logger);
|
|
3461
|
+
const pm = detectPackageManager(projectRoot);
|
|
3462
|
+
logger.info(`开始构建: ${pm} run build`);
|
|
3463
|
+
await runBuildScript(pm, projectRoot, runtime.spawn ?? childProcess.spawn);
|
|
3464
|
+
logger.success('构建完成');
|
|
3465
|
+
}
|
|
3466
|
+
else {
|
|
3467
|
+
parsedManifest = await readDeployManifest(projectRoot, logger);
|
|
3468
|
+
precheckVersion = parsedManifest.version;
|
|
3469
|
+
await runVersionPrecheck({
|
|
3470
|
+
session: session$1,
|
|
3471
|
+
miniProgramId,
|
|
3472
|
+
version: precheckVersion,
|
|
3473
|
+
releaseNote,
|
|
3474
|
+
autoPublish,
|
|
3475
|
+
}, runtime, apiBaseUrl, projectRoot, logger);
|
|
3476
|
+
}
|
|
3477
|
+
const distDir = path.join(projectRoot, 'dist');
|
|
3478
|
+
parsedManifest ??= await readDeployManifest(projectRoot, logger);
|
|
3479
|
+
const { manifest, version } = parsedManifest;
|
|
3480
|
+
if (version !== precheckVersion) {
|
|
3481
|
+
throw new Error(`dist/manifest.json.version (${version}) 与预检版本 (${precheckVersion}) 不一致,请重新 build 后再 deploy`);
|
|
3482
|
+
}
|
|
3483
|
+
const uploadFiles = await logger.task('正在校验 dist 上传文件', async () => {
|
|
3484
|
+
const allFiles = await walkDistFiles(distDir);
|
|
3485
|
+
const blocked = allFiles.find((entry) => relativePathContainsNodeModulesSegment(entry.relativePath));
|
|
3486
|
+
if (blocked) {
|
|
3487
|
+
throw new Error(`dist 目录含 node_modules:${blocked.relativePath}`);
|
|
3488
|
+
}
|
|
3489
|
+
const files = allFiles.filter((entry) => shouldUploadDistFile(entry.relativePath));
|
|
3490
|
+
const pathError = validateUploadPaths(files, { miniProgramId, version, maxLength: ACTIVITY_UPLOAD_KEY_MAX_LENGTH });
|
|
3491
|
+
if (pathError) {
|
|
3492
|
+
throw new Error(pathError);
|
|
3493
|
+
}
|
|
3494
|
+
logger.debug(`待上传文件数: ${files.length}`);
|
|
3495
|
+
return files;
|
|
3496
|
+
}, { successText: 'dist 上传文件校验完成' });
|
|
3497
|
+
let submitAuditResult;
|
|
3498
|
+
try {
|
|
3499
|
+
await (runtime.runUpload ?? runUpload)({ session: session$1, miniProgramId, version, files: uploadFiles }, { baseUrl: apiBaseUrl, fetchImpl: runtime.fetchImpl, logger });
|
|
3500
|
+
}
|
|
3501
|
+
catch (error) {
|
|
3502
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'upload', version });
|
|
3503
|
+
}
|
|
3504
|
+
try {
|
|
3505
|
+
submitAuditResult = await logger.task('正在提交审核', () => (runtime.submitUserMiniprogramAudit ?? submitUserMiniprogramAudit)({ session: session$1, miniProgramId, manifest, releaseNote, autoPublish }, { baseUrl: apiBaseUrl, fetchImpl: runtime.fetchImpl }), { successText: '审核提交完成' });
|
|
3506
|
+
}
|
|
3507
|
+
catch (error) {
|
|
3508
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'submitAudit', version });
|
|
3509
|
+
}
|
|
3510
|
+
logger.success(`提交审核成功:${miniProgramId} ${version}`);
|
|
3511
|
+
logger.info(`发布策略:${autoPublish ? '审核通过后自动发布' : '审核通过后需在开放平台手动发布'}`);
|
|
3512
|
+
if (submitAuditResult.preview_url) {
|
|
3513
|
+
logger.info(`Preview URL: ${submitAuditResult.preview_url}`);
|
|
3514
|
+
}
|
|
3515
|
+
}
|
|
3516
|
+
function findProjectRoot(startDir) {
|
|
3517
|
+
let current = path.resolve(startDir);
|
|
3518
|
+
while (true) {
|
|
3519
|
+
if (fs.existsSync(path.join(current, 'package.json'))) {
|
|
3520
|
+
return current;
|
|
3521
|
+
}
|
|
3522
|
+
const parent = path.dirname(current);
|
|
3523
|
+
if (parent === current) {
|
|
3524
|
+
throw new Error('当前目录或父目录未找到 package.json');
|
|
3525
|
+
}
|
|
3526
|
+
current = parent;
|
|
3527
|
+
}
|
|
3528
|
+
}
|
|
3529
|
+
async function readPackageJson(projectRoot) {
|
|
3530
|
+
return JSON.parse(await fs$1.readFile(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
3531
|
+
}
|
|
3532
|
+
async function readDeployManifest(projectRoot, logger) {
|
|
3533
|
+
const distDir = path.join(projectRoot, 'dist');
|
|
3534
|
+
const manifestPath = path.join(distDir, 'manifest.json');
|
|
3535
|
+
const entryHtmlPath = path.join(distDir, 'index.html');
|
|
3536
|
+
if (!fs.existsSync(manifestPath)) {
|
|
3537
|
+
throw new Error('未找到 dist/manifest.json,可能需要先跑 build 或检查 vite miniappManifest 插件');
|
|
3538
|
+
}
|
|
3539
|
+
if (!fs.existsSync(entryHtmlPath)) {
|
|
3540
|
+
throw new Error('未找到 dist/index.html,dist 目录残缺,请重新 build');
|
|
3541
|
+
}
|
|
3542
|
+
const { manifest, hadBom } = parseMiniappManifestJson(await fs$1.readFile(manifestPath, 'utf8'), 'dist/manifest.json');
|
|
3543
|
+
if (hadBom) {
|
|
3544
|
+
logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
|
|
3545
|
+
}
|
|
3546
|
+
return {
|
|
3547
|
+
manifest,
|
|
3548
|
+
version: validateMiniappManifestForDeploy(manifest),
|
|
3549
|
+
};
|
|
3550
|
+
}
|
|
3551
|
+
function validateVersionForDeploy(version, sourceLabel) {
|
|
3552
|
+
if (typeof version !== 'string' || !isValidMiniappManifestVersion(version)) {
|
|
3553
|
+
throw new Error(`${sourceLabel} 必须是合法 SemVer,允许 prerelease,不允许 build metadata 和 0.0.0:${String(version)}`);
|
|
3554
|
+
}
|
|
3555
|
+
return version.trim();
|
|
3556
|
+
}
|
|
3557
|
+
async function resolveDeployReleaseNote(options, runtime = {}) {
|
|
3558
|
+
const rawReleaseNote = options.releaseNote ?? (await maybePromptReleaseNote(runtime));
|
|
3559
|
+
return validateDeployReleaseNote(rawReleaseNote);
|
|
3560
|
+
}
|
|
3561
|
+
function validateDeployReleaseNote(value) {
|
|
3562
|
+
const releaseNote = String(value ?? '').trim();
|
|
3563
|
+
if (!releaseNote) {
|
|
3564
|
+
throw new Error('release note 不能为空,请通过 --release-note <text> 传入发布日志');
|
|
3565
|
+
}
|
|
3566
|
+
if (Array.from(releaseNote).length > 500) {
|
|
3567
|
+
throw new Error('release note 不能超过 500 个字符');
|
|
3568
|
+
}
|
|
3569
|
+
return releaseNote;
|
|
3570
|
+
}
|
|
3571
|
+
async function maybePromptReleaseNote(runtime) {
|
|
3572
|
+
if (runtime.promptReleaseNote) {
|
|
3573
|
+
return runtime.promptReleaseNote();
|
|
3574
|
+
}
|
|
3575
|
+
const isTTY = runtime.isTTY ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
3576
|
+
if (!isTTY) {
|
|
3577
|
+
throw new Error('非交互环境执行 hb-sdk deploy 必须传 --release-note <text>');
|
|
3578
|
+
}
|
|
3579
|
+
const input = runtime.stdin ?? process.stdin;
|
|
3580
|
+
const output = runtime.stdout ?? process.stdout;
|
|
3581
|
+
const rl = promises.createInterface({ input, output });
|
|
3582
|
+
try {
|
|
3583
|
+
return await rl.question('请输入发布日志 release note: ');
|
|
3584
|
+
}
|
|
3585
|
+
finally {
|
|
3586
|
+
rl.close();
|
|
3587
|
+
}
|
|
3588
|
+
}
|
|
3589
|
+
async function runVersionPrecheck(options, runtime, apiBaseUrl, projectRoot, logger) {
|
|
3590
|
+
try {
|
|
3591
|
+
await logger.task(`正在预检版本 ${options.version}`, () => (runtime.precheckUserMiniprogramVersion ?? precheckUserMiniprogramVersion)(options, {
|
|
3592
|
+
baseUrl: apiBaseUrl,
|
|
3593
|
+
fetchImpl: runtime.fetchImpl,
|
|
3594
|
+
}), { successText: `版本 ${options.version} 预检通过` });
|
|
3595
|
+
}
|
|
3596
|
+
catch (error) {
|
|
3597
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'precheck', version: options.version });
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
function detectPackageManager(projectRoot) {
|
|
3601
|
+
for (const candidate of SUPPORTED_PACKAGE_MANAGERS) {
|
|
3602
|
+
if (fs.existsSync(path.join(projectRoot, candidate.lockfile))) {
|
|
3603
|
+
return candidate.name;
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
return 'npm';
|
|
3607
|
+
}
|
|
3608
|
+
async function runBuildScript(pm, cwd, spawnImpl) {
|
|
3609
|
+
await new Promise((resolve, reject) => {
|
|
3610
|
+
const child = spawnImpl(pm, ['run', 'build'], {
|
|
3611
|
+
cwd,
|
|
3612
|
+
stdio: 'inherit',
|
|
3613
|
+
});
|
|
3614
|
+
child.on('error', reject);
|
|
3615
|
+
child.on('exit', (code) => {
|
|
3616
|
+
if (code === 0) {
|
|
3617
|
+
resolve();
|
|
3618
|
+
}
|
|
3619
|
+
else {
|
|
3620
|
+
reject(new Error(`${pm} run build exited with code ${code ?? 'null'}`));
|
|
3621
|
+
}
|
|
3622
|
+
});
|
|
3623
|
+
});
|
|
3624
|
+
}
|
|
3625
|
+
async function walkDistFiles(distDir) {
|
|
3626
|
+
const results = [];
|
|
3627
|
+
await walk(distDir, '');
|
|
3628
|
+
return results;
|
|
3629
|
+
async function walk(absDir, relDir) {
|
|
3630
|
+
const entries = await fs$1.readdir(absDir, { withFileTypes: true });
|
|
3631
|
+
for (const entry of entries) {
|
|
3632
|
+
const absPath = path.join(absDir, entry.name);
|
|
3633
|
+
const relPath = relDir ? `${relDir}/${entry.name}` : entry.name;
|
|
3634
|
+
const link = await fs$1.lstat(absPath);
|
|
3635
|
+
if (link.isSymbolicLink()) {
|
|
3636
|
+
throw new Error(`dist 目录包含 symlink,拒绝处理:${relPath}`);
|
|
3637
|
+
}
|
|
3638
|
+
if (entry.isDirectory()) {
|
|
3639
|
+
await walk(absPath, relPath);
|
|
3640
|
+
continue;
|
|
3641
|
+
}
|
|
3642
|
+
if (!entry.isFile()) {
|
|
3643
|
+
continue;
|
|
3644
|
+
}
|
|
3645
|
+
const fileStat = await fs$1.stat(absPath);
|
|
3646
|
+
results.push({
|
|
3647
|
+
relativePath: normalizeRelativePath(relPath),
|
|
3648
|
+
absolutePath: absPath,
|
|
3649
|
+
size: fileStat.size,
|
|
3650
|
+
mimeType: inferMimeType(entry.name),
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
function inferMimeType(fileName) {
|
|
3656
|
+
return MIME_BY_EXT[path.extname(fileName).toLowerCase()] || 'application/octet-stream';
|
|
3657
|
+
}
|
|
3658
|
+
function translateHeyboxDeployError(error, options) {
|
|
3659
|
+
const message = error instanceof Error && error.message ? error.message : String(error);
|
|
3660
|
+
if (isVersionLifecycleConflictMessage(message) && options.stage !== 'upload') {
|
|
3661
|
+
const packageJsonPath = path.join(options.projectRoot, 'package.json');
|
|
3662
|
+
const nextVersion = suggestNextPatchVersion(options.version);
|
|
3663
|
+
return new index.CliError([
|
|
3664
|
+
`当前小程序版本 ${options.version} 已进入线上生命周期或正在审核,不能复用。`,
|
|
3665
|
+
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
3666
|
+
].join('\n'), [
|
|
3667
|
+
`当前小程序版本 ${options.version} 已进入线上生命周期或正在审核,不能复用。`,
|
|
3668
|
+
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
3669
|
+
`原始错误:${readVerboseDeployErrorMessage(error)}`,
|
|
3670
|
+
].join('\n'));
|
|
3671
|
+
}
|
|
3672
|
+
if (isDuplicateUploadErrorMessage(message) && options.stage === 'upload') {
|
|
3673
|
+
const packageJsonPath = path.join(options.projectRoot, 'package.json');
|
|
3674
|
+
const nextVersion = suggestNextPatchVersion(options.version);
|
|
3675
|
+
return new index.CliError([
|
|
3676
|
+
`当前小程序版本 ${options.version} 的上传文件已存在,不能覆盖同版本发布产物。`,
|
|
3677
|
+
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
3678
|
+
].join('\n'), [
|
|
3679
|
+
`当前小程序版本 ${options.version} 的上传文件已存在,不能覆盖同版本发布产物。`,
|
|
3680
|
+
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
3681
|
+
`原始错误:${readVerboseDeployErrorMessage(error)}`,
|
|
3682
|
+
].join('\n'));
|
|
3683
|
+
}
|
|
3684
|
+
if (isAuthExpiredErrorMessage(message)) {
|
|
3685
|
+
if (options.stage === 'upload') {
|
|
3686
|
+
return new index.CliError([
|
|
3687
|
+
'CDN 上传接口拒绝了当前登录态或请求上下文。',
|
|
3688
|
+
'如果版本预检刚通过,通常不是本地登录缓存损坏;请用 `--verbose` 查看 upload/info 原始返回,并确认当前 API 环境支持 CDN 上传接口。',
|
|
3689
|
+
].join('\n'), [
|
|
3690
|
+
'CDN 上传接口拒绝了当前登录态或请求上下文。',
|
|
3691
|
+
'如果版本预检刚通过,通常不是本地登录缓存损坏;请用 `--verbose` 查看 upload/info 原始返回,并确认当前 API 环境支持 CDN 上传接口。',
|
|
3692
|
+
`原始错误:${readVerboseDeployErrorMessage(error)}`,
|
|
3693
|
+
].join('\n'));
|
|
3694
|
+
}
|
|
3695
|
+
return new index.CliError(['Heybox 登录态已失效(服务端 session 已过期或被清除)。', '请运行 `hb-sdk login` 重新登录后再执行 deploy。'].join('\n'), ['Heybox 登录态已失效(服务端 session 已过期或被清除)。', '请运行 `hb-sdk login` 重新登录后再执行 deploy。', `原始错误:${message}`].join('\n'));
|
|
3696
|
+
}
|
|
3697
|
+
return error instanceof Error ? error : new Error(message);
|
|
3698
|
+
}
|
|
3699
|
+
function isDuplicateUploadErrorMessage(message) {
|
|
3700
|
+
return /重名|duplicate|already exists|exists/i.test(message);
|
|
3701
|
+
}
|
|
3702
|
+
function isVersionLifecycleConflictMessage(message) {
|
|
3703
|
+
return /AlreadyExists\(6\)|不能复用|已进入线上生命周期|正在审核|活跃候选版本|同版本/i.test(message);
|
|
3704
|
+
}
|
|
3705
|
+
function isAuthExpiredErrorMessage(message) {
|
|
3706
|
+
return /请重新登录|未登录|登录已失效|登录态已失效|unauthorized|未授权/i.test(message);
|
|
3707
|
+
}
|
|
3708
|
+
function readVerboseDeployErrorMessage(error) {
|
|
3709
|
+
if (error instanceof index.CliError && error.verboseMessage) {
|
|
3710
|
+
return error.verboseMessage;
|
|
3711
|
+
}
|
|
3712
|
+
return error instanceof Error && error.message ? error.message : String(error);
|
|
3713
|
+
}
|
|
3714
|
+
function suggestNextPatchVersion(version) {
|
|
3715
|
+
const matched = version.match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
3716
|
+
if (!matched) {
|
|
3717
|
+
return '';
|
|
3718
|
+
}
|
|
3719
|
+
return `${matched[1]}.${matched[2]}.${Number(matched[3]) + 1}`;
|
|
3720
|
+
}
|
|
3721
|
+
|
|
3722
|
+
var deploy = /*#__PURE__*/Object.freeze({
|
|
3723
|
+
__proto__: null,
|
|
3724
|
+
resolveDeployReleaseNote: resolveDeployReleaseNote,
|
|
3725
|
+
runDeployCommand: runDeployCommand,
|
|
3726
|
+
validateDeployReleaseNote: validateDeployReleaseNote
|
|
3727
|
+
});
|
|
3728
|
+
|
|
3729
|
+
exports.deploy = deploy;
|
|
3730
|
+
exports.requireSemver = requireSemver;
|