@heybox/hb-sdk 0.8.2-alpha.1 → 0.8.2-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -1
- package/README.md +5 -1
- package/dist/cli-chunks/{build-DFwk1Xza.cjs → build-D2T3ky_9.cjs} +5 -5
- package/dist/cli-chunks/{context-DPwjjbIf.cjs → context-DEgmdpSL.cjs} +326 -104
- package/dist/cli-chunks/{create-Cbk708wm.cjs → create-DKqQhrG5.cjs} +5 -1
- package/dist/cli-chunks/{dev-B1dCAh3V.cjs → dev-BEXM7cmq.cjs} +17 -9
- package/dist/cli-chunks/{doctor-KX6cHAbM.cjs → doctor-B7UixGrd.cjs} +1 -1
- package/dist/cli-chunks/{index-B5GNdZS6.cjs → index-BtwfuoWI.cjs} +15 -17
- package/dist/cli-chunks/{index-D1CfvRqX.cjs → index-C69OtRug.cjs} +2 -2
- package/dist/cli-chunks/{index.esm-BvuovqBQ.cjs → index.esm-C86KlVdK.cjs} +11 -10
- package/dist/cli-chunks/{login-CqdIa3XD.cjs → login-Bp_HMx-i.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-Bw3UJTnC.cjs → project-vite-DZxipd13.cjs} +1 -1
- package/dist/cli-chunks/{remote-t0V-fuAW.cjs → remote-B_sVsbQP.cjs} +80 -60
- package/dist/cli-chunks/runtime-gate-GR9jZd37.cjs +58 -0
- package/dist/cli-chunks/{runtime-gate-BWb8QIcX.cjs → runtime-permission-env-COWketgE.cjs} +4533 -40
- package/dist/cli-chunks/{session-DFY2dygN.cjs → session-6-AApcTZ.cjs} +1 -1
- package/dist/cli-chunks/{skill-D3xHcK8w.cjs → skill-CPDLk7t7.cjs} +2 -2
- package/dist/cli-chunks/{version-DkVq4CXN.cjs → version-hHrSPRwW.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-CpwQQhA1.js +101 -0
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-8J62MOi_.js → desktop-app-launch-BdWBOIvY.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/{index-CrsPiYXy.js → index-BQSEynx6.js} +3 -3
- package/dist/devtools/browser-dev-host/index.html +2 -2
- package/dist/index.cjs.js +946 -42
- package/dist/index.esm.js +946 -42
- package/dist/miniapp-publish.cjs.js +9410 -122
- package/dist/miniapp-publish.esm.js +9406 -123
- package/dist/protocol.cjs.js +805 -0
- package/dist/protocol.esm.js +805 -0
- package/dist/templates/vanilla-vite-js/assets/heybox-placeholder.png +0 -0
- package/dist/templates/vanilla-vite-js/package.json.ejs +3 -0
- package/dist/vite.cjs.js +843 -507
- package/dist/vite.esm.js +844 -508
- package/package.json +8 -7
- package/skill/SKILL.md +5 -1
- package/skill/references/api-root.md +194 -9
- package/skill/references/cli.md +3 -3
- package/skill/references/recipes.md +43 -4
- package/skill/skill.json +5 -5
- package/types/core/errors.d.ts +33 -9
- package/types/core/handshake-state.d.ts +32 -2
- package/types/core/singleton.d.ts +265 -6
- package/types/miniapp-manifest/basic-info-browser.d.ts +9 -0
- package/types/miniapp-manifest/basic-info-image-header.d.ts +6 -0
- package/types/miniapp-manifest/basic-info-node.d.ts +17 -0
- package/types/miniapp-manifest/basic-info-placeholder.d.ts +1 -0
- package/types/miniapp-manifest/basic-info.d.ts +12 -0
- package/types/miniapp-manifest/bindings.d.ts +65 -0
- package/types/miniapp-manifest/schema.d.ts +143 -20
- package/types/miniapp-publish/index.d.ts +433 -29
- package/types/modules/auth/index.d.ts +159 -5
- package/types/modules/cloud/index.d.ts +514 -40
- package/types/modules/companion/index.d.ts +1518 -17
- package/types/modules/device/index.d.ts +140 -9
- package/types/modules/environment/index.d.ts +172 -4
- package/types/modules/files/types.d.ts +1396 -21
- package/types/modules/navigation/app-pages/types.d.ts +81 -24
- package/types/modules/navigation/index.d.ts +230 -7
- package/types/modules/network/index.d.ts +297 -26
- package/types/modules/share/copy-link.d.ts +35 -5
- package/types/modules/share/index.d.ts +210 -0
- package/types/modules/share/screenshot.d.ts +23 -5
- package/types/modules/share/show-share-menu.d.ts +18 -5
- package/types/modules/share/types.d.ts +148 -23
- package/types/modules/storage/index.d.ts +139 -9
- package/types/modules/ui/index.d.ts +249 -18
- package/types/modules/user/get-info.d.ts +29 -8
- package/types/modules/user/index.d.ts +157 -0
- package/types/modules/user/revoke-authorization.d.ts +26 -2
- package/types/modules/user/steam-game-list.d.ts +96 -15
- package/types/modules/viewport/index.d.ts +158 -22
- package/types/protocol/types.d.ts +19 -1
- package/types/vite/index.d.ts +159 -1
- package/dist/cli-chunks/runtime-permission-env-BgYjqHIE.cjs +0 -3942
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-DqPIIvha.js +0 -101
- /package/types/{vite → miniapp-manifest}/runtime-gate.d.ts +0 -0
|
@@ -1,3942 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('node:fs');
|
|
4
|
-
var path = require('node:path');
|
|
5
|
-
var version = require('./version-DkVq4CXN.cjs');
|
|
6
|
-
require('node:crypto');
|
|
7
|
-
var node_async_hooks = require('node:async_hooks');
|
|
8
|
-
|
|
9
|
-
var re = {exports: {}};
|
|
10
|
-
|
|
11
|
-
var constants;
|
|
12
|
-
var hasRequiredConstants;
|
|
13
|
-
|
|
14
|
-
function requireConstants () {
|
|
15
|
-
if (hasRequiredConstants) return constants;
|
|
16
|
-
hasRequiredConstants = 1;
|
|
17
|
-
|
|
18
|
-
// Note: this is the semver.org version of the spec that it implements
|
|
19
|
-
// Not necessarily the package version of this code.
|
|
20
|
-
const SEMVER_SPEC_VERSION = '2.0.0';
|
|
21
|
-
|
|
22
|
-
const MAX_LENGTH = 256;
|
|
23
|
-
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
|
24
|
-
/* istanbul ignore next */ 9007199254740991;
|
|
25
|
-
|
|
26
|
-
// Max safe segment length for coercion.
|
|
27
|
-
const MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
28
|
-
|
|
29
|
-
// Max safe length for a build identifier. The max length minus 6 characters for
|
|
30
|
-
// the shortest version with a build 0.0.0+BUILD.
|
|
31
|
-
const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
32
|
-
|
|
33
|
-
const RELEASE_TYPES = [
|
|
34
|
-
'major',
|
|
35
|
-
'premajor',
|
|
36
|
-
'minor',
|
|
37
|
-
'preminor',
|
|
38
|
-
'patch',
|
|
39
|
-
'prepatch',
|
|
40
|
-
'prerelease',
|
|
41
|
-
];
|
|
42
|
-
|
|
43
|
-
constants = {
|
|
44
|
-
MAX_LENGTH,
|
|
45
|
-
MAX_SAFE_COMPONENT_LENGTH,
|
|
46
|
-
MAX_SAFE_BUILD_LENGTH,
|
|
47
|
-
MAX_SAFE_INTEGER,
|
|
48
|
-
RELEASE_TYPES,
|
|
49
|
-
SEMVER_SPEC_VERSION,
|
|
50
|
-
FLAG_INCLUDE_PRERELEASE: 0b001,
|
|
51
|
-
FLAG_LOOSE: 0b010,
|
|
52
|
-
};
|
|
53
|
-
return constants;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var debug_1;
|
|
57
|
-
var hasRequiredDebug;
|
|
58
|
-
|
|
59
|
-
function requireDebug () {
|
|
60
|
-
if (hasRequiredDebug) return debug_1;
|
|
61
|
-
hasRequiredDebug = 1;
|
|
62
|
-
|
|
63
|
-
const debug = (
|
|
64
|
-
typeof process === 'object' &&
|
|
65
|
-
process.env &&
|
|
66
|
-
process.env.NODE_DEBUG &&
|
|
67
|
-
/\bsemver\b/i.test(process.env.NODE_DEBUG)
|
|
68
|
-
) ? (...args) => console.error('SEMVER', ...args)
|
|
69
|
-
: () => {};
|
|
70
|
-
|
|
71
|
-
debug_1 = debug;
|
|
72
|
-
return debug_1;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var hasRequiredRe;
|
|
76
|
-
|
|
77
|
-
function requireRe () {
|
|
78
|
-
if (hasRequiredRe) return re.exports;
|
|
79
|
-
hasRequiredRe = 1;
|
|
80
|
-
(function (module, exports) {
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
MAX_SAFE_COMPONENT_LENGTH,
|
|
84
|
-
MAX_SAFE_BUILD_LENGTH,
|
|
85
|
-
MAX_LENGTH,
|
|
86
|
-
} = requireConstants();
|
|
87
|
-
const debug = requireDebug();
|
|
88
|
-
exports = module.exports = {};
|
|
89
|
-
|
|
90
|
-
// The actual regexps go on exports.re
|
|
91
|
-
const re = exports.re = [];
|
|
92
|
-
const safeRe = exports.safeRe = [];
|
|
93
|
-
const src = exports.src = [];
|
|
94
|
-
const safeSrc = exports.safeSrc = [];
|
|
95
|
-
const t = exports.t = {};
|
|
96
|
-
let R = 0;
|
|
97
|
-
|
|
98
|
-
const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
|
|
99
|
-
|
|
100
|
-
// Replace some greedy regex tokens to prevent regex dos issues. These regex are
|
|
101
|
-
// used internally via the safeRe object since all inputs in this library get
|
|
102
|
-
// normalized first to trim and collapse all extra whitespace. The original
|
|
103
|
-
// regexes are exported for userland consumption and lower level usage. A
|
|
104
|
-
// future breaking change could export the safer regex only with a note that
|
|
105
|
-
// all input should have extra whitespace removed.
|
|
106
|
-
const safeRegexReplacements = [
|
|
107
|
-
['\\s', 1],
|
|
108
|
-
['\\d', MAX_LENGTH],
|
|
109
|
-
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
const makeSafeRegex = (value) => {
|
|
113
|
-
for (const [token, max] of safeRegexReplacements) {
|
|
114
|
-
value = value
|
|
115
|
-
.split(`${token}*`).join(`${token}{0,${max}}`)
|
|
116
|
-
.split(`${token}+`).join(`${token}{1,${max}}`);
|
|
117
|
-
}
|
|
118
|
-
return value
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const createToken = (name, value, isGlobal) => {
|
|
122
|
-
const safe = makeSafeRegex(value);
|
|
123
|
-
const index = R++;
|
|
124
|
-
debug(name, index, value);
|
|
125
|
-
t[name] = index;
|
|
126
|
-
src[index] = value;
|
|
127
|
-
safeSrc[index] = safe;
|
|
128
|
-
re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
|
|
129
|
-
safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// The following Regular Expressions can be used for tokenizing,
|
|
133
|
-
// validating, and parsing SemVer version strings.
|
|
134
|
-
|
|
135
|
-
// ## Numeric Identifier
|
|
136
|
-
// A single `0`, or a non-zero digit followed by zero or more digits.
|
|
137
|
-
|
|
138
|
-
createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
|
|
139
|
-
createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
|
|
140
|
-
|
|
141
|
-
// ## Non-numeric Identifier
|
|
142
|
-
// Zero or more digits, followed by a letter or hyphen, and then zero or
|
|
143
|
-
// more letters, digits, or hyphens.
|
|
144
|
-
|
|
145
|
-
createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
146
|
-
|
|
147
|
-
// ## Main Version
|
|
148
|
-
// Three dot-separated numeric identifiers.
|
|
149
|
-
|
|
150
|
-
createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
151
|
-
`(${src[t.NUMERICIDENTIFIER]})\\.` +
|
|
152
|
-
`(${src[t.NUMERICIDENTIFIER]})`);
|
|
153
|
-
|
|
154
|
-
createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
155
|
-
`(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
|
|
156
|
-
`(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
157
|
-
|
|
158
|
-
// ## Pre-release Version Identifier
|
|
159
|
-
// A numeric identifier, or a non-numeric identifier.
|
|
160
|
-
// Non-numeric identifiers include numeric identifiers but can be longer.
|
|
161
|
-
// Therefore non-numeric identifiers must go first.
|
|
162
|
-
|
|
163
|
-
createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
164
|
-
}|${src[t.NUMERICIDENTIFIER]})`);
|
|
165
|
-
|
|
166
|
-
createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
|
|
167
|
-
}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
168
|
-
|
|
169
|
-
// ## Pre-release Version
|
|
170
|
-
// Hyphen, followed by one or more dot-separated pre-release version
|
|
171
|
-
// identifiers.
|
|
172
|
-
|
|
173
|
-
createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
|
|
174
|
-
}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
175
|
-
|
|
176
|
-
createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
|
|
177
|
-
}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
178
|
-
|
|
179
|
-
// ## Build Metadata Identifier
|
|
180
|
-
// Any combination of digits, letters, or hyphens.
|
|
181
|
-
|
|
182
|
-
createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
|
|
183
|
-
|
|
184
|
-
// ## Build Metadata
|
|
185
|
-
// Plus sign, followed by one or more period-separated build metadata
|
|
186
|
-
// identifiers.
|
|
187
|
-
|
|
188
|
-
createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
|
|
189
|
-
}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
190
|
-
|
|
191
|
-
// ## Full Version String
|
|
192
|
-
// A main version, followed optionally by a pre-release version and
|
|
193
|
-
// build metadata.
|
|
194
|
-
|
|
195
|
-
// Note that the only major, minor, patch, and pre-release sections of
|
|
196
|
-
// the version string are capturing groups. The build metadata is not a
|
|
197
|
-
// capturing group, because it should not ever be used in version
|
|
198
|
-
// comparison.
|
|
199
|
-
|
|
200
|
-
createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
|
|
201
|
-
}${src[t.PRERELEASE]}?${
|
|
202
|
-
src[t.BUILD]}?`);
|
|
203
|
-
|
|
204
|
-
createToken('FULL', `^${src[t.FULLPLAIN]}$`);
|
|
205
|
-
|
|
206
|
-
// like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
|
|
207
|
-
// also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
|
|
208
|
-
// common in the npm registry.
|
|
209
|
-
createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
|
|
210
|
-
}${src[t.PRERELEASELOOSE]}?${
|
|
211
|
-
src[t.BUILD]}?`);
|
|
212
|
-
|
|
213
|
-
createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
|
|
214
|
-
|
|
215
|
-
createToken('GTLT', '((?:<|>)?=?)');
|
|
216
|
-
|
|
217
|
-
// Something like "2.*" or "1.2.x".
|
|
218
|
-
// Note that "x.x" is a valid xRange identifier, meaning "any version"
|
|
219
|
-
// Only the first item is strictly required.
|
|
220
|
-
createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
221
|
-
createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
222
|
-
|
|
223
|
-
createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
|
|
224
|
-
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
225
|
-
`(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
|
|
226
|
-
`(?:${src[t.PRERELEASE]})?${
|
|
227
|
-
src[t.BUILD]}?` +
|
|
228
|
-
`)?)?`);
|
|
229
|
-
|
|
230
|
-
createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
231
|
-
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
232
|
-
`(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
|
|
233
|
-
`(?:${src[t.PRERELEASELOOSE]})?${
|
|
234
|
-
src[t.BUILD]}?` +
|
|
235
|
-
`)?)?`);
|
|
236
|
-
|
|
237
|
-
createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
238
|
-
createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
239
|
-
|
|
240
|
-
// Coercion.
|
|
241
|
-
// Extract anything that could conceivably be a part of a valid semver
|
|
242
|
-
createToken('COERCEPLAIN', `${'(^|[^\\d])' +
|
|
243
|
-
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
|
|
244
|
-
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
|
245
|
-
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
246
|
-
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
247
|
-
createToken('COERCEFULL', src[t.COERCEPLAIN] +
|
|
248
|
-
`(?:${src[t.PRERELEASE]})?` +
|
|
249
|
-
`(?:${src[t.BUILD]})?` +
|
|
250
|
-
`(?:$|[^\\d])`);
|
|
251
|
-
createToken('COERCERTL', src[t.COERCE], true);
|
|
252
|
-
createToken('COERCERTLFULL', src[t.COERCEFULL], true);
|
|
253
|
-
|
|
254
|
-
// Tilde ranges.
|
|
255
|
-
// Meaning is "reasonably at or greater than"
|
|
256
|
-
createToken('LONETILDE', '(?:~>?)');
|
|
257
|
-
|
|
258
|
-
createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
259
|
-
exports.tildeTrimReplace = '$1~';
|
|
260
|
-
|
|
261
|
-
createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
262
|
-
createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
263
|
-
|
|
264
|
-
// Caret ranges.
|
|
265
|
-
// Meaning is "at least and backwards compatible with"
|
|
266
|
-
createToken('LONECARET', '(?:\\^)');
|
|
267
|
-
|
|
268
|
-
createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
269
|
-
exports.caretTrimReplace = '$1^';
|
|
270
|
-
|
|
271
|
-
createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
272
|
-
createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
273
|
-
|
|
274
|
-
// A simple gt/lt/eq thing, or just "" to indicate "any version"
|
|
275
|
-
createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
276
|
-
createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
277
|
-
|
|
278
|
-
// An expression to strip any whitespace between the gtlt and the thing
|
|
279
|
-
// it modifies, so that `> 1.2.3` ==> `>1.2.3`
|
|
280
|
-
createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
|
|
281
|
-
}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
282
|
-
exports.comparatorTrimReplace = '$1$2$3';
|
|
283
|
-
|
|
284
|
-
// Something like `1.2.3 - 1.2.4`
|
|
285
|
-
// Note that these all use the loose form, because they'll be
|
|
286
|
-
// checked against either the strict or loose comparator form
|
|
287
|
-
// later.
|
|
288
|
-
createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
|
|
289
|
-
`\\s+-\\s+` +
|
|
290
|
-
`(${src[t.XRANGEPLAIN]})` +
|
|
291
|
-
`\\s*$`);
|
|
292
|
-
|
|
293
|
-
createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
|
|
294
|
-
`\\s+-\\s+` +
|
|
295
|
-
`(${src[t.XRANGEPLAINLOOSE]})` +
|
|
296
|
-
`\\s*$`);
|
|
297
|
-
|
|
298
|
-
// Star ranges basically just allow anything at all.
|
|
299
|
-
createToken('STAR', '(<|>)?=?\\s*\\*');
|
|
300
|
-
// >=0.0.0 is like a star
|
|
301
|
-
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
|
|
302
|
-
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
|
|
303
|
-
} (re, re.exports));
|
|
304
|
-
return re.exports;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
var parseOptions_1;
|
|
308
|
-
var hasRequiredParseOptions;
|
|
309
|
-
|
|
310
|
-
function requireParseOptions () {
|
|
311
|
-
if (hasRequiredParseOptions) return parseOptions_1;
|
|
312
|
-
hasRequiredParseOptions = 1;
|
|
313
|
-
|
|
314
|
-
// parse out just the options we care about
|
|
315
|
-
const looseOption = Object.freeze({ loose: true });
|
|
316
|
-
const emptyOpts = Object.freeze({ });
|
|
317
|
-
const parseOptions = options => {
|
|
318
|
-
if (!options) {
|
|
319
|
-
return emptyOpts
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (typeof options !== 'object') {
|
|
323
|
-
return looseOption
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return options
|
|
327
|
-
};
|
|
328
|
-
parseOptions_1 = parseOptions;
|
|
329
|
-
return parseOptions_1;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
var identifiers;
|
|
333
|
-
var hasRequiredIdentifiers;
|
|
334
|
-
|
|
335
|
-
function requireIdentifiers () {
|
|
336
|
-
if (hasRequiredIdentifiers) return identifiers;
|
|
337
|
-
hasRequiredIdentifiers = 1;
|
|
338
|
-
|
|
339
|
-
const numeric = /^[0-9]+$/;
|
|
340
|
-
const compareIdentifiers = (a, b) => {
|
|
341
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
342
|
-
return a === b ? 0 : a < b ? -1 : 1
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const anum = numeric.test(a);
|
|
346
|
-
const bnum = numeric.test(b);
|
|
347
|
-
|
|
348
|
-
if (anum && bnum) {
|
|
349
|
-
a = +a;
|
|
350
|
-
b = +b;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return a === b ? 0
|
|
354
|
-
: (anum && !bnum) ? -1
|
|
355
|
-
: (bnum && !anum) ? 1
|
|
356
|
-
: a < b ? -1
|
|
357
|
-
: 1
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
|
|
361
|
-
|
|
362
|
-
identifiers = {
|
|
363
|
-
compareIdentifiers,
|
|
364
|
-
rcompareIdentifiers,
|
|
365
|
-
};
|
|
366
|
-
return identifiers;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
var semver$1;
|
|
370
|
-
var hasRequiredSemver$1;
|
|
371
|
-
|
|
372
|
-
function requireSemver$1 () {
|
|
373
|
-
if (hasRequiredSemver$1) return semver$1;
|
|
374
|
-
hasRequiredSemver$1 = 1;
|
|
375
|
-
|
|
376
|
-
const debug = requireDebug();
|
|
377
|
-
const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
|
|
378
|
-
const { safeRe: re, t } = requireRe();
|
|
379
|
-
|
|
380
|
-
const parseOptions = requireParseOptions();
|
|
381
|
-
const { compareIdentifiers } = requireIdentifiers();
|
|
382
|
-
class SemVer {
|
|
383
|
-
constructor (version, options) {
|
|
384
|
-
options = parseOptions(options);
|
|
385
|
-
|
|
386
|
-
if (version instanceof SemVer) {
|
|
387
|
-
if (version.loose === !!options.loose &&
|
|
388
|
-
version.includePrerelease === !!options.includePrerelease) {
|
|
389
|
-
return version
|
|
390
|
-
} else {
|
|
391
|
-
version = version.version;
|
|
392
|
-
}
|
|
393
|
-
} else if (typeof version !== 'string') {
|
|
394
|
-
throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (version.length > MAX_LENGTH) {
|
|
398
|
-
throw new TypeError(
|
|
399
|
-
`version is longer than ${MAX_LENGTH} characters`
|
|
400
|
-
)
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
debug('SemVer', version, options);
|
|
404
|
-
this.options = options;
|
|
405
|
-
this.loose = !!options.loose;
|
|
406
|
-
// this isn't actually relevant for versions, but keep it so that we
|
|
407
|
-
// don't run into trouble passing this.options around.
|
|
408
|
-
this.includePrerelease = !!options.includePrerelease;
|
|
409
|
-
|
|
410
|
-
const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
|
|
411
|
-
|
|
412
|
-
if (!m) {
|
|
413
|
-
throw new TypeError(`Invalid Version: ${version}`)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
this.raw = version;
|
|
417
|
-
|
|
418
|
-
// these are actually numbers
|
|
419
|
-
this.major = +m[1];
|
|
420
|
-
this.minor = +m[2];
|
|
421
|
-
this.patch = +m[3];
|
|
422
|
-
|
|
423
|
-
if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
|
|
424
|
-
throw new TypeError('Invalid major version')
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
|
|
428
|
-
throw new TypeError('Invalid minor version')
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
|
|
432
|
-
throw new TypeError('Invalid patch version')
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
// numberify any prerelease numeric ids
|
|
436
|
-
if (!m[4]) {
|
|
437
|
-
this.prerelease = [];
|
|
438
|
-
} else {
|
|
439
|
-
this.prerelease = m[4].split('.').map((id) => {
|
|
440
|
-
if (/^[0-9]+$/.test(id)) {
|
|
441
|
-
const num = +id;
|
|
442
|
-
if (num >= 0 && num < MAX_SAFE_INTEGER) {
|
|
443
|
-
return num
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return id
|
|
447
|
-
});
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
this.build = m[5] ? m[5].split('.') : [];
|
|
451
|
-
this.format();
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
format () {
|
|
455
|
-
this.version = `${this.major}.${this.minor}.${this.patch}`;
|
|
456
|
-
if (this.prerelease.length) {
|
|
457
|
-
this.version += `-${this.prerelease.join('.')}`;
|
|
458
|
-
}
|
|
459
|
-
return this.version
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
toString () {
|
|
463
|
-
return this.version
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
compare (other) {
|
|
467
|
-
debug('SemVer.compare', this.version, this.options, other);
|
|
468
|
-
if (!(other instanceof SemVer)) {
|
|
469
|
-
if (typeof other === 'string' && other === this.version) {
|
|
470
|
-
return 0
|
|
471
|
-
}
|
|
472
|
-
other = new SemVer(other, this.options);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (other.version === this.version) {
|
|
476
|
-
return 0
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
return this.compareMain(other) || this.comparePre(other)
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
compareMain (other) {
|
|
483
|
-
if (!(other instanceof SemVer)) {
|
|
484
|
-
other = new SemVer(other, this.options);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
if (this.major < other.major) {
|
|
488
|
-
return -1
|
|
489
|
-
}
|
|
490
|
-
if (this.major > other.major) {
|
|
491
|
-
return 1
|
|
492
|
-
}
|
|
493
|
-
if (this.minor < other.minor) {
|
|
494
|
-
return -1
|
|
495
|
-
}
|
|
496
|
-
if (this.minor > other.minor) {
|
|
497
|
-
return 1
|
|
498
|
-
}
|
|
499
|
-
if (this.patch < other.patch) {
|
|
500
|
-
return -1
|
|
501
|
-
}
|
|
502
|
-
if (this.patch > other.patch) {
|
|
503
|
-
return 1
|
|
504
|
-
}
|
|
505
|
-
return 0
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
comparePre (other) {
|
|
509
|
-
if (!(other instanceof SemVer)) {
|
|
510
|
-
other = new SemVer(other, this.options);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
// NOT having a prerelease is > having one
|
|
514
|
-
if (this.prerelease.length && !other.prerelease.length) {
|
|
515
|
-
return -1
|
|
516
|
-
} else if (!this.prerelease.length && other.prerelease.length) {
|
|
517
|
-
return 1
|
|
518
|
-
} else if (!this.prerelease.length && !other.prerelease.length) {
|
|
519
|
-
return 0
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
let i = 0;
|
|
523
|
-
do {
|
|
524
|
-
const a = this.prerelease[i];
|
|
525
|
-
const b = other.prerelease[i];
|
|
526
|
-
debug('prerelease compare', i, a, b);
|
|
527
|
-
if (a === undefined && b === undefined) {
|
|
528
|
-
return 0
|
|
529
|
-
} else if (b === undefined) {
|
|
530
|
-
return 1
|
|
531
|
-
} else if (a === undefined) {
|
|
532
|
-
return -1
|
|
533
|
-
} else if (a === b) {
|
|
534
|
-
continue
|
|
535
|
-
} else {
|
|
536
|
-
return compareIdentifiers(a, b)
|
|
537
|
-
}
|
|
538
|
-
} while (++i)
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
compareBuild (other) {
|
|
542
|
-
if (!(other instanceof SemVer)) {
|
|
543
|
-
other = new SemVer(other, this.options);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
let i = 0;
|
|
547
|
-
do {
|
|
548
|
-
const a = this.build[i];
|
|
549
|
-
const b = other.build[i];
|
|
550
|
-
debug('build compare', i, a, b);
|
|
551
|
-
if (a === undefined && b === undefined) {
|
|
552
|
-
return 0
|
|
553
|
-
} else if (b === undefined) {
|
|
554
|
-
return 1
|
|
555
|
-
} else if (a === undefined) {
|
|
556
|
-
return -1
|
|
557
|
-
} else if (a === b) {
|
|
558
|
-
continue
|
|
559
|
-
} else {
|
|
560
|
-
return compareIdentifiers(a, b)
|
|
561
|
-
}
|
|
562
|
-
} while (++i)
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// preminor will bump the version up to the next minor release, and immediately
|
|
566
|
-
// down to pre-release. premajor and prepatch work the same way.
|
|
567
|
-
inc (release, identifier, identifierBase) {
|
|
568
|
-
if (release.startsWith('pre')) {
|
|
569
|
-
if (!identifier && identifierBase === false) {
|
|
570
|
-
throw new Error('invalid increment argument: identifier is empty')
|
|
571
|
-
}
|
|
572
|
-
// Avoid an invalid semver results
|
|
573
|
-
if (identifier) {
|
|
574
|
-
const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
|
|
575
|
-
if (!match || match[1] !== identifier) {
|
|
576
|
-
throw new Error(`invalid identifier: ${identifier}`)
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
switch (release) {
|
|
582
|
-
case 'premajor':
|
|
583
|
-
this.prerelease.length = 0;
|
|
584
|
-
this.patch = 0;
|
|
585
|
-
this.minor = 0;
|
|
586
|
-
this.major++;
|
|
587
|
-
this.inc('pre', identifier, identifierBase);
|
|
588
|
-
break
|
|
589
|
-
case 'preminor':
|
|
590
|
-
this.prerelease.length = 0;
|
|
591
|
-
this.patch = 0;
|
|
592
|
-
this.minor++;
|
|
593
|
-
this.inc('pre', identifier, identifierBase);
|
|
594
|
-
break
|
|
595
|
-
case 'prepatch':
|
|
596
|
-
// If this is already a prerelease, it will bump to the next version
|
|
597
|
-
// drop any prereleases that might already exist, since they are not
|
|
598
|
-
// relevant at this point.
|
|
599
|
-
this.prerelease.length = 0;
|
|
600
|
-
this.inc('patch', identifier, identifierBase);
|
|
601
|
-
this.inc('pre', identifier, identifierBase);
|
|
602
|
-
break
|
|
603
|
-
// If the input is a non-prerelease version, this acts the same as
|
|
604
|
-
// prepatch.
|
|
605
|
-
case 'prerelease':
|
|
606
|
-
if (this.prerelease.length === 0) {
|
|
607
|
-
this.inc('patch', identifier, identifierBase);
|
|
608
|
-
}
|
|
609
|
-
this.inc('pre', identifier, identifierBase);
|
|
610
|
-
break
|
|
611
|
-
case 'release':
|
|
612
|
-
if (this.prerelease.length === 0) {
|
|
613
|
-
throw new Error(`version ${this.raw} is not a prerelease`)
|
|
614
|
-
}
|
|
615
|
-
this.prerelease.length = 0;
|
|
616
|
-
break
|
|
617
|
-
|
|
618
|
-
case 'major':
|
|
619
|
-
// If this is a pre-major version, bump up to the same major version.
|
|
620
|
-
// Otherwise increment major.
|
|
621
|
-
// 1.0.0-5 bumps to 1.0.0
|
|
622
|
-
// 1.1.0 bumps to 2.0.0
|
|
623
|
-
if (
|
|
624
|
-
this.minor !== 0 ||
|
|
625
|
-
this.patch !== 0 ||
|
|
626
|
-
this.prerelease.length === 0
|
|
627
|
-
) {
|
|
628
|
-
this.major++;
|
|
629
|
-
}
|
|
630
|
-
this.minor = 0;
|
|
631
|
-
this.patch = 0;
|
|
632
|
-
this.prerelease = [];
|
|
633
|
-
break
|
|
634
|
-
case 'minor':
|
|
635
|
-
// If this is a pre-minor version, bump up to the same minor version.
|
|
636
|
-
// Otherwise increment minor.
|
|
637
|
-
// 1.2.0-5 bumps to 1.2.0
|
|
638
|
-
// 1.2.1 bumps to 1.3.0
|
|
639
|
-
if (this.patch !== 0 || this.prerelease.length === 0) {
|
|
640
|
-
this.minor++;
|
|
641
|
-
}
|
|
642
|
-
this.patch = 0;
|
|
643
|
-
this.prerelease = [];
|
|
644
|
-
break
|
|
645
|
-
case 'patch':
|
|
646
|
-
// If this is not a pre-release version, it will increment the patch.
|
|
647
|
-
// If it is a pre-release it will bump up to the same patch version.
|
|
648
|
-
// 1.2.0-5 patches to 1.2.0
|
|
649
|
-
// 1.2.0 patches to 1.2.1
|
|
650
|
-
if (this.prerelease.length === 0) {
|
|
651
|
-
this.patch++;
|
|
652
|
-
}
|
|
653
|
-
this.prerelease = [];
|
|
654
|
-
break
|
|
655
|
-
// This probably shouldn't be used publicly.
|
|
656
|
-
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
|
|
657
|
-
case 'pre': {
|
|
658
|
-
const base = Number(identifierBase) ? 1 : 0;
|
|
659
|
-
|
|
660
|
-
if (this.prerelease.length === 0) {
|
|
661
|
-
this.prerelease = [base];
|
|
662
|
-
} else {
|
|
663
|
-
let i = this.prerelease.length;
|
|
664
|
-
while (--i >= 0) {
|
|
665
|
-
if (typeof this.prerelease[i] === 'number') {
|
|
666
|
-
this.prerelease[i]++;
|
|
667
|
-
i = -2;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
if (i === -1) {
|
|
671
|
-
// didn't increment anything
|
|
672
|
-
if (identifier === this.prerelease.join('.') && identifierBase === false) {
|
|
673
|
-
throw new Error('invalid increment argument: identifier already exists')
|
|
674
|
-
}
|
|
675
|
-
this.prerelease.push(base);
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
if (identifier) {
|
|
679
|
-
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
680
|
-
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
681
|
-
let prerelease = [identifier, base];
|
|
682
|
-
if (identifierBase === false) {
|
|
683
|
-
prerelease = [identifier];
|
|
684
|
-
}
|
|
685
|
-
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
686
|
-
if (isNaN(this.prerelease[1])) {
|
|
687
|
-
this.prerelease = prerelease;
|
|
688
|
-
}
|
|
689
|
-
} else {
|
|
690
|
-
this.prerelease = prerelease;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
break
|
|
694
|
-
}
|
|
695
|
-
default:
|
|
696
|
-
throw new Error(`invalid increment argument: ${release}`)
|
|
697
|
-
}
|
|
698
|
-
this.raw = this.format();
|
|
699
|
-
if (this.build.length) {
|
|
700
|
-
this.raw += `+${this.build.join('.')}`;
|
|
701
|
-
}
|
|
702
|
-
return this
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
semver$1 = SemVer;
|
|
707
|
-
return semver$1;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
var parse_1;
|
|
711
|
-
var hasRequiredParse;
|
|
712
|
-
|
|
713
|
-
function requireParse () {
|
|
714
|
-
if (hasRequiredParse) return parse_1;
|
|
715
|
-
hasRequiredParse = 1;
|
|
716
|
-
|
|
717
|
-
const SemVer = requireSemver$1();
|
|
718
|
-
const parse = (version, options, throwErrors = false) => {
|
|
719
|
-
if (version instanceof SemVer) {
|
|
720
|
-
return version
|
|
721
|
-
}
|
|
722
|
-
try {
|
|
723
|
-
return new SemVer(version, options)
|
|
724
|
-
} catch (er) {
|
|
725
|
-
if (!throwErrors) {
|
|
726
|
-
return null
|
|
727
|
-
}
|
|
728
|
-
throw er
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
|
|
732
|
-
parse_1 = parse;
|
|
733
|
-
return parse_1;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
var valid_1;
|
|
737
|
-
var hasRequiredValid$1;
|
|
738
|
-
|
|
739
|
-
function requireValid$1 () {
|
|
740
|
-
if (hasRequiredValid$1) return valid_1;
|
|
741
|
-
hasRequiredValid$1 = 1;
|
|
742
|
-
|
|
743
|
-
const parse = requireParse();
|
|
744
|
-
const valid = (version, options) => {
|
|
745
|
-
const v = parse(version, options);
|
|
746
|
-
return v ? v.version : null
|
|
747
|
-
};
|
|
748
|
-
valid_1 = valid;
|
|
749
|
-
return valid_1;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
var clean_1;
|
|
753
|
-
var hasRequiredClean;
|
|
754
|
-
|
|
755
|
-
function requireClean () {
|
|
756
|
-
if (hasRequiredClean) return clean_1;
|
|
757
|
-
hasRequiredClean = 1;
|
|
758
|
-
|
|
759
|
-
const parse = requireParse();
|
|
760
|
-
const clean = (version, options) => {
|
|
761
|
-
const s = parse(version.trim().replace(/^[=v]+/, ''), options);
|
|
762
|
-
return s ? s.version : null
|
|
763
|
-
};
|
|
764
|
-
clean_1 = clean;
|
|
765
|
-
return clean_1;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
var inc_1;
|
|
769
|
-
var hasRequiredInc;
|
|
770
|
-
|
|
771
|
-
function requireInc () {
|
|
772
|
-
if (hasRequiredInc) return inc_1;
|
|
773
|
-
hasRequiredInc = 1;
|
|
774
|
-
|
|
775
|
-
const SemVer = requireSemver$1();
|
|
776
|
-
|
|
777
|
-
const inc = (version, release, options, identifier, identifierBase) => {
|
|
778
|
-
if (typeof (options) === 'string') {
|
|
779
|
-
identifierBase = identifier;
|
|
780
|
-
identifier = options;
|
|
781
|
-
options = undefined;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
try {
|
|
785
|
-
return new SemVer(
|
|
786
|
-
version instanceof SemVer ? version.version : version,
|
|
787
|
-
options
|
|
788
|
-
).inc(release, identifier, identifierBase).version
|
|
789
|
-
} catch (er) {
|
|
790
|
-
return null
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
inc_1 = inc;
|
|
794
|
-
return inc_1;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
var diff_1;
|
|
798
|
-
var hasRequiredDiff;
|
|
799
|
-
|
|
800
|
-
function requireDiff () {
|
|
801
|
-
if (hasRequiredDiff) return diff_1;
|
|
802
|
-
hasRequiredDiff = 1;
|
|
803
|
-
|
|
804
|
-
const parse = requireParse();
|
|
805
|
-
|
|
806
|
-
const diff = (version1, version2) => {
|
|
807
|
-
const v1 = parse(version1, null, true);
|
|
808
|
-
const v2 = parse(version2, null, true);
|
|
809
|
-
const comparison = v1.compare(v2);
|
|
810
|
-
|
|
811
|
-
if (comparison === 0) {
|
|
812
|
-
return null
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
const v1Higher = comparison > 0;
|
|
816
|
-
const highVersion = v1Higher ? v1 : v2;
|
|
817
|
-
const lowVersion = v1Higher ? v2 : v1;
|
|
818
|
-
const highHasPre = !!highVersion.prerelease.length;
|
|
819
|
-
const lowHasPre = !!lowVersion.prerelease.length;
|
|
820
|
-
|
|
821
|
-
if (lowHasPre && !highHasPre) {
|
|
822
|
-
// Going from prerelease -> no prerelease requires some special casing
|
|
823
|
-
|
|
824
|
-
// If the low version has only a major, then it will always be a major
|
|
825
|
-
// Some examples:
|
|
826
|
-
// 1.0.0-1 -> 1.0.0
|
|
827
|
-
// 1.0.0-1 -> 1.1.1
|
|
828
|
-
// 1.0.0-1 -> 2.0.0
|
|
829
|
-
if (!lowVersion.patch && !lowVersion.minor) {
|
|
830
|
-
return 'major'
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// If the main part has no difference
|
|
834
|
-
if (lowVersion.compareMain(highVersion) === 0) {
|
|
835
|
-
if (lowVersion.minor && !lowVersion.patch) {
|
|
836
|
-
return 'minor'
|
|
837
|
-
}
|
|
838
|
-
return 'patch'
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
// add the `pre` prefix if we are going to a prerelease version
|
|
843
|
-
const prefix = highHasPre ? 'pre' : '';
|
|
844
|
-
|
|
845
|
-
if (v1.major !== v2.major) {
|
|
846
|
-
return prefix + 'major'
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
if (v1.minor !== v2.minor) {
|
|
850
|
-
return prefix + 'minor'
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (v1.patch !== v2.patch) {
|
|
854
|
-
return prefix + 'patch'
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// high and low are prereleases
|
|
858
|
-
return 'prerelease'
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
diff_1 = diff;
|
|
862
|
-
return diff_1;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
var major_1;
|
|
866
|
-
var hasRequiredMajor;
|
|
867
|
-
|
|
868
|
-
function requireMajor () {
|
|
869
|
-
if (hasRequiredMajor) return major_1;
|
|
870
|
-
hasRequiredMajor = 1;
|
|
871
|
-
|
|
872
|
-
const SemVer = requireSemver$1();
|
|
873
|
-
const major = (a, loose) => new SemVer(a, loose).major;
|
|
874
|
-
major_1 = major;
|
|
875
|
-
return major_1;
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
var minor_1;
|
|
879
|
-
var hasRequiredMinor;
|
|
880
|
-
|
|
881
|
-
function requireMinor () {
|
|
882
|
-
if (hasRequiredMinor) return minor_1;
|
|
883
|
-
hasRequiredMinor = 1;
|
|
884
|
-
|
|
885
|
-
const SemVer = requireSemver$1();
|
|
886
|
-
const minor = (a, loose) => new SemVer(a, loose).minor;
|
|
887
|
-
minor_1 = minor;
|
|
888
|
-
return minor_1;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
var patch_1;
|
|
892
|
-
var hasRequiredPatch;
|
|
893
|
-
|
|
894
|
-
function requirePatch () {
|
|
895
|
-
if (hasRequiredPatch) return patch_1;
|
|
896
|
-
hasRequiredPatch = 1;
|
|
897
|
-
|
|
898
|
-
const SemVer = requireSemver$1();
|
|
899
|
-
const patch = (a, loose) => new SemVer(a, loose).patch;
|
|
900
|
-
patch_1 = patch;
|
|
901
|
-
return patch_1;
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
var prerelease_1;
|
|
905
|
-
var hasRequiredPrerelease;
|
|
906
|
-
|
|
907
|
-
function requirePrerelease () {
|
|
908
|
-
if (hasRequiredPrerelease) return prerelease_1;
|
|
909
|
-
hasRequiredPrerelease = 1;
|
|
910
|
-
|
|
911
|
-
const parse = requireParse();
|
|
912
|
-
const prerelease = (version, options) => {
|
|
913
|
-
const parsed = parse(version, options);
|
|
914
|
-
return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
|
|
915
|
-
};
|
|
916
|
-
prerelease_1 = prerelease;
|
|
917
|
-
return prerelease_1;
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
var compare_1;
|
|
921
|
-
var hasRequiredCompare;
|
|
922
|
-
|
|
923
|
-
function requireCompare () {
|
|
924
|
-
if (hasRequiredCompare) return compare_1;
|
|
925
|
-
hasRequiredCompare = 1;
|
|
926
|
-
|
|
927
|
-
const SemVer = requireSemver$1();
|
|
928
|
-
const compare = (a, b, loose) =>
|
|
929
|
-
new SemVer(a, loose).compare(new SemVer(b, loose));
|
|
930
|
-
|
|
931
|
-
compare_1 = compare;
|
|
932
|
-
return compare_1;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
var rcompare_1;
|
|
936
|
-
var hasRequiredRcompare;
|
|
937
|
-
|
|
938
|
-
function requireRcompare () {
|
|
939
|
-
if (hasRequiredRcompare) return rcompare_1;
|
|
940
|
-
hasRequiredRcompare = 1;
|
|
941
|
-
|
|
942
|
-
const compare = requireCompare();
|
|
943
|
-
const rcompare = (a, b, loose) => compare(b, a, loose);
|
|
944
|
-
rcompare_1 = rcompare;
|
|
945
|
-
return rcompare_1;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
var compareLoose_1;
|
|
949
|
-
var hasRequiredCompareLoose;
|
|
950
|
-
|
|
951
|
-
function requireCompareLoose () {
|
|
952
|
-
if (hasRequiredCompareLoose) return compareLoose_1;
|
|
953
|
-
hasRequiredCompareLoose = 1;
|
|
954
|
-
|
|
955
|
-
const compare = requireCompare();
|
|
956
|
-
const compareLoose = (a, b) => compare(a, b, true);
|
|
957
|
-
compareLoose_1 = compareLoose;
|
|
958
|
-
return compareLoose_1;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
var compareBuild_1;
|
|
962
|
-
var hasRequiredCompareBuild;
|
|
963
|
-
|
|
964
|
-
function requireCompareBuild () {
|
|
965
|
-
if (hasRequiredCompareBuild) return compareBuild_1;
|
|
966
|
-
hasRequiredCompareBuild = 1;
|
|
967
|
-
|
|
968
|
-
const SemVer = requireSemver$1();
|
|
969
|
-
const compareBuild = (a, b, loose) => {
|
|
970
|
-
const versionA = new SemVer(a, loose);
|
|
971
|
-
const versionB = new SemVer(b, loose);
|
|
972
|
-
return versionA.compare(versionB) || versionA.compareBuild(versionB)
|
|
973
|
-
};
|
|
974
|
-
compareBuild_1 = compareBuild;
|
|
975
|
-
return compareBuild_1;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
var sort_1;
|
|
979
|
-
var hasRequiredSort;
|
|
980
|
-
|
|
981
|
-
function requireSort () {
|
|
982
|
-
if (hasRequiredSort) return sort_1;
|
|
983
|
-
hasRequiredSort = 1;
|
|
984
|
-
|
|
985
|
-
const compareBuild = requireCompareBuild();
|
|
986
|
-
const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
|
|
987
|
-
sort_1 = sort;
|
|
988
|
-
return sort_1;
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
var rsort_1;
|
|
992
|
-
var hasRequiredRsort;
|
|
993
|
-
|
|
994
|
-
function requireRsort () {
|
|
995
|
-
if (hasRequiredRsort) return rsort_1;
|
|
996
|
-
hasRequiredRsort = 1;
|
|
997
|
-
|
|
998
|
-
const compareBuild = requireCompareBuild();
|
|
999
|
-
const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
|
|
1000
|
-
rsort_1 = rsort;
|
|
1001
|
-
return rsort_1;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
var gt_1;
|
|
1005
|
-
var hasRequiredGt;
|
|
1006
|
-
|
|
1007
|
-
function requireGt () {
|
|
1008
|
-
if (hasRequiredGt) return gt_1;
|
|
1009
|
-
hasRequiredGt = 1;
|
|
1010
|
-
|
|
1011
|
-
const compare = requireCompare();
|
|
1012
|
-
const gt = (a, b, loose) => compare(a, b, loose) > 0;
|
|
1013
|
-
gt_1 = gt;
|
|
1014
|
-
return gt_1;
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
var lt_1;
|
|
1018
|
-
var hasRequiredLt;
|
|
1019
|
-
|
|
1020
|
-
function requireLt () {
|
|
1021
|
-
if (hasRequiredLt) return lt_1;
|
|
1022
|
-
hasRequiredLt = 1;
|
|
1023
|
-
|
|
1024
|
-
const compare = requireCompare();
|
|
1025
|
-
const lt = (a, b, loose) => compare(a, b, loose) < 0;
|
|
1026
|
-
lt_1 = lt;
|
|
1027
|
-
return lt_1;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
var eq_1;
|
|
1031
|
-
var hasRequiredEq;
|
|
1032
|
-
|
|
1033
|
-
function requireEq () {
|
|
1034
|
-
if (hasRequiredEq) return eq_1;
|
|
1035
|
-
hasRequiredEq = 1;
|
|
1036
|
-
|
|
1037
|
-
const compare = requireCompare();
|
|
1038
|
-
const eq = (a, b, loose) => compare(a, b, loose) === 0;
|
|
1039
|
-
eq_1 = eq;
|
|
1040
|
-
return eq_1;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
var neq_1;
|
|
1044
|
-
var hasRequiredNeq;
|
|
1045
|
-
|
|
1046
|
-
function requireNeq () {
|
|
1047
|
-
if (hasRequiredNeq) return neq_1;
|
|
1048
|
-
hasRequiredNeq = 1;
|
|
1049
|
-
|
|
1050
|
-
const compare = requireCompare();
|
|
1051
|
-
const neq = (a, b, loose) => compare(a, b, loose) !== 0;
|
|
1052
|
-
neq_1 = neq;
|
|
1053
|
-
return neq_1;
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
var gte_1;
|
|
1057
|
-
var hasRequiredGte;
|
|
1058
|
-
|
|
1059
|
-
function requireGte () {
|
|
1060
|
-
if (hasRequiredGte) return gte_1;
|
|
1061
|
-
hasRequiredGte = 1;
|
|
1062
|
-
|
|
1063
|
-
const compare = requireCompare();
|
|
1064
|
-
const gte = (a, b, loose) => compare(a, b, loose) >= 0;
|
|
1065
|
-
gte_1 = gte;
|
|
1066
|
-
return gte_1;
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
var lte_1;
|
|
1070
|
-
var hasRequiredLte;
|
|
1071
|
-
|
|
1072
|
-
function requireLte () {
|
|
1073
|
-
if (hasRequiredLte) return lte_1;
|
|
1074
|
-
hasRequiredLte = 1;
|
|
1075
|
-
|
|
1076
|
-
const compare = requireCompare();
|
|
1077
|
-
const lte = (a, b, loose) => compare(a, b, loose) <= 0;
|
|
1078
|
-
lte_1 = lte;
|
|
1079
|
-
return lte_1;
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
var cmp_1;
|
|
1083
|
-
var hasRequiredCmp;
|
|
1084
|
-
|
|
1085
|
-
function requireCmp () {
|
|
1086
|
-
if (hasRequiredCmp) return cmp_1;
|
|
1087
|
-
hasRequiredCmp = 1;
|
|
1088
|
-
|
|
1089
|
-
const eq = requireEq();
|
|
1090
|
-
const neq = requireNeq();
|
|
1091
|
-
const gt = requireGt();
|
|
1092
|
-
const gte = requireGte();
|
|
1093
|
-
const lt = requireLt();
|
|
1094
|
-
const lte = requireLte();
|
|
1095
|
-
|
|
1096
|
-
const cmp = (a, op, b, loose) => {
|
|
1097
|
-
switch (op) {
|
|
1098
|
-
case '===':
|
|
1099
|
-
if (typeof a === 'object') {
|
|
1100
|
-
a = a.version;
|
|
1101
|
-
}
|
|
1102
|
-
if (typeof b === 'object') {
|
|
1103
|
-
b = b.version;
|
|
1104
|
-
}
|
|
1105
|
-
return a === b
|
|
1106
|
-
|
|
1107
|
-
case '!==':
|
|
1108
|
-
if (typeof a === 'object') {
|
|
1109
|
-
a = a.version;
|
|
1110
|
-
}
|
|
1111
|
-
if (typeof b === 'object') {
|
|
1112
|
-
b = b.version;
|
|
1113
|
-
}
|
|
1114
|
-
return a !== b
|
|
1115
|
-
|
|
1116
|
-
case '':
|
|
1117
|
-
case '=':
|
|
1118
|
-
case '==':
|
|
1119
|
-
return eq(a, b, loose)
|
|
1120
|
-
|
|
1121
|
-
case '!=':
|
|
1122
|
-
return neq(a, b, loose)
|
|
1123
|
-
|
|
1124
|
-
case '>':
|
|
1125
|
-
return gt(a, b, loose)
|
|
1126
|
-
|
|
1127
|
-
case '>=':
|
|
1128
|
-
return gte(a, b, loose)
|
|
1129
|
-
|
|
1130
|
-
case '<':
|
|
1131
|
-
return lt(a, b, loose)
|
|
1132
|
-
|
|
1133
|
-
case '<=':
|
|
1134
|
-
return lte(a, b, loose)
|
|
1135
|
-
|
|
1136
|
-
default:
|
|
1137
|
-
throw new TypeError(`Invalid operator: ${op}`)
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
cmp_1 = cmp;
|
|
1141
|
-
return cmp_1;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
var coerce_1;
|
|
1145
|
-
var hasRequiredCoerce;
|
|
1146
|
-
|
|
1147
|
-
function requireCoerce () {
|
|
1148
|
-
if (hasRequiredCoerce) return coerce_1;
|
|
1149
|
-
hasRequiredCoerce = 1;
|
|
1150
|
-
|
|
1151
|
-
const SemVer = requireSemver$1();
|
|
1152
|
-
const parse = requireParse();
|
|
1153
|
-
const { safeRe: re, t } = requireRe();
|
|
1154
|
-
|
|
1155
|
-
const coerce = (version, options) => {
|
|
1156
|
-
if (version instanceof SemVer) {
|
|
1157
|
-
return version
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
if (typeof version === 'number') {
|
|
1161
|
-
version = String(version);
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
if (typeof version !== 'string') {
|
|
1165
|
-
return null
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
options = options || {};
|
|
1169
|
-
|
|
1170
|
-
let match = null;
|
|
1171
|
-
if (!options.rtl) {
|
|
1172
|
-
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
|
|
1173
|
-
} else {
|
|
1174
|
-
// Find the right-most coercible string that does not share
|
|
1175
|
-
// a terminus with a more left-ward coercible string.
|
|
1176
|
-
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
|
1177
|
-
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
|
|
1178
|
-
//
|
|
1179
|
-
// Walk through the string checking with a /g regexp
|
|
1180
|
-
// Manually set the index so as to pick up overlapping matches.
|
|
1181
|
-
// Stop when we get a match that ends at the string end, since no
|
|
1182
|
-
// coercible string can be more right-ward without the same terminus.
|
|
1183
|
-
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
|
|
1184
|
-
let next;
|
|
1185
|
-
while ((next = coerceRtlRegex.exec(version)) &&
|
|
1186
|
-
(!match || match.index + match[0].length !== version.length)
|
|
1187
|
-
) {
|
|
1188
|
-
if (!match ||
|
|
1189
|
-
next.index + next[0].length !== match.index + match[0].length) {
|
|
1190
|
-
match = next;
|
|
1191
|
-
}
|
|
1192
|
-
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
|
|
1193
|
-
}
|
|
1194
|
-
// leave it in a clean state
|
|
1195
|
-
coerceRtlRegex.lastIndex = -1;
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
|
-
if (match === null) {
|
|
1199
|
-
return null
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
const major = match[2];
|
|
1203
|
-
const minor = match[3] || '0';
|
|
1204
|
-
const patch = match[4] || '0';
|
|
1205
|
-
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
|
|
1206
|
-
const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
|
|
1207
|
-
|
|
1208
|
-
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
|
|
1209
|
-
};
|
|
1210
|
-
coerce_1 = coerce;
|
|
1211
|
-
return coerce_1;
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
var truncate_1;
|
|
1215
|
-
var hasRequiredTruncate;
|
|
1216
|
-
|
|
1217
|
-
function requireTruncate () {
|
|
1218
|
-
if (hasRequiredTruncate) return truncate_1;
|
|
1219
|
-
hasRequiredTruncate = 1;
|
|
1220
|
-
|
|
1221
|
-
const parse = requireParse();
|
|
1222
|
-
const constants = requireConstants();
|
|
1223
|
-
const SemVer = requireSemver$1();
|
|
1224
|
-
|
|
1225
|
-
const truncate = (version, truncation, options) => {
|
|
1226
|
-
if (!constants.RELEASE_TYPES.includes(truncation)) {
|
|
1227
|
-
return null
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
const clonedVersion = cloneInputVersion(version, options);
|
|
1231
|
-
return clonedVersion && doTruncation(clonedVersion, truncation)
|
|
1232
|
-
};
|
|
1233
|
-
|
|
1234
|
-
const cloneInputVersion = (version, options) => {
|
|
1235
|
-
const versionStringToParse = (
|
|
1236
|
-
version instanceof SemVer ? version.version : version
|
|
1237
|
-
);
|
|
1238
|
-
|
|
1239
|
-
return parse(versionStringToParse, options)
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
|
-
const doTruncation = (version, truncation) => {
|
|
1243
|
-
if (isPrerelease(truncation)) {
|
|
1244
|
-
return version.version
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
version.prerelease = [];
|
|
1248
|
-
|
|
1249
|
-
switch (truncation) {
|
|
1250
|
-
case 'major':
|
|
1251
|
-
version.minor = 0;
|
|
1252
|
-
version.patch = 0;
|
|
1253
|
-
break
|
|
1254
|
-
case 'minor':
|
|
1255
|
-
version.patch = 0;
|
|
1256
|
-
break
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
return version.format()
|
|
1260
|
-
};
|
|
1261
|
-
|
|
1262
|
-
const isPrerelease = (type) => {
|
|
1263
|
-
return type.startsWith('pre')
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
truncate_1 = truncate;
|
|
1267
|
-
return truncate_1;
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
var lrucache;
|
|
1271
|
-
var hasRequiredLrucache;
|
|
1272
|
-
|
|
1273
|
-
function requireLrucache () {
|
|
1274
|
-
if (hasRequiredLrucache) return lrucache;
|
|
1275
|
-
hasRequiredLrucache = 1;
|
|
1276
|
-
|
|
1277
|
-
class LRUCache {
|
|
1278
|
-
constructor () {
|
|
1279
|
-
this.max = 1000;
|
|
1280
|
-
this.map = new Map();
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
get (key) {
|
|
1284
|
-
const value = this.map.get(key);
|
|
1285
|
-
if (value === undefined) {
|
|
1286
|
-
return undefined
|
|
1287
|
-
} else {
|
|
1288
|
-
// Remove the key from the map and add it to the end
|
|
1289
|
-
this.map.delete(key);
|
|
1290
|
-
this.map.set(key, value);
|
|
1291
|
-
return value
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
delete (key) {
|
|
1296
|
-
return this.map.delete(key)
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
set (key, value) {
|
|
1300
|
-
const deleted = this.delete(key);
|
|
1301
|
-
|
|
1302
|
-
if (!deleted && value !== undefined) {
|
|
1303
|
-
// If cache is full, delete the least recently used item
|
|
1304
|
-
if (this.map.size >= this.max) {
|
|
1305
|
-
const firstKey = this.map.keys().next().value;
|
|
1306
|
-
this.delete(firstKey);
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
this.map.set(key, value);
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
return this
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
lrucache = LRUCache;
|
|
1317
|
-
return lrucache;
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
var range;
|
|
1321
|
-
var hasRequiredRange;
|
|
1322
|
-
|
|
1323
|
-
function requireRange () {
|
|
1324
|
-
if (hasRequiredRange) return range;
|
|
1325
|
-
hasRequiredRange = 1;
|
|
1326
|
-
|
|
1327
|
-
const SPACE_CHARACTERS = /\s+/g;
|
|
1328
|
-
|
|
1329
|
-
// hoisted class for cyclic dependency
|
|
1330
|
-
class Range {
|
|
1331
|
-
constructor (range, options) {
|
|
1332
|
-
options = parseOptions(options);
|
|
1333
|
-
|
|
1334
|
-
if (range instanceof Range) {
|
|
1335
|
-
if (
|
|
1336
|
-
range.loose === !!options.loose &&
|
|
1337
|
-
range.includePrerelease === !!options.includePrerelease
|
|
1338
|
-
) {
|
|
1339
|
-
return range
|
|
1340
|
-
} else {
|
|
1341
|
-
return new Range(range.raw, options)
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
if (range instanceof Comparator) {
|
|
1346
|
-
// just put it in the set and return
|
|
1347
|
-
this.raw = range.value;
|
|
1348
|
-
this.set = [[range]];
|
|
1349
|
-
this.formatted = undefined;
|
|
1350
|
-
return this
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
this.options = options;
|
|
1354
|
-
this.loose = !!options.loose;
|
|
1355
|
-
this.includePrerelease = !!options.includePrerelease;
|
|
1356
|
-
|
|
1357
|
-
// First reduce all whitespace as much as possible so we do not have to rely
|
|
1358
|
-
// on potentially slow regexes like \s*. This is then stored and used for
|
|
1359
|
-
// future error messages as well.
|
|
1360
|
-
this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
|
|
1361
|
-
|
|
1362
|
-
// First, split on ||
|
|
1363
|
-
this.set = this.raw
|
|
1364
|
-
.split('||')
|
|
1365
|
-
// map the range to a 2d array of comparators
|
|
1366
|
-
.map(r => this.parseRange(r.trim()))
|
|
1367
|
-
// throw out any comparator lists that are empty
|
|
1368
|
-
// this generally means that it was not a valid range, which is allowed
|
|
1369
|
-
// in loose mode, but will still throw if the WHOLE range is invalid.
|
|
1370
|
-
.filter(c => c.length);
|
|
1371
|
-
|
|
1372
|
-
if (!this.set.length) {
|
|
1373
|
-
throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
|
|
1374
|
-
}
|
|
1375
|
-
|
|
1376
|
-
// if we have any that are not the null set, throw out null sets.
|
|
1377
|
-
if (this.set.length > 1) {
|
|
1378
|
-
// keep the first one, in case they're all null sets
|
|
1379
|
-
const first = this.set[0];
|
|
1380
|
-
this.set = this.set.filter(c => !isNullSet(c[0]));
|
|
1381
|
-
if (this.set.length === 0) {
|
|
1382
|
-
this.set = [first];
|
|
1383
|
-
} else if (this.set.length > 1) {
|
|
1384
|
-
// if we have any that are *, then the range is just *
|
|
1385
|
-
for (const c of this.set) {
|
|
1386
|
-
if (c.length === 1 && isAny(c[0])) {
|
|
1387
|
-
this.set = [c];
|
|
1388
|
-
break
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
this.formatted = undefined;
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
get range () {
|
|
1398
|
-
if (this.formatted === undefined) {
|
|
1399
|
-
this.formatted = '';
|
|
1400
|
-
for (let i = 0; i < this.set.length; i++) {
|
|
1401
|
-
if (i > 0) {
|
|
1402
|
-
this.formatted += '||';
|
|
1403
|
-
}
|
|
1404
|
-
const comps = this.set[i];
|
|
1405
|
-
for (let k = 0; k < comps.length; k++) {
|
|
1406
|
-
if (k > 0) {
|
|
1407
|
-
this.formatted += ' ';
|
|
1408
|
-
}
|
|
1409
|
-
this.formatted += comps[k].toString().trim();
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
return this.formatted
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
format () {
|
|
1417
|
-
return this.range
|
|
1418
|
-
}
|
|
1419
|
-
|
|
1420
|
-
toString () {
|
|
1421
|
-
return this.range
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
parseRange (range) {
|
|
1425
|
-
// strip build metadata so it can't bleed into the version
|
|
1426
|
-
range = range.replace(BUILDSTRIPRE, '');
|
|
1427
|
-
|
|
1428
|
-
// memoize range parsing for performance.
|
|
1429
|
-
// this is a very hot path, and fully deterministic.
|
|
1430
|
-
const memoOpts =
|
|
1431
|
-
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
|
|
1432
|
-
(this.options.loose && FLAG_LOOSE);
|
|
1433
|
-
const memoKey = memoOpts + ':' + range;
|
|
1434
|
-
const cached = cache.get(memoKey);
|
|
1435
|
-
if (cached) {
|
|
1436
|
-
return cached
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
const loose = this.options.loose;
|
|
1440
|
-
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
1441
|
-
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
|
|
1442
|
-
range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
|
|
1443
|
-
debug('hyphen replace', range);
|
|
1444
|
-
|
|
1445
|
-
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
1446
|
-
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
|
|
1447
|
-
debug('comparator trim', range);
|
|
1448
|
-
|
|
1449
|
-
// `~ 1.2.3` => `~1.2.3`
|
|
1450
|
-
range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
|
|
1451
|
-
debug('tilde trim', range);
|
|
1452
|
-
|
|
1453
|
-
// `^ 1.2.3` => `^1.2.3`
|
|
1454
|
-
range = range.replace(re[t.CARETTRIM], caretTrimReplace);
|
|
1455
|
-
debug('caret trim', range);
|
|
1456
|
-
|
|
1457
|
-
// At this point, the range is completely trimmed and
|
|
1458
|
-
// ready to be split into comparators.
|
|
1459
|
-
|
|
1460
|
-
let rangeList = range
|
|
1461
|
-
.split(' ')
|
|
1462
|
-
.map(comp => parseComparator(comp, this.options))
|
|
1463
|
-
.join(' ')
|
|
1464
|
-
.split(/\s+/)
|
|
1465
|
-
// >=0.0.0 is equivalent to *
|
|
1466
|
-
.map(comp => replaceGTE0(comp, this.options));
|
|
1467
|
-
|
|
1468
|
-
if (loose) {
|
|
1469
|
-
// in loose mode, throw out any that are not valid comparators
|
|
1470
|
-
rangeList = rangeList.filter(comp => {
|
|
1471
|
-
debug('loose invalid filter', comp, this.options);
|
|
1472
|
-
return !!comp.match(re[t.COMPARATORLOOSE])
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
debug('range list', rangeList);
|
|
1476
|
-
|
|
1477
|
-
// if any comparators are the null set, then replace with JUST null set
|
|
1478
|
-
// if more than one comparator, remove any * comparators
|
|
1479
|
-
// also, don't include the same comparator more than once
|
|
1480
|
-
const rangeMap = new Map();
|
|
1481
|
-
const comparators = rangeList.map(comp => new Comparator(comp, this.options));
|
|
1482
|
-
for (const comp of comparators) {
|
|
1483
|
-
if (isNullSet(comp)) {
|
|
1484
|
-
return [comp]
|
|
1485
|
-
}
|
|
1486
|
-
rangeMap.set(comp.value, comp);
|
|
1487
|
-
}
|
|
1488
|
-
if (rangeMap.size > 1 && rangeMap.has('')) {
|
|
1489
|
-
rangeMap.delete('');
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
const result = [...rangeMap.values()];
|
|
1493
|
-
cache.set(memoKey, result);
|
|
1494
|
-
return result
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
intersects (range, options) {
|
|
1498
|
-
if (!(range instanceof Range)) {
|
|
1499
|
-
throw new TypeError('a Range is required')
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
return this.set.some((thisComparators) => {
|
|
1503
|
-
return (
|
|
1504
|
-
isSatisfiable(thisComparators, options) &&
|
|
1505
|
-
range.set.some((rangeComparators) => {
|
|
1506
|
-
return (
|
|
1507
|
-
isSatisfiable(rangeComparators, options) &&
|
|
1508
|
-
thisComparators.every((thisComparator) => {
|
|
1509
|
-
return rangeComparators.every((rangeComparator) => {
|
|
1510
|
-
return thisComparator.intersects(rangeComparator, options)
|
|
1511
|
-
})
|
|
1512
|
-
})
|
|
1513
|
-
)
|
|
1514
|
-
})
|
|
1515
|
-
)
|
|
1516
|
-
})
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
// if ANY of the sets match ALL of its comparators, then pass
|
|
1520
|
-
test (version) {
|
|
1521
|
-
if (!version) {
|
|
1522
|
-
return false
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
if (typeof version === 'string') {
|
|
1526
|
-
try {
|
|
1527
|
-
version = new SemVer(version, this.options);
|
|
1528
|
-
} catch (er) {
|
|
1529
|
-
return false
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
for (let i = 0; i < this.set.length; i++) {
|
|
1534
|
-
if (testSet(this.set[i], version, this.options)) {
|
|
1535
|
-
return true
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
return false
|
|
1539
|
-
}
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
range = Range;
|
|
1543
|
-
|
|
1544
|
-
const LRU = requireLrucache();
|
|
1545
|
-
const cache = new LRU();
|
|
1546
|
-
|
|
1547
|
-
const parseOptions = requireParseOptions();
|
|
1548
|
-
const Comparator = requireComparator();
|
|
1549
|
-
const debug = requireDebug();
|
|
1550
|
-
const SemVer = requireSemver$1();
|
|
1551
|
-
const {
|
|
1552
|
-
safeRe: re,
|
|
1553
|
-
src,
|
|
1554
|
-
t,
|
|
1555
|
-
comparatorTrimReplace,
|
|
1556
|
-
tildeTrimReplace,
|
|
1557
|
-
caretTrimReplace,
|
|
1558
|
-
} = requireRe();
|
|
1559
|
-
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = requireConstants();
|
|
1560
|
-
|
|
1561
|
-
// unbounded global build-metadata stripper used by parseRange
|
|
1562
|
-
const BUILDSTRIPRE = new RegExp(src[t.BUILD], 'g');
|
|
1563
|
-
|
|
1564
|
-
const isNullSet = c => c.value === '<0.0.0-0';
|
|
1565
|
-
const isAny = c => c.value === '';
|
|
1566
|
-
|
|
1567
|
-
// take a set of comparators and determine whether there
|
|
1568
|
-
// exists a version which can satisfy it
|
|
1569
|
-
const isSatisfiable = (comparators, options) => {
|
|
1570
|
-
let result = true;
|
|
1571
|
-
const remainingComparators = comparators.slice();
|
|
1572
|
-
let testComparator = remainingComparators.pop();
|
|
1573
|
-
|
|
1574
|
-
while (result && remainingComparators.length) {
|
|
1575
|
-
result = remainingComparators.every((otherComparator) => {
|
|
1576
|
-
return testComparator.intersects(otherComparator, options)
|
|
1577
|
-
});
|
|
1578
|
-
|
|
1579
|
-
testComparator = remainingComparators.pop();
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
return result
|
|
1583
|
-
};
|
|
1584
|
-
|
|
1585
|
-
// comprised of xranges, tildes, stars, and gtlt's at this point.
|
|
1586
|
-
// already replaced the hyphen ranges
|
|
1587
|
-
// turn into a set of JUST comparators.
|
|
1588
|
-
const parseComparator = (comp, options) => {
|
|
1589
|
-
comp = comp.replace(re[t.BUILD], '');
|
|
1590
|
-
debug('comp', comp, options);
|
|
1591
|
-
comp = replaceCarets(comp, options);
|
|
1592
|
-
debug('caret', comp);
|
|
1593
|
-
comp = replaceTildes(comp, options);
|
|
1594
|
-
debug('tildes', comp);
|
|
1595
|
-
comp = replaceXRanges(comp, options);
|
|
1596
|
-
debug('xrange', comp);
|
|
1597
|
-
comp = replaceStars(comp, options);
|
|
1598
|
-
debug('stars', comp);
|
|
1599
|
-
return comp
|
|
1600
|
-
};
|
|
1601
|
-
|
|
1602
|
-
const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
|
|
1603
|
-
|
|
1604
|
-
// ~, ~> --> * (any, kinda silly)
|
|
1605
|
-
// ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
|
|
1606
|
-
// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
|
|
1607
|
-
// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
|
|
1608
|
-
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
1609
|
-
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
1610
|
-
// ~0.0.1 --> >=0.0.1 <0.1.0-0
|
|
1611
|
-
const replaceTildes = (comp, options) => {
|
|
1612
|
-
return comp
|
|
1613
|
-
.trim()
|
|
1614
|
-
.split(/\s+/)
|
|
1615
|
-
.map((c) => replaceTilde(c, options))
|
|
1616
|
-
.join(' ')
|
|
1617
|
-
};
|
|
1618
|
-
|
|
1619
|
-
const replaceTilde = (comp, options) => {
|
|
1620
|
-
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
|
|
1621
|
-
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1622
|
-
debug('tilde', comp, _, M, m, p, pr);
|
|
1623
|
-
let ret;
|
|
1624
|
-
|
|
1625
|
-
if (isX(M)) {
|
|
1626
|
-
ret = '';
|
|
1627
|
-
} else if (isX(m)) {
|
|
1628
|
-
ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
|
|
1629
|
-
} else if (isX(p)) {
|
|
1630
|
-
// ~1.2 == >=1.2.0 <1.3.0-0
|
|
1631
|
-
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
|
|
1632
|
-
} else if (pr) {
|
|
1633
|
-
debug('replaceTilde pr', pr);
|
|
1634
|
-
ret = `>=${M}.${m}.${p}-${pr
|
|
1635
|
-
} <${M}.${+m + 1}.0-0`;
|
|
1636
|
-
} else {
|
|
1637
|
-
// ~1.2.3 == >=1.2.3 <1.3.0-0
|
|
1638
|
-
ret = `>=${M}.${m}.${p
|
|
1639
|
-
} <${M}.${+m + 1}.0-0`;
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
debug('tilde return', ret);
|
|
1643
|
-
return ret
|
|
1644
|
-
})
|
|
1645
|
-
};
|
|
1646
|
-
|
|
1647
|
-
// ^ --> * (any, kinda silly)
|
|
1648
|
-
// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
|
|
1649
|
-
// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
|
|
1650
|
-
// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
|
|
1651
|
-
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
1652
|
-
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
1653
|
-
// ^0.0.1 --> >=0.0.1 <0.0.2-0
|
|
1654
|
-
// ^0.1.0 --> >=0.1.0 <0.2.0-0
|
|
1655
|
-
const replaceCarets = (comp, options) => {
|
|
1656
|
-
return comp
|
|
1657
|
-
.trim()
|
|
1658
|
-
.split(/\s+/)
|
|
1659
|
-
.map((c) => replaceCaret(c, options))
|
|
1660
|
-
.join(' ')
|
|
1661
|
-
};
|
|
1662
|
-
|
|
1663
|
-
const replaceCaret = (comp, options) => {
|
|
1664
|
-
debug('caret', comp, options);
|
|
1665
|
-
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
|
|
1666
|
-
const z = options.includePrerelease ? '-0' : '';
|
|
1667
|
-
return comp.replace(r, (_, M, m, p, pr) => {
|
|
1668
|
-
debug('caret', comp, _, M, m, p, pr);
|
|
1669
|
-
let ret;
|
|
1670
|
-
|
|
1671
|
-
if (isX(M)) {
|
|
1672
|
-
ret = '';
|
|
1673
|
-
} else if (isX(m)) {
|
|
1674
|
-
ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
|
|
1675
|
-
} else if (isX(p)) {
|
|
1676
|
-
if (M === '0') {
|
|
1677
|
-
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
|
|
1678
|
-
} else {
|
|
1679
|
-
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
|
|
1680
|
-
}
|
|
1681
|
-
} else if (pr) {
|
|
1682
|
-
debug('replaceCaret pr', pr);
|
|
1683
|
-
if (M === '0') {
|
|
1684
|
-
if (m === '0') {
|
|
1685
|
-
ret = `>=${M}.${m}.${p}-${pr
|
|
1686
|
-
} <${M}.${m}.${+p + 1}-0`;
|
|
1687
|
-
} else {
|
|
1688
|
-
ret = `>=${M}.${m}.${p}-${pr
|
|
1689
|
-
} <${M}.${+m + 1}.0-0`;
|
|
1690
|
-
}
|
|
1691
|
-
} else {
|
|
1692
|
-
ret = `>=${M}.${m}.${p}-${pr
|
|
1693
|
-
} <${+M + 1}.0.0-0`;
|
|
1694
|
-
}
|
|
1695
|
-
} else {
|
|
1696
|
-
debug('no pr');
|
|
1697
|
-
if (M === '0') {
|
|
1698
|
-
if (m === '0') {
|
|
1699
|
-
ret = `>=${M}.${m}.${p
|
|
1700
|
-
}${z} <${M}.${m}.${+p + 1}-0`;
|
|
1701
|
-
} else {
|
|
1702
|
-
ret = `>=${M}.${m}.${p
|
|
1703
|
-
}${z} <${M}.${+m + 1}.0-0`;
|
|
1704
|
-
}
|
|
1705
|
-
} else {
|
|
1706
|
-
ret = `>=${M}.${m}.${p
|
|
1707
|
-
} <${+M + 1}.0.0-0`;
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
debug('caret return', ret);
|
|
1712
|
-
return ret
|
|
1713
|
-
})
|
|
1714
|
-
};
|
|
1715
|
-
|
|
1716
|
-
const replaceXRanges = (comp, options) => {
|
|
1717
|
-
debug('replaceXRanges', comp, options);
|
|
1718
|
-
return comp
|
|
1719
|
-
.split(/\s+/)
|
|
1720
|
-
.map((c) => replaceXRange(c, options))
|
|
1721
|
-
.join(' ')
|
|
1722
|
-
};
|
|
1723
|
-
|
|
1724
|
-
const replaceXRange = (comp, options) => {
|
|
1725
|
-
comp = comp.trim();
|
|
1726
|
-
const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
|
|
1727
|
-
return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
|
|
1728
|
-
debug('xRange', comp, ret, gtlt, M, m, p, pr);
|
|
1729
|
-
const xM = isX(M);
|
|
1730
|
-
const xm = xM || isX(m);
|
|
1731
|
-
const xp = xm || isX(p);
|
|
1732
|
-
const anyX = xp;
|
|
1733
|
-
|
|
1734
|
-
if (gtlt === '=' && anyX) {
|
|
1735
|
-
gtlt = '';
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
// if we're including prereleases in the match, then we need
|
|
1739
|
-
// to fix this to -0, the lowest possible prerelease value
|
|
1740
|
-
pr = options.includePrerelease ? '-0' : '';
|
|
1741
|
-
|
|
1742
|
-
if (xM) {
|
|
1743
|
-
if (gtlt === '>' || gtlt === '<') {
|
|
1744
|
-
// nothing is allowed
|
|
1745
|
-
ret = '<0.0.0-0';
|
|
1746
|
-
} else {
|
|
1747
|
-
// nothing is forbidden
|
|
1748
|
-
ret = '*';
|
|
1749
|
-
}
|
|
1750
|
-
} else if (gtlt && anyX) {
|
|
1751
|
-
// we know patch is an x, because we have any x at all.
|
|
1752
|
-
// replace X with 0
|
|
1753
|
-
if (xm) {
|
|
1754
|
-
m = 0;
|
|
1755
|
-
}
|
|
1756
|
-
p = 0;
|
|
1757
|
-
|
|
1758
|
-
if (gtlt === '>') {
|
|
1759
|
-
// >1 => >=2.0.0
|
|
1760
|
-
// >1.2 => >=1.3.0
|
|
1761
|
-
gtlt = '>=';
|
|
1762
|
-
if (xm) {
|
|
1763
|
-
M = +M + 1;
|
|
1764
|
-
m = 0;
|
|
1765
|
-
p = 0;
|
|
1766
|
-
} else {
|
|
1767
|
-
m = +m + 1;
|
|
1768
|
-
p = 0;
|
|
1769
|
-
}
|
|
1770
|
-
} else if (gtlt === '<=') {
|
|
1771
|
-
// <=0.7.x is actually <0.8.0, since any 0.7.x should
|
|
1772
|
-
// pass. Similarly, <=7.x is actually <8.0.0, etc.
|
|
1773
|
-
gtlt = '<';
|
|
1774
|
-
if (xm) {
|
|
1775
|
-
M = +M + 1;
|
|
1776
|
-
} else {
|
|
1777
|
-
m = +m + 1;
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
if (gtlt === '<') {
|
|
1782
|
-
pr = '-0';
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
ret = `${gtlt + M}.${m}.${p}${pr}`;
|
|
1786
|
-
} else if (xm) {
|
|
1787
|
-
ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
|
|
1788
|
-
} else if (xp) {
|
|
1789
|
-
ret = `>=${M}.${m}.0${pr
|
|
1790
|
-
} <${M}.${+m + 1}.0-0`;
|
|
1791
|
-
}
|
|
1792
|
-
|
|
1793
|
-
debug('xRange return', ret);
|
|
1794
|
-
|
|
1795
|
-
return ret
|
|
1796
|
-
})
|
|
1797
|
-
};
|
|
1798
|
-
|
|
1799
|
-
// Because * is AND-ed with everything else in the comparator,
|
|
1800
|
-
// and '' means "any version", just remove the *s entirely.
|
|
1801
|
-
const replaceStars = (comp, options) => {
|
|
1802
|
-
debug('replaceStars', comp, options);
|
|
1803
|
-
// Looseness is ignored here. star is always as loose as it gets!
|
|
1804
|
-
return comp
|
|
1805
|
-
.trim()
|
|
1806
|
-
.replace(re[t.STAR], '')
|
|
1807
|
-
};
|
|
1808
|
-
|
|
1809
|
-
const replaceGTE0 = (comp, options) => {
|
|
1810
|
-
debug('replaceGTE0', comp, options);
|
|
1811
|
-
return comp
|
|
1812
|
-
.trim()
|
|
1813
|
-
.replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
|
|
1814
|
-
};
|
|
1815
|
-
|
|
1816
|
-
// This function is passed to string.replace(re[t.HYPHENRANGE])
|
|
1817
|
-
// M, m, patch, prerelease, build
|
|
1818
|
-
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
1819
|
-
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
|
|
1820
|
-
// 1.2 - 3.4 => >=1.2.0 <3.5.0-0
|
|
1821
|
-
// TODO build?
|
|
1822
|
-
const hyphenReplace = incPr => ($0,
|
|
1823
|
-
from, fM, fm, fp, fpr, fb,
|
|
1824
|
-
to, tM, tm, tp, tpr) => {
|
|
1825
|
-
if (isX(fM)) {
|
|
1826
|
-
from = '';
|
|
1827
|
-
} else if (isX(fm)) {
|
|
1828
|
-
from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
|
|
1829
|
-
} else if (isX(fp)) {
|
|
1830
|
-
from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
|
|
1831
|
-
} else if (fpr) {
|
|
1832
|
-
from = `>=${from}`;
|
|
1833
|
-
} else {
|
|
1834
|
-
from = `>=${from}${incPr ? '-0' : ''}`;
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
if (isX(tM)) {
|
|
1838
|
-
to = '';
|
|
1839
|
-
} else if (isX(tm)) {
|
|
1840
|
-
to = `<${+tM + 1}.0.0-0`;
|
|
1841
|
-
} else if (isX(tp)) {
|
|
1842
|
-
to = `<${tM}.${+tm + 1}.0-0`;
|
|
1843
|
-
} else if (tpr) {
|
|
1844
|
-
to = `<=${tM}.${tm}.${tp}-${tpr}`;
|
|
1845
|
-
} else if (incPr) {
|
|
1846
|
-
to = `<${tM}.${tm}.${+tp + 1}-0`;
|
|
1847
|
-
} else {
|
|
1848
|
-
to = `<=${to}`;
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
return `${from} ${to}`.trim()
|
|
1852
|
-
};
|
|
1853
|
-
|
|
1854
|
-
const testSet = (set, version, options) => {
|
|
1855
|
-
for (let i = 0; i < set.length; i++) {
|
|
1856
|
-
if (!set[i].test(version)) {
|
|
1857
|
-
return false
|
|
1858
|
-
}
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
if (version.prerelease.length && !options.includePrerelease) {
|
|
1862
|
-
// Find the set of versions that are allowed to have prereleases
|
|
1863
|
-
// For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
|
|
1864
|
-
// That should allow `1.2.3-pr.2` to pass.
|
|
1865
|
-
// However, `1.2.4-alpha.notready` should NOT be allowed,
|
|
1866
|
-
// even though it's within the range set by the comparators.
|
|
1867
|
-
for (let i = 0; i < set.length; i++) {
|
|
1868
|
-
debug(set[i].semver);
|
|
1869
|
-
if (set[i].semver === Comparator.ANY) {
|
|
1870
|
-
continue
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
if (set[i].semver.prerelease.length > 0) {
|
|
1874
|
-
const allowed = set[i].semver;
|
|
1875
|
-
if (allowed.major === version.major &&
|
|
1876
|
-
allowed.minor === version.minor &&
|
|
1877
|
-
allowed.patch === version.patch) {
|
|
1878
|
-
return true
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
// Version has a -pre, but it's not one of the ones we like.
|
|
1884
|
-
return false
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
return true
|
|
1888
|
-
};
|
|
1889
|
-
return range;
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
var comparator;
|
|
1893
|
-
var hasRequiredComparator;
|
|
1894
|
-
|
|
1895
|
-
function requireComparator () {
|
|
1896
|
-
if (hasRequiredComparator) return comparator;
|
|
1897
|
-
hasRequiredComparator = 1;
|
|
1898
|
-
|
|
1899
|
-
const ANY = Symbol('SemVer ANY');
|
|
1900
|
-
// hoisted class for cyclic dependency
|
|
1901
|
-
class Comparator {
|
|
1902
|
-
static get ANY () {
|
|
1903
|
-
return ANY
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
constructor (comp, options) {
|
|
1907
|
-
options = parseOptions(options);
|
|
1908
|
-
|
|
1909
|
-
if (comp instanceof Comparator) {
|
|
1910
|
-
if (comp.loose === !!options.loose) {
|
|
1911
|
-
return comp
|
|
1912
|
-
} else {
|
|
1913
|
-
comp = comp.value;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
comp = comp.trim().split(/\s+/).join(' ');
|
|
1918
|
-
debug('comparator', comp, options);
|
|
1919
|
-
this.options = options;
|
|
1920
|
-
this.loose = !!options.loose;
|
|
1921
|
-
this.parse(comp);
|
|
1922
|
-
|
|
1923
|
-
if (this.semver === ANY) {
|
|
1924
|
-
this.value = '';
|
|
1925
|
-
} else {
|
|
1926
|
-
this.value = this.operator + this.semver.version;
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
debug('comp', this);
|
|
1930
|
-
}
|
|
1931
|
-
|
|
1932
|
-
parse (comp) {
|
|
1933
|
-
const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
|
|
1934
|
-
const m = comp.match(r);
|
|
1935
|
-
|
|
1936
|
-
if (!m) {
|
|
1937
|
-
throw new TypeError(`Invalid comparator: ${comp}`)
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
this.operator = m[1] !== undefined ? m[1] : '';
|
|
1941
|
-
if (this.operator === '=') {
|
|
1942
|
-
this.operator = '';
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
// if it literally is just '>' or '' then allow anything.
|
|
1946
|
-
if (!m[2]) {
|
|
1947
|
-
this.semver = ANY;
|
|
1948
|
-
} else {
|
|
1949
|
-
this.semver = new SemVer(m[2], this.options.loose);
|
|
1950
|
-
}
|
|
1951
|
-
}
|
|
1952
|
-
|
|
1953
|
-
toString () {
|
|
1954
|
-
return this.value
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
test (version) {
|
|
1958
|
-
debug('Comparator.test', version, this.options.loose);
|
|
1959
|
-
|
|
1960
|
-
if (this.semver === ANY || version === ANY) {
|
|
1961
|
-
return true
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
if (typeof version === 'string') {
|
|
1965
|
-
try {
|
|
1966
|
-
version = new SemVer(version, this.options);
|
|
1967
|
-
} catch (er) {
|
|
1968
|
-
return false
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
|
|
1972
|
-
return cmp(version, this.operator, this.semver, this.options)
|
|
1973
|
-
}
|
|
1974
|
-
|
|
1975
|
-
intersects (comp, options) {
|
|
1976
|
-
if (!(comp instanceof Comparator)) {
|
|
1977
|
-
throw new TypeError('a Comparator is required')
|
|
1978
|
-
}
|
|
1979
|
-
|
|
1980
|
-
if (this.operator === '') {
|
|
1981
|
-
if (this.value === '') {
|
|
1982
|
-
return true
|
|
1983
|
-
}
|
|
1984
|
-
return new Range(comp.value, options).test(this.value)
|
|
1985
|
-
} else if (comp.operator === '') {
|
|
1986
|
-
if (comp.value === '') {
|
|
1987
|
-
return true
|
|
1988
|
-
}
|
|
1989
|
-
return new Range(this.value, options).test(comp.semver)
|
|
1990
|
-
}
|
|
1991
|
-
|
|
1992
|
-
options = parseOptions(options);
|
|
1993
|
-
|
|
1994
|
-
// Special cases where nothing can possibly be lower
|
|
1995
|
-
if (options.includePrerelease &&
|
|
1996
|
-
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
|
|
1997
|
-
return false
|
|
1998
|
-
}
|
|
1999
|
-
if (!options.includePrerelease &&
|
|
2000
|
-
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
|
|
2001
|
-
return false
|
|
2002
|
-
}
|
|
2003
|
-
|
|
2004
|
-
// Same direction increasing (> or >=)
|
|
2005
|
-
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
|
|
2006
|
-
return true
|
|
2007
|
-
}
|
|
2008
|
-
// Same direction decreasing (< or <=)
|
|
2009
|
-
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
|
|
2010
|
-
return true
|
|
2011
|
-
}
|
|
2012
|
-
// same SemVer and both sides are inclusive (<= or >=)
|
|
2013
|
-
if (
|
|
2014
|
-
(this.semver.version === comp.semver.version) &&
|
|
2015
|
-
this.operator.includes('=') && comp.operator.includes('=')) {
|
|
2016
|
-
return true
|
|
2017
|
-
}
|
|
2018
|
-
// opposite directions less than
|
|
2019
|
-
if (cmp(this.semver, '<', comp.semver, options) &&
|
|
2020
|
-
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
|
|
2021
|
-
return true
|
|
2022
|
-
}
|
|
2023
|
-
// opposite directions greater than
|
|
2024
|
-
if (cmp(this.semver, '>', comp.semver, options) &&
|
|
2025
|
-
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
|
|
2026
|
-
return true
|
|
2027
|
-
}
|
|
2028
|
-
return false
|
|
2029
|
-
}
|
|
2030
|
-
}
|
|
2031
|
-
|
|
2032
|
-
comparator = Comparator;
|
|
2033
|
-
|
|
2034
|
-
const parseOptions = requireParseOptions();
|
|
2035
|
-
const { safeRe: re, t } = requireRe();
|
|
2036
|
-
const cmp = requireCmp();
|
|
2037
|
-
const debug = requireDebug();
|
|
2038
|
-
const SemVer = requireSemver$1();
|
|
2039
|
-
const Range = requireRange();
|
|
2040
|
-
return comparator;
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
var satisfies_1;
|
|
2044
|
-
var hasRequiredSatisfies;
|
|
2045
|
-
|
|
2046
|
-
function requireSatisfies () {
|
|
2047
|
-
if (hasRequiredSatisfies) return satisfies_1;
|
|
2048
|
-
hasRequiredSatisfies = 1;
|
|
2049
|
-
|
|
2050
|
-
const Range = requireRange();
|
|
2051
|
-
const satisfies = (version, range, options) => {
|
|
2052
|
-
try {
|
|
2053
|
-
range = new Range(range, options);
|
|
2054
|
-
} catch (er) {
|
|
2055
|
-
return false
|
|
2056
|
-
}
|
|
2057
|
-
return range.test(version)
|
|
2058
|
-
};
|
|
2059
|
-
satisfies_1 = satisfies;
|
|
2060
|
-
return satisfies_1;
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
var toComparators_1;
|
|
2064
|
-
var hasRequiredToComparators;
|
|
2065
|
-
|
|
2066
|
-
function requireToComparators () {
|
|
2067
|
-
if (hasRequiredToComparators) return toComparators_1;
|
|
2068
|
-
hasRequiredToComparators = 1;
|
|
2069
|
-
|
|
2070
|
-
const Range = requireRange();
|
|
2071
|
-
|
|
2072
|
-
// Mostly just for testing and legacy API reasons
|
|
2073
|
-
const toComparators = (range, options) =>
|
|
2074
|
-
new Range(range, options).set
|
|
2075
|
-
.map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
|
|
2076
|
-
|
|
2077
|
-
toComparators_1 = toComparators;
|
|
2078
|
-
return toComparators_1;
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
var maxSatisfying_1;
|
|
2082
|
-
var hasRequiredMaxSatisfying;
|
|
2083
|
-
|
|
2084
|
-
function requireMaxSatisfying () {
|
|
2085
|
-
if (hasRequiredMaxSatisfying) return maxSatisfying_1;
|
|
2086
|
-
hasRequiredMaxSatisfying = 1;
|
|
2087
|
-
|
|
2088
|
-
const SemVer = requireSemver$1();
|
|
2089
|
-
const Range = requireRange();
|
|
2090
|
-
|
|
2091
|
-
const maxSatisfying = (versions, range, options) => {
|
|
2092
|
-
let max = null;
|
|
2093
|
-
let maxSV = null;
|
|
2094
|
-
let rangeObj = null;
|
|
2095
|
-
try {
|
|
2096
|
-
rangeObj = new Range(range, options);
|
|
2097
|
-
} catch (er) {
|
|
2098
|
-
return null
|
|
2099
|
-
}
|
|
2100
|
-
versions.forEach((v) => {
|
|
2101
|
-
if (rangeObj.test(v)) {
|
|
2102
|
-
// satisfies(v, range, options)
|
|
2103
|
-
if (!max || maxSV.compare(v) === -1) {
|
|
2104
|
-
// compare(max, v, true)
|
|
2105
|
-
max = v;
|
|
2106
|
-
maxSV = new SemVer(max, options);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
});
|
|
2110
|
-
return max
|
|
2111
|
-
};
|
|
2112
|
-
maxSatisfying_1 = maxSatisfying;
|
|
2113
|
-
return maxSatisfying_1;
|
|
2114
|
-
}
|
|
2115
|
-
|
|
2116
|
-
var minSatisfying_1;
|
|
2117
|
-
var hasRequiredMinSatisfying;
|
|
2118
|
-
|
|
2119
|
-
function requireMinSatisfying () {
|
|
2120
|
-
if (hasRequiredMinSatisfying) return minSatisfying_1;
|
|
2121
|
-
hasRequiredMinSatisfying = 1;
|
|
2122
|
-
|
|
2123
|
-
const SemVer = requireSemver$1();
|
|
2124
|
-
const Range = requireRange();
|
|
2125
|
-
const minSatisfying = (versions, range, options) => {
|
|
2126
|
-
let min = null;
|
|
2127
|
-
let minSV = null;
|
|
2128
|
-
let rangeObj = null;
|
|
2129
|
-
try {
|
|
2130
|
-
rangeObj = new Range(range, options);
|
|
2131
|
-
} catch (er) {
|
|
2132
|
-
return null
|
|
2133
|
-
}
|
|
2134
|
-
versions.forEach((v) => {
|
|
2135
|
-
if (rangeObj.test(v)) {
|
|
2136
|
-
// satisfies(v, range, options)
|
|
2137
|
-
if (!min || minSV.compare(v) === 1) {
|
|
2138
|
-
// compare(min, v, true)
|
|
2139
|
-
min = v;
|
|
2140
|
-
minSV = new SemVer(min, options);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2144
|
-
return min
|
|
2145
|
-
};
|
|
2146
|
-
minSatisfying_1 = minSatisfying;
|
|
2147
|
-
return minSatisfying_1;
|
|
2148
|
-
}
|
|
2149
|
-
|
|
2150
|
-
var minVersion_1;
|
|
2151
|
-
var hasRequiredMinVersion;
|
|
2152
|
-
|
|
2153
|
-
function requireMinVersion () {
|
|
2154
|
-
if (hasRequiredMinVersion) return minVersion_1;
|
|
2155
|
-
hasRequiredMinVersion = 1;
|
|
2156
|
-
|
|
2157
|
-
const SemVer = requireSemver$1();
|
|
2158
|
-
const Range = requireRange();
|
|
2159
|
-
const gt = requireGt();
|
|
2160
|
-
|
|
2161
|
-
const minVersion = (range, loose) => {
|
|
2162
|
-
range = new Range(range, loose);
|
|
2163
|
-
|
|
2164
|
-
let minver = new SemVer('0.0.0');
|
|
2165
|
-
if (range.test(minver)) {
|
|
2166
|
-
return minver
|
|
2167
|
-
}
|
|
2168
|
-
|
|
2169
|
-
minver = new SemVer('0.0.0-0');
|
|
2170
|
-
if (range.test(minver)) {
|
|
2171
|
-
return minver
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
minver = null;
|
|
2175
|
-
for (let i = 0; i < range.set.length; ++i) {
|
|
2176
|
-
const comparators = range.set[i];
|
|
2177
|
-
|
|
2178
|
-
let setMin = null;
|
|
2179
|
-
comparators.forEach((comparator) => {
|
|
2180
|
-
// Clone to avoid manipulating the comparator's semver object.
|
|
2181
|
-
const compver = new SemVer(comparator.semver.version);
|
|
2182
|
-
switch (comparator.operator) {
|
|
2183
|
-
case '>':
|
|
2184
|
-
if (compver.prerelease.length === 0) {
|
|
2185
|
-
compver.patch++;
|
|
2186
|
-
} else {
|
|
2187
|
-
compver.prerelease.push(0);
|
|
2188
|
-
}
|
|
2189
|
-
compver.raw = compver.format();
|
|
2190
|
-
/* fallthrough */
|
|
2191
|
-
case '':
|
|
2192
|
-
case '>=':
|
|
2193
|
-
if (!setMin || gt(compver, setMin)) {
|
|
2194
|
-
setMin = compver;
|
|
2195
|
-
}
|
|
2196
|
-
break
|
|
2197
|
-
case '<':
|
|
2198
|
-
case '<=':
|
|
2199
|
-
/* Ignore maximum versions */
|
|
2200
|
-
break
|
|
2201
|
-
/* istanbul ignore next */
|
|
2202
|
-
default:
|
|
2203
|
-
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
|
2204
|
-
}
|
|
2205
|
-
});
|
|
2206
|
-
if (setMin && (!minver || gt(minver, setMin))) {
|
|
2207
|
-
minver = setMin;
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
if (minver && range.test(minver)) {
|
|
2212
|
-
return minver
|
|
2213
|
-
}
|
|
2214
|
-
|
|
2215
|
-
return null
|
|
2216
|
-
};
|
|
2217
|
-
minVersion_1 = minVersion;
|
|
2218
|
-
return minVersion_1;
|
|
2219
|
-
}
|
|
2220
|
-
|
|
2221
|
-
var valid;
|
|
2222
|
-
var hasRequiredValid;
|
|
2223
|
-
|
|
2224
|
-
function requireValid () {
|
|
2225
|
-
if (hasRequiredValid) return valid;
|
|
2226
|
-
hasRequiredValid = 1;
|
|
2227
|
-
|
|
2228
|
-
const Range = requireRange();
|
|
2229
|
-
const validRange = (range, options) => {
|
|
2230
|
-
try {
|
|
2231
|
-
// Return '*' instead of '' so that truthiness works.
|
|
2232
|
-
// This will throw if it's invalid anyway
|
|
2233
|
-
return new Range(range, options).range || '*'
|
|
2234
|
-
} catch (er) {
|
|
2235
|
-
return null
|
|
2236
|
-
}
|
|
2237
|
-
};
|
|
2238
|
-
valid = validRange;
|
|
2239
|
-
return valid;
|
|
2240
|
-
}
|
|
2241
|
-
|
|
2242
|
-
var outside_1;
|
|
2243
|
-
var hasRequiredOutside;
|
|
2244
|
-
|
|
2245
|
-
function requireOutside () {
|
|
2246
|
-
if (hasRequiredOutside) return outside_1;
|
|
2247
|
-
hasRequiredOutside = 1;
|
|
2248
|
-
|
|
2249
|
-
const SemVer = requireSemver$1();
|
|
2250
|
-
const Comparator = requireComparator();
|
|
2251
|
-
const { ANY } = Comparator;
|
|
2252
|
-
const Range = requireRange();
|
|
2253
|
-
const satisfies = requireSatisfies();
|
|
2254
|
-
const gt = requireGt();
|
|
2255
|
-
const lt = requireLt();
|
|
2256
|
-
const lte = requireLte();
|
|
2257
|
-
const gte = requireGte();
|
|
2258
|
-
|
|
2259
|
-
const outside = (version, range, hilo, options) => {
|
|
2260
|
-
version = new SemVer(version, options);
|
|
2261
|
-
range = new Range(range, options);
|
|
2262
|
-
|
|
2263
|
-
let gtfn, ltefn, ltfn, comp, ecomp;
|
|
2264
|
-
switch (hilo) {
|
|
2265
|
-
case '>':
|
|
2266
|
-
gtfn = gt;
|
|
2267
|
-
ltefn = lte;
|
|
2268
|
-
ltfn = lt;
|
|
2269
|
-
comp = '>';
|
|
2270
|
-
ecomp = '>=';
|
|
2271
|
-
break
|
|
2272
|
-
case '<':
|
|
2273
|
-
gtfn = lt;
|
|
2274
|
-
ltefn = gte;
|
|
2275
|
-
ltfn = gt;
|
|
2276
|
-
comp = '<';
|
|
2277
|
-
ecomp = '<=';
|
|
2278
|
-
break
|
|
2279
|
-
default:
|
|
2280
|
-
throw new TypeError('Must provide a hilo val of "<" or ">"')
|
|
2281
|
-
}
|
|
2282
|
-
|
|
2283
|
-
// If it satisfies the range it is not outside
|
|
2284
|
-
if (satisfies(version, range, options)) {
|
|
2285
|
-
return false
|
|
2286
|
-
}
|
|
2287
|
-
|
|
2288
|
-
// From now on, variable terms are as if we're in "gtr" mode.
|
|
2289
|
-
// but note that everything is flipped for the "ltr" function.
|
|
2290
|
-
|
|
2291
|
-
for (let i = 0; i < range.set.length; ++i) {
|
|
2292
|
-
const comparators = range.set[i];
|
|
2293
|
-
|
|
2294
|
-
let high = null;
|
|
2295
|
-
let low = null;
|
|
2296
|
-
|
|
2297
|
-
comparators.forEach((comparator) => {
|
|
2298
|
-
if (comparator.semver === ANY) {
|
|
2299
|
-
comparator = new Comparator('>=0.0.0');
|
|
2300
|
-
}
|
|
2301
|
-
high = high || comparator;
|
|
2302
|
-
low = low || comparator;
|
|
2303
|
-
if (gtfn(comparator.semver, high.semver, options)) {
|
|
2304
|
-
high = comparator;
|
|
2305
|
-
} else if (ltfn(comparator.semver, low.semver, options)) {
|
|
2306
|
-
low = comparator;
|
|
2307
|
-
}
|
|
2308
|
-
});
|
|
2309
|
-
|
|
2310
|
-
// If the edge version comparator has a operator then our version
|
|
2311
|
-
// isn't outside it
|
|
2312
|
-
if (high.operator === comp || high.operator === ecomp) {
|
|
2313
|
-
return false
|
|
2314
|
-
}
|
|
2315
|
-
|
|
2316
|
-
// If the lowest version comparator has an operator and our version
|
|
2317
|
-
// is less than it then it isn't higher than the range
|
|
2318
|
-
if ((!low.operator || low.operator === comp) &&
|
|
2319
|
-
ltefn(version, low.semver)) {
|
|
2320
|
-
return false
|
|
2321
|
-
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
2322
|
-
return false
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
return true
|
|
2326
|
-
};
|
|
2327
|
-
|
|
2328
|
-
outside_1 = outside;
|
|
2329
|
-
return outside_1;
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
var gtr_1;
|
|
2333
|
-
var hasRequiredGtr;
|
|
2334
|
-
|
|
2335
|
-
function requireGtr () {
|
|
2336
|
-
if (hasRequiredGtr) return gtr_1;
|
|
2337
|
-
hasRequiredGtr = 1;
|
|
2338
|
-
|
|
2339
|
-
// Determine if version is greater than all the versions possible in the range.
|
|
2340
|
-
const outside = requireOutside();
|
|
2341
|
-
const gtr = (version, range, options) => outside(version, range, '>', options);
|
|
2342
|
-
gtr_1 = gtr;
|
|
2343
|
-
return gtr_1;
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
var ltr_1;
|
|
2347
|
-
var hasRequiredLtr;
|
|
2348
|
-
|
|
2349
|
-
function requireLtr () {
|
|
2350
|
-
if (hasRequiredLtr) return ltr_1;
|
|
2351
|
-
hasRequiredLtr = 1;
|
|
2352
|
-
|
|
2353
|
-
const outside = requireOutside();
|
|
2354
|
-
// Determine if version is less than all the versions possible in the range
|
|
2355
|
-
const ltr = (version, range, options) => outside(version, range, '<', options);
|
|
2356
|
-
ltr_1 = ltr;
|
|
2357
|
-
return ltr_1;
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
var intersects_1;
|
|
2361
|
-
var hasRequiredIntersects;
|
|
2362
|
-
|
|
2363
|
-
function requireIntersects () {
|
|
2364
|
-
if (hasRequiredIntersects) return intersects_1;
|
|
2365
|
-
hasRequiredIntersects = 1;
|
|
2366
|
-
|
|
2367
|
-
const Range = requireRange();
|
|
2368
|
-
const intersects = (r1, r2, options) => {
|
|
2369
|
-
r1 = new Range(r1, options);
|
|
2370
|
-
r2 = new Range(r2, options);
|
|
2371
|
-
return r1.intersects(r2, options)
|
|
2372
|
-
};
|
|
2373
|
-
intersects_1 = intersects;
|
|
2374
|
-
return intersects_1;
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
var simplify;
|
|
2378
|
-
var hasRequiredSimplify;
|
|
2379
|
-
|
|
2380
|
-
function requireSimplify () {
|
|
2381
|
-
if (hasRequiredSimplify) return simplify;
|
|
2382
|
-
hasRequiredSimplify = 1;
|
|
2383
|
-
|
|
2384
|
-
// given a set of versions and a range, create a "simplified" range
|
|
2385
|
-
// that includes the same versions that the original range does
|
|
2386
|
-
// If the original range is shorter than the simplified one, return that.
|
|
2387
|
-
const satisfies = requireSatisfies();
|
|
2388
|
-
const compare = requireCompare();
|
|
2389
|
-
simplify = (versions, range, options) => {
|
|
2390
|
-
const set = [];
|
|
2391
|
-
let first = null;
|
|
2392
|
-
let prev = null;
|
|
2393
|
-
const v = versions.sort((a, b) => compare(a, b, options));
|
|
2394
|
-
for (const version of v) {
|
|
2395
|
-
const included = satisfies(version, range, options);
|
|
2396
|
-
if (included) {
|
|
2397
|
-
prev = version;
|
|
2398
|
-
if (!first) {
|
|
2399
|
-
first = version;
|
|
2400
|
-
}
|
|
2401
|
-
} else {
|
|
2402
|
-
if (prev) {
|
|
2403
|
-
set.push([first, prev]);
|
|
2404
|
-
}
|
|
2405
|
-
prev = null;
|
|
2406
|
-
first = null;
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
if (first) {
|
|
2410
|
-
set.push([first, null]);
|
|
2411
|
-
}
|
|
2412
|
-
|
|
2413
|
-
const ranges = [];
|
|
2414
|
-
for (const [min, max] of set) {
|
|
2415
|
-
if (min === max) {
|
|
2416
|
-
ranges.push(min);
|
|
2417
|
-
} else if (!max && min === v[0]) {
|
|
2418
|
-
ranges.push('*');
|
|
2419
|
-
} else if (!max) {
|
|
2420
|
-
ranges.push(`>=${min}`);
|
|
2421
|
-
} else if (min === v[0]) {
|
|
2422
|
-
ranges.push(`<=${max}`);
|
|
2423
|
-
} else {
|
|
2424
|
-
ranges.push(`${min} - ${max}`);
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
const simplified = ranges.join(' || ');
|
|
2428
|
-
const original = typeof range.raw === 'string' ? range.raw : String(range);
|
|
2429
|
-
return simplified.length < original.length ? simplified : range
|
|
2430
|
-
};
|
|
2431
|
-
return simplify;
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
var subset_1;
|
|
2435
|
-
var hasRequiredSubset;
|
|
2436
|
-
|
|
2437
|
-
function requireSubset () {
|
|
2438
|
-
if (hasRequiredSubset) return subset_1;
|
|
2439
|
-
hasRequiredSubset = 1;
|
|
2440
|
-
|
|
2441
|
-
const Range = requireRange();
|
|
2442
|
-
const Comparator = requireComparator();
|
|
2443
|
-
const { ANY } = Comparator;
|
|
2444
|
-
const satisfies = requireSatisfies();
|
|
2445
|
-
const compare = requireCompare();
|
|
2446
|
-
|
|
2447
|
-
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
|
2448
|
-
// - Every simple range `r1, r2, ...` is a null set, OR
|
|
2449
|
-
// - Every simple range `r1, r2, ...` which is not a null set is a subset of
|
|
2450
|
-
// some `R1, R2, ...`
|
|
2451
|
-
//
|
|
2452
|
-
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
|
2453
|
-
// - If c is only the ANY comparator
|
|
2454
|
-
// - If C is only the ANY comparator, return true
|
|
2455
|
-
// - Else if in prerelease mode, return false
|
|
2456
|
-
// - else replace c with `[>=0.0.0]`
|
|
2457
|
-
// - If C is only the ANY comparator
|
|
2458
|
-
// - if in prerelease mode, return true
|
|
2459
|
-
// - else replace C with `[>=0.0.0]`
|
|
2460
|
-
// - Let EQ be the set of = comparators in c
|
|
2461
|
-
// - If EQ is more than one, return true (null set)
|
|
2462
|
-
// - Let GT be the highest > or >= comparator in c
|
|
2463
|
-
// - Let LT be the lowest < or <= comparator in c
|
|
2464
|
-
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
|
2465
|
-
// - If any C is a = range, and GT or LT are set, return false
|
|
2466
|
-
// - If EQ
|
|
2467
|
-
// - If GT, and EQ does not satisfy GT, return true (null set)
|
|
2468
|
-
// - If LT, and EQ does not satisfy LT, return true (null set)
|
|
2469
|
-
// - If EQ satisfies every C, return true
|
|
2470
|
-
// - Else return false
|
|
2471
|
-
// - If GT
|
|
2472
|
-
// - If GT.semver is lower than any > or >= comp in C, return false
|
|
2473
|
-
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
|
2474
|
-
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
2475
|
-
// - If no C has a prerelease and the GT.semver tuple, return false
|
|
2476
|
-
// - If LT
|
|
2477
|
-
// - If LT.semver is greater than any < or <= comp in C, return false
|
|
2478
|
-
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
|
2479
|
-
// - If LT.semver has a prerelease, and not in prerelease mode
|
|
2480
|
-
// - If no C has a prerelease and the LT.semver tuple, return false
|
|
2481
|
-
// - Else return true
|
|
2482
|
-
|
|
2483
|
-
const subset = (sub, dom, options = {}) => {
|
|
2484
|
-
if (sub === dom) {
|
|
2485
|
-
return true
|
|
2486
|
-
}
|
|
2487
|
-
|
|
2488
|
-
sub = new Range(sub, options);
|
|
2489
|
-
dom = new Range(dom, options);
|
|
2490
|
-
let sawNonNull = false;
|
|
2491
|
-
|
|
2492
|
-
OUTER: for (const simpleSub of sub.set) {
|
|
2493
|
-
for (const simpleDom of dom.set) {
|
|
2494
|
-
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
|
2495
|
-
sawNonNull = sawNonNull || isSub !== null;
|
|
2496
|
-
if (isSub) {
|
|
2497
|
-
continue OUTER
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
// the null set is a subset of everything, but null simple ranges in
|
|
2501
|
-
// a complex range should be ignored. so if we saw a non-null range,
|
|
2502
|
-
// then we know this isn't a subset, but if EVERY simple range was null,
|
|
2503
|
-
// then it is a subset.
|
|
2504
|
-
if (sawNonNull) {
|
|
2505
|
-
return false
|
|
2506
|
-
}
|
|
2507
|
-
}
|
|
2508
|
-
return true
|
|
2509
|
-
};
|
|
2510
|
-
|
|
2511
|
-
const minimumVersionWithPreRelease = [new Comparator('>=0.0.0-0')];
|
|
2512
|
-
const minimumVersion = [new Comparator('>=0.0.0')];
|
|
2513
|
-
|
|
2514
|
-
const simpleSubset = (sub, dom, options) => {
|
|
2515
|
-
if (sub === dom) {
|
|
2516
|
-
return true
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
2520
|
-
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2521
|
-
return true
|
|
2522
|
-
} else if (options.includePrerelease) {
|
|
2523
|
-
sub = minimumVersionWithPreRelease;
|
|
2524
|
-
} else {
|
|
2525
|
-
sub = minimumVersion;
|
|
2526
|
-
}
|
|
2527
|
-
}
|
|
2528
|
-
|
|
2529
|
-
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
2530
|
-
if (options.includePrerelease) {
|
|
2531
|
-
return true
|
|
2532
|
-
} else {
|
|
2533
|
-
dom = minimumVersion;
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
|
|
2537
|
-
const eqSet = new Set();
|
|
2538
|
-
let gt, lt;
|
|
2539
|
-
for (const c of sub) {
|
|
2540
|
-
if (c.operator === '>' || c.operator === '>=') {
|
|
2541
|
-
gt = higherGT(gt, c, options);
|
|
2542
|
-
} else if (c.operator === '<' || c.operator === '<=') {
|
|
2543
|
-
lt = lowerLT(lt, c, options);
|
|
2544
|
-
} else {
|
|
2545
|
-
eqSet.add(c.semver);
|
|
2546
|
-
}
|
|
2547
|
-
}
|
|
2548
|
-
|
|
2549
|
-
if (eqSet.size > 1) {
|
|
2550
|
-
return null
|
|
2551
|
-
}
|
|
2552
|
-
|
|
2553
|
-
let gtltComp;
|
|
2554
|
-
if (gt && lt) {
|
|
2555
|
-
gtltComp = compare(gt.semver, lt.semver, options);
|
|
2556
|
-
if (gtltComp > 0) {
|
|
2557
|
-
return null
|
|
2558
|
-
} else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
|
|
2559
|
-
return null
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
|
|
2563
|
-
// will iterate one or zero times
|
|
2564
|
-
for (const eq of eqSet) {
|
|
2565
|
-
if (gt && !satisfies(eq, String(gt), options)) {
|
|
2566
|
-
return null
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
if (lt && !satisfies(eq, String(lt), options)) {
|
|
2570
|
-
return null
|
|
2571
|
-
}
|
|
2572
|
-
|
|
2573
|
-
for (const c of dom) {
|
|
2574
|
-
if (!satisfies(eq, String(c), options)) {
|
|
2575
|
-
return false
|
|
2576
|
-
}
|
|
2577
|
-
}
|
|
2578
|
-
|
|
2579
|
-
return true
|
|
2580
|
-
}
|
|
2581
|
-
|
|
2582
|
-
let higher, lower;
|
|
2583
|
-
let hasDomLT, hasDomGT;
|
|
2584
|
-
// if the subset has a prerelease, we need a comparator in the superset
|
|
2585
|
-
// with the same tuple and a prerelease, or it's not a subset
|
|
2586
|
-
let needDomLTPre = lt &&
|
|
2587
|
-
!options.includePrerelease &&
|
|
2588
|
-
lt.semver.prerelease.length ? lt.semver : false;
|
|
2589
|
-
let needDomGTPre = gt &&
|
|
2590
|
-
!options.includePrerelease &&
|
|
2591
|
-
gt.semver.prerelease.length ? gt.semver : false;
|
|
2592
|
-
// exception: <1.2.3-0 is the same as <1.2.3
|
|
2593
|
-
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
|
2594
|
-
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
|
2595
|
-
needDomLTPre = false;
|
|
2596
|
-
}
|
|
2597
|
-
|
|
2598
|
-
for (const c of dom) {
|
|
2599
|
-
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
|
|
2600
|
-
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
|
|
2601
|
-
if (gt) {
|
|
2602
|
-
if (needDomGTPre) {
|
|
2603
|
-
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2604
|
-
c.semver.major === needDomGTPre.major &&
|
|
2605
|
-
c.semver.minor === needDomGTPre.minor &&
|
|
2606
|
-
c.semver.patch === needDomGTPre.patch) {
|
|
2607
|
-
needDomGTPre = false;
|
|
2608
|
-
}
|
|
2609
|
-
}
|
|
2610
|
-
if (c.operator === '>' || c.operator === '>=') {
|
|
2611
|
-
higher = higherGT(gt, c, options);
|
|
2612
|
-
if (higher === c && higher !== gt) {
|
|
2613
|
-
return false
|
|
2614
|
-
}
|
|
2615
|
-
} else if (gt.operator === '>=' && !c.test(gt.semver)) {
|
|
2616
|
-
return false
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
if (lt) {
|
|
2620
|
-
if (needDomLTPre) {
|
|
2621
|
-
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
2622
|
-
c.semver.major === needDomLTPre.major &&
|
|
2623
|
-
c.semver.minor === needDomLTPre.minor &&
|
|
2624
|
-
c.semver.patch === needDomLTPre.patch) {
|
|
2625
|
-
needDomLTPre = false;
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
if (c.operator === '<' || c.operator === '<=') {
|
|
2629
|
-
lower = lowerLT(lt, c, options);
|
|
2630
|
-
if (lower === c && lower !== lt) {
|
|
2631
|
-
return false
|
|
2632
|
-
}
|
|
2633
|
-
} else if (lt.operator === '<=' && !c.test(lt.semver)) {
|
|
2634
|
-
return false
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
2638
|
-
return false
|
|
2639
|
-
}
|
|
2640
|
-
}
|
|
2641
|
-
|
|
2642
|
-
// if there was a < or >, and nothing in the dom, then must be false
|
|
2643
|
-
// UNLESS it was limited by another range in the other direction.
|
|
2644
|
-
// Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
|
|
2645
|
-
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
|
2646
|
-
return false
|
|
2647
|
-
}
|
|
2648
|
-
|
|
2649
|
-
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
|
2650
|
-
return false
|
|
2651
|
-
}
|
|
2652
|
-
|
|
2653
|
-
// we needed a prerelease range in a specific tuple, but didn't get one
|
|
2654
|
-
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
|
2655
|
-
// because it includes prereleases in the 1.2.3 tuple
|
|
2656
|
-
if (needDomGTPre || needDomLTPre) {
|
|
2657
|
-
return false
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
return true
|
|
2661
|
-
};
|
|
2662
|
-
|
|
2663
|
-
// >=1.2.3 is lower than >1.2.3
|
|
2664
|
-
const higherGT = (a, b, options) => {
|
|
2665
|
-
if (!a) {
|
|
2666
|
-
return b
|
|
2667
|
-
}
|
|
2668
|
-
const comp = compare(a.semver, b.semver, options);
|
|
2669
|
-
return comp > 0 ? a
|
|
2670
|
-
: comp < 0 ? b
|
|
2671
|
-
: b.operator === '>' && a.operator === '>=' ? b
|
|
2672
|
-
: a
|
|
2673
|
-
};
|
|
2674
|
-
|
|
2675
|
-
// <=1.2.3 is higher than <1.2.3
|
|
2676
|
-
const lowerLT = (a, b, options) => {
|
|
2677
|
-
if (!a) {
|
|
2678
|
-
return b
|
|
2679
|
-
}
|
|
2680
|
-
const comp = compare(a.semver, b.semver, options);
|
|
2681
|
-
return comp < 0 ? a
|
|
2682
|
-
: comp > 0 ? b
|
|
2683
|
-
: b.operator === '<' && a.operator === '<=' ? b
|
|
2684
|
-
: a
|
|
2685
|
-
};
|
|
2686
|
-
|
|
2687
|
-
subset_1 = subset;
|
|
2688
|
-
return subset_1;
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
var semver;
|
|
2692
|
-
var hasRequiredSemver;
|
|
2693
|
-
|
|
2694
|
-
function requireSemver () {
|
|
2695
|
-
if (hasRequiredSemver) return semver;
|
|
2696
|
-
hasRequiredSemver = 1;
|
|
2697
|
-
|
|
2698
|
-
// just pre-load all the stuff that index.js lazily exports
|
|
2699
|
-
const internalRe = requireRe();
|
|
2700
|
-
const constants = requireConstants();
|
|
2701
|
-
const SemVer = requireSemver$1();
|
|
2702
|
-
const identifiers = requireIdentifiers();
|
|
2703
|
-
const parse = requireParse();
|
|
2704
|
-
const valid = requireValid$1();
|
|
2705
|
-
const clean = requireClean();
|
|
2706
|
-
const inc = requireInc();
|
|
2707
|
-
const diff = requireDiff();
|
|
2708
|
-
const major = requireMajor();
|
|
2709
|
-
const minor = requireMinor();
|
|
2710
|
-
const patch = requirePatch();
|
|
2711
|
-
const prerelease = requirePrerelease();
|
|
2712
|
-
const compare = requireCompare();
|
|
2713
|
-
const rcompare = requireRcompare();
|
|
2714
|
-
const compareLoose = requireCompareLoose();
|
|
2715
|
-
const compareBuild = requireCompareBuild();
|
|
2716
|
-
const sort = requireSort();
|
|
2717
|
-
const rsort = requireRsort();
|
|
2718
|
-
const gt = requireGt();
|
|
2719
|
-
const lt = requireLt();
|
|
2720
|
-
const eq = requireEq();
|
|
2721
|
-
const neq = requireNeq();
|
|
2722
|
-
const gte = requireGte();
|
|
2723
|
-
const lte = requireLte();
|
|
2724
|
-
const cmp = requireCmp();
|
|
2725
|
-
const coerce = requireCoerce();
|
|
2726
|
-
const truncate = requireTruncate();
|
|
2727
|
-
const Comparator = requireComparator();
|
|
2728
|
-
const Range = requireRange();
|
|
2729
|
-
const satisfies = requireSatisfies();
|
|
2730
|
-
const toComparators = requireToComparators();
|
|
2731
|
-
const maxSatisfying = requireMaxSatisfying();
|
|
2732
|
-
const minSatisfying = requireMinSatisfying();
|
|
2733
|
-
const minVersion = requireMinVersion();
|
|
2734
|
-
const validRange = requireValid();
|
|
2735
|
-
const outside = requireOutside();
|
|
2736
|
-
const gtr = requireGtr();
|
|
2737
|
-
const ltr = requireLtr();
|
|
2738
|
-
const intersects = requireIntersects();
|
|
2739
|
-
const simplifyRange = requireSimplify();
|
|
2740
|
-
const subset = requireSubset();
|
|
2741
|
-
semver = {
|
|
2742
|
-
parse,
|
|
2743
|
-
valid,
|
|
2744
|
-
clean,
|
|
2745
|
-
inc,
|
|
2746
|
-
diff,
|
|
2747
|
-
major,
|
|
2748
|
-
minor,
|
|
2749
|
-
patch,
|
|
2750
|
-
prerelease,
|
|
2751
|
-
compare,
|
|
2752
|
-
rcompare,
|
|
2753
|
-
compareLoose,
|
|
2754
|
-
compareBuild,
|
|
2755
|
-
sort,
|
|
2756
|
-
rsort,
|
|
2757
|
-
gt,
|
|
2758
|
-
lt,
|
|
2759
|
-
eq,
|
|
2760
|
-
neq,
|
|
2761
|
-
gte,
|
|
2762
|
-
lte,
|
|
2763
|
-
cmp,
|
|
2764
|
-
coerce,
|
|
2765
|
-
truncate,
|
|
2766
|
-
Comparator,
|
|
2767
|
-
Range,
|
|
2768
|
-
satisfies,
|
|
2769
|
-
toComparators,
|
|
2770
|
-
maxSatisfying,
|
|
2771
|
-
minSatisfying,
|
|
2772
|
-
minVersion,
|
|
2773
|
-
validRange,
|
|
2774
|
-
outside,
|
|
2775
|
-
gtr,
|
|
2776
|
-
ltr,
|
|
2777
|
-
intersects,
|
|
2778
|
-
simplifyRange,
|
|
2779
|
-
subset,
|
|
2780
|
-
SemVer,
|
|
2781
|
-
re: internalRe.re,
|
|
2782
|
-
src: internalRe.src,
|
|
2783
|
-
tokens: internalRe.t,
|
|
2784
|
-
SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
|
|
2785
|
-
RELEASE_TYPES: constants.RELEASE_TYPES,
|
|
2786
|
-
compareIdentifiers: identifiers.compareIdentifiers,
|
|
2787
|
-
rcompareIdentifiers: identifiers.rcompareIdentifiers,
|
|
2788
|
-
};
|
|
2789
|
-
return semver;
|
|
2790
|
-
}
|
|
2791
|
-
|
|
2792
|
-
var semverExports = requireSemver();
|
|
2793
|
-
|
|
2794
|
-
const MINIAPP_BIND_APP_IDS_MAX_COUNT = 20;
|
|
2795
|
-
function parseMiniappBindAppIds(value, options = {}) {
|
|
2796
|
-
const sourceLabel = options.sourceLabel ?? 'package.json#heybox.bindAppIds';
|
|
2797
|
-
if (value === undefined)
|
|
2798
|
-
return Object.freeze([]);
|
|
2799
|
-
if (!Array.isArray(value))
|
|
2800
|
-
throw new Error(`${sourceLabel} 必须是字符串数组`);
|
|
2801
|
-
if (value.length > MINIAPP_BIND_APP_IDS_MAX_COUNT) {
|
|
2802
|
-
throw new Error(`${sourceLabel} 最多包含 ${MINIAPP_BIND_APP_IDS_MAX_COUNT} 个游戏 appid`);
|
|
2803
|
-
}
|
|
2804
|
-
const seen = new Set();
|
|
2805
|
-
const appIds = [];
|
|
2806
|
-
for (const item of value) {
|
|
2807
|
-
if (typeof item !== 'string' || !/^[1-9]\d*$/.test(item)) {
|
|
2808
|
-
throw new Error(`${sourceLabel} 包含非法游戏 appid:${String(item)}`);
|
|
2809
|
-
}
|
|
2810
|
-
const numeric = Number(item);
|
|
2811
|
-
if (!Number.isSafeInteger(numeric) || numeric > 2_147_483_647) {
|
|
2812
|
-
throw new Error(`${sourceLabel} 包含超出正 int32 范围的游戏 appid:${item}`);
|
|
2813
|
-
}
|
|
2814
|
-
if (seen.has(item))
|
|
2815
|
-
throw new Error(`${sourceLabel} 包含重复游戏 appid:${item}`);
|
|
2816
|
-
seen.add(item);
|
|
2817
|
-
appIds.push(item);
|
|
2818
|
-
}
|
|
2819
|
-
appIds.sort((left, right) => Number(left) - Number(right));
|
|
2820
|
-
return Object.freeze(appIds);
|
|
2821
|
-
}
|
|
2822
|
-
|
|
2823
|
-
const MINI_PROGRAM_PERMISSION_KEYS = [
|
|
2824
|
-
'userInfo',
|
|
2825
|
-
'steamLibrary',
|
|
2826
|
-
'share',
|
|
2827
|
-
'storage',
|
|
2828
|
-
'filesystem',
|
|
2829
|
-
'clipboard',
|
|
2830
|
-
'leaderboard',
|
|
2831
|
-
'network',
|
|
2832
|
-
'companion',
|
|
2833
|
-
];
|
|
2834
|
-
const MINI_PROGRAM_PERMISSION_CATALOG = [
|
|
2835
|
-
{
|
|
2836
|
-
key: 'userInfo',
|
|
2837
|
-
name: '用户信息',
|
|
2838
|
-
description: '登录小程序并读取当前用户的授权信息。',
|
|
2839
|
-
access: 'declaration',
|
|
2840
|
-
risk: 'medium',
|
|
2841
|
-
config: {},
|
|
2842
|
-
methods: ['auth.login', 'user.getInfo'],
|
|
2843
|
-
conditions: ['继续执行黑盒登录、用户授权和可信手势规则。'],
|
|
2844
|
-
},
|
|
2845
|
-
{
|
|
2846
|
-
key: 'steamLibrary',
|
|
2847
|
-
name: 'Steam 游戏库',
|
|
2848
|
-
description: '读取当前用户授权的 Steam 游戏库。',
|
|
2849
|
-
access: 'declaration',
|
|
2850
|
-
risk: 'high',
|
|
2851
|
-
config: {},
|
|
2852
|
-
methods: ['user.getSteamGameList'],
|
|
2853
|
-
conditions: ['继续执行账号绑定和数据可用性规则。'],
|
|
2854
|
-
},
|
|
2855
|
-
{
|
|
2856
|
-
key: 'share',
|
|
2857
|
-
name: '分享',
|
|
2858
|
-
description: '使用小程序分享、分享菜单和截图能力。',
|
|
2859
|
-
access: 'declaration',
|
|
2860
|
-
risk: 'medium',
|
|
2861
|
-
config: {},
|
|
2862
|
-
methods: ['share.copyLink', 'share.showShareMenu', 'share.screenshot'],
|
|
2863
|
-
conditions: ['继续执行分享参数校验和 Host 支持检查。'],
|
|
2864
|
-
},
|
|
2865
|
-
{
|
|
2866
|
-
key: 'storage',
|
|
2867
|
-
name: '键值存储',
|
|
2868
|
-
description: '读写按小程序隔离的简单键值数据。',
|
|
2869
|
-
access: 'declaration',
|
|
2870
|
-
risk: 'medium',
|
|
2871
|
-
config: {},
|
|
2872
|
-
methods: ['storage.getStorage', 'storage.setStorage'],
|
|
2873
|
-
conditions: ['仅用于简单键值存储,不包含文件系统。'],
|
|
2874
|
-
},
|
|
2875
|
-
{
|
|
2876
|
-
key: 'filesystem',
|
|
2877
|
-
name: '文件系统',
|
|
2878
|
-
description: '访问小程序沙盒文件和用户选择的外部文件。',
|
|
2879
|
-
access: 'declaration',
|
|
2880
|
-
risk: 'high',
|
|
2881
|
-
config: {},
|
|
2882
|
-
methods: [
|
|
2883
|
-
'network.download',
|
|
2884
|
-
'files.pickFiles',
|
|
2885
|
-
'files.pickDirectory',
|
|
2886
|
-
'files.saveFile',
|
|
2887
|
-
'file.create',
|
|
2888
|
-
'file.remove',
|
|
2889
|
-
'file.exists',
|
|
2890
|
-
'file.readText',
|
|
2891
|
-
'file.writeText',
|
|
2892
|
-
'file.readBytes',
|
|
2893
|
-
'file.writeBytes',
|
|
2894
|
-
'file.stat',
|
|
2895
|
-
'directory.create',
|
|
2896
|
-
'directory.remove',
|
|
2897
|
-
'directory.exists',
|
|
2898
|
-
'directory.list',
|
|
2899
|
-
],
|
|
2900
|
-
conditions: ['外部文件继续要求有效的用户选择、会话句柄和匹配的读写模式。'],
|
|
2901
|
-
},
|
|
2902
|
-
{
|
|
2903
|
-
key: 'clipboard',
|
|
2904
|
-
name: '剪贴板',
|
|
2905
|
-
description: '向系统剪贴板写入文本。',
|
|
2906
|
-
access: 'declaration',
|
|
2907
|
-
risk: 'medium',
|
|
2908
|
-
config: {},
|
|
2909
|
-
methods: ['device.setClipboard'],
|
|
2910
|
-
conditions: ['继续执行文本长度和 Host 支持限制。'],
|
|
2911
|
-
},
|
|
2912
|
-
{
|
|
2913
|
-
key: 'leaderboard',
|
|
2914
|
-
name: '排行榜',
|
|
2915
|
-
description: '读写小程序云排行榜。',
|
|
2916
|
-
access: 'declaration',
|
|
2917
|
-
risk: 'medium',
|
|
2918
|
-
config: {},
|
|
2919
|
-
methods: [
|
|
2920
|
-
'cloud.leaderboard.submit',
|
|
2921
|
-
'cloud.leaderboard.getList',
|
|
2922
|
-
'cloud.leaderboard.getCurrentUserEntry',
|
|
2923
|
-
'cloud.leaderboard.deleteCurrentUserEntry',
|
|
2924
|
-
'cloud.leaderboard.getInfo',
|
|
2925
|
-
],
|
|
2926
|
-
conditions: ['排行榜必须已创建,用户和资源规则保持不变。'],
|
|
2927
|
-
},
|
|
2928
|
-
{
|
|
2929
|
-
key: 'network',
|
|
2930
|
-
name: '网络',
|
|
2931
|
-
description: '通过 network 模块请求或下载外部资源。',
|
|
2932
|
-
access: 'platform-approval',
|
|
2933
|
-
risk: 'high',
|
|
2934
|
-
config: {
|
|
2935
|
-
useOfficialDomain: {
|
|
2936
|
-
type: 'boolean',
|
|
2937
|
-
required: false,
|
|
2938
|
-
default: false,
|
|
2939
|
-
description: '是否申请访问小黑盒官方域名。',
|
|
2940
|
-
},
|
|
2941
|
-
},
|
|
2942
|
-
methods: ['network.request', 'network.download'],
|
|
2943
|
-
conditions: ['声明后仍需平台批准,并继续执行网络安全策略。'],
|
|
2944
|
-
},
|
|
2945
|
-
{
|
|
2946
|
-
key: 'companion',
|
|
2947
|
-
name: '桌面辅助应用',
|
|
2948
|
-
description: '下载、准备并运行随当前小程序版本发布的受管桌面程序。',
|
|
2949
|
-
access: 'platform-approval',
|
|
2950
|
-
risk: 'high',
|
|
2951
|
-
config: {},
|
|
2952
|
-
methods: [
|
|
2953
|
-
'companion.getInfo',
|
|
2954
|
-
'companion.getPreparationStatus',
|
|
2955
|
-
'companion.prepare',
|
|
2956
|
-
'companion.cancelPreparation',
|
|
2957
|
-
'companion.getActiveSession',
|
|
2958
|
-
'companion.launch',
|
|
2959
|
-
'companion.session.write',
|
|
2960
|
-
'companion.session.closeStdin',
|
|
2961
|
-
'companion.session.terminate',
|
|
2962
|
-
'companion.session.ackOutput',
|
|
2963
|
-
'companion.openAttachment',
|
|
2964
|
-
'companion.showNotification',
|
|
2965
|
-
],
|
|
2966
|
-
conditions: ['声明后仍需平台批准,并继续执行可信用户手势、Host 能力和当前版本 Manifest 校验。'],
|
|
2967
|
-
},
|
|
2968
|
-
];
|
|
2969
|
-
new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
2970
|
-
|
|
2971
|
-
const MANAGED_RUNTIME_PERMISSION_KEYS = new Set(MINI_PROGRAM_PERMISSION_KEYS);
|
|
2972
|
-
function isManagedMiniProgramRuntimePermissionKey(key) {
|
|
2973
|
-
return MANAGED_RUNTIME_PERMISSION_KEYS.has(key);
|
|
2974
|
-
}
|
|
2975
|
-
function parseMiniProgramRuntimePermissions(snapshot) {
|
|
2976
|
-
if (!isRecord$4(snapshot) || snapshot.schema_version !== 1 || !Array.isArray(snapshot.entries)) {
|
|
2977
|
-
return { valid: false, permissions: {} };
|
|
2978
|
-
}
|
|
2979
|
-
if (snapshot.revision !== undefined && (typeof snapshot.revision !== 'number' || !Number.isInteger(snapshot.revision) || snapshot.revision < 0)) {
|
|
2980
|
-
return { valid: false, permissions: {} };
|
|
2981
|
-
}
|
|
2982
|
-
const seenKeys = new Set();
|
|
2983
|
-
const permissions = {};
|
|
2984
|
-
for (const rawEntry of snapshot.entries) {
|
|
2985
|
-
if (!isRecord$4(rawEntry) || typeof rawEntry.key !== 'string' || !rawEntry.key.trim()) {
|
|
2986
|
-
return { valid: false, permissions: {} };
|
|
2987
|
-
}
|
|
2988
|
-
const inputKey = rawEntry.key.trim();
|
|
2989
|
-
const key = inputKey === 'network.request' ? 'network' : inputKey;
|
|
2990
|
-
if (seenKeys.has(key) || (rawEntry.status !== 'enabled' && rawEntry.status !== 'disabled')) {
|
|
2991
|
-
return { valid: false, permissions: {} };
|
|
2992
|
-
}
|
|
2993
|
-
seenKeys.add(key);
|
|
2994
|
-
if (!isManagedMiniProgramRuntimePermissionKey(key)) {
|
|
2995
|
-
// 未知权限必须忽略,不能让 config:null / 缺字段把已认识的批准一起否掉。
|
|
2996
|
-
// 服务端会对无 config 的 message 字段输出 null(Rylai EmitUnpopulated)。
|
|
2997
|
-
continue;
|
|
2998
|
-
}
|
|
2999
|
-
if (key === 'network') {
|
|
3000
|
-
const config = rawEntry.config;
|
|
3001
|
-
if (!isRecord$4(config) || typeof config.useOfficialDomain !== 'boolean') {
|
|
3002
|
-
return { valid: false, permissions: {} };
|
|
3003
|
-
}
|
|
3004
|
-
permissions[key] = {
|
|
3005
|
-
key,
|
|
3006
|
-
status: rawEntry.status,
|
|
3007
|
-
config: { useOfficialDomain: config.useOfficialDomain },
|
|
3008
|
-
};
|
|
3009
|
-
continue;
|
|
3010
|
-
}
|
|
3011
|
-
if (rawEntry.config !== null && rawEntry.config !== undefined && (!isRecord$4(rawEntry.config) || Object.keys(rawEntry.config).length > 0)) {
|
|
3012
|
-
return { valid: false, permissions: {} };
|
|
3013
|
-
}
|
|
3014
|
-
permissions[key] = {
|
|
3015
|
-
key,
|
|
3016
|
-
status: rawEntry.status,
|
|
3017
|
-
config: {},
|
|
3018
|
-
};
|
|
3019
|
-
}
|
|
3020
|
-
return { valid: true, permissions };
|
|
3021
|
-
}
|
|
3022
|
-
function isRecord$4(value) {
|
|
3023
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3024
|
-
}
|
|
3025
|
-
|
|
3026
|
-
const MINIAPP_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
3027
|
-
function parseMiniappPermissions(value, options) {
|
|
3028
|
-
const sourceLabel = options.sourceLabel ?? 'package.json#heybox.permissions';
|
|
3029
|
-
if (!options.present) {
|
|
3030
|
-
if (requiresExplicitPermissions(options.sdkVersion)) {
|
|
3031
|
-
throw new Error(`${sourceLabel} 在 @heybox/hb-sdk ${options.sdkVersion} 中必须声明;无权限需求时请配置空对象 {}`);
|
|
3032
|
-
}
|
|
3033
|
-
return { declared: false };
|
|
3034
|
-
}
|
|
3035
|
-
if (!isRecord$3(value)) {
|
|
3036
|
-
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
3037
|
-
}
|
|
3038
|
-
const knownKeys = new Set(MINIAPP_PERMISSION_KEYS);
|
|
3039
|
-
for (const key of Object.keys(value)) {
|
|
3040
|
-
if (!knownKeys.has(key))
|
|
3041
|
-
throw new Error(`${sourceLabel} 包含未知权限:${key}`);
|
|
3042
|
-
}
|
|
3043
|
-
const permissions = {};
|
|
3044
|
-
for (const key of MINIAPP_PERMISSION_KEYS) {
|
|
3045
|
-
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
3046
|
-
continue;
|
|
3047
|
-
const declaration = value[key];
|
|
3048
|
-
const itemLabel = `${sourceLabel}.${key}`;
|
|
3049
|
-
if (!isRecord$3(declaration))
|
|
3050
|
-
throw new Error(`${itemLabel} 必须是 JSON 对象`);
|
|
3051
|
-
const definition = MINI_PROGRAM_PERMISSION_CATALOG.find((item) => item.key === key);
|
|
3052
|
-
if (!definition)
|
|
3053
|
-
throw new Error(`权限目录缺少定义:${key}`);
|
|
3054
|
-
const allowedFields = new Set(['enabled', ...Object.keys(definition.config)]);
|
|
3055
|
-
for (const field of Object.keys(declaration)) {
|
|
3056
|
-
if (!allowedFields.has(field))
|
|
3057
|
-
throw new Error(`${itemLabel} 包含未知字段:${field}`);
|
|
3058
|
-
}
|
|
3059
|
-
if (typeof declaration.enabled !== 'boolean')
|
|
3060
|
-
throw new Error(`${itemLabel}.enabled 必须是 boolean`);
|
|
3061
|
-
let useOfficialDomain = false;
|
|
3062
|
-
if (key === 'network') {
|
|
3063
|
-
if (declaration.useOfficialDomain !== undefined && typeof declaration.useOfficialDomain !== 'boolean') {
|
|
3064
|
-
throw new Error(`${itemLabel}.useOfficialDomain 必须是 boolean`);
|
|
3065
|
-
}
|
|
3066
|
-
useOfficialDomain = declaration.useOfficialDomain === true;
|
|
3067
|
-
}
|
|
3068
|
-
if (!declaration.enabled)
|
|
3069
|
-
continue;
|
|
3070
|
-
permissions[key] = key === 'network' ? { enabled: true, useOfficialDomain } : { enabled: true };
|
|
3071
|
-
}
|
|
3072
|
-
return { declared: true, permissions: permissions };
|
|
3073
|
-
}
|
|
3074
|
-
function requiresExplicitPermissions(sdkVersion) {
|
|
3075
|
-
const parsed = semverExports.parse(sdkVersion);
|
|
3076
|
-
if (!parsed)
|
|
3077
|
-
throw new Error(`sdkVersion 必须是合法 SemVer:${sdkVersion}`);
|
|
3078
|
-
return parsed.major > 0 || parsed.minor >= 9;
|
|
3079
|
-
}
|
|
3080
|
-
function getMissingPermissionsWarning(sourceLabel = 'package.json#heybox.permissions') {
|
|
3081
|
-
return `${sourceLabel} 尚未声明。当前按 0.8 兼容行为构建;0.9.0 起将拒绝构建,请尽快补充权限声明(无权限需求时配置 {})。`;
|
|
3082
|
-
}
|
|
3083
|
-
function composeMiniappRuntimePermissions(local, approvals) {
|
|
3084
|
-
const parsedApprovals = parseMiniProgramRuntimePermissions(approvals);
|
|
3085
|
-
const approvalRevision = isRecord$3(approvals) && Number.isInteger(approvals.revision) ? approvals.revision : undefined;
|
|
3086
|
-
const views = [];
|
|
3087
|
-
const entries = [];
|
|
3088
|
-
for (const definition of MINI_PROGRAM_PERMISSION_CATALOG) {
|
|
3089
|
-
const declaration = local.permissions?.[definition.key];
|
|
3090
|
-
const declared = !local.declared || declaration?.enabled === true;
|
|
3091
|
-
if (definition.access === 'declaration') {
|
|
3092
|
-
views.push({ key: definition.key, access: definition.access, declared, approved: null, effective: declared });
|
|
3093
|
-
if (declared)
|
|
3094
|
-
entries.push({ key: definition.key, status: 'enabled', config: {} });
|
|
3095
|
-
continue;
|
|
3096
|
-
}
|
|
3097
|
-
const approval = parsedApprovals.valid ? parsedApprovals.permissions[definition.key] : undefined;
|
|
3098
|
-
const approved = approval?.status === 'enabled';
|
|
3099
|
-
const effective = declared && approved;
|
|
3100
|
-
if (definition.key !== 'network') {
|
|
3101
|
-
views.push({
|
|
3102
|
-
key: definition.key,
|
|
3103
|
-
access: definition.access,
|
|
3104
|
-
declared,
|
|
3105
|
-
approved,
|
|
3106
|
-
effective,
|
|
3107
|
-
});
|
|
3108
|
-
if (declared) {
|
|
3109
|
-
entries.push({ key: definition.key, status: effective ? 'enabled' : 'disabled', config: {} });
|
|
3110
|
-
}
|
|
3111
|
-
continue;
|
|
3112
|
-
}
|
|
3113
|
-
const requestedOfficialDomain = declaration?.enabled === true && 'useOfficialDomain' in declaration && declaration.useOfficialDomain;
|
|
3114
|
-
const approvedOfficialDomain = approval?.config.useOfficialDomain === true;
|
|
3115
|
-
const effectiveOfficialDomain = effective && (local.declared ? requestedOfficialDomain : true) && approvedOfficialDomain;
|
|
3116
|
-
views.push({
|
|
3117
|
-
key: definition.key,
|
|
3118
|
-
access: definition.access,
|
|
3119
|
-
declared,
|
|
3120
|
-
approved,
|
|
3121
|
-
requestedConfig: { useOfficialDomain: requestedOfficialDomain },
|
|
3122
|
-
approvedConfig: { useOfficialDomain: approvedOfficialDomain },
|
|
3123
|
-
effective,
|
|
3124
|
-
effectiveConfig: { useOfficialDomain: effectiveOfficialDomain },
|
|
3125
|
-
});
|
|
3126
|
-
if (declared) {
|
|
3127
|
-
entries.push({ key: definition.key, status: effective ? 'enabled' : 'disabled', config: { useOfficialDomain: effectiveOfficialDomain } });
|
|
3128
|
-
}
|
|
3129
|
-
}
|
|
3130
|
-
return {
|
|
3131
|
-
runtimePermissions: { schema_version: 1, ...(approvalRevision === undefined ? {} : { revision: approvalRevision }), entries },
|
|
3132
|
-
views,
|
|
3133
|
-
};
|
|
3134
|
-
}
|
|
3135
|
-
function isRecord$3(value) {
|
|
3136
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3137
|
-
}
|
|
3138
|
-
|
|
3139
|
-
const MINIAPP_PLATFORM_VALUES = ['android', 'ios', 'ohos', 'windows', 'macos', 'linux'];
|
|
3140
|
-
/** 窗口尺寸字段的脏值兜底上限;真正的上限是宿主侧显示器 workArea。 */
|
|
3141
|
-
const MINIAPP_WINDOW_SIZE_MAX = 16_384;
|
|
3142
|
-
const MINIAPP_WINDOW_NUMBER_FIELDS = ['defaultWidth', 'defaultHeight', 'minWidth', 'minHeight'];
|
|
3143
|
-
const MINIAPP_WINDOW_ALLOWED_FIELDS = [...MINIAPP_WINDOW_NUMBER_FIELDS, 'resizable'];
|
|
3144
|
-
/**
|
|
3145
|
-
* 桌面平台子集:从唯一平台词表 `MINIAPP_PLATFORM_VALUES` 派生,`satisfies` 阻止它漂移出词表。
|
|
3146
|
-
* 小程序声明其中任一平台,即视为该项目承诺适配 PC / 桌面端;调试台据此取舍桌面调试入口。
|
|
3147
|
-
*
|
|
3148
|
-
* 注意:子集只表达「声明为桌面」,不保证已有可用的客户端基线——例如 `linux` 目前既没有 `@hbPlatform` 声明,
|
|
3149
|
-
* 也没有 Companion target,仅声明 `linux` 的项目会展示入口但未必能真正打开。
|
|
3150
|
-
*/
|
|
3151
|
-
const MINIAPP_DESKTOP_PLATFORM_VALUES = ['windows', 'macos', 'linux'];
|
|
3152
|
-
function hasMiniappDesktopPlatform(platforms) {
|
|
3153
|
-
if (!platforms)
|
|
3154
|
-
return false;
|
|
3155
|
-
return MINIAPP_DESKTOP_PLATFORM_VALUES.some((platform) => platforms.includes(platform));
|
|
3156
|
-
}
|
|
3157
|
-
function isValidMiniappManifestVersion(version) {
|
|
3158
|
-
return getMiniappManifestVersionError(version) === undefined;
|
|
3159
|
-
}
|
|
3160
|
-
function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version') {
|
|
3161
|
-
const error = getMiniappManifestVersionError(version);
|
|
3162
|
-
if (error) {
|
|
3163
|
-
throw new Error(`${sourceLabel} ${error}`);
|
|
3164
|
-
}
|
|
3165
|
-
return String(version).trim();
|
|
3166
|
-
}
|
|
3167
|
-
function parseMiniappManifestJson(raw, sourceLabel = 'manifest.json') {
|
|
3168
|
-
const hadBom = raw.charCodeAt(0) === 0xfeff;
|
|
3169
|
-
const text = hadBom ? raw.slice(1) : raw;
|
|
3170
|
-
let parsed;
|
|
3171
|
-
try {
|
|
3172
|
-
parsed = JSON.parse(text);
|
|
3173
|
-
}
|
|
3174
|
-
catch (error) {
|
|
3175
|
-
throw new Error(`${sourceLabel} 不是合法 JSON:${formatReason$1(error)}`);
|
|
3176
|
-
}
|
|
3177
|
-
if (!isManifestRecord(parsed)) {
|
|
3178
|
-
throw new Error(`${sourceLabel} 必须是 JSON 对象`);
|
|
3179
|
-
}
|
|
3180
|
-
return {
|
|
3181
|
-
manifest: parsed,
|
|
3182
|
-
hadBom,
|
|
3183
|
-
};
|
|
3184
|
-
}
|
|
3185
|
-
function validateMiniappManifestForDeploy(manifest) {
|
|
3186
|
-
const version = validateMiniappManifestVersion(manifest.version, 'manifest.version');
|
|
3187
|
-
const sdkVersion = validateSdkVersion(manifest.sdkVersion, 'manifest.sdkVersion');
|
|
3188
|
-
const permissions = parseMiniappPermissions(manifest.permissions, {
|
|
3189
|
-
present: Object.prototype.hasOwnProperty.call(manifest, 'permissions'),
|
|
3190
|
-
sdkVersion,
|
|
3191
|
-
sourceLabel: 'manifest.permissions',
|
|
3192
|
-
});
|
|
3193
|
-
const companions = validateGeneratedCompanions(manifest.companions);
|
|
3194
|
-
const window = validateMiniappWindow(manifest.window, 'manifest.window');
|
|
3195
|
-
const bindAppIds = parseMiniappBindAppIds(manifest.bindAppIds, { sourceLabel: 'manifest.bindAppIds' });
|
|
3196
|
-
return {
|
|
3197
|
-
version,
|
|
3198
|
-
sdkVersion,
|
|
3199
|
-
platforms: validateMiniappPlatforms(manifest.platforms, 'manifest.platforms'),
|
|
3200
|
-
...(permissions.permissions === undefined ? {} : { permissions: permissions.permissions }),
|
|
3201
|
-
...(companions === undefined ? {} : { companions }),
|
|
3202
|
-
...(window === undefined ? {} : { window }),
|
|
3203
|
-
...(bindAppIds.length === 0 ? {} : { bindAppIds }),
|
|
3204
|
-
};
|
|
3205
|
-
}
|
|
3206
|
-
function validateGeneratedCompanions(value) {
|
|
3207
|
-
if (value === undefined)
|
|
3208
|
-
return undefined;
|
|
3209
|
-
if (!isRecord$2(value) || Object.keys(value).length === 0)
|
|
3210
|
-
throw new Error('manifest.companions 必须是非空对象');
|
|
3211
|
-
for (const [alias, definition] of Object.entries(value)) {
|
|
3212
|
-
if (!/^[a-z][a-z0-9-]{0,31}$/.test(alias) ||
|
|
3213
|
-
!isRecord$2(definition) ||
|
|
3214
|
-
typeof definition.displayName !== 'string' ||
|
|
3215
|
-
!definition.displayName ||
|
|
3216
|
-
Array.from(definition.displayName).length > 120 ||
|
|
3217
|
-
!Array.isArray(definition.capabilities) ||
|
|
3218
|
-
definition.capabilities.some((capability) => capability !== 'stdio' && capability !== 'attachments' && capability !== 'notifications') ||
|
|
3219
|
-
new Set(definition.capabilities).size !== definition.capabilities.length ||
|
|
3220
|
-
!isRecord$2(definition.targets) ||
|
|
3221
|
-
Object.keys(definition.targets).length === 0)
|
|
3222
|
-
throw new Error(`manifest.companions.${alias} 不合法`);
|
|
3223
|
-
for (const [target, artifact] of Object.entries(definition.targets)) {
|
|
3224
|
-
if (isRecord$2(artifact) && artifact.elevation === 'required') {
|
|
3225
|
-
throw new Error(`manifest.companions.${alias}.targets.${target}.elevation V1 仅支持 none,暂不支持管理员权限启动`);
|
|
3226
|
-
}
|
|
3227
|
-
if ((target !== 'windows-x64' && target !== 'macos-arm64') ||
|
|
3228
|
-
!isRecord$2(artifact) ||
|
|
3229
|
-
artifact.path !== `companions/${alias}/${target}.zip` ||
|
|
3230
|
-
!Number.isSafeInteger(artifact.size) ||
|
|
3231
|
-
Number(artifact.size) <= 0 ||
|
|
3232
|
-
typeof artifact.sha256 !== 'string' ||
|
|
3233
|
-
!/^[a-f0-9]{64}$/.test(artifact.sha256) ||
|
|
3234
|
-
!isRecord$2(artifact.entrypoint) ||
|
|
3235
|
-
(artifact.entrypoint.kind !== 'executable' && artifact.entrypoint.kind !== 'app-bundle') ||
|
|
3236
|
-
typeof artifact.entrypoint.path !== 'string' ||
|
|
3237
|
-
!artifact.entrypoint.path ||
|
|
3238
|
-
artifact.elevation !== 'none' ||
|
|
3239
|
-
!isValidGeneratedCompanionArgs(artifact.args)) {
|
|
3240
|
-
throw new Error(`manifest.companions.${alias}.targets.${target} 不合法`);
|
|
3241
|
-
}
|
|
3242
|
-
}
|
|
3243
|
-
}
|
|
3244
|
-
return value;
|
|
3245
|
-
}
|
|
3246
|
-
function isValidGeneratedCompanionArgs(value) {
|
|
3247
|
-
if (!Array.isArray(value) || value.length > 64)
|
|
3248
|
-
return false;
|
|
3249
|
-
let totalBytes = 0;
|
|
3250
|
-
for (const arg of value) {
|
|
3251
|
-
if (typeof arg !== 'string' || /[\u0000\r\n]/.test(arg))
|
|
3252
|
-
return false;
|
|
3253
|
-
const bytes = Buffer.byteLength(arg, 'utf8');
|
|
3254
|
-
if (bytes > 1024)
|
|
3255
|
-
return false;
|
|
3256
|
-
totalBytes += bytes;
|
|
3257
|
-
}
|
|
3258
|
-
return totalBytes <= 16_384;
|
|
3259
|
-
}
|
|
3260
|
-
function validateMiniappPlatforms(platforms, sourceLabel = 'platforms') {
|
|
3261
|
-
if (!Array.isArray(platforms) || platforms.length === 0) {
|
|
3262
|
-
throw new Error(`${sourceLabel} 必须是非空平台数组`);
|
|
3263
|
-
}
|
|
3264
|
-
const allowedPlatforms = new Set(MINIAPP_PLATFORM_VALUES);
|
|
3265
|
-
const seen = new Set();
|
|
3266
|
-
for (const platform of platforms) {
|
|
3267
|
-
if (typeof platform !== 'string' || !allowedPlatforms.has(platform)) {
|
|
3268
|
-
throw new Error(`${sourceLabel} 包含不支持的平台:${String(platform)}`);
|
|
3269
|
-
}
|
|
3270
|
-
if (seen.has(platform)) {
|
|
3271
|
-
throw new Error(`${sourceLabel} 包含重复平台:${platform}`);
|
|
3272
|
-
}
|
|
3273
|
-
seen.add(platform);
|
|
3274
|
-
}
|
|
3275
|
-
return Object.freeze(MINIAPP_PLATFORM_VALUES.filter((platform) => seen.has(platform)));
|
|
3276
|
-
}
|
|
3277
|
-
function areMiniappPlatformsEqual(left, right) {
|
|
3278
|
-
return left.length === right.length && left.every((platform, index) => platform === right[index]);
|
|
3279
|
-
}
|
|
3280
|
-
/**
|
|
3281
|
-
* 校验并归一化 `package.json#heybox.window` / `manifest.window` 声明。
|
|
3282
|
-
*
|
|
3283
|
-
* @remarks
|
|
3284
|
-
* 与 `heybox.permissions` 同样的严格风格:未知字段报错,不做静默忽略。
|
|
3285
|
-
* `width` / `height` 显式给出改名提示;`x` / `y` 按未知字段显式报错(`INV-NO-DEV-POSITION`)。
|
|
3286
|
-
* 未声明时返回 `undefined`,由调用方决定不写入产物。
|
|
3287
|
-
* @param value - 待校验的原始声明(不可信输入)。
|
|
3288
|
-
* @param sourceLabel - 报错前缀,默认指向开发者声明路径。
|
|
3289
|
-
* @throws 当声明不是非空对象、含未知字段、数值/布尔类型不合法或 min/default 不配对时抛出。
|
|
3290
|
-
*/
|
|
3291
|
-
function validateMiniappWindow(value, sourceLabel = 'package.json#heybox.window') {
|
|
3292
|
-
if (value === undefined)
|
|
3293
|
-
return undefined;
|
|
3294
|
-
if (!isRecord$2(value) || Object.keys(value).length === 0) {
|
|
3295
|
-
throw new Error(`${sourceLabel} 至少需要声明 defaultWidth/defaultHeight/minWidth/minHeight/resizable 之一`);
|
|
3296
|
-
}
|
|
3297
|
-
if (Object.prototype.hasOwnProperty.call(value, 'width') || Object.prototype.hasOwnProperty.call(value, 'height')) {
|
|
3298
|
-
throw new Error(`${sourceLabel} 请使用 defaultWidth/defaultHeight,而不是 width/height`);
|
|
3299
|
-
}
|
|
3300
|
-
for (const key of Object.keys(value)) {
|
|
3301
|
-
if (!MINIAPP_WINDOW_ALLOWED_FIELDS.includes(key)) {
|
|
3302
|
-
throw new Error(`${sourceLabel} 包含未知字段:${key}`);
|
|
3303
|
-
}
|
|
3304
|
-
}
|
|
3305
|
-
const window = {};
|
|
3306
|
-
for (const field of MINIAPP_WINDOW_NUMBER_FIELDS) {
|
|
3307
|
-
if (!Object.prototype.hasOwnProperty.call(value, field))
|
|
3308
|
-
continue;
|
|
3309
|
-
const size = value[field];
|
|
3310
|
-
if (typeof size !== 'number' || !Number.isSafeInteger(size) || size <= 0) {
|
|
3311
|
-
throw new Error(`${sourceLabel}.${field} 必须是正整数`);
|
|
3312
|
-
}
|
|
3313
|
-
if (size > MINIAPP_WINDOW_SIZE_MAX) {
|
|
3314
|
-
throw new Error(`${sourceLabel}.${field} 不能大于 ${MINIAPP_WINDOW_SIZE_MAX}`);
|
|
3315
|
-
}
|
|
3316
|
-
window[field] = size;
|
|
3317
|
-
}
|
|
3318
|
-
if (Object.prototype.hasOwnProperty.call(value, 'resizable')) {
|
|
3319
|
-
if (typeof value.resizable !== 'boolean') {
|
|
3320
|
-
throw new Error(`${sourceLabel}.resizable 必须是 boolean`);
|
|
3321
|
-
}
|
|
3322
|
-
window.resizable = value.resizable;
|
|
3323
|
-
}
|
|
3324
|
-
for (const [minimum, fallback] of [
|
|
3325
|
-
['minWidth', 'defaultWidth'],
|
|
3326
|
-
['minHeight', 'defaultHeight'],
|
|
3327
|
-
]) {
|
|
3328
|
-
const minimumValue = window[minimum];
|
|
3329
|
-
if (minimumValue === undefined)
|
|
3330
|
-
continue;
|
|
3331
|
-
const fallbackValue = window[fallback];
|
|
3332
|
-
if (fallbackValue === undefined) {
|
|
3333
|
-
throw new Error(`${sourceLabel}.${minimum} 必须与 ${fallback} 同时声明`);
|
|
3334
|
-
}
|
|
3335
|
-
if (minimumValue > fallbackValue) {
|
|
3336
|
-
throw new Error(`${sourceLabel}.${minimum} 必须小于等于 ${fallback}`);
|
|
3337
|
-
}
|
|
3338
|
-
}
|
|
3339
|
-
return window;
|
|
3340
|
-
}
|
|
3341
|
-
/** 比较两份窗口声明是否逐字段一致;未声明视同 `undefined`。 */
|
|
3342
|
-
function areMiniappWindowsEqual(left, right) {
|
|
3343
|
-
if (left === undefined || right === undefined)
|
|
3344
|
-
return left === right;
|
|
3345
|
-
return (left.defaultWidth === right.defaultWidth &&
|
|
3346
|
-
left.defaultHeight === right.defaultHeight &&
|
|
3347
|
-
left.minWidth === right.minWidth &&
|
|
3348
|
-
left.minHeight === right.minHeight &&
|
|
3349
|
-
left.resizable === right.resizable);
|
|
3350
|
-
}
|
|
3351
|
-
function validateSdkVersion(version, sourceLabel = 'sdkVersion') {
|
|
3352
|
-
if (typeof version !== 'string' || version.trim() === '') {
|
|
3353
|
-
throw new Error(`${sourceLabel} 必须是合法 SemVer:${String(version)}`);
|
|
3354
|
-
}
|
|
3355
|
-
const normalized = version.trim();
|
|
3356
|
-
const parsed = semverExports.parse(normalized);
|
|
3357
|
-
if (!parsed || parsed.version !== normalized || parsed.build.length > 0) {
|
|
3358
|
-
throw new Error(`${sourceLabel} 必须是合法 SemVer:${normalized}`);
|
|
3359
|
-
}
|
|
3360
|
-
return normalized;
|
|
3361
|
-
}
|
|
3362
|
-
function isManifestRecord(value) {
|
|
3363
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3364
|
-
}
|
|
3365
|
-
function isRecord$2(value) {
|
|
3366
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3367
|
-
}
|
|
3368
|
-
function getMiniappManifestVersionError(version) {
|
|
3369
|
-
if (typeof version !== 'string' || version.trim() === '') {
|
|
3370
|
-
return `必须是合法 SemVer:${String(version)}`;
|
|
3371
|
-
}
|
|
3372
|
-
const normalized = version.trim();
|
|
3373
|
-
const parsed = semverExports.parse(normalized);
|
|
3374
|
-
if (!parsed) {
|
|
3375
|
-
return `必须是合法 SemVer:${normalized}`;
|
|
3376
|
-
}
|
|
3377
|
-
if (parsed.build.length > 0) {
|
|
3378
|
-
return `不能包含 build metadata:${normalized}`;
|
|
3379
|
-
}
|
|
3380
|
-
if (parsed.version !== normalized) {
|
|
3381
|
-
return `必须是合法 SemVer:${normalized}`;
|
|
3382
|
-
}
|
|
3383
|
-
if (parsed.major === 0 && parsed.minor === 0 && parsed.patch === 0) {
|
|
3384
|
-
return '不能是模板默认版本 0.0.0';
|
|
3385
|
-
}
|
|
3386
|
-
return undefined;
|
|
3387
|
-
}
|
|
3388
|
-
function formatReason$1(error) {
|
|
3389
|
-
if (error instanceof Error && error.message) {
|
|
3390
|
-
return error.message;
|
|
3391
|
-
}
|
|
3392
|
-
return String(error);
|
|
3393
|
-
}
|
|
3394
|
-
|
|
3395
|
-
const MINIAPP_UPLOAD_SCOPE = 'activity';
|
|
3396
|
-
const ACTIVITY_UPLOAD_KEY_MAX_LENGTH = 64;
|
|
3397
|
-
const MINIAPP_UPLOAD_BATCH_SIZE = 50;
|
|
3398
|
-
const MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES = 100 * 1024 * 1024;
|
|
3399
|
-
/** 与 Activity 上传后端合同一致的 Companion 归档总大小上限。 */
|
|
3400
|
-
const MINIAPP_COMPANION_UPLOAD_TEMPORARY_SIZE_LIMIT_BYTES = 500 * 1024 * 1024;
|
|
3401
|
-
const USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = '/mall/developer/user_miniprogram/access_status';
|
|
3402
|
-
const DEVELOPER_ENTITY_LIST_API_PATH = '/mall/developer/entity/list';
|
|
3403
|
-
const DEVELOPER_ENTITY_SWITCH_API_PATH = '/mall/developer/entity/switch';
|
|
3404
|
-
const LIST_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/list';
|
|
3405
|
-
const CREATE_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/create';
|
|
3406
|
-
const DETAIL_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/detail';
|
|
3407
|
-
const CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH = '/mall/developer/user_miniprogram/local_dev_launch_token';
|
|
3408
|
-
const USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = '/mall/developer/user_miniprogram/preview_allowlist';
|
|
3409
|
-
const UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = '/mall/developer/user_miniprogram/preview_allowlist/update';
|
|
3410
|
-
const CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = '/mall/developer/user_miniprogram/leaderboard/create';
|
|
3411
|
-
const DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH = '/mall/developer/user_miniprogram/leaderboard/detail';
|
|
3412
|
-
const LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH = '/mall/developer/user_miniprogram/leaderboard/list';
|
|
3413
|
-
const DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = '/mall/developer/user_miniprogram/leaderboard/delete';
|
|
3414
|
-
const PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = '/mall/developer/user_miniprogram/version/precheck';
|
|
3415
|
-
const SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH = '/mall/developer/user_miniprogram/version/submit_audit';
|
|
3416
|
-
const USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = '/mall/developer/user_miniprogram/version/preview_info';
|
|
3417
|
-
const WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = '/mall/developer/user_miniprogram/version/withdraw';
|
|
3418
|
-
const RELEASE_USER_MINIPROGRAM_VERSION_API_PATH = '/mall/developer/user_miniprogram/version/release';
|
|
3419
|
-
const TAKE_DOWN_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/take_down';
|
|
3420
|
-
const REOPEN_USER_MINIPROGRAM_API_PATH = '/mall/developer/user_miniprogram/reopen';
|
|
3421
|
-
const UPDATE_SQUARE_DISPLAY_API_PATH = '/mall/developer/user_miniprogram/square_display/update';
|
|
3422
|
-
const LIST_USER_MINIPROGRAM_VERSION_API_PATH = '/mall/developer/user_miniprogram/version/list';
|
|
3423
|
-
const FNV_OFFSET = 0x811c9dc5;
|
|
3424
|
-
const FNV_PRIME = 0x01000193;
|
|
3425
|
-
const MINIAPP_UPLOAD_SESSION_REF_LENGTH = 10;
|
|
3426
|
-
const MINIAPP_ARTIFACT_SIGNATURE_MAGIC = 'heybox-user-miniprogram-artifact\0v1\0';
|
|
3427
|
-
const UNPAIRED_SURROGATE_PATTERN = /[\ud800-\udbff](?![\udc00-\udfff])|(^|[^\ud800-\udbff])[\udc00-\udfff]/;
|
|
3428
|
-
const textEncoder = new TextEncoder();
|
|
3429
|
-
function normalizeRelativePath(relativePath) {
|
|
3430
|
-
return String(relativePath || '')
|
|
3431
|
-
.replace(/\\/g, '/')
|
|
3432
|
-
.replace(/^\/+/, '')
|
|
3433
|
-
.replace(/\/+/g, '/');
|
|
3434
|
-
}
|
|
3435
|
-
function relativePathContainsNodeModulesSegment(relativePath) {
|
|
3436
|
-
return normalizeRelativePath(relativePath)
|
|
3437
|
-
.split('/')
|
|
3438
|
-
.some((segment) => segment.length > 0 && segment.toLowerCase() === 'node_modules');
|
|
3439
|
-
}
|
|
3440
|
-
function getMiniProgramUploadAlias(miniProgramId) {
|
|
3441
|
-
let hash = FNV_OFFSET;
|
|
3442
|
-
const input = String(miniProgramId || '');
|
|
3443
|
-
for (let i = 0; i < input.length; i += 1) {
|
|
3444
|
-
hash ^= input.charCodeAt(i);
|
|
3445
|
-
hash = Math.imul(hash, FNV_PRIME) >>> 0;
|
|
3446
|
-
}
|
|
3447
|
-
return hash.toString(36);
|
|
3448
|
-
}
|
|
3449
|
-
function validateUploadTotalSize(items, options = {}) {
|
|
3450
|
-
const limit = options.limitBytes ?? MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES;
|
|
3451
|
-
const total = items.reduce((sum, item) => {
|
|
3452
|
-
const size = Number(item.size);
|
|
3453
|
-
return sum + (Number.isFinite(size) && size > 0 ? size : 0);
|
|
3454
|
-
}, 0);
|
|
3455
|
-
if (total > limit) {
|
|
3456
|
-
return '构建产物总大小超过 100MB,请删除未引用资源或压缩图片后重新 deploy';
|
|
3457
|
-
}
|
|
3458
|
-
return undefined;
|
|
3459
|
-
}
|
|
3460
|
-
function validateMiniappUploadSizeBudgets(items, options = {}) {
|
|
3461
|
-
const companionItems = items.filter((item) => normalizeRelativePath(item.relativePath).startsWith('companions/'));
|
|
3462
|
-
const webItems = items.filter((item) => !normalizeRelativePath(item.relativePath).startsWith('companions/'));
|
|
3463
|
-
const webError = validateUploadTotalSize(webItems, { limitBytes: options.webLimitBytes ?? MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES });
|
|
3464
|
-
if (webError)
|
|
3465
|
-
return webError;
|
|
3466
|
-
const companionTotal = companionItems.reduce((sum, item) => sum + (Number.isFinite(item.size) && item.size > 0 ? item.size : 0), 0);
|
|
3467
|
-
const companionLimit = options.companionLimitBytes ?? MINIAPP_COMPANION_UPLOAD_TEMPORARY_SIZE_LIMIT_BYTES;
|
|
3468
|
-
if (companionTotal > companionLimit)
|
|
3469
|
-
return 'Companion 归档总大小超过 500MiB 上限,请缩减归档后重新 deploy';
|
|
3470
|
-
return undefined;
|
|
3471
|
-
}
|
|
3472
|
-
function shouldUploadDistFile(relativePath) {
|
|
3473
|
-
const normalized = normalizeRelativePath(relativePath);
|
|
3474
|
-
if (!normalized) {
|
|
3475
|
-
return false;
|
|
3476
|
-
}
|
|
3477
|
-
if (normalized === 'manifest.json') {
|
|
3478
|
-
return false;
|
|
3479
|
-
}
|
|
3480
|
-
if (normalized === '.DS_Store' || normalized.endsWith('/.DS_Store')) {
|
|
3481
|
-
return false;
|
|
3482
|
-
}
|
|
3483
|
-
if (normalized.toLowerCase().endsWith('.map')) {
|
|
3484
|
-
return false;
|
|
3485
|
-
}
|
|
3486
|
-
return true;
|
|
3487
|
-
}
|
|
3488
|
-
/**
|
|
3489
|
-
* 校验构建产物路径和大小,并按路径 UTF-8 字节序排序。
|
|
3490
|
-
*
|
|
3491
|
-
* @param files - 待处理的构建产物文件。
|
|
3492
|
-
* @returns 保留输入附加字段的有序文件列表。
|
|
3493
|
-
* @throws 路径不规范、路径重复或文件大小非法时抛出错误。
|
|
3494
|
-
*/
|
|
3495
|
-
function prepareMiniappArtifactFiles(files) {
|
|
3496
|
-
if (files.length > 0xffffffff) {
|
|
3497
|
-
throw new Error('构建产物文件数量超出签名协议上限');
|
|
3498
|
-
}
|
|
3499
|
-
const usedPaths = new Set();
|
|
3500
|
-
const prepared = files.map((file) => {
|
|
3501
|
-
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
3502
|
-
if (usedPaths.has(relativePath)) {
|
|
3503
|
-
throw new Error(`构建产物包含重复文件路径:${relativePath}`);
|
|
3504
|
-
}
|
|
3505
|
-
usedPaths.add(relativePath);
|
|
3506
|
-
validateArtifactFileSize(file.size, relativePath);
|
|
3507
|
-
return { ...file, relativePath };
|
|
3508
|
-
});
|
|
3509
|
-
return prepared.sort((left, right) => compareBytes(textEncoder.encode(left.relativePath), textEncoder.encode(right.relativePath)));
|
|
3510
|
-
}
|
|
3511
|
-
/**
|
|
3512
|
-
* 按服务端 session key 前缀校验最终上传路径的 UTF-8 字节长度。
|
|
3513
|
-
*
|
|
3514
|
-
* @param files - 待上传的构建产物文件。
|
|
3515
|
-
* @param options - 小程序和长度限制配置。
|
|
3516
|
-
* @returns 第一个超长路径的错误提示;全部合法时返回 `undefined`。
|
|
3517
|
-
*/
|
|
3518
|
-
function validateMiniappUploadPathLengths(files, options) {
|
|
3519
|
-
const maxLength = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
|
|
3520
|
-
const prefix = `/u/${getMiniProgramUploadAlias(options.miniProgramId)}/${'x'.repeat(MINIAPP_UPLOAD_SESSION_REF_LENGTH)}/`;
|
|
3521
|
-
const prefixLength = textEncoder.encode(prefix).length;
|
|
3522
|
-
const tooLongFile = files.find((file) => {
|
|
3523
|
-
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
3524
|
-
return prefixLength + textEncoder.encode(relativePath).length > maxLength;
|
|
3525
|
-
});
|
|
3526
|
-
return tooLongFile ? `文件路径过长,请缩短构建产物文件名或目录层级:${tooLongFile.relativePath}` : undefined;
|
|
3527
|
-
}
|
|
3528
|
-
/**
|
|
3529
|
-
* 创建 v1 整包签名头。
|
|
3530
|
-
*
|
|
3531
|
-
* @param fileCount - 参与签名的文件数量。
|
|
3532
|
-
* @returns 包含协议标识和文件数量的字节数组。
|
|
3533
|
-
* @throws 文件数量超出协议范围时抛出错误。
|
|
3534
|
-
*/
|
|
3535
|
-
function createMiniappArtifactSignatureHeader(fileCount) {
|
|
3536
|
-
if (!Number.isInteger(fileCount) || fileCount < 0 || fileCount > 0xffffffff) {
|
|
3537
|
-
throw new Error('构建产物文件数量超出签名协议上限');
|
|
3538
|
-
}
|
|
3539
|
-
return concatBytes(textEncoder.encode(MINIAPP_ARTIFACT_SIGNATURE_MAGIC), encodeUint32BE(fileCount));
|
|
3540
|
-
}
|
|
3541
|
-
/**
|
|
3542
|
-
* 创建单个文件的 v1 framing header。
|
|
3543
|
-
*
|
|
3544
|
-
* @param file - 已规范化或待校验的构建产物文件。
|
|
3545
|
-
* @returns 包含路径长度、路径和文件大小的字节数组。
|
|
3546
|
-
* @throws 文件路径或大小非法时抛出错误。
|
|
3547
|
-
*/
|
|
3548
|
-
function createMiniappArtifactFileHeader(file) {
|
|
3549
|
-
const relativePath = normalizeMiniappArtifactRelativePath(file.relativePath);
|
|
3550
|
-
validateArtifactFileSize(file.size, relativePath);
|
|
3551
|
-
const pathBytes = textEncoder.encode(relativePath);
|
|
3552
|
-
return concatBytes(encodeUint32BE(pathBytes.length), pathBytes, encodeUint64BE(file.size));
|
|
3553
|
-
}
|
|
3554
|
-
/**
|
|
3555
|
-
* 校验服务端 session 文件映射,并计算仍需上传的文件。
|
|
3556
|
-
*
|
|
3557
|
-
* @param localFiles - 本地构建产物文件。
|
|
3558
|
-
* @param serverFiles - 服务端签发的文件映射。
|
|
3559
|
-
* @param uploadedKeys - 服务端已确认上传成功的 key。
|
|
3560
|
-
* @returns 完整映射、待上传文件和已确认 key。
|
|
3561
|
-
* @throws 服务端映射与本地产物不一致时抛出错误。
|
|
3562
|
-
*/
|
|
3563
|
-
function resolveMiniappUploadSessionFiles(localFiles, serverFiles, uploadedKeys) {
|
|
3564
|
-
const preparedFiles = prepareMiniappArtifactFiles(localFiles);
|
|
3565
|
-
if (serverFiles.length !== preparedFiles.length) {
|
|
3566
|
-
throw new Error(`上传会话文件数量异常:期望 ${preparedFiles.length},实际 ${serverFiles.length}`);
|
|
3567
|
-
}
|
|
3568
|
-
const mappings = new Map();
|
|
3569
|
-
const serverSizes = new Map();
|
|
3570
|
-
const serverHashes = new Map();
|
|
3571
|
-
const knownKeys = new Set();
|
|
3572
|
-
for (const serverFile of serverFiles) {
|
|
3573
|
-
const relativePath = normalizeMiniappArtifactRelativePath(serverFile.relative_path);
|
|
3574
|
-
if (mappings.has(relativePath)) {
|
|
3575
|
-
throw new Error(`上传会话返回重复文件路径:${relativePath}`);
|
|
3576
|
-
}
|
|
3577
|
-
const key = String(serverFile.key || '');
|
|
3578
|
-
if (!key) {
|
|
3579
|
-
throw new Error(`上传会话未返回文件 key:${relativePath}`);
|
|
3580
|
-
}
|
|
3581
|
-
if (knownKeys.has(key)) {
|
|
3582
|
-
throw new Error(`上传会话返回重复文件 key:${relativePath}`);
|
|
3583
|
-
}
|
|
3584
|
-
const size = Number(serverFile.size);
|
|
3585
|
-
if (!Number.isSafeInteger(size) || size < 0) {
|
|
3586
|
-
throw new Error(`上传会话返回文件大小异常:${relativePath}`);
|
|
3587
|
-
}
|
|
3588
|
-
const sha256 = String(serverFile.sha256 || '');
|
|
3589
|
-
if (!/^[a-f0-9]{64}$/.test(sha256)) {
|
|
3590
|
-
throw new Error(`上传会话返回文件 SHA-256 异常:${relativePath}`);
|
|
3591
|
-
}
|
|
3592
|
-
mappings.set(relativePath, key);
|
|
3593
|
-
serverSizes.set(relativePath, size);
|
|
3594
|
-
serverHashes.set(relativePath, sha256);
|
|
3595
|
-
knownKeys.add(key);
|
|
3596
|
-
}
|
|
3597
|
-
const files = preparedFiles.map((file) => {
|
|
3598
|
-
const key = mappings.get(file.relativePath);
|
|
3599
|
-
if (!key) {
|
|
3600
|
-
throw new Error(`上传会话缺少文件映射:${file.relativePath}`);
|
|
3601
|
-
}
|
|
3602
|
-
if (serverSizes.get(file.relativePath) !== file.size) {
|
|
3603
|
-
throw new Error(`上传会话文件大小与本地构建不一致:${file.relativePath}`);
|
|
3604
|
-
}
|
|
3605
|
-
if (!('sha256' in file) || serverHashes.get(file.relativePath) !== file.sha256) {
|
|
3606
|
-
throw new Error(`上传会话文件 SHA-256 与本地构建不一致:${file.relativePath}`);
|
|
3607
|
-
}
|
|
3608
|
-
return { file, key };
|
|
3609
|
-
});
|
|
3610
|
-
const completed = new Set();
|
|
3611
|
-
for (const rawKey of uploadedKeys) {
|
|
3612
|
-
const key = String(rawKey || '');
|
|
3613
|
-
if (!knownKeys.has(key)) {
|
|
3614
|
-
throw new Error('上传会话返回了不属于当前产物的已上传文件');
|
|
3615
|
-
}
|
|
3616
|
-
completed.add(key);
|
|
3617
|
-
}
|
|
3618
|
-
return {
|
|
3619
|
-
files,
|
|
3620
|
-
missingFiles: files.filter((file) => !completed.has(file.key)),
|
|
3621
|
-
uploadedKeys: [...completed],
|
|
3622
|
-
};
|
|
3623
|
-
}
|
|
3624
|
-
/** 校验 Manifest 中所有 Companion 归档都精确属于当前上传 receipt。 */
|
|
3625
|
-
function validateMiniappCompanionFileReceipts(companions, files) {
|
|
3626
|
-
const companionFiles = new Map(files.filter((file) => file.relativePath.startsWith('companions/')).map((file) => [file.relativePath, file]));
|
|
3627
|
-
if (companions === undefined) {
|
|
3628
|
-
if (companionFiles.size > 0)
|
|
3629
|
-
throw new Error('dist 包含未被 manifest.companions 引用的 Companion 归档');
|
|
3630
|
-
return;
|
|
3631
|
-
}
|
|
3632
|
-
if (!isRecord$1(companions))
|
|
3633
|
-
throw new Error('manifest.companions 必须是对象');
|
|
3634
|
-
const referenced = new Set();
|
|
3635
|
-
for (const definition of Object.values(companions)) {
|
|
3636
|
-
if (!isRecord$1(definition) || !isRecord$1(definition.targets))
|
|
3637
|
-
throw new Error('manifest.companions targets 不合法');
|
|
3638
|
-
for (const artifact of Object.values(definition.targets)) {
|
|
3639
|
-
if (!isRecord$1(artifact) || typeof artifact.path !== 'string' || typeof artifact.size !== 'number' || typeof artifact.sha256 !== 'string') {
|
|
3640
|
-
throw new Error('manifest.companions artifact 不合法');
|
|
3641
|
-
}
|
|
3642
|
-
const file = companionFiles.get(artifact.path);
|
|
3643
|
-
if (!file)
|
|
3644
|
-
throw new Error(`manifest.companions 引用的归档不在当前上传 receipt:${artifact.path}`);
|
|
3645
|
-
if (file.size !== artifact.size)
|
|
3646
|
-
throw new Error(`Companion 归档大小与 manifest 不一致:${artifact.path}`);
|
|
3647
|
-
if (file.sha256 !== artifact.sha256)
|
|
3648
|
-
throw new Error(`Companion 归档 SHA-256 与 manifest 不一致:${artifact.path}`);
|
|
3649
|
-
referenced.add(artifact.path);
|
|
3650
|
-
}
|
|
3651
|
-
}
|
|
3652
|
-
const extra = [...companionFiles.keys()].find((relativePath) => !referenced.has(relativePath));
|
|
3653
|
-
if (extra)
|
|
3654
|
-
throw new Error(`Companion 归档未被 manifest.companions 引用:${extra}`);
|
|
3655
|
-
}
|
|
3656
|
-
function isRecord$1(value) {
|
|
3657
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3658
|
-
}
|
|
3659
|
-
function normalizeMiniappArtifactRelativePath(relativePath) {
|
|
3660
|
-
const value = String(relativePath || '');
|
|
3661
|
-
if (!value) {
|
|
3662
|
-
throw new Error('构建产物包含空文件路径');
|
|
3663
|
-
}
|
|
3664
|
-
if (value.includes('\\')) {
|
|
3665
|
-
throw new Error(`构建产物路径不能包含反斜杠:${value}`);
|
|
3666
|
-
}
|
|
3667
|
-
if (value.startsWith('/') || value.endsWith('/') || /^[a-zA-Z]:\//.test(value)) {
|
|
3668
|
-
throw new Error(`构建产物必须使用相对文件路径:${value}`);
|
|
3669
|
-
}
|
|
3670
|
-
if (containsControlCharacter(value) || UNPAIRED_SURROGATE_PATTERN.test(value)) {
|
|
3671
|
-
throw new Error(`构建产物路径包含非法字符:${value}`);
|
|
3672
|
-
}
|
|
3673
|
-
if (value.split('/').some((segment) => !segment || segment === '.' || segment === '..')) {
|
|
3674
|
-
throw new Error(`构建产物路径包含非法目录段:${value}`);
|
|
3675
|
-
}
|
|
3676
|
-
if (value.includes(',')) {
|
|
3677
|
-
throw new Error(`构建产物路径不能包含逗号:${value}`);
|
|
3678
|
-
}
|
|
3679
|
-
if (value.includes('*') || value.includes('?')) {
|
|
3680
|
-
throw new Error(`构建产物路径不能包含通配符:${value}`);
|
|
3681
|
-
}
|
|
3682
|
-
return value;
|
|
3683
|
-
}
|
|
3684
|
-
function containsControlCharacter(value) {
|
|
3685
|
-
for (const character of value) {
|
|
3686
|
-
const code = character.charCodeAt(0);
|
|
3687
|
-
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
|
|
3688
|
-
return true;
|
|
3689
|
-
}
|
|
3690
|
-
}
|
|
3691
|
-
return false;
|
|
3692
|
-
}
|
|
3693
|
-
function validateArtifactFileSize(size, relativePath) {
|
|
3694
|
-
if (!Number.isSafeInteger(size) || size < 0) {
|
|
3695
|
-
throw new Error(`构建产物文件大小无效:${relativePath}`);
|
|
3696
|
-
}
|
|
3697
|
-
}
|
|
3698
|
-
function encodeUint32BE(value) {
|
|
3699
|
-
const bytes = new Uint8Array(4);
|
|
3700
|
-
new DataView(bytes.buffer).setUint32(0, value, false);
|
|
3701
|
-
return bytes;
|
|
3702
|
-
}
|
|
3703
|
-
function encodeUint64BE(value) {
|
|
3704
|
-
const bytes = new Uint8Array(8);
|
|
3705
|
-
const view = new DataView(bytes.buffer);
|
|
3706
|
-
view.setUint32(0, Math.floor(value / 0x100000000), false);
|
|
3707
|
-
view.setUint32(4, value % 0x100000000, false);
|
|
3708
|
-
return bytes;
|
|
3709
|
-
}
|
|
3710
|
-
function concatBytes(...parts) {
|
|
3711
|
-
const result = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
3712
|
-
let offset = 0;
|
|
3713
|
-
for (const part of parts) {
|
|
3714
|
-
result.set(part, offset);
|
|
3715
|
-
offset += part.length;
|
|
3716
|
-
}
|
|
3717
|
-
return result;
|
|
3718
|
-
}
|
|
3719
|
-
function compareBytes(left, right) {
|
|
3720
|
-
const length = Math.min(left.length, right.length);
|
|
3721
|
-
for (let index = 0; index < length; index += 1) {
|
|
3722
|
-
if (left[index] !== right[index]) {
|
|
3723
|
-
return left[index] - right[index];
|
|
3724
|
-
}
|
|
3725
|
-
}
|
|
3726
|
-
return left.length - right.length;
|
|
3727
|
-
}
|
|
3728
|
-
|
|
3729
|
-
function findNearestPackageJsonPath(startDir) {
|
|
3730
|
-
let current = path.resolve(startDir);
|
|
3731
|
-
while (true) {
|
|
3732
|
-
const packageJsonPath = path.join(current, 'package.json');
|
|
3733
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
3734
|
-
return packageJsonPath;
|
|
3735
|
-
}
|
|
3736
|
-
const parent = path.dirname(current);
|
|
3737
|
-
if (parent === current) {
|
|
3738
|
-
return path.join(path.resolve(startDir), 'package.json');
|
|
3739
|
-
}
|
|
3740
|
-
current = parent;
|
|
3741
|
-
}
|
|
3742
|
-
}
|
|
3743
|
-
function readMiniappPlatformsFromPackageJson(root) {
|
|
3744
|
-
const { packageJson } = readMiniappPackageJson(root);
|
|
3745
|
-
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3746
|
-
return validateMiniappPlatforms(heybox?.platforms, 'package.json#heybox.platforms');
|
|
3747
|
-
}
|
|
3748
|
-
/**
|
|
3749
|
-
* 读取并校验 `package.json#heybox.window`。
|
|
3750
|
-
*
|
|
3751
|
-
* @returns 合法声明;未声明时返回 `undefined`,调用方不得向 manifest 写入空对象或 `null`。
|
|
3752
|
-
* @throws 当声明违反 {@link validateMiniappWindow} 的规则时抛出,报错前缀为 `package.json#heybox.window`。
|
|
3753
|
-
*/
|
|
3754
|
-
function readMiniappWindowFromPackageJson(root) {
|
|
3755
|
-
const { packageJson } = readMiniappPackageJson(root);
|
|
3756
|
-
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3757
|
-
return validateMiniappWindow(heybox?.window, 'package.json#heybox.window');
|
|
3758
|
-
}
|
|
3759
|
-
function readMiniappPermissionsFromPackageJson(root, sdkVersion) {
|
|
3760
|
-
const { packageJson } = readMiniappPackageJson(root);
|
|
3761
|
-
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3762
|
-
const present = heybox !== undefined && Object.prototype.hasOwnProperty.call(heybox, 'permissions');
|
|
3763
|
-
return parseMiniappPermissions(heybox?.permissions, {
|
|
3764
|
-
present,
|
|
3765
|
-
sdkVersion,
|
|
3766
|
-
});
|
|
3767
|
-
}
|
|
3768
|
-
function readMiniappBindAppIdsFromPackageJson(root) {
|
|
3769
|
-
const { packageJson } = readMiniappPackageJson(root);
|
|
3770
|
-
const heybox = readMiniappHeyboxConfig(packageJson);
|
|
3771
|
-
return parseMiniappBindAppIds(heybox?.bindAppIds);
|
|
3772
|
-
}
|
|
3773
|
-
function resolveMiniappSdkVersion() {
|
|
3774
|
-
if (!version.HB_SDK_VERSION.startsWith('__HB_SDK_'))
|
|
3775
|
-
return version.HB_SDK_VERSION;
|
|
3776
|
-
const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', '..', 'package.json'), 'utf8'));
|
|
3777
|
-
if (typeof packageJson.version !== 'string' || !packageJson.version)
|
|
3778
|
-
throw new Error('未能读取 @heybox/hb-sdk 当前版本号');
|
|
3779
|
-
return packageJson.version;
|
|
3780
|
-
}
|
|
3781
|
-
function readMiniappPackageJson(root, requireVersion) {
|
|
3782
|
-
const packageJsonPath = findNearestPackageJsonPath(root);
|
|
3783
|
-
let content;
|
|
3784
|
-
try {
|
|
3785
|
-
content = fs.readFileSync(packageJsonPath, 'utf8');
|
|
3786
|
-
}
|
|
3787
|
-
catch (error) {
|
|
3788
|
-
throw new Error(`@heybox/hb-sdk 读取 package.json 失败:${formatReason(error)}`);
|
|
3789
|
-
}
|
|
3790
|
-
let packageJson;
|
|
3791
|
-
try {
|
|
3792
|
-
packageJson = JSON.parse(content);
|
|
3793
|
-
}
|
|
3794
|
-
catch (error) {
|
|
3795
|
-
throw new Error(`@heybox/hb-sdk 解析 package.json 失败:${formatReason(error)}`);
|
|
3796
|
-
}
|
|
3797
|
-
return { packageJson, packageJsonPath, version: typeof packageJson.version === 'string' ? packageJson.version.trim() : '' };
|
|
3798
|
-
}
|
|
3799
|
-
function readMiniappHeyboxConfig(packageJson) {
|
|
3800
|
-
if (packageJson.heybox === undefined)
|
|
3801
|
-
return undefined;
|
|
3802
|
-
if (!isRecord(packageJson.heybox)) {
|
|
3803
|
-
throw new Error('@heybox/hb-sdk 提示:package.json#heybox 必须是 JSON 对象');
|
|
3804
|
-
}
|
|
3805
|
-
return packageJson.heybox;
|
|
3806
|
-
}
|
|
3807
|
-
function isRecord(value) {
|
|
3808
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3809
|
-
}
|
|
3810
|
-
function formatReason(error) {
|
|
3811
|
-
if (error instanceof Error && error.message) {
|
|
3812
|
-
return error.message;
|
|
3813
|
-
}
|
|
3814
|
-
return String(error);
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
Array.from({ length: 256 }, (_, value) => {
|
|
3818
|
-
let crc = value;
|
|
3819
|
-
for (let bit = 0; bit < 8; bit++)
|
|
3820
|
-
crc = (crc >>> 1) ^ ((crc & 1) ? 0xedb88320 : 0);
|
|
3821
|
-
return crc >>> 0;
|
|
3822
|
-
});
|
|
3823
|
-
|
|
3824
|
-
const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
|
|
3825
|
-
const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
|
|
3826
|
-
const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
|
|
3827
|
-
const environmentScopeStorage = new node_async_hooks.AsyncLocalStorage();
|
|
3828
|
-
let environmentScopeTail = Promise.resolve();
|
|
3829
|
-
function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
|
|
3830
|
-
return env[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] === VERIFIED_RUNTIME_PERMISSION_CONTEXT && env[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] === '1';
|
|
3831
|
-
}
|
|
3832
|
-
function createMiniappPlatformCspEnv(env, skipPlatformCsp) {
|
|
3833
|
-
return {
|
|
3834
|
-
...env,
|
|
3835
|
-
[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV]: VERIFIED_RUNTIME_PERMISSION_CONTEXT,
|
|
3836
|
-
[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV]: skipPlatformCsp ? '1' : '0',
|
|
3837
|
-
};
|
|
3838
|
-
}
|
|
3839
|
-
async function withMiniappPlatformCspEnv(skipPlatformCsp, action, env = process.env) {
|
|
3840
|
-
if (environmentScopeStorage.getStore()?.active) {
|
|
3841
|
-
return runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env);
|
|
3842
|
-
}
|
|
3843
|
-
let releaseScope = () => undefined;
|
|
3844
|
-
const previousScope = environmentScopeTail;
|
|
3845
|
-
environmentScopeTail = new Promise((resolve) => {
|
|
3846
|
-
releaseScope = resolve;
|
|
3847
|
-
});
|
|
3848
|
-
await previousScope;
|
|
3849
|
-
const scope = { active: true };
|
|
3850
|
-
try {
|
|
3851
|
-
return await environmentScopeStorage.run(scope, () => runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env));
|
|
3852
|
-
}
|
|
3853
|
-
finally {
|
|
3854
|
-
scope.active = false;
|
|
3855
|
-
releaseScope();
|
|
3856
|
-
}
|
|
3857
|
-
}
|
|
3858
|
-
async function runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env) {
|
|
3859
|
-
const targets = env === process.env ? [env] : [env, process.env];
|
|
3860
|
-
const previousValues = targets.map((target) => ({
|
|
3861
|
-
context: target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV],
|
|
3862
|
-
officialDomain: target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV],
|
|
3863
|
-
}));
|
|
3864
|
-
for (const target of targets) {
|
|
3865
|
-
target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = VERIFIED_RUNTIME_PERMISSION_CONTEXT;
|
|
3866
|
-
target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = skipPlatformCsp ? '1' : '0';
|
|
3867
|
-
}
|
|
3868
|
-
try {
|
|
3869
|
-
return await action();
|
|
3870
|
-
}
|
|
3871
|
-
finally {
|
|
3872
|
-
targets.forEach((target, index) => {
|
|
3873
|
-
const previousValue = previousValues[index];
|
|
3874
|
-
if (previousValue?.context === undefined) {
|
|
3875
|
-
delete target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV];
|
|
3876
|
-
}
|
|
3877
|
-
else {
|
|
3878
|
-
target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = previousValue.context;
|
|
3879
|
-
}
|
|
3880
|
-
if (previousValue?.officialDomain === undefined) {
|
|
3881
|
-
delete target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV];
|
|
3882
|
-
}
|
|
3883
|
-
else {
|
|
3884
|
-
target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = previousValue.officialDomain;
|
|
3885
|
-
}
|
|
3886
|
-
});
|
|
3887
|
-
}
|
|
3888
|
-
}
|
|
3889
|
-
|
|
3890
|
-
exports.CREATE_USER_MINIPROGRAM_API_PATH = CREATE_USER_MINIPROGRAM_API_PATH;
|
|
3891
|
-
exports.CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
|
|
3892
|
-
exports.CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH = CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH;
|
|
3893
|
-
exports.DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
|
|
3894
|
-
exports.DETAIL_USER_MINIPROGRAM_API_PATH = DETAIL_USER_MINIPROGRAM_API_PATH;
|
|
3895
|
-
exports.DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH = DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
|
|
3896
|
-
exports.DEVELOPER_ENTITY_LIST_API_PATH = DEVELOPER_ENTITY_LIST_API_PATH;
|
|
3897
|
-
exports.DEVELOPER_ENTITY_SWITCH_API_PATH = DEVELOPER_ENTITY_SWITCH_API_PATH;
|
|
3898
|
-
exports.LIST_USER_MINIPROGRAM_API_PATH = LIST_USER_MINIPROGRAM_API_PATH;
|
|
3899
|
-
exports.LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH = LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
|
|
3900
|
-
exports.LIST_USER_MINIPROGRAM_VERSION_API_PATH = LIST_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3901
|
-
exports.MINIAPP_UPLOAD_BATCH_SIZE = MINIAPP_UPLOAD_BATCH_SIZE;
|
|
3902
|
-
exports.MINIAPP_UPLOAD_SCOPE = MINIAPP_UPLOAD_SCOPE;
|
|
3903
|
-
exports.MINI_PROGRAM_PERMISSION_KEYS = MINI_PROGRAM_PERMISSION_KEYS;
|
|
3904
|
-
exports.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH = PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3905
|
-
exports.RELEASE_USER_MINIPROGRAM_VERSION_API_PATH = RELEASE_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3906
|
-
exports.REOPEN_USER_MINIPROGRAM_API_PATH = REOPEN_USER_MINIPROGRAM_API_PATH;
|
|
3907
|
-
exports.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH = SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH;
|
|
3908
|
-
exports.TAKE_DOWN_USER_MINIPROGRAM_API_PATH = TAKE_DOWN_USER_MINIPROGRAM_API_PATH;
|
|
3909
|
-
exports.UPDATE_SQUARE_DISPLAY_API_PATH = UPDATE_SQUARE_DISPLAY_API_PATH;
|
|
3910
|
-
exports.UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
|
|
3911
|
-
exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS_API_PATH;
|
|
3912
|
-
exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
|
|
3913
|
-
exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
|
|
3914
|
-
exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;
|
|
3915
|
-
exports.areMiniappPlatformsEqual = areMiniappPlatformsEqual;
|
|
3916
|
-
exports.areMiniappWindowsEqual = areMiniappWindowsEqual;
|
|
3917
|
-
exports.composeMiniappRuntimePermissions = composeMiniappRuntimePermissions;
|
|
3918
|
-
exports.createMiniappArtifactFileHeader = createMiniappArtifactFileHeader;
|
|
3919
|
-
exports.createMiniappArtifactSignatureHeader = createMiniappArtifactSignatureHeader;
|
|
3920
|
-
exports.createMiniappPlatformCspEnv = createMiniappPlatformCspEnv;
|
|
3921
|
-
exports.getMissingPermissionsWarning = getMissingPermissionsWarning;
|
|
3922
|
-
exports.hasMiniappDesktopPlatform = hasMiniappDesktopPlatform;
|
|
3923
|
-
exports.isValidMiniappManifestVersion = isValidMiniappManifestVersion;
|
|
3924
|
-
exports.normalizeRelativePath = normalizeRelativePath;
|
|
3925
|
-
exports.parseMiniProgramRuntimePermissions = parseMiniProgramRuntimePermissions;
|
|
3926
|
-
exports.parseMiniappManifestJson = parseMiniappManifestJson;
|
|
3927
|
-
exports.prepareMiniappArtifactFiles = prepareMiniappArtifactFiles;
|
|
3928
|
-
exports.readMiniappBindAppIdsFromPackageJson = readMiniappBindAppIdsFromPackageJson;
|
|
3929
|
-
exports.readMiniappPermissionsFromPackageJson = readMiniappPermissionsFromPackageJson;
|
|
3930
|
-
exports.readMiniappPlatformsFromPackageJson = readMiniappPlatformsFromPackageJson;
|
|
3931
|
-
exports.readMiniappWindowFromPackageJson = readMiniappWindowFromPackageJson;
|
|
3932
|
-
exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
|
|
3933
|
-
exports.requireSemver = requireSemver;
|
|
3934
|
-
exports.resolveMiniappSdkVersion = resolveMiniappSdkVersion;
|
|
3935
|
-
exports.resolveMiniappUploadSessionFiles = resolveMiniappUploadSessionFiles;
|
|
3936
|
-
exports.shouldSkipMiniappPlatformCspFromEnv = shouldSkipMiniappPlatformCspFromEnv;
|
|
3937
|
-
exports.shouldUploadDistFile = shouldUploadDistFile;
|
|
3938
|
-
exports.validateMiniappCompanionFileReceipts = validateMiniappCompanionFileReceipts;
|
|
3939
|
-
exports.validateMiniappManifestForDeploy = validateMiniappManifestForDeploy;
|
|
3940
|
-
exports.validateMiniappUploadPathLengths = validateMiniappUploadPathLengths;
|
|
3941
|
-
exports.validateMiniappUploadSizeBudgets = validateMiniappUploadSizeBudgets;
|
|
3942
|
-
exports.withMiniappPlatformCspEnv = withMiniappPlatformCspEnv;
|