@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.
Files changed (53) hide show
  1. package/compiled/commander/{typings/index.d.ts → index.d.ts} +26 -24
  2. package/compiled/commander/index.js +3528 -1
  3. package/compiled/commander/package.json +1 -1
  4. package/compiled/connect-history-api-fallback/index.js +186 -1
  5. package/compiled/dotenv/{lib/main.d.ts → index.d.ts} +16 -12
  6. package/compiled/dotenv/index.js +458 -1
  7. package/compiled/dotenv/package.json +1 -1
  8. package/compiled/dotenv-expand/{lib/main.d.ts → index.d.ts} +9 -7
  9. package/compiled/dotenv-expand/index.js +146 -1
  10. package/compiled/dotenv-expand/package.json +1 -1
  11. package/compiled/http-compression/index.js +185 -1
  12. package/compiled/launch-editor-middleware/index.js +843 -1
  13. package/compiled/on-finished/index.d.ts +2 -2
  14. package/compiled/on-finished/index.js +390 -3
  15. package/compiled/on-finished/package.json +1 -1
  16. package/compiled/open/index.d.ts +1 -153
  17. package/compiled/open/index.js +526 -1
  18. package/compiled/open/package.json +1 -1
  19. package/compiled/sirv/index.d.ts +1 -0
  20. package/compiled/sirv/index.js +798 -1
  21. package/compiled/sirv/package.json +1 -1
  22. package/compiled/webpack-dev-middleware/index.d.ts +1 -0
  23. package/compiled/webpack-dev-middleware/index.js +6696 -0
  24. package/compiled/webpack-dev-middleware/license +20 -0
  25. package/compiled/webpack-dev-middleware/package.json +1 -0
  26. package/compiled/webpack-dev-middleware/schema-utils.js +1 -0
  27. package/compiled/ws/index.d.ts +7 -15
  28. package/compiled/ws/index.js +4885 -1
  29. package/compiled/ws/package.json +1 -1
  30. package/dist/cli/commands.js +1 -1
  31. package/dist/cli/prepare.js +1 -1
  32. package/dist/client/format.d.ts +5 -0
  33. package/dist/client/{formatStats.js → format.js} +8 -43
  34. package/dist/client/{hmr/index.d.ts → hmr.d.ts} +4 -0
  35. package/dist/client/hmr.mjs +194 -431
  36. package/dist/client/overlay.mjs +205 -227
  37. package/dist/createContext.js +1 -1
  38. package/dist/index.js +1 -1
  39. package/dist/plugins/target.js +19 -16
  40. package/dist/provider/plugins/swc.js +1 -0
  41. package/dist/provider/shared.js +2 -2
  42. package/dist/server/devMiddleware.js +1 -1
  43. package/dist/server/devServer.js +6 -1
  44. package/dist/server/getDevMiddlewares.d.ts +3 -0
  45. package/dist/server/getDevMiddlewares.js +6 -8
  46. package/dist/server/helper.d.ts +4 -4
  47. package/dist/server/middlewares.d.ts +5 -2
  48. package/dist/server/middlewares.js +1 -7
  49. package/package.json +6 -5
  50. package/compiled/open/license +0 -9
  51. package/compiled/sirv/sirv.d.ts +0 -27
  52. package/dist/client/formatStats.d.ts +0 -12
  53. package/dist/client/hmr/url.d.ts +0 -6
@@ -1,474 +1,237 @@
1
- // src/client/formatStats.ts
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
- var _stats_moduleIdentifier_match, _stats_moduleIdentifier;
178
- var regex = /(?:\!|^)([^!]+)$/;
179
- var _stats_moduleIdentifier_match_at;
180
- var 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 : "";
181
- return fileName ? // add default column add lines for linking
182
- "File: ".concat(fileName, ":1:1\n") : // fallback to moduleName if moduleIdentifier parse failed
183
- "File: ".concat(stats.moduleName, "\n");
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
- var lines = [];
187
- var message;
188
- if (typeof stats === "object") {
189
- var fileName = resolveFileName(stats);
190
- var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
191
- var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
192
- var stack = stats.stack ? "\n".concat(stats.stack) : "";
193
- message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
194
- } else {
195
- message = stats;
196
- }
197
- lines = message.split("\n");
198
- lines = lines.map(function(line) {
199
- var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
200
- if (!parsingError) {
201
- return line;
202
- }
203
- var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
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
- var _stats_errors, _stats_warnings, _result_errors;
224
- var formattedErrors = (_stats_errors = stats.errors) === null || _stats_errors === void 0 ? void 0 : _stats_errors.map(formatMessage);
225
- var formattedWarnings = (_stats_warnings = stats.warnings) === null || _stats_warnings === void 0 ? void 0 : _stats_warnings.map(formatMessage);
226
- var result = {
227
- errors: formattedErrors || [],
228
- warnings: formattedWarnings || []
229
- };
230
- if ((_result_errors = result.errors) === null || _result_errors === void 0 ? void 0 : _result_errors.some(isLikelyASyntaxError)) {
231
- result.errors = result.errors.filter(isLikelyASyntaxError);
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(param) {
241
- var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
242
- if (typeof URL !== "undefined") {
243
- var url = new URL("http://localhost");
244
- url.port = port;
245
- url.hostname = hostname;
246
- url.protocol = protocol;
247
- url.pathname = pathname;
248
- return url.toString();
249
- }
250
- var colon = protocol.indexOf(":") === -1 ? ":" : "";
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
- var location = self.location;
255
- var host = urlParts.host, port = urlParts.port, path = urlParts.path, protocol = urlParts.protocol;
256
- return formatURL({
257
- protocol: protocol || (location.protocol === "https:" ? "wss" : "ws"),
258
- hostname: host || location.hostname,
259
- port: port || location.port,
260
- pathname: path || HMR_SOCK_PATH
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
- if (console.clear && hasCompileErrors) {
269
- console.clear();
270
- }
69
+ if (console.clear && hasCompileErrors) {
70
+ console.clear();
71
+ }
271
72
  }
272
73
  var createOverlay;
273
74
  var clearOverlay;
274
- var registerOverlay = function(createFn, clearFn) {
275
- createOverlay = createFn;
276
- clearOverlay = clearFn;
75
+ var registerOverlay = (createFn, clearFn) => {
76
+ createOverlay = createFn;
77
+ clearOverlay = clearFn;
277
78
  };
278
79
  function handleSuccess() {
279
- clearOutdatedErrors();
280
- var isHotUpdate = !isFirstCompilation;
281
- isFirstCompilation = false;
282
- hasCompileErrors = false;
283
- if (isHotUpdate) {
284
- tryApplyUpdates();
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
- clearOutdatedErrors();
289
- var isHotUpdate = !isFirstCompilation;
290
- isFirstCompilation = false;
291
- hasCompileErrors = false;
292
- var formatted = formatStatsMessages({
293
- warnings: warnings,
294
- errors: []
295
- });
296
- for(var i = 0; i < formatted.warnings.length; i++){
297
- if (i === 5) {
298
- console.warn("There were more warnings in other files, you can find a complete log in the terminal.");
299
- break;
300
- }
301
- console.warn(formatted.warnings[i]);
302
- }
303
- if (isHotUpdate) {
304
- tryApplyUpdates();
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
- clearOutdatedErrors();
309
- isFirstCompilation = false;
310
- hasCompileErrors = true;
311
- var formatted = formatStatsMessages({
312
- errors: errors,
313
- warnings: []
314
- });
315
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
316
- try {
317
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
318
- var error = _step.value;
319
- console.error(error);
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
- return lastCompilationHash !== __webpack_hash__;
124
+ return lastCompilationHash !== __webpack_hash__;
341
125
  }
342
126
  function tryApplyUpdates() {
343
- if (!isUpdateAvailable()) {
344
- return;
345
- }
346
- if (!import.meta.webpackHot) {
347
- reloadPage();
348
- return;
349
- }
350
- if (import.meta.webpackHot.status() !== "idle") {
351
- return;
352
- }
353
- function handleApplyUpdates(err, updatedModules) {
354
- var forcedReload = err || !updatedModules;
355
- if (forcedReload) {
356
- if (err) {
357
- console.error("[HMR] Forced reload caused by: ", err);
358
- }
359
- reloadPage();
360
- return;
361
- }
362
- if (isUpdateAvailable()) {
363
- tryApplyUpdates();
364
- }
365
- }
366
- import.meta.webpackHot.check(true).then(function(updatedModules) {
367
- handleApplyUpdates(null, updatedModules);
368
- }, function(err) {
369
- handleApplyUpdates(err, null);
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
- console.info("[HMR] connected.");
160
+ console.info("[HMR] connected.");
377
161
  }
378
162
  function onMessage(e) {
379
- var message = JSON.parse(e.data);
380
- switch(message.type){
381
- case "hash":
382
- lastCompilationHash = message.data;
383
- if (clearOverlay && isUpdateAvailable()) {
384
- clearOverlay();
385
- }
386
- break;
387
- case "still-ok":
388
- case "ok":
389
- handleSuccess();
390
- break;
391
- case "static-changed":
392
- case "content-changed":
393
- reloadPage();
394
- break;
395
- case "warnings":
396
- handleWarnings(message.data);
397
- break;
398
- case "errors":
399
- handleErrors(message.data);
400
- break;
401
- }
402
- }
403
- function sleep() {
404
- var msec = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 1e3;
405
- return new Promise(function(resolve) {
406
- setTimeout(resolve, msec);
407
- });
408
- }
409
- function onClose() {
410
- return _onClose.apply(this, arguments);
411
- }
412
- function _onClose() {
413
- _onClose = _async_to_generator(function() {
414
- return _ts_generator(this, function(_state) {
415
- switch(_state.label){
416
- case 0:
417
- console.info("[HMR] disconnected. Attempting to reconnect.");
418
- removeListeners();
419
- return [
420
- 4,
421
- sleep(1e3)
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
- var socketUrl = getSocketUrl(RSBUILD_CLIENT_CONFIG);
450
- connection = new WebSocket(socketUrl);
451
- connection.addEventListener("open", onOpen);
452
- connection.addEventListener("close", onClose);
453
- connection.addEventListener("message", onMessage);
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
- if (connection) {
457
- connection.removeEventListener("open", onOpen);
458
- connection.removeEventListener("close", onClose);
459
- connection.removeEventListener("message", onMessage);
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
- if (connection) {
464
- connection = null;
465
- }
466
- connect();
223
+ if (connection) {
224
+ connection = null;
225
+ }
226
+ connect();
467
227
  }
468
228
  function reloadPage() {
469
- if (RSBUILD_DEV_LIVE_RELOAD) {
470
- window.location.reload();
471
- }
229
+ if (RSBUILD_DEV_LIVE_RELOAD) {
230
+ window.location.reload();
231
+ }
472
232
  }
473
233
  connect();
474
- export { registerOverlay };
234
+ export {
235
+ HMR_SOCK_PATH,
236
+ registerOverlay
237
+ };