@rsbuild/core 0.6.8 → 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} +8 -43
- package/dist/client/{hmr/index.d.ts → hmr.d.ts} +4 -0
- package/dist/client/hmr.mjs +194 -431
- package/dist/client/overlay.mjs +205 -227
- 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/url.d.ts +0 -6
package/dist/client/hmr.mjs
CHANGED
|
@@ -1,474 +1,237 @@
|
|
|
1
|
-
// src/client/
|
|
2
|
-
function _array_like_to_array(arr, len) {
|
|
3
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
4
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
5
|
-
return arr2;
|
|
6
|
-
}
|
|
7
|
-
function _array_with_holes(arr) {
|
|
8
|
-
if (Array.isArray(arr)) return arr;
|
|
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);
|
|
175
|
-
}
|
|
1
|
+
// src/client/format.ts
|
|
176
2
|
function resolveFileName(stats) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
+
`;
|
|
184
10
|
}
|
|
185
11
|
function formatMessage(stats) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
|
|
205
|
-
});
|
|
206
|
-
message = lines.join("\n");
|
|
207
|
-
message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
|
|
208
|
-
lines = message.split("\n");
|
|
209
|
-
if (lines.length > 2 && lines[1].trim() === "") {
|
|
210
|
-
lines.splice(1, 1);
|
|
211
|
-
}
|
|
212
|
-
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
|
|
213
|
-
if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
|
|
214
|
-
lines[1] = lines[1].replace("Error: ", "");
|
|
215
|
-
}
|
|
216
|
-
lines = lines.filter(function(line, index, arr) {
|
|
217
|
-
return index === 0 || line.trim() !== "" || line.trim() !== arr[index - 1].trim();
|
|
218
|
-
});
|
|
219
|
-
message = lines.join("\n");
|
|
220
|
-
return message.trim();
|
|
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();
|
|
221
30
|
}
|
|
222
31
|
function formatStatsMessages(stats) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (result.errors.length > 1) {
|
|
234
|
-
result.errors.length = 1;
|
|
235
|
-
}
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
238
|
-
// src/client/hmr/url.ts
|
|
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
|
|
239
42
|
var HMR_SOCK_PATH = "/rsbuild-hmr";
|
|
240
|
-
function formatURL(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return "".concat(protocol).concat(colon, "//").concat(hostname, ":").concat(port).concat(pathname);
|
|
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}`;
|
|
252
54
|
}
|
|
253
55
|
function getSocketUrl(urlParts) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
});
|
|
262
64
|
}
|
|
263
|
-
// src/client/hmr/index.ts
|
|
264
65
|
var isFirstCompilation = true;
|
|
265
66
|
var lastCompilationHash = null;
|
|
266
67
|
var hasCompileErrors = false;
|
|
267
68
|
function clearOutdatedErrors() {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
69
|
+
if (console.clear && hasCompileErrors) {
|
|
70
|
+
console.clear();
|
|
71
|
+
}
|
|
271
72
|
}
|
|
272
73
|
var createOverlay;
|
|
273
74
|
var clearOverlay;
|
|
274
|
-
var registerOverlay =
|
|
275
|
-
|
|
276
|
-
|
|
75
|
+
var registerOverlay = (createFn, clearFn) => {
|
|
76
|
+
createOverlay = createFn;
|
|
77
|
+
clearOverlay = clearFn;
|
|
277
78
|
};
|
|
278
79
|
function handleSuccess() {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
80
|
+
clearOutdatedErrors();
|
|
81
|
+
const isHotUpdate = !isFirstCompilation;
|
|
82
|
+
isFirstCompilation = false;
|
|
83
|
+
hasCompileErrors = false;
|
|
84
|
+
if (isHotUpdate) {
|
|
85
|
+
tryApplyUpdates();
|
|
86
|
+
}
|
|
286
87
|
}
|
|
287
88
|
function handleWarnings(warnings) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
+
}
|
|
306
107
|
}
|
|
307
108
|
function handleErrors(errors) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
} catch (err) {
|
|
322
|
-
_didIteratorError = true;
|
|
323
|
-
_iteratorError = err;
|
|
324
|
-
} finally{
|
|
325
|
-
try {
|
|
326
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
327
|
-
_iterator.return();
|
|
328
|
-
}
|
|
329
|
-
} finally{
|
|
330
|
-
if (_didIteratorError) {
|
|
331
|
-
throw _iteratorError;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (createOverlay) {
|
|
336
|
-
createOverlay(formatted.errors);
|
|
337
|
-
}
|
|
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
|
+
}
|
|
338
122
|
}
|
|
339
123
|
function isUpdateAvailable() {
|
|
340
|
-
|
|
124
|
+
return lastCompilationHash !== __webpack_hash__;
|
|
341
125
|
}
|
|
342
126
|
function tryApplyUpdates() {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
+
});
|
|
371
155
|
}
|
|
372
156
|
var MAX_RETRIES = 100;
|
|
373
157
|
var connection = null;
|
|
374
158
|
var retryCount = 0;
|
|
375
159
|
function onOpen() {
|
|
376
|
-
|
|
160
|
+
console.info("[HMR] connected.");
|
|
377
161
|
}
|
|
378
162
|
function onMessage(e) {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
function sleep() {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
case 1:
|
|
424
|
-
_state.sent();
|
|
425
|
-
retryCount++;
|
|
426
|
-
if (connection && (connection.readyState === connection.CONNECTING || connection.readyState === connection.OPEN)) {
|
|
427
|
-
retryCount = 0;
|
|
428
|
-
return [
|
|
429
|
-
2
|
|
430
|
-
];
|
|
431
|
-
}
|
|
432
|
-
if (retryCount > MAX_RETRIES) {
|
|
433
|
-
console.info("[HMR] Unable to establish a connection after exceeding the maximum retry attempts.");
|
|
434
|
-
retryCount = 0;
|
|
435
|
-
return [
|
|
436
|
-
2
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
|
-
reconnect();
|
|
440
|
-
return [
|
|
441
|
-
2
|
|
442
|
-
];
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
});
|
|
446
|
-
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();
|
|
447
207
|
}
|
|
448
208
|
function connect() {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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);
|
|
454
214
|
}
|
|
455
215
|
function removeListeners() {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
216
|
+
if (connection) {
|
|
217
|
+
connection.removeEventListener("open", onOpen);
|
|
218
|
+
connection.removeEventListener("close", onClose);
|
|
219
|
+
connection.removeEventListener("message", onMessage);
|
|
220
|
+
}
|
|
461
221
|
}
|
|
462
222
|
function reconnect() {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
223
|
+
if (connection) {
|
|
224
|
+
connection = null;
|
|
225
|
+
}
|
|
226
|
+
connect();
|
|
467
227
|
}
|
|
468
228
|
function reloadPage() {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
229
|
+
if (RSBUILD_DEV_LIVE_RELOAD) {
|
|
230
|
+
window.location.reload();
|
|
231
|
+
}
|
|
472
232
|
}
|
|
473
233
|
connect();
|
|
474
|
-
export {
|
|
234
|
+
export {
|
|
235
|
+
HMR_SOCK_PATH,
|
|
236
|
+
registerOverlay
|
|
237
|
+
};
|