@percy/core 1.26.2-beta.0 → 1.26.3-alpha.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/percy.js CHANGED
@@ -1,3 +1,9 @@
1
+ const _excluded = ["loglevel", "delayUploads", "deferUploads", "skipUploads", "skipDiscovery", "dryRun", "testing", "config", "token", "clientInfo", "environmentInfo", "server", "port", "projectType"],
2
+ _excluded2 = ["percy"],
3
+ _excluded3 = ["clientInfo", "environmentInfo"],
4
+ _excluded4 = ["clientInfo", "environmentInfo"];
5
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
7
  import PercyClient from '@percy/client';
2
8
  import PercyConfig from '@percy/config';
3
9
  import logger from '@percy/logger';
@@ -22,43 +28,46 @@ export class Percy {
22
28
  await instance.start();
23
29
  return instance;
24
30
  }
25
- constructor({
26
- // initial log level
27
- loglevel,
28
- // process uploads before the next snapshot
29
- delayUploads,
30
- // process uploads after all snapshots
31
- deferUploads,
32
- // run without uploading anything
33
- skipUploads,
34
- // run without asset discovery
35
- skipDiscovery,
36
- // implies `skipUploads` and `skipDiscovery`
37
- dryRun,
38
- // implies `dryRun`, silent logs, and adds extra api endpoints
39
- testing,
40
- // configuration filepath
41
- config: configFile,
42
- // provided to @percy/client
43
- token,
44
- clientInfo = '',
45
- environmentInfo = '',
46
- // snapshot server options
47
- server = true,
48
- port = 5338,
49
- projectType = null,
50
- // options such as `snapshot` and `discovery` that are valid Percy config
51
- // options which will become accessible via the `.config` property
52
- ...options
53
- } = {}) {
31
+ constructor(_ref = {}) {
32
+ var _deferUploads;
54
33
  let {
55
- percy,
56
- ...config
57
- } = PercyConfig.load({
58
- overrides: options,
59
- path: configFile
60
- });
61
- deferUploads ?? (deferUploads = percy === null || percy === void 0 ? void 0 : percy.deferUploads);
34
+ // initial log level
35
+ loglevel,
36
+ // process uploads before the next snapshot
37
+ delayUploads,
38
+ // process uploads after all snapshots
39
+ deferUploads,
40
+ // run without uploading anything
41
+ skipUploads,
42
+ // run without asset discovery
43
+ skipDiscovery,
44
+ // implies `skipUploads` and `skipDiscovery`
45
+ dryRun,
46
+ // implies `dryRun`, silent logs, and adds extra api endpoints
47
+ testing,
48
+ // configuration filepath
49
+ config: configFile,
50
+ // provided to @percy/client
51
+ token,
52
+ clientInfo = '',
53
+ environmentInfo = '',
54
+ // snapshot server options
55
+ server = true,
56
+ port = 5338,
57
+ projectType = null
58
+ // options such as `snapshot` and `discovery` that are valid Percy config
59
+ // options which will become accessible via the `.config` property
60
+ } = _ref,
61
+ options = _objectWithoutProperties(_ref, _excluded);
62
+ let _PercyConfig$load = PercyConfig.load({
63
+ overrides: options,
64
+ path: configFile
65
+ }),
66
+ {
67
+ percy
68
+ } = _PercyConfig$load,
69
+ config = _objectWithoutProperties(_PercyConfig$load, _excluded2);
70
+ (_deferUploads = deferUploads) !== null && _deferUploads !== void 0 ? _deferUploads : deferUploads = percy === null || percy === void 0 ? void 0 : percy.deferUploads;
62
71
  this.config = config;
63
72
  if (testing) loglevel = 'silent';
64
73
  if (loglevel) this.loglevel(loglevel);
@@ -99,11 +108,12 @@ export class Percy {
99
108
  }
100
109
 
101
110
  // Set client & environment info, and override loaded config options
102
- set({
103
- clientInfo,
104
- environmentInfo,
105
- ...config
106
- }) {
111
+ set(_ref2) {
112
+ let {
113
+ clientInfo,
114
+ environmentInfo
115
+ } = _ref2,
116
+ config = _objectWithoutProperties(_ref2, _excluded3);
107
117
  this.client.addClientInfo(clientInfo);
108
118
  this.client.addEnvironmentInfo(environmentInfo);
109
119
 
@@ -339,10 +349,10 @@ export class Percy {
339
349
  // normalize, migrate, and remove certain properties from validating
340
350
  options = PercyConfig.migrate(options, '/comparison');
341
351
  let {
342
- clientInfo,
343
- environmentInfo,
344
- ...comparison
345
- } = options;
352
+ clientInfo,
353
+ environmentInfo
354
+ } = options,
355
+ comparison = _objectWithoutProperties(options, _excluded4);
346
356
  let errors = PercyConfig.validate(comparison, '/comparison');
347
357
  if (errors) {
348
358
  this.log.warn('Invalid upload options:');
package/dist/queue.js CHANGED
@@ -1,7 +1,9 @@
1
1
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
2
2
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
3
3
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
4
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
7
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
6
8
  function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
7
9
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
@@ -73,7 +75,7 @@ export class Queue {
73
75
  value: null
74
76
  });
75
77
  _defineProperty(this, "readyState", 0);
76
- }
78
+ } // item concurrency
77
79
  // Configure queue properties
78
80
  set({
79
81
  concurrency
@@ -148,25 +150,27 @@ export class Queue {
148
150
 
149
151
  // Returns an item task matching the provided subject.
150
152
 
153
+ // keep track of start and end tasks
154
+
151
155
  // Initialize a starting task or return an existing one.
152
156
  start() {
153
- var _classPrivateFieldGet2;
154
- _classPrivateFieldGet(this, _start) ?? _classPrivateFieldSet(this, _start, deferred({
157
+ var _classPrivateFieldGet2, _classPrivateFieldGet3, _classPrivateFieldGet4;
158
+ (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _start)) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _classPrivateFieldSet(this, _start, deferred({
155
159
  readyState: 1
156
160
  }));
157
- (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _start)).handler ?? (_classPrivateFieldGet2.handler = _classPrivateFieldGet(this, _end) // wait for any ending task to complete first
158
- ? () => _classPrivateFieldGet(this, _end).promise.then(_classPrivateFieldGet(this, _handlers).start) : _classPrivateFieldGet(this, _handlers).start);
161
+ (_classPrivateFieldGet4 = (_classPrivateFieldGet3 = _classPrivateFieldGet(this, _start)).handler) !== null && _classPrivateFieldGet4 !== void 0 ? _classPrivateFieldGet4 : _classPrivateFieldGet3.handler = _classPrivateFieldGet(this, _end) // wait for any ending task to complete first
162
+ ? () => _classPrivateFieldGet(this, _end).promise.then(_classPrivateFieldGet(this, _handlers).start) : _classPrivateFieldGet(this, _handlers).start;
159
163
  return _classPrivateMethodGet(this, _process, _process2).call(this, _classPrivateFieldGet(this, _start)).deferred;
160
164
  }
161
165
 
162
166
  // intialize an ending task or return an existing one
163
167
  end() {
164
- var _classPrivateFieldGet3;
165
- _classPrivateFieldGet(this, _end) ?? _classPrivateFieldSet(this, _end, deferred({
168
+ var _classPrivateFieldGet5, _classPrivateFieldGet6, _classPrivateFieldGet7;
169
+ (_classPrivateFieldGet5 = _classPrivateFieldGet(this, _end)) !== null && _classPrivateFieldGet5 !== void 0 ? _classPrivateFieldGet5 : _classPrivateFieldSet(this, _end, deferred({
166
170
  readyState: 0
167
171
  }));
168
- (_classPrivateFieldGet3 = _classPrivateFieldGet(this, _end)).handler ?? (_classPrivateFieldGet3.handler = _classPrivateFieldGet(this, _start) // wait for any starting task to complete first
169
- ? () => _classPrivateFieldGet(this, _start).promise.then(_classPrivateFieldGet(this, _handlers).end) : _classPrivateFieldGet(this, _handlers).end);
172
+ (_classPrivateFieldGet7 = (_classPrivateFieldGet6 = _classPrivateFieldGet(this, _end)).handler) !== null && _classPrivateFieldGet7 !== void 0 ? _classPrivateFieldGet7 : _classPrivateFieldGet6.handler = _classPrivateFieldGet(this, _start) // wait for any starting task to complete first
173
+ ? () => _classPrivateFieldGet(this, _start).promise.then(_classPrivateFieldGet(this, _handlers).end) : _classPrivateFieldGet(this, _handlers).end;
170
174
  return _classPrivateMethodGet(this, _process, _process2).call(this, _classPrivateFieldGet(this, _end)).deferred;
171
175
  }
172
176
 
@@ -190,9 +194,9 @@ export class Queue {
190
194
 
191
195
  // close a running queue, optionally aborting it
192
196
  close(abort) {
193
- var _classPrivateFieldGet4;
197
+ var _classPrivateFieldGet8;
194
198
  // when starting, state is updated afterwards
195
- if ((_classPrivateFieldGet4 = _classPrivateFieldGet(this, _start)) !== null && _classPrivateFieldGet4 !== void 0 && _classPrivateFieldGet4.pending) _classPrivateFieldGet(this, _start).readyState = 3;
199
+ if ((_classPrivateFieldGet8 = _classPrivateFieldGet(this, _start)) !== null && _classPrivateFieldGet8 !== void 0 && _classPrivateFieldGet8.pending) _classPrivateFieldGet(this, _start).readyState = 3;
196
200
  if (this.readyState < 3) this.readyState = 3;
197
201
  if (abort) this.clear();
198
202
  return this;
@@ -210,10 +214,10 @@ export class Queue {
210
214
 
211
215
  // process a single item task when started
212
216
  process(item) {
213
- var _classPrivateFieldGet5;
217
+ var _classPrivateFieldGet9;
214
218
  let task = _classPrivateMethodGet(this, _find, _find2).call(this, item);
215
219
  if (task && !_classPrivateFieldGet(this, _start)) this.start();
216
- (_classPrivateFieldGet5 = _classPrivateFieldGet(this, _start)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.promise.then(() => _classPrivateMethodGet(this, _process, _process2).call(this, task));
220
+ (_classPrivateFieldGet9 = _classPrivateFieldGet(this, _start)) === null || _classPrivateFieldGet9 === void 0 ? void 0 : _classPrivateFieldGet9.promise.then(() => _classPrivateMethodGet(this, _process, _process2).call(this, task));
217
221
  return task === null || task === void 0 ? void 0 : task.deferred;
218
222
  }
219
223
 
@@ -223,9 +227,9 @@ export class Queue {
223
227
  // callback every 10ms during checks with the current number of pending tasks
224
228
  idle(callback) {
225
229
  return yieldFor(() => {
226
- var _classPrivateFieldGet6;
230
+ var _classPrivateFieldGet10;
227
231
  callback === null || callback === void 0 ? void 0 : callback(_classPrivateFieldGet(this, _pending).size);
228
- let starting = ((_classPrivateFieldGet6 = _classPrivateFieldGet(this, _start)) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.pending) === true;
232
+ let starting = ((_classPrivateFieldGet10 = _classPrivateFieldGet(this, _start)) === null || _classPrivateFieldGet10 === void 0 ? void 0 : _classPrivateFieldGet10.pending) === true;
229
233
  return !starting && !_classPrivateFieldGet(this, _pending).size;
230
234
  }, {
231
235
  idle: 10
@@ -235,14 +239,14 @@ export class Queue {
235
239
  // process items up to the latest queued item, starting the queue if necessary;
236
240
  // returns a generator that yields until the flushed item has finished processing
237
241
  flush(callback) {
238
- let interrupt =
239
- // check for existing interrupts
240
- [..._classPrivateFieldGet(this, _pending)].find(t => t.stop) ?? [..._classPrivateFieldGet(this, _queued)].find(t => t.stop);
242
+ var _find3, _pop, _interrupt$stop;
243
+ let interrupt = // check for existing interrupts
244
+ (_find3 = [..._classPrivateFieldGet(this, _pending)].find(t => t.stop)) !== null && _find3 !== void 0 ? _find3 : [..._classPrivateFieldGet(this, _queued)].find(t => t.stop);
241
245
 
242
246
  // get the latest queued or pending task to track
243
- let flush = [..._classPrivateFieldGet(this, _queued)].pop() ?? [..._classPrivateFieldGet(this, _pending)].pop();
247
+ let flush = (_pop = [..._classPrivateFieldGet(this, _queued)].pop()) !== null && _pop !== void 0 ? _pop : [..._classPrivateFieldGet(this, _pending)].pop();
244
248
  // determine if the queue should be stopped after flushing
245
- if (flush) flush.stop = (interrupt === null || interrupt === void 0 ? void 0 : interrupt.stop) ?? this.readyState < 2;
249
+ if (flush) flush.stop = (_interrupt$stop = interrupt === null || interrupt === void 0 ? void 0 : interrupt.stop) !== null && _interrupt$stop !== void 0 ? _interrupt$stop : this.readyState < 2;
246
250
  // remove the old interrupt to avoid stopping early
247
251
  if (interrupt) delete interrupt.stop;
248
252
  // start the queue if not started
@@ -263,6 +267,7 @@ function _dequeue2() {
263
267
  return _classPrivateMethodGet(this, _process, _process2).call(this, task);
264
268
  }
265
269
  function _find2(subject) {
270
+ var _find4;
266
271
  let find = _classPrivateFieldGet(this, _handlers).find
267
272
  // use any configured find handler to match items
268
273
  ? ({
@@ -270,9 +275,8 @@ function _find2(subject) {
270
275
  }) => _classPrivateFieldGet(this, _handlers).find(subject, item) : ({
271
276
  item
272
277
  }) => subject === item;
273
- return (
274
- // look at queued then pending items
275
- [..._classPrivateFieldGet(this, _queued)].find(find) ?? [..._classPrivateFieldGet(this, _pending)].find(find)
278
+ return (// look at queued then pending items
279
+ (_find4 = [..._classPrivateFieldGet(this, _queued)].find(find)) !== null && _find4 !== void 0 ? _find4 : [..._classPrivateFieldGet(this, _pending)].find(find)
276
280
  );
277
281
  }
278
282
  function _process2(task) {
@@ -299,7 +303,7 @@ function _process2(task) {
299
303
  // clean up internal tasks after ending
300
304
  if (!this.readyState) _classPrivateFieldSet(this, _start, _classPrivateFieldSet(this, _end, null));
301
305
  // resolve or reject the deferred task promise
302
- task[err ? 'reject' : 'resolve'](err ?? val);
306
+ task[err ? 'reject' : 'resolve'](err !== null && err !== void 0 ? err : val);
303
307
  // keep dequeuing when running
304
308
  if (this.readyState === 2) this.run();
305
309
  // mark pending task done
@@ -310,8 +314,8 @@ function _process2(task) {
310
314
  async function* _until2(task, callback) {
311
315
  try {
312
316
  yield* yieldFor(() => {
313
- var _classPrivateFieldGet7;
314
- if ((_classPrivateFieldGet7 = _classPrivateFieldGet(this, _start)) !== null && _classPrivateFieldGet7 !== void 0 && _classPrivateFieldGet7.pending) return false;
317
+ var _classPrivateFieldGet11, _queued2, _pending2;
318
+ if ((_classPrivateFieldGet11 = _classPrivateFieldGet(this, _start)) !== null && _classPrivateFieldGet11 !== void 0 && _classPrivateFieldGet11.pending) return false;
315
319
  let queued,
316
320
  pending = _classPrivateFieldGet(this, _pending).size;
317
321
  // calculate the position within queued when not pending
@@ -319,7 +323,7 @@ async function* _until2(task, callback) {
319
323
  // calculate the position within pending when not stopping
320
324
  if (!(task !== null && task !== void 0 && task.stop) && (task === null || task === void 0 ? void 0 : task.pending) != null) pending = positionOf(_classPrivateFieldGet(this, _pending), task);
321
325
  // call the callback and return true when not queued or pending
322
- let position = (queued ?? 0) + (pending ?? 0);
326
+ let position = ((_queued2 = queued) !== null && _queued2 !== void 0 ? _queued2 : 0) + ((_pending2 = pending) !== null && _pending2 !== void 0 ? _pending2 : 0);
323
327
  callback === null || callback === void 0 ? void 0 : callback(position);
324
328
  return !position;
325
329
  }, {
package/dist/server.js CHANGED
@@ -1,3 +1,6 @@
1
+ const _excluded = ["serve", "port", "baseUrl"];
2
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
4
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
2
5
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
3
6
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
@@ -159,8 +162,8 @@ export class Server extends http.Server {
159
162
 
160
163
  // return the listening port or any default port
161
164
  get port() {
162
- var _super$address;
163
- return ((_super$address = super.address()) === null || _super$address === void 0 ? void 0 : _super$address.port) ?? _classPrivateFieldGet(this, _defaultPort);
165
+ var _super$address$port, _super$address;
166
+ return (_super$address$port = (_super$address = super.address()) === null || _super$address === void 0 ? void 0 : _super$address.port) !== null && _super$address$port !== void 0 ? _super$address$port : _classPrivateFieldGet(this, _defaultPort);
164
167
  }
165
168
 
166
169
  // return a string representation of the server address
@@ -189,6 +192,8 @@ export class Server extends http.Server {
189
192
 
190
193
  // initial routes include cors and 404 handling
191
194
 
195
+ // adds a route in the correct priority order
196
+
192
197
  // set request routing and handling for pathnames and methods
193
198
  route(method, pathname, handle) {
194
199
  if (arguments.length === 1) [handle, method] = [method];
@@ -251,8 +256,9 @@ function _route2(route) {
251
256
  return this;
252
257
  }
253
258
  async function _handleRequest2(req, res) {
259
+ var _res$req;
254
260
  // support node < 15.7.0
255
- res.req ?? (res.req = req);
261
+ (_res$req = res.req) !== null && _res$req !== void 0 ? _res$req : res.req = req;
256
262
  try {
257
263
  // invoke routes like middleware
258
264
  await async function cont(routes, i = 0) {
@@ -299,9 +305,9 @@ function createRewriter(rewrites = [], cb) {
299
305
  apply: r => toPath(r.params)
300
306
  };
301
307
  })).reduceRight((next, rule) => pathname => {
302
- var _rule$match;
308
+ var _rule$match, _rule$match2;
303
309
  // compose all rewrites into a single function
304
- let result = ((_rule$match = rule.match) === null || _rule$match === void 0 ? void 0 : _rule$match.call(rule, pathname)) ?? pathname;
310
+ let result = (_rule$match = (_rule$match2 = rule.match) === null || _rule$match2 === void 0 ? void 0 : _rule$match2.call(rule, pathname)) !== null && _rule$match !== void 0 ? _rule$match : pathname;
305
311
  if (result) pathname = rule.apply(result);
306
312
  return next(pathname);
307
313
  }, p => p);
@@ -331,7 +337,8 @@ async function getFile(root, pathname, cleanUrls) {
331
337
  // returns the start and end of a byte range or undefined if unable to parse
332
338
  const RANGE_REGEXP = /^bytes=(\d*)?-(\d*)?(?:\b|$)/;
333
339
  function parseByteRange(range, size) {
334
- let [, start, end = size] = (range === null || range === void 0 ? void 0 : range.match(RANGE_REGEXP)) ?? [0, 0, 0];
340
+ var _range$match;
341
+ let [, start, end = size] = (_range$match = range === null || range === void 0 ? void 0 : range.match(RANGE_REGEXP)) !== null && _range$match !== void 0 ? _range$match : [0, 0, 0];
335
342
  start = Math.max(parseInt(start, 10), 0);
336
343
  end = Math.min(parseInt(end, 10), size - 1);
337
344
  if (isNaN(start)) [start, end] = [size - end, size - 1];
@@ -344,11 +351,11 @@ function parseByteRange(range, size) {
344
351
  // shorthand function for creating a new server with specific options
345
352
  export function createServer(options = {}) {
346
353
  let {
347
- serve,
348
- port,
349
- baseUrl = '/',
350
- ...opts
351
- } = options;
354
+ serve,
355
+ port,
356
+ baseUrl = '/'
357
+ } = options,
358
+ opts = _objectWithoutProperties(options, _excluded);
352
359
  let server = new Server({
353
360
  port
354
361
  });
package/dist/session.js CHANGED
@@ -89,7 +89,8 @@ export class Session extends EventEmitter {
89
89
 
90
90
  /* istanbul ignore next: encountered during closing races */
91
91
  _handleClosedError = error => {
92
- if (!(error.message ?? error).endsWith(this.closedReason)) {
92
+ var _error$message;
93
+ if (!((_error$message = error.message) !== null && _error$message !== void 0 ? _error$message : error).endsWith(this.closedReason)) {
93
94
  this.log.debug(error, this.meta);
94
95
  }
95
96
  };
package/dist/snapshot.js CHANGED
@@ -1,3 +1,16 @@
1
+ const _excluded = ["include", "exclude"],
2
+ _excluded2 = ["prefix", "suffix"],
3
+ _excluded3 = ["clientInfo", "environmentInfo", "snapshots"],
4
+ _excluded4 = ["resources"],
5
+ _excluded5 = ["resources", "widths", "width"],
6
+ _excluded6 = ["resources"];
7
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
13
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
14
  import logger from '@percy/logger';
2
15
  import PercyConfig from '@percy/config';
3
16
  import micromatch from 'micromatch';
@@ -70,15 +83,18 @@ function mapSnapshotOptions(snapshots, context) {
70
83
  if (!(snapshots !== null && snapshots !== void 0 && snapshots.length)) return [];
71
84
 
72
85
  // reduce options into a single function
73
- let applyOptions = [].concat((context === null || context === void 0 ? void 0 : context.options) || []).reduceRight((next, {
74
- include,
75
- exclude,
76
- ...opts
77
- }) => snap => next(
78
- // assign additional options to included snaphots
79
- snapshotMatches(snap, include, exclude) ? Object.assign(snap, opts) : snap), snap => getSnapshotOptions(snap, context));
80
-
81
- // reduce snapshots with overrides
86
+ let applyOptions = [].concat((context === null || context === void 0 ? void 0 : context.options) || []).reduceRight((next, _ref) => {
87
+ let {
88
+ include,
89
+ exclude
90
+ } = _ref,
91
+ opts = _objectWithoutProperties(_ref, _excluded);
92
+ return snap => next(
93
+ // assign additional options to included snaphots
94
+ snapshotMatches(snap, include, exclude) ? Object.assign(snap, opts) : snap);
95
+ }, snap => getSnapshotOptions(snap, context));
96
+
97
+ // reduce snapshots with options
82
98
  return snapshots.reduce((acc, snapshot) => {
83
99
  var _snapshot;
84
100
  // transform snapshot URL shorthand into an object
@@ -109,12 +125,11 @@ function getSnapshotOptions(options, {
109
125
  discovery: {
110
126
  allowedHostnames: [validURL(options.url).hostname]
111
127
  },
112
- meta: {
113
- ...meta,
128
+ meta: _objectSpread(_objectSpread({}, meta), {}, {
114
129
  snapshot: {
115
130
  name: options.name
116
131
  }
117
- }
132
+ })
118
133
  }, config.snapshot, {
119
134
  // only specific discovery options are used per-snapshot
120
135
  discovery: {
@@ -141,20 +156,19 @@ function getSnapshotOptions(options, {
141
156
  return Array.isArray(next) || typeof next !== 'object' ? [path.concat('beforeSnapshot'), next] : [path];
142
157
  case 'discovery.disallowedHostnames':
143
158
  // prevent disallowing the root hostname
144
- return [path, !((_next2 = next) !== null && _next2 !== void 0 && _next2.length) ? prev : (prev ?? []).concat(next).filter(h => !hostnameMatches(h, options.url))];
159
+ return [path, !((_next2 = next) !== null && _next2 !== void 0 && _next2.length) ? prev : (prev !== null && prev !== void 0 ? prev : []).concat(next).filter(h => !hostnameMatches(h, options.url))];
145
160
  }
146
161
 
147
162
  // ensure additional snapshots have complete names
148
163
  if (path[0] === 'additionalSnapshots' && path.length === 2) {
149
164
  let {
150
- prefix = '',
151
- suffix = '',
152
- ...n
153
- } = next;
154
- next = {
155
- name: `${prefix}${options.name}${suffix}`,
156
- ...n
157
- };
165
+ prefix = '',
166
+ suffix = ''
167
+ } = next,
168
+ n = _objectWithoutProperties(next, _excluded2);
169
+ next = _objectSpread({
170
+ name: `${prefix}${options.name}${suffix}`
171
+ }, n);
158
172
  return [path, next];
159
173
  }
160
174
  });
@@ -164,18 +178,19 @@ function getSnapshotOptions(options, {
164
178
  // properties. Eagerly throws an error when missing a URL for any snapshot, and warns about all
165
179
  // other invalid options which are also scrubbed from the returned migrated options.
166
180
  export function validateSnapshotOptions(options) {
167
- var _migrated$baseUrl, _migrated$domSnapshot;
181
+ var _migrated$baseUrl, _migrated$domSnapshot, _migrated$snapshots;
168
182
  let log = logger('core:snapshot');
169
183
 
170
184
  // decide which schema to validate against
171
185
  let schema = ['domSnapshot', 'dom-snapshot', 'dom_snapshot'].some(k => k in options) && '/snapshot/dom' || 'url' in options && '/snapshot' || 'sitemap' in options && '/snapshot/sitemap' || 'serve' in options && '/snapshot/server' || 'snapshots' in options && '/snapshot/list' || '/snapshot';
172
- let {
173
- // normalize, migrate, and remove certain properties from validating
174
- clientInfo,
175
- environmentInfo,
176
- snapshots,
177
- ...migrated
178
- } = PercyConfig.migrate(options, schema);
186
+ let _PercyConfig$migrate = PercyConfig.migrate(options, schema),
187
+ {
188
+ // normalize, migrate, and remove certain properties from validating
189
+ clientInfo,
190
+ environmentInfo,
191
+ snapshots
192
+ } = _PercyConfig$migrate,
193
+ migrated = _objectWithoutProperties(_PercyConfig$migrate, _excluded3);
179
194
 
180
195
  // maintain a trailing slash for base URLs to normalize them
181
196
  if (((_migrated$baseUrl = migrated.baseUrl) === null || _migrated$baseUrl === void 0 ? void 0 : _migrated$baseUrl.endsWith('/')) === false) migrated.baseUrl += '/';
@@ -211,18 +226,18 @@ export function validateSnapshotOptions(options) {
211
226
  // add back the snapshots function if there was one
212
227
  if (typeof snapshots === 'function') migrated.snapshots = snapshots;
213
228
  // add back an empty array if all server snapshots were scrubbed
214
- if ('serve' in options && 'snapshots' in options) migrated.snapshots ?? (migrated.snapshots = []);
215
- return {
229
+ if ('serve' in options && 'snapshots' in options) (_migrated$snapshots = migrated.snapshots) !== null && _migrated$snapshots !== void 0 ? _migrated$snapshots : migrated.snapshots = [];
230
+ return _objectSpread({
216
231
  clientInfo,
217
- environmentInfo,
218
- ...migrated
219
- };
232
+ environmentInfo
233
+ }, migrated);
220
234
  }
221
235
 
222
236
  // Fetches a sitemap and parses it into a list of URLs for taking snapshots. Duplicate URLs,
223
237
  // including a trailing slash, are removed from the resulting list.
224
238
  async function getSitemapSnapshots(options) {
225
239
  return request(options.sitemap, (body, res) => {
240
+ var _body$match;
226
241
  // validate sitemap content-type
227
242
  let [contentType] = res.headers['content-type'].split(';');
228
243
  if (!/^(application|text)\/xml$/.test(contentType)) {
@@ -230,7 +245,7 @@ async function getSitemapSnapshots(options) {
230
245
  }
231
246
 
232
247
  // parse XML content into a list of URLs
233
- let urls = body.match(/(?<=<loc>)(.*?)(?=<\/loc>)/ig) ?? [];
248
+ let urls = (_body$match = body.match(/(?<=<loc>)(.*?)(?=<\/loc>)/ig)) !== null && _body$match !== void 0 ? _body$match : [];
234
249
 
235
250
  // filter out duplicate URLs that differ by a trailing slash
236
251
  return urls.filter((url, i) => {
@@ -259,10 +274,7 @@ export async function* gatherSnapshots(options, context) {
259
274
  }
260
275
 
261
276
  // map snapshots with snapshot options
262
- snapshots = mapSnapshotOptions(snapshots, {
263
- ...options,
264
- ...context
265
- });
277
+ snapshots = mapSnapshotOptions(snapshots, _objectSpread(_objectSpread({}, options), context));
266
278
  if (!snapshots.length) throw new Error('No snapshots found');
267
279
  return snapshots;
268
280
  }
@@ -271,15 +283,15 @@ export async function* gatherSnapshots(options, context) {
271
283
  // resources are deduplicated by widths, and all other resources are deduplicated by their URL.
272
284
  function mergeSnapshotOptions(prev = {}, next) {
273
285
  let {
274
- resources: oldResources = [],
275
- ...existing
276
- } = prev;
286
+ resources: oldResources = []
287
+ } = prev,
288
+ existing = _objectWithoutProperties(prev, _excluded4);
277
289
  let {
278
- resources: newResources = [],
279
- widths = [],
280
- width,
281
- ...incoming
282
- } = next;
290
+ resources: newResources = [],
291
+ widths = [],
292
+ width
293
+ } = next,
294
+ incoming = _objectWithoutProperties(next, _excluded5);
283
295
 
284
296
  // prioritize singular widths over mutilple widths
285
297
  widths = width ? [width] : widths;
@@ -290,8 +302,7 @@ function mergeSnapshotOptions(prev = {}, next) {
290
302
  if (!resource.root && all.some(r => r.url === resource.url)) return all;
291
303
  resource.widths = resource.widths.filter(w => !widths.includes(w));
292
304
  return all.concat(resource);
293
- }, newResources.map(r => ({
294
- ...r,
305
+ }, newResources.map(r => _objectSpread(_objectSpread({}, r), {}, {
295
306
  widths
296
307
  })));
297
308
 
@@ -394,10 +405,11 @@ export function createSnapshotsQueue(percy) {
394
405
  return mergeSnapshotOptions(existing, snapshot);
395
406
  })
396
407
  // send snapshots to be uploaded to the build
397
- .handle('task', async function* ({
398
- resources,
399
- ...snapshot
400
- }) {
408
+ .handle('task', async function* (_ref2) {
409
+ let {
410
+ resources
411
+ } = _ref2,
412
+ snapshot = _objectWithoutProperties(_ref2, _excluded6);
401
413
  let {
402
414
  name,
403
415
  meta
@@ -410,18 +422,16 @@ export function createSnapshotsQueue(percy) {
410
422
  let send = 'tag' in snapshot ? 'sendComparison' : 'sendSnapshot';
411
423
  let response = yield percy.client[send](build.id, snapshot);
412
424
  if (percy.deferUploads) percy.log.info(`Snapshot uploaded: ${name}`, meta);
413
- return {
414
- ...snapshot,
425
+ return _objectSpread(_objectSpread({}, snapshot), {}, {
415
426
  response
416
- };
427
+ });
417
428
  })
418
429
  // handle possible build errors returned by the API
419
430
  .handle('error', (snapshot, error) => {
420
431
  var _error$response;
421
- let result = {
422
- ...snapshot,
432
+ let result = _objectSpread(_objectSpread({}, snapshot), {}, {
423
433
  error
424
- };
434
+ });
425
435
  let {
426
436
  name,
427
437
  meta