webpack-dev-server 4.7.3 → 4.8.1
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 +43 -6
- package/bin/cli-flags.js +34 -22
- package/client/index.js +1 -1
- package/client/modules/sockjs-client/index.js +76 -1120
- package/client/socket.js +5 -2
- package/client/utils/createSocketURL.js +1 -1
- package/client/utils/parseURL.js +1 -1
- package/client/utils/stripAnsi.js +20 -0
- package/lib/Server.js +136 -134
- package/lib/options.json +89 -21
- package/package.json +34 -33
- package/types/bin/cli-flags.d.ts +63 -33
- package/types/lib/Server.d.ts +464 -307
- package/types/lib/servers/WebsocketServer.d.ts +1 -1
- package/client/modules/strip-ansi/index.js +0 -119
package/client/socket.js
CHANGED
|
@@ -9,8 +9,11 @@ typeof __webpack_dev_server_client__ !== "undefined" ? typeof __webpack_dev_serv
|
|
|
9
9
|
/* eslint-enable camelcase */
|
|
10
10
|
|
|
11
11
|
var retries = 0;
|
|
12
|
-
var maxRetries = 10;
|
|
13
|
-
|
|
12
|
+
var maxRetries = 10; // Initialized client is exported so external consumers can utilize the same instance
|
|
13
|
+
// It is mutable to enforce singleton
|
|
14
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
15
|
+
|
|
16
|
+
export var client = null;
|
|
14
17
|
/**
|
|
15
18
|
* @param {string} url
|
|
16
19
|
* @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers
|
package/client/utils/parseURL.js
CHANGED
|
@@ -9,7 +9,7 @@ function parseURL(resourceQuery) {
|
|
|
9
9
|
var options = {};
|
|
10
10
|
|
|
11
11
|
if (typeof resourceQuery === "string" && resourceQuery !== "") {
|
|
12
|
-
var searchParams = resourceQuery.
|
|
12
|
+
var searchParams = resourceQuery.slice(1).split("&");
|
|
13
13
|
|
|
14
14
|
for (var i = 0; i < searchParams.length; i++) {
|
|
15
15
|
var pair = searchParams[i].split("=");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var ansiRegex = new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|"), "g");
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
|
|
5
|
+
* Adapted from code originally released by Sindre Sorhus
|
|
6
|
+
* Licensed the MIT License
|
|
7
|
+
*
|
|
8
|
+
* @param {string} string
|
|
9
|
+
* @return {string}
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function stripAnsi(string) {
|
|
13
|
+
if (typeof string !== "string") {
|
|
14
|
+
throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return string.replace(ansiRegex, "");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default stripAnsi;
|
package/lib/Server.js
CHANGED
|
@@ -28,8 +28,8 @@ const schema = require("./options.json");
|
|
|
28
28
|
/** @typedef {import("chokidar").WatchOptions} WatchOptions */
|
|
29
29
|
/** @typedef {import("chokidar").FSWatcher} FSWatcher */
|
|
30
30
|
/** @typedef {import("connect-history-api-fallback").Options} ConnectHistoryApiFallbackOptions */
|
|
31
|
-
/** @typedef {import("bonjour").Bonjour} Bonjour */
|
|
32
|
-
/** @typedef {import("bonjour").
|
|
31
|
+
/** @typedef {import("bonjour-service").Bonjour} Bonjour */
|
|
32
|
+
/** @typedef {import("bonjour-service").Service} BonjourOptions */
|
|
33
33
|
/** @typedef {import("http-proxy-middleware").RequestHandler} RequestHandler */
|
|
34
34
|
/** @typedef {import("http-proxy-middleware").Options} HttpProxyMiddlewareOptions */
|
|
35
35
|
/** @typedef {import("http-proxy-middleware").Filter} HttpProxyMiddlewareOptionsFilter */
|
|
@@ -64,7 +64,7 @@ const schema = require("./options.json");
|
|
|
64
64
|
/**
|
|
65
65
|
* @typedef {Object} WatchFiles
|
|
66
66
|
* @property {string | string[]} paths
|
|
67
|
-
* @property {WatchOptions & { aggregateTimeout?: number, ignored?:
|
|
67
|
+
* @property {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [options]
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -73,7 +73,7 @@ const schema = require("./options.json");
|
|
|
73
73
|
* @property {string | string[]} [publicPath]
|
|
74
74
|
* @property {boolean | ServeIndexOptions} [serveIndex]
|
|
75
75
|
* @property {ServeStaticOptions} [staticOptions]
|
|
76
|
-
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?:
|
|
76
|
+
* @property {boolean | WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} [watch]
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
79
|
/**
|
|
@@ -110,22 +110,22 @@ const schema = require("./options.json");
|
|
|
110
110
|
*/
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
* @
|
|
113
|
+
* @callback ByPass
|
|
114
|
+
* @param {Request} req
|
|
115
|
+
* @param {Response} res
|
|
116
|
+
* @param {ProxyConfigArrayItem} proxyConfig
|
|
114
117
|
*/
|
|
115
118
|
|
|
116
119
|
/**
|
|
117
|
-
* @typedef {HttpProxyMiddlewareOptions
|
|
120
|
+
* @typedef {{ path?: HttpProxyMiddlewareOptionsFilter | undefined, context?: HttpProxyMiddlewareOptionsFilter | undefined } & { bypass?: ByPass } & HttpProxyMiddlewareOptions } ProxyConfigArrayItem
|
|
118
121
|
*/
|
|
119
122
|
|
|
120
123
|
/**
|
|
121
|
-
* @
|
|
122
|
-
* @param {Request} req
|
|
123
|
-
* @param {Response} res
|
|
124
|
-
* @param {ProxyConfigArray} proxyConfig
|
|
124
|
+
* @typedef {(ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[]} ProxyConfigArray
|
|
125
125
|
*/
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* @typedef {{
|
|
128
|
+
* @typedef {{ [url: string]: string | ProxyConfigArrayItem }} ProxyConfigMap
|
|
129
129
|
*/
|
|
130
130
|
|
|
131
131
|
/**
|
|
@@ -187,14 +187,14 @@ const schema = require("./options.json");
|
|
|
187
187
|
* @property {"auto" | "all" | string | string[]} [allowedHosts]
|
|
188
188
|
* @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
|
|
189
189
|
* @property {boolean} [setupExitSignals]
|
|
190
|
-
* @property {boolean | BonjourOptions} [bonjour]
|
|
190
|
+
* @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
|
|
191
191
|
* @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
|
|
192
192
|
* @property {boolean | string | Static | Array<string | Static>} [static]
|
|
193
193
|
* @property {boolean | ServerOptions} [https]
|
|
194
194
|
* @property {boolean} [http2]
|
|
195
195
|
* @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server]
|
|
196
196
|
* @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer]
|
|
197
|
-
* @property {ProxyConfigMap |
|
|
197
|
+
* @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy]
|
|
198
198
|
* @property {boolean | string | Open | Array<string | Open>} [open]
|
|
199
199
|
* @property {boolean} [setupExitSignals]
|
|
200
200
|
* @property {boolean | ClientConfiguration} [client]
|
|
@@ -754,7 +754,7 @@ class Server {
|
|
|
754
754
|
// TODO remove `{}` after drop webpack v4 support
|
|
755
755
|
const compilerWatchOptions = compilerOptions.watchOptions || {};
|
|
756
756
|
/**
|
|
757
|
-
* @param {WatchOptions &
|
|
757
|
+
* @param {WatchOptions & { aggregateTimeout?: number, ignored?: WatchOptions["ignored"], poll?: number | boolean }} watchOptions
|
|
758
758
|
* @returns {WatchOptions}
|
|
759
759
|
*/
|
|
760
760
|
const getWatchOptions = (watchOptions = {}) => {
|
|
@@ -1132,13 +1132,15 @@ class Server {
|
|
|
1132
1132
|
|
|
1133
1133
|
// cert is more than 30 days old, kill it with fire
|
|
1134
1134
|
if ((now - Number(certificateStat.ctime)) / certificateTtl > 30) {
|
|
1135
|
-
const
|
|
1135
|
+
const { promisify } = require("util");
|
|
1136
|
+
const rimraf = require("rimraf");
|
|
1137
|
+
const del = promisify(rimraf);
|
|
1136
1138
|
|
|
1137
1139
|
this.logger.info(
|
|
1138
1140
|
"SSL certificate is more than 30 days old. Removing..."
|
|
1139
1141
|
);
|
|
1140
1142
|
|
|
1141
|
-
await del(
|
|
1143
|
+
await del(certificatePath);
|
|
1142
1144
|
|
|
1143
1145
|
certificateExists = false;
|
|
1144
1146
|
}
|
|
@@ -1380,10 +1382,10 @@ class Server {
|
|
|
1380
1382
|
Object.prototype.hasOwnProperty.call(options.proxy, "target") ||
|
|
1381
1383
|
Object.prototype.hasOwnProperty.call(options.proxy, "router")
|
|
1382
1384
|
) {
|
|
1383
|
-
/** @type {
|
|
1385
|
+
/** @type {ProxyConfigArray} */
|
|
1384
1386
|
(options.proxy) = [/** @type {ProxyConfigMap} */ (options.proxy)];
|
|
1385
1387
|
} else {
|
|
1386
|
-
/** @type {
|
|
1388
|
+
/** @type {ProxyConfigArray} */
|
|
1387
1389
|
(options.proxy) = Object.keys(options.proxy).map(
|
|
1388
1390
|
/**
|
|
1389
1391
|
* @param {string} context
|
|
@@ -1421,50 +1423,48 @@ class Server {
|
|
|
1421
1423
|
}
|
|
1422
1424
|
}
|
|
1423
1425
|
|
|
1424
|
-
/** @type {
|
|
1426
|
+
/** @type {ProxyConfigArray} */
|
|
1425
1427
|
(options.proxy) =
|
|
1426
|
-
/** @type {
|
|
1427
|
-
(options.proxy).map(
|
|
1428
|
+
/** @type {ProxyConfigArray} */
|
|
1429
|
+
(options.proxy).map((item) => {
|
|
1430
|
+
if (typeof item === "function") {
|
|
1431
|
+
return item;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1428
1434
|
/**
|
|
1429
|
-
* @param {
|
|
1430
|
-
* @returns {
|
|
1435
|
+
* @param {"info" | "warn" | "error" | "debug" | "silent" | undefined | "none" | "log" | "verbose"} level
|
|
1436
|
+
* @returns {"info" | "warn" | "error" | "debug" | "silent" | undefined}
|
|
1431
1437
|
*/
|
|
1432
|
-
(
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
*/
|
|
1437
|
-
const getLogLevelForProxy = (level) => {
|
|
1438
|
-
if (level === "none") {
|
|
1439
|
-
return "silent";
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
if (level === "log") {
|
|
1443
|
-
return "info";
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
if (level === "verbose") {
|
|
1447
|
-
return "debug";
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
return level;
|
|
1451
|
-
};
|
|
1438
|
+
const getLogLevelForProxy = (level) => {
|
|
1439
|
+
if (level === "none") {
|
|
1440
|
+
return "silent";
|
|
1441
|
+
}
|
|
1452
1442
|
|
|
1453
|
-
if (
|
|
1454
|
-
|
|
1455
|
-
compilerOptions.infrastructureLogging
|
|
1456
|
-
? compilerOptions.infrastructureLogging.level
|
|
1457
|
-
: "info"
|
|
1458
|
-
);
|
|
1443
|
+
if (level === "log") {
|
|
1444
|
+
return "info";
|
|
1459
1445
|
}
|
|
1460
1446
|
|
|
1461
|
-
if (
|
|
1462
|
-
|
|
1447
|
+
if (level === "verbose") {
|
|
1448
|
+
return "debug";
|
|
1463
1449
|
}
|
|
1464
1450
|
|
|
1465
|
-
return
|
|
1451
|
+
return level;
|
|
1452
|
+
};
|
|
1453
|
+
|
|
1454
|
+
if (typeof item.logLevel === "undefined") {
|
|
1455
|
+
item.logLevel = getLogLevelForProxy(
|
|
1456
|
+
compilerOptions.infrastructureLogging
|
|
1457
|
+
? compilerOptions.infrastructureLogging.level
|
|
1458
|
+
: "info"
|
|
1459
|
+
);
|
|
1466
1460
|
}
|
|
1467
|
-
|
|
1461
|
+
|
|
1462
|
+
if (typeof item.logProvider === "undefined") {
|
|
1463
|
+
item.logProvider = () => this.logger;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
return item;
|
|
1467
|
+
});
|
|
1468
1468
|
}
|
|
1469
1469
|
|
|
1470
1470
|
if (typeof options.setupExitSignals === "undefined") {
|
|
@@ -2124,7 +2124,7 @@ class Server {
|
|
|
2124
2124
|
const { createProxyMiddleware } = require("http-proxy-middleware");
|
|
2125
2125
|
|
|
2126
2126
|
/**
|
|
2127
|
-
* @param {
|
|
2127
|
+
* @param {ProxyConfigArrayItem} proxyConfig
|
|
2128
2128
|
* @returns {RequestHandler | undefined}
|
|
2129
2129
|
*/
|
|
2130
2130
|
const getProxyMiddleware = (proxyConfig) => {
|
|
@@ -2160,93 +2160,91 @@ class Server {
|
|
|
2160
2160
|
* }
|
|
2161
2161
|
* ]
|
|
2162
2162
|
*/
|
|
2163
|
-
/** @type {
|
|
2164
|
-
(this.options.proxy).forEach(
|
|
2163
|
+
/** @type {ProxyConfigArray} */
|
|
2164
|
+
(this.options.proxy).forEach((proxyConfigOrCallback) => {
|
|
2165
2165
|
/**
|
|
2166
|
-
* @
|
|
2166
|
+
* @type {RequestHandler}
|
|
2167
2167
|
*/
|
|
2168
|
-
|
|
2169
|
-
/**
|
|
2170
|
-
* @type {RequestHandler}
|
|
2171
|
-
*/
|
|
2172
|
-
let proxyMiddleware;
|
|
2168
|
+
let proxyMiddleware;
|
|
2173
2169
|
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2170
|
+
let proxyConfig =
|
|
2171
|
+
typeof proxyConfigOrCallback === "function"
|
|
2172
|
+
? proxyConfigOrCallback()
|
|
2173
|
+
: proxyConfigOrCallback;
|
|
2178
2174
|
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2175
|
+
proxyMiddleware =
|
|
2176
|
+
/** @type {RequestHandler} */
|
|
2177
|
+
(getProxyMiddleware(proxyConfig));
|
|
2182
2178
|
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2179
|
+
if (proxyConfig.ws) {
|
|
2180
|
+
this.webSocketProxies.push(proxyMiddleware);
|
|
2181
|
+
}
|
|
2186
2182
|
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
}
|
|
2183
|
+
/**
|
|
2184
|
+
* @param {Request} req
|
|
2185
|
+
* @param {Response} res
|
|
2186
|
+
* @param {NextFunction} next
|
|
2187
|
+
* @returns {Promise<void>}
|
|
2188
|
+
*/
|
|
2189
|
+
const handler = async (req, res, next) => {
|
|
2190
|
+
if (typeof proxyConfigOrCallback === "function") {
|
|
2191
|
+
const newProxyConfig = proxyConfigOrCallback(req, res, next);
|
|
2192
|
+
|
|
2193
|
+
if (newProxyConfig !== proxyConfig) {
|
|
2194
|
+
proxyConfig = newProxyConfig;
|
|
2195
|
+
proxyMiddleware =
|
|
2196
|
+
/** @type {RequestHandler} */
|
|
2197
|
+
(getProxyMiddleware(proxyConfig));
|
|
2203
2198
|
}
|
|
2199
|
+
}
|
|
2204
2200
|
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
}
|
|
2201
|
+
// - Check if we have a bypass function defined
|
|
2202
|
+
// - In case the bypass function is defined we'll retrieve the
|
|
2203
|
+
// bypassUrl from it otherwise bypassUrl would be null
|
|
2204
|
+
// TODO remove in the next major in favor `context` and `router` options
|
|
2205
|
+
const isByPassFuncDefined = typeof proxyConfig.bypass === "function";
|
|
2206
|
+
const bypassUrl = isByPassFuncDefined
|
|
2207
|
+
? await /** @type {ByPass} */ (proxyConfig.bypass)(
|
|
2208
|
+
req,
|
|
2209
|
+
res,
|
|
2210
|
+
proxyConfig
|
|
2211
|
+
)
|
|
2212
|
+
: null;
|
|
2213
|
+
|
|
2214
|
+
if (typeof bypassUrl === "boolean") {
|
|
2215
|
+
// skip the proxy
|
|
2216
|
+
// @ts-ignore
|
|
2217
|
+
req.url = null;
|
|
2218
|
+
next();
|
|
2219
|
+
} else if (typeof bypassUrl === "string") {
|
|
2220
|
+
// byPass to that url
|
|
2221
|
+
req.url = bypassUrl;
|
|
2222
|
+
next();
|
|
2223
|
+
} else if (proxyMiddleware) {
|
|
2224
|
+
return proxyMiddleware(req, res, next);
|
|
2225
|
+
} else {
|
|
2226
|
+
next();
|
|
2227
|
+
}
|
|
2228
|
+
};
|
|
2230
2229
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
);
|
|
2230
|
+
middlewares.push({
|
|
2231
|
+
name: "http-proxy-middleware",
|
|
2232
|
+
middleware: handler,
|
|
2233
|
+
});
|
|
2234
|
+
// Also forward error requests to the proxy so it can handle them.
|
|
2235
|
+
middlewares.push({
|
|
2236
|
+
name: "http-proxy-middleware-error-handler",
|
|
2237
|
+
middleware:
|
|
2238
|
+
/**
|
|
2239
|
+
* @param {Error} error
|
|
2240
|
+
* @param {Request} req
|
|
2241
|
+
* @param {Response} res
|
|
2242
|
+
* @param {NextFunction} next
|
|
2243
|
+
* @returns {any}
|
|
2244
|
+
*/
|
|
2245
|
+
(error, req, res, next) => handler(req, res, next),
|
|
2246
|
+
});
|
|
2247
|
+
});
|
|
2250
2248
|
|
|
2251
2249
|
middlewares.push({
|
|
2252
2250
|
name: "webpack-dev-middleware",
|
|
@@ -2595,14 +2593,18 @@ class Server {
|
|
|
2595
2593
|
* @returns {void}
|
|
2596
2594
|
*/
|
|
2597
2595
|
runBonjour() {
|
|
2596
|
+
const { Bonjour } = require("bonjour-service");
|
|
2598
2597
|
/**
|
|
2599
2598
|
* @private
|
|
2600
|
-
* @type {
|
|
2599
|
+
* @type {Bonjour | undefined}
|
|
2601
2600
|
*/
|
|
2602
|
-
this.bonjour =
|
|
2601
|
+
this.bonjour = new Bonjour();
|
|
2603
2602
|
this.bonjour.publish({
|
|
2603
|
+
// @ts-expect-error
|
|
2604
2604
|
name: `Webpack Dev Server ${os.hostname()}:${this.options.port}`,
|
|
2605
|
+
// @ts-expect-error
|
|
2605
2606
|
port: /** @type {number} */ (this.options.port),
|
|
2607
|
+
// @ts-expect-error
|
|
2606
2608
|
type:
|
|
2607
2609
|
/** @type {ServerConfiguration} */
|
|
2608
2610
|
(this.options.server).type === "http" ? "http" : "https",
|