@rsbuild/core 0.6.7 → 0.6.9
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/compiled/commander/{typings/index.d.ts → index.d.ts} +26 -24
- package/compiled/commander/index.js +3528 -1
- package/compiled/commander/package.json +1 -1
- package/compiled/connect-history-api-fallback/index.js +186 -1
- package/compiled/dotenv/{lib/main.d.ts → index.d.ts} +16 -12
- package/compiled/dotenv/index.js +458 -1
- package/compiled/dotenv/package.json +1 -1
- package/compiled/dotenv-expand/{lib/main.d.ts → index.d.ts} +9 -7
- package/compiled/dotenv-expand/index.js +146 -1
- package/compiled/dotenv-expand/package.json +1 -1
- package/compiled/http-compression/index.js +185 -1
- package/compiled/launch-editor-middleware/index.js +843 -1
- package/compiled/on-finished/index.d.ts +2 -2
- package/compiled/on-finished/index.js +390 -3
- package/compiled/on-finished/package.json +1 -1
- package/compiled/open/index.d.ts +1 -153
- package/compiled/open/index.js +526 -1
- package/compiled/open/package.json +1 -1
- package/compiled/sirv/index.d.ts +1 -0
- package/compiled/sirv/index.js +798 -1
- package/compiled/sirv/package.json +1 -1
- package/compiled/webpack-dev-middleware/index.d.ts +1 -0
- package/compiled/webpack-dev-middleware/index.js +6696 -0
- package/compiled/webpack-dev-middleware/license +20 -0
- package/compiled/webpack-dev-middleware/package.json +1 -0
- package/compiled/webpack-dev-middleware/schema-utils.js +1 -0
- package/compiled/ws/index.d.ts +7 -15
- package/compiled/ws/index.js +4885 -1
- package/compiled/ws/package.json +1 -1
- package/dist/cli/commands.js +1 -1
- package/dist/cli/prepare.js +1 -1
- package/dist/client/format.d.ts +5 -0
- package/dist/client/{formatStats.js → format.js} +22 -46
- package/dist/client/hmr.d.ts +5 -0
- package/dist/client/hmr.mjs +201 -474
- package/dist/client/overlay.mjs +208 -237
- package/dist/createContext.js +1 -1
- package/dist/index.js +1 -1
- package/dist/plugins/target.js +19 -16
- package/dist/provider/plugins/swc.js +1 -0
- package/dist/provider/shared.js +2 -2
- package/dist/server/devMiddleware.js +1 -1
- package/dist/server/devServer.js +6 -1
- package/dist/server/getDevMiddlewares.d.ts +3 -0
- package/dist/server/getDevMiddlewares.js +6 -8
- package/dist/server/helper.d.ts +4 -4
- package/dist/server/middlewares.d.ts +5 -2
- package/dist/server/middlewares.js +1 -7
- package/package.json +6 -5
- package/compiled/open/license +0 -9
- package/compiled/sirv/sirv.d.ts +0 -27
- package/dist/client/formatStats.d.ts +0 -12
- package/dist/client/hmr/createSocketUrl.d.ts +0 -12
- package/dist/client/hmr/index.d.ts +0 -4
package/dist/client/hmr.mjs
CHANGED
|
@@ -1,510 +1,237 @@
|
|
|
1
|
-
// src/client/
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
11
|
-
try {
|
|
12
|
-
var info = gen[key](arg);
|
|
13
|
-
var value = info.value;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
reject(error);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (info.done) {
|
|
19
|
-
resolve(value);
|
|
20
|
-
} else {
|
|
21
|
-
Promise.resolve(value).then(_next, _throw);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
function _async_to_generator(fn) {
|
|
25
|
-
return function() {
|
|
26
|
-
var self1 = this, args = arguments;
|
|
27
|
-
return new Promise(function(resolve, reject) {
|
|
28
|
-
var gen = fn.apply(self1, args);
|
|
29
|
-
function _next(value) {
|
|
30
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
-
}
|
|
32
|
-
function _throw(err) {
|
|
33
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
34
|
-
}
|
|
35
|
-
_next(undefined);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function _iterable_to_array_limit(arr, i) {
|
|
40
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
41
|
-
if (_i == null) return;
|
|
42
|
-
var _arr = [];
|
|
43
|
-
var _n = true;
|
|
44
|
-
var _d = false;
|
|
45
|
-
var _s, _e;
|
|
46
|
-
try {
|
|
47
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
48
|
-
_arr.push(_s.value);
|
|
49
|
-
if (i && _arr.length === i) break;
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
_d = true;
|
|
53
|
-
_e = err;
|
|
54
|
-
} finally{
|
|
55
|
-
try {
|
|
56
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
57
|
-
} finally{
|
|
58
|
-
if (_d) throw _e;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return _arr;
|
|
62
|
-
}
|
|
63
|
-
function _non_iterable_rest() {
|
|
64
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
65
|
-
}
|
|
66
|
-
function _sliced_to_array(arr, i) {
|
|
67
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
68
|
-
}
|
|
69
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
70
|
-
if (!o) return;
|
|
71
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
72
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
73
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
74
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
75
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
76
|
-
}
|
|
77
|
-
function _ts_generator(thisArg, body) {
|
|
78
|
-
var f, y, t, g, _ = {
|
|
79
|
-
label: 0,
|
|
80
|
-
sent: function() {
|
|
81
|
-
if (t[0] & 1) throw t[1];
|
|
82
|
-
return t[1];
|
|
83
|
-
},
|
|
84
|
-
trys: [],
|
|
85
|
-
ops: []
|
|
86
|
-
};
|
|
87
|
-
return g = {
|
|
88
|
-
next: verb(0),
|
|
89
|
-
"throw": verb(1),
|
|
90
|
-
"return": verb(2)
|
|
91
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
92
|
-
return this;
|
|
93
|
-
}), g;
|
|
94
|
-
function verb(n) {
|
|
95
|
-
return function(v) {
|
|
96
|
-
return step([
|
|
97
|
-
n,
|
|
98
|
-
v
|
|
99
|
-
]);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function step(op) {
|
|
103
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
104
|
-
while(_)try {
|
|
105
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
106
|
-
if (y = 0, t) op = [
|
|
107
|
-
op[0] & 2,
|
|
108
|
-
t.value
|
|
109
|
-
];
|
|
110
|
-
switch(op[0]){
|
|
111
|
-
case 0:
|
|
112
|
-
case 1:
|
|
113
|
-
t = op;
|
|
114
|
-
break;
|
|
115
|
-
case 4:
|
|
116
|
-
_.label++;
|
|
117
|
-
return {
|
|
118
|
-
value: op[1],
|
|
119
|
-
done: false
|
|
120
|
-
};
|
|
121
|
-
case 5:
|
|
122
|
-
_.label++;
|
|
123
|
-
y = op[1];
|
|
124
|
-
op = [
|
|
125
|
-
0
|
|
126
|
-
];
|
|
127
|
-
continue;
|
|
128
|
-
case 7:
|
|
129
|
-
op = _.ops.pop();
|
|
130
|
-
_.trys.pop();
|
|
131
|
-
continue;
|
|
132
|
-
default:
|
|
133
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
134
|
-
_ = 0;
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
138
|
-
_.label = op[1];
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
142
|
-
_.label = t[1];
|
|
143
|
-
t = op;
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
if (t && _.label < t[2]) {
|
|
147
|
-
_.label = t[2];
|
|
148
|
-
_.ops.push(op);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
if (t[2]) _.ops.pop();
|
|
152
|
-
_.trys.pop();
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
op = body.call(thisArg, _);
|
|
156
|
-
} catch (e) {
|
|
157
|
-
op = [
|
|
158
|
-
6,
|
|
159
|
-
e
|
|
160
|
-
];
|
|
161
|
-
y = 0;
|
|
162
|
-
} finally{
|
|
163
|
-
f = t = 0;
|
|
164
|
-
}
|
|
165
|
-
if (op[0] & 5) throw op[1];
|
|
166
|
-
return {
|
|
167
|
-
value: op[0] ? op[1] : void 0,
|
|
168
|
-
done: true
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
var friendlySyntaxErrorLabel = "SyntaxError:";
|
|
173
|
-
function isLikelyASyntaxError(message) {
|
|
174
|
-
return message.includes(friendlySyntaxErrorLabel);
|
|
1
|
+
// src/client/format.ts
|
|
2
|
+
function resolveFileName(stats) {
|
|
3
|
+
var _stats_moduleIdentifier_match, _stats_moduleIdentifier;
|
|
4
|
+
const regex = /(?:\!|^)([^!]+)$/;
|
|
5
|
+
var _stats_moduleIdentifier_match_at;
|
|
6
|
+
const fileName = (_stats_moduleIdentifier_match_at = (_stats_moduleIdentifier = stats.moduleIdentifier) === null || _stats_moduleIdentifier === void 0 ? void 0 : (_stats_moduleIdentifier_match = _stats_moduleIdentifier.match(regex)) === null || _stats_moduleIdentifier_match === void 0 ? void 0 : _stats_moduleIdentifier_match.at(-1)) !== null && _stats_moduleIdentifier_match_at !== void 0 ? _stats_moduleIdentifier_match_at : "";
|
|
7
|
+
return fileName ? `File: ${fileName}:1:1
|
|
8
|
+
` : `File: ${stats.moduleName}
|
|
9
|
+
`;
|
|
175
10
|
}
|
|
176
11
|
function formatMessage(stats) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
lines = lines.filter(function(line, index, arr) {
|
|
208
|
-
return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
|
|
209
|
-
});
|
|
210
|
-
message = lines.join("\n");
|
|
211
|
-
return message.trim();
|
|
212
|
-
}
|
|
213
|
-
function formatStatsMessages(json) {
|
|
214
|
-
var _json_errors, _json_warnings, _result_errors;
|
|
215
|
-
var formattedErrors = json === null || json === void 0 ? void 0 : (_json_errors = json.errors) === null || _json_errors === void 0 ? void 0 : _json_errors.map(formatMessage);
|
|
216
|
-
var formattedWarnings = json === null || json === void 0 ? void 0 : (_json_warnings = json.warnings) === null || _json_warnings === void 0 ? void 0 : _json_warnings.map(formatMessage);
|
|
217
|
-
var result = {
|
|
218
|
-
errors: formattedErrors || [],
|
|
219
|
-
warnings: formattedWarnings || [],
|
|
220
|
-
errorTips: []
|
|
221
|
-
};
|
|
222
|
-
if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
|
|
223
|
-
result.errors = result.errors.filter(isLikelyASyntaxError);
|
|
224
|
-
}
|
|
225
|
-
if (result.errors.length > 1) {
|
|
226
|
-
result.errors.length = 1;
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
// src/client/hmr/createSocketUrl.ts
|
|
12
|
+
let lines = [];
|
|
13
|
+
let message;
|
|
14
|
+
if (typeof stats === "object") {
|
|
15
|
+
const fileName = resolveFileName(stats);
|
|
16
|
+
const mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
|
|
17
|
+
const details = stats.details ? `
|
|
18
|
+
Details: ${stats.details}
|
|
19
|
+
` : "";
|
|
20
|
+
const stack = stats.stack ? `
|
|
21
|
+
${stats.stack}` : "";
|
|
22
|
+
message = `${fileName}${mainMessage}${details}${stack}`;
|
|
23
|
+
} else {
|
|
24
|
+
message = stats;
|
|
25
|
+
}
|
|
26
|
+
lines = message.split("\n");
|
|
27
|
+
lines = lines.filter((line, index, arr) => index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim());
|
|
28
|
+
message = lines.join("\n");
|
|
29
|
+
return message.trim();
|
|
30
|
+
}
|
|
31
|
+
function formatStatsMessages(stats) {
|
|
32
|
+
var _stats_errors, _stats_warnings;
|
|
33
|
+
const formattedErrors = ((_stats_errors = stats.errors) === null || _stats_errors === void 0 ? void 0 : _stats_errors.map(formatMessage)) || [];
|
|
34
|
+
const formattedWarnings = ((_stats_warnings = stats.warnings) === null || _stats_warnings === void 0 ? void 0 : _stats_warnings.map(formatMessage)) || [];
|
|
35
|
+
return {
|
|
36
|
+
errors: formattedErrors,
|
|
37
|
+
warnings: formattedWarnings
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/client/hmr.ts
|
|
231
42
|
var HMR_SOCK_PATH = "/rsbuild-hmr";
|
|
232
|
-
function
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
43
|
+
function formatURL({ port, protocol, hostname, pathname }) {
|
|
44
|
+
if (typeof URL !== "undefined") {
|
|
45
|
+
const url = new URL("http://localhost");
|
|
46
|
+
url.port = port;
|
|
47
|
+
url.hostname = hostname;
|
|
48
|
+
url.protocol = protocol;
|
|
49
|
+
url.pathname = pathname;
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
52
|
+
const colon = protocol.indexOf(":") === -1 ? ":" : "";
|
|
53
|
+
return `${protocol}${colon}//${hostname}:${port}${pathname}`;
|
|
54
|
+
}
|
|
55
|
+
function getSocketUrl(urlParts) {
|
|
56
|
+
const { location } = self;
|
|
57
|
+
const { host, port, path, protocol } = urlParts;
|
|
58
|
+
return formatURL({
|
|
59
|
+
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
60
|
+
hostname: host || location.hostname,
|
|
61
|
+
port: port || location.port,
|
|
62
|
+
pathname: path || HMR_SOCK_PATH
|
|
63
|
+
});
|
|
249
64
|
}
|
|
250
|
-
function getSocketUrl(urlParts, location) {
|
|
251
|
-
var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
|
|
252
|
-
return formatURL({
|
|
253
|
-
protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
|
|
254
|
-
hostname: host || location.hostname,
|
|
255
|
-
port: port || location.port,
|
|
256
|
-
pathname: path || HMR_SOCK_PATH
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
// src/client/hmr/index.ts
|
|
260
|
-
var options = RSBUILD_CLIENT_CONFIG;
|
|
261
|
-
var socketUrl = createSocketUrl(options);
|
|
262
|
-
var enableOverlay = !!options.overlay;
|
|
263
|
-
var enableLiveReload = RSBUILD_DEV_LIVE_RELOAD;
|
|
264
65
|
var isFirstCompilation = true;
|
|
265
|
-
var
|
|
66
|
+
var lastCompilationHash = null;
|
|
266
67
|
var hasCompileErrors = false;
|
|
267
68
|
function clearOutdatedErrors() {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
}
|
|
69
|
+
if (console.clear && hasCompileErrors) {
|
|
70
|
+
console.clear();
|
|
71
|
+
}
|
|
273
72
|
}
|
|
274
73
|
var createOverlay;
|
|
275
74
|
var clearOverlay;
|
|
276
|
-
var registerOverlay =
|
|
277
|
-
|
|
278
|
-
|
|
75
|
+
var registerOverlay = (createFn, clearFn) => {
|
|
76
|
+
createOverlay = createFn;
|
|
77
|
+
clearOverlay = clearFn;
|
|
279
78
|
};
|
|
280
79
|
function handleSuccess() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
80
|
+
clearOutdatedErrors();
|
|
81
|
+
const isHotUpdate = !isFirstCompilation;
|
|
82
|
+
isFirstCompilation = false;
|
|
83
|
+
hasCompileErrors = false;
|
|
84
|
+
if (isHotUpdate) {
|
|
85
|
+
tryApplyUpdates();
|
|
86
|
+
}
|
|
288
87
|
}
|
|
289
88
|
function handleWarnings(warnings) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
printWarnings();
|
|
310
|
-
if (isHotUpdate) {
|
|
311
|
-
tryApplyUpdates();
|
|
312
|
-
}
|
|
89
|
+
clearOutdatedErrors();
|
|
90
|
+
const isHotUpdate = !isFirstCompilation;
|
|
91
|
+
isFirstCompilation = false;
|
|
92
|
+
hasCompileErrors = false;
|
|
93
|
+
const formatted = formatStatsMessages({
|
|
94
|
+
warnings,
|
|
95
|
+
errors: []
|
|
96
|
+
});
|
|
97
|
+
for (let i = 0; i < formatted.warnings.length; i++) {
|
|
98
|
+
if (i === 5) {
|
|
99
|
+
console.warn("There were more warnings in other files, you can find a complete log in the terminal.");
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
console.warn(formatted.warnings[i]);
|
|
103
|
+
}
|
|
104
|
+
if (isHotUpdate) {
|
|
105
|
+
tryApplyUpdates();
|
|
106
|
+
}
|
|
313
107
|
}
|
|
314
108
|
function handleErrors(errors) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
} catch (err) {
|
|
330
|
-
_didIteratorError = true;
|
|
331
|
-
_iteratorError = err;
|
|
332
|
-
} finally{
|
|
333
|
-
try {
|
|
334
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
335
|
-
_iterator.return();
|
|
336
|
-
}
|
|
337
|
-
} finally{
|
|
338
|
-
if (_didIteratorError) {
|
|
339
|
-
throw _iteratorError;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (enableOverlay) {
|
|
345
|
-
createOverlay === null || createOverlay === void 0 ? void 0 : createOverlay(formatted.errors);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
function handleAvailableHash(hash) {
|
|
349
|
-
mostRecentCompilationHash = hash;
|
|
109
|
+
clearOutdatedErrors();
|
|
110
|
+
isFirstCompilation = false;
|
|
111
|
+
hasCompileErrors = true;
|
|
112
|
+
const formatted = formatStatsMessages({
|
|
113
|
+
errors,
|
|
114
|
+
warnings: []
|
|
115
|
+
});
|
|
116
|
+
for (const error of formatted.errors) {
|
|
117
|
+
console.error(error);
|
|
118
|
+
}
|
|
119
|
+
if (createOverlay) {
|
|
120
|
+
createOverlay(formatted.errors);
|
|
121
|
+
}
|
|
350
122
|
}
|
|
351
123
|
function isUpdateAvailable() {
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
function canApplyUpdates() {
|
|
355
|
-
return import.meta.webpackHot.status() === "idle";
|
|
124
|
+
return lastCompilationHash !== __webpack_hash__;
|
|
356
125
|
}
|
|
357
126
|
function tryApplyUpdates() {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
127
|
+
if (!isUpdateAvailable()) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!import.meta.webpackHot) {
|
|
131
|
+
reloadPage();
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (import.meta.webpackHot.status() !== "idle") {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
function handleApplyUpdates(err, updatedModules) {
|
|
138
|
+
const forcedReload = err || !updatedModules;
|
|
139
|
+
if (forcedReload) {
|
|
140
|
+
if (err) {
|
|
141
|
+
console.error("[HMR] Forced reload caused by: ", err);
|
|
142
|
+
}
|
|
143
|
+
reloadPage();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (isUpdateAvailable()) {
|
|
147
|
+
tryApplyUpdates();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
import.meta.webpackHot.check(true).then((updatedModules) => {
|
|
151
|
+
handleApplyUpdates(null, updatedModules);
|
|
152
|
+
}, (err) => {
|
|
153
|
+
handleApplyUpdates(err, null);
|
|
154
|
+
});
|
|
386
155
|
}
|
|
387
156
|
var MAX_RETRIES = 100;
|
|
388
157
|
var connection = null;
|
|
389
|
-
var
|
|
158
|
+
var retryCount = 0;
|
|
390
159
|
function onOpen() {
|
|
391
|
-
|
|
392
|
-
console.info("[HMR] connected.");
|
|
393
|
-
}
|
|
160
|
+
console.info("[HMR] connected.");
|
|
394
161
|
}
|
|
395
162
|
function onMessage(e) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return _sleep.apply(this, arguments);
|
|
441
|
-
}
|
|
442
|
-
function onClose() {
|
|
443
|
-
return _onClose.apply(this, arguments);
|
|
444
|
-
}
|
|
445
|
-
function _onClose() {
|
|
446
|
-
_onClose = _async_to_generator(function() {
|
|
447
|
-
return _ts_generator(this, function(_state) {
|
|
448
|
-
switch(_state.label){
|
|
449
|
-
case 0:
|
|
450
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
451
|
-
console.info("[HMR] disconnected. Attempting to reconnect.");
|
|
452
|
-
}
|
|
453
|
-
removeListeners();
|
|
454
|
-
return [
|
|
455
|
-
4,
|
|
456
|
-
sleep(1e3)
|
|
457
|
-
];
|
|
458
|
-
case 1:
|
|
459
|
-
_state.sent();
|
|
460
|
-
retry_counter++;
|
|
461
|
-
if (connection && (connection.readyState === connection.CONNECTING || connection.readyState === connection.OPEN)) {
|
|
462
|
-
retry_counter = 0;
|
|
463
|
-
return [
|
|
464
|
-
2
|
|
465
|
-
];
|
|
466
|
-
}
|
|
467
|
-
if (retry_counter > MAX_RETRIES) {
|
|
468
|
-
if (typeof console !== "undefined" && typeof console.info === "function") {
|
|
469
|
-
console.info("[HMR] Unable to establish a connection after exceeding the maximum retry attempts.");
|
|
470
|
-
}
|
|
471
|
-
retry_counter = 0;
|
|
472
|
-
return [
|
|
473
|
-
2
|
|
474
|
-
];
|
|
475
|
-
}
|
|
476
|
-
reconnect();
|
|
477
|
-
return [
|
|
478
|
-
2
|
|
479
|
-
];
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
return _onClose.apply(this, arguments);
|
|
163
|
+
const message = JSON.parse(e.data);
|
|
164
|
+
switch (message.type) {
|
|
165
|
+
case "hash":
|
|
166
|
+
lastCompilationHash = message.data;
|
|
167
|
+
if (clearOverlay && isUpdateAvailable()) {
|
|
168
|
+
clearOverlay();
|
|
169
|
+
}
|
|
170
|
+
break;
|
|
171
|
+
case "still-ok":
|
|
172
|
+
case "ok":
|
|
173
|
+
handleSuccess();
|
|
174
|
+
break;
|
|
175
|
+
case "static-changed":
|
|
176
|
+
case "content-changed":
|
|
177
|
+
reloadPage();
|
|
178
|
+
break;
|
|
179
|
+
case "warnings":
|
|
180
|
+
handleWarnings(message.data);
|
|
181
|
+
break;
|
|
182
|
+
case "errors":
|
|
183
|
+
handleErrors(message.data);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function sleep(msec = 1e3) {
|
|
188
|
+
return new Promise((resolve) => {
|
|
189
|
+
setTimeout(resolve, msec);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async function onClose() {
|
|
193
|
+
console.info("[HMR] disconnected. Attempting to reconnect.");
|
|
194
|
+
removeListeners();
|
|
195
|
+
await sleep(1e3);
|
|
196
|
+
retryCount++;
|
|
197
|
+
if (connection && (connection.readyState === connection.CONNECTING || connection.readyState === connection.OPEN)) {
|
|
198
|
+
retryCount = 0;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (retryCount > MAX_RETRIES) {
|
|
202
|
+
console.info("[HMR] Unable to establish a connection after exceeding the maximum retry attempts.");
|
|
203
|
+
retryCount = 0;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
reconnect();
|
|
484
207
|
}
|
|
485
208
|
function connect() {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
209
|
+
const socketUrl = getSocketUrl(RSBUILD_CLIENT_CONFIG);
|
|
210
|
+
connection = new WebSocket(socketUrl);
|
|
211
|
+
connection.addEventListener("open", onOpen);
|
|
212
|
+
connection.addEventListener("close", onClose);
|
|
213
|
+
connection.addEventListener("message", onMessage);
|
|
490
214
|
}
|
|
491
215
|
function removeListeners() {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
216
|
+
if (connection) {
|
|
217
|
+
connection.removeEventListener("open", onOpen);
|
|
218
|
+
connection.removeEventListener("close", onClose);
|
|
219
|
+
connection.removeEventListener("message", onMessage);
|
|
220
|
+
}
|
|
497
221
|
}
|
|
498
222
|
function reconnect() {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
223
|
+
if (connection) {
|
|
224
|
+
connection = null;
|
|
225
|
+
}
|
|
226
|
+
connect();
|
|
503
227
|
}
|
|
504
228
|
function reloadPage() {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
229
|
+
if (RSBUILD_DEV_LIVE_RELOAD) {
|
|
230
|
+
window.location.reload();
|
|
231
|
+
}
|
|
508
232
|
}
|
|
509
233
|
connect();
|
|
510
|
-
export {
|
|
234
|
+
export {
|
|
235
|
+
HMR_SOCK_PATH,
|
|
236
|
+
registerOverlay
|
|
237
|
+
};
|