Skip to content

Commit e151055

Browse files
authored
chore: remove SockJS support and related configurations from the project
1 parent 1181c3c commit e151055

20 files changed

+81
-572
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:

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: 14 additions & 41 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
@@ -674,28 +674,17 @@ class Server {
674674
/** @type {string} */
675675
let hostname;
676676

677-
// SockJS is not supported server mode, so `hostname` and `port` can't specified, let's ignore them
678-
const isSockJSType = webSocketServer.type === "sockjs";
679677
const isWebSocketServerHostDefined =
680678
typeof webSocketServer.options.host !== "undefined";
681679
const isWebSocketServerPortDefined =
682680
typeof webSocketServer.options.port !== "undefined";
683681

684-
if (
685-
isSockJSType &&
686-
(isWebSocketServerHostDefined || isWebSocketServerPortDefined)
687-
) {
688-
this.logger.warn(
689-
"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.",
690-
);
691-
}
692-
693682
// We are proxying dev server and need to specify custom `hostname`
694683
if (typeof webSocketURL.hostname !== "undefined") {
695684
hostname = webSocketURL.hostname;
696685
}
697686
// Web socket server works on custom `hostname`, only for `ws` because `sock-js` is not support custom `hostname`
698-
else if (isWebSocketServerHostDefined && !isSockJSType) {
687+
else if (isWebSocketServerHostDefined) {
699688
hostname = webSocketServer.options.host;
700689
}
701690
// The `host` option is specified
@@ -717,7 +706,7 @@ class Server {
717706
port = webSocketURL.port;
718707
}
719708
// Web socket server works on custom `port`, only for `ws` because `sock-js` is not support custom `port`
720-
else if (isWebSocketServerPortDefined && !isSockJSType) {
709+
else if (isWebSocketServerPortDefined) {
721710
port = webSocketServer.options.port;
722711
}
723712
// The `port` option is specified
@@ -1560,9 +1549,7 @@ class Server {
15601549
(this.options.webSocketServer).type
15611550
) === "string" &&
15621551
// @ts-expect-error
1563-
(this.options.webSocketServer.type === "ws" ||
1564-
/** @type {WebSocketServerConfiguration} */
1565-
(this.options.webSocketServer).type === "sockjs");
1552+
this.options.webSocketServer.type === "ws";
15661553

15671554
let clientTransport;
15681555

@@ -1589,12 +1576,8 @@ class Server {
15891576

15901577
switch (typeof clientTransport) {
15911578
case "string":
1592-
// could be 'sockjs', 'ws', or a path that should be required
1593-
if (clientTransport === "sockjs") {
1594-
clientImplementation = require.resolve(
1595-
"../client/clients/SockJSClient",
1596-
);
1597-
} else if (clientTransport === "ws") {
1579+
// could be 'ws', or a path that should be required
1580+
if (clientTransport === "ws") {
15981581
clientImplementation = require.resolve(
15991582
"../client/clients/WebSocketClient",
16001583
);
@@ -1616,7 +1599,7 @@ class Server {
16161599
!isKnownWebSocketServerImplementation
16171600
? "When you use custom web socket implementation you must explicitly specify client.webSocketTransport. "
16181601
: ""
1619-
}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 `,
1602+
}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 `,
16201603
);
16211604
}
16221605

@@ -1639,14 +1622,8 @@ class Server {
16391622
)
16401623
) {
16411624
case "string":
1642-
// Could be 'sockjs', in the future 'ws', or a path that should be required
1625+
// Could be 'ws', or a path that should be required
16431626
if (
1644-
/** @type {WebSocketServerConfiguration} */ (
1645-
this.options.webSocketServer
1646-
).type === "sockjs"
1647-
) {
1648-
implementation = require("./servers/SockJSServer");
1649-
} else if (
16501627
/** @type {WebSocketServerConfiguration} */ (
16511628
this.options.webSocketServer
16521629
).type === "ws"
@@ -1674,7 +1651,7 @@ class Server {
16741651

16751652
if (!implementationFound) {
16761653
throw new Error(
1677-
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws', 'sockjs'), a full path to " +
1654+
"webSocketServer (webSocketServer.type) must be a string denoting a default implementation (e.g. 'ws'), a full path to " +
16781655
"a JS file which exports a class extending BaseServer (webpack-dev-server/lib/servers/BaseServer.js) " +
16791656
"via require.resolve(...), or the class itself which extends BaseServer",
16801657
);
@@ -2677,11 +2654,7 @@ class Server {
26772654
typeof request !== "undefined"
26782655
? /** @type {{ [key: string]: string | undefined }} */
26792656
(request.headers)
2680-
: typeof (
2681-
/** @type {import("sockjs").Connection} */ (client).headers
2682-
) !== "undefined"
2683-
? /** @type {import("sockjs").Connection} */ (client).headers
2684-
: undefined;
2657+
: undefined;
26852658

26862659
if (!headers) {
26872660
this.logger.warn(

lib/options.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
"link": "https://webpack.js.org/configuration/dev-server/#websockettransport"
194194
},
195195
"ClientWebSocketTransportEnum": {
196-
"enum": ["sockjs", "ws"]
196+
"enum": ["ws"]
197197
},
198198
"ClientWebSocketTransportString": {
199199
"type": "string",
@@ -907,7 +907,7 @@
907907
"link": "https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver"
908908
},
909909
"WebSocketServerType": {
910-
"enum": ["sockjs", "ws"]
910+
"enum": ["ws"]
911911
},
912912
"WebSocketServerEnum": {
913913
"anyOf": [
@@ -918,7 +918,7 @@
918918
}
919919
},
920920
{
921-
"enum": ["sockjs", "ws"],
921+
"enum": ["ws"],
922922
"cli": {
923923
"exclude": true
924924
}

lib/servers/SockJSServer.js

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

test/cli/client-option.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ const { testBin } = require("../helpers/test-bin");
44
const port = require("../ports-map")["cli-client"];
55

66
describe('"client" CLI option', () => {
7-
it('should work using "--client-web-socket-transport sockjs"', async () => {
8-
const { exitCode } = await testBin([
9-
"--port",
10-
port,
11-
"--client-web-socket-transport",
12-
"sockjs",
13-
]);
14-
15-
expect(exitCode).toBe(0);
16-
});
17-
187
it('should work using "--client-web-socket-transport ws"', async () => {
198
const { exitCode } = await testBin([
209
"--port",

test/cli/webSocketServer-option.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ describe('"webSocketServer" CLI option', () => {
1515
expect(exitCode).toBe(0);
1616
});
1717

18-
it('should work using "--web-socket-server-type sockjs"', async () => {
19-
const { exitCode } = await testBin([
20-
"--port",
21-
port,
22-
"--web-socket-server-type",
23-
"sockjs",
24-
]);
25-
26-
expect(exitCode).toBe(0);
27-
});
28-
2918
it('should work using "--no-web-socket-server"', async () => {
3019
const { exitCode } = await testBin([
3120
"--port",

test/e2e/allowed-hosts.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config = require("../fixtures/client-config/webpack.config");
88
const runBrowser = require("../helpers/run-browser");
99
const [port1, port2] = require("../ports-map")["allowed-hosts"];
1010

11-
const webSocketServers = ["ws", "sockjs"];
11+
const webSocketServers = ["ws"];
1212

1313
describe("allowed hosts", () => {
1414
for (const webSocketServer of webSocketServers) {

0 commit comments

Comments
 (0)