webpack-dev-server 4.2.0 → 4.4.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 +60 -14
- package/bin/cli-flags.js +288 -32
- package/client/index.js +35 -16
- package/client/modules/logger/index.js +43 -14
- package/client/modules/sockjs-client/index.js +2 -1
- package/client/modules/strip-ansi/index.js +1 -1
- package/client/overlay.js +30 -5
- package/client/socket.js +7 -3
- package/client/utils/reloadApp.js +4 -12
- package/lib/Server.js +163 -109
- package/lib/options.json +275 -11
- package/package.json +6 -6
package/client/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import webpackHotLog from "webpack/hot/log.js";
|
|
|
3
3
|
import stripAnsi from "./modules/strip-ansi/index.js";
|
|
4
4
|
import parseURL from "./utils/parseURL.js";
|
|
5
5
|
import socket from "./socket.js";
|
|
6
|
-
import { show, hide } from "./overlay.js";
|
|
6
|
+
import { formatProblem, show, hide } from "./overlay.js";
|
|
7
7
|
import { log, setLogLevel } from "./utils/log.js";
|
|
8
8
|
import sendMessage from "./utils/sendMessage.js";
|
|
9
9
|
import reloadApp from "./utils/reloadApp.js";
|
|
@@ -13,8 +13,7 @@ var status = {
|
|
|
13
13
|
// TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
|
|
14
14
|
// eslint-disable-next-line camelcase
|
|
15
15
|
currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
|
|
16
|
-
};
|
|
17
|
-
|
|
16
|
+
};
|
|
18
17
|
var options = {
|
|
19
18
|
hot: false,
|
|
20
19
|
liveReload: false,
|
|
@@ -37,6 +36,10 @@ if (parsedResourceQuery.logging) {
|
|
|
37
36
|
options.logging = parsedResourceQuery.logging;
|
|
38
37
|
}
|
|
39
38
|
|
|
39
|
+
if (typeof parsedResourceQuery.reconnect !== "undefined") {
|
|
40
|
+
options.reconnect = Number(parsedResourceQuery.reconnect);
|
|
41
|
+
}
|
|
42
|
+
|
|
40
43
|
function setAllLogLevel(level) {
|
|
41
44
|
// This is needed because the HMR logger operate separately from dev server logger
|
|
42
45
|
webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
|
|
@@ -77,6 +80,7 @@ var onSocketMessage = {
|
|
|
77
80
|
sendMessage("Invalid");
|
|
78
81
|
},
|
|
79
82
|
hash: function hash(_hash) {
|
|
83
|
+
status.previousHash = status.currentHash;
|
|
80
84
|
status.currentHash = _hash;
|
|
81
85
|
},
|
|
82
86
|
logging: setAllLogLevel,
|
|
@@ -87,6 +91,13 @@ var onSocketMessage = {
|
|
|
87
91
|
|
|
88
92
|
options.overlay = value;
|
|
89
93
|
},
|
|
94
|
+
reconnect: function reconnect(value) {
|
|
95
|
+
if (parsedResourceQuery.reconnect === "false") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
options.reconnect = value;
|
|
100
|
+
},
|
|
90
101
|
progress: function progress(_progress) {
|
|
91
102
|
options.progress = _progress;
|
|
92
103
|
},
|
|
@@ -127,20 +138,24 @@ var onSocketMessage = {
|
|
|
127
138
|
warnings: function warnings(_warnings) {
|
|
128
139
|
log.warn("Warnings while compiling.");
|
|
129
140
|
|
|
130
|
-
var
|
|
131
|
-
|
|
141
|
+
var printableWarnings = _warnings.map(function (error) {
|
|
142
|
+
var _formatProblem = formatProblem("warning", error),
|
|
143
|
+
header = _formatProblem.header,
|
|
144
|
+
body = _formatProblem.body;
|
|
145
|
+
|
|
146
|
+
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
132
147
|
});
|
|
133
148
|
|
|
134
|
-
sendMessage("Warnings",
|
|
149
|
+
sendMessage("Warnings", printableWarnings);
|
|
135
150
|
|
|
136
|
-
for (var i = 0; i <
|
|
137
|
-
log.warn(
|
|
151
|
+
for (var i = 0; i < printableWarnings.length; i++) {
|
|
152
|
+
log.warn(printableWarnings[i]);
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
var needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings;
|
|
141
156
|
|
|
142
157
|
if (needShowOverlayForWarnings) {
|
|
143
|
-
show(
|
|
158
|
+
show("warning", _warnings);
|
|
144
159
|
}
|
|
145
160
|
|
|
146
161
|
reloadApp(options, status);
|
|
@@ -148,20 +163,24 @@ var onSocketMessage = {
|
|
|
148
163
|
errors: function errors(_errors) {
|
|
149
164
|
log.error("Errors while compiling. Reload prevented.");
|
|
150
165
|
|
|
151
|
-
var
|
|
152
|
-
|
|
166
|
+
var printableErrors = _errors.map(function (error) {
|
|
167
|
+
var _formatProblem2 = formatProblem("error", error),
|
|
168
|
+
header = _formatProblem2.header,
|
|
169
|
+
body = _formatProblem2.body;
|
|
170
|
+
|
|
171
|
+
return "".concat(header, "\n").concat(stripAnsi(body));
|
|
153
172
|
});
|
|
154
173
|
|
|
155
|
-
sendMessage("Errors",
|
|
174
|
+
sendMessage("Errors", printableErrors);
|
|
156
175
|
|
|
157
|
-
for (var i = 0; i <
|
|
158
|
-
log.error(
|
|
176
|
+
for (var i = 0; i < printableErrors.length; i++) {
|
|
177
|
+
log.error(printableErrors[i]);
|
|
159
178
|
}
|
|
160
179
|
|
|
161
180
|
var needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors;
|
|
162
181
|
|
|
163
182
|
if (needShowOverlayForErrors) {
|
|
164
|
-
show(
|
|
183
|
+
show("error", _errors);
|
|
165
184
|
}
|
|
166
185
|
},
|
|
167
186
|
error: function error(_error) {
|
|
@@ -178,4 +197,4 @@ var onSocketMessage = {
|
|
|
178
197
|
}
|
|
179
198
|
};
|
|
180
199
|
var socketURL = createSocketURL(parsedResourceQuery);
|
|
181
|
-
socket(socketURL, onSocketMessage);
|
|
200
|
+
socket(socketURL, onSocketMessage, options.reconnect);
|
|
@@ -91,33 +91,61 @@ function _createClass(Constructor, protoProps, staticProps) {
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
var LogType = Object.freeze({
|
|
94
|
-
error:
|
|
94
|
+
error:
|
|
95
|
+
/** @type {"error"} */
|
|
96
|
+
"error",
|
|
95
97
|
// message, c style arguments
|
|
96
|
-
warn:
|
|
98
|
+
warn:
|
|
99
|
+
/** @type {"warn"} */
|
|
100
|
+
"warn",
|
|
97
101
|
// message, c style arguments
|
|
98
|
-
info:
|
|
102
|
+
info:
|
|
103
|
+
/** @type {"info"} */
|
|
104
|
+
"info",
|
|
99
105
|
// message, c style arguments
|
|
100
|
-
log:
|
|
106
|
+
log:
|
|
107
|
+
/** @type {"log"} */
|
|
108
|
+
"log",
|
|
101
109
|
// message, c style arguments
|
|
102
|
-
debug:
|
|
110
|
+
debug:
|
|
111
|
+
/** @type {"debug"} */
|
|
112
|
+
"debug",
|
|
103
113
|
// message, c style arguments
|
|
104
|
-
trace:
|
|
114
|
+
trace:
|
|
115
|
+
/** @type {"trace"} */
|
|
116
|
+
"trace",
|
|
105
117
|
// no arguments
|
|
106
|
-
group:
|
|
118
|
+
group:
|
|
119
|
+
/** @type {"group"} */
|
|
120
|
+
"group",
|
|
107
121
|
// [label]
|
|
108
|
-
groupCollapsed:
|
|
122
|
+
groupCollapsed:
|
|
123
|
+
/** @type {"groupCollapsed"} */
|
|
124
|
+
"groupCollapsed",
|
|
109
125
|
// [label]
|
|
110
|
-
groupEnd:
|
|
126
|
+
groupEnd:
|
|
127
|
+
/** @type {"groupEnd"} */
|
|
128
|
+
"groupEnd",
|
|
111
129
|
// [label]
|
|
112
|
-
profile:
|
|
130
|
+
profile:
|
|
131
|
+
/** @type {"profile"} */
|
|
132
|
+
"profile",
|
|
113
133
|
// [profileName]
|
|
114
|
-
profileEnd:
|
|
134
|
+
profileEnd:
|
|
135
|
+
/** @type {"profileEnd"} */
|
|
136
|
+
"profileEnd",
|
|
115
137
|
// [profileName]
|
|
116
|
-
time:
|
|
138
|
+
time:
|
|
139
|
+
/** @type {"time"} */
|
|
140
|
+
"time",
|
|
117
141
|
// name, time as [seconds, nanoseconds]
|
|
118
|
-
clear:
|
|
142
|
+
clear:
|
|
143
|
+
/** @type {"clear"} */
|
|
144
|
+
"clear",
|
|
119
145
|
// no arguments
|
|
120
|
-
status:
|
|
146
|
+
status:
|
|
147
|
+
/** @type {"status"} */
|
|
148
|
+
"status" // message, arguments
|
|
121
149
|
|
|
122
150
|
});
|
|
123
151
|
exports.LogType = LogType;
|
|
@@ -314,6 +342,7 @@ var WebpackLogger = /*#__PURE__*/function () {
|
|
|
314
342
|
if (this[TIMERS_AGGREGATES_SYMBOL] === undefined) return;
|
|
315
343
|
var time = this[TIMERS_AGGREGATES_SYMBOL].get(label);
|
|
316
344
|
if (time === undefined) return;
|
|
345
|
+
this[TIMERS_AGGREGATES_SYMBOL].delete(label);
|
|
317
346
|
this[LOG_SYMBOL](LogType.time, [label].concat(_toConsumableArray(time)));
|
|
318
347
|
}
|
|
319
348
|
}]);
|
|
@@ -2958,7 +2958,8 @@ if ('ab'.split(/(?:ab)*/).length !== 2 || '.'.split(/(.?)(.?)/).length !== 4 ||
|
|
|
2958
2958
|
}
|
|
2959
2959
|
|
|
2960
2960
|
var output = [],
|
|
2961
|
-
flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.extended ? 'x' : '') + (
|
|
2961
|
+
flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.extended ? 'x' : '') + ( // Proposed for ES6
|
|
2962
|
+
separator.sticky ? 'y' : ''),
|
|
2962
2963
|
// Firefox 3+
|
|
2963
2964
|
lastLastIndex = 0,
|
|
2964
2965
|
// Make `global` and avoid `lastIndex` issues by working with a copy
|
|
@@ -39,7 +39,7 @@ function ansiRegex() {
|
|
|
39
39
|
_ref$onlyFirst = _ref.onlyFirst,
|
|
40
40
|
onlyFirst = _ref$onlyFirst === void 0 ? false : _ref$onlyFirst;
|
|
41
41
|
|
|
42
|
-
var pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]
|
|
42
|
+
var pattern = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
|
|
43
43
|
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
44
44
|
}
|
|
45
45
|
|
package/client/overlay.js
CHANGED
|
@@ -108,19 +108,44 @@ function hide() {
|
|
|
108
108
|
document.body.removeChild(iframeContainerElement);
|
|
109
109
|
iframeContainerElement = null;
|
|
110
110
|
containerElement = null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function formatProblem(type, item) {
|
|
114
|
+
var header = type === "warning" ? "WARNING" : "ERROR";
|
|
115
|
+
var body = "";
|
|
116
|
+
|
|
117
|
+
if (typeof item === "string") {
|
|
118
|
+
body += item;
|
|
119
|
+
} else {
|
|
120
|
+
var file = item.file || ""; // eslint-disable-next-line no-nested-ternary
|
|
121
|
+
|
|
122
|
+
var moduleName = item.moduleName ? item.moduleName.indexOf("!") !== -1 ? "".concat(item.moduleName.replace(/^(\s|\S)*!/, ""), " (").concat(item.moduleName, ")") : "".concat(item.moduleName) : "";
|
|
123
|
+
var loc = item.loc;
|
|
124
|
+
header += "".concat(moduleName || file ? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : "") : file).concat(loc ? " ".concat(loc) : "") : "");
|
|
125
|
+
body += item.message || "";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
header: header,
|
|
130
|
+
body: body
|
|
131
|
+
};
|
|
111
132
|
} // Compilation with errors (e.g. syntax error or missing modules).
|
|
112
133
|
|
|
113
134
|
|
|
114
|
-
function show(
|
|
135
|
+
function show(type, messages) {
|
|
115
136
|
ensureOverlayExists(function () {
|
|
116
137
|
messages.forEach(function (message) {
|
|
117
138
|
var entryElement = document.createElement("div");
|
|
118
139
|
var typeElement = document.createElement("span");
|
|
119
|
-
|
|
140
|
+
|
|
141
|
+
var _formatProblem = formatProblem(type, message),
|
|
142
|
+
header = _formatProblem.header,
|
|
143
|
+
body = _formatProblem.body;
|
|
144
|
+
|
|
145
|
+
typeElement.innerText = header;
|
|
120
146
|
typeElement.style.color = "#".concat(colors.red); // Make it look similar to our terminal.
|
|
121
147
|
|
|
122
|
-
var
|
|
123
|
-
var text = ansiHTML(encode(errorMessage));
|
|
148
|
+
var text = ansiHTML(encode(body));
|
|
124
149
|
var messageTextNode = document.createElement("div");
|
|
125
150
|
messageTextNode.innerHTML = text;
|
|
126
151
|
entryElement.appendChild(typeElement);
|
|
@@ -134,4 +159,4 @@ function show(messages, type) {
|
|
|
134
159
|
});
|
|
135
160
|
}
|
|
136
161
|
|
|
137
|
-
export { show, hide };
|
|
162
|
+
export { formatProblem, show, hide };
|
package/client/socket.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* global __webpack_dev_server_client__ */
|
|
2
|
-
import WebSocketClient from "./clients/WebSocketClient.js";
|
|
2
|
+
import WebSocketClient from "./clients/WebSocketClient.js";
|
|
3
|
+
import { log } from "./utils/log.js"; // this WebsocketClient is here as a default fallback, in case the client is not injected
|
|
3
4
|
|
|
4
5
|
/* eslint-disable camelcase */
|
|
5
6
|
|
|
@@ -9,12 +10,14 @@ typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_ser
|
|
|
9
10
|
/* eslint-enable camelcase */
|
|
10
11
|
|
|
11
12
|
var retries = 0;
|
|
13
|
+
var maxRetries = 10;
|
|
12
14
|
var client = null;
|
|
13
15
|
|
|
14
|
-
var socket = function initSocket(url, handlers) {
|
|
16
|
+
var socket = function initSocket(url, handlers, reconnect) {
|
|
15
17
|
client = new Client(url);
|
|
16
18
|
client.onOpen(function () {
|
|
17
19
|
retries = 0;
|
|
20
|
+
maxRetries = reconnect;
|
|
18
21
|
});
|
|
19
22
|
client.onClose(function () {
|
|
20
23
|
if (retries === 0) {
|
|
@@ -24,12 +27,13 @@ var socket = function initSocket(url, handlers) {
|
|
|
24
27
|
|
|
25
28
|
client = null; // After 10 retries stop trying, to prevent logspam.
|
|
26
29
|
|
|
27
|
-
if (retries
|
|
30
|
+
if (retries < maxRetries) {
|
|
28
31
|
// Exponentially increase timeout to reconnect.
|
|
29
32
|
// Respectfully copied from the package `got`.
|
|
30
33
|
// eslint-disable-next-line no-mixed-operators, no-restricted-properties
|
|
31
34
|
var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
|
|
32
35
|
retries += 1;
|
|
36
|
+
log.info("Trying to reconnect...");
|
|
33
37
|
setTimeout(function () {
|
|
34
38
|
socket(url, handlers);
|
|
35
39
|
}, retryInMs);
|
|
@@ -8,21 +8,13 @@ function reloadApp(_ref, status) {
|
|
|
8
8
|
|
|
9
9
|
if (status.isUnloading) {
|
|
10
10
|
return;
|
|
11
|
-
}
|
|
12
|
-
|
|
11
|
+
}
|
|
13
12
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var isInitial = status.currentHash.indexOf(webpackHash) === 0;
|
|
13
|
+
var currentHash = status.currentHash,
|
|
14
|
+
previousHash = status.previousHash;
|
|
15
|
+
var isInitial = currentHash.indexOf(previousHash) >= 0;
|
|
18
16
|
|
|
19
17
|
if (isInitial) {
|
|
20
|
-
var isLegacyInitial = webpackHash === "" && hot === false && liveReload === true;
|
|
21
|
-
|
|
22
|
-
if (isLegacyInitial) {
|
|
23
|
-
status.previousHash = status.currentHash;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
18
|
return;
|
|
27
19
|
}
|
|
28
20
|
|