webpack-dev-server 4.6.0 → 4.7.0
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 +56 -66
- package/bin/cli-flags.js +265 -267
- package/bin/process-arguments.js +87 -7
- package/bin/webpack-dev-server.js +3 -0
- package/client/clients/SockJSClient.js +21 -2
- package/client/clients/WebSocketClient.js +16 -1
- package/client/index.js +21 -0
- package/client/modules/logger/index.js +3 -0
- package/client/socket.js +3 -4
- package/client/utils/log.js +6 -1
- package/client/utils/sendMessage.js +5 -0
- package/lib/Server.js +1672 -752
- package/lib/options.json +37 -18
- package/lib/servers/BaseServer.js +8 -0
- package/lib/servers/SockJSServer.js +42 -9
- package/lib/servers/WebsocketServer.js +66 -35
- package/package.json +20 -10
- package/types/bin/cli-flags.d.ts +934 -0
- package/types/bin/process-arguments.d.ts +50 -0
- package/types/bin/webpack-dev-server.d.ts +27 -0
- package/types/lib/Server.d.ts +3388 -0
- package/types/lib/servers/BaseServer.d.ts +15 -0
- package/types/lib/servers/SockJSServer.d.ts +12 -0
- package/types/lib/servers/WebsocketServer.d.ts +13 -0
package/bin/process-arguments.js
CHANGED
|
@@ -5,8 +5,50 @@ const path = require("path");
|
|
|
5
5
|
// Based on https://github.com/webpack/webpack/blob/master/lib/cli.js
|
|
6
6
|
// Please do not modify it
|
|
7
7
|
|
|
8
|
+
/** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "multiple-values-unexpected" | "invalid-value"} ProblemType */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {Object} Problem
|
|
12
|
+
* @property {ProblemType} type
|
|
13
|
+
* @property {string} path
|
|
14
|
+
* @property {string} argument
|
|
15
|
+
* @property {any=} value
|
|
16
|
+
* @property {number=} index
|
|
17
|
+
* @property {string=} expected
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {Object} LocalProblem
|
|
22
|
+
* @property {ProblemType} type
|
|
23
|
+
* @property {string} path
|
|
24
|
+
* @property {string=} expected
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {Object} ArgumentConfig
|
|
29
|
+
* @property {string} description
|
|
30
|
+
* @property {string} path
|
|
31
|
+
* @property {boolean} multiple
|
|
32
|
+
* @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type
|
|
33
|
+
* @property {any[]=} values
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {Object} Argument
|
|
38
|
+
* @property {string} description
|
|
39
|
+
* @property {"string"|"number"|"boolean"} simpleType
|
|
40
|
+
* @property {boolean} multiple
|
|
41
|
+
* @property {ArgumentConfig[]} configs
|
|
42
|
+
*/
|
|
43
|
+
|
|
8
44
|
const cliAddedItems = new WeakMap();
|
|
9
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @param {any} config configuration
|
|
48
|
+
* @param {string} schemaPath path in the config
|
|
49
|
+
* @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
|
|
50
|
+
* @returns {{ problem?: LocalProblem, object?: any, property?: string | number, value?: any }} problem or object with property and value
|
|
51
|
+
*/
|
|
10
52
|
const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
|
11
53
|
if (!schemaPath) {
|
|
12
54
|
return { value: config };
|
|
@@ -81,10 +123,10 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
|
|
81
123
|
i++;
|
|
82
124
|
}
|
|
83
125
|
|
|
84
|
-
const value = current[property];
|
|
126
|
+
const value = current[/** @type {string} */ (property)];
|
|
85
127
|
|
|
86
|
-
if (property.endsWith("[]")) {
|
|
87
|
-
const name = property.slice(0, -2);
|
|
128
|
+
if (/** @type {string} */ (property).endsWith("[]")) {
|
|
129
|
+
const name = /** @type {string} */ (property).slice(0, -2);
|
|
88
130
|
// eslint-disable-next-line no-shadow
|
|
89
131
|
const value = current[name];
|
|
90
132
|
|
|
@@ -140,6 +182,11 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
|
|
140
182
|
return { object: current, property, value };
|
|
141
183
|
};
|
|
142
184
|
|
|
185
|
+
/**
|
|
186
|
+
* @param {ArgumentConfig} argConfig processing instructions
|
|
187
|
+
* @param {any} value the value
|
|
188
|
+
* @returns {any | undefined} parsed value
|
|
189
|
+
*/
|
|
143
190
|
const parseValueForArgumentConfig = (argConfig, value) => {
|
|
144
191
|
// eslint-disable-next-line default-case
|
|
145
192
|
switch (argConfig.type) {
|
|
@@ -194,11 +241,11 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
|
|
194
241
|
|
|
195
242
|
break;
|
|
196
243
|
case "enum":
|
|
197
|
-
if (argConfig.values.includes(value)) {
|
|
244
|
+
if (/** @type {any[]} */ (argConfig.values).includes(value)) {
|
|
198
245
|
return value;
|
|
199
246
|
}
|
|
200
247
|
|
|
201
|
-
for (const item of argConfig.values) {
|
|
248
|
+
for (const item of /** @type {any[]} */ (argConfig.values)) {
|
|
202
249
|
if (`${item}` === value) return item;
|
|
203
250
|
}
|
|
204
251
|
|
|
@@ -212,6 +259,10 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
|
|
212
259
|
}
|
|
213
260
|
};
|
|
214
261
|
|
|
262
|
+
/**
|
|
263
|
+
* @param {ArgumentConfig} argConfig processing instructions
|
|
264
|
+
* @returns {string | undefined} expected message
|
|
265
|
+
*/
|
|
215
266
|
const getExpectedValue = (argConfig) => {
|
|
216
267
|
switch (argConfig.type) {
|
|
217
268
|
default:
|
|
@@ -221,12 +272,21 @@ const getExpectedValue = (argConfig) => {
|
|
|
221
272
|
case "RegExp":
|
|
222
273
|
return "regular expression (example: /ab?c*/)";
|
|
223
274
|
case "enum":
|
|
224
|
-
return
|
|
275
|
+
return /** @type {any[]} */ (argConfig.values)
|
|
276
|
+
.map((v) => `${v}`)
|
|
277
|
+
.join(" | ");
|
|
225
278
|
case "reset":
|
|
226
279
|
return "true (will reset the previous value to an empty array)";
|
|
227
280
|
}
|
|
228
281
|
};
|
|
229
282
|
|
|
283
|
+
/**
|
|
284
|
+
* @param {any} config configuration
|
|
285
|
+
* @param {string} schemaPath path in the config
|
|
286
|
+
* @param {any} value parsed value
|
|
287
|
+
* @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
|
|
288
|
+
* @returns {LocalProblem | null} problem or null for success
|
|
289
|
+
*/
|
|
230
290
|
const setValue = (config, schemaPath, value, index) => {
|
|
231
291
|
const { problem, object, property } = getObjectAndProperty(
|
|
232
292
|
config,
|
|
@@ -238,11 +298,18 @@ const setValue = (config, schemaPath, value, index) => {
|
|
|
238
298
|
return problem;
|
|
239
299
|
}
|
|
240
300
|
|
|
241
|
-
object[property] = value;
|
|
301
|
+
object[/** @type {string} */ (property)] = value;
|
|
242
302
|
|
|
243
303
|
return null;
|
|
244
304
|
};
|
|
245
305
|
|
|
306
|
+
/**
|
|
307
|
+
* @param {ArgumentConfig} argConfig processing instructions
|
|
308
|
+
* @param {any} config configuration
|
|
309
|
+
* @param {any} value the value
|
|
310
|
+
* @param {number | undefined} index the index if multiple values provided
|
|
311
|
+
* @returns {LocalProblem | null} a problem if any
|
|
312
|
+
*/
|
|
246
313
|
const processArgumentConfig = (argConfig, config, value, index) => {
|
|
247
314
|
// eslint-disable-next-line no-undefined
|
|
248
315
|
if (index !== undefined && !argConfig.multiple) {
|
|
@@ -272,7 +339,16 @@ const processArgumentConfig = (argConfig, config, value, index) => {
|
|
|
272
339
|
return null;
|
|
273
340
|
};
|
|
274
341
|
|
|
342
|
+
/**
|
|
343
|
+
* @param {Record<string, Argument>} args object of arguments
|
|
344
|
+
* @param {any} config configuration
|
|
345
|
+
* @param {Record<string, string | number | boolean | RegExp | (string | number | boolean | RegExp)[]>} values object with values
|
|
346
|
+
* @returns {Problem[] | null} problems or null for success
|
|
347
|
+
*/
|
|
275
348
|
const processArguments = (args, config, values) => {
|
|
349
|
+
/**
|
|
350
|
+
* @type {Problem[]}
|
|
351
|
+
*/
|
|
276
352
|
const problems = [];
|
|
277
353
|
|
|
278
354
|
for (const key of Object.keys(values)) {
|
|
@@ -289,6 +365,10 @@ const processArguments = (args, config, values) => {
|
|
|
289
365
|
continue;
|
|
290
366
|
}
|
|
291
367
|
|
|
368
|
+
/**
|
|
369
|
+
* @param {any} value
|
|
370
|
+
* @param {number | undefined} i
|
|
371
|
+
*/
|
|
292
372
|
const processValue = (value, i) => {
|
|
293
373
|
const currentProblems = [];
|
|
294
374
|
|
|
@@ -2,34 +2,53 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
2
2
|
|
|
3
3
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
4
|
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
6
|
|
|
7
7
|
import SockJS from "../modules/sockjs-client/index.js";
|
|
8
8
|
import { log } from "../utils/log.js";
|
|
9
9
|
|
|
10
10
|
var SockJSClient = /*#__PURE__*/function () {
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} url
|
|
13
|
+
*/
|
|
11
14
|
function SockJSClient(url) {
|
|
12
15
|
_classCallCheck(this, SockJSClient);
|
|
13
16
|
|
|
14
17
|
// SockJS requires `http` and `https` protocols
|
|
15
18
|
this.sock = new SockJS(url.replace(/^ws:/i, "http:").replace(/^wss:/i, "https:"));
|
|
16
19
|
|
|
17
|
-
this.sock.onerror =
|
|
20
|
+
this.sock.onerror =
|
|
21
|
+
/**
|
|
22
|
+
* @param {Error} error
|
|
23
|
+
*/
|
|
24
|
+
function (error) {
|
|
18
25
|
log.error(error);
|
|
19
26
|
};
|
|
20
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* @param {(...args: any[]) => void} f
|
|
30
|
+
*/
|
|
31
|
+
|
|
21
32
|
|
|
22
33
|
_createClass(SockJSClient, [{
|
|
23
34
|
key: "onOpen",
|
|
24
35
|
value: function onOpen(f) {
|
|
25
36
|
this.sock.onopen = f;
|
|
26
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @param {(...args: any[]) => void} f
|
|
40
|
+
*/
|
|
41
|
+
|
|
27
42
|
}, {
|
|
28
43
|
key: "onClose",
|
|
29
44
|
value: function onClose(f) {
|
|
30
45
|
this.sock.onclose = f;
|
|
31
46
|
} // call f with the message string as the first argument
|
|
32
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {(...args: any[]) => void} f
|
|
50
|
+
*/
|
|
51
|
+
|
|
33
52
|
}, {
|
|
34
53
|
key: "onMessage",
|
|
35
54
|
value: function onMessage(f) {
|
|
@@ -2,11 +2,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
2
2
|
|
|
3
3
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
4
4
|
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
6
|
|
|
7
7
|
import { log } from "../utils/log.js";
|
|
8
8
|
|
|
9
9
|
var WebSocketClient = /*#__PURE__*/function () {
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} url
|
|
12
|
+
*/
|
|
10
13
|
function WebSocketClient(url) {
|
|
11
14
|
_classCallCheck(this, WebSocketClient);
|
|
12
15
|
|
|
@@ -16,18 +19,30 @@ var WebSocketClient = /*#__PURE__*/function () {
|
|
|
16
19
|
log.error(error);
|
|
17
20
|
};
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* @param {(...args: any[]) => void} f
|
|
24
|
+
*/
|
|
25
|
+
|
|
19
26
|
|
|
20
27
|
_createClass(WebSocketClient, [{
|
|
21
28
|
key: "onOpen",
|
|
22
29
|
value: function onOpen(f) {
|
|
23
30
|
this.client.onopen = f;
|
|
24
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* @param {(...args: any[]) => void} f
|
|
34
|
+
*/
|
|
35
|
+
|
|
25
36
|
}, {
|
|
26
37
|
key: "onClose",
|
|
27
38
|
value: function onClose(f) {
|
|
28
39
|
this.client.onclose = f;
|
|
29
40
|
} // call f with the message string as the first argument
|
|
30
41
|
|
|
42
|
+
/**
|
|
43
|
+
* @param {(...args: any[]) => void} f
|
|
44
|
+
*/
|
|
45
|
+
|
|
31
46
|
}, {
|
|
32
47
|
key: "onMessage",
|
|
33
48
|
value: function onMessage(f) {
|
package/client/index.js
CHANGED
|
@@ -39,6 +39,10 @@ if (parsedResourceQuery.logging) {
|
|
|
39
39
|
if (typeof parsedResourceQuery.reconnect !== "undefined") {
|
|
40
40
|
options.reconnect = Number(parsedResourceQuery.reconnect);
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} level
|
|
44
|
+
*/
|
|
45
|
+
|
|
42
46
|
|
|
43
47
|
function setAllLogLevel(level) {
|
|
44
48
|
// This is needed because the HMR logger operate separately from dev server logger
|
|
@@ -79,6 +83,10 @@ var onSocketMessage = {
|
|
|
79
83
|
|
|
80
84
|
sendMessage("Invalid");
|
|
81
85
|
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @param {string} hash
|
|
89
|
+
*/
|
|
82
90
|
hash: function hash(_hash) {
|
|
83
91
|
status.previousHash = status.currentHash;
|
|
84
92
|
status.currentHash = _hash;
|
|
@@ -135,6 +143,11 @@ var onSocketMessage = {
|
|
|
135
143
|
log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
|
|
136
144
|
self.location.reload();
|
|
137
145
|
},
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {Error[]} warnings
|
|
149
|
+
* @param {any} params
|
|
150
|
+
*/
|
|
138
151
|
warnings: function warnings(_warnings, params) {
|
|
139
152
|
log.warn("Warnings while compiling.");
|
|
140
153
|
|
|
@@ -164,6 +177,10 @@ var onSocketMessage = {
|
|
|
164
177
|
|
|
165
178
|
reloadApp(options, status);
|
|
166
179
|
},
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {Error[]} errors
|
|
183
|
+
*/
|
|
167
184
|
errors: function errors(_errors) {
|
|
168
185
|
log.error("Errors while compiling. Reload prevented.");
|
|
169
186
|
|
|
@@ -187,6 +204,10 @@ var onSocketMessage = {
|
|
|
187
204
|
show("error", _errors);
|
|
188
205
|
}
|
|
189
206
|
},
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* @param {Error} error
|
|
210
|
+
*/
|
|
190
211
|
error: function error(_error) {
|
|
191
212
|
log.error(_error);
|
|
192
213
|
},
|
|
@@ -87,6 +87,9 @@ function _defineProperties(target, props) {
|
|
|
87
87
|
function _createClass(Constructor, protoProps, staticProps) {
|
|
88
88
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
89
89
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
90
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
91
|
+
writable: false
|
|
92
|
+
});
|
|
90
93
|
return Constructor;
|
|
91
94
|
}
|
|
92
95
|
|
package/client/socket.js
CHANGED
|
@@ -4,9 +4,8 @@ import { log } from "./utils/log.js"; // this WebsocketClient is here as a defau
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
|
|
7
|
-
var Client = // eslint-disable-next-line
|
|
8
|
-
typeof __webpack_dev_server_client__ !== "undefined" ?
|
|
9
|
-
typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;
|
|
7
|
+
var Client = // eslint-disable-next-line no-nested-ternary
|
|
8
|
+
typeof __webpack_dev_server_client__ !== "undefined" ? typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;
|
|
10
9
|
/* eslint-enable camelcase */
|
|
11
10
|
|
|
12
11
|
var retries = 0;
|
|
@@ -30,7 +29,7 @@ var socket = function initSocket(url, handlers, reconnect) {
|
|
|
30
29
|
if (retries < maxRetries) {
|
|
31
30
|
// Exponentially increase timeout to reconnect.
|
|
32
31
|
// Respectfully copied from the package `got`.
|
|
33
|
-
// eslint-disable-next-line no-
|
|
32
|
+
// eslint-disable-next-line no-restricted-properties
|
|
34
33
|
var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
|
|
35
34
|
retries += 1;
|
|
36
35
|
log.info("Trying to reconnect...");
|
package/client/utils/log.js
CHANGED
|
@@ -2,7 +2,12 @@ import logger from "../modules/logger/index.js";
|
|
|
2
2
|
var name = "webpack-dev-server"; // default level is set on the client side, so it does not need
|
|
3
3
|
// to be set by the CLI or API
|
|
4
4
|
|
|
5
|
-
var defaultLevel = "info";
|
|
5
|
+
var defaultLevel = "info"; // options new options, merge with old options
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level
|
|
9
|
+
* @returns {void}
|
|
10
|
+
*/
|
|
6
11
|
|
|
7
12
|
function setLogLevel(level) {
|
|
8
13
|
logger.configureDefaultLogger({
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/* global __resourceQuery WorkerGlobalScope */
|
|
2
2
|
// Send messages to the outside, so plugins can consume it.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} type
|
|
6
|
+
* @param {any} data
|
|
7
|
+
*/
|
|
3
8
|
function sendMsg(type, data) {
|
|
4
9
|
if (typeof self !== "undefined" && (typeof WorkerGlobalScope === "undefined" || !(self instanceof WorkerGlobalScope))) {
|
|
5
10
|
self.postMessage({
|