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/README.md +4 -4
- package/bin/webpack-dev-server.js +17 -16
- package/client/clients/SockJSClient.js +18 -20
- package/client/clients/WebSocketClient.js +17 -11
- package/client/index.js +111 -72
- package/client/modules/logger/index.js +42 -35
- package/client/modules/sockjs-client/index.js +0 -1
- package/client/overlay.js +129 -79
- package/client/progress.js +40 -13
- package/client/socket.js +17 -13
- package/client/utils/log.js +1 -1
- package/client/utils/sendMessage.js +5 -3
- package/lib/Server.js +336 -317
- package/lib/getPort.js +21 -22
- package/lib/servers/BaseServer.js +1 -1
- package/lib/servers/SockJSServer.js +16 -14
- package/lib/servers/WebsocketServer.js +17 -22
- package/package.json +36 -31
- package/types/bin/webpack-dev-server.d.ts +1 -1
- package/types/lib/Server.d.ts +216 -149
- package/types/lib/getPort.d.ts +3 -3
- package/types/lib/servers/BaseServer.d.ts +1 -1
package/README.md
CHANGED
|
@@ -229,7 +229,7 @@ If you use TypeScript in the webpack config, you'll need to properly type `devSe
|
|
|
229
229
|
|
|
230
230
|
```ts
|
|
231
231
|
/// <reference path="node_modules/webpack-dev-server/types/lib/Server.d.ts"/>
|
|
232
|
-
import type
|
|
232
|
+
import { type Configuration } from "webpack";
|
|
233
233
|
|
|
234
234
|
// Your logic
|
|
235
235
|
```
|
|
@@ -237,8 +237,8 @@ import type { Configuration } from "webpack";
|
|
|
237
237
|
Or you can import the type from `webpack-dev-server`, i.e.
|
|
238
238
|
|
|
239
239
|
```ts
|
|
240
|
-
import type
|
|
241
|
-
import type
|
|
240
|
+
import { type Configuration } from "webpack";
|
|
241
|
+
import { type Configuration as DevServerConfiguration } from "webpack-dev-server";
|
|
242
242
|
|
|
243
243
|
const devServer: DevServerConfiguration = {};
|
|
244
244
|
const config: Configuration = { devServer };
|
|
@@ -311,7 +311,7 @@ This project is heavily inspired by [peerigon/nof5](https://github.com/peerigon/
|
|
|
311
311
|
[node-url]: https://nodejs.org
|
|
312
312
|
[tests]: https://github.com/webpack/webpack-dev-server/workflows/webpack-dev-server/badge.svg
|
|
313
313
|
[tests-url]: https://github.com/webpack/webpack-dev-server/actions?query=workflow%3Awebpack-dev-server
|
|
314
|
-
[cover]: https://codecov.io/gh/webpack/webpack-dev-server/
|
|
314
|
+
[cover]: https://codecov.io/gh/webpack/webpack-dev-server/graph/badge.svg
|
|
315
315
|
[cover-url]: https://codecov.io/gh/webpack/webpack-dev-server
|
|
316
316
|
[discussion]: https://img.shields.io/github/discussions/webpack/webpack
|
|
317
317
|
[discussion-url]: https://github.com/webpack/webpack/discussions
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* @returns {Promise<void>} promise
|
|
11
11
|
*/
|
|
12
12
|
const runCommand = (command, args) => {
|
|
13
|
-
const cp = require("child_process");
|
|
13
|
+
const cp = require("node:child_process");
|
|
14
|
+
|
|
14
15
|
return new Promise((resolve, reject) => {
|
|
15
16
|
const executedCommand = cp.spawn(command, args, {
|
|
16
17
|
stdio: "inherit",
|
|
@@ -40,7 +41,7 @@ const isInstalled = (packageName) => {
|
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
const path = require("path");
|
|
44
|
+
const path = require("node:path");
|
|
44
45
|
const fs = require("graceful-fs");
|
|
45
46
|
|
|
46
47
|
let dir = __dirname;
|
|
@@ -52,20 +53,19 @@ const isInstalled = (packageName) => {
|
|
|
52
53
|
) {
|
|
53
54
|
return true;
|
|
54
55
|
}
|
|
55
|
-
} catch
|
|
56
|
+
} catch {
|
|
56
57
|
// Nothing
|
|
57
58
|
}
|
|
58
|
-
// eslint-disable-next-line no-cond-assign
|
|
59
59
|
} while (dir !== (dir = path.dirname(dir)));
|
|
60
60
|
|
|
61
61
|
// https://github.com/nodejs/node/blob/v18.9.1/lib/internal/modules/cjs/loader.js#L1274
|
|
62
|
-
// @ts-
|
|
63
|
-
for (const internalPath of require("module").globalPaths) {
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
for (const internalPath of require("node:module").globalPaths) {
|
|
64
64
|
try {
|
|
65
65
|
if (fs.statSync(path.join(internalPath, packageName)).isDirectory()) {
|
|
66
66
|
return true;
|
|
67
67
|
}
|
|
68
|
-
} catch
|
|
68
|
+
} catch {
|
|
69
69
|
// Nothing
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -81,9 +81,11 @@ const runCli = (cli) => {
|
|
|
81
81
|
if (cli.preprocess) {
|
|
82
82
|
cli.preprocess();
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
|
|
85
|
+
const path = require("node:path");
|
|
86
|
+
|
|
85
87
|
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
|
86
|
-
|
|
88
|
+
|
|
87
89
|
const pkg = require(pkgPath);
|
|
88
90
|
|
|
89
91
|
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
|
|
@@ -94,19 +96,18 @@ const runCli = (cli) => {
|
|
|
94
96
|
},
|
|
95
97
|
);
|
|
96
98
|
} else {
|
|
97
|
-
// eslint-disable-next-line import/no-dynamic-require
|
|
98
99
|
require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
|
|
99
100
|
}
|
|
100
101
|
};
|
|
101
102
|
|
|
102
103
|
/**
|
|
103
|
-
* @typedef {
|
|
104
|
+
* @typedef {object} CliOption
|
|
104
105
|
* @property {string} name display name
|
|
105
106
|
* @property {string} package npm package name
|
|
106
107
|
* @property {string} binName name of the executable file
|
|
107
108
|
* @property {boolean} installed currently installed?
|
|
108
109
|
* @property {string} url homepage
|
|
109
|
-
* @property {
|
|
110
|
+
* @property {() => void} preprocess preprocessor
|
|
110
111
|
*/
|
|
111
112
|
|
|
112
113
|
/** @type {CliOption} */
|
|
@@ -122,9 +123,9 @@ const cli = {
|
|
|
122
123
|
};
|
|
123
124
|
|
|
124
125
|
if (!cli.installed) {
|
|
125
|
-
const path = require("path");
|
|
126
|
+
const path = require("node:path");
|
|
126
127
|
const fs = require("graceful-fs");
|
|
127
|
-
const readLine = require("readline");
|
|
128
|
+
const readLine = require("node:readline");
|
|
128
129
|
|
|
129
130
|
const notify = `CLI for webpack must be installed.\n ${cli.name} (${cli.url})\n`;
|
|
130
131
|
|
|
@@ -151,7 +152,7 @@ if (!cli.installed) {
|
|
|
151
152
|
)} ${cli.package}".`,
|
|
152
153
|
);
|
|
153
154
|
|
|
154
|
-
const question =
|
|
155
|
+
const question = "Do you want to install 'webpack-cli' (yes/no): ";
|
|
155
156
|
|
|
156
157
|
const questionInterface = readLine.createInterface({
|
|
157
158
|
input: process.stdin,
|
|
@@ -185,7 +186,7 @@ if (!cli.installed) {
|
|
|
185
186
|
}')...`,
|
|
186
187
|
);
|
|
187
188
|
|
|
188
|
-
runCommand(packageManager, installOptions
|
|
189
|
+
runCommand(packageManager, [...installOptions, cli.package])
|
|
189
190
|
.then(() => {
|
|
190
191
|
runCli(cli);
|
|
191
192
|
})
|
|
@@ -6,54 +6,52 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import SockJS from "../modules/sockjs-client/index.js";
|
|
8
8
|
import { log } from "../utils/log.js";
|
|
9
|
+
|
|
10
|
+
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @implements {CommunicationClient}
|
|
14
|
+
*/
|
|
9
15
|
var SockJSClient = /*#__PURE__*/function () {
|
|
10
16
|
/**
|
|
11
|
-
* @param {string} url
|
|
17
|
+
* @param {string} url url
|
|
12
18
|
*/
|
|
13
19
|
function SockJSClient(url) {
|
|
14
20
|
_classCallCheck(this, SockJSClient);
|
|
15
21
|
// SockJS requires `http` and `https` protocols
|
|
16
22
|
this.sock = new SockJS(url.replace(/^ws:/i, "http:").replace(/^wss:/i, "https:"));
|
|
17
|
-
this.sock.onerror =
|
|
18
|
-
/**
|
|
19
|
-
* @param {Error} error
|
|
20
|
-
*/
|
|
21
|
-
function (error) {
|
|
23
|
+
this.sock.onerror = function (error) {
|
|
22
24
|
log.error(error);
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
|
-
* @param {(...args:
|
|
29
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
28
30
|
*/
|
|
29
31
|
return _createClass(SockJSClient, [{
|
|
30
32
|
key: "onOpen",
|
|
31
|
-
value: function onOpen(
|
|
32
|
-
this.sock.onopen =
|
|
33
|
+
value: function onOpen(fn) {
|
|
34
|
+
this.sock.onopen = fn;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
|
-
* @param {(...args:
|
|
38
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
37
39
|
*/
|
|
38
40
|
}, {
|
|
39
41
|
key: "onClose",
|
|
40
|
-
value: function onClose(
|
|
41
|
-
this.sock.onclose =
|
|
42
|
+
value: function onClose(fn) {
|
|
43
|
+
this.sock.onclose = fn;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
// call f with the message string as the first argument
|
|
45
47
|
/**
|
|
46
|
-
* @param {(...args:
|
|
48
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
47
49
|
*/
|
|
48
50
|
}, {
|
|
49
51
|
key: "onMessage",
|
|
50
|
-
value: function onMessage(
|
|
51
|
-
this.sock.onmessage =
|
|
52
|
-
|
|
53
|
-
* @param {Error & { data: string }} e
|
|
54
|
-
*/
|
|
55
|
-
function (e) {
|
|
56
|
-
f(e.data);
|
|
52
|
+
value: function onMessage(fn) {
|
|
53
|
+
this.sock.onmessage = function (err) {
|
|
54
|
+
fn(err.data);
|
|
57
55
|
};
|
|
58
56
|
}
|
|
59
57
|
}]);
|
|
@@ -5,9 +5,15 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { log } from "../utils/log.js";
|
|
8
|
+
|
|
9
|
+
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @implements {CommunicationClient}
|
|
13
|
+
*/
|
|
8
14
|
var WebSocketClient = /*#__PURE__*/function () {
|
|
9
15
|
/**
|
|
10
|
-
* @param {string} url
|
|
16
|
+
* @param {string} url url to connect
|
|
11
17
|
*/
|
|
12
18
|
function WebSocketClient(url) {
|
|
13
19
|
_classCallCheck(this, WebSocketClient);
|
|
@@ -18,32 +24,32 @@ var WebSocketClient = /*#__PURE__*/function () {
|
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
|
-
* @param {(...args:
|
|
27
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
22
28
|
*/
|
|
23
29
|
return _createClass(WebSocketClient, [{
|
|
24
30
|
key: "onOpen",
|
|
25
|
-
value: function onOpen(
|
|
26
|
-
this.client.onopen =
|
|
31
|
+
value: function onOpen(fn) {
|
|
32
|
+
this.client.onopen = fn;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
/**
|
|
30
|
-
* @param {(...args:
|
|
36
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
31
37
|
*/
|
|
32
38
|
}, {
|
|
33
39
|
key: "onClose",
|
|
34
|
-
value: function onClose(
|
|
35
|
-
this.client.onclose =
|
|
40
|
+
value: function onClose(fn) {
|
|
41
|
+
this.client.onclose = fn;
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
// call f with the message string as the first argument
|
|
39
45
|
/**
|
|
40
|
-
* @param {(...args:
|
|
46
|
+
* @param {(...args: EXPECTED_ANY[]) => void} fn function
|
|
41
47
|
*/
|
|
42
48
|
}, {
|
|
43
49
|
key: "onMessage",
|
|
44
|
-
value: function onMessage(
|
|
45
|
-
this.client.onmessage = function (
|
|
46
|
-
|
|
50
|
+
value: function onMessage(fn) {
|
|
51
|
+
this.client.onmessage = function (err) {
|
|
52
|
+
fn(err.data);
|
|
47
53
|
};
|
|
48
54
|
}
|
|
49
55
|
}]);
|