@rspack/plugin-react-refresh 1.6.2 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -57
- package/client/reactRefresh.js +16 -28
- package/client/reactRefreshEntry.js +11 -12
- package/client/refreshUtils.js +116 -133
- package/dist/index.d.ts +1 -6
- package/dist/index.js +10 -176
- package/dist/options.d.ts +3 -20
- package/package.json +24 -40
- package/client/errorOverlayEntry.js +0 -101
- package/client/overlay/components/CompileErrorTrace.js +0 -68
- package/client/overlay/components/PageHeader.js +0 -60
- package/client/overlay/components/RuntimeErrorFooter.js +0 -93
- package/client/overlay/components/RuntimeErrorHeader.js +0 -38
- package/client/overlay/components/RuntimeErrorStack.js +0 -80
- package/client/overlay/components/Spacer.js +0 -19
- package/client/overlay/containers/CompileErrorContainer.js +0 -25
- package/client/overlay/containers/RuntimeErrorContainer.js +0 -29
- package/client/overlay/index.js +0 -351
- package/client/overlay/theme.js +0 -39
- package/client/overlay/utils.js +0 -74
- package/client/utils/ansi-html.js +0 -300
- package/client/utils/errorEventHandlers.js +0 -102
- package/client/utils/formatWebpackErrors.js +0 -106
- package/client/utils/retry.js +0 -23
- package/dist/sockets/WDSSocket.d.ts +0 -13
- package/dist/sockets/WDSSocket.js +0 -63
- package/dist/sockets/WHMEventSource.d.ts +0 -26
- package/dist/sockets/WHMEventSource.js +0 -52
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +0 -1
- package/dist/sockets/utils/getCurrentScriptSource.js +0 -45
- package/dist/sockets/utils/getSocketUrlParts.d.ts +0 -9
- package/dist/sockets/utils/getSocketUrlParts.js +0 -87
- package/dist/sockets/utils/getUrlFromParts.d.ts +0 -9
- package/dist/sockets/utils/getUrlFromParts.js +0 -49
- package/dist/sockets/utils/getWDSMetadata.d.ts +0 -16
- package/dist/sockets/utils/getWDSMetadata.js +0 -45
- package/dist/utils/getAdditionalEntries.d.ts +0 -9
- package/dist/utils/getIntegrationEntry.d.ts +0 -7
- package/dist/utils/getSocketIntegration.d.ts +0 -2
- package/exports/index.cjs +0 -7
- package/exports/index.d.cts +0 -3
- package/exports/index.d.mts +0 -5
- package/exports/index.mjs +0 -11
package/client/overlay/utils.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debounce a function to delay invoking until wait (ms) have elapsed since the last invocation.
|
|
3
|
-
* @param {function(...*): *} fn The function to be debounced.
|
|
4
|
-
* @param {number} wait Milliseconds to wait before invoking again.
|
|
5
|
-
* @return {function(...*): void} The debounced function.
|
|
6
|
-
*/
|
|
7
|
-
function debounce(fn, wait) {
|
|
8
|
-
/**
|
|
9
|
-
* A cached setTimeout handler.
|
|
10
|
-
* @type {number | undefined}
|
|
11
|
-
*/
|
|
12
|
-
let timer;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @returns {void}
|
|
16
|
-
*/
|
|
17
|
-
function debounced() {
|
|
18
|
-
const context = this;
|
|
19
|
-
const args = arguments;
|
|
20
|
-
|
|
21
|
-
clearTimeout(timer);
|
|
22
|
-
timer = setTimeout(function () {
|
|
23
|
-
return fn.apply(context, args);
|
|
24
|
-
}, wait);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return debounced;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Prettify a filename from error stacks into the desired format.
|
|
32
|
-
* @param {string} filename The filename to be formatted.
|
|
33
|
-
* @returns {string} The formatted filename.
|
|
34
|
-
*/
|
|
35
|
-
function formatFilename(filename) {
|
|
36
|
-
// Strip away protocol and domain for compiled files
|
|
37
|
-
const htmlMatch = /^https?:\/\/(.*)\/(.*)/.exec(filename);
|
|
38
|
-
if (htmlMatch && htmlMatch[1] && htmlMatch[2]) {
|
|
39
|
-
return htmlMatch[2];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Strip everything before the first directory for source files
|
|
43
|
-
const sourceMatch = /\/.*?([^./]+[/|\\].*)$/.exec(filename);
|
|
44
|
-
if (sourceMatch && sourceMatch[1]) {
|
|
45
|
-
return sourceMatch[1].replace(/\?$/, '');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Unknown filename type, use it as is
|
|
49
|
-
return filename;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Remove all children of an element.
|
|
54
|
-
* @param {HTMLElement} element A valid HTML element.
|
|
55
|
-
* @param {number} [skip] Number of elements to skip removing.
|
|
56
|
-
* @returns {void}
|
|
57
|
-
*/
|
|
58
|
-
function removeAllChildren(element, skip) {
|
|
59
|
-
/** @type {Node[]} */
|
|
60
|
-
const childList = Array.prototype.slice.call(
|
|
61
|
-
element.childNodes,
|
|
62
|
-
typeof skip !== 'undefined' ? skip : 0,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
for (let i = 0; i < childList.length; i += 1) {
|
|
66
|
-
element.removeChild(childList[i]);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
debounce: debounce,
|
|
72
|
-
formatFilename: formatFilename,
|
|
73
|
-
removeAllChildren: removeAllChildren,
|
|
74
|
-
};
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
/**
|
|
4
|
-
* The following code is modified based on mahdyar/ansi-html-community
|
|
5
|
-
* Added support for 24-bit RGB colors.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
module.exports = ansiHTML;
|
|
10
|
-
|
|
11
|
-
// Reference to https://github.com/sindresorhus/ansi-regex
|
|
12
|
-
var _regANSI =
|
|
13
|
-
/(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
|
|
14
|
-
|
|
15
|
-
var _defColors = {
|
|
16
|
-
reset: ['fff', '000'], // [FOREGROUND_COLOR, BACKGROUND_COLOR]
|
|
17
|
-
black: '000',
|
|
18
|
-
red: 'ff0000',
|
|
19
|
-
green: '209805',
|
|
20
|
-
yellow: 'e8bf03',
|
|
21
|
-
blue: '0000ff',
|
|
22
|
-
magenta: 'ff00ff',
|
|
23
|
-
cyan: '00ffee',
|
|
24
|
-
lightgrey: 'f0f0f0',
|
|
25
|
-
darkgrey: '888',
|
|
26
|
-
};
|
|
27
|
-
var _styles = {
|
|
28
|
-
30: 'black',
|
|
29
|
-
31: 'red',
|
|
30
|
-
32: 'green',
|
|
31
|
-
33: 'yellow',
|
|
32
|
-
34: 'blue',
|
|
33
|
-
35: 'magenta',
|
|
34
|
-
36: 'cyan',
|
|
35
|
-
37: 'lightgrey',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
var _colorMode = {
|
|
39
|
-
2: 'rgb',
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var _openTags = {
|
|
43
|
-
1: 'font-weight:bold', // bold
|
|
44
|
-
2: 'opacity:0.5', // dim
|
|
45
|
-
3: '<i>', // italic
|
|
46
|
-
4: '<u>', // underscore
|
|
47
|
-
8: 'display:none', // hidden
|
|
48
|
-
9: '<del>', // delete
|
|
49
|
-
38: function (match) {
|
|
50
|
-
// color
|
|
51
|
-
var mode = _colorMode[match[0]];
|
|
52
|
-
if (mode === 'rgb') {
|
|
53
|
-
var r, g, b;
|
|
54
|
-
r = match[1];
|
|
55
|
-
g = match[2];
|
|
56
|
-
b = match[3];
|
|
57
|
-
match.advance(4);
|
|
58
|
-
return 'color: rgb(' + r + ',' + g + ',' + b + ')';
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
48: function (match) {
|
|
62
|
-
// background color
|
|
63
|
-
var mode = _colorMode[match[0]];
|
|
64
|
-
if (mode === 'rgb') {
|
|
65
|
-
var r, g, b;
|
|
66
|
-
r = match[1];
|
|
67
|
-
g = match[2];
|
|
68
|
-
b = match[3];
|
|
69
|
-
match.advance(4);
|
|
70
|
-
return 'background-color: rgb(' + r + ',' + g + ',' + b + ')';
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
var _openTagToCloseTag = {
|
|
76
|
-
3: '23',
|
|
77
|
-
4: '24',
|
|
78
|
-
9: '29',
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
var _closeTags = {
|
|
82
|
-
0: function (ansiCodes) {
|
|
83
|
-
if (!ansiCodes) return '</span>';
|
|
84
|
-
if (!ansiCodes.length) return '';
|
|
85
|
-
var code,
|
|
86
|
-
ret = '';
|
|
87
|
-
while ((code = ansiCodes.pop())) {
|
|
88
|
-
var closeTag = _openTagToCloseTag[code];
|
|
89
|
-
if (closeTag) {
|
|
90
|
-
ret += _closeTags[closeTag];
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
ret += '</span>';
|
|
94
|
-
}
|
|
95
|
-
return ret;
|
|
96
|
-
},
|
|
97
|
-
23: '</i>', // reset italic
|
|
98
|
-
24: '</u>', // reset underscore
|
|
99
|
-
29: '</del>', // reset delete
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
[21, 22, 27, 28, 39, 49].forEach(function (n) {
|
|
103
|
-
_closeTags[n] = '</span>';
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Normalize ';<seq>' | '<seq>' -> '<seq>'
|
|
108
|
-
* @param {string | null} seq
|
|
109
|
-
* @returns {null | string}
|
|
110
|
-
*/
|
|
111
|
-
function normalizeSeq(seq) {
|
|
112
|
-
if (seq === null || seq === undefined) return null;
|
|
113
|
-
if (seq.startsWith(';')) {
|
|
114
|
-
return seq.slice(1);
|
|
115
|
-
}
|
|
116
|
-
return seq;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Converts text with ANSI color codes to HTML markup.
|
|
121
|
-
* @param {String} text
|
|
122
|
-
* @returns {*}
|
|
123
|
-
*/
|
|
124
|
-
function ansiHTML(text) {
|
|
125
|
-
// Returns the text if the string has no ANSI escape code.
|
|
126
|
-
if (!_regANSI.test(text)) {
|
|
127
|
-
return text;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Cache opened sequence.
|
|
131
|
-
var ansiCodes = [];
|
|
132
|
-
// Replace with markup.
|
|
133
|
-
var ret = text.replace(
|
|
134
|
-
/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g,
|
|
135
|
-
function (m) {
|
|
136
|
-
var match = m.match(/(;?\d+)/g).map(normalizeSeq);
|
|
137
|
-
Object.defineProperty(match, 'advance', {
|
|
138
|
-
value: function (count) {
|
|
139
|
-
this.splice(0, count);
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
var seq,
|
|
143
|
-
rep = '';
|
|
144
|
-
while ((seq = match[0])) {
|
|
145
|
-
match.advance(1);
|
|
146
|
-
rep += applySeq(seq);
|
|
147
|
-
}
|
|
148
|
-
return rep;
|
|
149
|
-
|
|
150
|
-
function applySeq(seq) {
|
|
151
|
-
var other = _openTags[seq];
|
|
152
|
-
if (
|
|
153
|
-
other &&
|
|
154
|
-
(other = typeof other === 'function' ? other(match) : other)
|
|
155
|
-
) {
|
|
156
|
-
// If reset signal is encountered, we have to reset everything.
|
|
157
|
-
var ret = '';
|
|
158
|
-
if (seq === '0') {
|
|
159
|
-
ret += _closeTags[seq](ansiCodes);
|
|
160
|
-
}
|
|
161
|
-
// If current sequence has been opened, close it.
|
|
162
|
-
if (!!~ansiCodes.indexOf(seq)) {
|
|
163
|
-
// eslint-disable-line no-extra-boolean-cast
|
|
164
|
-
ansiCodes.pop();
|
|
165
|
-
return '</span>';
|
|
166
|
-
}
|
|
167
|
-
// Open tag.
|
|
168
|
-
ansiCodes.push(seq);
|
|
169
|
-
return (
|
|
170
|
-
ret + (other[0] === '<' ? other : '<span style="' + other + ';">')
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
var ct = _closeTags[seq];
|
|
175
|
-
if (typeof ct === 'function') {
|
|
176
|
-
return ct(ansiCodes);
|
|
177
|
-
} else if (ct) {
|
|
178
|
-
// Pop sequence
|
|
179
|
-
ansiCodes.pop();
|
|
180
|
-
return ct;
|
|
181
|
-
}
|
|
182
|
-
return '';
|
|
183
|
-
}
|
|
184
|
-
},
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
// Make sure tags are closed.
|
|
188
|
-
var l = ansiCodes.length;
|
|
189
|
-
l > 0 && (ret += Array(l + 1).join('</span>'));
|
|
190
|
-
|
|
191
|
-
return ret;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Customize colors.
|
|
196
|
-
* @param {Object} colors reference to _defColors
|
|
197
|
-
*/
|
|
198
|
-
ansiHTML.setColors = function (colors) {
|
|
199
|
-
if (typeof colors !== 'object') {
|
|
200
|
-
throw new Error('`colors` parameter must be an Object.');
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
var _finalColors = {};
|
|
204
|
-
for (var key in _defColors) {
|
|
205
|
-
var hex = colors.hasOwnProperty(key) ? colors[key] : null;
|
|
206
|
-
if (!hex) {
|
|
207
|
-
_finalColors[key] = _defColors[key];
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if ('reset' === key) {
|
|
211
|
-
if (typeof hex === 'string') {
|
|
212
|
-
hex = [hex];
|
|
213
|
-
}
|
|
214
|
-
if (
|
|
215
|
-
!Array.isArray(hex) ||
|
|
216
|
-
hex.length === 0 ||
|
|
217
|
-
hex.some(function (h) {
|
|
218
|
-
return typeof h !== 'string';
|
|
219
|
-
})
|
|
220
|
-
) {
|
|
221
|
-
throw new Error(
|
|
222
|
-
'The value of `' +
|
|
223
|
-
key +
|
|
224
|
-
'` property must be an Array and each item could only be a hex string, e.g.: FF0000',
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
var defHexColor = _defColors[key];
|
|
228
|
-
if (!hex[0]) {
|
|
229
|
-
hex[0] = defHexColor[0];
|
|
230
|
-
}
|
|
231
|
-
if (hex.length === 1 || !hex[1]) {
|
|
232
|
-
hex = [hex[0]];
|
|
233
|
-
hex.push(defHexColor[1]);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
hex = hex.slice(0, 2);
|
|
237
|
-
} else if (typeof hex !== 'string') {
|
|
238
|
-
throw new Error(
|
|
239
|
-
'The value of `' +
|
|
240
|
-
key +
|
|
241
|
-
'` property must be a hex string, e.g.: FF0000',
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
_finalColors[key] = hex;
|
|
245
|
-
}
|
|
246
|
-
_setTags(_finalColors);
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Reset colors.
|
|
251
|
-
*/
|
|
252
|
-
ansiHTML.reset = function () {
|
|
253
|
-
_setTags(_defColors);
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Expose tags, including open and close.
|
|
258
|
-
* @type {Object}
|
|
259
|
-
*/
|
|
260
|
-
ansiHTML.tags = {};
|
|
261
|
-
|
|
262
|
-
if (Object.defineProperty) {
|
|
263
|
-
Object.defineProperty(ansiHTML.tags, 'open', {
|
|
264
|
-
get: function () {
|
|
265
|
-
return _openTags;
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
Object.defineProperty(ansiHTML.tags, 'close', {
|
|
269
|
-
get: function () {
|
|
270
|
-
return _closeTags;
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
} else {
|
|
274
|
-
ansiHTML.tags.open = _openTags;
|
|
275
|
-
ansiHTML.tags.close = _closeTags;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function _setTags(colors) {
|
|
279
|
-
// reset all
|
|
280
|
-
_openTags['0'] =
|
|
281
|
-
'font-weight:normal;opacity:1;color:#' +
|
|
282
|
-
colors.reset[0] +
|
|
283
|
-
';background:#' +
|
|
284
|
-
colors.reset[1];
|
|
285
|
-
// inverse
|
|
286
|
-
_openTags['7'] =
|
|
287
|
-
'color:#' + colors.reset[1] + ';background:#' + colors.reset[0];
|
|
288
|
-
// dark grey
|
|
289
|
-
_openTags['90'] = 'color:#' + colors.darkgrey;
|
|
290
|
-
|
|
291
|
-
for (var code in _styles) {
|
|
292
|
-
var color = _styles[code];
|
|
293
|
-
var oriColor = colors[color] || '000';
|
|
294
|
-
_openTags[code] = 'color:#' + oriColor;
|
|
295
|
-
code = parseInt(code);
|
|
296
|
-
_openTags[(code + 10).toString()] = 'background:#' + oriColor;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
ansiHTML.reset();
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @callback EventCallback
|
|
3
|
-
* @param {string | Error | null} context
|
|
4
|
-
* @returns {void}
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* @callback EventHandler
|
|
8
|
-
* @param {Event} event
|
|
9
|
-
* @returns {void}
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A function that creates an event handler for the `error` event.
|
|
14
|
-
* @param {EventCallback} callback A function called to handle the error context.
|
|
15
|
-
* @returns {EventHandler} A handler for the `error` event.
|
|
16
|
-
*/
|
|
17
|
-
function createErrorHandler(callback) {
|
|
18
|
-
return function errorHandler(event) {
|
|
19
|
-
if (!event || !event.error) {
|
|
20
|
-
return callback(null);
|
|
21
|
-
}
|
|
22
|
-
if (event.error instanceof Error) {
|
|
23
|
-
return callback(event.error);
|
|
24
|
-
}
|
|
25
|
-
// A non-error was thrown, we don't have a trace. :(
|
|
26
|
-
// Look in your browser's devtools for more information
|
|
27
|
-
return callback(new Error(event.error));
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* A function that creates an event handler for the `unhandledrejection` event.
|
|
33
|
-
* @param {EventCallback} callback A function called to handle the error context.
|
|
34
|
-
* @returns {EventHandler} A handler for the `unhandledrejection` event.
|
|
35
|
-
*/
|
|
36
|
-
function createRejectionHandler(callback) {
|
|
37
|
-
return function rejectionHandler(event) {
|
|
38
|
-
if (!event || !event.reason) {
|
|
39
|
-
return callback(new Error('Unknown'));
|
|
40
|
-
}
|
|
41
|
-
if (event.reason instanceof Error) {
|
|
42
|
-
return callback(event.reason);
|
|
43
|
-
}
|
|
44
|
-
// A non-error was rejected, we don't have a trace :(
|
|
45
|
-
// Look in your browser's devtools for more information
|
|
46
|
-
return callback(new Error(event.reason));
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates a handler that registers an EventListener on window for a valid type
|
|
52
|
-
* and calls a callback when the event fires.
|
|
53
|
-
* @param {string} eventType A valid DOM event type.
|
|
54
|
-
* @param {function(EventCallback): EventHandler} createHandler A function that creates an event handler.
|
|
55
|
-
* @returns {register} A function that registers the EventListener given a callback.
|
|
56
|
-
*/
|
|
57
|
-
function createWindowEventHandler(eventType, createHandler) {
|
|
58
|
-
/**
|
|
59
|
-
* @type {EventHandler | null} A cached event handler function.
|
|
60
|
-
*/
|
|
61
|
-
let eventHandler = null;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Unregisters an EventListener if it has been registered.
|
|
65
|
-
* @returns {void}
|
|
66
|
-
*/
|
|
67
|
-
function unregister() {
|
|
68
|
-
if (eventHandler === null) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
window.removeEventListener(eventType, eventHandler);
|
|
72
|
-
eventHandler = null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Registers an EventListener if it hasn't been registered.
|
|
77
|
-
* @param {EventCallback} callback A function called after the event handler to handle its context.
|
|
78
|
-
* @returns {unregister | void} A function to unregister the registered EventListener if registration is performed.
|
|
79
|
-
*/
|
|
80
|
-
function register(callback) {
|
|
81
|
-
if (eventHandler !== null) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
eventHandler = createHandler(callback);
|
|
85
|
-
window.addEventListener(eventType, eventHandler);
|
|
86
|
-
|
|
87
|
-
return unregister;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return register;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const handleError = createWindowEventHandler('error', createErrorHandler);
|
|
94
|
-
const handleUnhandledRejection = createWindowEventHandler(
|
|
95
|
-
'unhandledrejection',
|
|
96
|
-
createRejectionHandler,
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
module.exports = {
|
|
100
|
-
handleError: handleError,
|
|
101
|
-
handleUnhandledRejection: handleUnhandledRejection,
|
|
102
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {Object} WebpackErrorObj
|
|
3
|
-
* @property {string} moduleIdentifier
|
|
4
|
-
* @property {string} moduleName
|
|
5
|
-
* @property {string} message
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const friendlySyntaxErrorLabel = 'Syntax error:';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Checks if the error message is for a syntax error.
|
|
12
|
-
* @param {string} message The raw Webpack error message.
|
|
13
|
-
* @returns {boolean} Whether the error message is for a syntax error.
|
|
14
|
-
*/
|
|
15
|
-
function isLikelyASyntaxError(message) {
|
|
16
|
-
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Cleans up Webpack error messages.
|
|
21
|
-
*
|
|
22
|
-
* This implementation is based on the one from [create-react-app](https://github.com/facebook/create-react-app/blob/edc671eeea6b7d26ac3f1eb2050e50f75cf9ad5d/packages/react-dev-utils/formatWebpackMessages.js).
|
|
23
|
-
* @param {string} message The raw Webpack error message.
|
|
24
|
-
* @returns {string} The formatted Webpack error message.
|
|
25
|
-
*/
|
|
26
|
-
function formatMessage(message) {
|
|
27
|
-
let lines = message.split('\n');
|
|
28
|
-
|
|
29
|
-
// Strip Webpack-added headers off errors/warnings
|
|
30
|
-
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
31
|
-
lines = lines.filter(function (line) {
|
|
32
|
-
return !/Module [A-z ]+\(from/.test(line);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// Remove leading newline
|
|
36
|
-
if (lines.length > 2 && lines[1].trim() === '') {
|
|
37
|
-
lines.splice(1, 1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Remove duplicated newlines
|
|
41
|
-
lines = lines.filter(function (line, index, arr) {
|
|
42
|
-
return (
|
|
43
|
-
index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// Clean up the file name
|
|
48
|
-
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
|
|
49
|
-
|
|
50
|
-
// Cleans up verbose "module not found" messages for files and packages.
|
|
51
|
-
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
|
52
|
-
lines = [
|
|
53
|
-
lines[0],
|
|
54
|
-
lines[1]
|
|
55
|
-
.replace('Error: ', '')
|
|
56
|
-
.replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
message = lines.join('\n');
|
|
61
|
-
|
|
62
|
-
// Clean up syntax errors
|
|
63
|
-
message = message.replace('SyntaxError:', friendlySyntaxErrorLabel);
|
|
64
|
-
|
|
65
|
-
// Internal stacks are generally useless, so we strip them -
|
|
66
|
-
// except the stacks containing `webpack:`,
|
|
67
|
-
// because they're normally from user code generated by webpack.
|
|
68
|
-
message = message.replace(
|
|
69
|
-
/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm,
|
|
70
|
-
'',
|
|
71
|
-
); // at ... ...:x:y
|
|
72
|
-
message = message.replace(
|
|
73
|
-
/^\s*at\s((?!webpack:).)*<anonymous>[\s)]*(\n|$)/gm,
|
|
74
|
-
'',
|
|
75
|
-
); // at ... <anonymous>
|
|
76
|
-
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
|
77
|
-
|
|
78
|
-
return message.trim();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Formats Webpack error messages into a more readable format.
|
|
83
|
-
* @param {Array<string | WebpackErrorObj>} errors An array of Webpack error messages.
|
|
84
|
-
* @returns {string[]} The formatted Webpack error messages.
|
|
85
|
-
*/
|
|
86
|
-
function formatWebpackErrors(errors) {
|
|
87
|
-
let formattedErrors = errors.map(function (errorObjOrMessage) {
|
|
88
|
-
// Webpack 5 compilation errors are in the form of descriptor objects,
|
|
89
|
-
// so we have to join pieces to get the format we want.
|
|
90
|
-
if (typeof errorObjOrMessage === 'object') {
|
|
91
|
-
return formatMessage(
|
|
92
|
-
[errorObjOrMessage.moduleName, errorObjOrMessage.message].join('\n'),
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
// Webpack 4 compilation errors are strings
|
|
96
|
-
return formatMessage(errorObjOrMessage);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (formattedErrors.some(isLikelyASyntaxError)) {
|
|
100
|
-
// If there are any syntax errors, show just them.
|
|
101
|
-
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
|
|
102
|
-
}
|
|
103
|
-
return formattedErrors;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = formatWebpackErrors;
|
package/client/utils/retry.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function runWithRetry(callback, maxRetries) {
|
|
2
|
-
function executeWithRetryAndTimeout(currentCount) {
|
|
3
|
-
try {
|
|
4
|
-
if (currentCount > maxRetries - 1) {
|
|
5
|
-
console.warn('[React Refresh] Failed to set up the socket connection.');
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
callback();
|
|
10
|
-
} catch (err) {
|
|
11
|
-
setTimeout(
|
|
12
|
-
function () {
|
|
13
|
-
executeWithRetryAndTimeout(currentCount + 1);
|
|
14
|
-
},
|
|
15
|
-
Math.pow(10, currentCount),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
executeWithRetryAndTimeout(0);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = runWithRetry;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { SocketClient } from './utils/getWDSMetadata';
|
|
2
|
-
declare global {
|
|
3
|
-
var __webpack_dev_server_client__: SocketClient | {
|
|
4
|
-
default: SocketClient;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Initializes a socket server for HMR for webpack-dev-server.
|
|
9
|
-
* @param messageHandler A handler to consume Webpack compilation messages.
|
|
10
|
-
* @param resourceQuery Webpack's `__resourceQuery` string.
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export declare function init(messageHandler: (...args: unknown[]) => void, resourceQuery: string): void;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
|
-
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: definition[key]
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
})();
|
|
20
|
-
(()=>{
|
|
21
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
-
})();
|
|
23
|
-
(()=>{
|
|
24
|
-
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
-
value: 'Module'
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
-
value: true
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __webpack_exports__ = {};
|
|
34
|
-
__webpack_require__.r(__webpack_exports__);
|
|
35
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
init: ()=>init
|
|
37
|
-
});
|
|
38
|
-
const getSocketUrlParts_js_namespaceObject = require("./utils/getSocketUrlParts.js");
|
|
39
|
-
var getSocketUrlParts_js_default = /*#__PURE__*/ __webpack_require__.n(getSocketUrlParts_js_namespaceObject);
|
|
40
|
-
const getUrlFromParts_js_namespaceObject = require("./utils/getUrlFromParts.js");
|
|
41
|
-
var getUrlFromParts_js_default = /*#__PURE__*/ __webpack_require__.n(getUrlFromParts_js_namespaceObject);
|
|
42
|
-
const getWDSMetadata_js_namespaceObject = require("./utils/getWDSMetadata.js");
|
|
43
|
-
var getWDSMetadata_js_default = /*#__PURE__*/ __webpack_require__.n(getWDSMetadata_js_namespaceObject);
|
|
44
|
-
function init(messageHandler, resourceQuery) {
|
|
45
|
-
if ("u" > typeof __webpack_dev_server_client__) {
|
|
46
|
-
let SocketClient;
|
|
47
|
-
SocketClient = 'default' in __webpack_dev_server_client__ ? __webpack_dev_server_client__.default : __webpack_dev_server_client__;
|
|
48
|
-
const wdsMeta = getWDSMetadata_js_default()(SocketClient);
|
|
49
|
-
const urlParts = getSocketUrlParts_js_default()(resourceQuery, wdsMeta);
|
|
50
|
-
const connection = new SocketClient(getUrlFromParts_js_default()(urlParts, wdsMeta));
|
|
51
|
-
connection.onMessage(function(data) {
|
|
52
|
-
const message = JSON.parse(data);
|
|
53
|
-
messageHandler(message);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.init = __webpack_exports__.init;
|
|
58
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
59
|
-
"init"
|
|
60
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
61
|
-
Object.defineProperty(exports, '__esModule', {
|
|
62
|
-
value: true
|
|
63
|
-
});
|