@oclif/plugin-test-esbuild 0.4.21 → 0.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{chunk-NYAOQONU.js → chunk-3RGGSNDJ.js} +1 -1
- package/dist/{chunk-WBL2ZEOX.js → chunk-BIYL2HN3.js} +1 -1
- package/dist/{chunk-ROBJRQRG.js → chunk-EB5PZLA5.js} +1 -1
- package/dist/{chunk-4P6LCYSK.js → chunk-L44NO6VG.js} +1 -1
- package/dist/{chunk-24X2WV72.js → chunk-PAHNEEAY.js} +6 -6
- package/dist/chunk-ZQOI2LXL.js +1966 -0
- package/dist/commands/esbuild.js +2 -2
- package/dist/commands/hello/index.js +2 -2
- package/dist/commands/hello/world.js +2 -2
- package/dist/hooks/init/init.js +2 -2
- package/dist/index.js +18 -1966
- package/dist/npa-TC6TVPHC.js +2260 -0
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
- package/dist/npa-FUCICWXG.js +0 -4907
|
@@ -0,0 +1,2260 @@
|
|
|
1
|
+
import {
|
|
2
|
+
require_lib,
|
|
3
|
+
require_semver
|
|
4
|
+
} from "./chunk-ZQOI2LXL.js";
|
|
5
|
+
import {
|
|
6
|
+
__commonJS,
|
|
7
|
+
__require,
|
|
8
|
+
init_cjs_shims
|
|
9
|
+
} from "./chunk-RRP6KXWN.js";
|
|
10
|
+
|
|
11
|
+
// node_modules/lru-cache/dist/commonjs/index.js
|
|
12
|
+
var require_commonjs = __commonJS({
|
|
13
|
+
"node_modules/lru-cache/dist/commonjs/index.js"(exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
init_cjs_shims();
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.LRUCache = void 0;
|
|
18
|
+
var perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
19
|
+
var warned = /* @__PURE__ */ new Set();
|
|
20
|
+
var PROCESS = typeof process === "object" && !!process ? process : {};
|
|
21
|
+
var emitWarning = (msg, type, code, fn) => {
|
|
22
|
+
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
23
|
+
};
|
|
24
|
+
var AC = globalThis.AbortController;
|
|
25
|
+
var AS = globalThis.AbortSignal;
|
|
26
|
+
if (typeof AC === "undefined") {
|
|
27
|
+
AS = class AbortSignal {
|
|
28
|
+
onabort;
|
|
29
|
+
_onabort = [];
|
|
30
|
+
reason;
|
|
31
|
+
aborted = false;
|
|
32
|
+
addEventListener(_, fn) {
|
|
33
|
+
this._onabort.push(fn);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
AC = class AbortController {
|
|
37
|
+
constructor() {
|
|
38
|
+
warnACPolyfill();
|
|
39
|
+
}
|
|
40
|
+
signal = new AS();
|
|
41
|
+
abort(reason) {
|
|
42
|
+
if (this.signal.aborted)
|
|
43
|
+
return;
|
|
44
|
+
this.signal.reason = reason;
|
|
45
|
+
this.signal.aborted = true;
|
|
46
|
+
for (const fn of this.signal._onabort) {
|
|
47
|
+
fn(reason);
|
|
48
|
+
}
|
|
49
|
+
this.signal.onabort?.(reason);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
let printACPolyfillWarning = PROCESS.env?.LRU_CACHE_IGNORE_AC_WARNING !== "1";
|
|
53
|
+
const warnACPolyfill = () => {
|
|
54
|
+
if (!printACPolyfillWarning)
|
|
55
|
+
return;
|
|
56
|
+
printACPolyfillWarning = false;
|
|
57
|
+
emitWarning("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.", "NO_ABORT_CONTROLLER", "ENOTSUP", warnACPolyfill);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var shouldWarn = (code) => !warned.has(code);
|
|
61
|
+
var TYPE = Symbol("type");
|
|
62
|
+
var isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
|
|
63
|
+
var getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null;
|
|
64
|
+
var ZeroArray = class extends Array {
|
|
65
|
+
constructor(size) {
|
|
66
|
+
super(size);
|
|
67
|
+
this.fill(0);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var Stack = class _Stack {
|
|
71
|
+
heap;
|
|
72
|
+
length;
|
|
73
|
+
// private constructor
|
|
74
|
+
static #constructing = false;
|
|
75
|
+
static create(max) {
|
|
76
|
+
const HeapCls = getUintArray(max);
|
|
77
|
+
if (!HeapCls)
|
|
78
|
+
return [];
|
|
79
|
+
_Stack.#constructing = true;
|
|
80
|
+
const s = new _Stack(max, HeapCls);
|
|
81
|
+
_Stack.#constructing = false;
|
|
82
|
+
return s;
|
|
83
|
+
}
|
|
84
|
+
constructor(max, HeapCls) {
|
|
85
|
+
if (!_Stack.#constructing) {
|
|
86
|
+
throw new TypeError("instantiate Stack using Stack.create(n)");
|
|
87
|
+
}
|
|
88
|
+
this.heap = new HeapCls(max);
|
|
89
|
+
this.length = 0;
|
|
90
|
+
}
|
|
91
|
+
push(n) {
|
|
92
|
+
this.heap[this.length++] = n;
|
|
93
|
+
}
|
|
94
|
+
pop() {
|
|
95
|
+
return this.heap[--this.length];
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var LRUCache = class _LRUCache {
|
|
99
|
+
// properties coming in from the options of these, only max and maxSize
|
|
100
|
+
// really *need* to be protected. The rest can be modified, as they just
|
|
101
|
+
// set defaults for various methods.
|
|
102
|
+
#max;
|
|
103
|
+
#maxSize;
|
|
104
|
+
#dispose;
|
|
105
|
+
#disposeAfter;
|
|
106
|
+
#fetchMethod;
|
|
107
|
+
/**
|
|
108
|
+
* {@link LRUCache.OptionsBase.ttl}
|
|
109
|
+
*/
|
|
110
|
+
ttl;
|
|
111
|
+
/**
|
|
112
|
+
* {@link LRUCache.OptionsBase.ttlResolution}
|
|
113
|
+
*/
|
|
114
|
+
ttlResolution;
|
|
115
|
+
/**
|
|
116
|
+
* {@link LRUCache.OptionsBase.ttlAutopurge}
|
|
117
|
+
*/
|
|
118
|
+
ttlAutopurge;
|
|
119
|
+
/**
|
|
120
|
+
* {@link LRUCache.OptionsBase.updateAgeOnGet}
|
|
121
|
+
*/
|
|
122
|
+
updateAgeOnGet;
|
|
123
|
+
/**
|
|
124
|
+
* {@link LRUCache.OptionsBase.updateAgeOnHas}
|
|
125
|
+
*/
|
|
126
|
+
updateAgeOnHas;
|
|
127
|
+
/**
|
|
128
|
+
* {@link LRUCache.OptionsBase.allowStale}
|
|
129
|
+
*/
|
|
130
|
+
allowStale;
|
|
131
|
+
/**
|
|
132
|
+
* {@link LRUCache.OptionsBase.noDisposeOnSet}
|
|
133
|
+
*/
|
|
134
|
+
noDisposeOnSet;
|
|
135
|
+
/**
|
|
136
|
+
* {@link LRUCache.OptionsBase.noUpdateTTL}
|
|
137
|
+
*/
|
|
138
|
+
noUpdateTTL;
|
|
139
|
+
/**
|
|
140
|
+
* {@link LRUCache.OptionsBase.maxEntrySize}
|
|
141
|
+
*/
|
|
142
|
+
maxEntrySize;
|
|
143
|
+
/**
|
|
144
|
+
* {@link LRUCache.OptionsBase.sizeCalculation}
|
|
145
|
+
*/
|
|
146
|
+
sizeCalculation;
|
|
147
|
+
/**
|
|
148
|
+
* {@link LRUCache.OptionsBase.noDeleteOnFetchRejection}
|
|
149
|
+
*/
|
|
150
|
+
noDeleteOnFetchRejection;
|
|
151
|
+
/**
|
|
152
|
+
* {@link LRUCache.OptionsBase.noDeleteOnStaleGet}
|
|
153
|
+
*/
|
|
154
|
+
noDeleteOnStaleGet;
|
|
155
|
+
/**
|
|
156
|
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchAbort}
|
|
157
|
+
*/
|
|
158
|
+
allowStaleOnFetchAbort;
|
|
159
|
+
/**
|
|
160
|
+
* {@link LRUCache.OptionsBase.allowStaleOnFetchRejection}
|
|
161
|
+
*/
|
|
162
|
+
allowStaleOnFetchRejection;
|
|
163
|
+
/**
|
|
164
|
+
* {@link LRUCache.OptionsBase.ignoreFetchAbort}
|
|
165
|
+
*/
|
|
166
|
+
ignoreFetchAbort;
|
|
167
|
+
// computed properties
|
|
168
|
+
#size;
|
|
169
|
+
#calculatedSize;
|
|
170
|
+
#keyMap;
|
|
171
|
+
#keyList;
|
|
172
|
+
#valList;
|
|
173
|
+
#next;
|
|
174
|
+
#prev;
|
|
175
|
+
#head;
|
|
176
|
+
#tail;
|
|
177
|
+
#free;
|
|
178
|
+
#disposed;
|
|
179
|
+
#sizes;
|
|
180
|
+
#starts;
|
|
181
|
+
#ttls;
|
|
182
|
+
#hasDispose;
|
|
183
|
+
#hasFetchMethod;
|
|
184
|
+
#hasDisposeAfter;
|
|
185
|
+
/**
|
|
186
|
+
* Do not call this method unless you need to inspect the
|
|
187
|
+
* inner workings of the cache. If anything returned by this
|
|
188
|
+
* object is modified in any way, strange breakage may occur.
|
|
189
|
+
*
|
|
190
|
+
* These fields are private for a reason!
|
|
191
|
+
*
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
static unsafeExposeInternals(c) {
|
|
195
|
+
return {
|
|
196
|
+
// properties
|
|
197
|
+
starts: c.#starts,
|
|
198
|
+
ttls: c.#ttls,
|
|
199
|
+
sizes: c.#sizes,
|
|
200
|
+
keyMap: c.#keyMap,
|
|
201
|
+
keyList: c.#keyList,
|
|
202
|
+
valList: c.#valList,
|
|
203
|
+
next: c.#next,
|
|
204
|
+
prev: c.#prev,
|
|
205
|
+
get head() {
|
|
206
|
+
return c.#head;
|
|
207
|
+
},
|
|
208
|
+
get tail() {
|
|
209
|
+
return c.#tail;
|
|
210
|
+
},
|
|
211
|
+
free: c.#free,
|
|
212
|
+
// methods
|
|
213
|
+
isBackgroundFetch: (p) => c.#isBackgroundFetch(p),
|
|
214
|
+
backgroundFetch: (k, index, options, context) => c.#backgroundFetch(k, index, options, context),
|
|
215
|
+
moveToTail: (index) => c.#moveToTail(index),
|
|
216
|
+
indexes: (options) => c.#indexes(options),
|
|
217
|
+
rindexes: (options) => c.#rindexes(options),
|
|
218
|
+
isStale: (index) => c.#isStale(index)
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// Protected read-only members
|
|
222
|
+
/**
|
|
223
|
+
* {@link LRUCache.OptionsBase.max} (read-only)
|
|
224
|
+
*/
|
|
225
|
+
get max() {
|
|
226
|
+
return this.#max;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* {@link LRUCache.OptionsBase.maxSize} (read-only)
|
|
230
|
+
*/
|
|
231
|
+
get maxSize() {
|
|
232
|
+
return this.#maxSize;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* The total computed size of items in the cache (read-only)
|
|
236
|
+
*/
|
|
237
|
+
get calculatedSize() {
|
|
238
|
+
return this.#calculatedSize;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The number of items stored in the cache (read-only)
|
|
242
|
+
*/
|
|
243
|
+
get size() {
|
|
244
|
+
return this.#size;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* {@link LRUCache.OptionsBase.fetchMethod} (read-only)
|
|
248
|
+
*/
|
|
249
|
+
get fetchMethod() {
|
|
250
|
+
return this.#fetchMethod;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* {@link LRUCache.OptionsBase.dispose} (read-only)
|
|
254
|
+
*/
|
|
255
|
+
get dispose() {
|
|
256
|
+
return this.#dispose;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* {@link LRUCache.OptionsBase.disposeAfter} (read-only)
|
|
260
|
+
*/
|
|
261
|
+
get disposeAfter() {
|
|
262
|
+
return this.#disposeAfter;
|
|
263
|
+
}
|
|
264
|
+
constructor(options) {
|
|
265
|
+
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
|
|
266
|
+
if (max !== 0 && !isPosInt(max)) {
|
|
267
|
+
throw new TypeError("max option must be a nonnegative integer");
|
|
268
|
+
}
|
|
269
|
+
const UintArray = max ? getUintArray(max) : Array;
|
|
270
|
+
if (!UintArray) {
|
|
271
|
+
throw new Error("invalid max value: " + max);
|
|
272
|
+
}
|
|
273
|
+
this.#max = max;
|
|
274
|
+
this.#maxSize = maxSize;
|
|
275
|
+
this.maxEntrySize = maxEntrySize || this.#maxSize;
|
|
276
|
+
this.sizeCalculation = sizeCalculation;
|
|
277
|
+
if (this.sizeCalculation) {
|
|
278
|
+
if (!this.#maxSize && !this.maxEntrySize) {
|
|
279
|
+
throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");
|
|
280
|
+
}
|
|
281
|
+
if (typeof this.sizeCalculation !== "function") {
|
|
282
|
+
throw new TypeError("sizeCalculation set to non-function");
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (fetchMethod !== void 0 && typeof fetchMethod !== "function") {
|
|
286
|
+
throw new TypeError("fetchMethod must be a function if specified");
|
|
287
|
+
}
|
|
288
|
+
this.#fetchMethod = fetchMethod;
|
|
289
|
+
this.#hasFetchMethod = !!fetchMethod;
|
|
290
|
+
this.#keyMap = /* @__PURE__ */ new Map();
|
|
291
|
+
this.#keyList = new Array(max).fill(void 0);
|
|
292
|
+
this.#valList = new Array(max).fill(void 0);
|
|
293
|
+
this.#next = new UintArray(max);
|
|
294
|
+
this.#prev = new UintArray(max);
|
|
295
|
+
this.#head = 0;
|
|
296
|
+
this.#tail = 0;
|
|
297
|
+
this.#free = Stack.create(max);
|
|
298
|
+
this.#size = 0;
|
|
299
|
+
this.#calculatedSize = 0;
|
|
300
|
+
if (typeof dispose === "function") {
|
|
301
|
+
this.#dispose = dispose;
|
|
302
|
+
}
|
|
303
|
+
if (typeof disposeAfter === "function") {
|
|
304
|
+
this.#disposeAfter = disposeAfter;
|
|
305
|
+
this.#disposed = [];
|
|
306
|
+
} else {
|
|
307
|
+
this.#disposeAfter = void 0;
|
|
308
|
+
this.#disposed = void 0;
|
|
309
|
+
}
|
|
310
|
+
this.#hasDispose = !!this.#dispose;
|
|
311
|
+
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
312
|
+
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
313
|
+
this.noUpdateTTL = !!noUpdateTTL;
|
|
314
|
+
this.noDeleteOnFetchRejection = !!noDeleteOnFetchRejection;
|
|
315
|
+
this.allowStaleOnFetchRejection = !!allowStaleOnFetchRejection;
|
|
316
|
+
this.allowStaleOnFetchAbort = !!allowStaleOnFetchAbort;
|
|
317
|
+
this.ignoreFetchAbort = !!ignoreFetchAbort;
|
|
318
|
+
if (this.maxEntrySize !== 0) {
|
|
319
|
+
if (this.#maxSize !== 0) {
|
|
320
|
+
if (!isPosInt(this.#maxSize)) {
|
|
321
|
+
throw new TypeError("maxSize must be a positive integer if specified");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!isPosInt(this.maxEntrySize)) {
|
|
325
|
+
throw new TypeError("maxEntrySize must be a positive integer if specified");
|
|
326
|
+
}
|
|
327
|
+
this.#initializeSizeTracking();
|
|
328
|
+
}
|
|
329
|
+
this.allowStale = !!allowStale;
|
|
330
|
+
this.noDeleteOnStaleGet = !!noDeleteOnStaleGet;
|
|
331
|
+
this.updateAgeOnGet = !!updateAgeOnGet;
|
|
332
|
+
this.updateAgeOnHas = !!updateAgeOnHas;
|
|
333
|
+
this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 ? ttlResolution : 1;
|
|
334
|
+
this.ttlAutopurge = !!ttlAutopurge;
|
|
335
|
+
this.ttl = ttl || 0;
|
|
336
|
+
if (this.ttl) {
|
|
337
|
+
if (!isPosInt(this.ttl)) {
|
|
338
|
+
throw new TypeError("ttl must be a positive integer if specified");
|
|
339
|
+
}
|
|
340
|
+
this.#initializeTTLTracking();
|
|
341
|
+
}
|
|
342
|
+
if (this.#max === 0 && this.ttl === 0 && this.#maxSize === 0) {
|
|
343
|
+
throw new TypeError("At least one of max, maxSize, or ttl is required");
|
|
344
|
+
}
|
|
345
|
+
if (!this.ttlAutopurge && !this.#max && !this.#maxSize) {
|
|
346
|
+
const code = "LRU_CACHE_UNBOUNDED";
|
|
347
|
+
if (shouldWarn(code)) {
|
|
348
|
+
warned.add(code);
|
|
349
|
+
const msg = "TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.";
|
|
350
|
+
emitWarning(msg, "UnboundedCacheWarning", code, _LRUCache);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Return the remaining TTL time for a given entry key
|
|
356
|
+
*/
|
|
357
|
+
getRemainingTTL(key) {
|
|
358
|
+
return this.#keyMap.has(key) ? Infinity : 0;
|
|
359
|
+
}
|
|
360
|
+
#initializeTTLTracking() {
|
|
361
|
+
const ttls = new ZeroArray(this.#max);
|
|
362
|
+
const starts = new ZeroArray(this.#max);
|
|
363
|
+
this.#ttls = ttls;
|
|
364
|
+
this.#starts = starts;
|
|
365
|
+
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
366
|
+
starts[index] = ttl !== 0 ? start : 0;
|
|
367
|
+
ttls[index] = ttl;
|
|
368
|
+
if (ttl !== 0 && this.ttlAutopurge) {
|
|
369
|
+
const t = setTimeout(() => {
|
|
370
|
+
if (this.#isStale(index)) {
|
|
371
|
+
this.delete(this.#keyList[index]);
|
|
372
|
+
}
|
|
373
|
+
}, ttl + 1);
|
|
374
|
+
if (t.unref) {
|
|
375
|
+
t.unref();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
this.#updateItemAge = (index) => {
|
|
380
|
+
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
381
|
+
};
|
|
382
|
+
this.#statusTTL = (status, index) => {
|
|
383
|
+
if (ttls[index]) {
|
|
384
|
+
const ttl = ttls[index];
|
|
385
|
+
const start = starts[index];
|
|
386
|
+
if (!ttl || !start)
|
|
387
|
+
return;
|
|
388
|
+
status.ttl = ttl;
|
|
389
|
+
status.start = start;
|
|
390
|
+
status.now = cachedNow || getNow();
|
|
391
|
+
const age = status.now - start;
|
|
392
|
+
status.remainingTTL = ttl - age;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
let cachedNow = 0;
|
|
396
|
+
const getNow = () => {
|
|
397
|
+
const n = perf.now();
|
|
398
|
+
if (this.ttlResolution > 0) {
|
|
399
|
+
cachedNow = n;
|
|
400
|
+
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
401
|
+
if (t.unref) {
|
|
402
|
+
t.unref();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return n;
|
|
406
|
+
};
|
|
407
|
+
this.getRemainingTTL = (key) => {
|
|
408
|
+
const index = this.#keyMap.get(key);
|
|
409
|
+
if (index === void 0) {
|
|
410
|
+
return 0;
|
|
411
|
+
}
|
|
412
|
+
const ttl = ttls[index];
|
|
413
|
+
const start = starts[index];
|
|
414
|
+
if (!ttl || !start) {
|
|
415
|
+
return Infinity;
|
|
416
|
+
}
|
|
417
|
+
const age = (cachedNow || getNow()) - start;
|
|
418
|
+
return ttl - age;
|
|
419
|
+
};
|
|
420
|
+
this.#isStale = (index) => {
|
|
421
|
+
const s = starts[index];
|
|
422
|
+
const t = ttls[index];
|
|
423
|
+
return !!t && !!s && (cachedNow || getNow()) - s > t;
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
// conditionally set private methods related to TTL
|
|
427
|
+
#updateItemAge = () => {
|
|
428
|
+
};
|
|
429
|
+
#statusTTL = () => {
|
|
430
|
+
};
|
|
431
|
+
#setItemTTL = () => {
|
|
432
|
+
};
|
|
433
|
+
/* c8 ignore stop */
|
|
434
|
+
#isStale = () => false;
|
|
435
|
+
#initializeSizeTracking() {
|
|
436
|
+
const sizes = new ZeroArray(this.#max);
|
|
437
|
+
this.#calculatedSize = 0;
|
|
438
|
+
this.#sizes = sizes;
|
|
439
|
+
this.#removeItemSize = (index) => {
|
|
440
|
+
this.#calculatedSize -= sizes[index];
|
|
441
|
+
sizes[index] = 0;
|
|
442
|
+
};
|
|
443
|
+
this.#requireSize = (k, v, size, sizeCalculation) => {
|
|
444
|
+
if (this.#isBackgroundFetch(v)) {
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
if (!isPosInt(size)) {
|
|
448
|
+
if (sizeCalculation) {
|
|
449
|
+
if (typeof sizeCalculation !== "function") {
|
|
450
|
+
throw new TypeError("sizeCalculation must be a function");
|
|
451
|
+
}
|
|
452
|
+
size = sizeCalculation(v, k);
|
|
453
|
+
if (!isPosInt(size)) {
|
|
454
|
+
throw new TypeError("sizeCalculation return invalid (expect positive integer)");
|
|
455
|
+
}
|
|
456
|
+
} else {
|
|
457
|
+
throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return size;
|
|
461
|
+
};
|
|
462
|
+
this.#addItemSize = (index, size, status) => {
|
|
463
|
+
sizes[index] = size;
|
|
464
|
+
if (this.#maxSize) {
|
|
465
|
+
const maxSize = this.#maxSize - sizes[index];
|
|
466
|
+
while (this.#calculatedSize > maxSize) {
|
|
467
|
+
this.#evict(true);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
this.#calculatedSize += sizes[index];
|
|
471
|
+
if (status) {
|
|
472
|
+
status.entrySize = size;
|
|
473
|
+
status.totalCalculatedSize = this.#calculatedSize;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
#removeItemSize = (_i) => {
|
|
478
|
+
};
|
|
479
|
+
#addItemSize = (_i, _s, _st) => {
|
|
480
|
+
};
|
|
481
|
+
#requireSize = (_k, _v, size, sizeCalculation) => {
|
|
482
|
+
if (size || sizeCalculation) {
|
|
483
|
+
throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");
|
|
484
|
+
}
|
|
485
|
+
return 0;
|
|
486
|
+
};
|
|
487
|
+
*#indexes({ allowStale = this.allowStale } = {}) {
|
|
488
|
+
if (this.#size) {
|
|
489
|
+
for (let i = this.#tail; true; ) {
|
|
490
|
+
if (!this.#isValidIndex(i)) {
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
if (allowStale || !this.#isStale(i)) {
|
|
494
|
+
yield i;
|
|
495
|
+
}
|
|
496
|
+
if (i === this.#head) {
|
|
497
|
+
break;
|
|
498
|
+
} else {
|
|
499
|
+
i = this.#prev[i];
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
*#rindexes({ allowStale = this.allowStale } = {}) {
|
|
505
|
+
if (this.#size) {
|
|
506
|
+
for (let i = this.#head; true; ) {
|
|
507
|
+
if (!this.#isValidIndex(i)) {
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
if (allowStale || !this.#isStale(i)) {
|
|
511
|
+
yield i;
|
|
512
|
+
}
|
|
513
|
+
if (i === this.#tail) {
|
|
514
|
+
break;
|
|
515
|
+
} else {
|
|
516
|
+
i = this.#next[i];
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
#isValidIndex(index) {
|
|
522
|
+
return index !== void 0 && this.#keyMap.get(this.#keyList[index]) === index;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Return a generator yielding `[key, value]` pairs,
|
|
526
|
+
* in order from most recently used to least recently used.
|
|
527
|
+
*/
|
|
528
|
+
*entries() {
|
|
529
|
+
for (const i of this.#indexes()) {
|
|
530
|
+
if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
531
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Inverse order version of {@link LRUCache.entries}
|
|
537
|
+
*
|
|
538
|
+
* Return a generator yielding `[key, value]` pairs,
|
|
539
|
+
* in order from least recently used to most recently used.
|
|
540
|
+
*/
|
|
541
|
+
*rentries() {
|
|
542
|
+
for (const i of this.#rindexes()) {
|
|
543
|
+
if (this.#valList[i] !== void 0 && this.#keyList[i] !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
544
|
+
yield [this.#keyList[i], this.#valList[i]];
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Return a generator yielding the keys in the cache,
|
|
550
|
+
* in order from most recently used to least recently used.
|
|
551
|
+
*/
|
|
552
|
+
*keys() {
|
|
553
|
+
for (const i of this.#indexes()) {
|
|
554
|
+
const k = this.#keyList[i];
|
|
555
|
+
if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
556
|
+
yield k;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Inverse order version of {@link LRUCache.keys}
|
|
562
|
+
*
|
|
563
|
+
* Return a generator yielding the keys in the cache,
|
|
564
|
+
* in order from least recently used to most recently used.
|
|
565
|
+
*/
|
|
566
|
+
*rkeys() {
|
|
567
|
+
for (const i of this.#rindexes()) {
|
|
568
|
+
const k = this.#keyList[i];
|
|
569
|
+
if (k !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
570
|
+
yield k;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Return a generator yielding the values in the cache,
|
|
576
|
+
* in order from most recently used to least recently used.
|
|
577
|
+
*/
|
|
578
|
+
*values() {
|
|
579
|
+
for (const i of this.#indexes()) {
|
|
580
|
+
const v = this.#valList[i];
|
|
581
|
+
if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
582
|
+
yield this.#valList[i];
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Inverse order version of {@link LRUCache.values}
|
|
588
|
+
*
|
|
589
|
+
* Return a generator yielding the values in the cache,
|
|
590
|
+
* in order from least recently used to most recently used.
|
|
591
|
+
*/
|
|
592
|
+
*rvalues() {
|
|
593
|
+
for (const i of this.#rindexes()) {
|
|
594
|
+
const v = this.#valList[i];
|
|
595
|
+
if (v !== void 0 && !this.#isBackgroundFetch(this.#valList[i])) {
|
|
596
|
+
yield this.#valList[i];
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Iterating over the cache itself yields the same results as
|
|
602
|
+
* {@link LRUCache.entries}
|
|
603
|
+
*/
|
|
604
|
+
[Symbol.iterator]() {
|
|
605
|
+
return this.entries();
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* A String value that is used in the creation of the default string description of an object.
|
|
609
|
+
* Called by the built-in method Object.prototype.toString.
|
|
610
|
+
*/
|
|
611
|
+
[Symbol.toStringTag] = "LRUCache";
|
|
612
|
+
/**
|
|
613
|
+
* Find a value for which the supplied fn method returns a truthy value,
|
|
614
|
+
* similar to Array.find(). fn is called as fn(value, key, cache).
|
|
615
|
+
*/
|
|
616
|
+
find(fn, getOptions = {}) {
|
|
617
|
+
for (const i of this.#indexes()) {
|
|
618
|
+
const v = this.#valList[i];
|
|
619
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
620
|
+
if (value === void 0)
|
|
621
|
+
continue;
|
|
622
|
+
if (fn(value, this.#keyList[i], this)) {
|
|
623
|
+
return this.get(this.#keyList[i], getOptions);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Call the supplied function on each item in the cache, in order from
|
|
629
|
+
* most recently used to least recently used. fn is called as
|
|
630
|
+
* fn(value, key, cache). Does not update age or recenty of use.
|
|
631
|
+
* Does not iterate over stale values.
|
|
632
|
+
*/
|
|
633
|
+
forEach(fn, thisp = this) {
|
|
634
|
+
for (const i of this.#indexes()) {
|
|
635
|
+
const v = this.#valList[i];
|
|
636
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
637
|
+
if (value === void 0)
|
|
638
|
+
continue;
|
|
639
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* The same as {@link LRUCache.forEach} but items are iterated over in
|
|
644
|
+
* reverse order. (ie, less recently used items are iterated over first.)
|
|
645
|
+
*/
|
|
646
|
+
rforEach(fn, thisp = this) {
|
|
647
|
+
for (const i of this.#rindexes()) {
|
|
648
|
+
const v = this.#valList[i];
|
|
649
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
650
|
+
if (value === void 0)
|
|
651
|
+
continue;
|
|
652
|
+
fn.call(thisp, value, this.#keyList[i], this);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Delete any stale entries. Returns true if anything was removed,
|
|
657
|
+
* false otherwise.
|
|
658
|
+
*/
|
|
659
|
+
purgeStale() {
|
|
660
|
+
let deleted = false;
|
|
661
|
+
for (const i of this.#rindexes({ allowStale: true })) {
|
|
662
|
+
if (this.#isStale(i)) {
|
|
663
|
+
this.delete(this.#keyList[i]);
|
|
664
|
+
deleted = true;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return deleted;
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Get the extended info about a given entry, to get its value, size, and
|
|
671
|
+
* TTL info simultaneously. Like {@link LRUCache#dump}, but just for a
|
|
672
|
+
* single key. Always returns stale values, if their info is found in the
|
|
673
|
+
* cache, so be sure to check for expired TTLs if relevant.
|
|
674
|
+
*/
|
|
675
|
+
info(key) {
|
|
676
|
+
const i = this.#keyMap.get(key);
|
|
677
|
+
if (i === void 0)
|
|
678
|
+
return void 0;
|
|
679
|
+
const v = this.#valList[i];
|
|
680
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
681
|
+
if (value === void 0)
|
|
682
|
+
return void 0;
|
|
683
|
+
const entry = { value };
|
|
684
|
+
if (this.#ttls && this.#starts) {
|
|
685
|
+
const ttl = this.#ttls[i];
|
|
686
|
+
const start = this.#starts[i];
|
|
687
|
+
if (ttl && start) {
|
|
688
|
+
const remain = ttl - (perf.now() - start);
|
|
689
|
+
entry.ttl = remain;
|
|
690
|
+
entry.start = Date.now();
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (this.#sizes) {
|
|
694
|
+
entry.size = this.#sizes[i];
|
|
695
|
+
}
|
|
696
|
+
return entry;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Return an array of [key, {@link LRUCache.Entry}] tuples which can be
|
|
700
|
+
* passed to cache.load()
|
|
701
|
+
*/
|
|
702
|
+
dump() {
|
|
703
|
+
const arr = [];
|
|
704
|
+
for (const i of this.#indexes({ allowStale: true })) {
|
|
705
|
+
const key = this.#keyList[i];
|
|
706
|
+
const v = this.#valList[i];
|
|
707
|
+
const value = this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
708
|
+
if (value === void 0 || key === void 0)
|
|
709
|
+
continue;
|
|
710
|
+
const entry = { value };
|
|
711
|
+
if (this.#ttls && this.#starts) {
|
|
712
|
+
entry.ttl = this.#ttls[i];
|
|
713
|
+
const age = perf.now() - this.#starts[i];
|
|
714
|
+
entry.start = Math.floor(Date.now() - age);
|
|
715
|
+
}
|
|
716
|
+
if (this.#sizes) {
|
|
717
|
+
entry.size = this.#sizes[i];
|
|
718
|
+
}
|
|
719
|
+
arr.unshift([key, entry]);
|
|
720
|
+
}
|
|
721
|
+
return arr;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Reset the cache and load in the items in entries in the order listed.
|
|
725
|
+
* Note that the shape of the resulting cache may be different if the
|
|
726
|
+
* same options are not used in both caches.
|
|
727
|
+
*/
|
|
728
|
+
load(arr) {
|
|
729
|
+
this.clear();
|
|
730
|
+
for (const [key, entry] of arr) {
|
|
731
|
+
if (entry.start) {
|
|
732
|
+
const age = Date.now() - entry.start;
|
|
733
|
+
entry.start = perf.now() - age;
|
|
734
|
+
}
|
|
735
|
+
this.set(key, entry.value, entry);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Add a value to the cache.
|
|
740
|
+
*
|
|
741
|
+
* Note: if `undefined` is specified as a value, this is an alias for
|
|
742
|
+
* {@link LRUCache#delete}
|
|
743
|
+
*/
|
|
744
|
+
set(k, v, setOptions = {}) {
|
|
745
|
+
if (v === void 0) {
|
|
746
|
+
this.delete(k);
|
|
747
|
+
return this;
|
|
748
|
+
}
|
|
749
|
+
const { ttl = this.ttl, start, noDisposeOnSet = this.noDisposeOnSet, sizeCalculation = this.sizeCalculation, status } = setOptions;
|
|
750
|
+
let { noUpdateTTL = this.noUpdateTTL } = setOptions;
|
|
751
|
+
const size = this.#requireSize(k, v, setOptions.size || 0, sizeCalculation);
|
|
752
|
+
if (this.maxEntrySize && size > this.maxEntrySize) {
|
|
753
|
+
if (status) {
|
|
754
|
+
status.set = "miss";
|
|
755
|
+
status.maxEntrySizeExceeded = true;
|
|
756
|
+
}
|
|
757
|
+
this.delete(k);
|
|
758
|
+
return this;
|
|
759
|
+
}
|
|
760
|
+
let index = this.#size === 0 ? void 0 : this.#keyMap.get(k);
|
|
761
|
+
if (index === void 0) {
|
|
762
|
+
index = this.#size === 0 ? this.#tail : this.#free.length !== 0 ? this.#free.pop() : this.#size === this.#max ? this.#evict(false) : this.#size;
|
|
763
|
+
this.#keyList[index] = k;
|
|
764
|
+
this.#valList[index] = v;
|
|
765
|
+
this.#keyMap.set(k, index);
|
|
766
|
+
this.#next[this.#tail] = index;
|
|
767
|
+
this.#prev[index] = this.#tail;
|
|
768
|
+
this.#tail = index;
|
|
769
|
+
this.#size++;
|
|
770
|
+
this.#addItemSize(index, size, status);
|
|
771
|
+
if (status)
|
|
772
|
+
status.set = "add";
|
|
773
|
+
noUpdateTTL = false;
|
|
774
|
+
} else {
|
|
775
|
+
this.#moveToTail(index);
|
|
776
|
+
const oldVal = this.#valList[index];
|
|
777
|
+
if (v !== oldVal) {
|
|
778
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(oldVal)) {
|
|
779
|
+
oldVal.__abortController.abort(new Error("replaced"));
|
|
780
|
+
const { __staleWhileFetching: s } = oldVal;
|
|
781
|
+
if (s !== void 0 && !noDisposeOnSet) {
|
|
782
|
+
if (this.#hasDispose) {
|
|
783
|
+
this.#dispose?.(s, k, "set");
|
|
784
|
+
}
|
|
785
|
+
if (this.#hasDisposeAfter) {
|
|
786
|
+
this.#disposed?.push([s, k, "set"]);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
} else if (!noDisposeOnSet) {
|
|
790
|
+
if (this.#hasDispose) {
|
|
791
|
+
this.#dispose?.(oldVal, k, "set");
|
|
792
|
+
}
|
|
793
|
+
if (this.#hasDisposeAfter) {
|
|
794
|
+
this.#disposed?.push([oldVal, k, "set"]);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
this.#removeItemSize(index);
|
|
798
|
+
this.#addItemSize(index, size, status);
|
|
799
|
+
this.#valList[index] = v;
|
|
800
|
+
if (status) {
|
|
801
|
+
status.set = "replace";
|
|
802
|
+
const oldValue = oldVal && this.#isBackgroundFetch(oldVal) ? oldVal.__staleWhileFetching : oldVal;
|
|
803
|
+
if (oldValue !== void 0)
|
|
804
|
+
status.oldValue = oldValue;
|
|
805
|
+
}
|
|
806
|
+
} else if (status) {
|
|
807
|
+
status.set = "update";
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (ttl !== 0 && !this.#ttls) {
|
|
811
|
+
this.#initializeTTLTracking();
|
|
812
|
+
}
|
|
813
|
+
if (this.#ttls) {
|
|
814
|
+
if (!noUpdateTTL) {
|
|
815
|
+
this.#setItemTTL(index, ttl, start);
|
|
816
|
+
}
|
|
817
|
+
if (status)
|
|
818
|
+
this.#statusTTL(status, index);
|
|
819
|
+
}
|
|
820
|
+
if (!noDisposeOnSet && this.#hasDisposeAfter && this.#disposed) {
|
|
821
|
+
const dt = this.#disposed;
|
|
822
|
+
let task;
|
|
823
|
+
while (task = dt?.shift()) {
|
|
824
|
+
this.#disposeAfter?.(...task);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return this;
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Evict the least recently used item, returning its value or
|
|
831
|
+
* `undefined` if cache is empty.
|
|
832
|
+
*/
|
|
833
|
+
pop() {
|
|
834
|
+
try {
|
|
835
|
+
while (this.#size) {
|
|
836
|
+
const val = this.#valList[this.#head];
|
|
837
|
+
this.#evict(true);
|
|
838
|
+
if (this.#isBackgroundFetch(val)) {
|
|
839
|
+
if (val.__staleWhileFetching) {
|
|
840
|
+
return val.__staleWhileFetching;
|
|
841
|
+
}
|
|
842
|
+
} else if (val !== void 0) {
|
|
843
|
+
return val;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
} finally {
|
|
847
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
848
|
+
const dt = this.#disposed;
|
|
849
|
+
let task;
|
|
850
|
+
while (task = dt?.shift()) {
|
|
851
|
+
this.#disposeAfter?.(...task);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
#evict(free) {
|
|
857
|
+
const head = this.#head;
|
|
858
|
+
const k = this.#keyList[head];
|
|
859
|
+
const v = this.#valList[head];
|
|
860
|
+
if (this.#hasFetchMethod && this.#isBackgroundFetch(v)) {
|
|
861
|
+
v.__abortController.abort(new Error("evicted"));
|
|
862
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
863
|
+
if (this.#hasDispose) {
|
|
864
|
+
this.#dispose?.(v, k, "evict");
|
|
865
|
+
}
|
|
866
|
+
if (this.#hasDisposeAfter) {
|
|
867
|
+
this.#disposed?.push([v, k, "evict"]);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
this.#removeItemSize(head);
|
|
871
|
+
if (free) {
|
|
872
|
+
this.#keyList[head] = void 0;
|
|
873
|
+
this.#valList[head] = void 0;
|
|
874
|
+
this.#free.push(head);
|
|
875
|
+
}
|
|
876
|
+
if (this.#size === 1) {
|
|
877
|
+
this.#head = this.#tail = 0;
|
|
878
|
+
this.#free.length = 0;
|
|
879
|
+
} else {
|
|
880
|
+
this.#head = this.#next[head];
|
|
881
|
+
}
|
|
882
|
+
this.#keyMap.delete(k);
|
|
883
|
+
this.#size--;
|
|
884
|
+
return head;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Check if a key is in the cache, without updating the recency of use.
|
|
888
|
+
* Will return false if the item is stale, even though it is technically
|
|
889
|
+
* in the cache.
|
|
890
|
+
*
|
|
891
|
+
* Will not update item age unless
|
|
892
|
+
* {@link LRUCache.OptionsBase.updateAgeOnHas} is set.
|
|
893
|
+
*/
|
|
894
|
+
has(k, hasOptions = {}) {
|
|
895
|
+
const { updateAgeOnHas = this.updateAgeOnHas, status } = hasOptions;
|
|
896
|
+
const index = this.#keyMap.get(k);
|
|
897
|
+
if (index !== void 0) {
|
|
898
|
+
const v = this.#valList[index];
|
|
899
|
+
if (this.#isBackgroundFetch(v) && v.__staleWhileFetching === void 0) {
|
|
900
|
+
return false;
|
|
901
|
+
}
|
|
902
|
+
if (!this.#isStale(index)) {
|
|
903
|
+
if (updateAgeOnHas) {
|
|
904
|
+
this.#updateItemAge(index);
|
|
905
|
+
}
|
|
906
|
+
if (status) {
|
|
907
|
+
status.has = "hit";
|
|
908
|
+
this.#statusTTL(status, index);
|
|
909
|
+
}
|
|
910
|
+
return true;
|
|
911
|
+
} else if (status) {
|
|
912
|
+
status.has = "stale";
|
|
913
|
+
this.#statusTTL(status, index);
|
|
914
|
+
}
|
|
915
|
+
} else if (status) {
|
|
916
|
+
status.has = "miss";
|
|
917
|
+
}
|
|
918
|
+
return false;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Like {@link LRUCache#get} but doesn't update recency or delete stale
|
|
922
|
+
* items.
|
|
923
|
+
*
|
|
924
|
+
* Returns `undefined` if the item is stale, unless
|
|
925
|
+
* {@link LRUCache.OptionsBase.allowStale} is set.
|
|
926
|
+
*/
|
|
927
|
+
peek(k, peekOptions = {}) {
|
|
928
|
+
const { allowStale = this.allowStale } = peekOptions;
|
|
929
|
+
const index = this.#keyMap.get(k);
|
|
930
|
+
if (index === void 0 || !allowStale && this.#isStale(index)) {
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const v = this.#valList[index];
|
|
934
|
+
return this.#isBackgroundFetch(v) ? v.__staleWhileFetching : v;
|
|
935
|
+
}
|
|
936
|
+
#backgroundFetch(k, index, options, context) {
|
|
937
|
+
const v = index === void 0 ? void 0 : this.#valList[index];
|
|
938
|
+
if (this.#isBackgroundFetch(v)) {
|
|
939
|
+
return v;
|
|
940
|
+
}
|
|
941
|
+
const ac = new AC();
|
|
942
|
+
const { signal } = options;
|
|
943
|
+
signal?.addEventListener("abort", () => ac.abort(signal.reason), {
|
|
944
|
+
signal: ac.signal
|
|
945
|
+
});
|
|
946
|
+
const fetchOpts = {
|
|
947
|
+
signal: ac.signal,
|
|
948
|
+
options,
|
|
949
|
+
context
|
|
950
|
+
};
|
|
951
|
+
const cb = (v2, updateCache = false) => {
|
|
952
|
+
const { aborted } = ac.signal;
|
|
953
|
+
const ignoreAbort = options.ignoreFetchAbort && v2 !== void 0;
|
|
954
|
+
if (options.status) {
|
|
955
|
+
if (aborted && !updateCache) {
|
|
956
|
+
options.status.fetchAborted = true;
|
|
957
|
+
options.status.fetchError = ac.signal.reason;
|
|
958
|
+
if (ignoreAbort)
|
|
959
|
+
options.status.fetchAbortIgnored = true;
|
|
960
|
+
} else {
|
|
961
|
+
options.status.fetchResolved = true;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (aborted && !ignoreAbort && !updateCache) {
|
|
965
|
+
return fetchFail(ac.signal.reason);
|
|
966
|
+
}
|
|
967
|
+
const bf2 = p;
|
|
968
|
+
if (this.#valList[index] === p) {
|
|
969
|
+
if (v2 === void 0) {
|
|
970
|
+
if (bf2.__staleWhileFetching) {
|
|
971
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
972
|
+
} else {
|
|
973
|
+
this.delete(k);
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
if (options.status)
|
|
977
|
+
options.status.fetchUpdated = true;
|
|
978
|
+
this.set(k, v2, fetchOpts.options);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
return v2;
|
|
982
|
+
};
|
|
983
|
+
const eb = (er) => {
|
|
984
|
+
if (options.status) {
|
|
985
|
+
options.status.fetchRejected = true;
|
|
986
|
+
options.status.fetchError = er;
|
|
987
|
+
}
|
|
988
|
+
return fetchFail(er);
|
|
989
|
+
};
|
|
990
|
+
const fetchFail = (er) => {
|
|
991
|
+
const { aborted } = ac.signal;
|
|
992
|
+
const allowStaleAborted = aborted && options.allowStaleOnFetchAbort;
|
|
993
|
+
const allowStale = allowStaleAborted || options.allowStaleOnFetchRejection;
|
|
994
|
+
const noDelete = allowStale || options.noDeleteOnFetchRejection;
|
|
995
|
+
const bf2 = p;
|
|
996
|
+
if (this.#valList[index] === p) {
|
|
997
|
+
const del = !noDelete || bf2.__staleWhileFetching === void 0;
|
|
998
|
+
if (del) {
|
|
999
|
+
this.delete(k);
|
|
1000
|
+
} else if (!allowStaleAborted) {
|
|
1001
|
+
this.#valList[index] = bf2.__staleWhileFetching;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
if (allowStale) {
|
|
1005
|
+
if (options.status && bf2.__staleWhileFetching !== void 0) {
|
|
1006
|
+
options.status.returnedStale = true;
|
|
1007
|
+
}
|
|
1008
|
+
return bf2.__staleWhileFetching;
|
|
1009
|
+
} else if (bf2.__returned === bf2) {
|
|
1010
|
+
throw er;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
const pcall = (res, rej) => {
|
|
1014
|
+
const fmp = this.#fetchMethod?.(k, v, fetchOpts);
|
|
1015
|
+
if (fmp && fmp instanceof Promise) {
|
|
1016
|
+
fmp.then((v2) => res(v2 === void 0 ? void 0 : v2), rej);
|
|
1017
|
+
}
|
|
1018
|
+
ac.signal.addEventListener("abort", () => {
|
|
1019
|
+
if (!options.ignoreFetchAbort || options.allowStaleOnFetchAbort) {
|
|
1020
|
+
res(void 0);
|
|
1021
|
+
if (options.allowStaleOnFetchAbort) {
|
|
1022
|
+
res = (v2) => cb(v2, true);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
};
|
|
1027
|
+
if (options.status)
|
|
1028
|
+
options.status.fetchDispatched = true;
|
|
1029
|
+
const p = new Promise(pcall).then(cb, eb);
|
|
1030
|
+
const bf = Object.assign(p, {
|
|
1031
|
+
__abortController: ac,
|
|
1032
|
+
__staleWhileFetching: v,
|
|
1033
|
+
__returned: void 0
|
|
1034
|
+
});
|
|
1035
|
+
if (index === void 0) {
|
|
1036
|
+
this.set(k, bf, { ...fetchOpts.options, status: void 0 });
|
|
1037
|
+
index = this.#keyMap.get(k);
|
|
1038
|
+
} else {
|
|
1039
|
+
this.#valList[index] = bf;
|
|
1040
|
+
}
|
|
1041
|
+
return bf;
|
|
1042
|
+
}
|
|
1043
|
+
#isBackgroundFetch(p) {
|
|
1044
|
+
if (!this.#hasFetchMethod)
|
|
1045
|
+
return false;
|
|
1046
|
+
const b = p;
|
|
1047
|
+
return !!b && b instanceof Promise && b.hasOwnProperty("__staleWhileFetching") && b.__abortController instanceof AC;
|
|
1048
|
+
}
|
|
1049
|
+
async fetch(k, fetchOptions = {}) {
|
|
1050
|
+
const {
|
|
1051
|
+
// get options
|
|
1052
|
+
allowStale = this.allowStale,
|
|
1053
|
+
updateAgeOnGet = this.updateAgeOnGet,
|
|
1054
|
+
noDeleteOnStaleGet = this.noDeleteOnStaleGet,
|
|
1055
|
+
// set options
|
|
1056
|
+
ttl = this.ttl,
|
|
1057
|
+
noDisposeOnSet = this.noDisposeOnSet,
|
|
1058
|
+
size = 0,
|
|
1059
|
+
sizeCalculation = this.sizeCalculation,
|
|
1060
|
+
noUpdateTTL = this.noUpdateTTL,
|
|
1061
|
+
// fetch exclusive options
|
|
1062
|
+
noDeleteOnFetchRejection = this.noDeleteOnFetchRejection,
|
|
1063
|
+
allowStaleOnFetchRejection = this.allowStaleOnFetchRejection,
|
|
1064
|
+
ignoreFetchAbort = this.ignoreFetchAbort,
|
|
1065
|
+
allowStaleOnFetchAbort = this.allowStaleOnFetchAbort,
|
|
1066
|
+
context,
|
|
1067
|
+
forceRefresh = false,
|
|
1068
|
+
status,
|
|
1069
|
+
signal
|
|
1070
|
+
} = fetchOptions;
|
|
1071
|
+
if (!this.#hasFetchMethod) {
|
|
1072
|
+
if (status)
|
|
1073
|
+
status.fetch = "get";
|
|
1074
|
+
return this.get(k, {
|
|
1075
|
+
allowStale,
|
|
1076
|
+
updateAgeOnGet,
|
|
1077
|
+
noDeleteOnStaleGet,
|
|
1078
|
+
status
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
const options = {
|
|
1082
|
+
allowStale,
|
|
1083
|
+
updateAgeOnGet,
|
|
1084
|
+
noDeleteOnStaleGet,
|
|
1085
|
+
ttl,
|
|
1086
|
+
noDisposeOnSet,
|
|
1087
|
+
size,
|
|
1088
|
+
sizeCalculation,
|
|
1089
|
+
noUpdateTTL,
|
|
1090
|
+
noDeleteOnFetchRejection,
|
|
1091
|
+
allowStaleOnFetchRejection,
|
|
1092
|
+
allowStaleOnFetchAbort,
|
|
1093
|
+
ignoreFetchAbort,
|
|
1094
|
+
status,
|
|
1095
|
+
signal
|
|
1096
|
+
};
|
|
1097
|
+
let index = this.#keyMap.get(k);
|
|
1098
|
+
if (index === void 0) {
|
|
1099
|
+
if (status)
|
|
1100
|
+
status.fetch = "miss";
|
|
1101
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
1102
|
+
return p.__returned = p;
|
|
1103
|
+
} else {
|
|
1104
|
+
const v = this.#valList[index];
|
|
1105
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1106
|
+
const stale = allowStale && v.__staleWhileFetching !== void 0;
|
|
1107
|
+
if (status) {
|
|
1108
|
+
status.fetch = "inflight";
|
|
1109
|
+
if (stale)
|
|
1110
|
+
status.returnedStale = true;
|
|
1111
|
+
}
|
|
1112
|
+
return stale ? v.__staleWhileFetching : v.__returned = v;
|
|
1113
|
+
}
|
|
1114
|
+
const isStale = this.#isStale(index);
|
|
1115
|
+
if (!forceRefresh && !isStale) {
|
|
1116
|
+
if (status)
|
|
1117
|
+
status.fetch = "hit";
|
|
1118
|
+
this.#moveToTail(index);
|
|
1119
|
+
if (updateAgeOnGet) {
|
|
1120
|
+
this.#updateItemAge(index);
|
|
1121
|
+
}
|
|
1122
|
+
if (status)
|
|
1123
|
+
this.#statusTTL(status, index);
|
|
1124
|
+
return v;
|
|
1125
|
+
}
|
|
1126
|
+
const p = this.#backgroundFetch(k, index, options, context);
|
|
1127
|
+
const hasStale = p.__staleWhileFetching !== void 0;
|
|
1128
|
+
const staleVal = hasStale && allowStale;
|
|
1129
|
+
if (status) {
|
|
1130
|
+
status.fetch = isStale ? "stale" : "refresh";
|
|
1131
|
+
if (staleVal && isStale)
|
|
1132
|
+
status.returnedStale = true;
|
|
1133
|
+
}
|
|
1134
|
+
return staleVal ? p.__staleWhileFetching : p.__returned = p;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Return a value from the cache. Will update the recency of the cache
|
|
1139
|
+
* entry found.
|
|
1140
|
+
*
|
|
1141
|
+
* If the key is not found, get() will return `undefined`.
|
|
1142
|
+
*/
|
|
1143
|
+
get(k, getOptions = {}) {
|
|
1144
|
+
const { allowStale = this.allowStale, updateAgeOnGet = this.updateAgeOnGet, noDeleteOnStaleGet = this.noDeleteOnStaleGet, status } = getOptions;
|
|
1145
|
+
const index = this.#keyMap.get(k);
|
|
1146
|
+
if (index !== void 0) {
|
|
1147
|
+
const value = this.#valList[index];
|
|
1148
|
+
const fetching = this.#isBackgroundFetch(value);
|
|
1149
|
+
if (status)
|
|
1150
|
+
this.#statusTTL(status, index);
|
|
1151
|
+
if (this.#isStale(index)) {
|
|
1152
|
+
if (status)
|
|
1153
|
+
status.get = "stale";
|
|
1154
|
+
if (!fetching) {
|
|
1155
|
+
if (!noDeleteOnStaleGet) {
|
|
1156
|
+
this.delete(k);
|
|
1157
|
+
}
|
|
1158
|
+
if (status && allowStale)
|
|
1159
|
+
status.returnedStale = true;
|
|
1160
|
+
return allowStale ? value : void 0;
|
|
1161
|
+
} else {
|
|
1162
|
+
if (status && allowStale && value.__staleWhileFetching !== void 0) {
|
|
1163
|
+
status.returnedStale = true;
|
|
1164
|
+
}
|
|
1165
|
+
return allowStale ? value.__staleWhileFetching : void 0;
|
|
1166
|
+
}
|
|
1167
|
+
} else {
|
|
1168
|
+
if (status)
|
|
1169
|
+
status.get = "hit";
|
|
1170
|
+
if (fetching) {
|
|
1171
|
+
return value.__staleWhileFetching;
|
|
1172
|
+
}
|
|
1173
|
+
this.#moveToTail(index);
|
|
1174
|
+
if (updateAgeOnGet) {
|
|
1175
|
+
this.#updateItemAge(index);
|
|
1176
|
+
}
|
|
1177
|
+
return value;
|
|
1178
|
+
}
|
|
1179
|
+
} else if (status) {
|
|
1180
|
+
status.get = "miss";
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
#connect(p, n) {
|
|
1184
|
+
this.#prev[n] = p;
|
|
1185
|
+
this.#next[p] = n;
|
|
1186
|
+
}
|
|
1187
|
+
#moveToTail(index) {
|
|
1188
|
+
if (index !== this.#tail) {
|
|
1189
|
+
if (index === this.#head) {
|
|
1190
|
+
this.#head = this.#next[index];
|
|
1191
|
+
} else {
|
|
1192
|
+
this.#connect(this.#prev[index], this.#next[index]);
|
|
1193
|
+
}
|
|
1194
|
+
this.#connect(this.#tail, index);
|
|
1195
|
+
this.#tail = index;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Deletes a key out of the cache.
|
|
1200
|
+
* Returns true if the key was deleted, false otherwise.
|
|
1201
|
+
*/
|
|
1202
|
+
delete(k) {
|
|
1203
|
+
let deleted = false;
|
|
1204
|
+
if (this.#size !== 0) {
|
|
1205
|
+
const index = this.#keyMap.get(k);
|
|
1206
|
+
if (index !== void 0) {
|
|
1207
|
+
deleted = true;
|
|
1208
|
+
if (this.#size === 1) {
|
|
1209
|
+
this.clear();
|
|
1210
|
+
} else {
|
|
1211
|
+
this.#removeItemSize(index);
|
|
1212
|
+
const v = this.#valList[index];
|
|
1213
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1214
|
+
v.__abortController.abort(new Error("deleted"));
|
|
1215
|
+
} else if (this.#hasDispose || this.#hasDisposeAfter) {
|
|
1216
|
+
if (this.#hasDispose) {
|
|
1217
|
+
this.#dispose?.(v, k, "delete");
|
|
1218
|
+
}
|
|
1219
|
+
if (this.#hasDisposeAfter) {
|
|
1220
|
+
this.#disposed?.push([v, k, "delete"]);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
this.#keyMap.delete(k);
|
|
1224
|
+
this.#keyList[index] = void 0;
|
|
1225
|
+
this.#valList[index] = void 0;
|
|
1226
|
+
if (index === this.#tail) {
|
|
1227
|
+
this.#tail = this.#prev[index];
|
|
1228
|
+
} else if (index === this.#head) {
|
|
1229
|
+
this.#head = this.#next[index];
|
|
1230
|
+
} else {
|
|
1231
|
+
const pi = this.#prev[index];
|
|
1232
|
+
this.#next[pi] = this.#next[index];
|
|
1233
|
+
const ni = this.#next[index];
|
|
1234
|
+
this.#prev[ni] = this.#prev[index];
|
|
1235
|
+
}
|
|
1236
|
+
this.#size--;
|
|
1237
|
+
this.#free.push(index);
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
if (this.#hasDisposeAfter && this.#disposed?.length) {
|
|
1242
|
+
const dt = this.#disposed;
|
|
1243
|
+
let task;
|
|
1244
|
+
while (task = dt?.shift()) {
|
|
1245
|
+
this.#disposeAfter?.(...task);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
return deleted;
|
|
1249
|
+
}
|
|
1250
|
+
/**
|
|
1251
|
+
* Clear the cache entirely, throwing away all values.
|
|
1252
|
+
*/
|
|
1253
|
+
clear() {
|
|
1254
|
+
for (const index of this.#rindexes({ allowStale: true })) {
|
|
1255
|
+
const v = this.#valList[index];
|
|
1256
|
+
if (this.#isBackgroundFetch(v)) {
|
|
1257
|
+
v.__abortController.abort(new Error("deleted"));
|
|
1258
|
+
} else {
|
|
1259
|
+
const k = this.#keyList[index];
|
|
1260
|
+
if (this.#hasDispose) {
|
|
1261
|
+
this.#dispose?.(v, k, "delete");
|
|
1262
|
+
}
|
|
1263
|
+
if (this.#hasDisposeAfter) {
|
|
1264
|
+
this.#disposed?.push([v, k, "delete"]);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
this.#keyMap.clear();
|
|
1269
|
+
this.#valList.fill(void 0);
|
|
1270
|
+
this.#keyList.fill(void 0);
|
|
1271
|
+
if (this.#ttls && this.#starts) {
|
|
1272
|
+
this.#ttls.fill(0);
|
|
1273
|
+
this.#starts.fill(0);
|
|
1274
|
+
}
|
|
1275
|
+
if (this.#sizes) {
|
|
1276
|
+
this.#sizes.fill(0);
|
|
1277
|
+
}
|
|
1278
|
+
this.#head = 0;
|
|
1279
|
+
this.#tail = 0;
|
|
1280
|
+
this.#free.length = 0;
|
|
1281
|
+
this.#calculatedSize = 0;
|
|
1282
|
+
this.#size = 0;
|
|
1283
|
+
if (this.#hasDisposeAfter && this.#disposed) {
|
|
1284
|
+
const dt = this.#disposed;
|
|
1285
|
+
let task;
|
|
1286
|
+
while (task = dt?.shift()) {
|
|
1287
|
+
this.#disposeAfter?.(...task);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
};
|
|
1292
|
+
exports.LRUCache = LRUCache;
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
|
|
1296
|
+
// node_modules/hosted-git-info/lib/hosts.js
|
|
1297
|
+
var require_hosts = __commonJS({
|
|
1298
|
+
"node_modules/hosted-git-info/lib/hosts.js"(exports, module) {
|
|
1299
|
+
"use strict";
|
|
1300
|
+
init_cjs_shims();
|
|
1301
|
+
var maybeJoin = (...args) => args.every((arg) => arg) ? args.join("") : "";
|
|
1302
|
+
var maybeEncode = (arg) => arg ? encodeURIComponent(arg) : "";
|
|
1303
|
+
var formatHashFragment = (f) => f.toLowerCase().replace(/^\W+|\/|\W+$/g, "").replace(/\W+/g, "-");
|
|
1304
|
+
var defaults = {
|
|
1305
|
+
sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1306
|
+
sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1307
|
+
edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin("/", editpath, "/", maybeEncode(committish || "HEAD"), "/", path)}`,
|
|
1308
|
+
browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}`,
|
|
1309
|
+
browsetreetemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
1310
|
+
browseblobtemplate: ({ domain, user, project, committish, blobpath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${blobpath}/${maybeEncode(committish || "HEAD")}/${path}${maybeJoin("#", hashformat(fragment || ""))}`,
|
|
1311
|
+
docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish))}#readme`,
|
|
1312
|
+
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1313
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/raw/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
1314
|
+
shortcuttemplate: ({ type, user, project, committish }) => `${type}:${user}/${project}${maybeJoin("#", committish)}`,
|
|
1315
|
+
pathtemplate: ({ user, project, committish }) => `${user}/${project}${maybeJoin("#", committish)}`,
|
|
1316
|
+
bugstemplate: ({ domain, user, project }) => `https://${domain}/${user}/${project}/issues`,
|
|
1317
|
+
hashformat: formatHashFragment
|
|
1318
|
+
};
|
|
1319
|
+
var hosts = {};
|
|
1320
|
+
hosts.github = {
|
|
1321
|
+
// First two are insecure and generally shouldn't be used any more, but
|
|
1322
|
+
// they are still supported.
|
|
1323
|
+
protocols: ["git:", "http:", "git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1324
|
+
domain: "github.com",
|
|
1325
|
+
treepath: "tree",
|
|
1326
|
+
blobpath: "blob",
|
|
1327
|
+
editpath: "edit",
|
|
1328
|
+
filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, "@")}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish || "HEAD")}/${path}`,
|
|
1329
|
+
gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1330
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish || "HEAD")}`,
|
|
1331
|
+
extract: (url) => {
|
|
1332
|
+
let [, user, project, type, committish] = url.pathname.split("/", 5);
|
|
1333
|
+
if (type && type !== "tree") {
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
if (!type) {
|
|
1337
|
+
committish = url.hash.slice(1);
|
|
1338
|
+
}
|
|
1339
|
+
if (project && project.endsWith(".git")) {
|
|
1340
|
+
project = project.slice(0, -4);
|
|
1341
|
+
}
|
|
1342
|
+
if (!user || !project) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
return { user, project, committish };
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
hosts.bitbucket = {
|
|
1349
|
+
protocols: ["git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1350
|
+
domain: "bitbucket.org",
|
|
1351
|
+
treepath: "src",
|
|
1352
|
+
blobpath: "src",
|
|
1353
|
+
editpath: "?mode=edit",
|
|
1354
|
+
edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", treepath, "/", maybeEncode(committish || "HEAD"), "/", path, editpath)}`,
|
|
1355
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish || "HEAD")}.tar.gz`,
|
|
1356
|
+
extract: (url) => {
|
|
1357
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1358
|
+
if (["get"].includes(aux)) {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
if (project && project.endsWith(".git")) {
|
|
1362
|
+
project = project.slice(0, -4);
|
|
1363
|
+
}
|
|
1364
|
+
if (!user || !project) {
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
hosts.gitlab = {
|
|
1371
|
+
protocols: ["git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1372
|
+
domain: "gitlab.com",
|
|
1373
|
+
treepath: "tree",
|
|
1374
|
+
blobpath: "tree",
|
|
1375
|
+
editpath: "-/edit",
|
|
1376
|
+
httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, "@")}${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1377
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish || "HEAD")}`,
|
|
1378
|
+
extract: (url) => {
|
|
1379
|
+
const path = url.pathname.slice(1);
|
|
1380
|
+
if (path.includes("/-/") || path.includes("/archive.tar.gz")) {
|
|
1381
|
+
return;
|
|
1382
|
+
}
|
|
1383
|
+
const segments = path.split("/");
|
|
1384
|
+
let project = segments.pop();
|
|
1385
|
+
if (project.endsWith(".git")) {
|
|
1386
|
+
project = project.slice(0, -4);
|
|
1387
|
+
}
|
|
1388
|
+
const user = segments.join("/");
|
|
1389
|
+
if (!user || !project) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1393
|
+
}
|
|
1394
|
+
};
|
|
1395
|
+
hosts.gist = {
|
|
1396
|
+
protocols: ["git:", "git+ssh:", "git+https:", "ssh:", "https:"],
|
|
1397
|
+
domain: "gist.github.com",
|
|
1398
|
+
editpath: "edit",
|
|
1399
|
+
sshtemplate: ({ domain, project, committish }) => `git@${domain}:${project}.git${maybeJoin("#", committish)}`,
|
|
1400
|
+
sshurltemplate: ({ domain, project, committish }) => `git+ssh://git@${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1401
|
+
edittemplate: ({ domain, user, project, committish, editpath }) => `https://${domain}/${user}/${project}${maybeJoin("/", maybeEncode(committish))}/${editpath}`,
|
|
1402
|
+
browsetemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
1403
|
+
browsetreetemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
1404
|
+
browseblobtemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}${maybeJoin("#", hashformat(path))}`,
|
|
1405
|
+
docstemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin("/", maybeEncode(committish))}`,
|
|
1406
|
+
httpstemplate: ({ domain, project, committish }) => `git+https://${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1407
|
+
filetemplate: ({ user, project, committish, path }) => `https://gist.githubusercontent.com/${user}/${project}/raw${maybeJoin("/", maybeEncode(committish))}/${path}`,
|
|
1408
|
+
shortcuttemplate: ({ type, project, committish }) => `${type}:${project}${maybeJoin("#", committish)}`,
|
|
1409
|
+
pathtemplate: ({ project, committish }) => `${project}${maybeJoin("#", committish)}`,
|
|
1410
|
+
bugstemplate: ({ domain, project }) => `https://${domain}/${project}`,
|
|
1411
|
+
gittemplate: ({ domain, project, committish }) => `git://${domain}/${project}.git${maybeJoin("#", committish)}`,
|
|
1412
|
+
tarballtemplate: ({ project, committish }) => `https://codeload.github.com/gist/${project}/tar.gz/${maybeEncode(committish || "HEAD")}`,
|
|
1413
|
+
extract: (url) => {
|
|
1414
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1415
|
+
if (aux === "raw") {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
if (!project) {
|
|
1419
|
+
if (!user) {
|
|
1420
|
+
return;
|
|
1421
|
+
}
|
|
1422
|
+
project = user;
|
|
1423
|
+
user = null;
|
|
1424
|
+
}
|
|
1425
|
+
if (project.endsWith(".git")) {
|
|
1426
|
+
project = project.slice(0, -4);
|
|
1427
|
+
}
|
|
1428
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1429
|
+
},
|
|
1430
|
+
hashformat: function(fragment) {
|
|
1431
|
+
return fragment && "file-" + formatHashFragment(fragment);
|
|
1432
|
+
}
|
|
1433
|
+
};
|
|
1434
|
+
hosts.sourcehut = {
|
|
1435
|
+
protocols: ["git+ssh:", "https:"],
|
|
1436
|
+
domain: "git.sr.ht",
|
|
1437
|
+
treepath: "tree",
|
|
1438
|
+
blobpath: "tree",
|
|
1439
|
+
filetemplate: ({ domain, user, project, committish, path }) => `https://${domain}/${user}/${project}/blob/${maybeEncode(committish) || "HEAD"}/${path}`,
|
|
1440
|
+
httpstemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}.git${maybeJoin("#", committish)}`,
|
|
1441
|
+
tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/archive/${maybeEncode(committish) || "HEAD"}.tar.gz`,
|
|
1442
|
+
bugstemplate: ({ user, project }) => null,
|
|
1443
|
+
extract: (url) => {
|
|
1444
|
+
let [, user, project, aux] = url.pathname.split("/", 4);
|
|
1445
|
+
if (["archive"].includes(aux)) {
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
if (project && project.endsWith(".git")) {
|
|
1449
|
+
project = project.slice(0, -4);
|
|
1450
|
+
}
|
|
1451
|
+
if (!user || !project) {
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
return { user, project, committish: url.hash.slice(1) };
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
for (const [name, host] of Object.entries(hosts)) {
|
|
1458
|
+
hosts[name] = Object.assign({}, defaults, host);
|
|
1459
|
+
}
|
|
1460
|
+
module.exports = hosts;
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
|
|
1464
|
+
// node_modules/hosted-git-info/lib/parse-url.js
|
|
1465
|
+
var require_parse_url = __commonJS({
|
|
1466
|
+
"node_modules/hosted-git-info/lib/parse-url.js"(exports, module) {
|
|
1467
|
+
init_cjs_shims();
|
|
1468
|
+
var url = __require("url");
|
|
1469
|
+
var lastIndexOfBefore = (str, char, beforeChar) => {
|
|
1470
|
+
const startPosition = str.indexOf(beforeChar);
|
|
1471
|
+
return str.lastIndexOf(char, startPosition > -1 ? startPosition : Infinity);
|
|
1472
|
+
};
|
|
1473
|
+
var safeUrl = (u) => {
|
|
1474
|
+
try {
|
|
1475
|
+
return new url.URL(u);
|
|
1476
|
+
} catch {
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var correctProtocol = (arg, protocols) => {
|
|
1480
|
+
const firstColon = arg.indexOf(":");
|
|
1481
|
+
const proto = arg.slice(0, firstColon + 1);
|
|
1482
|
+
if (Object.prototype.hasOwnProperty.call(protocols, proto)) {
|
|
1483
|
+
return arg;
|
|
1484
|
+
}
|
|
1485
|
+
const firstAt = arg.indexOf("@");
|
|
1486
|
+
if (firstAt > -1) {
|
|
1487
|
+
if (firstAt > firstColon) {
|
|
1488
|
+
return `git+ssh://${arg}`;
|
|
1489
|
+
} else {
|
|
1490
|
+
return arg;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
const doubleSlash = arg.indexOf("//");
|
|
1494
|
+
if (doubleSlash === firstColon + 1) {
|
|
1495
|
+
return arg;
|
|
1496
|
+
}
|
|
1497
|
+
return `${arg.slice(0, firstColon + 1)}//${arg.slice(firstColon + 1)}`;
|
|
1498
|
+
};
|
|
1499
|
+
var correctUrl = (giturl) => {
|
|
1500
|
+
const firstAt = lastIndexOfBefore(giturl, "@", "#");
|
|
1501
|
+
const lastColonBeforeHash = lastIndexOfBefore(giturl, ":", "#");
|
|
1502
|
+
if (lastColonBeforeHash > firstAt) {
|
|
1503
|
+
giturl = giturl.slice(0, lastColonBeforeHash) + "/" + giturl.slice(lastColonBeforeHash + 1);
|
|
1504
|
+
}
|
|
1505
|
+
if (lastIndexOfBefore(giturl, ":", "#") === -1 && giturl.indexOf("//") === -1) {
|
|
1506
|
+
giturl = `git+ssh://${giturl}`;
|
|
1507
|
+
}
|
|
1508
|
+
return giturl;
|
|
1509
|
+
};
|
|
1510
|
+
module.exports = (giturl, protocols) => {
|
|
1511
|
+
const withProtocol = protocols ? correctProtocol(giturl, protocols) : giturl;
|
|
1512
|
+
return safeUrl(withProtocol) || safeUrl(correctUrl(withProtocol));
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
|
|
1517
|
+
// node_modules/hosted-git-info/lib/from-url.js
|
|
1518
|
+
var require_from_url = __commonJS({
|
|
1519
|
+
"node_modules/hosted-git-info/lib/from-url.js"(exports, module) {
|
|
1520
|
+
"use strict";
|
|
1521
|
+
init_cjs_shims();
|
|
1522
|
+
var parseUrl = require_parse_url();
|
|
1523
|
+
var isGitHubShorthand = (arg) => {
|
|
1524
|
+
const firstHash = arg.indexOf("#");
|
|
1525
|
+
const firstSlash = arg.indexOf("/");
|
|
1526
|
+
const secondSlash = arg.indexOf("/", firstSlash + 1);
|
|
1527
|
+
const firstColon = arg.indexOf(":");
|
|
1528
|
+
const firstSpace = /\s/.exec(arg);
|
|
1529
|
+
const firstAt = arg.indexOf("@");
|
|
1530
|
+
const spaceOnlyAfterHash = !firstSpace || firstHash > -1 && firstSpace.index > firstHash;
|
|
1531
|
+
const atOnlyAfterHash = firstAt === -1 || firstHash > -1 && firstAt > firstHash;
|
|
1532
|
+
const colonOnlyAfterHash = firstColon === -1 || firstHash > -1 && firstColon > firstHash;
|
|
1533
|
+
const secondSlashOnlyAfterHash = secondSlash === -1 || firstHash > -1 && secondSlash > firstHash;
|
|
1534
|
+
const hasSlash = firstSlash > 0;
|
|
1535
|
+
const doesNotEndWithSlash = firstHash > -1 ? arg[firstHash - 1] !== "/" : !arg.endsWith("/");
|
|
1536
|
+
const doesNotStartWithDot = !arg.startsWith(".");
|
|
1537
|
+
return spaceOnlyAfterHash && hasSlash && doesNotEndWithSlash && doesNotStartWithDot && atOnlyAfterHash && colonOnlyAfterHash && secondSlashOnlyAfterHash;
|
|
1538
|
+
};
|
|
1539
|
+
module.exports = (giturl, opts, { gitHosts, protocols }) => {
|
|
1540
|
+
if (!giturl) {
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
const correctedUrl = isGitHubShorthand(giturl) ? `github:${giturl}` : giturl;
|
|
1544
|
+
const parsed = parseUrl(correctedUrl, protocols);
|
|
1545
|
+
if (!parsed) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
const gitHostShortcut = gitHosts.byShortcut[parsed.protocol];
|
|
1549
|
+
const gitHostDomain = gitHosts.byDomain[parsed.hostname.startsWith("www.") ? parsed.hostname.slice(4) : parsed.hostname];
|
|
1550
|
+
const gitHostName = gitHostShortcut || gitHostDomain;
|
|
1551
|
+
if (!gitHostName) {
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
const gitHostInfo = gitHosts[gitHostShortcut || gitHostDomain];
|
|
1555
|
+
let auth = null;
|
|
1556
|
+
if (protocols[parsed.protocol]?.auth && (parsed.username || parsed.password)) {
|
|
1557
|
+
auth = `${parsed.username}${parsed.password ? ":" + parsed.password : ""}`;
|
|
1558
|
+
}
|
|
1559
|
+
let committish = null;
|
|
1560
|
+
let user = null;
|
|
1561
|
+
let project = null;
|
|
1562
|
+
let defaultRepresentation = null;
|
|
1563
|
+
try {
|
|
1564
|
+
if (gitHostShortcut) {
|
|
1565
|
+
let pathname = parsed.pathname.startsWith("/") ? parsed.pathname.slice(1) : parsed.pathname;
|
|
1566
|
+
const firstAt = pathname.indexOf("@");
|
|
1567
|
+
if (firstAt > -1) {
|
|
1568
|
+
pathname = pathname.slice(firstAt + 1);
|
|
1569
|
+
}
|
|
1570
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
1571
|
+
if (lastSlash > -1) {
|
|
1572
|
+
user = decodeURIComponent(pathname.slice(0, lastSlash));
|
|
1573
|
+
if (!user) {
|
|
1574
|
+
user = null;
|
|
1575
|
+
}
|
|
1576
|
+
project = decodeURIComponent(pathname.slice(lastSlash + 1));
|
|
1577
|
+
} else {
|
|
1578
|
+
project = decodeURIComponent(pathname);
|
|
1579
|
+
}
|
|
1580
|
+
if (project.endsWith(".git")) {
|
|
1581
|
+
project = project.slice(0, -4);
|
|
1582
|
+
}
|
|
1583
|
+
if (parsed.hash) {
|
|
1584
|
+
committish = decodeURIComponent(parsed.hash.slice(1));
|
|
1585
|
+
}
|
|
1586
|
+
defaultRepresentation = "shortcut";
|
|
1587
|
+
} else {
|
|
1588
|
+
if (!gitHostInfo.protocols.includes(parsed.protocol)) {
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
const segments = gitHostInfo.extract(parsed);
|
|
1592
|
+
if (!segments) {
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
1595
|
+
user = segments.user && decodeURIComponent(segments.user);
|
|
1596
|
+
project = decodeURIComponent(segments.project);
|
|
1597
|
+
committish = decodeURIComponent(segments.committish);
|
|
1598
|
+
defaultRepresentation = protocols[parsed.protocol]?.name || parsed.protocol.slice(0, -1);
|
|
1599
|
+
}
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
if (err instanceof URIError) {
|
|
1602
|
+
return;
|
|
1603
|
+
} else {
|
|
1604
|
+
throw err;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
return [gitHostName, user, auth, project, committish, defaultRepresentation, opts];
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
|
|
1612
|
+
// node_modules/hosted-git-info/lib/index.js
|
|
1613
|
+
var require_lib2 = __commonJS({
|
|
1614
|
+
"node_modules/hosted-git-info/lib/index.js"(exports, module) {
|
|
1615
|
+
"use strict";
|
|
1616
|
+
init_cjs_shims();
|
|
1617
|
+
var { LRUCache } = require_commonjs();
|
|
1618
|
+
var hosts = require_hosts();
|
|
1619
|
+
var fromUrl = require_from_url();
|
|
1620
|
+
var parseUrl = require_parse_url();
|
|
1621
|
+
var cache = new LRUCache({ max: 1e3 });
|
|
1622
|
+
var GitHost = class _GitHost {
|
|
1623
|
+
constructor(type, user, auth, project, committish, defaultRepresentation, opts = {}) {
|
|
1624
|
+
Object.assign(this, _GitHost.#gitHosts[type], {
|
|
1625
|
+
type,
|
|
1626
|
+
user,
|
|
1627
|
+
auth,
|
|
1628
|
+
project,
|
|
1629
|
+
committish,
|
|
1630
|
+
default: defaultRepresentation,
|
|
1631
|
+
opts
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
static #gitHosts = { byShortcut: {}, byDomain: {} };
|
|
1635
|
+
static #protocols = {
|
|
1636
|
+
"git+ssh:": { name: "sshurl" },
|
|
1637
|
+
"ssh:": { name: "sshurl" },
|
|
1638
|
+
"git+https:": { name: "https", auth: true },
|
|
1639
|
+
"git:": { auth: true },
|
|
1640
|
+
"http:": { auth: true },
|
|
1641
|
+
"https:": { auth: true },
|
|
1642
|
+
"git+http:": { auth: true }
|
|
1643
|
+
};
|
|
1644
|
+
static addHost(name, host) {
|
|
1645
|
+
_GitHost.#gitHosts[name] = host;
|
|
1646
|
+
_GitHost.#gitHosts.byDomain[host.domain] = name;
|
|
1647
|
+
_GitHost.#gitHosts.byShortcut[`${name}:`] = name;
|
|
1648
|
+
_GitHost.#protocols[`${name}:`] = { name };
|
|
1649
|
+
}
|
|
1650
|
+
static fromUrl(giturl, opts) {
|
|
1651
|
+
if (typeof giturl !== "string") {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
const key = giturl + JSON.stringify(opts || {});
|
|
1655
|
+
if (!cache.has(key)) {
|
|
1656
|
+
const hostArgs = fromUrl(giturl, opts, {
|
|
1657
|
+
gitHosts: _GitHost.#gitHosts,
|
|
1658
|
+
protocols: _GitHost.#protocols
|
|
1659
|
+
});
|
|
1660
|
+
cache.set(key, hostArgs ? new _GitHost(...hostArgs) : void 0);
|
|
1661
|
+
}
|
|
1662
|
+
return cache.get(key);
|
|
1663
|
+
}
|
|
1664
|
+
static parseUrl(url) {
|
|
1665
|
+
return parseUrl(url);
|
|
1666
|
+
}
|
|
1667
|
+
#fill(template, opts) {
|
|
1668
|
+
if (typeof template !== "function") {
|
|
1669
|
+
return null;
|
|
1670
|
+
}
|
|
1671
|
+
const options = { ...this, ...this.opts, ...opts };
|
|
1672
|
+
if (!options.path) {
|
|
1673
|
+
options.path = "";
|
|
1674
|
+
}
|
|
1675
|
+
if (options.path.startsWith("/")) {
|
|
1676
|
+
options.path = options.path.slice(1);
|
|
1677
|
+
}
|
|
1678
|
+
if (options.noCommittish) {
|
|
1679
|
+
options.committish = null;
|
|
1680
|
+
}
|
|
1681
|
+
const result = template(options);
|
|
1682
|
+
return options.noGitPlus && result.startsWith("git+") ? result.slice(4) : result;
|
|
1683
|
+
}
|
|
1684
|
+
hash() {
|
|
1685
|
+
return this.committish ? `#${this.committish}` : "";
|
|
1686
|
+
}
|
|
1687
|
+
ssh(opts) {
|
|
1688
|
+
return this.#fill(this.sshtemplate, opts);
|
|
1689
|
+
}
|
|
1690
|
+
sshurl(opts) {
|
|
1691
|
+
return this.#fill(this.sshurltemplate, opts);
|
|
1692
|
+
}
|
|
1693
|
+
browse(path, ...args) {
|
|
1694
|
+
if (typeof path !== "string") {
|
|
1695
|
+
return this.#fill(this.browsetemplate, path);
|
|
1696
|
+
}
|
|
1697
|
+
if (typeof args[0] !== "string") {
|
|
1698
|
+
return this.#fill(this.browsetreetemplate, { ...args[0], path });
|
|
1699
|
+
}
|
|
1700
|
+
return this.#fill(this.browsetreetemplate, { ...args[1], fragment: args[0], path });
|
|
1701
|
+
}
|
|
1702
|
+
// If the path is known to be a file, then browseFile should be used. For some hosts
|
|
1703
|
+
// the url is the same as browse, but for others like GitHub a file can use both `/tree/`
|
|
1704
|
+
// and `/blob/` in the path. When using a default committish of `HEAD` then the `/tree/`
|
|
1705
|
+
// path will redirect to a specific commit. Using the `/blob/` path avoids this and
|
|
1706
|
+
// does not redirect to a different commit.
|
|
1707
|
+
browseFile(path, ...args) {
|
|
1708
|
+
if (typeof args[0] !== "string") {
|
|
1709
|
+
return this.#fill(this.browseblobtemplate, { ...args[0], path });
|
|
1710
|
+
}
|
|
1711
|
+
return this.#fill(this.browseblobtemplate, { ...args[1], fragment: args[0], path });
|
|
1712
|
+
}
|
|
1713
|
+
docs(opts) {
|
|
1714
|
+
return this.#fill(this.docstemplate, opts);
|
|
1715
|
+
}
|
|
1716
|
+
bugs(opts) {
|
|
1717
|
+
return this.#fill(this.bugstemplate, opts);
|
|
1718
|
+
}
|
|
1719
|
+
https(opts) {
|
|
1720
|
+
return this.#fill(this.httpstemplate, opts);
|
|
1721
|
+
}
|
|
1722
|
+
git(opts) {
|
|
1723
|
+
return this.#fill(this.gittemplate, opts);
|
|
1724
|
+
}
|
|
1725
|
+
shortcut(opts) {
|
|
1726
|
+
return this.#fill(this.shortcuttemplate, opts);
|
|
1727
|
+
}
|
|
1728
|
+
path(opts) {
|
|
1729
|
+
return this.#fill(this.pathtemplate, opts);
|
|
1730
|
+
}
|
|
1731
|
+
tarball(opts) {
|
|
1732
|
+
return this.#fill(this.tarballtemplate, { ...opts, noCommittish: false });
|
|
1733
|
+
}
|
|
1734
|
+
file(path, opts) {
|
|
1735
|
+
return this.#fill(this.filetemplate, { ...opts, path });
|
|
1736
|
+
}
|
|
1737
|
+
edit(path, opts) {
|
|
1738
|
+
return this.#fill(this.edittemplate, { ...opts, path });
|
|
1739
|
+
}
|
|
1740
|
+
getDefaultRepresentation() {
|
|
1741
|
+
return this.default;
|
|
1742
|
+
}
|
|
1743
|
+
toString(opts) {
|
|
1744
|
+
if (this.default && typeof this[this.default] === "function") {
|
|
1745
|
+
return this[this.default](opts);
|
|
1746
|
+
}
|
|
1747
|
+
return this.sshurl(opts);
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
for (const [name, host] of Object.entries(hosts)) {
|
|
1751
|
+
GitHost.addHost(name, host);
|
|
1752
|
+
}
|
|
1753
|
+
module.exports = GitHost;
|
|
1754
|
+
}
|
|
1755
|
+
});
|
|
1756
|
+
|
|
1757
|
+
// node_modules/proc-log/lib/index.js
|
|
1758
|
+
var require_lib3 = __commonJS({
|
|
1759
|
+
"node_modules/proc-log/lib/index.js"(exports, module) {
|
|
1760
|
+
init_cjs_shims();
|
|
1761
|
+
var META = Symbol("proc-log.meta");
|
|
1762
|
+
module.exports = {
|
|
1763
|
+
META,
|
|
1764
|
+
output: {
|
|
1765
|
+
LEVELS: [
|
|
1766
|
+
"standard",
|
|
1767
|
+
"error",
|
|
1768
|
+
"buffer",
|
|
1769
|
+
"flush"
|
|
1770
|
+
],
|
|
1771
|
+
KEYS: {
|
|
1772
|
+
standard: "standard",
|
|
1773
|
+
error: "error",
|
|
1774
|
+
buffer: "buffer",
|
|
1775
|
+
flush: "flush"
|
|
1776
|
+
},
|
|
1777
|
+
standard: function(...args) {
|
|
1778
|
+
return process.emit("output", "standard", ...args);
|
|
1779
|
+
},
|
|
1780
|
+
error: function(...args) {
|
|
1781
|
+
return process.emit("output", "error", ...args);
|
|
1782
|
+
},
|
|
1783
|
+
buffer: function(...args) {
|
|
1784
|
+
return process.emit("output", "buffer", ...args);
|
|
1785
|
+
},
|
|
1786
|
+
flush: function(...args) {
|
|
1787
|
+
return process.emit("output", "flush", ...args);
|
|
1788
|
+
}
|
|
1789
|
+
},
|
|
1790
|
+
log: {
|
|
1791
|
+
LEVELS: [
|
|
1792
|
+
"notice",
|
|
1793
|
+
"error",
|
|
1794
|
+
"warn",
|
|
1795
|
+
"info",
|
|
1796
|
+
"verbose",
|
|
1797
|
+
"http",
|
|
1798
|
+
"silly",
|
|
1799
|
+
"timing",
|
|
1800
|
+
"pause",
|
|
1801
|
+
"resume"
|
|
1802
|
+
],
|
|
1803
|
+
KEYS: {
|
|
1804
|
+
notice: "notice",
|
|
1805
|
+
error: "error",
|
|
1806
|
+
warn: "warn",
|
|
1807
|
+
info: "info",
|
|
1808
|
+
verbose: "verbose",
|
|
1809
|
+
http: "http",
|
|
1810
|
+
silly: "silly",
|
|
1811
|
+
timing: "timing",
|
|
1812
|
+
pause: "pause",
|
|
1813
|
+
resume: "resume"
|
|
1814
|
+
},
|
|
1815
|
+
error: function(...args) {
|
|
1816
|
+
return process.emit("log", "error", ...args);
|
|
1817
|
+
},
|
|
1818
|
+
notice: function(...args) {
|
|
1819
|
+
return process.emit("log", "notice", ...args);
|
|
1820
|
+
},
|
|
1821
|
+
warn: function(...args) {
|
|
1822
|
+
return process.emit("log", "warn", ...args);
|
|
1823
|
+
},
|
|
1824
|
+
info: function(...args) {
|
|
1825
|
+
return process.emit("log", "info", ...args);
|
|
1826
|
+
},
|
|
1827
|
+
verbose: function(...args) {
|
|
1828
|
+
return process.emit("log", "verbose", ...args);
|
|
1829
|
+
},
|
|
1830
|
+
http: function(...args) {
|
|
1831
|
+
return process.emit("log", "http", ...args);
|
|
1832
|
+
},
|
|
1833
|
+
silly: function(...args) {
|
|
1834
|
+
return process.emit("log", "silly", ...args);
|
|
1835
|
+
},
|
|
1836
|
+
timing: function(...args) {
|
|
1837
|
+
return process.emit("log", "timing", ...args);
|
|
1838
|
+
},
|
|
1839
|
+
pause: function() {
|
|
1840
|
+
return process.emit("log", "pause");
|
|
1841
|
+
},
|
|
1842
|
+
resume: function() {
|
|
1843
|
+
return process.emit("log", "resume");
|
|
1844
|
+
}
|
|
1845
|
+
},
|
|
1846
|
+
time: {
|
|
1847
|
+
LEVELS: [
|
|
1848
|
+
"start",
|
|
1849
|
+
"end"
|
|
1850
|
+
],
|
|
1851
|
+
KEYS: {
|
|
1852
|
+
start: "start",
|
|
1853
|
+
end: "end"
|
|
1854
|
+
},
|
|
1855
|
+
start: function(name, fn) {
|
|
1856
|
+
process.emit("time", "start", name);
|
|
1857
|
+
function end() {
|
|
1858
|
+
return process.emit("time", "end", name);
|
|
1859
|
+
}
|
|
1860
|
+
if (typeof fn === "function") {
|
|
1861
|
+
const res = fn();
|
|
1862
|
+
if (res && res.finally) {
|
|
1863
|
+
return res.finally(end);
|
|
1864
|
+
}
|
|
1865
|
+
end();
|
|
1866
|
+
return res;
|
|
1867
|
+
}
|
|
1868
|
+
return end;
|
|
1869
|
+
},
|
|
1870
|
+
end: function(name) {
|
|
1871
|
+
return process.emit("time", "end", name);
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
input: {
|
|
1875
|
+
LEVELS: [
|
|
1876
|
+
"start",
|
|
1877
|
+
"end",
|
|
1878
|
+
"read"
|
|
1879
|
+
],
|
|
1880
|
+
KEYS: {
|
|
1881
|
+
start: "start",
|
|
1882
|
+
end: "end",
|
|
1883
|
+
read: "read"
|
|
1884
|
+
},
|
|
1885
|
+
start: function(fn) {
|
|
1886
|
+
process.emit("input", "start");
|
|
1887
|
+
function end() {
|
|
1888
|
+
return process.emit("input", "end");
|
|
1889
|
+
}
|
|
1890
|
+
if (typeof fn === "function") {
|
|
1891
|
+
const res = fn();
|
|
1892
|
+
if (res && res.finally) {
|
|
1893
|
+
return res.finally(end);
|
|
1894
|
+
}
|
|
1895
|
+
end();
|
|
1896
|
+
return res;
|
|
1897
|
+
}
|
|
1898
|
+
return end;
|
|
1899
|
+
},
|
|
1900
|
+
end: function() {
|
|
1901
|
+
return process.emit("input", "end");
|
|
1902
|
+
},
|
|
1903
|
+
read: function(...args) {
|
|
1904
|
+
let resolve, reject;
|
|
1905
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
1906
|
+
resolve = _resolve;
|
|
1907
|
+
reject = _reject;
|
|
1908
|
+
});
|
|
1909
|
+
process.emit("input", "read", resolve, reject, ...args);
|
|
1910
|
+
return promise;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
});
|
|
1916
|
+
|
|
1917
|
+
// node_modules/npm-package-arg/lib/npa.js
|
|
1918
|
+
var require_npa = __commonJS({
|
|
1919
|
+
"node_modules/npm-package-arg/lib/npa.js"(exports, module) {
|
|
1920
|
+
init_cjs_shims();
|
|
1921
|
+
module.exports = npa;
|
|
1922
|
+
module.exports.resolve = resolve;
|
|
1923
|
+
module.exports.toPurl = toPurl;
|
|
1924
|
+
module.exports.Result = Result;
|
|
1925
|
+
var { URL } = __require("url");
|
|
1926
|
+
var HostedGit = require_lib2();
|
|
1927
|
+
var semver = require_semver();
|
|
1928
|
+
var path = global.FAKE_WINDOWS ? __require("path").win32 : __require("path");
|
|
1929
|
+
var validatePackageName = require_lib();
|
|
1930
|
+
var { homedir } = __require("os");
|
|
1931
|
+
var { log } = require_lib3();
|
|
1932
|
+
var isWindows = process.platform === "win32" || global.FAKE_WINDOWS;
|
|
1933
|
+
var hasSlashes = isWindows ? /\\|[/]/ : /[/]/;
|
|
1934
|
+
var isURL = /^(?:git[+])?[a-z]+:/i;
|
|
1935
|
+
var isGit = /^[^@]+@[^:.]+\.[^:]+:.+$/i;
|
|
1936
|
+
var isFilename = /[.](?:tgz|tar.gz|tar)$/i;
|
|
1937
|
+
function npa(arg, where) {
|
|
1938
|
+
let name;
|
|
1939
|
+
let spec;
|
|
1940
|
+
if (typeof arg === "object") {
|
|
1941
|
+
if (arg instanceof Result && (!where || where === arg.where)) {
|
|
1942
|
+
return arg;
|
|
1943
|
+
} else if (arg.name && arg.rawSpec) {
|
|
1944
|
+
return npa.resolve(arg.name, arg.rawSpec, where || arg.where);
|
|
1945
|
+
} else {
|
|
1946
|
+
return npa(arg.raw, where || arg.where);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
const nameEndsAt = arg[0] === "@" ? arg.slice(1).indexOf("@") + 1 : arg.indexOf("@");
|
|
1950
|
+
const namePart = nameEndsAt > 0 ? arg.slice(0, nameEndsAt) : arg;
|
|
1951
|
+
if (isURL.test(arg)) {
|
|
1952
|
+
spec = arg;
|
|
1953
|
+
} else if (isGit.test(arg)) {
|
|
1954
|
+
spec = `git+ssh://${arg}`;
|
|
1955
|
+
} else if (namePart[0] !== "@" && (hasSlashes.test(namePart) || isFilename.test(namePart))) {
|
|
1956
|
+
spec = arg;
|
|
1957
|
+
} else if (nameEndsAt > 0) {
|
|
1958
|
+
name = namePart;
|
|
1959
|
+
spec = arg.slice(nameEndsAt + 1) || "*";
|
|
1960
|
+
} else {
|
|
1961
|
+
const valid = validatePackageName(arg);
|
|
1962
|
+
if (valid.validForOldPackages) {
|
|
1963
|
+
name = arg;
|
|
1964
|
+
spec = "*";
|
|
1965
|
+
} else {
|
|
1966
|
+
spec = arg;
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return resolve(name, spec, where, arg);
|
|
1970
|
+
}
|
|
1971
|
+
var isFilespec = isWindows ? /^(?:[.]|~[/]|[/\\]|[a-zA-Z]:)/ : /^(?:[.]|~[/]|[/]|[a-zA-Z]:)/;
|
|
1972
|
+
function resolve(name, spec, where, arg) {
|
|
1973
|
+
const res = new Result({
|
|
1974
|
+
raw: arg,
|
|
1975
|
+
name,
|
|
1976
|
+
rawSpec: spec,
|
|
1977
|
+
fromArgument: arg != null
|
|
1978
|
+
});
|
|
1979
|
+
if (name) {
|
|
1980
|
+
res.setName(name);
|
|
1981
|
+
}
|
|
1982
|
+
if (spec && (isFilespec.test(spec) || /^file:/i.test(spec))) {
|
|
1983
|
+
return fromFile(res, where);
|
|
1984
|
+
} else if (spec && /^npm:/i.test(spec)) {
|
|
1985
|
+
return fromAlias(res, where);
|
|
1986
|
+
}
|
|
1987
|
+
const hosted = HostedGit.fromUrl(spec, {
|
|
1988
|
+
noGitPlus: true,
|
|
1989
|
+
noCommittish: true
|
|
1990
|
+
});
|
|
1991
|
+
if (hosted) {
|
|
1992
|
+
return fromHostedGit(res, hosted);
|
|
1993
|
+
} else if (spec && isURL.test(spec)) {
|
|
1994
|
+
return fromURL(res);
|
|
1995
|
+
} else if (spec && (hasSlashes.test(spec) || isFilename.test(spec))) {
|
|
1996
|
+
return fromFile(res, where);
|
|
1997
|
+
} else {
|
|
1998
|
+
return fromRegistry(res);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
var defaultRegistry = "https://registry.npmjs.org";
|
|
2002
|
+
function toPurl(arg, reg = defaultRegistry) {
|
|
2003
|
+
const res = npa(arg);
|
|
2004
|
+
if (res.type !== "version") {
|
|
2005
|
+
throw invalidPurlType(res.type, res.raw);
|
|
2006
|
+
}
|
|
2007
|
+
let purl = "pkg:npm/" + res.name.replace(/^@/, "%40") + "@" + res.rawSpec;
|
|
2008
|
+
if (reg !== defaultRegistry) {
|
|
2009
|
+
purl += "?repository_url=" + reg;
|
|
2010
|
+
}
|
|
2011
|
+
return purl;
|
|
2012
|
+
}
|
|
2013
|
+
function invalidPackageName(name, valid, raw) {
|
|
2014
|
+
const err = new Error(`Invalid package name "${name}" of package "${raw}": ${valid.errors.join("; ")}.`);
|
|
2015
|
+
err.code = "EINVALIDPACKAGENAME";
|
|
2016
|
+
return err;
|
|
2017
|
+
}
|
|
2018
|
+
function invalidTagName(name, raw) {
|
|
2019
|
+
const err = new Error(`Invalid tag name "${name}" of package "${raw}": Tags may not have any characters that encodeURIComponent encodes.`);
|
|
2020
|
+
err.code = "EINVALIDTAGNAME";
|
|
2021
|
+
return err;
|
|
2022
|
+
}
|
|
2023
|
+
function invalidPurlType(type, raw) {
|
|
2024
|
+
const err = new Error(`Invalid type "${type}" of package "${raw}": Purl can only be generated for "version" types.`);
|
|
2025
|
+
err.code = "EINVALIDPURLTYPE";
|
|
2026
|
+
return err;
|
|
2027
|
+
}
|
|
2028
|
+
function Result(opts) {
|
|
2029
|
+
this.type = opts.type;
|
|
2030
|
+
this.registry = opts.registry;
|
|
2031
|
+
this.where = opts.where;
|
|
2032
|
+
if (opts.raw == null) {
|
|
2033
|
+
this.raw = opts.name ? opts.name + "@" + opts.rawSpec : opts.rawSpec;
|
|
2034
|
+
} else {
|
|
2035
|
+
this.raw = opts.raw;
|
|
2036
|
+
}
|
|
2037
|
+
this.name = void 0;
|
|
2038
|
+
this.escapedName = void 0;
|
|
2039
|
+
this.scope = void 0;
|
|
2040
|
+
this.rawSpec = opts.rawSpec || "";
|
|
2041
|
+
this.saveSpec = opts.saveSpec;
|
|
2042
|
+
this.fetchSpec = opts.fetchSpec;
|
|
2043
|
+
if (opts.name) {
|
|
2044
|
+
this.setName(opts.name);
|
|
2045
|
+
}
|
|
2046
|
+
this.gitRange = opts.gitRange;
|
|
2047
|
+
this.gitCommittish = opts.gitCommittish;
|
|
2048
|
+
this.gitSubdir = opts.gitSubdir;
|
|
2049
|
+
this.hosted = opts.hosted;
|
|
2050
|
+
}
|
|
2051
|
+
Result.prototype.setName = function(name) {
|
|
2052
|
+
const valid = validatePackageName(name);
|
|
2053
|
+
if (!valid.validForOldPackages) {
|
|
2054
|
+
throw invalidPackageName(name, valid, this.raw);
|
|
2055
|
+
}
|
|
2056
|
+
this.name = name;
|
|
2057
|
+
this.scope = name[0] === "@" ? name.slice(0, name.indexOf("/")) : void 0;
|
|
2058
|
+
this.escapedName = name.replace("/", "%2f");
|
|
2059
|
+
return this;
|
|
2060
|
+
};
|
|
2061
|
+
Result.prototype.toString = function() {
|
|
2062
|
+
const full = [];
|
|
2063
|
+
if (this.name != null && this.name !== "") {
|
|
2064
|
+
full.push(this.name);
|
|
2065
|
+
}
|
|
2066
|
+
const spec = this.saveSpec || this.fetchSpec || this.rawSpec;
|
|
2067
|
+
if (spec != null && spec !== "") {
|
|
2068
|
+
full.push(spec);
|
|
2069
|
+
}
|
|
2070
|
+
return full.length ? full.join("@") : this.raw;
|
|
2071
|
+
};
|
|
2072
|
+
Result.prototype.toJSON = function() {
|
|
2073
|
+
const result = Object.assign({}, this);
|
|
2074
|
+
delete result.hosted;
|
|
2075
|
+
return result;
|
|
2076
|
+
};
|
|
2077
|
+
function setGitAttrs(res, committish) {
|
|
2078
|
+
if (!committish) {
|
|
2079
|
+
res.gitCommittish = null;
|
|
2080
|
+
return;
|
|
2081
|
+
}
|
|
2082
|
+
for (const part of committish.split("::")) {
|
|
2083
|
+
if (!part.includes(":")) {
|
|
2084
|
+
if (res.gitRange) {
|
|
2085
|
+
throw new Error("cannot override existing semver range with a committish");
|
|
2086
|
+
}
|
|
2087
|
+
if (res.gitCommittish) {
|
|
2088
|
+
throw new Error("cannot override existing committish with a second committish");
|
|
2089
|
+
}
|
|
2090
|
+
res.gitCommittish = part;
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
const [name, value] = part.split(":");
|
|
2094
|
+
if (name === "semver") {
|
|
2095
|
+
if (res.gitCommittish) {
|
|
2096
|
+
throw new Error("cannot override existing committish with a semver range");
|
|
2097
|
+
}
|
|
2098
|
+
if (res.gitRange) {
|
|
2099
|
+
throw new Error("cannot override existing semver range with a second semver range");
|
|
2100
|
+
}
|
|
2101
|
+
res.gitRange = decodeURIComponent(value);
|
|
2102
|
+
continue;
|
|
2103
|
+
}
|
|
2104
|
+
if (name === "path") {
|
|
2105
|
+
if (res.gitSubdir) {
|
|
2106
|
+
throw new Error("cannot override existing path with a second path");
|
|
2107
|
+
}
|
|
2108
|
+
res.gitSubdir = `/${value}`;
|
|
2109
|
+
continue;
|
|
2110
|
+
}
|
|
2111
|
+
log.warn("npm-package-arg", `ignoring unknown key "${name}"`);
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
function fromFile(res, where) {
|
|
2115
|
+
if (!where) {
|
|
2116
|
+
where = process.cwd();
|
|
2117
|
+
}
|
|
2118
|
+
res.type = isFilename.test(res.rawSpec) ? "file" : "directory";
|
|
2119
|
+
res.where = where;
|
|
2120
|
+
let specUrl;
|
|
2121
|
+
let resolvedUrl;
|
|
2122
|
+
const prefix = !/^file:/.test(res.rawSpec) ? "file:" : "";
|
|
2123
|
+
const rawWithPrefix = prefix + res.rawSpec;
|
|
2124
|
+
let rawNoPrefix = rawWithPrefix.replace(/^file:/, "");
|
|
2125
|
+
try {
|
|
2126
|
+
resolvedUrl = new URL(rawWithPrefix, `file://${path.resolve(where)}/`);
|
|
2127
|
+
specUrl = new URL(rawWithPrefix);
|
|
2128
|
+
} catch (originalError) {
|
|
2129
|
+
const er = new Error("Invalid file: URL, must comply with RFC 8089");
|
|
2130
|
+
throw Object.assign(er, {
|
|
2131
|
+
raw: res.rawSpec,
|
|
2132
|
+
spec: res,
|
|
2133
|
+
where,
|
|
2134
|
+
originalError
|
|
2135
|
+
});
|
|
2136
|
+
}
|
|
2137
|
+
if (resolvedUrl.host && resolvedUrl.host !== "localhost") {
|
|
2138
|
+
const rawSpec = res.rawSpec.replace(/^file:\/\//, "file:///");
|
|
2139
|
+
resolvedUrl = new URL(rawSpec, `file://${path.resolve(where)}/`);
|
|
2140
|
+
specUrl = new URL(rawSpec);
|
|
2141
|
+
rawNoPrefix = rawSpec.replace(/^file:/, "");
|
|
2142
|
+
}
|
|
2143
|
+
if (/^\/{1,3}\.\.?(\/|$)/.test(rawNoPrefix)) {
|
|
2144
|
+
const rawSpec = res.rawSpec.replace(/^file:\/{1,3}/, "file:");
|
|
2145
|
+
resolvedUrl = new URL(rawSpec, `file://${path.resolve(where)}/`);
|
|
2146
|
+
specUrl = new URL(rawSpec);
|
|
2147
|
+
rawNoPrefix = rawSpec.replace(/^file:/, "");
|
|
2148
|
+
}
|
|
2149
|
+
let specPath = decodeURIComponent(specUrl.pathname);
|
|
2150
|
+
let resolvedPath = decodeURIComponent(resolvedUrl.pathname);
|
|
2151
|
+
if (isWindows) {
|
|
2152
|
+
specPath = specPath.replace(/^\/+([a-z]:\/)/i, "$1");
|
|
2153
|
+
resolvedPath = resolvedPath.replace(/^\/+([a-z]:\/)/i, "$1");
|
|
2154
|
+
}
|
|
2155
|
+
if (/^\/~(\/|$)/.test(specPath)) {
|
|
2156
|
+
res.saveSpec = `file:${specPath.substr(1)}`;
|
|
2157
|
+
resolvedPath = path.resolve(homedir(), specPath.substr(3));
|
|
2158
|
+
} else if (!path.isAbsolute(rawNoPrefix)) {
|
|
2159
|
+
res.saveSpec = `file:${path.relative(where, resolvedPath)}`;
|
|
2160
|
+
} else {
|
|
2161
|
+
res.saveSpec = `file:${path.resolve(resolvedPath)}`;
|
|
2162
|
+
}
|
|
2163
|
+
res.fetchSpec = path.resolve(where, resolvedPath);
|
|
2164
|
+
return res;
|
|
2165
|
+
}
|
|
2166
|
+
function fromHostedGit(res, hosted) {
|
|
2167
|
+
res.type = "git";
|
|
2168
|
+
res.hosted = hosted;
|
|
2169
|
+
res.saveSpec = hosted.toString({ noGitPlus: false, noCommittish: false });
|
|
2170
|
+
res.fetchSpec = hosted.getDefaultRepresentation() === "shortcut" ? null : hosted.toString();
|
|
2171
|
+
setGitAttrs(res, hosted.committish);
|
|
2172
|
+
return res;
|
|
2173
|
+
}
|
|
2174
|
+
function unsupportedURLType(protocol, spec) {
|
|
2175
|
+
const err = new Error(`Unsupported URL Type "${protocol}": ${spec}`);
|
|
2176
|
+
err.code = "EUNSUPPORTEDPROTOCOL";
|
|
2177
|
+
return err;
|
|
2178
|
+
}
|
|
2179
|
+
function fromURL(res) {
|
|
2180
|
+
let rawSpec = res.rawSpec;
|
|
2181
|
+
res.saveSpec = rawSpec;
|
|
2182
|
+
if (rawSpec.startsWith("git+ssh:")) {
|
|
2183
|
+
const matched = rawSpec.match(/^git\+ssh:\/\/([^:#]+:[^#]+(?:\.git)?)(?:#(.*))?$/i);
|
|
2184
|
+
if (matched && !matched[1].match(/:[0-9]+\/?.*$/i)) {
|
|
2185
|
+
res.type = "git";
|
|
2186
|
+
setGitAttrs(res, matched[2]);
|
|
2187
|
+
res.fetchSpec = matched[1];
|
|
2188
|
+
return res;
|
|
2189
|
+
}
|
|
2190
|
+
} else if (rawSpec.startsWith("git+file://")) {
|
|
2191
|
+
rawSpec = rawSpec.replace(/\\/g, "/");
|
|
2192
|
+
}
|
|
2193
|
+
const parsedUrl = new URL(rawSpec);
|
|
2194
|
+
switch (parsedUrl.protocol) {
|
|
2195
|
+
case "git:":
|
|
2196
|
+
case "git+http:":
|
|
2197
|
+
case "git+https:":
|
|
2198
|
+
case "git+rsync:":
|
|
2199
|
+
case "git+ftp:":
|
|
2200
|
+
case "git+file:":
|
|
2201
|
+
case "git+ssh:":
|
|
2202
|
+
res.type = "git";
|
|
2203
|
+
setGitAttrs(res, parsedUrl.hash.slice(1));
|
|
2204
|
+
if (parsedUrl.protocol === "git+file:" && /^git\+file:\/\/[a-z]:/i.test(rawSpec)) {
|
|
2205
|
+
res.fetchSpec = `git+file://${parsedUrl.host.toLowerCase()}:${parsedUrl.pathname}`;
|
|
2206
|
+
} else {
|
|
2207
|
+
parsedUrl.hash = "";
|
|
2208
|
+
res.fetchSpec = parsedUrl.toString();
|
|
2209
|
+
}
|
|
2210
|
+
if (res.fetchSpec.startsWith("git+")) {
|
|
2211
|
+
res.fetchSpec = res.fetchSpec.slice(4);
|
|
2212
|
+
}
|
|
2213
|
+
break;
|
|
2214
|
+
case "http:":
|
|
2215
|
+
case "https:":
|
|
2216
|
+
res.type = "remote";
|
|
2217
|
+
res.fetchSpec = res.saveSpec;
|
|
2218
|
+
break;
|
|
2219
|
+
default:
|
|
2220
|
+
throw unsupportedURLType(parsedUrl.protocol, rawSpec);
|
|
2221
|
+
}
|
|
2222
|
+
return res;
|
|
2223
|
+
}
|
|
2224
|
+
function fromAlias(res, where) {
|
|
2225
|
+
const subSpec = npa(res.rawSpec.substr(4), where);
|
|
2226
|
+
if (subSpec.type === "alias") {
|
|
2227
|
+
throw new Error("nested aliases not supported");
|
|
2228
|
+
}
|
|
2229
|
+
if (!subSpec.registry) {
|
|
2230
|
+
throw new Error("aliases only work for registry deps");
|
|
2231
|
+
}
|
|
2232
|
+
res.subSpec = subSpec;
|
|
2233
|
+
res.registry = true;
|
|
2234
|
+
res.type = "alias";
|
|
2235
|
+
res.saveSpec = null;
|
|
2236
|
+
res.fetchSpec = null;
|
|
2237
|
+
return res;
|
|
2238
|
+
}
|
|
2239
|
+
function fromRegistry(res) {
|
|
2240
|
+
res.registry = true;
|
|
2241
|
+
const spec = res.rawSpec.trim();
|
|
2242
|
+
res.saveSpec = null;
|
|
2243
|
+
res.fetchSpec = spec;
|
|
2244
|
+
const version = semver.valid(spec, true);
|
|
2245
|
+
const range = semver.validRange(spec, true);
|
|
2246
|
+
if (version) {
|
|
2247
|
+
res.type = "version";
|
|
2248
|
+
} else if (range) {
|
|
2249
|
+
res.type = "range";
|
|
2250
|
+
} else {
|
|
2251
|
+
if (encodeURIComponent(spec) !== spec) {
|
|
2252
|
+
throw invalidTagName(spec, res.raw);
|
|
2253
|
+
}
|
|
2254
|
+
res.type = "tag";
|
|
2255
|
+
}
|
|
2256
|
+
return res;
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
export default require_npa();
|