Skip to content

Commit

Permalink
refactor: bump prettier to version 2.8.1
Browse files Browse the repository at this point in the history
This major bump creates a lot of noise, but it is necessary for
prettier to be able to parse new syntax such as:

- typed imports: `import { type xxx } from ...`
- private attributes: `class A { #b; #c() {} }`
  • Loading branch information
darrachequesne committed Jan 10, 2023
1 parent 33dc073 commit bc98bf1
Show file tree
Hide file tree
Showing 20 changed files with 860 additions and 839 deletions.
2 changes: 1 addition & 1 deletion lib/engine.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function listen(port, options: AttachOptions & ServerOptions, fn) {
options = {};
}

const server = createServer(function(req, res) {
const server = createServer(function (req, res) {
res.writeHead(501);
res.end("Not Implemented");
});
Expand Down
54 changes: 27 additions & 27 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ export abstract class BaseServer extends EventEmitter {
transports: Object.keys(transports),
allowUpgrades: true,
httpCompression: {
threshold: 1024
threshold: 1024,
},
cors: false,
allowEIO3: false
allowEIO3: false,
},
opts
);
Expand All @@ -163,7 +163,7 @@ export abstract class BaseServer extends EventEmitter {
path: "/",
// @ts-ignore
httpOnly: opts.cookie.path !== false,
sameSite: "lax"
sameSite: "lax",
},
opts.cookie
);
Expand All @@ -176,7 +176,7 @@ export abstract class BaseServer extends EventEmitter {
if (opts.perMessageDeflate) {
this.opts.perMessageDeflate = Object.assign(
{
threshold: 1024
threshold: 1024,
},
opts.perMessageDeflate
);
Expand Down Expand Up @@ -237,7 +237,7 @@ export abstract class BaseServer extends EventEmitter {
debug("origin header invalid");
return fn(Server.errors.BAD_REQUEST, {
name: "INVALID_ORIGIN",
origin
origin,
});
}

Expand All @@ -247,7 +247,7 @@ export abstract class BaseServer extends EventEmitter {
if (!this.clients.hasOwnProperty(sid)) {
debug('unknown sid "%s"', sid);
return fn(Server.errors.UNKNOWN_SID, {
sid
sid,
});
}
const previousTransport = this.clients[sid].transport.name;
Expand All @@ -256,21 +256,21 @@ export abstract class BaseServer extends EventEmitter {
return fn(Server.errors.BAD_REQUEST, {
name: "TRANSPORT_MISMATCH",
transport,
previousTransport
previousTransport,
});
}
} else {
// handshake is GET only
if ("GET" !== req.method) {
return fn(Server.errors.BAD_HANDSHAKE_METHOD, {
method: req.method
method: req.method,
});
}

if (transport === "websocket" && !upgrade) {
debug("invalid transport upgrade");
return fn(Server.errors.BAD_REQUEST, {
name: "TRANSPORT_HANDSHAKE_ERROR"
name: "TRANSPORT_HANDSHAKE_ERROR",
});
}

Expand All @@ -279,7 +279,7 @@ export abstract class BaseServer extends EventEmitter {
return this.opts.allowRequest(req, (message, success) => {
if (!success) {
return fn(Server.errors.FORBIDDEN, {
message
message,
});
}
fn();
Expand Down Expand Up @@ -337,8 +337,8 @@ export abstract class BaseServer extends EventEmitter {
message:
Server.errorMessages[Server.errors.UNSUPPORTED_PROTOCOL_VERSION],
context: {
protocol
}
protocol,
},
});
closeConnection(Server.errors.UNSUPPORTED_PROTOCOL_VERSION);
return;
Expand All @@ -355,8 +355,8 @@ export abstract class BaseServer extends EventEmitter {
message: Server.errorMessages[Server.errors.BAD_REQUEST],
context: {
name: "ID_GENERATION_ERROR",
error: e
}
error: e,
},
});
closeConnection(Server.errors.BAD_REQUEST);
return;
Expand Down Expand Up @@ -386,8 +386,8 @@ export abstract class BaseServer extends EventEmitter {
message: Server.errorMessages[Server.errors.BAD_REQUEST],
context: {
name: "TRANSPORT_HANDSHAKE_ERROR",
error: e
}
error: e,
},
});
closeConnection(Server.errors.BAD_REQUEST);
return;
Expand All @@ -401,7 +401,7 @@ export abstract class BaseServer extends EventEmitter {
if (this.opts.cookie) {
headers["Set-Cookie"] = [
// @ts-ignore
serialize(this.opts.cookie.name, id, this.opts.cookie)
serialize(this.opts.cookie.name, id, this.opts.cookie),
];
}
this.emit("initial_headers", headers, req);
Expand Down Expand Up @@ -436,7 +436,7 @@ export abstract class BaseServer extends EventEmitter {
BAD_HANDSHAKE_METHOD: 2,
BAD_REQUEST: 3,
FORBIDDEN: 4,
UNSUPPORTED_PROTOCOL_VERSION: 5
UNSUPPORTED_PROTOCOL_VERSION: 5,
};

static errorMessages = {
Expand All @@ -445,7 +445,7 @@ export abstract class BaseServer extends EventEmitter {
2: "Bad handshake method",
3: "Bad request",
4: "Forbidden",
5: "Unsupported protocol version"
5: "Unsupported protocol version",
};
}

Expand All @@ -467,7 +467,7 @@ export class Server extends BaseServer {
noServer: true,
clientTracking: false,
perMessageDeflate: this.opts.perMessageDeflate,
maxPayload: this.opts.maxHttpBufferSize
maxPayload: this.opts.maxHttpBufferSize,
});

if (typeof this.ws.on === "function") {
Expand All @@ -483,7 +483,7 @@ export class Server extends BaseServer {

this.emit("headers", additionalHeaders, req);

Object.keys(additionalHeaders).forEach(key => {
Object.keys(additionalHeaders).forEach((key) => {
headersArray.push(`${key}: ${additionalHeaders[key]}`);
});
});
Expand Down Expand Up @@ -532,7 +532,7 @@ export class Server extends BaseServer {
req,
code: errorCode,
message: Server.errorMessages[errorCode],
context: errorContext
context: errorContext,
});
abortRequest(res, errorCode, errorContext);
return;
Expand Down Expand Up @@ -571,7 +571,7 @@ export class Server extends BaseServer {
req,
code: errorCode,
message: Server.errorMessages[errorCode],
context: errorContext
context: errorContext,
});
abortUpgrade(socket, errorCode, errorContext);
return;
Expand All @@ -581,7 +581,7 @@ export class Server extends BaseServer {
upgradeHead = null;

// delegate to ws
this.ws.handleUpgrade(req, socket, head, websocket => {
this.ws.handleUpgrade(req, socket, head, (websocket) => {
this.onWebSocket(req, socket, websocket);
});
});
Expand Down Expand Up @@ -694,10 +694,10 @@ export class Server extends BaseServer {
// but by adding a handler, we prevent that
// and if no eio thing handles the upgrade
// then the socket needs to die!
setTimeout(function() {
setTimeout(function () {
// @ts-ignore
if (socket.writable && socket.bytesWritten <= 0) {
socket.on("error", e => {
socket.on("error", (e) => {
debug("error while destroying upgrade: %s", e.message);
});
return socket.end();
Expand Down Expand Up @@ -730,7 +730,7 @@ function abortRequest(res, errorCode, errorContext) {
res.end(
JSON.stringify({
code: errorCode,
message
message,
})
);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class Socket extends EventEmitter {
upgrades: this.getAvailableUpgrades(),
pingInterval: this.server.opts.pingInterval,
pingTimeout: this.server.opts.pingTimeout,
maxPayload: this.server.opts.maxHttpBufferSize
maxPayload: this.server.opts.maxHttpBufferSize,
})
);

Expand Down Expand Up @@ -232,7 +232,7 @@ export class Socket extends EventEmitter {
// this function will manage packet events (also message callbacks)
this.setupSendCallback();

this.cleanupFn.push(function() {
this.cleanupFn.push(function () {
transport.removeListener("error", onError);
transport.removeListener("packet", onPacket);
transport.removeListener("drain", flush);
Expand Down Expand Up @@ -264,7 +264,7 @@ export class Socket extends EventEmitter {
}
}, this.server.opts.upgradeTimeout);

const onPacket = packet => {
const onPacket = (packet) => {
if ("ping" === packet.type && "probe" === packet.data) {
debug("got probe ping packet, sending pong");
transport.send([{ type: "pong", data: "probe" }]);
Expand Down Expand Up @@ -314,7 +314,7 @@ export class Socket extends EventEmitter {
this.removeListener("close", onClose);
};

const onError = err => {
const onError = (err) => {
debug("client did not complete upgrade - %s", err);
cleanup();
transport.close();
Expand Down Expand Up @@ -352,7 +352,7 @@ export class Socket extends EventEmitter {
}

// silence further transport errors and prevent uncaught exceptions
this.transport.on("error", function() {
this.transport.on("error", function () {
debug("error triggered by discarded transport");
});

Expand Down Expand Up @@ -483,7 +483,7 @@ export class Socket extends EventEmitter {

const packet: Packet = {
type,
options
options,
};

if (data) packet.data = data;
Expand Down
2 changes: 1 addition & 1 deletion lib/transports-uws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { WebSocket } from "./websocket";

export default {
polling: Polling,
websocket: WebSocket
websocket: WebSocket,
};
22 changes: 11 additions & 11 deletions lib/transports-uws/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const debug = debugModule("engine:polling");

const compressionMethods = {
gzip: createGzip,
deflate: createDeflate
deflate: createDeflate,
};

export class Polling extends Transport {
Expand Down Expand Up @@ -151,15 +151,15 @@ export class Polling extends Transport {
const headers = {
// text/html is required instead of text/plain to avoid an
// unwanted download dialog on certain user-agents (GH-43)
"Content-Type": "text/html"
"Content-Type": "text/html",
};

this.headers(req, headers);
for (let key in headers) {
res.writeHeader(key, String(headers[key]));
}

const onEnd = buffer => {
const onEnd = (buffer) => {
this.onData(buffer.toString());
this.onDataRequestCleanup();
res.end("ok");
Expand Down Expand Up @@ -220,7 +220,7 @@ export class Polling extends Transport {
*/
onData(data) {
debug('received "%s"', data);
const callback = packet => {
const callback = (packet) => {
if ("close" === packet.type) {
debug("got xhr close packet");
this.onClose();
Expand Down Expand Up @@ -266,8 +266,8 @@ export class Polling extends Transport {
this.shouldClose = null;
}

const doWrite = data => {
const compress = packets.some(packet => {
const doWrite = (data) => {
const compress = packets.some((packet) => {
return packet.options && packet.options.compress;
});
this.write(data, { compress });
Expand Down Expand Up @@ -307,12 +307,12 @@ export class Polling extends Transport {
: "application/octet-stream";

const headers = {
"Content-Type": contentType
"Content-Type": contentType,
};

const respond = data => {
const respond = (data) => {
this.headers(this.req, headers);
Object.keys(headers).forEach(key => {
Object.keys(headers).forEach((key) => {
this.res.writeHeader(key, String(headers[key]));
});
this.res.end(data);
Expand Down Expand Up @@ -362,11 +362,11 @@ export class Polling extends Transport {

compressionMethods[encoding](this.httpCompression)
.on("error", callback)
.on("data", function(chunk) {
.on("data", function (chunk) {
buffers.push(chunk);
nread += chunk.length;
})
.on("end", function() {
.on("end", function () {
callback(null, Buffer.concat(buffers, nread));
})
.end(data);
Expand Down
2 changes: 1 addition & 1 deletion lib/transports-uws/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class WebSocket extends Transport {
opts.compress = packet.options.compress;
}

const send = data => {
const send = (data) => {
const isBinary = typeof data !== "string";
const compress =
this.perMessageDeflate &&
Expand Down
2 changes: 1 addition & 1 deletion lib/transports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WebSocket } from "./websocket";

export default {
polling: polling,
websocket: WebSocket
websocket: WebSocket,
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/transports/polling-jsonp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class JSONP extends Polling {
if ("string" === typeof data) {
// client will send already escaped newlines as \\\\n and newlines as \\n
// \\n must be replaced with \n and \\\\n with \\n
data = data.replace(rSlashes, function(match, slashes) {
data = data.replace(rSlashes, function (match, slashes) {
return slashes ? match : "\n";
});
super.onData(data.replace(rDoubleSlashes, "\\n"));
Expand Down
Loading

0 comments on commit bc98bf1

Please sign in to comment.