@percy/core 1.29.4-beta.5 → 1.29.4
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/api.js +3 -3
- package/dist/browser.js +3 -3
- package/dist/discovery.js +1 -1
- package/dist/percy.js +50 -52
- package/dist/queue.js +82 -115
- package/dist/server.js +39 -57
- package/dist/session.js +2 -2
- package/dist/snapshot.js +2 -2
- package/package.json +9 -9
package/dist/api.js
CHANGED
|
@@ -22,7 +22,7 @@ export function createPercyServer(percy, port) {
|
|
|
22
22
|
})
|
|
23
23
|
// general middleware
|
|
24
24
|
.route((req, res, next) => {
|
|
25
|
-
var _percy$testing, _percy$testing4, _percy$
|
|
25
|
+
var _percy$testing, _percy$testing4, _percy$testing5;
|
|
26
26
|
// treat all request bodies as json
|
|
27
27
|
if (req.body) try {
|
|
28
28
|
req.body = JSON.parse(req.body);
|
|
@@ -48,12 +48,12 @@ export function createPercyServer(percy, port) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
// support sabotaging requests in testing mode
|
|
51
|
-
if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0
|
|
51
|
+
if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 || (_percy$testing4 = _percy$testing4.api) === null || _percy$testing4 === void 0 ? void 0 : _percy$testing4[req.url.pathname]) === 'error') {
|
|
52
52
|
next = () => {
|
|
53
53
|
var _percy$testing$build;
|
|
54
54
|
return Promise.reject(new Error(((_percy$testing$build = percy.testing.build) === null || _percy$testing$build === void 0 ? void 0 : _percy$testing$build.error) || 'testing'));
|
|
55
55
|
};
|
|
56
|
-
} else if (((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0
|
|
56
|
+
} else if (((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 || (_percy$testing5 = _percy$testing5.api) === null || _percy$testing5 === void 0 ? void 0 : _percy$testing5[req.url.pathname]) === 'disconnect') {
|
|
57
57
|
next = () => req.connection.destroy();
|
|
58
58
|
}
|
|
59
59
|
|
package/dist/browser.js
CHANGED
|
@@ -182,7 +182,7 @@ export class Browser extends EventEmitter {
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
// close the socket connection
|
|
185
|
-
(_this$ws2 = this.ws) === null || _this$ws2 === void 0
|
|
185
|
+
(_this$ws2 = this.ws) === null || _this$ws2 === void 0 || _this$ws2.close();
|
|
186
186
|
|
|
187
187
|
// wait for the browser to close
|
|
188
188
|
return this._closed;
|
|
@@ -278,12 +278,12 @@ export class Browser extends EventEmitter {
|
|
|
278
278
|
// remove the old session reference when detached from a target
|
|
279
279
|
let session = this.sessions.get(data.params.sessionId);
|
|
280
280
|
this.sessions.delete(data.params.sessionId);
|
|
281
|
-
session === null || session === void 0
|
|
281
|
+
session === null || session === void 0 || session._handleClose();
|
|
282
282
|
}
|
|
283
283
|
if (data.sessionId) {
|
|
284
284
|
// message was for a specific session that sent it
|
|
285
285
|
let session = this.sessions.get(data.sessionId);
|
|
286
|
-
session === null || session === void 0
|
|
286
|
+
session === null || session === void 0 || session._handleMessage(data);
|
|
287
287
|
} else if (data.id && this.#callbacks.has(data.id)) {
|
|
288
288
|
// resolve or reject a pending promise created with #send()
|
|
289
289
|
let callback = this.#callbacks.get(data.id);
|
package/dist/discovery.js
CHANGED
|
@@ -196,7 +196,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
|
|
|
196
196
|
mobile,
|
|
197
197
|
captureForDevices
|
|
198
198
|
} = options;
|
|
199
|
-
let cookies = parseCookies(snapshot === null || snapshot === void 0
|
|
199
|
+
let cookies = parseCookies(snapshot === null || snapshot === void 0 || (_snapshot$domSnapshot = snapshot.domSnapshot) === null || _snapshot$domSnapshot === void 0 ? void 0 : _snapshot$domSnapshot.cookies);
|
|
200
200
|
|
|
201
201
|
// iterate over device to trigger reqeusts and capture other dpr width
|
|
202
202
|
async function* captureResponsiveAssets() {
|
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';
|
|
@@ -22,14 +18,14 @@ import { createPercyServer, createStaticServer } from './api.js';
|
|
|
22
18
|
import { gatherSnapshots, createSnapshotsQueue, validateSnapshotOptions } from './snapshot.js';
|
|
23
19
|
import { discoverSnapshotResources, createDiscoveryQueue } from './discovery.js';
|
|
24
20
|
import { WaitForJob } from './wait-for-job.js';
|
|
21
|
+
const MAX_SUGGESTION_CALLS = 10;
|
|
25
22
|
|
|
26
23
|
// A Percy instance will create a new build when started, handle snapshot creation, asset discovery,
|
|
27
24
|
// and resource uploads, and will finalize the build when stopped. Snapshots are processed
|
|
28
25
|
// concurrently and the build is not finalized until all snapshots have been handled.
|
|
29
26
|
var _discovery = /*#__PURE__*/new WeakMap();
|
|
30
27
|
var _snapshots = /*#__PURE__*/new WeakMap();
|
|
31
|
-
var
|
|
32
|
-
var _proxyEnabled = /*#__PURE__*/new WeakSet();
|
|
28
|
+
var _Percy_brand = /*#__PURE__*/new WeakSet();
|
|
33
29
|
export class Percy {
|
|
34
30
|
// Static shortcut to create and start an instance in one call
|
|
35
31
|
static async start(options) {
|
|
@@ -63,23 +59,17 @@ export class Percy {
|
|
|
63
59
|
server = true,
|
|
64
60
|
port = 5338,
|
|
65
61
|
projectType = null,
|
|
62
|
+
suggestionsCallCounter = 0,
|
|
66
63
|
// options such as `snapshot` and `discovery` that are valid Percy config
|
|
67
64
|
// options which will become accessible via the `.config` property
|
|
68
65
|
..._options
|
|
69
66
|
} = {}) {
|
|
70
67
|
var _config$percy, _config$percy2;
|
|
71
|
-
_classPrivateMethodInitSpec(this,
|
|
72
|
-
_classPrivateMethodInitSpec(this, _displaySuggestionLogs);
|
|
68
|
+
_classPrivateMethodInitSpec(this, _Percy_brand);
|
|
73
69
|
_defineProperty(this, "log", logger('core'));
|
|
74
70
|
_defineProperty(this, "readyState", null);
|
|
75
|
-
_classPrivateFieldInitSpec(this, _discovery,
|
|
76
|
-
|
|
77
|
-
value: null
|
|
78
|
-
});
|
|
79
|
-
_classPrivateFieldInitSpec(this, _snapshots, {
|
|
80
|
-
writable: true,
|
|
81
|
-
value: null
|
|
82
|
-
});
|
|
71
|
+
_classPrivateFieldInitSpec(this, _discovery, null);
|
|
72
|
+
_classPrivateFieldInitSpec(this, _snapshots, null);
|
|
83
73
|
let config = PercyConfig.load({
|
|
84
74
|
overrides: _options,
|
|
85
75
|
path: configFile
|
|
@@ -99,6 +89,7 @@ export class Percy {
|
|
|
99
89
|
this.delayUploads = this.skipUploads || !!delayUploads;
|
|
100
90
|
this.deferUploads = this.skipUploads || !!deferUploads;
|
|
101
91
|
this.labels = labels;
|
|
92
|
+
this.suggestionsCallCounter = suggestionsCallCounter;
|
|
102
93
|
this.client = new PercyClient({
|
|
103
94
|
token,
|
|
104
95
|
clientInfo,
|
|
@@ -108,8 +99,8 @@ export class Percy {
|
|
|
108
99
|
});
|
|
109
100
|
if (server) this.server = createPercyServer(this, port);
|
|
110
101
|
this.browser = new Browser(this);
|
|
111
|
-
_classPrivateFieldSet(
|
|
112
|
-
_classPrivateFieldSet(
|
|
102
|
+
_classPrivateFieldSet(_discovery, this, createDiscoveryQueue(this));
|
|
103
|
+
_classPrivateFieldSet(_snapshots, this, createSnapshotsQueue(this));
|
|
113
104
|
|
|
114
105
|
// generator methods are wrapped to autorun and return promises
|
|
115
106
|
for (let m of ['start', 'stop', 'flush', 'idle', 'snapshot', 'upload']) {
|
|
@@ -162,10 +153,10 @@ export class Percy {
|
|
|
162
153
|
let {
|
|
163
154
|
concurrency
|
|
164
155
|
} = this.config.discovery;
|
|
165
|
-
|
|
156
|
+
_classPrivateFieldGet(_discovery, this).set({
|
|
166
157
|
concurrency
|
|
167
158
|
});
|
|
168
|
-
|
|
159
|
+
_classPrivateFieldGet(_snapshots, this).set({
|
|
169
160
|
concurrency
|
|
170
161
|
});
|
|
171
162
|
return this.config;
|
|
@@ -185,9 +176,9 @@ export class Percy {
|
|
|
185
176
|
const detectProxy = detectSystemProxyAndLog(this.config.percy.useSystemProxy);
|
|
186
177
|
if (this.config.percy.useSystemProxy) await detectProxy;
|
|
187
178
|
// start the snapshots queue immediately when not delayed or deferred
|
|
188
|
-
if (!this.delayUploads && !this.deferUploads) yield
|
|
179
|
+
if (!this.delayUploads && !this.deferUploads) yield _classPrivateFieldGet(_snapshots, this).start();
|
|
189
180
|
// do not start the discovery queue when not needed
|
|
190
|
-
if (!this.skipDiscovery) yield
|
|
181
|
+
if (!this.skipDiscovery) yield _classPrivateFieldGet(_discovery, this).start();
|
|
191
182
|
// start a local API server for SDK communication
|
|
192
183
|
if (this.server) yield this.server.listen();
|
|
193
184
|
if (this.projectType === 'web') {
|
|
@@ -205,8 +196,8 @@ export class Percy {
|
|
|
205
196
|
var _this$server2;
|
|
206
197
|
// on error, close any running server and end queues
|
|
207
198
|
await ((_this$server2 = this.server) === null || _this$server2 === void 0 ? void 0 : _this$server2.close());
|
|
208
|
-
await
|
|
209
|
-
await
|
|
199
|
+
await _classPrivateFieldGet(_discovery, this).end();
|
|
200
|
+
await _classPrivateFieldGet(_snapshots, this).end();
|
|
210
201
|
|
|
211
202
|
// mark this instance as closed unless aborting
|
|
212
203
|
this.readyState = error.name !== 'AbortError' ? 3 : null;
|
|
@@ -225,8 +216,8 @@ export class Percy {
|
|
|
225
216
|
|
|
226
217
|
// Resolves once snapshot and upload queues are idle
|
|
227
218
|
async *idle() {
|
|
228
|
-
yield*
|
|
229
|
-
yield*
|
|
219
|
+
yield* _classPrivateFieldGet(_discovery, this).idle();
|
|
220
|
+
yield* _classPrivateFieldGet(_snapshots, this).idle();
|
|
230
221
|
}
|
|
231
222
|
|
|
232
223
|
// Wait for currently queued snapshots then run and wait for resulting uploads
|
|
@@ -239,13 +230,13 @@ export class Percy {
|
|
|
239
230
|
yield new Promise(r => setImmediate(r));
|
|
240
231
|
|
|
241
232
|
// flush and log progress for discovery before snapshots
|
|
242
|
-
if (!this.skipDiscovery &&
|
|
243
|
-
if (options) yield* yieldAll(options.map(o =>
|
|
233
|
+
if (!this.skipDiscovery && _classPrivateFieldGet(_discovery, this).size) {
|
|
234
|
+
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));
|
|
244
235
|
}
|
|
245
236
|
|
|
246
237
|
// flush and log progress for snapshot uploads
|
|
247
|
-
if (!this.skipUploads &&
|
|
248
|
-
if (options) yield* yieldAll(options.map(o =>
|
|
238
|
+
if (!this.skipUploads && _classPrivateFieldGet(_snapshots, this).size) {
|
|
239
|
+
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));
|
|
249
240
|
}
|
|
250
241
|
}
|
|
251
242
|
|
|
@@ -264,8 +255,8 @@ export class Percy {
|
|
|
264
255
|
|
|
265
256
|
// close queues asap
|
|
266
257
|
if (force) {
|
|
267
|
-
|
|
268
|
-
|
|
258
|
+
_classPrivateFieldGet(_discovery, this).close(true);
|
|
259
|
+
_classPrivateFieldGet(_snapshots, this).close(true);
|
|
269
260
|
}
|
|
270
261
|
|
|
271
262
|
// already stopping
|
|
@@ -290,14 +281,14 @@ export class Percy {
|
|
|
290
281
|
}
|
|
291
282
|
|
|
292
283
|
// if dry-running, log the total number of snapshots
|
|
293
|
-
if (this.dryRun &&
|
|
294
|
-
this.log.info(info('Found',
|
|
284
|
+
if (this.dryRun && _classPrivateFieldGet(_snapshots, this).size) {
|
|
285
|
+
this.log.info(info('Found', _classPrivateFieldGet(_snapshots, this).size));
|
|
295
286
|
}
|
|
296
287
|
|
|
297
288
|
// close server and end queues
|
|
298
289
|
await ((_this$server3 = this.server) === null || _this$server3 === void 0 ? void 0 : _this$server3.close());
|
|
299
|
-
await
|
|
300
|
-
await
|
|
290
|
+
await _classPrivateFieldGet(_discovery, this).end();
|
|
291
|
+
await _classPrivateFieldGet(_snapshots, this).end();
|
|
301
292
|
|
|
302
293
|
// mark instance as stopped
|
|
303
294
|
this.readyState = 3;
|
|
@@ -360,7 +351,7 @@ export class Percy {
|
|
|
360
351
|
}
|
|
361
352
|
|
|
362
353
|
// gather snapshots and discover snapshot resources
|
|
363
|
-
yield* discoverSnapshotResources(
|
|
354
|
+
yield* discoverSnapshotResources(_classPrivateFieldGet(_discovery, this), {
|
|
364
355
|
skipDiscovery: this.skipDiscovery,
|
|
365
356
|
dryRun: this.dryRun,
|
|
366
357
|
snapshots: yield* gatherSnapshots(options, {
|
|
@@ -380,7 +371,7 @@ export class Percy {
|
|
|
380
371
|
});
|
|
381
372
|
}
|
|
382
373
|
// push each finished snapshot to the snapshots queue
|
|
383
|
-
|
|
374
|
+
_classPrivateFieldGet(_snapshots, this).push(snapshot);
|
|
384
375
|
});
|
|
385
376
|
} finally {
|
|
386
377
|
var _server;
|
|
@@ -440,9 +431,9 @@ export class Percy {
|
|
|
440
431
|
// return an async generator to allow cancelation
|
|
441
432
|
return async function* () {
|
|
442
433
|
try {
|
|
443
|
-
return yield* yieldTo(
|
|
434
|
+
return yield* yieldTo(_classPrivateFieldGet(_snapshots, this).push(options));
|
|
444
435
|
} catch (error) {
|
|
445
|
-
|
|
436
|
+
_classPrivateFieldGet(_snapshots, this).cancel(options);
|
|
446
437
|
// Detecting and suggesting fix for errors;
|
|
447
438
|
await this.suggestionsForFix(error.message);
|
|
448
439
|
throw error;
|
|
@@ -456,9 +447,9 @@ export class Percy {
|
|
|
456
447
|
return tokenType !== 'web';
|
|
457
448
|
}
|
|
458
449
|
syncMode(options) {
|
|
459
|
-
var _this$config
|
|
450
|
+
var _this$config;
|
|
460
451
|
let syncMode = false;
|
|
461
|
-
if ((_this$config = this.config) !== null && _this$config !== void 0 && (_this$config
|
|
452
|
+
if ((_this$config = this.config) !== null && _this$config !== void 0 && (_this$config = _this$config.snapshot) !== null && _this$config !== void 0 && _this$config.sync) syncMode = true;
|
|
462
453
|
if (options !== null && options !== void 0 && options.sync) syncMode = true;
|
|
463
454
|
if ((options === null || options === void 0 ? void 0 : options.sync) === false) syncMode = false;
|
|
464
455
|
if ((this.skipUploads || this.deferUploads || this.delayUploads) && syncMode) {
|
|
@@ -483,16 +474,16 @@ export class Percy {
|
|
|
483
474
|
let containsSnapshotTaken = false;
|
|
484
475
|
logger.query(item => {
|
|
485
476
|
var _item$message, _item$message2, _item$message3;
|
|
486
|
-
isPercyStarted || (isPercyStarted = item === null || item === void 0
|
|
487
|
-
containsSnapshotTaken || (containsSnapshotTaken = item === null || item === void 0
|
|
477
|
+
isPercyStarted || (isPercyStarted = item === null || item === void 0 || (_item$message = item.message) === null || _item$message === void 0 ? void 0 : _item$message.includes('Percy has started'));
|
|
478
|
+
containsSnapshotTaken || (containsSnapshotTaken = item === null || item === void 0 || (_item$message2 = item.message) === null || _item$message2 === void 0 ? void 0 : _item$message2.includes('Snapshot taken'));
|
|
488
479
|
|
|
489
480
|
// This case happens when you directly upload it using cli-upload
|
|
490
|
-
containsSnapshotTaken || (containsSnapshotTaken = item === null || item === void 0
|
|
481
|
+
containsSnapshotTaken || (containsSnapshotTaken = item === null || item === void 0 || (_item$message3 = item.message) === null || _item$message3 === void 0 ? void 0 : _item$message3.includes('Snapshot uploaded'));
|
|
491
482
|
return item;
|
|
492
483
|
});
|
|
493
484
|
if (isPercyStarted && !containsSnapshotTaken) {
|
|
494
485
|
// This is the case for No snapshot command called
|
|
495
|
-
|
|
486
|
+
_assertClassBrand(_Percy_brand, this, _displaySuggestionLogs).call(this, [{
|
|
496
487
|
failure_reason: 'Snapshot command was not called',
|
|
497
488
|
reason_message: 'Snapshot Command was not called. please check your CI for errors',
|
|
498
489
|
suggestion: 'Try using percy snapshot command to take snapshots',
|
|
@@ -502,15 +493,22 @@ export class Percy {
|
|
|
502
493
|
}
|
|
503
494
|
async suggestionsForFix(errors, options = {}) {
|
|
504
495
|
try {
|
|
496
|
+
this.suggestionsCallCounter++;
|
|
497
|
+
if (this.suggestionsCallCounter > MAX_SUGGESTION_CALLS) {
|
|
498
|
+
if (this.suggestionsCallCounter === MAX_SUGGESTION_CALLS + 1) {
|
|
499
|
+
this.log.debug('Rate limit exceeded for Maximum allowed suggestions per build.');
|
|
500
|
+
}
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
505
503
|
const suggestionResponse = await this.client.getErrorAnalysis(errors);
|
|
506
|
-
|
|
504
|
+
_assertClassBrand(_Percy_brand, this, _displaySuggestionLogs).call(this, suggestionResponse, options);
|
|
507
505
|
} catch (e) {
|
|
508
506
|
// Common error code for Proxy issues
|
|
509
507
|
const PROXY_CODES = ['ECONNREFUSED', 'ECONNRESET', 'EHOSTUNREACH'];
|
|
510
508
|
if (!!e.code && PROXY_CODES.includes(e.code)) {
|
|
511
509
|
// This can be due to proxy issue
|
|
512
510
|
this.log.error('percy.io might not be reachable, check network connection, proxy and ensure that percy.io is whitelisted.');
|
|
513
|
-
if (!
|
|
511
|
+
if (!_assertClassBrand(_Percy_brand, this, _proxyEnabled).call(this)) {
|
|
514
512
|
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');
|
|
515
513
|
}
|
|
516
514
|
}
|
|
@@ -549,7 +547,7 @@ export class Percy {
|
|
|
549
547
|
}
|
|
550
548
|
}
|
|
551
549
|
}
|
|
552
|
-
function
|
|
550
|
+
function _displaySuggestionLogs(suggestions, options = {}) {
|
|
553
551
|
if (!(suggestions !== null && suggestions !== void 0 && suggestions.length)) return;
|
|
554
552
|
suggestions.forEach(item => {
|
|
555
553
|
const failure = item === null || item === void 0 ? void 0 : item.failure_reason;
|
|
@@ -566,13 +564,13 @@ function _displaySuggestionLogs2(suggestions, options = {}) {
|
|
|
566
564
|
this.log.warn(`Suggestion: ${suggestion}`);
|
|
567
565
|
if ((referenceDocLinks === null || referenceDocLinks === void 0 ? void 0 : referenceDocLinks.length) > 0) {
|
|
568
566
|
this.log.warn('Refer to the below Doc Links for the same');
|
|
569
|
-
referenceDocLinks === null || referenceDocLinks === void 0
|
|
567
|
+
referenceDocLinks === null || referenceDocLinks === void 0 || referenceDocLinks.forEach(_docLink => {
|
|
570
568
|
this.log.warn(`* ${_docLink}`);
|
|
571
569
|
});
|
|
572
570
|
}
|
|
573
571
|
});
|
|
574
572
|
}
|
|
575
|
-
function
|
|
573
|
+
function _proxyEnabled() {
|
|
576
574
|
return !!(getProxy({
|
|
577
575
|
protocol: 'https:'
|
|
578
576
|
}) || 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 =
|
|
151
|
-
task === null || task === void 0
|
|
152
|
-
let queued = _classPrivateFieldGet(
|
|
153
|
-
let pending = _classPrivateFieldGet(
|
|
120
|
+
let task = _assertClassBrand(_Queue_brand, this, _find).call(this, item);
|
|
121
|
+
task === null || task === void 0 || task.ctrl.abort();
|
|
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 || _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
|
|
246
|
-
let starting = ((
|
|
247
|
-
return !starting && !_classPrivateFieldGet(
|
|
211
|
+
var _classPrivateFieldGet6;
|
|
212
|
+
callback === null || callback === 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,18 +293,18 @@ 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
|
-
callback === null || callback === void 0
|
|
307
|
+
callback === null || callback === void 0 || callback(position);
|
|
341
308
|
return !position;
|
|
342
309
|
}, {
|
|
343
310
|
idle: 10
|
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/dist/session.js
CHANGED
|
@@ -16,7 +16,7 @@ export class Session extends EventEmitter {
|
|
|
16
16
|
this.type = params.targetInfo.type;
|
|
17
17
|
this.isDocument = this.type === 'page' || this.type === 'iframe';
|
|
18
18
|
this.parent = browser.sessions.get(parentId);
|
|
19
|
-
(_this$parent = this.parent) === null || _this$parent === void 0
|
|
19
|
+
(_this$parent = this.parent) === null || _this$parent === void 0 || _this$parent.children.set(this.sessionId, this);
|
|
20
20
|
this.on('Inspector.targetCrashed', this._handleTargetCrashed);
|
|
21
21
|
}
|
|
22
22
|
async close() {
|
|
@@ -79,7 +79,7 @@ export class Session extends EventEmitter {
|
|
|
79
79
|
}));
|
|
80
80
|
}
|
|
81
81
|
this.#callbacks.clear();
|
|
82
|
-
(_this$parent2 = this.parent) === null || _this$parent2 === void 0
|
|
82
|
+
(_this$parent2 = this.parent) === null || _this$parent2 === void 0 || _this$parent2.children.delete(this.sessionId);
|
|
83
83
|
this.browser = null;
|
|
84
84
|
}
|
|
85
85
|
_handleTargetCrashed = () => {
|
package/dist/snapshot.js
CHANGED
|
@@ -476,7 +476,7 @@ export function createSnapshotsQueue(percy) {
|
|
|
476
476
|
})
|
|
477
477
|
// handle possible build errors returned by the API
|
|
478
478
|
.handle('error', async (snapshot, error) => {
|
|
479
|
-
var _error$response, _error$response2
|
|
479
|
+
var _error$response, _error$response2;
|
|
480
480
|
let result = {
|
|
481
481
|
...snapshot,
|
|
482
482
|
error
|
|
@@ -496,7 +496,7 @@ export function createSnapshotsQueue(percy) {
|
|
|
496
496
|
build.failed = true;
|
|
497
497
|
queue.close(true);
|
|
498
498
|
}
|
|
499
|
-
let errors = (_error$response2 = error.response) === null || _error$response2 === void 0
|
|
499
|
+
let errors = (_error$response2 = error.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.body) === null || _error$response2 === void 0 ? void 0 : _error$response2.errors;
|
|
500
500
|
let duplicate = (errors === null || errors === void 0 ? void 0 : errors.length) > 1 && errors[1].detail.includes('must be unique');
|
|
501
501
|
if (duplicate) {
|
|
502
502
|
if (process.env.PERCY_IGNORE_DUPLICATES !== 'true') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/core",
|
|
3
|
-
"version": "1.29.4
|
|
3
|
+
"version": "1.29.4",
|
|
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": "latest"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=14"
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"test:types": "tsd"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@percy/client": "1.29.4
|
|
47
|
-
"@percy/config": "1.29.4
|
|
48
|
-
"@percy/dom": "1.29.4
|
|
49
|
-
"@percy/logger": "1.29.4
|
|
50
|
-
"@percy/webdriver-utils": "1.29.4
|
|
46
|
+
"@percy/client": "1.29.4",
|
|
47
|
+
"@percy/config": "1.29.4",
|
|
48
|
+
"@percy/dom": "1.29.4",
|
|
49
|
+
"@percy/logger": "1.29.4",
|
|
50
|
+
"@percy/webdriver-utils": "1.29.4",
|
|
51
51
|
"content-disposition": "^0.5.4",
|
|
52
52
|
"cross-spawn": "^7.0.3",
|
|
53
53
|
"extract-zip": "^2.0.1",
|
|
54
54
|
"fast-glob": "^3.2.11",
|
|
55
|
-
"micromatch": "^4.0.
|
|
55
|
+
"micromatch": "^4.0.8",
|
|
56
56
|
"mime-types": "^2.1.34",
|
|
57
57
|
"pako": "^2.1.0",
|
|
58
58
|
"path-to-regexp": "^6.3.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"ws": "^8.17.1",
|
|
61
61
|
"yaml": "^2.4.1"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "17468058cf55d75557451a81e82b0d6fd5c0e26b"
|
|
64
64
|
}
|