@percy/core 1.28.9 → 1.29.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/percy.js +34 -46
- package/dist/queue.js +80 -113
- package/dist/server.js +39 -57
- package/package.json +8 -8
package/dist/percy.js
CHANGED
|
@@ -4,13 +4,9 @@ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("C
|
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
function _classPrivateMethodGet(s, a, r) { return _assertClassBrand(a, s), r; }
|
|
8
|
-
function _classPrivateFieldGet2(e, t) { var r = _classPrivateFieldGet(t, e); return _classApplyDescriptorGet(e, r); }
|
|
9
|
-
function _classApplyDescriptorGet(e, t) { return t.get ? t.get.call(e) : t.value; }
|
|
10
|
-
function _classPrivateFieldSet(e, t, r) { var s = _classPrivateFieldGet(t, e); return _classApplyDescriptorSet(e, s, r), r; }
|
|
11
7
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
8
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
12
9
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
13
|
-
function _classApplyDescriptorSet(e, t, l) { if (t.set) t.set.call(e, l);else { if (!t.writable) throw new TypeError("attempted to set read only private field"); t.value = l; } }
|
|
14
10
|
import PercyClient from '@percy/client';
|
|
15
11
|
import PercyConfig from '@percy/config';
|
|
16
12
|
import logger from '@percy/logger';
|
|
@@ -28,8 +24,7 @@ import { WaitForJob } from './wait-for-job.js';
|
|
|
28
24
|
// concurrently and the build is not finalized until all snapshots have been handled.
|
|
29
25
|
var _discovery = /*#__PURE__*/new WeakMap();
|
|
30
26
|
var _snapshots = /*#__PURE__*/new WeakMap();
|
|
31
|
-
var
|
|
32
|
-
var _proxyEnabled = /*#__PURE__*/new WeakSet();
|
|
27
|
+
var _Percy_brand = /*#__PURE__*/new WeakSet();
|
|
33
28
|
export class Percy {
|
|
34
29
|
// Static shortcut to create and start an instance in one call
|
|
35
30
|
static async start(options) {
|
|
@@ -68,18 +63,11 @@ export class Percy {
|
|
|
68
63
|
..._options
|
|
69
64
|
} = {}) {
|
|
70
65
|
var _config$percy, _config$percy2;
|
|
71
|
-
_classPrivateMethodInitSpec(this,
|
|
72
|
-
_classPrivateMethodInitSpec(this, _displaySuggestionLogs);
|
|
66
|
+
_classPrivateMethodInitSpec(this, _Percy_brand);
|
|
73
67
|
_defineProperty(this, "log", logger('core'));
|
|
74
68
|
_defineProperty(this, "readyState", null);
|
|
75
|
-
_classPrivateFieldInitSpec(this, _discovery,
|
|
76
|
-
|
|
77
|
-
value: null
|
|
78
|
-
});
|
|
79
|
-
_classPrivateFieldInitSpec(this, _snapshots, {
|
|
80
|
-
writable: true,
|
|
81
|
-
value: null
|
|
82
|
-
});
|
|
69
|
+
_classPrivateFieldInitSpec(this, _discovery, null);
|
|
70
|
+
_classPrivateFieldInitSpec(this, _snapshots, null);
|
|
83
71
|
let config = PercyConfig.load({
|
|
84
72
|
overrides: _options,
|
|
85
73
|
path: configFile
|
|
@@ -107,8 +95,8 @@ export class Percy {
|
|
|
107
95
|
});
|
|
108
96
|
if (server) this.server = createPercyServer(this, port);
|
|
109
97
|
this.browser = new Browser(this);
|
|
110
|
-
_classPrivateFieldSet(
|
|
111
|
-
_classPrivateFieldSet(
|
|
98
|
+
_classPrivateFieldSet(_discovery, this, createDiscoveryQueue(this));
|
|
99
|
+
_classPrivateFieldSet(_snapshots, this, createSnapshotsQueue(this));
|
|
112
100
|
|
|
113
101
|
// generator methods are wrapped to autorun and return promises
|
|
114
102
|
for (let m of ['start', 'stop', 'flush', 'idle', 'snapshot', 'upload']) {
|
|
@@ -161,10 +149,10 @@ export class Percy {
|
|
|
161
149
|
let {
|
|
162
150
|
concurrency
|
|
163
151
|
} = this.config.discovery;
|
|
164
|
-
|
|
152
|
+
_classPrivateFieldGet(_discovery, this).set({
|
|
165
153
|
concurrency
|
|
166
154
|
});
|
|
167
|
-
|
|
155
|
+
_classPrivateFieldGet(_snapshots, this).set({
|
|
168
156
|
concurrency
|
|
169
157
|
});
|
|
170
158
|
return this.config;
|
|
@@ -180,9 +168,9 @@ export class Percy {
|
|
|
180
168
|
this.log.warn('Notice: Percy collects CI logs for service improvement, stored for 30 days. Opt-out anytime with export PERCY_CLIENT_ERROR_LOGS=false');
|
|
181
169
|
}
|
|
182
170
|
// start the snapshots queue immediately when not delayed or deferred
|
|
183
|
-
if (!this.delayUploads && !this.deferUploads) yield
|
|
171
|
+
if (!this.delayUploads && !this.deferUploads) yield _classPrivateFieldGet(_snapshots, this).start();
|
|
184
172
|
// do not start the discovery queue when not needed
|
|
185
|
-
if (!this.skipDiscovery) yield
|
|
173
|
+
if (!this.skipDiscovery) yield _classPrivateFieldGet(_discovery, this).start();
|
|
186
174
|
// start a local API server for SDK communication
|
|
187
175
|
if (this.server) yield this.server.listen();
|
|
188
176
|
if (this.projectType === 'web') {
|
|
@@ -200,8 +188,8 @@ export class Percy {
|
|
|
200
188
|
var _this$server2;
|
|
201
189
|
// on error, close any running server and end queues
|
|
202
190
|
await ((_this$server2 = this.server) === null || _this$server2 === void 0 ? void 0 : _this$server2.close());
|
|
203
|
-
await
|
|
204
|
-
await
|
|
191
|
+
await _classPrivateFieldGet(_discovery, this).end();
|
|
192
|
+
await _classPrivateFieldGet(_snapshots, this).end();
|
|
205
193
|
|
|
206
194
|
// mark this instance as closed unless aborting
|
|
207
195
|
this.readyState = error.name !== 'AbortError' ? 3 : null;
|
|
@@ -220,8 +208,8 @@ export class Percy {
|
|
|
220
208
|
|
|
221
209
|
// Resolves once snapshot and upload queues are idle
|
|
222
210
|
async *idle() {
|
|
223
|
-
yield*
|
|
224
|
-
yield*
|
|
211
|
+
yield* _classPrivateFieldGet(_discovery, this).idle();
|
|
212
|
+
yield* _classPrivateFieldGet(_snapshots, this).idle();
|
|
225
213
|
}
|
|
226
214
|
|
|
227
215
|
// Wait for currently queued snapshots then run and wait for resulting uploads
|
|
@@ -234,13 +222,13 @@ export class Percy {
|
|
|
234
222
|
yield new Promise(r => setImmediate(r));
|
|
235
223
|
|
|
236
224
|
// flush and log progress for discovery before snapshots
|
|
237
|
-
if (!this.skipDiscovery &&
|
|
238
|
-
if (options) yield* yieldAll(options.map(o =>
|
|
225
|
+
if (!this.skipDiscovery && _classPrivateFieldGet(_discovery, this).size) {
|
|
226
|
+
if (options) yield* yieldAll(options.map(o => _classPrivateFieldGet(_discovery, this).process(o)));else yield* _classPrivateFieldGet(_discovery, this).flush(size => callback === null || callback === void 0 ? void 0 : callback('Processing', size));
|
|
239
227
|
}
|
|
240
228
|
|
|
241
229
|
// flush and log progress for snapshot uploads
|
|
242
|
-
if (!this.skipUploads &&
|
|
243
|
-
if (options) yield* yieldAll(options.map(o =>
|
|
230
|
+
if (!this.skipUploads && _classPrivateFieldGet(_snapshots, this).size) {
|
|
231
|
+
if (options) yield* yieldAll(options.map(o => _classPrivateFieldGet(_snapshots, this).process(o)));else yield* _classPrivateFieldGet(_snapshots, this).flush(size => callback === null || callback === void 0 ? void 0 : callback('Uploading', size));
|
|
244
232
|
}
|
|
245
233
|
}
|
|
246
234
|
|
|
@@ -259,8 +247,8 @@ export class Percy {
|
|
|
259
247
|
|
|
260
248
|
// close queues asap
|
|
261
249
|
if (force) {
|
|
262
|
-
|
|
263
|
-
|
|
250
|
+
_classPrivateFieldGet(_discovery, this).close(true);
|
|
251
|
+
_classPrivateFieldGet(_snapshots, this).close(true);
|
|
264
252
|
}
|
|
265
253
|
|
|
266
254
|
// already stopping
|
|
@@ -285,14 +273,14 @@ export class Percy {
|
|
|
285
273
|
}
|
|
286
274
|
|
|
287
275
|
// if dry-running, log the total number of snapshots
|
|
288
|
-
if (this.dryRun &&
|
|
289
|
-
this.log.info(info('Found',
|
|
276
|
+
if (this.dryRun && _classPrivateFieldGet(_snapshots, this).size) {
|
|
277
|
+
this.log.info(info('Found', _classPrivateFieldGet(_snapshots, this).size));
|
|
290
278
|
}
|
|
291
279
|
|
|
292
280
|
// close server and end queues
|
|
293
281
|
await ((_this$server3 = this.server) === null || _this$server3 === void 0 ? void 0 : _this$server3.close());
|
|
294
|
-
await
|
|
295
|
-
await
|
|
282
|
+
await _classPrivateFieldGet(_discovery, this).end();
|
|
283
|
+
await _classPrivateFieldGet(_snapshots, this).end();
|
|
296
284
|
|
|
297
285
|
// mark instance as stopped
|
|
298
286
|
this.readyState = 3;
|
|
@@ -355,7 +343,7 @@ export class Percy {
|
|
|
355
343
|
}
|
|
356
344
|
|
|
357
345
|
// gather snapshots and discover snapshot resources
|
|
358
|
-
yield* discoverSnapshotResources(
|
|
346
|
+
yield* discoverSnapshotResources(_classPrivateFieldGet(_discovery, this), {
|
|
359
347
|
skipDiscovery: this.skipDiscovery,
|
|
360
348
|
dryRun: this.dryRun,
|
|
361
349
|
snapshots: yield* gatherSnapshots(options, {
|
|
@@ -375,7 +363,7 @@ export class Percy {
|
|
|
375
363
|
});
|
|
376
364
|
}
|
|
377
365
|
// push each finished snapshot to the snapshots queue
|
|
378
|
-
|
|
366
|
+
_classPrivateFieldGet(_snapshots, this).push(snapshot);
|
|
379
367
|
});
|
|
380
368
|
} finally {
|
|
381
369
|
var _server;
|
|
@@ -435,9 +423,9 @@ export class Percy {
|
|
|
435
423
|
// return an async generator to allow cancelation
|
|
436
424
|
return async function* () {
|
|
437
425
|
try {
|
|
438
|
-
return yield* yieldTo(
|
|
426
|
+
return yield* yieldTo(_classPrivateFieldGet(_snapshots, this).push(options));
|
|
439
427
|
} catch (error) {
|
|
440
|
-
|
|
428
|
+
_classPrivateFieldGet(_snapshots, this).cancel(options);
|
|
441
429
|
// Detecting and suggesting fix for errors;
|
|
442
430
|
await this.suggestionsForFix(error.message);
|
|
443
431
|
throw error;
|
|
@@ -487,7 +475,7 @@ export class Percy {
|
|
|
487
475
|
});
|
|
488
476
|
if (isPercyStarted && !containsSnapshotTaken) {
|
|
489
477
|
// This is the case for No snapshot command called
|
|
490
|
-
|
|
478
|
+
_assertClassBrand(_Percy_brand, this, _displaySuggestionLogs).call(this, [{
|
|
491
479
|
failure_reason: 'Snapshot command was not called',
|
|
492
480
|
reason_message: 'Snapshot Command was not called. please check your CI for errors',
|
|
493
481
|
suggestion: 'Try using percy snapshot command to take snapshots',
|
|
@@ -498,14 +486,14 @@ export class Percy {
|
|
|
498
486
|
async suggestionsForFix(errors, options = {}) {
|
|
499
487
|
try {
|
|
500
488
|
const suggestionResponse = await this.client.getErrorAnalysis(errors);
|
|
501
|
-
|
|
489
|
+
_assertClassBrand(_Percy_brand, this, _displaySuggestionLogs).call(this, suggestionResponse, options);
|
|
502
490
|
} catch (e) {
|
|
503
491
|
// Common error code for Proxy issues
|
|
504
492
|
const PROXY_CODES = ['ECONNREFUSED', 'ECONNRESET', 'EHOSTUNREACH'];
|
|
505
493
|
if (!!e.code && PROXY_CODES.includes(e.code)) {
|
|
506
494
|
// This can be due to proxy issue
|
|
507
495
|
this.log.error('percy.io might not be reachable, check network connection, proxy and ensure that percy.io is whitelisted.');
|
|
508
|
-
if (!
|
|
496
|
+
if (!_assertClassBrand(_Percy_brand, this, _proxyEnabled).call(this)) {
|
|
509
497
|
this.log.error('If inside a proxied envirnment, please configure the following environment variables: HTTP_PROXY, [ and optionally HTTPS_PROXY if you need it ]. Refer to our documentation for more details');
|
|
510
498
|
}
|
|
511
499
|
}
|
|
@@ -544,7 +532,7 @@ export class Percy {
|
|
|
544
532
|
}
|
|
545
533
|
}
|
|
546
534
|
}
|
|
547
|
-
function
|
|
535
|
+
function _displaySuggestionLogs(suggestions, options = {}) {
|
|
548
536
|
if (!(suggestions !== null && suggestions !== void 0 && suggestions.length)) return;
|
|
549
537
|
suggestions.forEach(item => {
|
|
550
538
|
const failure = item === null || item === void 0 ? void 0 : item.failure_reason;
|
|
@@ -567,7 +555,7 @@ function _displaySuggestionLogs2(suggestions, options = {}) {
|
|
|
567
555
|
}
|
|
568
556
|
});
|
|
569
557
|
}
|
|
570
|
-
function
|
|
558
|
+
function _proxyEnabled() {
|
|
571
559
|
return !!(getProxy({
|
|
572
560
|
protocol: 'https:'
|
|
573
561
|
}) || getProxy({}));
|
package/dist/queue.js
CHANGED
|
@@ -4,13 +4,9 @@ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("C
|
|
|
4
4
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
-
function _classPrivateFieldSet(
|
|
8
|
-
function
|
|
9
|
-
function _classPrivateMethodGet(s, a, r) { return _assertClassBrand(a, s), r; }
|
|
10
|
-
function _classPrivateFieldGet(e, t) { var r = _classPrivateFieldGet2(t, e); return _classApplyDescriptorGet(e, r); }
|
|
11
|
-
function _classPrivateFieldGet2(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
7
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
8
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
12
9
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
13
|
-
function _classApplyDescriptorGet(e, t) { return t.get ? t.get.call(e) : t.value; }
|
|
14
10
|
import { yieldFor, generatePromise, AbortController } from './utils.js';
|
|
15
11
|
import logger from '@percy/logger';
|
|
16
12
|
|
|
@@ -43,42 +39,25 @@ class QueueClosedError extends Error {
|
|
|
43
39
|
var _handlers = /*#__PURE__*/new WeakMap();
|
|
44
40
|
var _queued = /*#__PURE__*/new WeakMap();
|
|
45
41
|
var _pending = /*#__PURE__*/new WeakMap();
|
|
46
|
-
var
|
|
47
|
-
var _find = /*#__PURE__*/new WeakSet();
|
|
42
|
+
var _Queue_brand = /*#__PURE__*/new WeakSet();
|
|
48
43
|
var _start = /*#__PURE__*/new WeakMap();
|
|
49
44
|
var _end = /*#__PURE__*/new WeakMap();
|
|
50
|
-
var _process = /*#__PURE__*/new WeakSet();
|
|
51
|
-
var _until = /*#__PURE__*/new WeakSet();
|
|
52
45
|
export class Queue {
|
|
53
|
-
// item concurrency
|
|
54
|
-
|
|
55
46
|
constructor(name) {
|
|
56
|
-
|
|
57
|
-
_classPrivateMethodInitSpec(this,
|
|
58
|
-
|
|
59
|
-
_classPrivateMethodInitSpec(this, _dequeue);
|
|
47
|
+
// Maybe processes the next queued item task.
|
|
48
|
+
_classPrivateMethodInitSpec(this, _Queue_brand);
|
|
49
|
+
// item concurrency
|
|
60
50
|
_defineProperty(this, "concurrency", 10);
|
|
61
51
|
_defineProperty(this, "log", logger('core:queue'));
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_classPrivateFieldInitSpec(this,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
writable: true,
|
|
72
|
-
value: new Set()
|
|
73
|
-
});
|
|
74
|
-
_classPrivateFieldInitSpec(this, _start, {
|
|
75
|
-
writable: true,
|
|
76
|
-
value: null
|
|
77
|
-
});
|
|
78
|
-
_classPrivateFieldInitSpec(this, _end, {
|
|
79
|
-
writable: true,
|
|
80
|
-
value: null
|
|
81
|
-
});
|
|
52
|
+
// Configure queue handlers
|
|
53
|
+
_classPrivateFieldInitSpec(this, _handlers, {});
|
|
54
|
+
// internal queues
|
|
55
|
+
_classPrivateFieldInitSpec(this, _queued, new Set());
|
|
56
|
+
_classPrivateFieldInitSpec(this, _pending, new Set());
|
|
57
|
+
// keep track of start and end tasks
|
|
58
|
+
_classPrivateFieldInitSpec(this, _start, null);
|
|
59
|
+
_classPrivateFieldInitSpec(this, _end, null);
|
|
60
|
+
// represents various queue states such as ready, running, or closed
|
|
82
61
|
_defineProperty(this, "readyState", 0);
|
|
83
62
|
this.name = name;
|
|
84
63
|
}
|
|
@@ -90,19 +69,13 @@ export class Queue {
|
|
|
90
69
|
if (concurrency) this.concurrency = concurrency;
|
|
91
70
|
return this;
|
|
92
71
|
}
|
|
93
|
-
|
|
94
|
-
// Configure queue handlers
|
|
95
|
-
|
|
96
72
|
handle(event, handler) {
|
|
97
|
-
_classPrivateFieldGet(
|
|
73
|
+
_classPrivateFieldGet(_handlers, this)[event] = handler;
|
|
98
74
|
return this;
|
|
99
75
|
}
|
|
100
|
-
|
|
101
|
-
// internal queues
|
|
102
|
-
|
|
103
76
|
// Queue size is total queued and pending items
|
|
104
77
|
get size() {
|
|
105
|
-
return _classPrivateFieldGet(
|
|
78
|
+
return _classPrivateFieldGet(_queued, this).size + _classPrivateFieldGet(_pending, this).size;
|
|
106
79
|
}
|
|
107
80
|
|
|
108
81
|
// Pushes an item into the queue, additional args are passed to any configured task handler.
|
|
@@ -113,8 +86,8 @@ export class Queue {
|
|
|
113
86
|
|
|
114
87
|
// attach any configured error handler
|
|
115
88
|
task.deferred = task.deferred.catch(e => {
|
|
116
|
-
if (!_classPrivateFieldGet(
|
|
117
|
-
return _classPrivateFieldGet(
|
|
89
|
+
if (!_classPrivateFieldGet(_handlers, this).error) throw e;
|
|
90
|
+
return _classPrivateFieldGet(_handlers, this).error(item, e);
|
|
118
91
|
});
|
|
119
92
|
|
|
120
93
|
// when closed, reject with a queue closed error
|
|
@@ -132,25 +105,22 @@ export class Queue {
|
|
|
132
105
|
if (typeof item === 'object' && !Array.isArray(item) && item !== null) {
|
|
133
106
|
item._ctrl = task.ctrl;
|
|
134
107
|
}
|
|
135
|
-
task.item = item = _classPrivateFieldGet(
|
|
136
|
-
task.handler = () => _classPrivateFieldGet(
|
|
108
|
+
task.item = item = _classPrivateFieldGet(_handlers, this).push ? _classPrivateFieldGet(_handlers, this).push(item, exists) : item;
|
|
109
|
+
task.handler = () => _classPrivateFieldGet(_handlers, this).task ? _classPrivateFieldGet(_handlers, this).task(item, ...args) : item;
|
|
137
110
|
|
|
138
111
|
// queue this task & maybe dequeue the next task
|
|
139
|
-
_classPrivateFieldGet(
|
|
140
|
-
|
|
112
|
+
_classPrivateFieldGet(_queued, this).add(task);
|
|
113
|
+
_assertClassBrand(_Queue_brand, this, _dequeue).call(this);
|
|
141
114
|
|
|
142
115
|
// return the deferred task promise
|
|
143
116
|
return task.deferred;
|
|
144
117
|
}
|
|
145
|
-
|
|
146
|
-
// Maybe processes the next queued item task.
|
|
147
|
-
|
|
148
118
|
// Cancels and aborts a specific item task.
|
|
149
119
|
cancel(item) {
|
|
150
|
-
let task =
|
|
120
|
+
let task = _assertClassBrand(_Queue_brand, this, _find).call(this, item);
|
|
151
121
|
task === null || task === void 0 ? void 0 : task.ctrl.abort();
|
|
152
|
-
let queued = _classPrivateFieldGet(
|
|
153
|
-
let pending = _classPrivateFieldGet(
|
|
122
|
+
let queued = _classPrivateFieldGet(_queued, this).delete(task);
|
|
123
|
+
let pending = _classPrivateFieldGet(_pending, this).delete(task);
|
|
154
124
|
|
|
155
125
|
// reject queued tasks that are not pending
|
|
156
126
|
if (task && queued && !pending) {
|
|
@@ -163,39 +133,36 @@ export class Queue {
|
|
|
163
133
|
|
|
164
134
|
// Returns an item task matching the provided subject.
|
|
165
135
|
|
|
166
|
-
// keep track of start and end tasks
|
|
167
|
-
|
|
168
136
|
// Initialize a starting task or return an existing one.
|
|
169
137
|
start() {
|
|
170
|
-
var
|
|
171
|
-
_classPrivateFieldGet(
|
|
138
|
+
var _classPrivateFieldGet2;
|
|
139
|
+
_classPrivateFieldGet(_start, this) ?? _classPrivateFieldSet(_start, this, deferred({
|
|
172
140
|
readyState: 1
|
|
173
141
|
}));
|
|
174
|
-
(
|
|
175
|
-
|
|
176
|
-
|
|
142
|
+
(_classPrivateFieldGet2 = _classPrivateFieldGet(_start, this)).handler ?? (_classPrivateFieldGet2.handler = _classPrivateFieldGet(_end, this)
|
|
143
|
+
// wait for any ending task to complete first
|
|
144
|
+
? () => _classPrivateFieldGet(_end, this).promise.then(_classPrivateFieldGet(_handlers, this).start) : _classPrivateFieldGet(_handlers, this).start);
|
|
145
|
+
return _assertClassBrand(_Queue_brand, this, _process).call(this, _classPrivateFieldGet(_start, this)).deferred;
|
|
177
146
|
}
|
|
178
147
|
|
|
179
148
|
// intialize an ending task or return an existing one
|
|
180
149
|
end() {
|
|
181
|
-
var
|
|
182
|
-
_classPrivateFieldGet(
|
|
150
|
+
var _classPrivateFieldGet3;
|
|
151
|
+
_classPrivateFieldGet(_end, this) ?? _classPrivateFieldSet(_end, this, deferred({
|
|
183
152
|
readyState: 0
|
|
184
153
|
}));
|
|
185
|
-
(
|
|
186
|
-
|
|
187
|
-
|
|
154
|
+
(_classPrivateFieldGet3 = _classPrivateFieldGet(_end, this)).handler ?? (_classPrivateFieldGet3.handler = _classPrivateFieldGet(_start, this)
|
|
155
|
+
// wait for any starting task to complete first
|
|
156
|
+
? () => _classPrivateFieldGet(_start, this).promise.then(_classPrivateFieldGet(_handlers, this).end) : _classPrivateFieldGet(_handlers, this).end);
|
|
157
|
+
return _assertClassBrand(_Queue_brand, this, _process).call(this, _classPrivateFieldGet(_end, this)).deferred;
|
|
188
158
|
}
|
|
189
|
-
|
|
190
|
-
// represents various queue states such as ready, running, or closed
|
|
191
|
-
|
|
192
159
|
// run the queue, starting it if necessary, and start dequeuing tasks
|
|
193
160
|
run() {
|
|
194
|
-
if (!_classPrivateFieldGet(
|
|
161
|
+
if (!_classPrivateFieldGet(_start, this)) this.start();
|
|
195
162
|
// when starting, state is updated afterwards
|
|
196
|
-
if (this.readyState === 0) _classPrivateFieldGet(
|
|
163
|
+
if (this.readyState === 0) _classPrivateFieldGet(_start, this).readyState = 2;
|
|
197
164
|
if (this.readyState === 1) this.readyState = 2;
|
|
198
|
-
while (
|
|
165
|
+
while (_assertClassBrand(_Queue_brand, this, _dequeue).call(this)) _assertClassBrand(_Queue_brand, this, _dequeue).call(this);
|
|
199
166
|
return this;
|
|
200
167
|
}
|
|
201
168
|
|
|
@@ -207,9 +174,9 @@ export class Queue {
|
|
|
207
174
|
|
|
208
175
|
// close a running queue, optionally aborting it
|
|
209
176
|
close(abort) {
|
|
210
|
-
var
|
|
177
|
+
var _classPrivateFieldGet4;
|
|
211
178
|
// when starting, state is updated afterwards
|
|
212
|
-
if ((
|
|
179
|
+
if ((_classPrivateFieldGet4 = _classPrivateFieldGet(_start, this)) !== null && _classPrivateFieldGet4 !== void 0 && _classPrivateFieldGet4.pending) _classPrivateFieldGet(_start, this).readyState = 3;
|
|
213
180
|
if (this.readyState < 3) this.readyState = 3;
|
|
214
181
|
if (abort) this.clear();
|
|
215
182
|
return this;
|
|
@@ -217,9 +184,9 @@ export class Queue {
|
|
|
217
184
|
|
|
218
185
|
// clear and abort any queued tasks
|
|
219
186
|
clear() {
|
|
220
|
-
let tasks = [..._classPrivateFieldGet(
|
|
221
|
-
this.log.debug(`Clearing ${this.name} queue, queued state: ${_classPrivateFieldGet(
|
|
222
|
-
_classPrivateFieldGet(
|
|
187
|
+
let tasks = [..._classPrivateFieldGet(_queued, this)];
|
|
188
|
+
this.log.debug(`Clearing ${this.name} queue, queued state: ${_classPrivateFieldGet(_queued, this).size}, pending state: ${_classPrivateFieldGet(_pending, this).size}`);
|
|
189
|
+
_classPrivateFieldGet(_queued, this).clear();
|
|
223
190
|
for (let task of tasks) {
|
|
224
191
|
task.ctrl.abort();
|
|
225
192
|
task.reject(task.ctrl.signal.reason);
|
|
@@ -228,10 +195,10 @@ export class Queue {
|
|
|
228
195
|
|
|
229
196
|
// process a single item task when started
|
|
230
197
|
process(item) {
|
|
231
|
-
var
|
|
232
|
-
let task =
|
|
233
|
-
if (task && !_classPrivateFieldGet(
|
|
234
|
-
(
|
|
198
|
+
var _classPrivateFieldGet5;
|
|
199
|
+
let task = _assertClassBrand(_Queue_brand, this, _find).call(this, item);
|
|
200
|
+
if (task && !_classPrivateFieldGet(_start, this)) this.start();
|
|
201
|
+
(_classPrivateFieldGet5 = _classPrivateFieldGet(_start, this)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.promise.then(() => _assertClassBrand(_Queue_brand, this, _process).call(this, task));
|
|
235
202
|
return task === null || task === void 0 ? void 0 : task.deferred;
|
|
236
203
|
}
|
|
237
204
|
|
|
@@ -241,10 +208,10 @@ export class Queue {
|
|
|
241
208
|
// callback every 10ms during checks with the current number of pending tasks
|
|
242
209
|
idle(callback) {
|
|
243
210
|
return yieldFor(() => {
|
|
244
|
-
var
|
|
245
|
-
callback === null || callback === void 0 ? void 0 : callback(_classPrivateFieldGet(
|
|
246
|
-
let starting = ((
|
|
247
|
-
return !starting && !_classPrivateFieldGet(
|
|
211
|
+
var _classPrivateFieldGet6;
|
|
212
|
+
callback === null || callback === void 0 ? void 0 : callback(_classPrivateFieldGet(_pending, this).size);
|
|
213
|
+
let starting = ((_classPrivateFieldGet6 = _classPrivateFieldGet(_start, this)) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.pending) === true;
|
|
214
|
+
return !starting && !_classPrivateFieldGet(_pending, this).size;
|
|
248
215
|
}, {
|
|
249
216
|
idle: 10
|
|
250
217
|
});
|
|
@@ -253,57 +220,57 @@ export class Queue {
|
|
|
253
220
|
// process items up to the latest queued item, starting the queue if necessary;
|
|
254
221
|
// returns a generator that yields until the flushed item has finished processing
|
|
255
222
|
flush(callback) {
|
|
256
|
-
this.log.debug(`Flushing ${this.name} queue, queued state: ${_classPrivateFieldGet(
|
|
223
|
+
this.log.debug(`Flushing ${this.name} queue, queued state: ${_classPrivateFieldGet(_queued, this).size}, pending state: ${_classPrivateFieldGet(_pending, this).size}`);
|
|
257
224
|
let interrupt =
|
|
258
225
|
// check for existing interrupts
|
|
259
|
-
[..._classPrivateFieldGet(
|
|
226
|
+
[..._classPrivateFieldGet(_pending, this)].find(t => t.stop) ?? [..._classPrivateFieldGet(_queued, this)].find(t => t.stop);
|
|
260
227
|
|
|
261
228
|
// get the latest queued or pending task to track
|
|
262
|
-
let flush = [..._classPrivateFieldGet(
|
|
229
|
+
let flush = [..._classPrivateFieldGet(_queued, this)].pop() ?? [..._classPrivateFieldGet(_pending, this)].pop();
|
|
263
230
|
// determine if the queue should be stopped after flushing
|
|
264
231
|
if (flush) flush.stop = (interrupt === null || interrupt === void 0 ? void 0 : interrupt.stop) ?? this.readyState < 2;
|
|
265
232
|
// remove the old interrupt to avoid stopping early
|
|
266
233
|
if (interrupt) delete interrupt.stop;
|
|
267
234
|
// start the queue if not started
|
|
268
|
-
if (!_classPrivateFieldGet(
|
|
235
|
+
if (!_classPrivateFieldGet(_start, this)) this.start();
|
|
269
236
|
// run the queue if stopped
|
|
270
237
|
if (flush !== null && flush !== void 0 && flush.stop) this.run();
|
|
271
238
|
|
|
272
239
|
// will yield with the callback until done flushing
|
|
273
|
-
return
|
|
240
|
+
return _assertClassBrand(_Queue_brand, this, _until).call(this, flush, callback);
|
|
274
241
|
}
|
|
275
242
|
|
|
276
243
|
// Repeatedly yields, calling the callback with the position of the task within the queue
|
|
277
244
|
}
|
|
278
|
-
function
|
|
279
|
-
if (!_classPrivateFieldGet(
|
|
280
|
-
if (_classPrivateFieldGet(
|
|
281
|
-
let [task] = _classPrivateFieldGet(
|
|
282
|
-
return
|
|
245
|
+
function _dequeue() {
|
|
246
|
+
if (!_classPrivateFieldGet(_queued, this).size || this.readyState < 2) return;
|
|
247
|
+
if (_classPrivateFieldGet(_pending, this).size >= this.concurrency) return;
|
|
248
|
+
let [task] = _classPrivateFieldGet(_queued, this);
|
|
249
|
+
return _assertClassBrand(_Queue_brand, this, _process).call(this, task);
|
|
283
250
|
}
|
|
284
|
-
function
|
|
285
|
-
let find = _classPrivateFieldGet(
|
|
251
|
+
function _find(subject) {
|
|
252
|
+
let find = _classPrivateFieldGet(_handlers, this).find
|
|
286
253
|
// use any configured find handler to match items
|
|
287
254
|
? ({
|
|
288
255
|
item
|
|
289
|
-
}) => _classPrivateFieldGet(
|
|
256
|
+
}) => _classPrivateFieldGet(_handlers, this).find(subject, item) : ({
|
|
290
257
|
item
|
|
291
258
|
}) => subject === item;
|
|
292
259
|
return (
|
|
293
260
|
// look at queued then pending items
|
|
294
|
-
[..._classPrivateFieldGet(
|
|
261
|
+
[..._classPrivateFieldGet(_queued, this)].find(find) ?? [..._classPrivateFieldGet(_pending, this)].find(find)
|
|
295
262
|
);
|
|
296
263
|
}
|
|
297
|
-
function
|
|
264
|
+
function _process(task) {
|
|
298
265
|
var _task$ctrl;
|
|
299
266
|
if (!task || task.promise) return task;
|
|
300
|
-
let queued = _classPrivateFieldGet(
|
|
267
|
+
let queued = _classPrivateFieldGet(_queued, this).has(task);
|
|
301
268
|
// remove queued tasks from the queue
|
|
302
|
-
if (queued) _classPrivateFieldGet(
|
|
269
|
+
if (queued) _classPrivateFieldGet(_queued, this).delete(task);
|
|
303
270
|
// clear queued tasks when ending
|
|
304
|
-
if (task === _classPrivateFieldGet(
|
|
271
|
+
if (task === _classPrivateFieldGet(_end, this)) this.clear();
|
|
305
272
|
// add queued tasks to pending queue
|
|
306
|
-
if (queued) _classPrivateFieldGet(
|
|
273
|
+
if (queued) _classPrivateFieldGet(_pending, this).add(task);
|
|
307
274
|
// stop the queue when necessary
|
|
308
275
|
if (task.stop) this.stop();
|
|
309
276
|
// mark task as pending
|
|
@@ -312,11 +279,11 @@ function _process2(task) {
|
|
|
312
279
|
// handle the task using a generator promise
|
|
313
280
|
task.promise = generatePromise(task.handler, (_task$ctrl = task.ctrl) === null || _task$ctrl === void 0 ? void 0 : _task$ctrl.signal, (err, val) => {
|
|
314
281
|
// clean up pending tasks that have not been aborted
|
|
315
|
-
if (queued && !task.ctrl.signal.aborted) _classPrivateFieldGet(
|
|
282
|
+
if (queued && !task.ctrl.signal.aborted) _classPrivateFieldGet(_pending, this).delete(task);
|
|
316
283
|
// update queue state when necessary
|
|
317
284
|
if (task.readyState != null) this.readyState = task.readyState;
|
|
318
285
|
// clean up internal tasks after ending
|
|
319
|
-
if (!this.readyState) _classPrivateFieldSet(
|
|
286
|
+
if (!this.readyState) _classPrivateFieldSet(_start, this, _classPrivateFieldSet(_end, this, null));
|
|
320
287
|
// resolve or reject the deferred task promise
|
|
321
288
|
task[err ? 'reject' : 'resolve'](err ?? val);
|
|
322
289
|
// keep dequeuing when running
|
|
@@ -326,15 +293,15 @@ function _process2(task) {
|
|
|
326
293
|
});
|
|
327
294
|
return task;
|
|
328
295
|
}
|
|
329
|
-
async function*
|
|
296
|
+
async function* _until(task, callback) {
|
|
330
297
|
try {
|
|
331
298
|
yield* yieldFor(() => {
|
|
332
|
-
var
|
|
333
|
-
if ((
|
|
299
|
+
var _classPrivateFieldGet7;
|
|
300
|
+
if ((_classPrivateFieldGet7 = _classPrivateFieldGet(_start, this)) !== null && _classPrivateFieldGet7 !== void 0 && _classPrivateFieldGet7.pending) return false;
|
|
334
301
|
let queued,
|
|
335
|
-
pending = _classPrivateFieldGet(
|
|
302
|
+
pending = _classPrivateFieldGet(_pending, this).size;
|
|
336
303
|
// calculate the position within queued when not pending
|
|
337
|
-
if (task && task.pending == null) queued = positionOf(_classPrivateFieldGet(
|
|
304
|
+
if (task && task.pending == null) queued = positionOf(_classPrivateFieldGet(_queued, this), task);
|
|
338
305
|
// call the callback and return true when not queued or pending
|
|
339
306
|
let position = (queued ?? 0) + pending;
|
|
340
307
|
callback === null || callback === void 0 ? void 0 : callback(position);
|
package/dist/server.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
2
2
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
3
3
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
4
|
-
function _classPrivateFieldGet2(e, t) { var r = _classPrivateFieldGet(t, e); return _classApplyDescriptorGet(e, r); }
|
|
5
|
-
function _classApplyDescriptorGet(e, t) { return t.get ? t.get.call(e) : t.value; }
|
|
6
|
-
function _classPrivateMethodGet(s, a, r) { return _assertClassBrand(a, s), r; }
|
|
7
|
-
function _classPrivateFieldSet(e, t, r) { var s = _classPrivateFieldGet(t, e); return _classApplyDescriptorSet(e, s, r), r; }
|
|
8
4
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
5
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
9
6
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
10
|
-
function _classApplyDescriptorSet(e, t, l) { if (t.set) t.set.call(e, l);else { if (!t.writable) throw new TypeError("attempted to set read only private field"); t.value = l; } }
|
|
11
7
|
import fs from 'fs';
|
|
12
8
|
import path from 'path';
|
|
13
9
|
import http from 'http';
|
|
@@ -103,8 +99,7 @@ export class ServerError extends Error {
|
|
|
103
99
|
var _sockets = /*#__PURE__*/new WeakMap();
|
|
104
100
|
var _defaultPort = /*#__PURE__*/new WeakMap();
|
|
105
101
|
var _routes = /*#__PURE__*/new WeakMap();
|
|
106
|
-
var
|
|
107
|
-
var _handleRequest = /*#__PURE__*/new WeakSet();
|
|
102
|
+
var _Server_brand = /*#__PURE__*/new WeakSet();
|
|
108
103
|
export class Server extends http.Server {
|
|
109
104
|
constructor({
|
|
110
105
|
port
|
|
@@ -113,48 +108,40 @@ export class Server extends http.Server {
|
|
|
113
108
|
IncomingMessage,
|
|
114
109
|
ServerResponse
|
|
115
110
|
});
|
|
116
|
-
|
|
117
|
-
_classPrivateMethodInitSpec(this,
|
|
118
|
-
_classPrivateFieldInitSpec(this, _sockets,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
let allowMethods = [...new Set(_classPrivateFieldGet2(this, _routes).flatMap(route => (!route.match || route.match(req.url.pathname)) && route.methods || []))].join(', ');
|
|
135
|
-
res.setHeader('Access-Control-Allow-Headers', allowHeaders);
|
|
136
|
-
res.setHeader('Access-Control-Allow-Methods', allowMethods);
|
|
137
|
-
res.writeHead(204).end();
|
|
138
|
-
} else {
|
|
139
|
-
res.setHeader('Access-Control-Expose-Headers', '*');
|
|
140
|
-
return next();
|
|
141
|
-
}
|
|
111
|
+
// adds a route in the correct priority order
|
|
112
|
+
_classPrivateMethodInitSpec(this, _Server_brand);
|
|
113
|
+
_classPrivateFieldInitSpec(this, _sockets, new Set());
|
|
114
|
+
_classPrivateFieldInitSpec(this, _defaultPort, void 0);
|
|
115
|
+
// initial routes include cors and 404 handling
|
|
116
|
+
_classPrivateFieldInitSpec(this, _routes, [{
|
|
117
|
+
priority: -1,
|
|
118
|
+
handle: (req, res, next) => {
|
|
119
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
120
|
+
if (req.method === 'OPTIONS') {
|
|
121
|
+
let allowHeaders = req.headers['access-control-request-headers'] || '*';
|
|
122
|
+
let allowMethods = [...new Set(_classPrivateFieldGet(_routes, this).flatMap(route => (!route.match || route.match(req.url.pathname)) && route.methods || []))].join(', ');
|
|
123
|
+
res.setHeader('Access-Control-Allow-Headers', allowHeaders);
|
|
124
|
+
res.setHeader('Access-Control-Allow-Methods', allowMethods);
|
|
125
|
+
res.writeHead(204).end();
|
|
126
|
+
} else {
|
|
127
|
+
res.setHeader('Access-Control-Expose-Headers', '*');
|
|
128
|
+
return next();
|
|
142
129
|
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
_classPrivateFieldSet(
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
priority: 3,
|
|
133
|
+
handle: req => ServerError.throw(404)
|
|
134
|
+
}]);
|
|
135
|
+
_classPrivateFieldSet(_defaultPort, this, port);
|
|
149
136
|
|
|
150
137
|
// handle requests on end
|
|
151
138
|
this.on('request', (req, res) => {
|
|
152
|
-
req.on('end', () =>
|
|
139
|
+
req.on('end', () => _assertClassBrand(_Server_brand, this, _handleRequest).call(this, req, res));
|
|
153
140
|
});
|
|
154
141
|
// track open connections to terminate when the server closes
|
|
155
142
|
this.on('connection', socket => {
|
|
156
|
-
let handleClose = () =>
|
|
157
|
-
|
|
143
|
+
let handleClose = () => _classPrivateFieldGet(_sockets, this).delete(socket);
|
|
144
|
+
_classPrivateFieldGet(_sockets, this).add(socket.on('close', handleClose));
|
|
158
145
|
});
|
|
159
146
|
}
|
|
160
147
|
|
|
@@ -166,7 +153,7 @@ export class Server extends http.Server {
|
|
|
166
153
|
// return the listening port or any default port
|
|
167
154
|
get port() {
|
|
168
155
|
var _super$address;
|
|
169
|
-
return ((_super$address = super.address()) === null || _super$address === void 0 ? void 0 : _super$address.port) ??
|
|
156
|
+
return ((_super$address = super.address()) === null || _super$address === void 0 ? void 0 : _super$address.port) ?? _classPrivateFieldGet(_defaultPort, this);
|
|
170
157
|
}
|
|
171
158
|
|
|
172
159
|
// return a string representation of the server address
|
|
@@ -181,7 +168,7 @@ export class Server extends http.Server {
|
|
|
181
168
|
}
|
|
182
169
|
|
|
183
170
|
// return a promise that resolves when the server is listening
|
|
184
|
-
listen(port =
|
|
171
|
+
listen(port = _classPrivateFieldGet(_defaultPort, this)) {
|
|
185
172
|
return new Promise((resolve, reject) => {
|
|
186
173
|
let handle = err => off() && err ? reject(err) : resolve(this);
|
|
187
174
|
let off = () => this.off('error', handle).off('listening', handle);
|
|
@@ -192,21 +179,16 @@ export class Server extends http.Server {
|
|
|
192
179
|
// return a promise that resolves when the server closes
|
|
193
180
|
close() {
|
|
194
181
|
return new Promise(resolve => {
|
|
195
|
-
|
|
182
|
+
_classPrivateFieldGet(_sockets, this).forEach(socket => socket.destroy());
|
|
196
183
|
super.close(resolve);
|
|
197
184
|
});
|
|
198
185
|
}
|
|
199
|
-
|
|
200
|
-
// initial routes include cors and 404 handling
|
|
201
|
-
|
|
202
|
-
// adds a route in the correct priority order
|
|
203
|
-
|
|
204
186
|
// set request routing and handling for pathnames and methods
|
|
205
187
|
route(method, pathname, handle) {
|
|
206
188
|
if (arguments.length === 1) [handle, method] = [method];
|
|
207
189
|
if (arguments.length === 2) [handle, pathname] = [pathname];
|
|
208
190
|
if (arguments.length === 2 && !Array.isArray(method) && method[0] === '/') [pathname, method] = [method];
|
|
209
|
-
return
|
|
191
|
+
return _assertClassBrand(_Server_brand, this, _route).call(this, {
|
|
210
192
|
priority: !pathname ? 0 : !method ? 1 : 2,
|
|
211
193
|
methods: method && [].concat(method).map(m => m.toUpperCase()),
|
|
212
194
|
match: pathname && pathToMatch(pathname),
|
|
@@ -233,7 +215,7 @@ export class Server extends http.Server {
|
|
|
233
215
|
throw new ServerError(400);
|
|
234
216
|
}
|
|
235
217
|
});
|
|
236
|
-
return
|
|
218
|
+
return _assertClassBrand(_Server_brand, this, _route).call(this, {
|
|
237
219
|
priority: 2,
|
|
238
220
|
methods: ['GET'],
|
|
239
221
|
match: pathname => mountPattern.test(pathname),
|
|
@@ -257,12 +239,12 @@ export class Server extends http.Server {
|
|
|
257
239
|
}
|
|
258
240
|
|
|
259
241
|
// create a url rewriter from provided rewrite rules
|
|
260
|
-
function
|
|
261
|
-
let i =
|
|
262
|
-
|
|
242
|
+
function _route(route) {
|
|
243
|
+
let i = _classPrivateFieldGet(_routes, this).findIndex(r => r.priority >= route.priority);
|
|
244
|
+
_classPrivateFieldGet(_routes, this).splice(i, 0, route);
|
|
263
245
|
return this;
|
|
264
246
|
}
|
|
265
|
-
async function
|
|
247
|
+
async function _handleRequest(req, res) {
|
|
266
248
|
// support node < 15.7.0
|
|
267
249
|
res.req ?? (res.req = req);
|
|
268
250
|
try {
|
|
@@ -278,7 +260,7 @@ async function _handleRequest2(req, res) {
|
|
|
278
260
|
result && (result = !match || match(req.url.pathname));
|
|
279
261
|
if (result) req.params = result.params;
|
|
280
262
|
return result ? handle(req, res, next) : next();
|
|
281
|
-
}(
|
|
263
|
+
}(_classPrivateFieldGet(_routes, this));
|
|
282
264
|
} catch (error) {
|
|
283
265
|
var _req$headers$accept, _req$headers$content;
|
|
284
266
|
let {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.1-alpha.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public",
|
|
12
|
-
"tag": "
|
|
12
|
+
"tag": "alpha"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"test:types": "tsd"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@percy/client": "1.
|
|
47
|
-
"@percy/config": "1.
|
|
48
|
-
"@percy/dom": "1.
|
|
49
|
-
"@percy/logger": "1.
|
|
50
|
-
"@percy/webdriver-utils": "1.
|
|
46
|
+
"@percy/client": "1.29.1-alpha.0",
|
|
47
|
+
"@percy/config": "1.29.1-alpha.0",
|
|
48
|
+
"@percy/dom": "1.29.1-alpha.0",
|
|
49
|
+
"@percy/logger": "1.29.1-alpha.0",
|
|
50
|
+
"@percy/webdriver-utils": "1.29.1-alpha.0",
|
|
51
51
|
"content-disposition": "^0.5.4",
|
|
52
52
|
"cross-spawn": "^7.0.3",
|
|
53
53
|
"extract-zip": "^2.0.1",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"ws": "^8.17.1",
|
|
61
61
|
"yaml": "^2.4.1"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "5044adb5caa7507fdec629eda8f33d6ddde07997"
|
|
64
64
|
}
|