@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.
Files changed (54) 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} +22 -46
  34. package/dist/client/hmr.d.ts +5 -0
  35. package/dist/client/hmr.mjs +201 -474
  36. package/dist/client/overlay.mjs +208 -237
  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/createSocketUrl.d.ts +0 -12
  54. package/dist/client/hmr/index.d.ts +0 -4
@@ -1,510 +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);
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
- var lines = [];
178
- var message;
179
- if (typeof stats === "object") {
180
- var fileName = stats.moduleName ? "File: ".concat(stats.moduleName, "\n") : "";
181
- var mainMessage = typeof stats.formatted === "string" ? stats.formatted : stats.message;
182
- var details = stats.details ? "\nDetails: ".concat(stats.details, "\n") : "";
183
- var stack = stats.stack ? "\n".concat(stats.stack) : "";
184
- message = "".concat(fileName).concat(mainMessage).concat(details).concat(stack);
185
- } else {
186
- message = stats;
187
- }
188
- lines = message.split("\n");
189
- lines = lines.map(function(line) {
190
- var parsingError = /Line (\d+):(?:(\d+):)?\s*Parsing error: (.+)$/.exec(line);
191
- if (!parsingError) {
192
- return line;
193
- }
194
- var _parsingError = _sliced_to_array(parsingError, 4), errorLine = _parsingError[1], errorColumn = _parsingError[2], errorMessage = _parsingError[3];
195
- return "".concat(friendlySyntaxErrorLabel, " ").concat(errorMessage, " (").concat(errorLine, ":").concat(errorColumn, ")");
196
- });
197
- message = lines.join("\n");
198
- message = message.replace(/SyntaxError\s+\((\d+):(\d+)\)\s*(.+?)\n/g, "".concat(friendlySyntaxErrorLabel, " $3 ($1:$2)\n"));
199
- lines = message.split("\n");
200
- if (lines.length > 2 && lines[1].trim() === "") {
201
- lines.splice(1, 1);
202
- }
203
- lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, "$1");
204
- if (lines[1] && lines[1].indexOf("Module not found:") !== -1) {
205
- lines[1] = lines[1].replace("Error: ", "");
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 createSocketUrl() {
233
- var options2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
234
- var currentLocation = self.location;
235
- return getSocketUrl(options2, currentLocation);
236
- }
237
- function formatURL(param) {
238
- var port = param.port, protocol = param.protocol, hostname = param.hostname, pathname = param.pathname;
239
- if (typeof URL !== "undefined") {
240
- var url = new URL("http://localhost");
241
- url.port = port;
242
- url.hostname = hostname;
243
- url.protocol = protocol;
244
- url.pathname = pathname;
245
- return url.toString();
246
- }
247
- var colon = protocol.indexOf(":") === -1 ? ":" : "";
248
- 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}`;
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 mostRecentCompilationHash = null;
66
+ var lastCompilationHash = null;
266
67
  var hasCompileErrors = false;
267
68
  function clearOutdatedErrors() {
268
- if (typeof console !== "undefined" && typeof console.clear === "function") {
269
- if (hasCompileErrors) {
270
- console.clear();
271
- }
272
- }
69
+ if (console.clear && hasCompileErrors) {
70
+ console.clear();
71
+ }
273
72
  }
274
73
  var createOverlay;
275
74
  var clearOverlay;
276
- var registerOverlay = function(options2) {
277
- createOverlay = options2.createOverlay;
278
- clearOverlay = options2.clearOverlay;
75
+ var registerOverlay = (createFn, clearFn) => {
76
+ createOverlay = createFn;
77
+ clearOverlay = clearFn;
279
78
  };
280
79
  function handleSuccess() {
281
- clearOutdatedErrors();
282
- var isHotUpdate = !isFirstCompilation;
283
- isFirstCompilation = false;
284
- hasCompileErrors = false;
285
- if (isHotUpdate) {
286
- tryApplyUpdates();
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
- clearOutdatedErrors();
291
- var isHotUpdate = !isFirstCompilation;
292
- isFirstCompilation = false;
293
- hasCompileErrors = false;
294
- function printWarnings() {
295
- var formatted = formatStatsMessages({
296
- warnings: warnings,
297
- errors: []
298
- });
299
- if (typeof console !== "undefined" && typeof console.warn === "function") {
300
- for(var i = 0; i < formatted.warnings.length; i++){
301
- if (i === 5) {
302
- console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
303
- break;
304
- }
305
- console.warn(formatted.warnings[i]);
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
- clearOutdatedErrors();
316
- isFirstCompilation = false;
317
- hasCompileErrors = true;
318
- var formatted = formatStatsMessages({
319
- errors: errors,
320
- warnings: []
321
- });
322
- if (typeof console !== "undefined" && typeof console.error === "function") {
323
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
324
- try {
325
- for(var _iterator = formatted.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
326
- var error = _step.value;
327
- console.error(error);
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
- return mostRecentCompilationHash !== __webpack_hash__;
353
- }
354
- function canApplyUpdates() {
355
- return import.meta.webpackHot.status() === "idle";
124
+ return lastCompilationHash !== __webpack_hash__;
356
125
  }
357
126
  function tryApplyUpdates() {
358
- if (!isUpdateAvailable()) {
359
- return;
360
- }
361
- if (!import.meta.webpackHot) {
362
- reloadPage();
363
- return;
364
- }
365
- if (!canApplyUpdates()) {
366
- return;
367
- }
368
- function handleApplyUpdates(err, updatedModules) {
369
- var wantsForcedReload = err || !updatedModules;
370
- if (wantsForcedReload) {
371
- if (err && typeof console !== "undefined" && typeof console.error === "function") {
372
- console.error("[HMR] Forced reload caused by: ", err);
373
- }
374
- reloadPage();
375
- return;
376
- }
377
- if (isUpdateAvailable()) {
378
- tryApplyUpdates();
379
- }
380
- }
381
- import.meta.webpackHot.check(true).then(function(updatedModules) {
382
- handleApplyUpdates(null, updatedModules);
383
- }, function(err) {
384
- handleApplyUpdates(err, null);
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 retry_counter = 0;
158
+ var retryCount = 0;
390
159
  function onOpen() {
391
- if (typeof console !== "undefined" && typeof console.info === "function") {
392
- console.info("[HMR] connected.");
393
- }
160
+ console.info("[HMR] connected.");
394
161
  }
395
162
  function onMessage(e) {
396
- var message = JSON.parse(e.data);
397
- switch(message.type){
398
- case "hash":
399
- if (enableOverlay) {
400
- clearOverlay === null || clearOverlay === void 0 ? void 0 : clearOverlay();
401
- }
402
- handleAvailableHash(message.data);
403
- break;
404
- case "still-ok":
405
- case "ok":
406
- handleSuccess();
407
- break;
408
- case "static-changed":
409
- reloadPage();
410
- break;
411
- case "content-changed":
412
- reloadPage();
413
- break;
414
- case "warnings":
415
- handleWarnings(message.data);
416
- break;
417
- case "errors":
418
- handleErrors(message.data);
419
- break;
420
- default:
421
- }
422
- }
423
- function sleep() {
424
- return _sleep.apply(this, arguments);
425
- }
426
- function _sleep() {
427
- _sleep = _async_to_generator(function() {
428
- var msec;
429
- var _arguments = arguments;
430
- return _ts_generator(this, function(_state) {
431
- msec = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : 1e3;
432
- return [
433
- 2,
434
- new Promise(function(resolve) {
435
- setTimeout(resolve, msec);
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
- connection = new WebSocket(socketUrl);
487
- connection.addEventListener("open", onOpen);
488
- connection.addEventListener("close", onClose);
489
- 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);
490
214
  }
491
215
  function removeListeners() {
492
- if (connection) {
493
- connection.removeEventListener("open", onOpen);
494
- connection.removeEventListener("close", onClose);
495
- connection.removeEventListener("message", onMessage);
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
- if (connection) {
500
- connection = null;
501
- }
502
- connect();
223
+ if (connection) {
224
+ connection = null;
225
+ }
226
+ connect();
503
227
  }
504
228
  function reloadPage() {
505
- if (enableLiveReload) {
506
- window.location.reload();
507
- }
229
+ if (RSBUILD_DEV_LIVE_RELOAD) {
230
+ window.location.reload();
231
+ }
508
232
  }
509
233
  connect();
510
- export { registerOverlay };
234
+ export {
235
+ HMR_SOCK_PATH,
236
+ registerOverlay
237
+ };