@rspack/plugin-react-refresh 1.0.0-alpha.0 → 1.0.0-alpha.2
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/client/errorOverlayEntry.js +108 -0
- package/client/overlay/components/CompileErrorTrace.js +58 -0
- package/client/overlay/components/PageHeader.js +58 -0
- package/client/overlay/components/RuntimeErrorFooter.js +93 -0
- package/client/overlay/components/RuntimeErrorHeader.js +37 -0
- package/client/overlay/components/RuntimeErrorStack.js +79 -0
- package/client/overlay/components/Spacer.js +19 -0
- package/client/overlay/containers/CompileErrorContainer.js +25 -0
- package/client/overlay/containers/RuntimeErrorContainer.js +29 -0
- package/client/overlay/index.js +348 -0
- package/client/overlay/theme.js +39 -0
- package/client/overlay/utils.js +74 -0
- package/client/utils/ansi-html.js +305 -0
- package/client/utils/errorEventHandlers.js +102 -0
- package/client/utils/formatWebpackErrors.js +96 -0
- package/client/utils/retry.js +23 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +33 -3
- package/dist/options.d.ts +16 -1
- package/dist/options.js +19 -0
- package/dist/sockets/WDSSocket.d.ts +10 -0
- package/dist/sockets/WDSSocket.js +41 -0
- package/dist/sockets/utils/getCurrentScriptSource.d.ts +1 -0
- package/dist/sockets/utils/getCurrentScriptSource.js +26 -0
- package/dist/sockets/utils/getSocketUrlParts.d.ts +9 -0
- package/dist/sockets/utils/getSocketUrlParts.js +112 -0
- package/dist/sockets/utils/getUrlFromParts.d.ts +9 -0
- package/dist/sockets/utils/getUrlFromParts.js +32 -0
- package/dist/sockets/utils/getWDSMetadata.d.ts +5 -0
- package/dist/sockets/utils/getWDSMetadata.js +30 -0
- package/dist/utils/getAdditionalEntries.d.ts +9 -0
- package/dist/utils/getAdditionalEntries.js +93 -0
- package/dist/utils/getSocketIntegration.d.ts +2 -0
- package/dist/utils/getSocketIntegration.js +17 -0
- package/package.json +7 -3
@@ -0,0 +1,305 @@
|
|
1
|
+
/* eslint-disable */
|
2
|
+
// @ts-nocheck
|
3
|
+
/**
|
4
|
+
* The following code is modified based on
|
5
|
+
* https://github.com/mahdyar/ansi-html-community/blob/b86cc3f1fa1d118477877352f0eafe1a70fd20ab/index.js
|
6
|
+
*
|
7
|
+
* Supported:
|
8
|
+
* - added support for 24-bit RGB colors.
|
9
|
+
*
|
10
|
+
* Apache 2.0 Licensed
|
11
|
+
* Author @Tjatse
|
12
|
+
* https://github.com/mahdyar/ansi-html-community/blob/master/LICENSE
|
13
|
+
*/
|
14
|
+
"use strict";
|
15
|
+
|
16
|
+
module.exports = ansiHTML;
|
17
|
+
|
18
|
+
// Reference to https://github.com/sindresorhus/ansi-regex
|
19
|
+
var _regANSI =
|
20
|
+
/(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
|
21
|
+
|
22
|
+
var _defColors = {
|
23
|
+
reset: ["fff", "000"], // [FOREGROUND_COLOR, BACKGROUND_COLOR]
|
24
|
+
black: "000",
|
25
|
+
red: "ff0000",
|
26
|
+
green: "209805",
|
27
|
+
yellow: "e8bf03",
|
28
|
+
blue: "0000ff",
|
29
|
+
magenta: "ff00ff",
|
30
|
+
cyan: "00ffee",
|
31
|
+
lightgrey: "f0f0f0",
|
32
|
+
darkgrey: "888"
|
33
|
+
};
|
34
|
+
var _styles = {
|
35
|
+
30: "black",
|
36
|
+
31: "red",
|
37
|
+
32: "green",
|
38
|
+
33: "yellow",
|
39
|
+
34: "blue",
|
40
|
+
35: "magenta",
|
41
|
+
36: "cyan",
|
42
|
+
37: "lightgrey"
|
43
|
+
};
|
44
|
+
|
45
|
+
var _colorMode = {
|
46
|
+
2: "rgb"
|
47
|
+
};
|
48
|
+
|
49
|
+
var _openTags = {
|
50
|
+
1: "font-weight:bold", // bold
|
51
|
+
2: "opacity:0.5", // dim
|
52
|
+
3: "<i>", // italic
|
53
|
+
4: "<u>", // underscore
|
54
|
+
8: "display:none", // hidden
|
55
|
+
9: "<del>", // delete
|
56
|
+
38: function (match) {
|
57
|
+
// color
|
58
|
+
var mode = _colorMode[match[0]];
|
59
|
+
if (mode === "rgb") {
|
60
|
+
var r, g, b;
|
61
|
+
r = match[1];
|
62
|
+
g = match[2];
|
63
|
+
b = match[3];
|
64
|
+
match.advance(4);
|
65
|
+
return "color: rgb(" + r + "," + g + "," + b + ")";
|
66
|
+
}
|
67
|
+
},
|
68
|
+
48: function (match) {
|
69
|
+
// background color
|
70
|
+
var mode = _colorMode[match[0]];
|
71
|
+
if (mode === "rgb") {
|
72
|
+
var r, g, b;
|
73
|
+
r = match[1];
|
74
|
+
g = match[2];
|
75
|
+
b = match[3];
|
76
|
+
match.advance(4);
|
77
|
+
return "background-color: rgb(" + r + "," + g + "," + b + ")";
|
78
|
+
}
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
var _openTagToCloseTag = {
|
83
|
+
3: "23",
|
84
|
+
4: "24",
|
85
|
+
9: "29"
|
86
|
+
};
|
87
|
+
|
88
|
+
var _closeTags = {
|
89
|
+
0: function (ansiCodes) {
|
90
|
+
if (!ansiCodes) return "</span>";
|
91
|
+
if (!ansiCodes.length) return "";
|
92
|
+
var code,
|
93
|
+
ret = "";
|
94
|
+
while ((code = ansiCodes.pop())) {
|
95
|
+
var closeTag = _openTagToCloseTag[code];
|
96
|
+
if (closeTag) {
|
97
|
+
ret += _closeTags[closeTag];
|
98
|
+
continue;
|
99
|
+
}
|
100
|
+
ret += "</span>";
|
101
|
+
}
|
102
|
+
return ret;
|
103
|
+
},
|
104
|
+
23: "</i>", // reset italic
|
105
|
+
24: "</u>", // reset underscore
|
106
|
+
29: "</del>" // reset delete
|
107
|
+
};
|
108
|
+
|
109
|
+
[21, 22, 27, 28, 39, 49].forEach(function (n) {
|
110
|
+
_closeTags[n] = "</span>";
|
111
|
+
});
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Normalize ';<seq>' | '<seq>' -> '<seq>'
|
115
|
+
* @param {string | null} seq
|
116
|
+
* @returns {null | string}
|
117
|
+
*/
|
118
|
+
function normalizeSeq(seq) {
|
119
|
+
if (seq === null || seq === undefined) return null;
|
120
|
+
if (seq.startsWith(";")) {
|
121
|
+
return seq.slice(1);
|
122
|
+
}
|
123
|
+
return seq;
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Converts text with ANSI color codes to HTML markup.
|
128
|
+
* @param {String} text
|
129
|
+
* @returns {*}
|
130
|
+
*/
|
131
|
+
function ansiHTML(text) {
|
132
|
+
// Returns the text if the string has no ANSI escape code.
|
133
|
+
if (!_regANSI.test(text)) {
|
134
|
+
return text;
|
135
|
+
}
|
136
|
+
|
137
|
+
// Cache opened sequence.
|
138
|
+
var ansiCodes = [];
|
139
|
+
// Replace with markup.
|
140
|
+
var ret = text.replace(
|
141
|
+
/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g,
|
142
|
+
function (m) {
|
143
|
+
var match = m.match(/(;?\d+)/g).map(normalizeSeq);
|
144
|
+
Object.defineProperty(match, "advance", {
|
145
|
+
value: function (count) {
|
146
|
+
this.splice(0, count);
|
147
|
+
}
|
148
|
+
});
|
149
|
+
var seq,
|
150
|
+
rep = "";
|
151
|
+
while ((seq = match[0])) {
|
152
|
+
match.advance(1);
|
153
|
+
rep += applySeq(seq);
|
154
|
+
}
|
155
|
+
return rep;
|
156
|
+
|
157
|
+
function applySeq(seq) {
|
158
|
+
var other = _openTags[seq];
|
159
|
+
if (
|
160
|
+
other &&
|
161
|
+
(other = typeof other === "function" ? other(match) : other)
|
162
|
+
) {
|
163
|
+
// If reset signal is encountered, we have to reset everything.
|
164
|
+
var ret = "";
|
165
|
+
if (seq === "0") {
|
166
|
+
ret += _closeTags[seq](ansiCodes);
|
167
|
+
}
|
168
|
+
// If current sequence has been opened, close it.
|
169
|
+
if (!!~ansiCodes.indexOf(seq)) {
|
170
|
+
// eslint-disable-line no-extra-boolean-cast
|
171
|
+
ansiCodes.pop();
|
172
|
+
return "</span>";
|
173
|
+
}
|
174
|
+
// Open tag.
|
175
|
+
ansiCodes.push(seq);
|
176
|
+
return (
|
177
|
+
ret + (other[0] === "<" ? other : '<span style="' + other + ';">')
|
178
|
+
);
|
179
|
+
}
|
180
|
+
|
181
|
+
var ct = _closeTags[seq];
|
182
|
+
if (typeof ct === "function") {
|
183
|
+
return ct(ansiCodes);
|
184
|
+
} else if (ct) {
|
185
|
+
// Pop sequence
|
186
|
+
ansiCodes.pop();
|
187
|
+
return ct;
|
188
|
+
}
|
189
|
+
return "";
|
190
|
+
}
|
191
|
+
}
|
192
|
+
);
|
193
|
+
|
194
|
+
// Make sure tags are closed.
|
195
|
+
var l = ansiCodes.length;
|
196
|
+
l > 0 && (ret += Array(l + 1).join("</span>"));
|
197
|
+
|
198
|
+
return ret;
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Customize colors.
|
203
|
+
* @param {Object} colors reference to _defColors
|
204
|
+
*/
|
205
|
+
ansiHTML.setColors = function (colors) {
|
206
|
+
if (typeof colors !== "object") {
|
207
|
+
throw new Error("`colors` parameter must be an Object.");
|
208
|
+
}
|
209
|
+
|
210
|
+
var _finalColors = {};
|
211
|
+
for (var key in _defColors) {
|
212
|
+
var hex = colors.hasOwnProperty(key) ? colors[key] : null;
|
213
|
+
if (!hex) {
|
214
|
+
_finalColors[key] = _defColors[key];
|
215
|
+
continue;
|
216
|
+
}
|
217
|
+
if ("reset" === key) {
|
218
|
+
if (typeof hex === "string") {
|
219
|
+
hex = [hex];
|
220
|
+
}
|
221
|
+
if (
|
222
|
+
!Array.isArray(hex) ||
|
223
|
+
hex.length === 0 ||
|
224
|
+
hex.some(function (h) {
|
225
|
+
return typeof h !== "string";
|
226
|
+
})
|
227
|
+
) {
|
228
|
+
throw new Error(
|
229
|
+
"The value of `" +
|
230
|
+
key +
|
231
|
+
"` property must be an Array and each item could only be a hex string, e.g.: FF0000"
|
232
|
+
);
|
233
|
+
}
|
234
|
+
var defHexColor = _defColors[key];
|
235
|
+
if (!hex[0]) {
|
236
|
+
hex[0] = defHexColor[0];
|
237
|
+
}
|
238
|
+
if (hex.length === 1 || !hex[1]) {
|
239
|
+
hex = [hex[0]];
|
240
|
+
hex.push(defHexColor[1]);
|
241
|
+
}
|
242
|
+
|
243
|
+
hex = hex.slice(0, 2);
|
244
|
+
} else if (typeof hex !== "string") {
|
245
|
+
throw new Error(
|
246
|
+
"The value of `" + key + "` property must be a hex string, e.g.: FF0000"
|
247
|
+
);
|
248
|
+
}
|
249
|
+
_finalColors[key] = hex;
|
250
|
+
}
|
251
|
+
_setTags(_finalColors);
|
252
|
+
};
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Reset colors.
|
256
|
+
*/
|
257
|
+
ansiHTML.reset = function () {
|
258
|
+
_setTags(_defColors);
|
259
|
+
};
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Expose tags, including open and close.
|
263
|
+
* @type {Object}
|
264
|
+
*/
|
265
|
+
ansiHTML.tags = {};
|
266
|
+
|
267
|
+
if (Object.defineProperty) {
|
268
|
+
Object.defineProperty(ansiHTML.tags, "open", {
|
269
|
+
get: function () {
|
270
|
+
return _openTags;
|
271
|
+
}
|
272
|
+
});
|
273
|
+
Object.defineProperty(ansiHTML.tags, "close", {
|
274
|
+
get: function () {
|
275
|
+
return _closeTags;
|
276
|
+
}
|
277
|
+
});
|
278
|
+
} else {
|
279
|
+
ansiHTML.tags.open = _openTags;
|
280
|
+
ansiHTML.tags.close = _closeTags;
|
281
|
+
}
|
282
|
+
|
283
|
+
function _setTags(colors) {
|
284
|
+
// reset all
|
285
|
+
_openTags["0"] =
|
286
|
+
"font-weight:normal;opacity:1;color:#" +
|
287
|
+
colors.reset[0] +
|
288
|
+
";background:#" +
|
289
|
+
colors.reset[1];
|
290
|
+
// inverse
|
291
|
+
_openTags["7"] =
|
292
|
+
"color:#" + colors.reset[1] + ";background:#" + colors.reset[0];
|
293
|
+
// dark grey
|
294
|
+
_openTags["90"] = "color:#" + colors.darkgrey;
|
295
|
+
|
296
|
+
for (var code in _styles) {
|
297
|
+
var color = _styles[code];
|
298
|
+
var oriColor = colors[color] || "000";
|
299
|
+
_openTags[code] = "color:#" + oriColor;
|
300
|
+
code = parseInt(code);
|
301
|
+
_openTags[(code + 10).toString()] = "background:#" + oriColor;
|
302
|
+
}
|
303
|
+
}
|
304
|
+
|
305
|
+
ansiHTML.reset();
|
@@ -0,0 +1,102 @@
|
|
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
|
+
};
|
@@ -0,0 +1,96 @@
|
|
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 index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim();
|
43
|
+
});
|
44
|
+
|
45
|
+
// Clean up the file name
|
46
|
+
lines[0] = lines[0].replace(/^(.*) \d+:\d+-\d+$/, '$1');
|
47
|
+
|
48
|
+
// Cleans up verbose "module not found" messages for files and packages.
|
49
|
+
if (lines[1] && lines[1].indexOf('Module not found: ') === 0) {
|
50
|
+
lines = [
|
51
|
+
lines[0],
|
52
|
+
lines[1]
|
53
|
+
.replace('Error: ', '')
|
54
|
+
.replace('Module not found: Cannot find file:', 'Cannot find file:'),
|
55
|
+
];
|
56
|
+
}
|
57
|
+
|
58
|
+
message = lines.join('\n');
|
59
|
+
|
60
|
+
// Clean up syntax errors
|
61
|
+
message = message.replace('SyntaxError:', friendlySyntaxErrorLabel);
|
62
|
+
|
63
|
+
// Internal stacks are generally useless, so we strip them -
|
64
|
+
// except the stacks containing `webpack:`,
|
65
|
+
// because they're normally from user code generated by webpack.
|
66
|
+
message = message.replace(/^\s*at\s((?!webpack:).)*:\d+:\d+[\s)]*(\n|$)/gm, ''); // at ... ...:x:y
|
67
|
+
message = message.replace(/^\s*at\s((?!webpack:).)*<anonymous>[\s)]*(\n|$)/gm, ''); // at ... <anonymous>
|
68
|
+
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
69
|
+
|
70
|
+
return message.trim();
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Formats Webpack error messages into a more readable format.
|
75
|
+
* @param {Array<string | WebpackErrorObj>} errors An array of Webpack error messages.
|
76
|
+
* @returns {string[]} The formatted Webpack error messages.
|
77
|
+
*/
|
78
|
+
function formatWebpackErrors(errors) {
|
79
|
+
let formattedErrors = errors.map(function (errorObjOrMessage) {
|
80
|
+
// Webpack 5 compilation errors are in the form of descriptor objects,
|
81
|
+
// so we have to join pieces to get the format we want.
|
82
|
+
if (typeof errorObjOrMessage === 'object') {
|
83
|
+
return formatMessage([errorObjOrMessage.moduleName, errorObjOrMessage.message].join('\n'));
|
84
|
+
}
|
85
|
+
// Webpack 4 compilation errors are strings
|
86
|
+
return formatMessage(errorObjOrMessage);
|
87
|
+
});
|
88
|
+
|
89
|
+
if (formattedErrors.some(isLikelyASyntaxError)) {
|
90
|
+
// If there are any syntax errors, show just them.
|
91
|
+
formattedErrors = formattedErrors.filter(isLikelyASyntaxError);
|
92
|
+
}
|
93
|
+
return formattedErrors;
|
94
|
+
}
|
95
|
+
|
96
|
+
module.exports = formatWebpackErrors;
|
@@ -0,0 +1,23 @@
|
|
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;
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { Compiler } from "@rspack/core";
|
2
|
-
import { type PluginOptions } from "./options";
|
2
|
+
import { type NormalizedPluginOptions, type PluginOptions } from "./options";
|
3
3
|
export type { PluginOptions };
|
4
4
|
/**
|
5
5
|
* @typedef {Object} Options
|
@@ -7,7 +7,7 @@ export type { PluginOptions };
|
|
7
7
|
* @property {(string | RegExp | (string | RegExp)[] | null)=} exclude excluded resourcePath for loader
|
8
8
|
*/
|
9
9
|
declare class ReactRefreshRspackPlugin {
|
10
|
-
options:
|
10
|
+
options: NormalizedPluginOptions;
|
11
11
|
static deprecated_runtimePaths: string[];
|
12
12
|
constructor(options?: PluginOptions);
|
13
13
|
apply(compiler: Compiler): void;
|
package/dist/index.js
CHANGED
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
const path_1 = __importDefault(require("path"));
|
6
6
|
const options_1 = require("./options");
|
7
|
+
const getAdditionalEntries_1 = require("./utils/getAdditionalEntries");
|
8
|
+
const getSocketIntegration_1 = __importDefault(require("./utils/getSocketIntegration"));
|
7
9
|
const reactRefreshPath = require.resolve("../client/reactRefresh.js");
|
8
10
|
const reactRefreshEntryPath = require.resolve("../client/reactRefreshEntry.js");
|
9
11
|
const refreshUtilsPath = require.resolve("../client/refreshUtils.js");
|
@@ -36,9 +38,20 @@ class ReactRefreshRspackPlugin {
|
|
36
38
|
!this.options.forceEnable) {
|
37
39
|
return;
|
38
40
|
}
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
const addEntries = (0, getAdditionalEntries_1.getAdditionalEntries)({
|
42
|
+
devServer: compiler.options.devServer,
|
43
|
+
options: this.options
|
44
|
+
});
|
45
|
+
addEntries.prependEntries.forEach(entry => {
|
46
|
+
new compiler.webpack.EntryPlugin(compiler.context, entry, {
|
47
|
+
name: undefined
|
48
|
+
}).apply(compiler);
|
49
|
+
});
|
50
|
+
addEntries.overlayEntries.forEach(entry => {
|
51
|
+
new compiler.webpack.EntryPlugin(compiler.context, entry, {
|
52
|
+
name: undefined
|
53
|
+
}).apply(compiler);
|
54
|
+
});
|
42
55
|
new compiler.webpack.ProvidePlugin({
|
43
56
|
$ReactRefreshRuntime$: reactRefreshPath
|
44
57
|
}).apply(compiler);
|
@@ -55,7 +68,24 @@ class ReactRefreshRspackPlugin {
|
|
55
68
|
compiler.options.output.uniqueName ||
|
56
69
|
compiler.options.output.library))
|
57
70
|
};
|
71
|
+
const providedModules = {
|
72
|
+
__react_refresh_utils__: refreshUtilsPath
|
73
|
+
};
|
74
|
+
if (this.options.overlay === false) {
|
75
|
+
// Stub errorOverlay module so their calls can be erased
|
76
|
+
definedModules.__react_refresh_error_overlay__ = false;
|
77
|
+
definedModules.__react_refresh_socket__ = false;
|
78
|
+
}
|
79
|
+
else {
|
80
|
+
if (this.options.overlay.module) {
|
81
|
+
providedModules.__react_refresh_error_overlay__ = require.resolve(this.options.overlay.module);
|
82
|
+
}
|
83
|
+
if (this.options.overlay.sockIntegration) {
|
84
|
+
providedModules.__react_refresh_socket__ = (0, getSocketIntegration_1.default)(this.options.overlay.sockIntegration);
|
85
|
+
}
|
86
|
+
}
|
58
87
|
new compiler.webpack.DefinePlugin(definedModules).apply(compiler);
|
88
|
+
new compiler.webpack.ProvidePlugin(providedModules).apply(compiler);
|
59
89
|
const refreshPath = path_1.default.dirname(require.resolve("react-refresh"));
|
60
90
|
compiler.options.resolve.alias = {
|
61
91
|
"react-refresh": refreshPath,
|
package/dist/options.d.ts
CHANGED
@@ -1,7 +1,22 @@
|
|
1
|
+
import type { IntegrationType } from "./utils/getSocketIntegration";
|
2
|
+
interface OverlayOptions {
|
3
|
+
entry: string;
|
4
|
+
module: string;
|
5
|
+
sockIntegration: IntegrationType;
|
6
|
+
sockHost?: string;
|
7
|
+
sockPath?: string;
|
8
|
+
sockPort?: string;
|
9
|
+
sockProtocol?: string;
|
10
|
+
}
|
1
11
|
export type PluginOptions = {
|
2
12
|
include?: string | RegExp | (string | RegExp)[] | null;
|
3
13
|
exclude?: string | RegExp | (string | RegExp)[] | null;
|
4
14
|
library?: string;
|
5
15
|
forceEnable?: boolean;
|
16
|
+
overlay?: boolean | OverlayOptions;
|
6
17
|
};
|
7
|
-
export
|
18
|
+
export interface NormalizedPluginOptions extends Required<PluginOptions> {
|
19
|
+
overlay: false | OverlayOptions;
|
20
|
+
}
|
21
|
+
export declare function normalizeOptions(options: PluginOptions): NormalizedPluginOptions;
|
22
|
+
export {};
|
package/dist/options.js
CHANGED
@@ -9,11 +9,30 @@ const d = (object, property, defaultValue) => {
|
|
9
9
|
}
|
10
10
|
return object[property];
|
11
11
|
};
|
12
|
+
const normalizeOverlay = (options) => {
|
13
|
+
const defaultOverlay = {
|
14
|
+
entry: require.resolve("../client/errorOverlayEntry.js"),
|
15
|
+
module: require.resolve("../client/overlay/index.js"),
|
16
|
+
sockIntegration: "wds"
|
17
|
+
};
|
18
|
+
if (!options) {
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
if (typeof options === "undefined" || options === true) {
|
22
|
+
return defaultOverlay;
|
23
|
+
}
|
24
|
+
options.entry = options.entry ?? defaultOverlay.entry;
|
25
|
+
options.module = options.module ?? defaultOverlay.module;
|
26
|
+
options.sockIntegration =
|
27
|
+
options.sockIntegration ?? defaultOverlay.sockIntegration;
|
28
|
+
return options;
|
29
|
+
};
|
12
30
|
function normalizeOptions(options) {
|
13
31
|
d(options, "exclude", /node_modules/i);
|
14
32
|
d(options, "include", /\.([cm]js|[jt]sx?|flow)$/i);
|
15
33
|
d(options, "library");
|
16
34
|
d(options, "forceEnable", false);
|
35
|
+
options.overlay = normalizeOverlay(options.overlay);
|
17
36
|
return options;
|
18
37
|
}
|
19
38
|
exports.normalizeOptions = normalizeOptions;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
declare global {
|
2
|
+
var __webpack_dev_server_client__: any;
|
3
|
+
}
|
4
|
+
/**
|
5
|
+
* Initializes a socket server for HMR for webpack-dev-server.
|
6
|
+
* @param {function(*): void} messageHandler A handler to consume Webpack compilation messages.
|
7
|
+
* @param {string} [resourceQuery] Webpack's `__resourceQuery` string.
|
8
|
+
* @returns {void}
|
9
|
+
*/
|
10
|
+
export declare function init(messageHandler: (...args: any[]) => void, resourceQuery: string): void;
|