@rspack/plugin-react-refresh 1.0.0-beta.3 → 1.0.0-beta.4
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/LICENSE +0 -1
- package/README.md +67 -3
- package/client/errorOverlayEntry.js +9 -7
- package/client/overlay/components/CompileErrorTrace.js +7 -2
- package/client/overlay/components/PageHeader.js +4 -2
- package/client/overlay/components/RuntimeErrorHeader.js +2 -1
- package/client/overlay/components/RuntimeErrorStack.js +2 -1
- package/client/overlay/index.js +10 -3
- package/client/overlay/utils.js +1 -1
- package/client/reactRefresh.js +15 -15
- package/client/reactRefreshEntry.js +41 -41
- package/client/refreshUtils.js +213 -213
- package/client/utils/ansi-html.js +80 -78
- package/client/utils/errorEventHandlers.js +2 -2
- package/client/utils/formatWebpackErrors.js +15 -5
- package/client/utils/retry.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -19
- package/dist/options.d.ts +1 -1
- package/dist/options.js +10 -10
- package/dist/sockets/WDSSocket.d.ts +2 -2
- package/dist/sockets/WDSSocket.js +2 -2
- package/dist/sockets/utils/getCurrentScriptSource.js +4 -4
- package/dist/sockets/utils/getSocketUrlParts.d.ts +1 -1
- package/dist/sockets/utils/getSocketUrlParts.js +13 -12
- package/dist/sockets/utils/getUrlFromParts.d.ts +2 -2
- package/dist/sockets/utils/getUrlFromParts.js +3 -3
- package/dist/sockets/utils/getWDSMetadata.d.ts +3 -3
- package/dist/sockets/utils/getWDSMetadata.js +6 -6
- package/dist/utils/getAdditionalEntries.d.ts +2 -2
- package/dist/utils/getAdditionalEntries.js +11 -11
- package/dist/utils/getSocketIntegration.d.ts +1 -1
- package/dist/utils/getSocketIntegration.js +2 -2
- package/package.json +31 -21
@@ -11,7 +11,7 @@
|
|
11
11
|
* Author @Tjatse
|
12
12
|
* https://github.com/mahdyar/ansi-html-community/blob/master/LICENSE
|
13
13
|
*/
|
14
|
-
|
14
|
+
'use strict';
|
15
15
|
|
16
16
|
module.exports = ansiHTML;
|
17
17
|
|
@@ -20,94 +20,94 @@ var _regANSI =
|
|
20
20
|
/(?:(?:\u001b\[)|\u009b)(?:(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?[A-M|f-m])|\u001b[A-M]/;
|
21
21
|
|
22
22
|
var _defColors = {
|
23
|
-
reset: [
|
24
|
-
black:
|
25
|
-
red:
|
26
|
-
green:
|
27
|
-
yellow:
|
28
|
-
blue:
|
29
|
-
magenta:
|
30
|
-
cyan:
|
31
|
-
lightgrey:
|
32
|
-
darkgrey:
|
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
33
|
};
|
34
34
|
var _styles = {
|
35
|
-
30:
|
36
|
-
31:
|
37
|
-
32:
|
38
|
-
33:
|
39
|
-
34:
|
40
|
-
35:
|
41
|
-
36:
|
42
|
-
37:
|
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
43
|
};
|
44
44
|
|
45
45
|
var _colorMode = {
|
46
|
-
2:
|
46
|
+
2: 'rgb',
|
47
47
|
};
|
48
48
|
|
49
49
|
var _openTags = {
|
50
|
-
1:
|
51
|
-
2:
|
52
|
-
3:
|
53
|
-
4:
|
54
|
-
8:
|
55
|
-
9:
|
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
56
|
38: function (match) {
|
57
57
|
// color
|
58
58
|
var mode = _colorMode[match[0]];
|
59
|
-
if (mode ===
|
59
|
+
if (mode === 'rgb') {
|
60
60
|
var r, g, b;
|
61
61
|
r = match[1];
|
62
62
|
g = match[2];
|
63
63
|
b = match[3];
|
64
64
|
match.advance(4);
|
65
|
-
return
|
65
|
+
return 'color: rgb(' + r + ',' + g + ',' + b + ')';
|
66
66
|
}
|
67
67
|
},
|
68
68
|
48: function (match) {
|
69
69
|
// background color
|
70
70
|
var mode = _colorMode[match[0]];
|
71
|
-
if (mode ===
|
71
|
+
if (mode === 'rgb') {
|
72
72
|
var r, g, b;
|
73
73
|
r = match[1];
|
74
74
|
g = match[2];
|
75
75
|
b = match[3];
|
76
76
|
match.advance(4);
|
77
|
-
return
|
77
|
+
return 'background-color: rgb(' + r + ',' + g + ',' + b + ')';
|
78
78
|
}
|
79
|
-
}
|
79
|
+
},
|
80
80
|
};
|
81
81
|
|
82
82
|
var _openTagToCloseTag = {
|
83
|
-
3:
|
84
|
-
4:
|
85
|
-
9:
|
83
|
+
3: '23',
|
84
|
+
4: '24',
|
85
|
+
9: '29',
|
86
86
|
};
|
87
87
|
|
88
88
|
var _closeTags = {
|
89
89
|
0: function (ansiCodes) {
|
90
|
-
if (!ansiCodes) return
|
91
|
-
if (!ansiCodes.length) return
|
90
|
+
if (!ansiCodes) return '</span>';
|
91
|
+
if (!ansiCodes.length) return '';
|
92
92
|
var code,
|
93
|
-
ret =
|
93
|
+
ret = '';
|
94
94
|
while ((code = ansiCodes.pop())) {
|
95
95
|
var closeTag = _openTagToCloseTag[code];
|
96
96
|
if (closeTag) {
|
97
97
|
ret += _closeTags[closeTag];
|
98
98
|
continue;
|
99
99
|
}
|
100
|
-
ret +=
|
100
|
+
ret += '</span>';
|
101
101
|
}
|
102
102
|
return ret;
|
103
103
|
},
|
104
|
-
23:
|
105
|
-
24:
|
106
|
-
29:
|
104
|
+
23: '</i>', // reset italic
|
105
|
+
24: '</u>', // reset underscore
|
106
|
+
29: '</del>', // reset delete
|
107
107
|
};
|
108
108
|
|
109
109
|
[21, 22, 27, 28, 39, 49].forEach(function (n) {
|
110
|
-
_closeTags[n] =
|
110
|
+
_closeTags[n] = '</span>';
|
111
111
|
});
|
112
112
|
|
113
113
|
/**
|
@@ -117,7 +117,7 @@ var _closeTags = {
|
|
117
117
|
*/
|
118
118
|
function normalizeSeq(seq) {
|
119
119
|
if (seq === null || seq === undefined) return null;
|
120
|
-
if (seq.startsWith(
|
120
|
+
if (seq.startsWith(';')) {
|
121
121
|
return seq.slice(1);
|
122
122
|
}
|
123
123
|
return seq;
|
@@ -141,13 +141,13 @@ function ansiHTML(text) {
|
|
141
141
|
/\033\[(?:[0-9]{1,3})?(?:(?:;[0-9]{0,3})*)?m/g,
|
142
142
|
function (m) {
|
143
143
|
var match = m.match(/(;?\d+)/g).map(normalizeSeq);
|
144
|
-
Object.defineProperty(match,
|
144
|
+
Object.defineProperty(match, 'advance', {
|
145
145
|
value: function (count) {
|
146
146
|
this.splice(0, count);
|
147
|
-
}
|
147
|
+
},
|
148
148
|
});
|
149
149
|
var seq,
|
150
|
-
rep =
|
150
|
+
rep = '';
|
151
151
|
while ((seq = match[0])) {
|
152
152
|
match.advance(1);
|
153
153
|
rep += applySeq(seq);
|
@@ -158,42 +158,42 @@ function ansiHTML(text) {
|
|
158
158
|
var other = _openTags[seq];
|
159
159
|
if (
|
160
160
|
other &&
|
161
|
-
(other = typeof other ===
|
161
|
+
(other = typeof other === 'function' ? other(match) : other)
|
162
162
|
) {
|
163
163
|
// If reset signal is encountered, we have to reset everything.
|
164
|
-
var ret =
|
165
|
-
if (seq ===
|
164
|
+
var ret = '';
|
165
|
+
if (seq === '0') {
|
166
166
|
ret += _closeTags[seq](ansiCodes);
|
167
167
|
}
|
168
168
|
// If current sequence has been opened, close it.
|
169
169
|
if (!!~ansiCodes.indexOf(seq)) {
|
170
170
|
// eslint-disable-line no-extra-boolean-cast
|
171
171
|
ansiCodes.pop();
|
172
|
-
return
|
172
|
+
return '</span>';
|
173
173
|
}
|
174
174
|
// Open tag.
|
175
175
|
ansiCodes.push(seq);
|
176
176
|
return (
|
177
|
-
ret + (other[0] ===
|
177
|
+
ret + (other[0] === '<' ? other : '<span style="' + other + ';">')
|
178
178
|
);
|
179
179
|
}
|
180
180
|
|
181
181
|
var ct = _closeTags[seq];
|
182
|
-
if (typeof ct ===
|
182
|
+
if (typeof ct === 'function') {
|
183
183
|
return ct(ansiCodes);
|
184
184
|
} else if (ct) {
|
185
185
|
// Pop sequence
|
186
186
|
ansiCodes.pop();
|
187
187
|
return ct;
|
188
188
|
}
|
189
|
-
return
|
189
|
+
return '';
|
190
190
|
}
|
191
|
-
}
|
191
|
+
},
|
192
192
|
);
|
193
193
|
|
194
194
|
// Make sure tags are closed.
|
195
195
|
var l = ansiCodes.length;
|
196
|
-
l > 0 && (ret += Array(l + 1).join(
|
196
|
+
l > 0 && (ret += Array(l + 1).join('</span>'));
|
197
197
|
|
198
198
|
return ret;
|
199
199
|
}
|
@@ -203,8 +203,8 @@ function ansiHTML(text) {
|
|
203
203
|
* @param {Object} colors reference to _defColors
|
204
204
|
*/
|
205
205
|
ansiHTML.setColors = function (colors) {
|
206
|
-
if (typeof colors !==
|
207
|
-
throw new Error(
|
206
|
+
if (typeof colors !== 'object') {
|
207
|
+
throw new Error('`colors` parameter must be an Object.');
|
208
208
|
}
|
209
209
|
|
210
210
|
var _finalColors = {};
|
@@ -214,21 +214,21 @@ ansiHTML.setColors = function (colors) {
|
|
214
214
|
_finalColors[key] = _defColors[key];
|
215
215
|
continue;
|
216
216
|
}
|
217
|
-
if (
|
218
|
-
if (typeof hex ===
|
217
|
+
if ('reset' === key) {
|
218
|
+
if (typeof hex === 'string') {
|
219
219
|
hex = [hex];
|
220
220
|
}
|
221
221
|
if (
|
222
222
|
!Array.isArray(hex) ||
|
223
223
|
hex.length === 0 ||
|
224
224
|
hex.some(function (h) {
|
225
|
-
return typeof h !==
|
225
|
+
return typeof h !== 'string';
|
226
226
|
})
|
227
227
|
) {
|
228
228
|
throw new Error(
|
229
|
-
|
230
|
-
|
231
|
-
|
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
232
|
);
|
233
233
|
}
|
234
234
|
var defHexColor = _defColors[key];
|
@@ -241,9 +241,11 @@ ansiHTML.setColors = function (colors) {
|
|
241
241
|
}
|
242
242
|
|
243
243
|
hex = hex.slice(0, 2);
|
244
|
-
} else if (typeof hex !==
|
244
|
+
} else if (typeof hex !== 'string') {
|
245
245
|
throw new Error(
|
246
|
-
|
246
|
+
'The value of `' +
|
247
|
+
key +
|
248
|
+
'` property must be a hex string, e.g.: FF0000',
|
247
249
|
);
|
248
250
|
}
|
249
251
|
_finalColors[key] = hex;
|
@@ -265,15 +267,15 @@ ansiHTML.reset = function () {
|
|
265
267
|
ansiHTML.tags = {};
|
266
268
|
|
267
269
|
if (Object.defineProperty) {
|
268
|
-
Object.defineProperty(ansiHTML.tags,
|
270
|
+
Object.defineProperty(ansiHTML.tags, 'open', {
|
269
271
|
get: function () {
|
270
272
|
return _openTags;
|
271
|
-
}
|
273
|
+
},
|
272
274
|
});
|
273
|
-
Object.defineProperty(ansiHTML.tags,
|
275
|
+
Object.defineProperty(ansiHTML.tags, 'close', {
|
274
276
|
get: function () {
|
275
277
|
return _closeTags;
|
276
|
-
}
|
278
|
+
},
|
277
279
|
});
|
278
280
|
} else {
|
279
281
|
ansiHTML.tags.open = _openTags;
|
@@ -282,23 +284,23 @@ if (Object.defineProperty) {
|
|
282
284
|
|
283
285
|
function _setTags(colors) {
|
284
286
|
// reset all
|
285
|
-
_openTags[
|
286
|
-
|
287
|
+
_openTags['0'] =
|
288
|
+
'font-weight:normal;opacity:1;color:#' +
|
287
289
|
colors.reset[0] +
|
288
|
-
|
290
|
+
';background:#' +
|
289
291
|
colors.reset[1];
|
290
292
|
// inverse
|
291
|
-
_openTags[
|
292
|
-
|
293
|
+
_openTags['7'] =
|
294
|
+
'color:#' + colors.reset[1] + ';background:#' + colors.reset[0];
|
293
295
|
// dark grey
|
294
|
-
_openTags[
|
296
|
+
_openTags['90'] = 'color:#' + colors.darkgrey;
|
295
297
|
|
296
298
|
for (var code in _styles) {
|
297
299
|
var color = _styles[code];
|
298
|
-
var oriColor = colors[color] ||
|
299
|
-
_openTags[code] =
|
300
|
+
var oriColor = colors[color] || '000';
|
301
|
+
_openTags[code] = 'color:#' + oriColor;
|
300
302
|
code = parseInt(code);
|
301
|
-
_openTags[(code + 10).toString()] =
|
303
|
+
_openTags[(code + 10).toString()] = 'background:#' + oriColor;
|
302
304
|
}
|
303
305
|
}
|
304
306
|
|
@@ -93,10 +93,10 @@ function createWindowEventHandler(eventType, createHandler) {
|
|
93
93
|
const handleError = createWindowEventHandler('error', createErrorHandler);
|
94
94
|
const handleUnhandledRejection = createWindowEventHandler(
|
95
95
|
'unhandledrejection',
|
96
|
-
createRejectionHandler
|
96
|
+
createRejectionHandler,
|
97
97
|
);
|
98
98
|
|
99
99
|
module.exports = {
|
100
100
|
handleError: handleError,
|
101
101
|
handleUnhandledRejection: handleUnhandledRejection,
|
102
|
-
};
|
102
|
+
};
|
@@ -39,7 +39,9 @@ function formatMessage(message) {
|
|
39
39
|
|
40
40
|
// Remove duplicated newlines
|
41
41
|
lines = lines.filter(function (line, index, arr) {
|
42
|
-
return
|
42
|
+
return (
|
43
|
+
index === 0 || line.trim() !== '' || line.trim() !== arr[index - 1].trim()
|
44
|
+
);
|
43
45
|
});
|
44
46
|
|
45
47
|
// Clean up the file name
|
@@ -63,8 +65,14 @@ function formatMessage(message) {
|
|
63
65
|
// Internal stacks are generally useless, so we strip them -
|
64
66
|
// except the stacks containing `webpack:`,
|
65
67
|
// because they're normally from user code generated by webpack.
|
66
|
-
message = message.replace(
|
67
|
-
|
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>
|
68
76
|
message = message.replace(/^\s*at\s<anonymous>(\n|$)/gm, ''); // at <anonymous>
|
69
77
|
|
70
78
|
return message.trim();
|
@@ -80,7 +88,9 @@ function formatWebpackErrors(errors) {
|
|
80
88
|
// Webpack 5 compilation errors are in the form of descriptor objects,
|
81
89
|
// so we have to join pieces to get the format we want.
|
82
90
|
if (typeof errorObjOrMessage === 'object') {
|
83
|
-
return formatMessage(
|
91
|
+
return formatMessage(
|
92
|
+
[errorObjOrMessage.moduleName, errorObjOrMessage.message].join('\n'),
|
93
|
+
);
|
84
94
|
}
|
85
95
|
// Webpack 4 compilation errors are strings
|
86
96
|
return formatMessage(errorObjOrMessage);
|
@@ -93,4 +103,4 @@ function formatWebpackErrors(errors) {
|
|
93
103
|
return formattedErrors;
|
94
104
|
}
|
95
105
|
|
96
|
-
module.exports = formatWebpackErrors;
|
106
|
+
module.exports = formatWebpackErrors;
|
package/client/utils/retry.js
CHANGED
@@ -12,7 +12,7 @@ function runWithRetry(callback, maxRetries) {
|
|
12
12
|
function () {
|
13
13
|
executeWithRetryAndTimeout(currentCount + 1);
|
14
14
|
},
|
15
|
-
Math.pow(10, currentCount)
|
15
|
+
Math.pow(10, currentCount),
|
16
16
|
);
|
17
17
|
}
|
18
18
|
}
|
@@ -20,4 +20,4 @@ function runWithRetry(callback, maxRetries) {
|
|
20
20
|
executeWithRetryAndTimeout(0);
|
21
21
|
}
|
22
22
|
|
23
|
-
module.exports = runWithRetry;
|
23
|
+
module.exports = runWithRetry;
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { Compiler } from
|
2
|
-
import type { NormalizedPluginOptions, PluginOptions } from
|
1
|
+
import type { Compiler } from '@rspack/core';
|
2
|
+
import type { NormalizedPluginOptions, PluginOptions } from './options';
|
3
3
|
export type { PluginOptions };
|
4
4
|
declare class ReactRefreshRspackPlugin {
|
5
5
|
options: NormalizedPluginOptions;
|
package/dist/index.js
CHANGED
@@ -6,17 +6,17 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
6
6
|
const options_1 = require("./options");
|
7
7
|
const getAdditionalEntries_1 = require("./utils/getAdditionalEntries");
|
8
8
|
const getSocketIntegration_1 = require("./utils/getSocketIntegration");
|
9
|
-
const reactRefreshPath = require.resolve(
|
10
|
-
const reactRefreshEntryPath = require.resolve(
|
11
|
-
const refreshUtilsPath = require.resolve(
|
12
|
-
const refreshRuntimeDirPath = node_path_1.default.dirname(require.resolve(
|
13
|
-
paths: [reactRefreshPath]
|
9
|
+
const reactRefreshPath = require.resolve('../client/reactRefresh.js');
|
10
|
+
const reactRefreshEntryPath = require.resolve('../client/reactRefreshEntry.js');
|
11
|
+
const refreshUtilsPath = require.resolve('../client/refreshUtils.js');
|
12
|
+
const refreshRuntimeDirPath = node_path_1.default.dirname(require.resolve('react-refresh', {
|
13
|
+
paths: [reactRefreshPath],
|
14
14
|
}));
|
15
15
|
const runtimePaths = [
|
16
16
|
reactRefreshEntryPath,
|
17
17
|
reactRefreshPath,
|
18
18
|
refreshUtilsPath,
|
19
|
-
refreshRuntimeDirPath
|
19
|
+
refreshRuntimeDirPath,
|
20
20
|
];
|
21
21
|
class ReactRefreshRspackPlugin {
|
22
22
|
constructor(options = {}) {
|
@@ -26,45 +26,47 @@ class ReactRefreshRspackPlugin {
|
|
26
26
|
if (
|
27
27
|
// Webpack do not set process.env.NODE_ENV, so we need to check for mode.
|
28
28
|
// Ref: https://github.com/webpack/webpack/issues/7074
|
29
|
-
(compiler.options.mode !==
|
29
|
+
(compiler.options.mode !== 'development' ||
|
30
30
|
// We also check for production process.env.NODE_ENV,
|
31
31
|
// in case it was set and mode is non-development (e.g. 'none')
|
32
|
-
(process.env.NODE_ENV && process.env.NODE_ENV ===
|
32
|
+
(process.env.NODE_ENV && process.env.NODE_ENV === 'production')) &&
|
33
33
|
!this.options.forceEnable) {
|
34
34
|
return;
|
35
35
|
}
|
36
36
|
const addEntries = (0, getAdditionalEntries_1.getAdditionalEntries)({
|
37
37
|
devServer: compiler.options.devServer,
|
38
|
-
options: this.options
|
38
|
+
options: this.options,
|
39
39
|
});
|
40
40
|
for (const entry of addEntries.prependEntries) {
|
41
41
|
new compiler.webpack.EntryPlugin(compiler.context, entry, {
|
42
|
-
name: undefined
|
42
|
+
name: undefined,
|
43
43
|
}).apply(compiler);
|
44
44
|
}
|
45
45
|
for (const entry of addEntries.overlayEntries) {
|
46
46
|
new compiler.webpack.EntryPlugin(compiler.context, entry, {
|
47
|
-
name: undefined
|
47
|
+
name: undefined,
|
48
48
|
}).apply(compiler);
|
49
49
|
}
|
50
50
|
new compiler.webpack.ProvidePlugin({
|
51
|
-
$ReactRefreshRuntime$: reactRefreshPath
|
51
|
+
$ReactRefreshRuntime$: reactRefreshPath,
|
52
52
|
}).apply(compiler);
|
53
53
|
compiler.options.module.rules.unshift({
|
54
|
+
// biome-ignore lint: exists
|
54
55
|
include: this.options.include,
|
55
56
|
exclude: {
|
56
|
-
|
57
|
+
// biome-ignore lint: exists
|
58
|
+
or: [this.options.exclude, [...runtimePaths]].filter(Boolean),
|
57
59
|
},
|
58
|
-
use:
|
60
|
+
use: 'builtin:react-refresh-loader',
|
59
61
|
});
|
60
62
|
const definedModules = {
|
61
63
|
// For Multiple Instance Mode
|
62
64
|
__react_refresh_library__: JSON.stringify(compiler.webpack.Template.toIdentifier(this.options.library ||
|
63
65
|
compiler.options.output.uniqueName ||
|
64
|
-
compiler.options.output.library))
|
66
|
+
compiler.options.output.library)),
|
65
67
|
};
|
66
68
|
const providedModules = {
|
67
|
-
__react_refresh_utils__: refreshUtilsPath
|
69
|
+
__react_refresh_utils__: refreshUtilsPath,
|
68
70
|
};
|
69
71
|
if (this.options.overlay === false) {
|
70
72
|
// Stub errorOverlay module so their calls can be erased
|
@@ -81,10 +83,10 @@ class ReactRefreshRspackPlugin {
|
|
81
83
|
}
|
82
84
|
new compiler.webpack.DefinePlugin(definedModules).apply(compiler);
|
83
85
|
new compiler.webpack.ProvidePlugin(providedModules).apply(compiler);
|
84
|
-
const refreshPath = node_path_1.default.dirname(require.resolve(
|
86
|
+
const refreshPath = node_path_1.default.dirname(require.resolve('react-refresh'));
|
85
87
|
compiler.options.resolve.alias = {
|
86
|
-
|
87
|
-
...compiler.options.resolve.alias
|
88
|
+
'react-refresh': refreshPath,
|
89
|
+
...compiler.options.resolve.alias,
|
88
90
|
};
|
89
91
|
}
|
90
92
|
}
|
package/dist/options.d.ts
CHANGED
package/dist/options.js
CHANGED
@@ -3,22 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizeOptions = void 0;
|
4
4
|
const d = (object, property, defaultValue) => {
|
5
5
|
// TODO: should we also add default for null?
|
6
|
-
if (typeof object[property] ===
|
7
|
-
typeof defaultValue !==
|
6
|
+
if (typeof object[property] === 'undefined' &&
|
7
|
+
typeof defaultValue !== 'undefined') {
|
8
8
|
object[property] = defaultValue;
|
9
9
|
}
|
10
10
|
return object[property];
|
11
11
|
};
|
12
12
|
const normalizeOverlay = (options) => {
|
13
13
|
const defaultOverlay = {
|
14
|
-
entry: require.resolve(
|
15
|
-
module: require.resolve(
|
16
|
-
sockIntegration:
|
14
|
+
entry: require.resolve('../client/errorOverlayEntry.js'),
|
15
|
+
module: require.resolve('../client/overlay/index.js'),
|
16
|
+
sockIntegration: 'wds',
|
17
17
|
};
|
18
18
|
if (!options) {
|
19
19
|
return false;
|
20
20
|
}
|
21
|
-
if (typeof options ===
|
21
|
+
if (typeof options === 'undefined' || options === true) {
|
22
22
|
return defaultOverlay;
|
23
23
|
}
|
24
24
|
options.entry = options.entry ?? defaultOverlay.entry;
|
@@ -28,10 +28,10 @@ const normalizeOverlay = (options) => {
|
|
28
28
|
return options;
|
29
29
|
};
|
30
30
|
function normalizeOptions(options) {
|
31
|
-
d(options,
|
32
|
-
d(options,
|
33
|
-
d(options,
|
34
|
-
d(options,
|
31
|
+
d(options, 'exclude', /node_modules/i);
|
32
|
+
d(options, 'include', /\.([cm]js|[jt]sx?|flow)$/i);
|
33
|
+
d(options, 'library');
|
34
|
+
d(options, 'forceEnable', false);
|
35
35
|
options.overlay = normalizeOverlay(options.overlay);
|
36
36
|
return options;
|
37
37
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { SocketClient } from
|
1
|
+
import type { SocketClient } from './utils/getWDSMetadata';
|
2
2
|
declare global {
|
3
3
|
var __webpack_dev_server_client__: SocketClient | {
|
4
4
|
default: SocketClient;
|
@@ -10,4 +10,4 @@ declare global {
|
|
10
10
|
* @param resourceQuery Webpack's `__resourceQuery` string.
|
11
11
|
* @returns
|
12
12
|
*/
|
13
|
-
export declare function init(messageHandler: (...args:
|
13
|
+
export declare function init(messageHandler: (...args: unknown[]) => void, resourceQuery: string): void;
|
@@ -23,9 +23,9 @@ const getWDSMetadata_1 = __importDefault(require("./utils/getWDSMetadata"));
|
|
23
23
|
* @returns
|
24
24
|
*/
|
25
25
|
function init(messageHandler, resourceQuery) {
|
26
|
-
if (typeof __webpack_dev_server_client__ !==
|
26
|
+
if (typeof __webpack_dev_server_client__ !== 'undefined') {
|
27
27
|
let SocketClient;
|
28
|
-
if (
|
28
|
+
if ('default' in __webpack_dev_server_client__) {
|
29
29
|
SocketClient = __webpack_dev_server_client__.default;
|
30
30
|
}
|
31
31
|
else {
|
@@ -3,20 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function getCurrentScriptSource() {
|
4
4
|
// `document.currentScript` is the most accurate way to get the current running script,
|
5
5
|
// but is not supported in all browsers (most notably, IE).
|
6
|
-
if (
|
6
|
+
if ('currentScript' in document) {
|
7
7
|
// In some cases, `document.currentScript` would be `null` even if the browser supports it:
|
8
8
|
// e.g. asynchronous chunks on Firefox.
|
9
9
|
// We should not fallback to the list-approach as it would not be safe.
|
10
10
|
if (document.currentScript == null)
|
11
11
|
return;
|
12
|
-
return document.currentScript.getAttribute(
|
12
|
+
return document.currentScript.getAttribute('src');
|
13
13
|
}
|
14
14
|
// Fallback to getting all scripts running in the document,
|
15
15
|
// and finding the last one injected.
|
16
|
-
const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], elem => elem.getAttribute(
|
16
|
+
const scriptElementsWithSrc = Array.prototype.filter.call(document.scripts || [], (elem) => elem.getAttribute('src'));
|
17
17
|
if (!scriptElementsWithSrc.length)
|
18
18
|
return;
|
19
19
|
const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
20
|
-
return currentScript.getAttribute(
|
20
|
+
return currentScript.getAttribute('src');
|
21
21
|
}
|
22
22
|
exports.default = getCurrentScriptSource;
|