@rspack/dev-server 1.2.1 → 2.0.0-beta.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/README.md +17 -17
- package/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +28 -28
- package/client/index.d.ts +17 -0
- package/client/index.js +224 -363
- package/client/modules/logger/Logger.d.ts +40 -0
- package/client/modules/logger/Logger.js +123 -0
- package/client/modules/logger/createConsoleLogger.d.ts +12 -0
- package/client/modules/logger/createConsoleLogger.js +119 -0
- package/client/modules/logger/index.d.ts +18 -0
- package/client/modules/logger/index.js +20 -712
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +44 -0
- package/client/overlay.js +243 -292
- package/client/progress.d.ts +11 -0
- package/client/progress.js +178 -111
- package/client/socket.d.ts +15 -0
- package/client/socket.js +19 -46
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +98 -145
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +7 -17
- package/{dist/servers/SockJSServer.d.ts → client/utils/sendMessage.d.ts} +2 -1
- package/client/utils/sendMessage.js +6 -15
- package/dist/0~launch-editor.js +618 -0
- package/dist/0~open.js +547 -0
- package/dist/0~p-retry.js +158 -0
- package/dist/131.js +1398 -0
- package/dist/config.d.ts +1 -3
- package/dist/getPort.d.ts +4 -1
- package/dist/index.js +1 -5
- package/dist/rslib-runtime.js +66 -0
- package/dist/server.d.ts +7 -18
- package/dist/servers/WebsocketServer.d.ts +8 -1
- package/dist/types.d.ts +14 -29
- package/package.json +74 -103
- package/client/clients/SockJSClient.js +0 -34
- package/client/modules/sockjs-client/index.js +0 -4506
- package/dist/config.js +0 -2
- package/dist/getPort.js +0 -131
- package/dist/options.json +0 -1034
- package/dist/server.js +0 -2222
- package/dist/servers/BaseServer.js +0 -20
- package/dist/servers/SockJSServer.js +0 -110
- package/dist/servers/WebsocketServer.js +0 -72
- package/dist/types.js +0 -5
package/client/overlay.js
CHANGED
|
@@ -1,228 +1,221 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).
|
|
23
|
-
import ansiHTML from './utils/ansiHTML';
|
|
24
|
-
var getCodePoint = !!String.prototype.codePointAt
|
|
25
|
-
? function (input, position) {
|
|
26
|
-
return input.codePointAt(position);
|
|
1
|
+
import ansiHTML from "./utils/ansiHTML.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
function _object_spread(target) {
|
|
13
|
+
for(var i = 1; i < arguments.length; i++){
|
|
14
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
15
|
+
var ownKeys = Object.keys(source);
|
|
16
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
17
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
18
|
+
}));
|
|
19
|
+
ownKeys.forEach(function(key) {
|
|
20
|
+
_define_property(target, key, source[key]);
|
|
21
|
+
});
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function overlay_ownKeys(object, enumerableOnly) {
|
|
26
|
+
var keys = Object.keys(object);
|
|
27
|
+
if (Object.getOwnPropertySymbols) {
|
|
28
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
29
|
+
if (enumerableOnly) symbols = symbols.filter(function(sym) {
|
|
30
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
31
|
+
});
|
|
32
|
+
keys.push.apply(keys, symbols);
|
|
33
|
+
}
|
|
34
|
+
return keys;
|
|
35
|
+
}
|
|
36
|
+
function _object_spread_props(target, source) {
|
|
37
|
+
source = null != source ? source : {};
|
|
38
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
39
|
+
else overlay_ownKeys(Object(source)).forEach(function(key) {
|
|
40
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
41
|
+
});
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
const getCodePoint = String.prototype.codePointAt ? (input, position)=>input.codePointAt(position) : (input, position)=>(input.charCodeAt(position) - 0xd800) * 0x400 + input.charCodeAt(position + 1) - 0xdc00 + 0x10000;
|
|
45
|
+
const replaceUsingRegExp = (macroText, macroRegExp, macroReplacer)=>{
|
|
35
46
|
macroRegExp.lastIndex = 0;
|
|
36
|
-
|
|
37
|
-
|
|
47
|
+
let replaceMatch = macroRegExp.exec(macroText);
|
|
48
|
+
let replaceResult;
|
|
38
49
|
if (replaceMatch) {
|
|
39
50
|
replaceResult = '';
|
|
40
|
-
|
|
51
|
+
let replaceLastIndex = 0;
|
|
41
52
|
do {
|
|
42
|
-
if (replaceLastIndex !== replaceMatch.index)
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
var replaceInput = replaceMatch[0];
|
|
53
|
+
if (replaceLastIndex !== replaceMatch.index) replaceResult += macroText.slice(replaceLastIndex, replaceMatch.index);
|
|
54
|
+
const replaceInput = replaceMatch[0];
|
|
46
55
|
replaceResult += macroReplacer(replaceInput);
|
|
47
56
|
replaceLastIndex = replaceMatch.index + replaceInput.length;
|
|
48
|
-
}
|
|
49
|
-
if (replaceLastIndex !== macroText.length)
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
replaceResult = macroText;
|
|
55
|
-
}
|
|
57
|
+
}while (replaceMatch = macroRegExp.exec(macroText));
|
|
58
|
+
if (replaceLastIndex !== macroText.length) replaceResult += macroText.slice(replaceLastIndex);
|
|
59
|
+
} else replaceResult = macroText;
|
|
56
60
|
return replaceResult;
|
|
57
61
|
};
|
|
58
|
-
|
|
62
|
+
const references = {
|
|
59
63
|
'<': '<',
|
|
60
64
|
'>': '>',
|
|
61
65
|
'"': '"',
|
|
62
66
|
"'": ''',
|
|
63
|
-
'&': '&'
|
|
67
|
+
'&': '&'
|
|
64
68
|
};
|
|
65
69
|
function encode(text) {
|
|
66
|
-
if (!text)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return replaceUsingRegExp(text, /[<>'"&]/g, function (input) {
|
|
70
|
-
var result = references[input];
|
|
70
|
+
if (!text) return '';
|
|
71
|
+
return replaceUsingRegExp(text, /[<>'"&]/g, (input)=>{
|
|
72
|
+
let result = references[input];
|
|
71
73
|
if (!result) {
|
|
72
|
-
|
|
73
|
-
result =
|
|
74
|
+
const code = input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0);
|
|
75
|
+
result = `&#${code};`;
|
|
74
76
|
}
|
|
75
77
|
return result;
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* - the state definition only support `on` and target must be declared with { target: 'nextState', actions: [] } explicitly.
|
|
82
|
-
* - event passed to `send` must be an object with `type` property.
|
|
83
|
-
* - actions implementation will be [assign action](https://xstate.js.org/docs/guides/context.html#assign-action) if you return any value.
|
|
84
|
-
* Do not return anything if you just want to invoke side effect.
|
|
85
|
-
*
|
|
86
|
-
* The goal of this custom function is to avoid installing the entire `'xstate/fsm'` package, while enabling modeling using
|
|
87
|
-
* state machine. You can copy the first parameter into the editor at https://stately.ai/viz to visualize the state machine.
|
|
88
|
-
*/
|
|
89
|
-
function createMachine(_a, _b) {
|
|
90
|
-
var states = _a.states, context = _a.context, initial = _a.initial;
|
|
91
|
-
var actions = _b.actions;
|
|
92
|
-
var currentState = initial;
|
|
93
|
-
var currentContext = context;
|
|
80
|
+
function createMachine({ states, context, initial }, { actions }) {
|
|
81
|
+
let currentState = initial;
|
|
82
|
+
let currentContext = context;
|
|
94
83
|
return {
|
|
95
|
-
send:
|
|
96
|
-
|
|
97
|
-
|
|
84
|
+
send: (event)=>{
|
|
85
|
+
const currentStateOn = states[currentState].on;
|
|
86
|
+
const transitionConfig = currentStateOn && currentStateOn[event.type];
|
|
98
87
|
if (transitionConfig) {
|
|
99
88
|
currentState = transitionConfig.target;
|
|
100
|
-
if (transitionConfig.actions) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
currentContext = __assign(__assign({}, currentContext), nextContextValue);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
89
|
+
if (transitionConfig.actions) transitionConfig.actions.forEach((actName)=>{
|
|
90
|
+
const actionImpl = actions[actName];
|
|
91
|
+
const nextContextValue = actionImpl && actionImpl(currentContext, event);
|
|
92
|
+
if (nextContextValue) currentContext = _object_spread({}, currentContext, nextContextValue);
|
|
93
|
+
});
|
|
109
94
|
}
|
|
110
|
-
}
|
|
95
|
+
}
|
|
111
96
|
};
|
|
112
97
|
}
|
|
113
|
-
|
|
114
|
-
|
|
98
|
+
const createOverlayMachine = (options)=>{
|
|
99
|
+
const { hideOverlay, showOverlay } = options;
|
|
115
100
|
return createMachine({
|
|
116
101
|
initial: 'hidden',
|
|
117
102
|
context: {
|
|
118
103
|
level: 'error',
|
|
119
104
|
messages: [],
|
|
120
|
-
messageSource: 'build'
|
|
105
|
+
messageSource: 'build'
|
|
121
106
|
},
|
|
122
107
|
states: {
|
|
123
108
|
hidden: {
|
|
124
109
|
on: {
|
|
125
110
|
BUILD_ERROR: {
|
|
126
111
|
target: 'displayBuildError',
|
|
127
|
-
actions: [
|
|
112
|
+
actions: [
|
|
113
|
+
'setMessages',
|
|
114
|
+
'showOverlay'
|
|
115
|
+
]
|
|
128
116
|
},
|
|
129
117
|
RUNTIME_ERROR: {
|
|
130
118
|
target: 'displayRuntimeError',
|
|
131
|
-
actions: [
|
|
132
|
-
|
|
133
|
-
|
|
119
|
+
actions: [
|
|
120
|
+
'setMessages',
|
|
121
|
+
'showOverlay'
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
134
125
|
},
|
|
135
126
|
displayBuildError: {
|
|
136
127
|
on: {
|
|
137
128
|
DISMISS: {
|
|
138
129
|
target: 'hidden',
|
|
139
|
-
actions: [
|
|
130
|
+
actions: [
|
|
131
|
+
'dismissMessages',
|
|
132
|
+
'hideOverlay'
|
|
133
|
+
]
|
|
140
134
|
},
|
|
141
135
|
BUILD_ERROR: {
|
|
142
136
|
target: 'displayBuildError',
|
|
143
|
-
actions: [
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
actions: [
|
|
138
|
+
'appendMessages',
|
|
139
|
+
'showOverlay'
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
146
143
|
},
|
|
147
144
|
displayRuntimeError: {
|
|
148
145
|
on: {
|
|
149
146
|
DISMISS: {
|
|
150
147
|
target: 'hidden',
|
|
151
|
-
actions: [
|
|
148
|
+
actions: [
|
|
149
|
+
'dismissMessages',
|
|
150
|
+
'hideOverlay'
|
|
151
|
+
]
|
|
152
152
|
},
|
|
153
153
|
RUNTIME_ERROR: {
|
|
154
154
|
target: 'displayRuntimeError',
|
|
155
|
-
actions: [
|
|
155
|
+
actions: [
|
|
156
|
+
'appendMessages',
|
|
157
|
+
'showOverlay'
|
|
158
|
+
]
|
|
156
159
|
},
|
|
157
160
|
BUILD_ERROR: {
|
|
158
161
|
target: 'displayBuildError',
|
|
159
|
-
actions: [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
actions: [
|
|
163
|
+
'setMessages',
|
|
164
|
+
'showOverlay'
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
164
170
|
}, {
|
|
165
171
|
actions: {
|
|
166
|
-
dismissMessages:
|
|
167
|
-
return {
|
|
172
|
+
dismissMessages: ()=>({
|
|
168
173
|
messages: [],
|
|
169
174
|
level: 'error',
|
|
170
|
-
messageSource: 'build'
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
appendMessages: function (context, event) {
|
|
174
|
-
return {
|
|
175
|
+
messageSource: 'build'
|
|
176
|
+
}),
|
|
177
|
+
appendMessages: (context, event)=>({
|
|
175
178
|
messages: context.messages.concat(event.messages),
|
|
176
179
|
level: event.level || context.level,
|
|
177
|
-
messageSource: event.type
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
setMessages: function (context, event) {
|
|
181
|
-
return {
|
|
180
|
+
messageSource: 'RUNTIME_ERROR' === event.type ? 'runtime' : 'build'
|
|
181
|
+
}),
|
|
182
|
+
setMessages: (context, event)=>({
|
|
182
183
|
messages: event.messages,
|
|
183
184
|
level: event.level || context.level,
|
|
184
|
-
messageSource: event.type
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
185
|
+
messageSource: 'RUNTIME_ERROR' === event.type ? 'runtime' : 'build'
|
|
186
|
+
}),
|
|
187
|
+
hideOverlay,
|
|
188
|
+
showOverlay
|
|
189
|
+
}
|
|
190
190
|
});
|
|
191
191
|
};
|
|
192
|
-
|
|
193
|
-
if (!error || !(error instanceof Error))
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
if (typeof error.stack === 'string') {
|
|
197
|
-
return error.stack
|
|
198
|
-
.split('\n')
|
|
199
|
-
.filter(function (stack) { return stack !== "Error: ".concat(error.message); });
|
|
200
|
-
}
|
|
192
|
+
const parseErrorToStacks = (error)=>{
|
|
193
|
+
if (!error || !(error instanceof Error)) throw new Error('parseErrorToStacks expects Error object');
|
|
194
|
+
if ('string' == typeof error.stack) return error.stack.split('\n').filter((stack)=>stack !== `Error: ${error.message}`);
|
|
201
195
|
};
|
|
202
|
-
|
|
196
|
+
const listenToRuntimeError = (callback)=>{
|
|
203
197
|
window.addEventListener('error', callback);
|
|
204
|
-
return function
|
|
198
|
+
return function() {
|
|
205
199
|
window.removeEventListener('error', callback);
|
|
206
200
|
};
|
|
207
201
|
};
|
|
208
|
-
|
|
202
|
+
const listenToUnhandledRejection = (callback)=>{
|
|
209
203
|
window.addEventListener('unhandledrejection', callback);
|
|
210
|
-
return function
|
|
204
|
+
return function() {
|
|
211
205
|
window.removeEventListener('unhandledrejection', callback);
|
|
212
206
|
};
|
|
213
207
|
};
|
|
214
|
-
|
|
215
|
-
var msgStyles = {
|
|
208
|
+
const msgStyles = {
|
|
216
209
|
error: {
|
|
217
210
|
backgroundColor: 'rgba(206, 17, 38, 0.1)',
|
|
218
|
-
color: '#fccfcf'
|
|
211
|
+
color: '#fccfcf'
|
|
219
212
|
},
|
|
220
213
|
warning: {
|
|
221
214
|
backgroundColor: 'rgba(251, 245, 180, 0.1)',
|
|
222
|
-
color: '#fbf5b4'
|
|
223
|
-
}
|
|
215
|
+
color: '#fbf5b4'
|
|
216
|
+
}
|
|
224
217
|
};
|
|
225
|
-
|
|
218
|
+
const iframeStyle = {
|
|
226
219
|
position: 'fixed',
|
|
227
220
|
top: '0px',
|
|
228
221
|
left: '0px',
|
|
@@ -231,9 +224,9 @@ var iframeStyle = {
|
|
|
231
224
|
width: '100vw',
|
|
232
225
|
height: '100vh',
|
|
233
226
|
border: 'none',
|
|
234
|
-
'z-index': 9999999999
|
|
227
|
+
'z-index': 9999999999
|
|
235
228
|
};
|
|
236
|
-
|
|
229
|
+
const containerStyle = {
|
|
237
230
|
position: 'fixed',
|
|
238
231
|
boxSizing: 'border-box',
|
|
239
232
|
left: '0px',
|
|
@@ -248,9 +241,9 @@ var containerStyle = {
|
|
|
248
241
|
whiteSpace: 'pre-wrap',
|
|
249
242
|
overflow: 'auto',
|
|
250
243
|
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
|
251
|
-
color: 'white'
|
|
244
|
+
color: 'white'
|
|
252
245
|
};
|
|
253
|
-
|
|
246
|
+
const headerStyle = {
|
|
254
247
|
color: '#e83b46',
|
|
255
248
|
fontSize: '2em',
|
|
256
249
|
whiteSpace: 'pre-wrap',
|
|
@@ -258,9 +251,9 @@ var headerStyle = {
|
|
|
258
251
|
margin: '0 2rem 2rem 0',
|
|
259
252
|
flex: '0 0 auto',
|
|
260
253
|
maxHeight: '50%',
|
|
261
|
-
overflow: 'auto'
|
|
254
|
+
overflow: 'auto'
|
|
262
255
|
};
|
|
263
|
-
|
|
256
|
+
const dismissButtonStyle = {
|
|
264
257
|
color: '#ffffff',
|
|
265
258
|
lineHeight: '1rem',
|
|
266
259
|
fontSize: '1.5rem',
|
|
@@ -270,22 +263,24 @@ var dismissButtonStyle = {
|
|
|
270
263
|
right: '0px',
|
|
271
264
|
top: '0px',
|
|
272
265
|
backgroundColor: 'transparent',
|
|
273
|
-
border: 'none'
|
|
266
|
+
border: 'none'
|
|
274
267
|
};
|
|
275
|
-
|
|
268
|
+
const msgTypeStyle = {
|
|
276
269
|
color: '#e83b46',
|
|
277
270
|
fontSize: '1.2em',
|
|
278
271
|
marginBottom: '1rem',
|
|
279
|
-
fontFamily: 'sans-serif'
|
|
272
|
+
fontFamily: 'sans-serif'
|
|
280
273
|
};
|
|
281
|
-
|
|
274
|
+
const msgTextStyle = {
|
|
282
275
|
lineHeight: '1.5',
|
|
283
276
|
fontSize: '1rem',
|
|
284
|
-
fontFamily: 'Menlo, Consolas, monospace'
|
|
277
|
+
fontFamily: 'Menlo, Consolas, monospace'
|
|
285
278
|
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
279
|
+
const colors = {
|
|
280
|
+
reset: [
|
|
281
|
+
'transparent',
|
|
282
|
+
'transparent'
|
|
283
|
+
],
|
|
289
284
|
black: '181818',
|
|
290
285
|
red: 'E36049',
|
|
291
286
|
green: 'B3CB74',
|
|
@@ -294,81 +289,69 @@ var colors = {
|
|
|
294
289
|
magenta: '7FACCA',
|
|
295
290
|
cyan: 'C3C2EF',
|
|
296
291
|
lightgrey: 'EBE7E3',
|
|
297
|
-
darkgrey: '6D7891'
|
|
292
|
+
darkgrey: '6D7891'
|
|
298
293
|
};
|
|
299
294
|
ansiHTML.setColors(colors);
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (typeof item
|
|
304
|
-
body += item;
|
|
305
|
-
}
|
|
295
|
+
const formatProblem = (type, item)=>{
|
|
296
|
+
let header = 'warning' === type ? 'WARNING' : 'ERROR';
|
|
297
|
+
let body = '';
|
|
298
|
+
if ('string' == typeof item) body += item;
|
|
306
299
|
else {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
: "".concat(item.moduleName)
|
|
312
|
-
: '';
|
|
313
|
-
var loc = item.loc;
|
|
314
|
-
header += "".concat(moduleName || file
|
|
315
|
-
? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : '') : file).concat(loc ? " ".concat(loc) : '')
|
|
316
|
-
: '');
|
|
300
|
+
const file = item.file || '';
|
|
301
|
+
const moduleName = item.moduleName ? -1 !== item.moduleName.indexOf('!') ? `${item.moduleName.replace(/^(\s|\S)*!/, '')} (${item.moduleName})` : `${item.moduleName}` : '';
|
|
302
|
+
const loc = item.loc;
|
|
303
|
+
header += `${moduleName || file ? ` in ${moduleName ? `${moduleName}${file ? ` (${file})` : ''}` : file}${loc ? ` ${loc}` : ''}` : ''}`;
|
|
317
304
|
body += item.message || '';
|
|
318
305
|
}
|
|
319
|
-
if (typeof item
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
return { header: header, body: body };
|
|
306
|
+
if ('string' != typeof item && Array.isArray(item.stack)) item.stack.forEach((stack)=>{
|
|
307
|
+
if ('string' == typeof stack) body += `\r\n${stack}`;
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
header,
|
|
311
|
+
body
|
|
312
|
+
};
|
|
327
313
|
};
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
314
|
+
const createOverlay = (options)=>{
|
|
315
|
+
let iframeContainerElement;
|
|
316
|
+
let containerElement;
|
|
317
|
+
let headerElement;
|
|
318
|
+
let onLoadQueue = [];
|
|
319
|
+
let overlayTrustedTypesPolicy;
|
|
334
320
|
function applyStyle(element, style) {
|
|
335
|
-
Object.keys(style).forEach(
|
|
336
|
-
element.style[prop] =
|
|
337
|
-
style[prop];
|
|
321
|
+
Object.keys(style).forEach((prop)=>{
|
|
322
|
+
element.style[prop] = style[prop];
|
|
338
323
|
});
|
|
339
324
|
}
|
|
340
325
|
function createContainer(trustedTypesPolicyName) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
createHTML: function (value) { return value; },
|
|
345
|
-
});
|
|
346
|
-
}
|
|
326
|
+
if (window.trustedTypes) overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || 'rspack-dev-server#overlay', {
|
|
327
|
+
createHTML: (value)=>value
|
|
328
|
+
});
|
|
347
329
|
iframeContainerElement = document.createElement('iframe');
|
|
348
|
-
iframeContainerElement.id = '
|
|
330
|
+
iframeContainerElement.id = 'rspack-dev-server-client-overlay';
|
|
349
331
|
iframeContainerElement.src = 'about:blank';
|
|
350
332
|
applyStyle(iframeContainerElement, iframeStyle);
|
|
351
|
-
iframeContainerElement.onload =
|
|
352
|
-
|
|
353
|
-
containerElement = (
|
|
354
|
-
contentElement.id = '
|
|
333
|
+
iframeContainerElement.onload = ()=>{
|
|
334
|
+
const contentElement = (null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
335
|
+
containerElement = (null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
336
|
+
contentElement.id = 'rspack-dev-server-client-overlay-div';
|
|
355
337
|
applyStyle(contentElement, containerStyle);
|
|
356
338
|
headerElement = document.createElement('div');
|
|
357
339
|
headerElement.innerText = 'Compiled with problems:';
|
|
358
340
|
applyStyle(headerElement, headerStyle);
|
|
359
|
-
|
|
341
|
+
const closeButtonElement = document.createElement('button');
|
|
360
342
|
applyStyle(closeButtonElement, dismissButtonStyle);
|
|
361
343
|
closeButtonElement.innerText = '×';
|
|
362
344
|
closeButtonElement.ariaLabel = 'Dismiss';
|
|
363
|
-
closeButtonElement.addEventListener('click',
|
|
364
|
-
|
|
365
|
-
|
|
345
|
+
closeButtonElement.addEventListener('click', ()=>{
|
|
346
|
+
overlayService.send({
|
|
347
|
+
type: 'DISMISS'
|
|
348
|
+
});
|
|
366
349
|
});
|
|
367
350
|
contentElement.appendChild(headerElement);
|
|
368
351
|
contentElement.appendChild(closeButtonElement);
|
|
369
352
|
contentElement.appendChild(containerElement);
|
|
370
|
-
(
|
|
371
|
-
onLoadQueue.forEach(
|
|
353
|
+
(null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).body.appendChild(contentElement);
|
|
354
|
+
onLoadQueue.forEach((onLoad)=>{
|
|
372
355
|
onLoad(contentElement);
|
|
373
356
|
});
|
|
374
357
|
onLoadQueue = [];
|
|
@@ -378,124 +361,92 @@ var createOverlay = function (options) {
|
|
|
378
361
|
}
|
|
379
362
|
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
380
363
|
if (containerElement) {
|
|
381
|
-
containerElement.innerHTML = overlayTrustedTypesPolicy
|
|
382
|
-
? overlayTrustedTypesPolicy.createHTML('')
|
|
383
|
-
: '';
|
|
384
|
-
// Everything is ready, call the callback right away.
|
|
364
|
+
containerElement.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML('') : '';
|
|
385
365
|
callback(containerElement);
|
|
386
366
|
return;
|
|
387
367
|
}
|
|
388
368
|
onLoadQueue.push(callback);
|
|
389
|
-
if (iframeContainerElement)
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
369
|
+
if (iframeContainerElement) return;
|
|
392
370
|
createContainer(trustedTypesPolicyName);
|
|
393
371
|
}
|
|
394
|
-
// Successful compilation.
|
|
395
372
|
function hide() {
|
|
396
|
-
if (!iframeContainerElement)
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
// Clean up and reset internal state.
|
|
373
|
+
if (!iframeContainerElement) return;
|
|
400
374
|
document.body.removeChild(iframeContainerElement);
|
|
401
375
|
iframeContainerElement = null;
|
|
402
376
|
containerElement = null;
|
|
403
377
|
}
|
|
404
|
-
// Compilation with errors (e.g. syntax error or missing modules).
|
|
405
378
|
function show(type, messages, trustedTypesPolicyName, messageSource) {
|
|
406
|
-
ensureOverlayExists(
|
|
407
|
-
headerElement.innerText =
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
var _a = formatProblem(type, message), header = _a.header, body = _a.body;
|
|
379
|
+
ensureOverlayExists(()=>{
|
|
380
|
+
headerElement.innerText = 'runtime' === messageSource ? 'Uncaught runtime errors:' : 'Compiled with problems:';
|
|
381
|
+
messages.forEach((message)=>{
|
|
382
|
+
const entryElement = document.createElement('div');
|
|
383
|
+
const msgStyle = 'warning' === type ? msgStyles.warning : msgStyles.error;
|
|
384
|
+
applyStyle(entryElement, _object_spread_props(_object_spread({}, msgStyle), {
|
|
385
|
+
padding: '1rem 1rem 1.5rem 1rem'
|
|
386
|
+
}));
|
|
387
|
+
const typeElement = document.createElement('div');
|
|
388
|
+
const { header, body } = formatProblem(type, message);
|
|
417
389
|
typeElement.innerText = header;
|
|
418
390
|
applyStyle(typeElement, msgTypeStyle);
|
|
419
|
-
if (typeof message
|
|
420
|
-
applyStyle(typeElement, {
|
|
421
|
-
|
|
391
|
+
if ('string' != typeof message && message.moduleIdentifier) {
|
|
392
|
+
applyStyle(typeElement, {
|
|
393
|
+
cursor: 'pointer'
|
|
394
|
+
});
|
|
422
395
|
typeElement.setAttribute('data-can-open', 'true');
|
|
423
|
-
typeElement.addEventListener('click',
|
|
424
|
-
fetch(
|
|
396
|
+
typeElement.addEventListener('click', ()=>{
|
|
397
|
+
fetch(`/rspack-dev-server/open-editor?fileName=${message.moduleIdentifier}`);
|
|
425
398
|
});
|
|
426
399
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
var messageTextNode = document.createElement('div');
|
|
400
|
+
const text = ansiHTML(encode(body));
|
|
401
|
+
const messageTextNode = document.createElement('div');
|
|
430
402
|
applyStyle(messageTextNode, msgTextStyle);
|
|
431
|
-
messageTextNode.innerHTML = overlayTrustedTypesPolicy
|
|
432
|
-
? overlayTrustedTypesPolicy.createHTML(text)
|
|
433
|
-
: text;
|
|
403
|
+
messageTextNode.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML(text) : text;
|
|
434
404
|
entryElement.appendChild(typeElement);
|
|
435
405
|
entryElement.appendChild(messageTextNode);
|
|
436
|
-
|
|
406
|
+
null == containerElement || containerElement.appendChild(entryElement);
|
|
437
407
|
});
|
|
438
408
|
}, trustedTypesPolicyName);
|
|
439
409
|
}
|
|
440
|
-
|
|
441
|
-
|
|
410
|
+
let handleEscapeKey;
|
|
411
|
+
const hideOverlayWithEscCleanup = ()=>{
|
|
442
412
|
window.removeEventListener('keydown', handleEscapeKey);
|
|
443
413
|
hide();
|
|
444
414
|
};
|
|
445
|
-
|
|
446
|
-
showOverlay:
|
|
447
|
-
|
|
448
|
-
return show(level, messages, options.trustedTypesPolicyName, messageSource);
|
|
449
|
-
},
|
|
450
|
-
hideOverlay: hideOverlayWithEscCleanup,
|
|
415
|
+
const overlayService = createOverlayMachine({
|
|
416
|
+
showOverlay: ({ level = 'error', messages, messageSource })=>show(level, messages, options.trustedTypesPolicyName, messageSource),
|
|
417
|
+
hideOverlay: hideOverlayWithEscCleanup
|
|
451
418
|
});
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (event.key === 'Escape' || event.key === 'Esc' || event.keyCode === 27) {
|
|
457
|
-
overlayService.send({ type: 'DISMISS' });
|
|
458
|
-
}
|
|
419
|
+
handleEscapeKey = (event)=>{
|
|
420
|
+
if ('Escape' === event.key || 'Esc' === event.key || 27 === event.keyCode) overlayService.send({
|
|
421
|
+
type: 'DISMISS'
|
|
422
|
+
});
|
|
459
423
|
};
|
|
460
424
|
window.addEventListener('keydown', handleEscapeKey);
|
|
461
425
|
if (options.catchRuntimeError) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
:
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
stack: parseErrorToStacks(errorObject),
|
|
477
|
-
},
|
|
478
|
-
],
|
|
479
|
-
});
|
|
480
|
-
}
|
|
426
|
+
const handleError = (error, fallbackMessage)=>{
|
|
427
|
+
const errorObject = error instanceof Error ? error : new Error(error || fallbackMessage, {
|
|
428
|
+
cause: error
|
|
429
|
+
});
|
|
430
|
+
const shouldDisplay = 'function' == typeof options.catchRuntimeError ? options.catchRuntimeError(errorObject) : true;
|
|
431
|
+
if (shouldDisplay) overlayService.send({
|
|
432
|
+
type: 'RUNTIME_ERROR',
|
|
433
|
+
messages: [
|
|
434
|
+
{
|
|
435
|
+
message: errorObject.message,
|
|
436
|
+
stack: parseErrorToStacks(errorObject)
|
|
437
|
+
}
|
|
438
|
+
]
|
|
439
|
+
});
|
|
481
440
|
};
|
|
482
|
-
listenToRuntimeError(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
if (
|
|
486
|
-
|
|
487
|
-
}
|
|
488
|
-
// if error stack indicates a React error boundary caught the error, do not show overlay.
|
|
489
|
-
if (error &&
|
|
490
|
-
error.stack &&
|
|
491
|
-
error.stack.includes('invokeGuardedCallbackDev')) {
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
handleError_1(error, message);
|
|
441
|
+
listenToRuntimeError((errorEvent)=>{
|
|
442
|
+
const { error, message } = errorEvent;
|
|
443
|
+
if (!error && !message) return;
|
|
444
|
+
if (error && error.stack && error.stack.includes('invokeGuardedCallbackDev')) return;
|
|
445
|
+
handleError(error, message);
|
|
495
446
|
});
|
|
496
|
-
listenToUnhandledRejection(
|
|
497
|
-
|
|
498
|
-
|
|
447
|
+
listenToUnhandledRejection((promiseRejectionEvent)=>{
|
|
448
|
+
const { reason } = promiseRejectionEvent;
|
|
449
|
+
handleError(reason, 'Unknown promise rejection reason');
|
|
499
450
|
});
|
|
500
451
|
}
|
|
501
452
|
return overlayService;
|