@percy/core
Advanced tools
Comparing version 1.10.2 to 1.10.3
@@ -13,35 +13,5 @@ import fs from 'fs'; | ||
port | ||
}) // facilitate logger websocket connections | ||
.websocket('/(logger)?', ws => { | ||
var _percy$testing, _percy$testing2; | ||
// support sabotaging remote logging connections in testing mode | ||
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 | ||
if (percy.testing) ((_percy$testing2 = percy.testing).remoteLoggers || (_percy$testing2.remoteLoggers = new Set())).add(ws); | ||
ws.addEventListener('close', () => { | ||
var _percy$testing3, _percy$testing3$remot; | ||
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); | ||
}); // listen for messages with specific logging payloads | ||
ws.addEventListener('message', ({ | ||
data | ||
}) => { | ||
let { | ||
log, | ||
messages = [] | ||
} = JSON.parse(data); | ||
for (let m of messages) logger.instance.messages.add(m); | ||
if (log) logger.instance.log(...log); | ||
}); // respond with the current loglevel | ||
ws.send(JSON.stringify({ | ||
loglevel: logger.loglevel() | ||
})); | ||
}) // general middleware | ||
.route((req, res, next) => { | ||
var _percy$testing4, _percy$testing7, _percy$testing7$api, _percy$testing8, _percy$testing8$api; | ||
var _percy$testing, _percy$testing4, _percy$testing4$api, _percy$testing5, _percy$testing5$api; | ||
@@ -55,6 +25,6 @@ // treat all request bodies as json | ||
if (((_percy$testing4 = percy.testing) === null || _percy$testing4 === void 0 ? void 0 : _percy$testing4.version) !== false) { | ||
var _percy$testing5; | ||
if (((_percy$testing = percy.testing) === null || _percy$testing === void 0 ? void 0 : _percy$testing.version) !== false) { | ||
var _percy$testing2; | ||
res.setHeader('X-Percy-Core-Version', ((_percy$testing5 = percy.testing) === null || _percy$testing5 === void 0 ? void 0 : _percy$testing5.version) ?? pkg.version); | ||
res.setHeader('X-Percy-Core-Version', ((_percy$testing2 = percy.testing) === null || _percy$testing2 === void 0 ? void 0 : _percy$testing2.version) ?? pkg.version); | ||
} // track all api reqeusts in testing mode | ||
@@ -64,5 +34,5 @@ | ||
if (percy.testing && !req.url.pathname.startsWith('/test/')) { | ||
var _percy$testing6; | ||
var _percy$testing3; | ||
((_percy$testing6 = percy.testing).requests || (_percy$testing6.requests = [])).push({ | ||
((_percy$testing3 = percy.testing).requests || (_percy$testing3.requests = [])).push({ | ||
url: `${req.url.pathname}${req.url.search}`, | ||
@@ -75,3 +45,3 @@ method: req.method, | ||
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') { | ||
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') { | ||
next = () => { | ||
@@ -82,3 +52,3 @@ var _percy$testing$build; | ||
}; | ||
} 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') { | ||
} 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') { | ||
next = () => req.connection.destroy(); | ||
@@ -89,6 +59,6 @@ } // return json errors | ||
return next().catch(e => { | ||
var _percy$testing9; | ||
var _percy$testing6; | ||
return res.json(e.status ?? 500, { | ||
build: ((_percy$testing9 = percy.testing) === null || _percy$testing9 === void 0 ? void 0 : _percy$testing9.build) || percy.build, | ||
build: ((_percy$testing6 = percy.testing) === null || _percy$testing6 === void 0 ? void 0 : _percy$testing6.build) || percy.build, | ||
error: e.message, | ||
@@ -100,6 +70,6 @@ success: false | ||
.route('get', '/percy/healthcheck', (req, res) => { | ||
var _percy$testing10; | ||
var _percy$testing7; | ||
return res.json(200, { | ||
build: ((_percy$testing10 = percy.testing) === null || _percy$testing10 === void 0 ? void 0 : _percy$testing10.build) ?? percy.build, | ||
build: ((_percy$testing7 = percy.testing) === null || _percy$testing7 === void 0 ? void 0 : _percy$testing7.build) ?? percy.build, | ||
loglevel: percy.loglevel(), | ||
@@ -148,11 +118,6 @@ config: percy.config, | ||
body = Buffer.isBuffer(body) ? body.toString() : body; | ||
let { | ||
remoteLoggers | ||
} = percy.testing; | ||
if (cmd === 'reset') { | ||
// the reset command will reset testing mode and clear any logs | ||
percy.testing = remoteLoggers ? { | ||
remoteLoggers | ||
} : {}; | ||
percy.testing = {}; | ||
logger.instance.messages.clear(); | ||
@@ -163,6 +128,6 @@ } else if (cmd === 'version') { | ||
} else if (cmd === 'error' || cmd === 'disconnect') { | ||
var _percy$testing11; | ||
var _percy$testing8; | ||
// the error or disconnect commands will cause specific endpoints to fail | ||
((_percy$testing11 = percy.testing).api || (_percy$testing11.api = {}))[body] = cmd; | ||
((_percy$testing8 = percy.testing).api || (_percy$testing8.api = {}))[body] = cmd; | ||
} else if (cmd === 'build-failure') { | ||
@@ -174,6 +139,2 @@ // the build-failure command will cause api errors to include a failed build | ||
}; | ||
} else if (cmd === 'remote-logging') { | ||
// the remote-logging command will toggle remote logging support | ||
if (body === false) remoteLoggers === null || remoteLoggers === void 0 ? void 0 : remoteLoggers.forEach(ws => ws.terminate()); | ||
percy.testing.remoteLogging = body; | ||
} else { | ||
@@ -180,0 +141,0 @@ // 404 for unknown commands |
@@ -22,3 +22,2 @@ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); } | ||
import http from 'http'; | ||
import { WebSocketServer } from 'ws'; | ||
import mime from 'mime-types'; | ||
@@ -121,6 +120,2 @@ import disposition from 'content-disposition'; | ||
var _up = /*#__PURE__*/new WeakMap(); | ||
var _handleUpgrade = /*#__PURE__*/new WeakSet(); | ||
var _routes = /*#__PURE__*/new WeakMap(); | ||
@@ -145,4 +140,2 @@ | ||
_classPrivateMethodInitSpec(this, _handleUpgrade); | ||
_classPrivateFieldInitSpec(this, _sockets, { | ||
@@ -158,7 +151,2 @@ writable: true, | ||
_classPrivateFieldInitSpec(this, _up, { | ||
writable: true, | ||
value: [] | ||
}); | ||
_classPrivateFieldInitSpec(this, _routes, { | ||
@@ -193,6 +181,2 @@ writable: true, | ||
req.on('end', () => _classPrivateMethodGet(this, _handleRequest, _handleRequest2).call(this, req, res)); | ||
}); // handle websocket upgrades | ||
this.on('upgrade', (req, sock, head) => { | ||
_classPrivateMethodGet(this, _handleUpgrade, _handleUpgrade2).call(this, req, sock, head); | ||
}); // track open connections to terminate when the server closes | ||
@@ -239,26 +223,5 @@ | ||
}); | ||
} // handle websocket upgrades | ||
} // initial routes include cors and 404 handling | ||
websocket(pathname, handle) { | ||
if (!handle) [pathname, handle] = [null, pathname]; | ||
_classPrivateFieldGet(this, _up).push({ | ||
match: pathname && pathToMatch(pathname), | ||
handle: (req, sock, head) => new Promise(resolve => { | ||
let wss = new WebSocketServer({ | ||
noServer: true, | ||
clientTracking: false | ||
}); | ||
wss.handleUpgrade(req, sock, head, resolve); | ||
}).then(ws => handle(ws, req)) | ||
}); | ||
if (pathname) { | ||
_classPrivateFieldGet(this, _up).sort((a, b) => (a.match ? -1 : 1) - (b.match ? -1 : 1)); | ||
} | ||
return this; | ||
} | ||
// set request routing and handling for pathnames and methods | ||
@@ -321,10 +284,2 @@ route(method, pathname, handle) { | ||
function _handleUpgrade2(req, sock, head) { | ||
let up = _classPrivateFieldGet(this, _up).find(u => !u.match || u.match(req.url)); | ||
if (up) return up.handle(req, sock, head); | ||
sock.write(`HTTP/1.1 400 ${http.STATUS_CODES[400]}\r\n` + 'Connection: close\r\n\r\n'); | ||
sock.destroy(); | ||
} | ||
function _route2(route) { | ||
@@ -331,0 +286,0 @@ let i = _classPrivateFieldGet(this, _routes).findIndex(r => r.priority >= route.priority); |
{ | ||
"name": "@percy/core", | ||
"version": "1.10.2", | ||
"version": "1.10.3", | ||
"license": "MIT", | ||
@@ -42,6 +42,6 @@ "repository": { | ||
"dependencies": { | ||
"@percy/client": "1.10.2", | ||
"@percy/config": "1.10.2", | ||
"@percy/dom": "1.10.2", | ||
"@percy/logger": "1.10.2", | ||
"@percy/client": "1.10.3", | ||
"@percy/config": "1.10.3", | ||
"@percy/dom": "1.10.3", | ||
"@percy/logger": "1.10.3", | ||
"content-disposition": "^0.5.4", | ||
@@ -57,3 +57,3 @@ "cross-spawn": "^7.0.3", | ||
}, | ||
"gitHead": "66527175cdac3848157be7dd8368f5845d98e77e" | ||
"gitHead": "a9858d20a9b9708da0464c0617b32b2ee1c97433" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
150201
3310
+ Added@percy/client@1.10.3(transitive)
+ Added@percy/config@1.10.3(transitive)
+ Added@percy/dom@1.10.3(transitive)
+ Added@percy/env@1.10.3(transitive)
+ Added@percy/logger@1.10.3(transitive)
- Removed@percy/client@1.10.2(transitive)
- Removed@percy/config@1.10.2(transitive)
- Removed@percy/dom@1.10.2(transitive)
- Removed@percy/env@1.10.2(transitive)
- Removed@percy/logger@1.10.2(transitive)
Updated@percy/client@1.10.3
Updated@percy/config@1.10.3
Updated@percy/dom@1.10.3
Updated@percy/logger@1.10.3