@percy/core 1.10.1 → 1.10.3

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 CHANGED
@@ -10,39 +10,9 @@ export function createPercyServer(percy, port) {
10
10
  let pkg = getPackageJSON(import.meta.url);
11
11
  let server = Server.createServer({
12
12
  port
13
- }) // facilitate logger websocket connections
14
- .websocket('/(logger)?', ws => {
15
- var _percy$testing, _percy$testing2;
16
-
17
- // support sabotaging remote logging connections in testing mode
18
- if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.remoteLogging) === false) return ws.terminate(); // track all remote logging connections in testing mode
19
-
20
- if (percy.testing) ((_percy$testing2 = percy.testing).remoteLoggers || (_percy$testing2.remoteLoggers = new Set())).add(ws);
21
- ws.addEventListener('close', () => {
22
- var _percy$testing3, _percy$testing3$remot;
23
-
24
- return (_percy$testing3 = percy.testing) === null || _percy$testing3 === void 0 ? void 0 : (_percy$testing3$remot = _percy$testing3.remoteLoggers) === null || _percy$testing3$remot === void 0 ? void 0 : _percy$testing3$remot.delete(ws);
25
- }); // listen for messages with specific logging payloads
26
-
27
- ws.addEventListener('message', ({
28
- data
29
- }) => {
30
- let {
31
- log,
32
- messages = []
33
- } = JSON.parse(data);
34
-
35
- for (let m of messages) logger.instance.messages.add(m);
36
-
37
- if (log) logger.instance.log(...log);
38
- }); // respond with the current loglevel
39
-
40
- ws.send(JSON.stringify({
41
- loglevel: logger.loglevel()
42
- }));
43
13
  }) // general middleware
44
14
  .route((req, res, next) => {
45
- var _percy$testing4, _percy$testing7, _percy$testing7$api, _percy$testing8, _percy$testing8$api;
15
+ var _percy$testing, _percy$testing4, _percy$testing4$api, _percy$testing5, _percy$testing5$api;
46
16
 
47
17
  // treat all request bodies as json
48
18
  if (req.body) try {
@@ -51,17 +21,17 @@ export function createPercyServer(percy, port) {
51
21
 
52
22
  res.setHeader('Access-Control-Expose-Headers', '*, X-Percy-Core-Version'); // skip or change api version header in testing mode
53
23
 
54
- if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : _percy$testing4.version) !== false) {
55
- var _percy$testing5;
24
+ if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.version) !== false) {
25
+ var _percy$testing2;
56
26
 
57
- res.setHeader('X-Percy-Core-Version', ((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 ? void 0 : _percy$testing5.version) ?? pkg.version);
27
+ res.setHeader('X-Percy-Core-Version', ((_percy$testing2 = percy.testing) === null || _percy$testing2 === void 0 ? void 0 : _percy$testing2.version) ?? pkg.version);
58
28
  } // track all api reqeusts in testing mode
59
29
 
60
30
 
61
31
  if (percy.testing && !req.url.pathname.startsWith('/test/')) {
62
- var _percy$testing6;
32
+ var _percy$testing3;
63
33
 
64
- ((_percy$testing6 = percy.testing).requests || (_percy$testing6.requests = [])).push({
34
+ ((_percy$testing3 = percy.testing).requests || (_percy$testing3.requests = [])).push({
65
35
  url: `${req.url.pathname}${req.url.search}`,
66
36
  method: req.method,
67
37
  body: req.body
@@ -69,32 +39,32 @@ export function createPercyServer(percy, port) {
69
39
  } // support sabotaging requests in testing mode
70
40
 
71
41
 
72
- if (((_percy$testing7 = percy.testing) === null || _percy$testing7 === void 0 ? void 0 : (_percy$testing7$api = _percy$testing7.api) === null || _percy$testing7$api === void 0 ? void 0 : _percy$testing7$api[req.url.pathname]) === 'error') {
42
+ if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : (_percy$testing4$api = _percy$testing4.api) === null || _percy$testing4$api === void 0 ? void 0 : _percy$testing4$api[req.url.pathname]) === 'error') {
73
43
  next = () => {
74
44
  var _percy$testing$build;
75
45
 
76
46
  return Promise.reject(new Error(((_percy$testing$build = percy.testing.build) === null || _percy$testing$build === void 0 ? void 0 : _percy$testing$build.error) || 'testing'));
77
47
  };
78
- } else if (((_percy$testing8 = percy.testing) === null || _percy$testing8 === void 0 ? void 0 : (_percy$testing8$api = _percy$testing8.api) === null || _percy$testing8$api === void 0 ? void 0 : _percy$testing8$api[req.url.pathname]) === 'disconnect') {
48
+ } else if (((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 ? void 0 : (_percy$testing5$api = _percy$testing5.api) === null || _percy$testing5$api === void 0 ? void 0 : _percy$testing5$api[req.url.pathname]) === 'disconnect') {
79
49
  next = () => req.connection.destroy();
80
50
  } // return json errors
81
51
 
82
52
 
83
53
  return next().catch(e => {
84
- var _percy$testing9;
54
+ var _percy$testing6;
85
55
 
86
56
  return res.json(e.status ?? 500, {
87
- build: ((_percy$testing9 = percy.testing) === null || _percy$testing9 === void 0 ? void 0 : _percy$testing9.build) || percy.build,
57
+ build: ((_percy$testing6 = percy.testing) === null || _percy$testing6 === void 0 ? void 0 : _percy$testing6.build) || percy.build,
88
58
  error: e.message,
89
59
  success: false
90
60
  });
91
61
  });
92
62
  }) // healthcheck returns basic information
93
63
  .route('get', '/percy/healthcheck', (req, res) => {
94
- var _percy$testing10;
64
+ var _percy$testing7;
95
65
 
96
66
  return res.json(200, {
97
- build: ((_percy$testing10 = percy.testing) === null || _percy$testing10 === void 0 ? void 0 : _percy$testing10.build) ?? percy.build,
67
+ build: ((_percy$testing7 = percy.testing) === null || _percy$testing7 === void 0 ? void 0 : _percy$testing7.build) ?? percy.build,
98
68
  loglevel: percy.loglevel(),
99
69
  config: percy.config,
100
70
  success: true
@@ -138,34 +108,25 @@ export function createPercyServer(percy, port) {
138
108
  }
139
109
  }, res) => {
140
110
  body = Buffer.isBuffer(body) ? body.toString() : body;
141
- let {
142
- remoteLoggers
143
- } = percy.testing;
144
111
 
145
112
  if (cmd === 'reset') {
146
113
  // the reset command will reset testing mode and clear any logs
147
- percy.testing = remoteLoggers ? {
148
- remoteLoggers
149
- } : {};
114
+ percy.testing = {};
150
115
  logger.instance.messages.clear();
151
116
  } else if (cmd === 'version') {
152
117
  // the version command will update the api version header for testing
153
118
  percy.testing.version = body;
154
119
  } else if (cmd === 'error' || cmd === 'disconnect') {
155
- var _percy$testing11;
120
+ var _percy$testing8;
156
121
 
157
122
  // the error or disconnect commands will cause specific endpoints to fail
158
- ((_percy$testing11 = percy.testing).api || (_percy$testing11.api = {}))[body] = cmd;
123
+ ((_percy$testing8 = percy.testing).api || (_percy$testing8.api = {}))[body] = cmd;
159
124
  } else if (cmd === 'build-failure') {
160
125
  // the build-failure command will cause api errors to include a failed build
161
126
  percy.testing.build = {
162
127
  failed: true,
163
128
  error: 'Build failed'
164
129
  };
165
- } else if (cmd === 'remote-logging') {
166
- // the remote-logging command will toggle remote logging support
167
- if (body === false) remoteLoggers === null || remoteLoggers === void 0 ? void 0 : remoteLoggers.forEach(ws => ws.terminate());
168
- percy.testing.remoteLogging = body;
169
130
  } else {
170
131
  // 404 for unknown commands
171
132
  return res.send(404);
package/dist/server.js CHANGED
@@ -19,7 +19,6 @@ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.
19
19
  import fs from 'fs';
20
20
  import path from 'path';
21
21
  import http from 'http';
22
- import { WebSocketServer } from 'ws';
23
22
  import mime from 'mime-types';
24
23
  import disposition from 'content-disposition';
25
24
  import { pathToRegexp, match as pathToMatch, compile as makeToPath } from 'path-to-regexp'; // custom incoming message adds a `url` and `body` properties containing the parsed URL and message
@@ -117,10 +116,6 @@ var _sockets = /*#__PURE__*/new WeakMap();
117
116
 
118
117
  var _defaultPort = /*#__PURE__*/new WeakMap();
119
118
 
120
- var _up = /*#__PURE__*/new WeakMap();
121
-
122
- var _handleUpgrade = /*#__PURE__*/new WeakSet();
123
-
124
119
  var _routes = /*#__PURE__*/new WeakMap();
125
120
 
126
121
  var _route = /*#__PURE__*/new WeakSet();
@@ -140,8 +135,6 @@ export class Server extends http.Server {
140
135
 
141
136
  _classPrivateMethodInitSpec(this, _route);
142
137
 
143
- _classPrivateMethodInitSpec(this, _handleUpgrade);
144
-
145
138
  _classPrivateFieldInitSpec(this, _sockets, {
146
139
  writable: true,
147
140
  value: new Set()
@@ -152,11 +145,6 @@ export class Server extends http.Server {
152
145
  value: void 0
153
146
  });
154
147
 
155
- _classPrivateFieldInitSpec(this, _up, {
156
- writable: true,
157
- value: []
158
- });
159
-
160
148
  _classPrivateFieldInitSpec(this, _routes, {
161
149
  writable: true,
162
150
  value: [{
@@ -186,10 +174,6 @@ export class Server extends http.Server {
186
174
 
187
175
  this.on('request', (req, res) => {
188
176
  req.on('end', () => _classPrivateMethodGet(this, _handleRequest, _handleRequest2).call(this, req, res));
189
- }); // handle websocket upgrades
190
-
191
- this.on('upgrade', (req, sock, head) => {
192
- _classPrivateMethodGet(this, _handleUpgrade, _handleUpgrade2).call(this, req, sock, head);
193
177
  }); // track open connections to terminate when the server closes
194
178
 
195
179
  this.on('connection', socket => {
@@ -231,29 +215,8 @@ export class Server extends http.Server {
231
215
 
232
216
  super.close(resolve);
233
217
  });
234
- } // handle websocket upgrades
235
-
218
+ } // initial routes include cors and 404 handling
236
219
 
237
- websocket(pathname, handle) {
238
- if (!handle) [pathname, handle] = [null, pathname];
239
-
240
- _classPrivateFieldGet(this, _up).push({
241
- match: pathname && pathToMatch(pathname),
242
- handle: (req, sock, head) => new Promise(resolve => {
243
- let wss = new WebSocketServer({
244
- noServer: true,
245
- clientTracking: false
246
- });
247
- wss.handleUpgrade(req, sock, head, resolve);
248
- }).then(ws => handle(ws, req))
249
- });
250
-
251
- if (pathname) {
252
- _classPrivateFieldGet(this, _up).sort((a, b) => (a.match ? -1 : 1) - (b.match ? -1 : 1));
253
- }
254
-
255
- return this;
256
- }
257
220
 
258
221
  // set request routing and handling for pathnames and methods
259
222
  route(method, pathname, handle) {
@@ -312,14 +275,6 @@ export class Server extends http.Server {
312
275
 
313
276
  } // create a url rewriter from provided rewrite rules
314
277
 
315
- function _handleUpgrade2(req, sock, head) {
316
- let up = _classPrivateFieldGet(this, _up).find(u => !u.match || u.match(req.url));
317
-
318
- if (up) return up.handle(req, sock, head);
319
- sock.write(`HTTP/1.1 400 ${http.STATUS_CODES[400]}\r\n` + 'Connection: close\r\n\r\n');
320
- sock.destroy();
321
- }
322
-
323
278
  function _route2(route) {
324
279
  let i = _classPrivateFieldGet(this, _routes).findIndex(r => r.priority >= route.priority);
325
280
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.10.1",
3
+ "version": "1.10.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -39,10 +39,10 @@
39
39
  "test:types": "tsd"
40
40
  },
41
41
  "dependencies": {
42
- "@percy/client": "1.10.1",
43
- "@percy/config": "1.10.1",
44
- "@percy/dom": "1.10.1",
45
- "@percy/logger": "1.10.1",
42
+ "@percy/client": "1.10.3",
43
+ "@percy/config": "1.10.3",
44
+ "@percy/dom": "1.10.3",
45
+ "@percy/logger": "1.10.3",
46
46
  "content-disposition": "^0.5.4",
47
47
  "cross-spawn": "^7.0.3",
48
48
  "extract-zip": "^2.0.1",
@@ -53,5 +53,5 @@
53
53
  "rimraf": "^3.0.2",
54
54
  "ws": "^8.0.0"
55
55
  },
56
- "gitHead": "3e16144300e8b49aab638ceb699630f4be71bb9f"
56
+ "gitHead": "a9858d20a9b9708da0464c0617b32b2ee1c97433"
57
57
  }