Skip to content

Commit cc0b931

Browse files
authored
feat: remove SockJS support (#5626)
* chore: remove SockJSClient and related files from the project * chore: remove SockJS support and related configurations from the project * chore: remove SockJS example files and configurations * chore: remove SockJS support and related tests from the project * refactor: change sockjs to ws for customclient * fix: update import typedef * fix: update snapshots Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com> * chore: remove SockJS and related type definitions from package.json and package-lock.json * refactor: simplify WebSocket session handling in tests * test: update WebSocket handling in client tests to use CDP sessions * fix: update snapshot for SSL certificate generation log in server options test * docs: update migration guide to reflect removal of SockJS support * refactor: remove SockJS dependency from CustomWebSocketClient * chore: update puppeteer to version 24.35.0 in package.json * fix: update import path for webpack config in client tests * fix: update createCDPSession usage in client tests * refactor: update session creation and subscription handling in tests * fix: update webSocketTransport configuration to include webSocketURL and host --------- Signed-off-by: Sebastian Beltran <bjohansebas@gmail.com>
1 parent f0caae4 commit cc0b931

File tree

55 files changed

+646
-2863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+646
-2863
lines changed

bin/cli-flags.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ module.exports = {
214214
configs: [
215215
{
216216
type: "enum",
217-
values: ["sockjs", "ws"],
217+
values: ["ws"],
218218
multiple: false,
219219
description:
220220
"Allows to set custom web socket transport to communicate with dev server.",
@@ -1253,7 +1253,7 @@ module.exports = {
12531253
multiple: false,
12541254
path: "webSocketServer",
12551255
type: "enum",
1256-
values: ["sockjs", "ws"],
1256+
values: ["ws"],
12571257
},
12581258
{
12591259
description:
@@ -1276,7 +1276,7 @@ module.exports = {
12761276
multiple: false,
12771277
path: "webSocketServer.type",
12781278
type: "enum",
1279-
values: ["sockjs", "ws"],
1279+
values: ["ws"],
12801280
},
12811281
{
12821282
description:

client-src/clients/SockJSClient.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

client-src/modules/sockjs-client/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

client-src/socket.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import WebSocketClient from "./clients/WebSocketClient.js";
44
import { log } from "./utils/log.js";
55

66
/** @typedef {import("./index.js").EXPECTED_ANY} EXPECTED_ANY */
7-
/** @typedef {import("./clients/SockJSClient")} SockJSClient */
7+
/** @typedef {WebSocketClient} */
88

99
// this WebsocketClient is here as a default fallback, in case the client is not injected
1010
/** @type {CommunicationClientConstructor} */

client-src/webpack.config.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,4 @@ module.exports = [
6969
),
7070
],
7171
}),
72-
merge(baseForModules, {
73-
entry: path.join(__dirname, "modules/sockjs-client/index.js"),
74-
output: {
75-
filename: "sockjs-client/index.js",
76-
library: "SockJS",
77-
libraryTarget: "umd",
78-
globalObject: "(typeof self !== 'undefined' ? self : this)",
79-
},
80-
}),
8172
];

examples/web-socket-server/sockjs/README.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

examples/web-socket-server/sockjs/app.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/web-socket-server/sockjs/webpack.config.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

jest.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,5 @@ module.exports = {
2626
// https://jestjs.io/docs/upgrading-to-jest28#packagejson-exports
2727
// https://github.com/microsoft/accessibility-insights-web/pull/5421#issuecomment-1109168149
2828
//
29-
// FIXME: this uuid moduleNameMapper workaround can be removed after sockjs > uuid@v9 release
30-
// https://github.com/uuidjs/uuid/pull/616#issuecomment-1206283882
31-
// eslint-disable-next-line n/no-extraneous-require
32-
"^uuid$": require.resolve("uuid"),
3329
},
3430
};

lib/Server.js

Lines changed: 15 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ const schema = require("./options.json");
121121

122122
/**
123123
* @typedef {object} WebSocketServerConfiguration
124-
* @property {("sockjs" | "ws" | string | (() => WebSocketServerConfiguration))=} type type
124+
* @property {( "ws" | string | (() => WebSocketServerConfiguration))=} type type
125125
* @property {Record<string, EXPECTED_ANY>=} options options
126126
*/
127127

128128
/**
129-
* @typedef {(import("ws").WebSocket | import("sockjs").Connection & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
129+
* @typedef {(import("ws").WebSocket & { send: import("ws").WebSocket["send"], terminate: import("ws").WebSocket["terminate"], ping: import("ws").WebSocket["ping"] }) & { isAlive?: boolean }} ClientConnection
130130
*/
131131

132132
/**
133-
* @typedef {import("ws").WebSocketServer | import("sockjs").Server & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
133+
* @typedef {import("ws").WebSocketServer & { close: import("ws").WebSocketServer["close"] }} WebSocketServer
134134
*/
135135

136136
/**
@@ -190,7 +190,7 @@ const schema = require("./options.json");
190190
* @property {(boolean | { warnings?: OverlayMessageOptions, errors?: OverlayMessageOptions, runtimeErrors?: OverlayMessageOptions })=} overlay overlay
191191
* @property {boolean=} progress progress
192192
* @property {(boolean | number)=} reconnect reconnect
193-
* @property {("ws" | "sockjs" | string)=} webSocketTransport web socket transport
193+
* @property {("ws" | string)=} webSocketTransport web socket transport
194194
* @property {(string | WebSocketURL)=} webSocketURL web socket URL
195195
*/
196196

@@ -231,7 +231,7 @@ const schema = require("./options.json");
231231
* @property {(boolean | string | Static | Array<string | Static>)=} static
232232
* @property {(ServerType<A, S> | ServerConfiguration<A, S>)=} server
233233
* @property {(() => Promise<A>)=} app
234-
* @property {(boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration)=} webSocketServer
234+
* @property {(boolean | "ws" | string | WebSocketServerConfiguration)=} webSocketServer
235235
* @property {ProxyConfigArray=} proxy
236236
* @property {(boolean | string | Open | Array<string | Open>)=} open
237237
* @property {boolean=} setupExitSignals
@@ -656,28 +656,17 @@ class Server {
656656
/** @type {string} */
657657
let hostname;
658658

659-
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
660-
const isSockJSType = webSocketServer.type === "sockjs";
661659
const isWebSocketServerHostDefined =
662660
typeof webSocketServer.options.host !== "undefined";
663661
const isWebSocketServerPortDefined =
664662
typeof webSocketServer.options.port !== "undefined";
665663

666-
if (
667-
isSockJSType &&
668-
(isWebSocketServerHostDefined || isWebSocketServerPortDefined)
669-
) {
670-
this.logger.warn(
671-
"SockJS only supports client mode and does not support custom hostname and port options. Please consider using 'ws' if you need to customize these options.",
672-
);
673-
}
674-
675664
// We are proxying dev server and need to specify custom `hostname`
676665
if (typeof webSocketURL.hostname !== "undefined") {
677666
hostname = webSocketURL.hostname;
678667
}
679668
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
680-
else if (isWebSocketServerHostDefined && !isSockJSType) {
669+
else if (isWebSocketServerHostDefined) {
681670
hostname = webSocketServer.options.host;
682671
}
683672
// The `host` option is specified
@@ -699,7 +688,7 @@ class Server {
699688
port = webSocketURL.port;
700689
}
701690
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
702-
else if (isWebSocketServerPortDefined && !isSockJSType) {
691+
else if (isWebSocketServerPortDefined) {
703692
port = webSocketServer.options.port;
704693
}
705694
// The `port` option is specified
@@ -1542,9 +1531,7 @@ class Server {
15421531
(this.options.webSocketServer).type
15431532
) === "string" &&
15441533
// @ts-expect-error
1545-
(this.options.webSocketServer.type === "ws" ||
1546-
/** @type {WebSocketServerConfiguration} */
1547-
(this.options.webSocketServer).type === "sockjs");
1534+
this.options.webSocketServer.type === "ws";
15481535

15491536
let clientTransport;
15501537

@@ -1571,12 +1558,8 @@ class Server {
15711558

15721559
switch (typeof clientTransport) {
15731560
case "string":
1574-
// could be 'sockjs', 'ws', or a path that should be required
1575-
if (clientTransport === "sockjs") {
1576-
clientImplementation = require.resolve(
1577-
"../client/clients/SockJSClient",
1578-
);
1579-
} else if (clientTransport === "ws") {
1561+
// could be 'ws', or a path that should be required
1562+
if (clientTransport === "ws") {
15801563
clientImplementation = require.resolve(
15811564
"../client/clients/WebSocketClient",
15821565
);
@@ -1598,7 +1581,7 @@ class Server {
15981581
!isKnownWebSocketServerImplementation
15991582
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
16001583
: ""
1601-
}client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `,
1584+
}client.webSocketTransport must be a string denoting a default implementation (e.g. 'ws') or a full path to a JS file via require.resolve(...) which exports a class `,
16021585
);
16031586
}
16041587

@@ -1621,14 +1604,8 @@ class Server {
16211604
)
16221605
) {
16231606
case "string":
1624-
// Could be 'sockjs', in the future 'ws', or a path that should be required
1607+
// Could be 'ws', or a path that should be required
16251608
if (
1626-
/** @type {WebSocketServerConfiguration} */ (
1627-
this.options.webSocketServer
1628-
).type === "sockjs"
1629-
) {
1630-
implementation = require("./servers/SockJSServer");
1631-
} else if (
16321609
/** @type {WebSocketServerConfiguration} */ (
16331610
this.options.webSocketServer
16341611
).type === "ws"
@@ -1656,7 +1633,7 @@ class Server {
16561633

16571634
if (!implementationFound) {
16581635
throw new Error(
1659-
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to " +
1636+
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws'), a full path to " +
16601637
"a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) " +
16611638
"via require.resolve(...), or the class itself which extends BaseServer",
16621639
);
@@ -2047,56 +2024,6 @@ class Server {
20472024
middleware: /** @type {MiddlewareHandler} */ (this.middleware),
20482025
});
20492026

2050-
// Should be after `webpack-dev-middleware`, otherwise other middlewares might rewrite response
2051-
middlewares.push({
2052-
name: "webpack-dev-server-sockjs-bundle",
2053-
path: "/__webpack_dev_server__/sockjs.bundle.js",
2054-
/**
2055-
* @param {Request} req request
2056-
* @param {Response} res response
2057-
* @param {NextFunction} next next function
2058-
* @returns {void}
2059-
*/
2060-
middleware: (req, res, next) => {
2061-
if (req.method !== "GET" && req.method !== "HEAD") {
2062-
next();
2063-
return;
2064-
}
2065-
2066-
const clientPath = path.join(
2067-
__dirname,
2068-
"..",
2069-
"client/modules/sockjs-client/index.js",
2070-
);
2071-
2072-
// Express send Etag and other headers by default, so let's keep them for compatibility reasons
2073-
if (typeof res.sendFile === "function") {
2074-
res.sendFile(clientPath);
2075-
return;
2076-
}
2077-
2078-
let stats;
2079-
2080-
try {
2081-
// TODO implement `inputFileSystem.createReadStream` in webpack
2082-
stats = fs.statSync(clientPath);
2083-
} catch {
2084-
next();
2085-
return;
2086-
}
2087-
2088-
res.setHeader("Content-Type", "application/javascript; charset=UTF-8");
2089-
res.setHeader("Content-Length", stats.size);
2090-
2091-
if (req.method === "HEAD") {
2092-
res.end();
2093-
return;
2094-
}
2095-
2096-
fs.createReadStream(clientPath).pipe(res);
2097-
},
2098-
});
2099-
21002027
middlewares.push({
21012028
name: "webpack-dev-server-invalidate",
21022029
path: "/webpack-dev-server/invalidate",
@@ -2659,11 +2586,7 @@ class Server {
26592586
typeof request !== "undefined"
26602587
? /** @type {{ [key: string]: string | undefined }} */
26612588
(request.headers)
2662-
: typeof (
2663-
/** @type {import("sockjs").Connection} */ (client).headers
2664-
) !== "undefined"
2665-
? /** @type {import("sockjs").Connection} */ (client).headers
2666-
: undefined;
2589+
: undefined;
26672590

26682591
if (!headers) {
26692592
this.logger.warn(
@@ -3297,8 +3220,7 @@ class Server {
32973220
*/
32983221
sendMessage(clients, type, data, params) {
32993222
for (const client of clients) {
3300-
// `sockjs` uses `1` to indicate client is ready to accept data
3301-
// `ws` uses `WebSocket.OPEN`, but it is mean `1` too
3223+
// `ws` uses `WebSocket.OPEN`, which is `1`
33023224
if (client.readyState === 1) {
33033225
client.send(JSON.stringify({ type, data, params }));
33043226
}

0 commit comments

Comments
 (0)