webpack-dev-server 5.2.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/getPort.js CHANGED
@@ -6,21 +6,21 @@
6
6
  * The code structure is similar to get-port, but it searches
7
7
  * ports deterministically like portfinder
8
8
  */
9
- const net = require("net");
10
- const os = require("os");
9
+ const net = require("node:net");
10
+ const os = require("node:os");
11
11
 
12
12
  const minPort = 1024;
13
13
  const maxPort = 65_535;
14
14
 
15
15
  /**
16
- * @return {Set<string|undefined>}
16
+ * @returns {Set<string | undefined>} local hosts
17
17
  */
18
18
  const getLocalHosts = () => {
19
19
  const interfaces = os.networkInterfaces();
20
20
 
21
21
  // Add undefined value for createServer function to use default host,
22
22
  // and default IPv4 host in case createServer defaults to IPv6.
23
- // eslint-disable-next-line no-undefined
23
+
24
24
  const results = new Set([undefined, "0.0.0.0"]);
25
25
 
26
26
  for (const _interface of Object.values(interfaces)) {
@@ -35,9 +35,9 @@ const getLocalHosts = () => {
35
35
  };
36
36
 
37
37
  /**
38
- * @param {number} basePort
39
- * @param {string | undefined} host
40
- * @return {Promise<number>}
38
+ * @param {number} basePort base port
39
+ * @param {string | undefined} host host
40
+ * @returns {Promise<number>} resolved port
41
41
  */
42
42
  const checkAvailablePort = (basePort, host) =>
43
43
  new Promise((resolve, reject) => {
@@ -57,9 +57,9 @@ const checkAvailablePort = (basePort, host) =>
57
57
  });
58
58
 
59
59
  /**
60
- * @param {number} port
61
- * @param {Set<string|undefined>} hosts
62
- * @return {Promise<number>}
60
+ * @param {number} port port
61
+ * @param {Set<string|undefined>} hosts hosts
62
+ * @returns {Promise<number>} resolved port
63
63
  */
64
64
  const getAvailablePort = async (port, hosts) => {
65
65
  /**
@@ -70,7 +70,7 @@ const getAvailablePort = async (port, hosts) => {
70
70
  /* Check if the post is available on every local host name */
71
71
  for (const host of hosts) {
72
72
  try {
73
- await checkAvailablePort(port, host); // eslint-disable-line no-await-in-loop
73
+ await checkAvailablePort(port, host);
74
74
  } catch (error) {
75
75
  /* We throw an error only if the interface exists */
76
76
  if (
@@ -87,9 +87,9 @@ const getAvailablePort = async (port, hosts) => {
87
87
  };
88
88
 
89
89
  /**
90
- * @param {number} basePort
91
- * @param {string=} host
92
- * @return {Promise<number>}
90
+ * @param {number} basePort base port
91
+ * @param {string=} host host
92
+ * @returns {Promise<number>} resolved port
93
93
  */
94
94
  async function getPorts(basePort, host) {
95
95
  if (basePort < minPort || basePort > maxPort) {
@@ -97,22 +97,21 @@ async function getPorts(basePort, host) {
97
97
  }
98
98
 
99
99
  let port = basePort;
100
+
100
101
  const localhosts = getLocalHosts();
101
- let hosts;
102
- if (host && !localhosts.has(host)) {
103
- hosts = new Set([host]);
104
- } else {
105
- /* If the host is equivalent to localhost
102
+ const hosts =
103
+ host && !localhosts.has(host)
104
+ ? new Set([host])
105
+ : /* If the host is equivalent to localhost
106
106
  we need to check every equivalent host
107
107
  else the port might falsely appear as available
108
108
  on some operating systems */
109
- hosts = localhosts;
110
- }
109
+ localhosts;
111
110
  /** @type {Set<string | undefined>} */
112
111
  const portUnavailableErrors = new Set(["EADDRINUSE", "EACCES"]);
113
112
  while (port <= maxPort) {
114
113
  try {
115
- const availablePort = await getAvailablePort(port, hosts); // eslint-disable-line no-await-in-loop
114
+ const availablePort = await getAvailablePort(port, hosts);
116
115
  return availablePort;
117
116
  } catch (error) {
118
117
  /* Try next port if port is busy; throw for any other error */
@@ -6,7 +6,7 @@
6
6
  // server implementation
7
7
  module.exports = class BaseServer {
8
8
  /**
9
- * @param {import("../Server")} server
9
+ * @param {import("../Server")} server server
10
10
  */
11
11
  constructor(server) {
12
12
  /** @type {import("../Server")} */
@@ -10,18 +10,19 @@ const BaseServer = require("./BaseServer");
10
10
  // sockjs will remove Origin header, however Origin header is required for checking host.
11
11
  // See https://github.com/webpack/webpack-dev-server/issues/1604 for more information
12
12
  {
13
- // @ts-ignore
13
+ // @ts-expect-error
14
14
  const SockjsSession = require("sockjs/lib/transport").Session;
15
- const decorateConnection = SockjsSession.prototype.decorateConnection;
15
+
16
+ const { decorateConnection } = SockjsSession.prototype;
16
17
 
17
18
  /**
18
- * @param {import("http").IncomingMessage} req
19
+ * @param {import("http").IncomingMessage} req request
19
20
  */
20
21
  // eslint-disable-next-line func-names
21
22
  SockjsSession.prototype.decorateConnection = function (req) {
22
23
  decorateConnection.call(this, req);
23
24
 
24
- const connection = this.connection;
25
+ const { connection } = this;
25
26
 
26
27
  if (
27
28
  connection.headers &&
@@ -36,7 +37,7 @@ const BaseServer = require("./BaseServer");
36
37
  module.exports = class SockJSServer extends BaseServer {
37
38
  // options has: error (function), debug (function), server (http/s server), path (string)
38
39
  /**
39
- * @param {import("../Server")} server
40
+ * @param {import("../Server")} server server
40
41
  */
41
42
  constructor(server) {
42
43
  super(server);
@@ -49,8 +50,8 @@ module.exports = class SockJSServer extends BaseServer {
49
50
  );
50
51
 
51
52
  /**
52
- * @param {NonNullable<WebSocketServerConfiguration["options"]>} options
53
- * @returns {string}
53
+ * @param {NonNullable<WebSocketServerConfiguration["options"]>} options options
54
+ * @returns {string} sockjs URL
54
55
  */
55
56
  const getSockjsUrl = (options) => {
56
57
  if (typeof options.sockjsUrl !== "undefined") {
@@ -62,11 +63,12 @@ module.exports = class SockJSServer extends BaseServer {
62
63
 
63
64
  this.implementation = sockjs.createServer({
64
65
  // Use provided up-to-date sockjs-client
66
+ // eslint-disable-next-line camelcase
65
67
  sockjs_url: getSockjsUrl(webSocketServerOptions),
66
68
  // Default logger is very annoy. Limit useless logs.
67
69
  /**
68
- * @param {string} severity
69
- * @param {string} line
70
+ * @param {string} severity severity
71
+ * @param {string} line line
70
72
  */
71
73
  log: (severity, line) => {
72
74
  if (severity === "error") {
@@ -80,8 +82,8 @@ module.exports = class SockJSServer extends BaseServer {
80
82
  });
81
83
 
82
84
  /**
83
- * @param {import("sockjs").ServerOptions & { path?: string }} options
84
- * @returns {string | undefined}
85
+ * @param {import("sockjs").ServerOptions & { path?: string }} options options
86
+ * @returns {string | undefined} prefix
85
87
  */
86
88
  const getPrefix = (options) => {
87
89
  if (typeof options.prefix !== "undefined") {
@@ -102,10 +104,10 @@ module.exports = class SockJSServer extends BaseServer {
102
104
  );
103
105
 
104
106
  this.implementation.on("connection", (client) => {
105
- // @ts-ignore
107
+ // @ts-expect-error
106
108
  // Implement the the same API as for `ws`
107
109
  client.send = client.write;
108
- // @ts-ignore
110
+ // @ts-expect-error
109
111
  client.terminate = client.close;
110
112
 
111
113
  this.clients.push(/** @type {ClientConnection} */ (client));
@@ -118,7 +120,7 @@ module.exports = class SockJSServer extends BaseServer {
118
120
  });
119
121
  });
120
122
 
121
- // @ts-ignore
123
+ // @ts-expect-error
122
124
  this.implementation.close = (callback) => {
123
125
  callback();
124
126
  };
@@ -10,7 +10,7 @@ module.exports = class WebsocketServer extends BaseServer {
10
10
  static heartbeatInterval = 1000;
11
11
 
12
12
  /**
13
- * @param {import("../Server")} server
13
+ * @param {import("../Server")} server server
14
14
  */
15
15
  constructor(server) {
16
16
  super(server);
@@ -35,9 +35,9 @@ module.exports = class WebsocketServer extends BaseServer {
35
35
  (this.server.server).on(
36
36
  "upgrade",
37
37
  /**
38
- * @param {import("http").IncomingMessage} req
39
- * @param {import("stream").Duplex} sock
40
- * @param {Buffer} head
38
+ * @param {import("http").IncomingMessage} req request
39
+ * @param {import("stream").Duplex} sock socket
40
+ * @param {Buffer} head head
41
41
  */
42
42
  (req, sock, head) => {
43
43
  if (!this.implementation.shouldHandle(req)) {
@@ -53,7 +53,7 @@ module.exports = class WebsocketServer extends BaseServer {
53
53
  this.implementation.on(
54
54
  "error",
55
55
  /**
56
- * @param {Error} err
56
+ * @param {Error} err error
57
57
  */
58
58
  (err) => {
59
59
  this.server.logger.error(err.message);
@@ -61,27 +61,22 @@ module.exports = class WebsocketServer extends BaseServer {
61
61
  );
62
62
 
63
63
  const interval = setInterval(() => {
64
- this.clients.forEach(
65
- /**
66
- * @param {ClientConnection} client
67
- */
68
- (client) => {
69
- if (client.isAlive === false) {
70
- client.terminate();
71
-
72
- return;
73
- }
74
-
75
- client.isAlive = false;
76
- client.ping(() => {});
77
- },
78
- );
64
+ for (const client of this.clients) {
65
+ if (client.isAlive === false) {
66
+ client.terminate();
67
+
68
+ continue;
69
+ }
70
+
71
+ client.isAlive = false;
72
+ client.ping(() => {});
73
+ }
79
74
  }, WebsocketServer.heartbeatInterval);
80
75
 
81
76
  this.implementation.on(
82
77
  "connection",
83
78
  /**
84
- * @param {ClientConnection} client
79
+ * @param {ClientConnection} client client
85
80
  */
86
81
  (client) => {
87
82
  this.clients.push(client);
@@ -100,7 +95,7 @@ module.exports = class WebsocketServer extends BaseServer {
100
95
  client.on(
101
96
  "error",
102
97
  /**
103
- * @param {Error} err
98
+ * @param {Error} err err
104
99
  */
105
100
  (err) => {
106
101
  this.server.logger.error(err.message);
package/package.json CHANGED
@@ -1,39 +1,37 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "5.2.2",
3
+ "version": "5.2.3",
4
4
  "description": "Serves a webpack app. Updates the browser on changes.",
5
- "bin": "bin/webpack-dev-server.js",
6
- "main": "lib/Server.js",
7
- "types": "types/lib/Server.d.ts",
8
- "author": "Tobias Koppers @sokra",
9
- "bugs": "https://github.com/webpack/webpack-dev-server/issues",
10
5
  "homepage": "https://github.com/webpack/webpack-dev-server#readme",
6
+ "bugs": "https://github.com/webpack/webpack-dev-server/issues",
11
7
  "repository": "https://github.com/webpack/webpack-dev-server",
12
- "license": "MIT",
13
8
  "funding": {
14
9
  "type": "opencollective",
15
10
  "url": "https://opencollective.com/webpack"
16
11
  },
12
+ "license": "MIT",
13
+ "author": "Tobias Koppers @sokra",
14
+ "main": "lib/Server.js",
15
+ "types": "types/lib/Server.d.ts",
16
+ "bin": "bin/webpack-dev-server.js",
17
17
  "files": [
18
18
  "bin",
19
19
  "lib",
20
20
  "client",
21
21
  "types"
22
22
  ],
23
- "engines": {
24
- "node": ">= 18.12.0"
25
- },
26
23
  "scripts": {
27
24
  "fmt:check": "prettier \"{**/*,*}.{js,json,md,yml,css,ts}\" --list-different",
28
25
  "lint:prettier": "prettier --cache --list-different .",
29
- "lint:js": "eslint --cache .",
26
+ "lint:code": "eslint --cache .",
30
27
  "lint:types": "tsc --pretty --noEmit",
28
+ "lint:types-client": "tsc -p tsconfig.client.json",
31
29
  "lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
32
30
  "lint": "npm-run-all -l -p \"lint:**\"",
33
- "fix:js": "npm run lint:js -- --fix",
31
+ "fix:code": "npm run lint:code -- --fix",
34
32
  "fix:prettier": "npm run lint:prettier -- --write",
35
- "fix": "npm-run-all -l fix:js fix:prettier",
36
- "commitlint": "commitlint --from=master",
33
+ "fix": "npm-run-all -l fix:code fix:prettier",
34
+ "commitlint": "commitlint --from=main",
37
35
  "build:client": "rimraf -g ./client/* && babel client-src/ --out-dir client/ --ignore \"client-src/webpack.config.js\" --ignore \"client-src/modules\" && webpack --config client-src/webpack.config.js",
38
36
  "build:types": "rimraf -g ./types/* && tsc --declaration --emitDeclarationOnly --outDir types && node ./scripts/extend-webpack-types.js && prettier \"types/**/*.ts\" --write && prettier \"types/**/*.ts\" --write",
39
37
  "build": "npm-run-all -p \"build:**\"",
@@ -48,7 +46,7 @@
48
46
  "dependencies": {
49
47
  "@types/bonjour": "^3.5.13",
50
48
  "@types/connect-history-api-fallback": "^1.5.4",
51
- "@types/express": "^4.17.21",
49
+ "@types/express": "^4.17.25",
52
50
  "@types/express-serve-static-core": "^4.17.21",
53
51
  "@types/serve-index": "^1.9.4",
54
52
  "@types/serve-static": "^1.15.5",
@@ -58,9 +56,9 @@
58
56
  "bonjour-service": "^1.2.1",
59
57
  "chokidar": "^3.6.0",
60
58
  "colorette": "^2.0.10",
61
- "compression": "^1.7.4",
59
+ "compression": "^1.8.1",
62
60
  "connect-history-api-fallback": "^2.0.0",
63
- "express": "^4.21.2",
61
+ "express": "^4.22.1",
64
62
  "graceful-fs": "^4.2.6",
65
63
  "http-proxy-middleware": "^2.0.9",
66
64
  "ipaddr.js": "^2.1.0",
@@ -68,7 +66,7 @@
68
66
  "open": "^10.0.3",
69
67
  "p-retry": "^6.2.0",
70
68
  "schema-utils": "^4.2.0",
71
- "selfsigned": "^2.4.1",
69
+ "selfsigned": "^5.5.0",
72
70
  "serve-index": "^1.9.1",
73
71
  "sockjs": "^0.3.24",
74
72
  "spdy": "^4.0.2",
@@ -85,31 +83,35 @@
85
83
  "@babel/runtime": "^7.25.9",
86
84
  "@commitlint/cli": "^19.5.0",
87
85
  "@commitlint/config-conventional": "^19.5.0",
86
+ "@eslint/markdown": "^7.0.0",
88
87
  "@hono/node-server": "^1.13.3",
89
88
  "@types/compression": "^1.7.2",
90
- "@types/node": "^22.8.4",
89
+ "@types/graceful-fs": "^4.1.9",
90
+ "@types/node": "^24.0.14",
91
91
  "@types/node-forge": "^1.3.1",
92
92
  "@types/sockjs-client": "^1.5.1",
93
- "@types/trusted-types": "^2.0.2",
93
+ "@types/trusted-types": "^2.0.7",
94
94
  "acorn": "^8.14.0",
95
- "babel-jest": "^29.5.0",
95
+ "babel-jest": "^30.0.4",
96
96
  "babel-loader": "^10.0.0",
97
- "body-parser": "^1.19.2",
98
97
  "connect": "^3.7.0",
99
98
  "core-js": "^3.38.1",
100
99
  "cspell": "^8.15.5",
101
100
  "css-loader": "^7.1.1",
102
- "eslint": "^8.57.1",
103
- "eslint-config-prettier": "^9.1.0",
104
- "eslint-config-webpack": "^1.2.5",
105
- "eslint-plugin-import": "^2.31.0",
101
+ "eslint": "^9.30.1",
102
+ "eslint-config-prettier": "^10.1.5",
103
+ "eslint-config-webpack": "^4.4.0",
104
+ "eslint-plugin-import": "^2.32.0",
105
+ "eslint-plugin-jest": "^29.0.1",
106
+ "eslint-plugin-jsdoc": "^51.3.4",
107
+ "eslint-plugin-n": "^17.21.0",
106
108
  "execa": "^5.1.1",
107
109
  "hono": "^4.6.8",
108
110
  "html-webpack-plugin": "^5.6.3",
109
111
  "http-proxy": "^1.18.1",
110
112
  "husky": "^9.1.6",
111
- "jest": "^29.5.0",
112
- "jest-environment-jsdom": "^29.5.0",
113
+ "jest": "^30.0.4",
114
+ "jest-environment-jsdom": "^29.7.0",
113
115
  "klona": "^2.0.4",
114
116
  "less": "^4.1.1",
115
117
  "less-loader": "^12.1.0",
@@ -124,14 +126,14 @@
124
126
  "rimraf": "^5.0.5",
125
127
  "sockjs-client": "^1.6.1",
126
128
  "standard-version": "^9.3.0",
127
- "strip-ansi-v6": "npm:strip-ansi@^6.0.0",
128
129
  "style-loader": "^4.0.0",
129
- "supertest": "^7.0.0",
130
+ "supertest": "^7.2.2",
130
131
  "tcp-port-used": "^1.0.2",
131
132
  "typescript": "^5.7.2",
133
+ "typescript-eslint": "^8.36.0",
132
134
  "wait-for-expect": "^3.0.2",
133
135
  "webpack": "^5.94.0",
134
- "webpack-cli": "^5.0.1",
136
+ "webpack-cli": "^6.0.1",
135
137
  "webpack-merge": "^6.0.1"
136
138
  },
137
139
  "peerDependencies": {
@@ -144,5 +146,8 @@
144
146
  "webpack": {
145
147
  "optional": true
146
148
  }
149
+ },
150
+ "engines": {
151
+ "node": ">= 18.12.0"
147
152
  }
148
153
  }
@@ -23,5 +23,5 @@ export type CliOption = {
23
23
  /**
24
24
  * preprocessor
25
25
  */
26
- preprocess: Function;
26
+ preprocess: () => void;
27
27
  };