Remove temporary browser-test dependency socketConnection.js
Browse files
node_modules/playwright-core/lib/tools/utils/socketConnection.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
| 1 |
-
"use strict";
|
| 2 |
-
var __defProp = Object.defineProperty;
|
| 3 |
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
| 4 |
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
| 5 |
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
| 6 |
-
var __export = (target, all) => {
|
| 7 |
-
for (var name in all)
|
| 8 |
-
__defProp(target, name, { get: all[name], enumerable: true });
|
| 9 |
-
};
|
| 10 |
-
var __copyProps = (to, from, except, desc) => {
|
| 11 |
-
if (from && typeof from === "object" || typeof from === "function") {
|
| 12 |
-
for (let key of __getOwnPropNames(from))
|
| 13 |
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
| 14 |
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
| 15 |
-
}
|
| 16 |
-
return to;
|
| 17 |
-
};
|
| 18 |
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
| 19 |
-
var socketConnection_exports = {};
|
| 20 |
-
__export(socketConnection_exports, {
|
| 21 |
-
SocketConnection: () => SocketConnection,
|
| 22 |
-
compareSemver: () => compareSemver
|
| 23 |
-
});
|
| 24 |
-
module.exports = __toCommonJS(socketConnection_exports);
|
| 25 |
-
class SocketConnection {
|
| 26 |
-
constructor(socket) {
|
| 27 |
-
this._pendingBuffers = [];
|
| 28 |
-
this._socket = socket;
|
| 29 |
-
socket.on("data", (buffer) => this._onData(buffer));
|
| 30 |
-
socket.on("close", () => {
|
| 31 |
-
this.onclose?.();
|
| 32 |
-
});
|
| 33 |
-
socket.on("error", (e) => console.error(`error: ${e.message}`));
|
| 34 |
-
}
|
| 35 |
-
async send(message) {
|
| 36 |
-
await new Promise((resolve, reject) => {
|
| 37 |
-
this._socket.write(`${JSON.stringify(message)}
|
| 38 |
-
`, (error) => {
|
| 39 |
-
if (error)
|
| 40 |
-
reject(error);
|
| 41 |
-
else
|
| 42 |
-
resolve(void 0);
|
| 43 |
-
});
|
| 44 |
-
});
|
| 45 |
-
}
|
| 46 |
-
close() {
|
| 47 |
-
this._socket.destroy();
|
| 48 |
-
}
|
| 49 |
-
_onData(buffer) {
|
| 50 |
-
let end = buffer.indexOf("\n");
|
| 51 |
-
if (end === -1) {
|
| 52 |
-
this._pendingBuffers.push(buffer);
|
| 53 |
-
return;
|
| 54 |
-
}
|
| 55 |
-
this._pendingBuffers.push(buffer.slice(0, end));
|
| 56 |
-
const message = Buffer.concat(this._pendingBuffers).toString();
|
| 57 |
-
this._dispatchMessage(message);
|
| 58 |
-
let start = end + 1;
|
| 59 |
-
end = buffer.indexOf("\n", start);
|
| 60 |
-
while (end !== -1) {
|
| 61 |
-
const message2 = buffer.toString(void 0, start, end);
|
| 62 |
-
this._dispatchMessage(message2);
|
| 63 |
-
start = end + 1;
|
| 64 |
-
end = buffer.indexOf("\n", start);
|
| 65 |
-
}
|
| 66 |
-
this._pendingBuffers = [buffer.slice(start)];
|
| 67 |
-
}
|
| 68 |
-
_dispatchMessage(message) {
|
| 69 |
-
try {
|
| 70 |
-
this.onmessage?.(JSON.parse(message));
|
| 71 |
-
} catch (e) {
|
| 72 |
-
console.error("failed to dispatch message", e);
|
| 73 |
-
}
|
| 74 |
-
}
|
| 75 |
-
}
|
| 76 |
-
function compareSemver(a, b) {
|
| 77 |
-
const aBase = a.replace(/-.*$/, "");
|
| 78 |
-
const bBase = b.replace(/-.*$/, "");
|
| 79 |
-
const aParts = aBase.split(".").map(Number);
|
| 80 |
-
const bParts = bBase.split(".").map(Number);
|
| 81 |
-
for (let i = 0; i < 3; i++) {
|
| 82 |
-
if (aParts[i] > bParts[i])
|
| 83 |
-
return 1;
|
| 84 |
-
if (aParts[i] < bParts[i])
|
| 85 |
-
return -1;
|
| 86 |
-
}
|
| 87 |
-
const aTimestamp = parseSuffixTimestamp(a);
|
| 88 |
-
const bTimestamp = parseSuffixTimestamp(b);
|
| 89 |
-
if (aTimestamp > bTimestamp)
|
| 90 |
-
return 1;
|
| 91 |
-
if (aTimestamp < bTimestamp)
|
| 92 |
-
return -1;
|
| 93 |
-
return 0;
|
| 94 |
-
}
|
| 95 |
-
function parseSuffixTimestamp(version) {
|
| 96 |
-
const match = version.match(/^\d+\.\d+\.\d+-(?:alpha|beta)-(.+)$/);
|
| 97 |
-
if (!match)
|
| 98 |
-
return Infinity;
|
| 99 |
-
const suffix = match[1];
|
| 100 |
-
if (/^\d{4}-\d{2}-\d{2}$/.test(suffix))
|
| 101 |
-
return new Date(suffix).getTime();
|
| 102 |
-
return Number(suffix);
|
| 103 |
-
}
|
| 104 |
-
// Annotate the CommonJS export names for ESM import in node:
|
| 105 |
-
0 && (module.exports = {
|
| 106 |
-
SocketConnection,
|
| 107 |
-
compareSemver
|
| 108 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|