@lvce-editor/extension-detail-view 2.1.0 → 3.0.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/dist/extensionDetailViewWorkerMain.js +743 -712
- package/package.json +1 -1
|
@@ -1,368 +1,149 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
jsonrpc: Two,
|
|
5
|
-
method,
|
|
6
|
-
params
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
const state$1 = {
|
|
10
|
-
callbacks: Object.create(null)
|
|
11
|
-
};
|
|
12
|
-
const set = (id, fn) => {
|
|
13
|
-
state$1.callbacks[id] = fn;
|
|
14
|
-
};
|
|
15
|
-
const get = id => {
|
|
16
|
-
return state$1.callbacks[id];
|
|
17
|
-
};
|
|
18
|
-
const remove = id => {
|
|
19
|
-
delete state$1.callbacks[id];
|
|
20
|
-
};
|
|
21
|
-
let id = 0;
|
|
22
|
-
const create$3 = () => {
|
|
23
|
-
return ++id;
|
|
24
|
-
};
|
|
25
|
-
const warn = (...args) => {
|
|
26
|
-
console.warn(...args);
|
|
27
|
-
};
|
|
28
|
-
const registerPromise = () => {
|
|
29
|
-
const id = create$3();
|
|
30
|
-
const {
|
|
31
|
-
resolve,
|
|
32
|
-
promise
|
|
33
|
-
} = Promise.withResolvers();
|
|
34
|
-
set(id, resolve);
|
|
35
|
-
return {
|
|
36
|
-
id,
|
|
37
|
-
promise
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const resolve = (id, response) => {
|
|
41
|
-
const fn = get(id);
|
|
42
|
-
if (!fn) {
|
|
43
|
-
console.log(response);
|
|
44
|
-
warn(`callback ${id} may already be disposed`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
fn(response);
|
|
48
|
-
remove(id);
|
|
49
|
-
};
|
|
50
|
-
const create$2 = (method, params) => {
|
|
51
|
-
const {
|
|
52
|
-
id,
|
|
53
|
-
promise
|
|
54
|
-
} = registerPromise();
|
|
55
|
-
const message = {
|
|
56
|
-
jsonrpc: Two,
|
|
57
|
-
method,
|
|
58
|
-
params,
|
|
59
|
-
id
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
message,
|
|
63
|
-
promise
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
class JsonRpcError extends Error {
|
|
67
|
-
constructor(message) {
|
|
68
|
-
super(message);
|
|
69
|
-
this.name = 'JsonRpcError';
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const NewLine$2 = '\n';
|
|
73
|
-
const DomException = 'DOMException';
|
|
74
|
-
const ReferenceError$1 = 'ReferenceError';
|
|
75
|
-
const SyntaxError$1 = 'SyntaxError';
|
|
76
|
-
const TypeError$1 = 'TypeError';
|
|
77
|
-
const getErrorConstructor = (message, type) => {
|
|
78
|
-
if (type) {
|
|
79
|
-
switch (type) {
|
|
80
|
-
case DomException:
|
|
81
|
-
return DOMException;
|
|
82
|
-
case TypeError$1:
|
|
83
|
-
return TypeError;
|
|
84
|
-
case SyntaxError$1:
|
|
85
|
-
return SyntaxError;
|
|
86
|
-
case ReferenceError$1:
|
|
87
|
-
return ReferenceError;
|
|
88
|
-
default:
|
|
89
|
-
return Error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (message.startsWith('TypeError: ')) {
|
|
93
|
-
return TypeError;
|
|
94
|
-
}
|
|
95
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
96
|
-
return SyntaxError;
|
|
1
|
+
const normalizeLine = line => {
|
|
2
|
+
if (line.startsWith('Error: ')) {
|
|
3
|
+
return line.slice('Error: '.length);
|
|
97
4
|
}
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
5
|
+
if (line.startsWith('VError: ')) {
|
|
6
|
+
return line.slice('VError: '.length);
|
|
100
7
|
}
|
|
101
|
-
return
|
|
8
|
+
return line;
|
|
102
9
|
};
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
return
|
|
107
|
-
}
|
|
108
|
-
if (ErrorConstructor === Error) {
|
|
109
|
-
const error = new Error(message);
|
|
110
|
-
if (name && name !== 'VError') {
|
|
111
|
-
error.name = name;
|
|
112
|
-
}
|
|
113
|
-
return error;
|
|
10
|
+
const getCombinedMessage = (error, message) => {
|
|
11
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
12
|
+
if (message) {
|
|
13
|
+
return `${message}: ${stringifiedError}`;
|
|
114
14
|
}
|
|
115
|
-
return
|
|
15
|
+
return stringifiedError;
|
|
116
16
|
};
|
|
17
|
+
const NewLine$2 = '\n';
|
|
117
18
|
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
118
19
|
return string.indexOf(NewLine$2, startIndex);
|
|
119
20
|
};
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
parentStack = error.message + NewLine$2 + parentStack;
|
|
21
|
+
const mergeStacks = (parent, child) => {
|
|
22
|
+
if (!child) {
|
|
23
|
+
return parent;
|
|
124
24
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
25
|
+
const parentNewLineIndex = getNewLineIndex$1(parent);
|
|
26
|
+
const childNewLineIndex = getNewLineIndex$1(child);
|
|
27
|
+
if (childNewLineIndex === -1) {
|
|
28
|
+
return parent;
|
|
29
|
+
}
|
|
30
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
31
|
+
const childRest = child.slice(childNewLineIndex);
|
|
32
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
33
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
34
|
+
return parentFirstLine + childRest;
|
|
35
|
+
}
|
|
36
|
+
return child;
|
|
134
37
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
38
|
+
class VError extends Error {
|
|
39
|
+
constructor(error, message) {
|
|
40
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
41
|
+
super(combinedMessage);
|
|
42
|
+
this.name = 'VError';
|
|
43
|
+
if (error instanceof Error) {
|
|
44
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
45
|
+
}
|
|
46
|
+
if (error.codeFrame) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
this.codeFrame = error.codeFrame;
|
|
49
|
+
}
|
|
50
|
+
if (error.code) {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
this.code = error.code;
|
|
53
|
+
}
|
|
138
54
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
class AssertionError extends Error {
|
|
58
|
+
constructor(message) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = 'AssertionError';
|
|
145
61
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (error.data.code) {
|
|
159
|
-
// @ts-ignore
|
|
160
|
-
restoredError.code = error.data.code;
|
|
161
|
-
}
|
|
162
|
-
if (error.data.type) {
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
restoredError.name = error.data.type;
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
if (error.stack) {
|
|
168
|
-
const lowerStack = restoredError.stack || '';
|
|
169
|
-
// @ts-ignore
|
|
170
|
-
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
171
|
-
const parentStack = getParentStack(error);
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
62
|
+
}
|
|
63
|
+
const getType = value => {
|
|
64
|
+
switch (typeof value) {
|
|
65
|
+
case 'number':
|
|
66
|
+
return 'number';
|
|
67
|
+
case 'function':
|
|
68
|
+
return 'function';
|
|
69
|
+
case 'string':
|
|
70
|
+
return 'string';
|
|
71
|
+
case 'object':
|
|
72
|
+
if (value === null) {
|
|
73
|
+
return 'null';
|
|
174
74
|
}
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
restoredError.codeFrame = error.codeFrame;
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
return 'array';
|
|
178
77
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
78
|
+
return 'object';
|
|
79
|
+
case 'boolean':
|
|
80
|
+
return 'boolean';
|
|
81
|
+
default:
|
|
82
|
+
return 'unknown';
|
|
184
83
|
}
|
|
185
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
186
84
|
};
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
throw
|
|
191
|
-
}
|
|
192
|
-
if ('result' in responseMessage) {
|
|
193
|
-
return responseMessage.result;
|
|
85
|
+
const array = value => {
|
|
86
|
+
const type = getType(value);
|
|
87
|
+
if (type !== 'array') {
|
|
88
|
+
throw new AssertionError('expected value to be of type array');
|
|
194
89
|
}
|
|
195
|
-
throw new JsonRpcError('unexpected response message');
|
|
196
90
|
};
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
203
|
-
return prettyError.constructor.name;
|
|
91
|
+
const string = value => {
|
|
92
|
+
const type = getType(value);
|
|
93
|
+
if (type !== 'string') {
|
|
94
|
+
throw new AssertionError('expected value to be of type string');
|
|
204
95
|
}
|
|
205
|
-
return undefined;
|
|
206
96
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
code: MethodNotFound,
|
|
211
|
-
message: error.message,
|
|
212
|
-
data: error.stack
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
return {
|
|
216
|
-
code: Custom,
|
|
217
|
-
message: prettyError.message,
|
|
218
|
-
data: {
|
|
219
|
-
stack: prettyError.stack,
|
|
220
|
-
codeFrame: prettyError.codeFrame,
|
|
221
|
-
type: getErrorType(prettyError),
|
|
222
|
-
code: prettyError.code,
|
|
223
|
-
name: prettyError.name
|
|
224
|
-
}
|
|
225
|
-
};
|
|
97
|
+
|
|
98
|
+
const isMessagePort = value => {
|
|
99
|
+
return value && value instanceof MessagePort;
|
|
226
100
|
};
|
|
227
|
-
const
|
|
228
|
-
return
|
|
229
|
-
jsonrpc: Two,
|
|
230
|
-
id: message.id,
|
|
231
|
-
error
|
|
232
|
-
};
|
|
101
|
+
const isMessagePortMain = value => {
|
|
102
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
233
103
|
};
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
logError(error, prettyError);
|
|
237
|
-
const errorProperty = getErrorProperty(error, prettyError);
|
|
238
|
-
return create$1(message, errorProperty);
|
|
104
|
+
const isOffscreenCanvas = value => {
|
|
105
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
239
106
|
};
|
|
240
|
-
const
|
|
241
|
-
return
|
|
242
|
-
jsonrpc: Two,
|
|
243
|
-
id: message.id,
|
|
244
|
-
result: result ?? null
|
|
245
|
-
};
|
|
107
|
+
const isInstanceOf = (value, constructorName) => {
|
|
108
|
+
return value?.constructor?.name === constructorName;
|
|
246
109
|
};
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
return create$5(message, resultProperty);
|
|
110
|
+
const isSocket = value => {
|
|
111
|
+
return isInstanceOf(value, 'Socket');
|
|
250
112
|
};
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
113
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
114
|
+
const isTransferrable = value => {
|
|
115
|
+
for (const fn of transferrables) {
|
|
116
|
+
if (fn(value)) {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
257
119
|
}
|
|
258
|
-
};
|
|
259
|
-
const defaultPreparePrettyError = error => {
|
|
260
|
-
return error;
|
|
261
|
-
};
|
|
262
|
-
const defaultLogError = () => {
|
|
263
|
-
// ignore
|
|
264
|
-
};
|
|
265
|
-
const defaultRequiresSocket = () => {
|
|
266
120
|
return false;
|
|
267
121
|
};
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
271
|
-
const normalizeParams = args => {
|
|
272
|
-
if (args.length === 1) {
|
|
273
|
-
const options = args[0];
|
|
274
|
-
return {
|
|
275
|
-
ipc: options.ipc,
|
|
276
|
-
message: options.message,
|
|
277
|
-
execute: options.execute,
|
|
278
|
-
resolve: options.resolve || defaultResolve,
|
|
279
|
-
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
280
|
-
logError: options.logError || defaultLogError,
|
|
281
|
-
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
return {
|
|
285
|
-
ipc: args[0],
|
|
286
|
-
message: args[1],
|
|
287
|
-
execute: args[2],
|
|
288
|
-
resolve: args[3],
|
|
289
|
-
preparePrettyError: args[4],
|
|
290
|
-
logError: args[5],
|
|
291
|
-
requiresSocket: args[6]
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
const handleJsonRpcMessage = async (...args) => {
|
|
295
|
-
const options = normalizeParams(args);
|
|
296
|
-
const {
|
|
297
|
-
message,
|
|
298
|
-
ipc,
|
|
299
|
-
execute,
|
|
300
|
-
resolve,
|
|
301
|
-
preparePrettyError,
|
|
302
|
-
logError,
|
|
303
|
-
requiresSocket
|
|
304
|
-
} = options;
|
|
305
|
-
if ('id' in message) {
|
|
306
|
-
if ('method' in message) {
|
|
307
|
-
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
308
|
-
try {
|
|
309
|
-
ipc.send(response);
|
|
310
|
-
} catch (error) {
|
|
311
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
312
|
-
ipc.send(errorResponse);
|
|
313
|
-
}
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
resolve(message.id, message);
|
|
122
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
123
|
+
if (!value) {
|
|
317
124
|
return;
|
|
318
125
|
}
|
|
319
|
-
if (
|
|
320
|
-
|
|
126
|
+
if (isTransferrable(value)) {
|
|
127
|
+
transferrables.push(value);
|
|
321
128
|
return;
|
|
322
129
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
promise
|
|
329
|
-
} = create$2(method, params);
|
|
330
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
331
|
-
ipc.sendAndTransfer(message);
|
|
332
|
-
} else {
|
|
333
|
-
ipc.send(message);
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
for (const item of value) {
|
|
132
|
+
walkValue(item, transferrables, isTransferrable);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
334
135
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
transport.send(message);
|
|
341
|
-
};
|
|
342
|
-
const invoke$1 = (ipc, method, ...params) => {
|
|
343
|
-
return invokeHelper(ipc, method, params, false);
|
|
344
|
-
};
|
|
345
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
346
|
-
return invokeHelper(ipc, method, params, true);
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
const commands = Object.create(null);
|
|
350
|
-
const register = commandMap => {
|
|
351
|
-
Object.assign(commands, commandMap);
|
|
352
|
-
};
|
|
353
|
-
const getCommand = key => {
|
|
354
|
-
return commands[key];
|
|
355
|
-
};
|
|
356
|
-
const execute = (command, ...args) => {
|
|
357
|
-
const fn = getCommand(command);
|
|
358
|
-
if (!fn) {
|
|
359
|
-
throw new Error(`command not found ${command}`);
|
|
136
|
+
if (typeof value === 'object') {
|
|
137
|
+
for (const property of Object.values(value)) {
|
|
138
|
+
walkValue(property, transferrables, isTransferrable);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
360
141
|
}
|
|
361
|
-
return fn(...args);
|
|
362
142
|
};
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
|
|
143
|
+
const getTransferrables = value => {
|
|
144
|
+
const transferrables = [];
|
|
145
|
+
walkValue(value, transferrables, isTransferrable);
|
|
146
|
+
return transferrables;
|
|
366
147
|
};
|
|
367
148
|
const attachEvents = that => {
|
|
368
149
|
const handleMessage = (...args) => {
|
|
@@ -377,77 +158,169 @@ const attachEvents = that => {
|
|
|
377
158
|
};
|
|
378
159
|
that.onClose(handleClose);
|
|
379
160
|
};
|
|
380
|
-
class Ipc extends EventTarget {
|
|
381
|
-
constructor(rawIpc) {
|
|
382
|
-
super();
|
|
383
|
-
this._rawIpc = rawIpc;
|
|
384
|
-
attachEvents(this);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
161
|
+
class Ipc extends EventTarget {
|
|
162
|
+
constructor(rawIpc) {
|
|
163
|
+
super();
|
|
164
|
+
this._rawIpc = rawIpc;
|
|
165
|
+
attachEvents(this);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
169
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
170
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
171
|
+
const NewLine$1 = '\n';
|
|
172
|
+
const joinLines$1 = lines => {
|
|
173
|
+
return lines.join(NewLine$1);
|
|
174
|
+
};
|
|
175
|
+
const RE_AT = /^\s+at/;
|
|
176
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
177
|
+
const isNormalStackLine = line => {
|
|
178
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
179
|
+
};
|
|
180
|
+
const getDetails = lines => {
|
|
181
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
182
|
+
if (index === -1) {
|
|
183
|
+
return {
|
|
184
|
+
actualMessage: joinLines$1(lines),
|
|
185
|
+
rest: []
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
let lastIndex = index - 1;
|
|
189
|
+
while (++lastIndex < lines.length) {
|
|
190
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
actualMessage: lines[index - 1],
|
|
196
|
+
rest: lines.slice(index, lastIndex)
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const splitLines$1 = lines => {
|
|
200
|
+
return lines.split(NewLine$1);
|
|
201
|
+
};
|
|
202
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
203
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
204
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
205
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
206
|
+
};
|
|
207
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
208
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
209
|
+
};
|
|
210
|
+
const getMessageCodeBlock = stderr => {
|
|
211
|
+
const lines = splitLines$1(stderr);
|
|
212
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
213
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
214
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
215
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
216
|
+
return relevantMessage;
|
|
217
|
+
};
|
|
218
|
+
const isModuleNotFoundMessage = line => {
|
|
219
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
220
|
+
};
|
|
221
|
+
const getModuleNotFoundError = stderr => {
|
|
222
|
+
const lines = splitLines$1(stderr);
|
|
223
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
224
|
+
const message = lines[messageIndex];
|
|
225
|
+
return {
|
|
226
|
+
message,
|
|
227
|
+
code: ERR_MODULE_NOT_FOUND
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
const isModuleNotFoundError = stderr => {
|
|
231
|
+
if (!stderr) {
|
|
232
|
+
return false;
|
|
407
233
|
}
|
|
234
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
408
235
|
};
|
|
409
|
-
const
|
|
410
|
-
|
|
236
|
+
const isModulesSyntaxError = stderr => {
|
|
237
|
+
if (!stderr) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
411
241
|
};
|
|
412
|
-
const
|
|
413
|
-
|
|
242
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
243
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
244
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
245
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
414
246
|
};
|
|
415
|
-
const
|
|
416
|
-
|
|
247
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
248
|
+
const message = getMessageCodeBlock(stderr);
|
|
249
|
+
return {
|
|
250
|
+
message: `Incompatible native node module: ${message}`,
|
|
251
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
252
|
+
};
|
|
417
253
|
};
|
|
418
|
-
const
|
|
419
|
-
return
|
|
254
|
+
const getModuleSyntaxError = () => {
|
|
255
|
+
return {
|
|
256
|
+
message: `ES Modules are not supported in electron`,
|
|
257
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
258
|
+
};
|
|
420
259
|
};
|
|
421
|
-
const
|
|
422
|
-
|
|
260
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
261
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
262
|
+
return getNativeModuleErrorMessage(stderr);
|
|
263
|
+
}
|
|
264
|
+
if (isModulesSyntaxError(stderr)) {
|
|
265
|
+
return getModuleSyntaxError();
|
|
266
|
+
}
|
|
267
|
+
if (isModuleNotFoundError(stderr)) {
|
|
268
|
+
return getModuleNotFoundError(stderr);
|
|
269
|
+
}
|
|
270
|
+
const lines = splitLines$1(stderr);
|
|
271
|
+
const {
|
|
272
|
+
actualMessage,
|
|
273
|
+
rest
|
|
274
|
+
} = getDetails(lines);
|
|
275
|
+
return {
|
|
276
|
+
message: actualMessage,
|
|
277
|
+
code: '',
|
|
278
|
+
stack: rest
|
|
279
|
+
};
|
|
423
280
|
};
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (
|
|
428
|
-
|
|
281
|
+
class IpcError extends VError {
|
|
282
|
+
// @ts-ignore
|
|
283
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
284
|
+
if (stdout || stderr) {
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
const {
|
|
287
|
+
message,
|
|
288
|
+
code,
|
|
289
|
+
stack
|
|
290
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
291
|
+
const cause = new Error(message);
|
|
292
|
+
// @ts-ignore
|
|
293
|
+
cause.code = code;
|
|
294
|
+
cause.stack = stack;
|
|
295
|
+
super(cause, betterMessage);
|
|
296
|
+
} else {
|
|
297
|
+
super(betterMessage);
|
|
429
298
|
}
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
this.name = 'IpcError';
|
|
301
|
+
// @ts-ignore
|
|
302
|
+
this.stdout = stdout;
|
|
303
|
+
// @ts-ignore
|
|
304
|
+
this.stderr = stderr;
|
|
430
305
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
walkValue(value, transferrables, isTransferrable);
|
|
436
|
-
return transferrables;
|
|
306
|
+
}
|
|
307
|
+
const readyMessage = 'ready';
|
|
308
|
+
const getData$2 = event => {
|
|
309
|
+
return event.data;
|
|
437
310
|
};
|
|
438
|
-
const listen$
|
|
311
|
+
const listen$7 = () => {
|
|
439
312
|
// @ts-ignore
|
|
440
313
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
441
314
|
throw new TypeError('module is not in web worker scope');
|
|
442
315
|
}
|
|
443
316
|
return globalThis;
|
|
444
317
|
};
|
|
445
|
-
const signal$
|
|
318
|
+
const signal$8 = global => {
|
|
446
319
|
global.postMessage(readyMessage);
|
|
447
320
|
};
|
|
448
321
|
class IpcChildWithModuleWorker extends Ipc {
|
|
449
322
|
getData(event) {
|
|
450
|
-
return getData$
|
|
323
|
+
return getData$2(event);
|
|
451
324
|
}
|
|
452
325
|
send(message) {
|
|
453
326
|
// @ts-ignore
|
|
@@ -468,284 +341,451 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
468
341
|
this._rawIpc.addEventListener('message', callback);
|
|
469
342
|
}
|
|
470
343
|
}
|
|
471
|
-
const wrap$
|
|
344
|
+
const wrap$f = global => {
|
|
472
345
|
return new IpcChildWithModuleWorker(global);
|
|
473
346
|
};
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
return
|
|
347
|
+
const withResolvers = () => {
|
|
348
|
+
let _resolve;
|
|
349
|
+
const promise = new Promise(resolve => {
|
|
350
|
+
_resolve = resolve;
|
|
351
|
+
});
|
|
352
|
+
return {
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
354
|
+
resolve: _resolve,
|
|
355
|
+
promise
|
|
356
|
+
};
|
|
480
357
|
};
|
|
481
|
-
const
|
|
482
|
-
|
|
358
|
+
const waitForFirstMessage = async port => {
|
|
359
|
+
const {
|
|
360
|
+
resolve,
|
|
361
|
+
promise
|
|
362
|
+
} = withResolvers();
|
|
363
|
+
port.addEventListener('message', resolve, {
|
|
364
|
+
once: true
|
|
365
|
+
});
|
|
366
|
+
const event = await promise;
|
|
367
|
+
// @ts-ignore
|
|
368
|
+
return event.data;
|
|
483
369
|
};
|
|
484
|
-
const
|
|
485
|
-
|
|
370
|
+
const listen$6 = async () => {
|
|
371
|
+
const parentIpcRaw = listen$7();
|
|
372
|
+
signal$8(parentIpcRaw);
|
|
373
|
+
const parentIpc = wrap$f(parentIpcRaw);
|
|
374
|
+
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
375
|
+
if (firstMessage.method !== 'initialize') {
|
|
376
|
+
throw new IpcError('unexpected first message');
|
|
377
|
+
}
|
|
378
|
+
const type = firstMessage.params[0];
|
|
379
|
+
if (type === 'message-port') {
|
|
380
|
+
parentIpc.send({
|
|
381
|
+
jsonrpc: '2.0',
|
|
382
|
+
id: firstMessage.id,
|
|
383
|
+
result: null
|
|
384
|
+
});
|
|
385
|
+
parentIpc.dispose();
|
|
386
|
+
const port = firstMessage.params[1];
|
|
387
|
+
return port;
|
|
388
|
+
}
|
|
389
|
+
return globalThis;
|
|
486
390
|
};
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
391
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
392
|
+
getData(event) {
|
|
393
|
+
return getData$2(event);
|
|
394
|
+
}
|
|
395
|
+
send(message) {
|
|
396
|
+
this._rawIpc.postMessage(message);
|
|
397
|
+
}
|
|
398
|
+
sendAndTransfer(message) {
|
|
399
|
+
const transfer = getTransferrables(message);
|
|
400
|
+
this._rawIpc.postMessage(message, transfer);
|
|
401
|
+
}
|
|
402
|
+
dispose() {
|
|
403
|
+
if (this._rawIpc.close) {
|
|
404
|
+
this._rawIpc.close();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
onClose(callback) {
|
|
408
|
+
// ignore
|
|
409
|
+
}
|
|
410
|
+
onMessage(callback) {
|
|
411
|
+
this._rawIpc.addEventListener('message', callback);
|
|
412
|
+
this._rawIpc.start();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const wrap$e = port => {
|
|
416
|
+
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
417
|
+
};
|
|
418
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
419
|
+
__proto__: null,
|
|
420
|
+
listen: listen$6,
|
|
421
|
+
wrap: wrap$e
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
const Two = '2.0';
|
|
425
|
+
const create$4 = (method, params) => {
|
|
491
426
|
return {
|
|
492
|
-
|
|
493
|
-
|
|
427
|
+
jsonrpc: Two,
|
|
428
|
+
method,
|
|
429
|
+
params
|
|
494
430
|
};
|
|
495
431
|
};
|
|
496
|
-
const
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
500
|
-
const RE_AT = /^\s+at/;
|
|
501
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
502
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
503
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
432
|
+
const callbacks = Object.create(null);
|
|
433
|
+
const set$1 = (id, fn) => {
|
|
434
|
+
callbacks[id] = fn;
|
|
504
435
|
};
|
|
505
|
-
const
|
|
506
|
-
return
|
|
436
|
+
const get$1 = id => {
|
|
437
|
+
return callbacks[id];
|
|
507
438
|
};
|
|
508
|
-
const
|
|
509
|
-
|
|
439
|
+
const remove = id => {
|
|
440
|
+
delete callbacks[id];
|
|
510
441
|
};
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
515
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
516
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
517
|
-
return relevantMessage;
|
|
442
|
+
let id = 0;
|
|
443
|
+
const create$3 = () => {
|
|
444
|
+
return ++id;
|
|
518
445
|
};
|
|
519
|
-
const
|
|
520
|
-
const
|
|
446
|
+
const registerPromise = () => {
|
|
447
|
+
const id = create$3();
|
|
448
|
+
const {
|
|
449
|
+
resolve,
|
|
450
|
+
promise
|
|
451
|
+
} = Promise.withResolvers();
|
|
452
|
+
set$1(id, resolve);
|
|
521
453
|
return {
|
|
522
|
-
|
|
523
|
-
|
|
454
|
+
id,
|
|
455
|
+
promise
|
|
524
456
|
};
|
|
525
457
|
};
|
|
526
|
-
const
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
458
|
+
const create$2 = (method, params) => {
|
|
459
|
+
const {
|
|
460
|
+
id,
|
|
461
|
+
promise
|
|
462
|
+
} = registerPromise();
|
|
463
|
+
const message = {
|
|
464
|
+
jsonrpc: Two,
|
|
465
|
+
method,
|
|
466
|
+
params,
|
|
467
|
+
id
|
|
468
|
+
};
|
|
469
|
+
return {
|
|
470
|
+
message,
|
|
471
|
+
promise
|
|
536
472
|
};
|
|
537
473
|
};
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
474
|
+
class JsonRpcError extends Error {
|
|
475
|
+
constructor(message) {
|
|
476
|
+
super(message);
|
|
477
|
+
this.name = 'JsonRpcError';
|
|
541
478
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
|
|
479
|
+
}
|
|
480
|
+
const NewLine = '\n';
|
|
481
|
+
const DomException = 'DOMException';
|
|
482
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
483
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
484
|
+
const TypeError$1 = 'TypeError';
|
|
485
|
+
const getErrorConstructor = (message, type) => {
|
|
486
|
+
if (type) {
|
|
487
|
+
switch (type) {
|
|
488
|
+
case DomException:
|
|
489
|
+
return DOMException;
|
|
490
|
+
case TypeError$1:
|
|
491
|
+
return TypeError;
|
|
492
|
+
case SyntaxError$1:
|
|
493
|
+
return SyntaxError;
|
|
494
|
+
case ReferenceError$1:
|
|
495
|
+
return ReferenceError;
|
|
496
|
+
default:
|
|
497
|
+
return Error;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (message.startsWith('TypeError: ')) {
|
|
501
|
+
return TypeError;
|
|
502
|
+
}
|
|
503
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
504
|
+
return SyntaxError;
|
|
505
|
+
}
|
|
506
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
507
|
+
return ReferenceError;
|
|
508
|
+
}
|
|
509
|
+
return Error;
|
|
546
510
|
};
|
|
547
|
-
const
|
|
548
|
-
const
|
|
549
|
-
if (
|
|
550
|
-
return
|
|
551
|
-
actualMessage: joinLines(lines),
|
|
552
|
-
rest: []
|
|
553
|
-
};
|
|
511
|
+
const constructError = (message, type, name) => {
|
|
512
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
513
|
+
if (ErrorConstructor === DOMException && name) {
|
|
514
|
+
return new ErrorConstructor(message, name);
|
|
554
515
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (
|
|
558
|
-
|
|
516
|
+
if (ErrorConstructor === Error) {
|
|
517
|
+
const error = new Error(message);
|
|
518
|
+
if (name && name !== 'VError') {
|
|
519
|
+
error.name = name;
|
|
559
520
|
}
|
|
521
|
+
return error;
|
|
560
522
|
}
|
|
561
|
-
return
|
|
562
|
-
actualMessage: lines[index - 1],
|
|
563
|
-
rest: lines.slice(index, lastIndex)
|
|
564
|
-
};
|
|
523
|
+
return new ErrorConstructor(message);
|
|
565
524
|
};
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
525
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
526
|
+
return string.indexOf(NewLine, startIndex);
|
|
527
|
+
};
|
|
528
|
+
const getParentStack = error => {
|
|
529
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
530
|
+
if (parentStack.startsWith(' at')) {
|
|
531
|
+
parentStack = error.message + NewLine + parentStack;
|
|
569
532
|
}
|
|
570
|
-
|
|
571
|
-
|
|
533
|
+
return parentStack;
|
|
534
|
+
};
|
|
535
|
+
const joinLines = lines => {
|
|
536
|
+
return lines.join(NewLine);
|
|
537
|
+
};
|
|
538
|
+
const MethodNotFound = -32601;
|
|
539
|
+
const Custom = -32001;
|
|
540
|
+
const splitLines = lines => {
|
|
541
|
+
return lines.split(NewLine);
|
|
542
|
+
};
|
|
543
|
+
const restoreJsonRpcError = error => {
|
|
544
|
+
if (error && error instanceof Error) {
|
|
545
|
+
return error;
|
|
572
546
|
}
|
|
573
|
-
|
|
574
|
-
|
|
547
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
548
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
549
|
+
const restoredError = new JsonRpcError(error.message);
|
|
550
|
+
const parentStack = getParentStack(error);
|
|
551
|
+
restoredError.stack = parentStack + NewLine + currentStack;
|
|
552
|
+
return restoredError;
|
|
575
553
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
554
|
+
if (error && error.message) {
|
|
555
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
556
|
+
if (error.data) {
|
|
557
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
558
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
559
|
+
} else if (error.data.stack) {
|
|
560
|
+
restoredError.stack = error.data.stack;
|
|
561
|
+
}
|
|
562
|
+
if (error.data.codeFrame) {
|
|
563
|
+
// @ts-ignore
|
|
564
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
565
|
+
}
|
|
566
|
+
if (error.data.code) {
|
|
567
|
+
// @ts-ignore
|
|
568
|
+
restoredError.code = error.data.code;
|
|
569
|
+
}
|
|
570
|
+
if (error.data.type) {
|
|
571
|
+
// @ts-ignore
|
|
572
|
+
restoredError.name = error.data.type;
|
|
573
|
+
}
|
|
574
|
+
} else {
|
|
575
|
+
if (error.stack) {
|
|
576
|
+
const lowerStack = restoredError.stack || '';
|
|
577
|
+
// @ts-ignore
|
|
578
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
579
|
+
const parentStack = getParentStack(error);
|
|
580
|
+
// @ts-ignore
|
|
581
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
582
|
+
}
|
|
583
|
+
if (error.codeFrame) {
|
|
584
|
+
// @ts-ignore
|
|
585
|
+
restoredError.codeFrame = error.codeFrame;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return restoredError;
|
|
590
589
|
}
|
|
591
|
-
if (
|
|
592
|
-
return
|
|
590
|
+
if (typeof error === 'string') {
|
|
591
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
593
592
|
}
|
|
594
|
-
return
|
|
593
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
595
594
|
};
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
595
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
596
|
+
if ('error' in responseMessage) {
|
|
597
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
598
|
+
throw restoredError;
|
|
600
599
|
}
|
|
601
|
-
|
|
600
|
+
if ('result' in responseMessage) {
|
|
601
|
+
return responseMessage.result;
|
|
602
|
+
}
|
|
603
|
+
throw new JsonRpcError('unexpected response message');
|
|
602
604
|
};
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
return string.indexOf(NewLine, startIndex);
|
|
605
|
+
const warn = (...args) => {
|
|
606
|
+
console.warn(...args);
|
|
606
607
|
};
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
608
|
+
const resolve = (id, response) => {
|
|
609
|
+
const fn = get$1(id);
|
|
610
|
+
if (!fn) {
|
|
611
|
+
console.log(response);
|
|
612
|
+
warn(`callback ${id} may already be disposed`);
|
|
613
|
+
return;
|
|
610
614
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
+
fn(response);
|
|
616
|
+
remove(id);
|
|
617
|
+
};
|
|
618
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
619
|
+
const getErrorType = prettyError => {
|
|
620
|
+
if (prettyError && prettyError.type) {
|
|
621
|
+
return prettyError.type;
|
|
615
622
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
619
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
620
|
-
return parentFirstLine + childRest;
|
|
623
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
624
|
+
return prettyError.constructor.name;
|
|
621
625
|
}
|
|
622
|
-
return
|
|
626
|
+
return undefined;
|
|
623
627
|
};
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}
|
|
632
|
-
if (error.codeFrame) {
|
|
633
|
-
// @ts-ignore
|
|
634
|
-
this.codeFrame = error.codeFrame;
|
|
635
|
-
}
|
|
636
|
-
if (error.code) {
|
|
637
|
-
// @ts-ignore
|
|
638
|
-
this.code = error.code;
|
|
639
|
-
}
|
|
628
|
+
const getErrorProperty = (error, prettyError) => {
|
|
629
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
630
|
+
return {
|
|
631
|
+
code: MethodNotFound,
|
|
632
|
+
message: error.message,
|
|
633
|
+
data: error.stack
|
|
634
|
+
};
|
|
640
635
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
stack
|
|
651
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
652
|
-
const cause = new Error(message);
|
|
653
|
-
// @ts-ignore
|
|
654
|
-
cause.code = code;
|
|
655
|
-
cause.stack = stack;
|
|
656
|
-
super(cause, betterMessage);
|
|
657
|
-
} else {
|
|
658
|
-
super(betterMessage);
|
|
636
|
+
return {
|
|
637
|
+
code: Custom,
|
|
638
|
+
message: prettyError.message,
|
|
639
|
+
data: {
|
|
640
|
+
stack: prettyError.stack,
|
|
641
|
+
codeFrame: prettyError.codeFrame,
|
|
642
|
+
type: getErrorType(prettyError),
|
|
643
|
+
code: prettyError.code,
|
|
644
|
+
name: prettyError.name
|
|
659
645
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
this.stdout = stdout;
|
|
664
|
-
// @ts-ignore
|
|
665
|
-
this.stderr = stderr;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
const withResolvers = () => {
|
|
669
|
-
let _resolve;
|
|
670
|
-
const promise = new Promise(resolve => {
|
|
671
|
-
_resolve = resolve;
|
|
672
|
-
});
|
|
646
|
+
};
|
|
647
|
+
};
|
|
648
|
+
const create$1 = (message, error) => {
|
|
673
649
|
return {
|
|
674
|
-
|
|
675
|
-
|
|
650
|
+
jsonrpc: Two,
|
|
651
|
+
id: message.id,
|
|
652
|
+
error
|
|
676
653
|
};
|
|
677
654
|
};
|
|
678
|
-
const
|
|
679
|
-
const
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
port.addEventListener('message', resolve, {
|
|
684
|
-
once: true
|
|
685
|
-
});
|
|
686
|
-
const event = await promise;
|
|
687
|
-
// @ts-ignore
|
|
688
|
-
return event.data;
|
|
655
|
+
const getErrorResponse = (message, error, preparePrettyError, logError) => {
|
|
656
|
+
const prettyError = preparePrettyError(error);
|
|
657
|
+
logError(error, prettyError);
|
|
658
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
659
|
+
return create$1(message, errorProperty);
|
|
689
660
|
};
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
throw new IpcError('unexpected first message');
|
|
697
|
-
}
|
|
698
|
-
const type = firstMessage.params[0];
|
|
699
|
-
if (type === 'message-port') {
|
|
700
|
-
parentIpc.send({
|
|
701
|
-
jsonrpc: '2.0',
|
|
702
|
-
id: firstMessage.id,
|
|
703
|
-
result: null
|
|
704
|
-
});
|
|
705
|
-
parentIpc.dispose();
|
|
706
|
-
const port = firstMessage.params[1];
|
|
707
|
-
return port;
|
|
708
|
-
}
|
|
709
|
-
return globalThis;
|
|
661
|
+
const create$5 = (message, result) => {
|
|
662
|
+
return {
|
|
663
|
+
jsonrpc: Two,
|
|
664
|
+
id: message.id,
|
|
665
|
+
result: result ?? null
|
|
666
|
+
};
|
|
710
667
|
};
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
668
|
+
const getSuccessResponse = (message, result) => {
|
|
669
|
+
const resultProperty = result ?? null;
|
|
670
|
+
return create$5(message, resultProperty);
|
|
671
|
+
};
|
|
672
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
673
|
+
try {
|
|
674
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
675
|
+
return getSuccessResponse(message, result);
|
|
676
|
+
} catch (error) {
|
|
677
|
+
return getErrorResponse(message, error, preparePrettyError, logError);
|
|
720
678
|
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
679
|
+
};
|
|
680
|
+
const defaultPreparePrettyError = error => {
|
|
681
|
+
return error;
|
|
682
|
+
};
|
|
683
|
+
const defaultLogError = () => {
|
|
684
|
+
// ignore
|
|
685
|
+
};
|
|
686
|
+
const defaultRequiresSocket = () => {
|
|
687
|
+
return false;
|
|
688
|
+
};
|
|
689
|
+
const defaultResolve = resolve;
|
|
690
|
+
|
|
691
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
692
|
+
const normalizeParams = args => {
|
|
693
|
+
if (args.length === 1) {
|
|
694
|
+
const options = args[0];
|
|
695
|
+
return {
|
|
696
|
+
ipc: options.ipc,
|
|
697
|
+
message: options.message,
|
|
698
|
+
execute: options.execute,
|
|
699
|
+
resolve: options.resolve || defaultResolve,
|
|
700
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
701
|
+
logError: options.logError || defaultLogError,
|
|
702
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
703
|
+
};
|
|
724
704
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
705
|
+
return {
|
|
706
|
+
ipc: args[0],
|
|
707
|
+
message: args[1],
|
|
708
|
+
execute: args[2],
|
|
709
|
+
resolve: args[3],
|
|
710
|
+
preparePrettyError: args[4],
|
|
711
|
+
logError: args[5],
|
|
712
|
+
requiresSocket: args[6]
|
|
713
|
+
};
|
|
714
|
+
};
|
|
715
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
716
|
+
const options = normalizeParams(args);
|
|
717
|
+
const {
|
|
718
|
+
message,
|
|
719
|
+
ipc,
|
|
720
|
+
execute,
|
|
721
|
+
resolve,
|
|
722
|
+
preparePrettyError,
|
|
723
|
+
logError,
|
|
724
|
+
requiresSocket
|
|
725
|
+
} = options;
|
|
726
|
+
if ('id' in message) {
|
|
727
|
+
if ('method' in message) {
|
|
728
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
729
|
+
try {
|
|
730
|
+
ipc.send(response);
|
|
731
|
+
} catch (error) {
|
|
732
|
+
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
733
|
+
ipc.send(errorResponse);
|
|
734
|
+
}
|
|
735
|
+
return;
|
|
728
736
|
}
|
|
737
|
+
resolve(message.id, message);
|
|
738
|
+
return;
|
|
729
739
|
}
|
|
730
|
-
|
|
731
|
-
|
|
740
|
+
if ('method' in message) {
|
|
741
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
742
|
+
return;
|
|
732
743
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
744
|
+
throw new JsonRpcError('unexpected message');
|
|
745
|
+
};
|
|
746
|
+
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
747
|
+
const {
|
|
748
|
+
message,
|
|
749
|
+
promise
|
|
750
|
+
} = create$2(method, params);
|
|
751
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
752
|
+
ipc.sendAndTransfer(message);
|
|
753
|
+
} else {
|
|
754
|
+
ipc.send(message);
|
|
736
755
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
756
|
+
const responseMessage = await promise;
|
|
757
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
740
758
|
};
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
759
|
+
const send = (transport, method, ...params) => {
|
|
760
|
+
const message = create$4(method, params);
|
|
761
|
+
transport.send(message);
|
|
762
|
+
};
|
|
763
|
+
const invoke$1 = (ipc, method, ...params) => {
|
|
764
|
+
return invokeHelper(ipc, method, params, false);
|
|
765
|
+
};
|
|
766
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
767
|
+
return invokeHelper(ipc, method, params, true);
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
const commands = Object.create(null);
|
|
771
|
+
const register = commandMap => {
|
|
772
|
+
Object.assign(commands, commandMap);
|
|
773
|
+
};
|
|
774
|
+
const getCommand = key => {
|
|
775
|
+
return commands[key];
|
|
776
|
+
};
|
|
777
|
+
const execute = (command, ...args) => {
|
|
778
|
+
const fn = getCommand(command);
|
|
779
|
+
if (!fn) {
|
|
780
|
+
throw new Error(`command not found ${command}`);
|
|
781
|
+
}
|
|
782
|
+
return fn(...args);
|
|
745
783
|
};
|
|
746
784
|
|
|
747
785
|
const createRpc = ipc => {
|
|
748
786
|
const rpc = {
|
|
787
|
+
// @ts-ignore
|
|
788
|
+
ipc,
|
|
749
789
|
/**
|
|
750
790
|
* @deprecated
|
|
751
791
|
*/
|
|
@@ -771,16 +811,23 @@ const logError = () => {
|
|
|
771
811
|
// handled by renderer worker
|
|
772
812
|
};
|
|
773
813
|
const handleMessage = event => {
|
|
774
|
-
|
|
814
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
815
|
+
const actualExecute = event?.target?.execute || execute;
|
|
816
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
775
817
|
};
|
|
776
818
|
const handleIpc = ipc => {
|
|
777
|
-
|
|
819
|
+
if ('addEventListener' in ipc) {
|
|
820
|
+
ipc.addEventListener('message', handleMessage);
|
|
821
|
+
} else if ('on' in ipc) {
|
|
822
|
+
// deprecated
|
|
823
|
+
ipc.on('message', handleMessage);
|
|
824
|
+
}
|
|
778
825
|
};
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
826
|
+
const listen$1 = async (module, options) => {
|
|
827
|
+
const rawIpc = await module.listen(options);
|
|
828
|
+
if (module.signal) {
|
|
829
|
+
module.signal(rawIpc);
|
|
830
|
+
}
|
|
784
831
|
const ipc = module.wrap(rawIpc);
|
|
785
832
|
return ipc;
|
|
786
833
|
};
|
|
@@ -789,7 +836,7 @@ const create = async ({
|
|
|
789
836
|
}) => {
|
|
790
837
|
// TODO create a commandMap per rpc instance
|
|
791
838
|
register(commandMap);
|
|
792
|
-
const ipc = await listen$1();
|
|
839
|
+
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
793
840
|
handleIpc(ipc);
|
|
794
841
|
const rpc = createRpc(ipc);
|
|
795
842
|
return rpc;
|
|
@@ -801,14 +848,16 @@ const WebWorkerRpcClient = {
|
|
|
801
848
|
|
|
802
849
|
const Document = 'document';
|
|
803
850
|
|
|
804
|
-
const
|
|
805
|
-
|
|
851
|
+
const ExtensionDetail = 'ExtensionDetail';
|
|
806
852
|
const ExtensionDetailDescription = 'ExtensionDetailDescription';
|
|
807
853
|
const ExtensionDetailHeader = 'ExtensionDetailHeader';
|
|
808
854
|
const ExtensionDetailHeaderDetails = 'ExtensionDetailHeaderDetails';
|
|
809
855
|
const ExtensionDetailIcon = 'ExtensionDetailIcon';
|
|
810
856
|
const ExtensionDetailName = 'ExtensionDetailName';
|
|
811
857
|
const Markdown = 'Markdown';
|
|
858
|
+
const Viewlet = 'Viewlet';
|
|
859
|
+
|
|
860
|
+
const HandleReadmeContextMenu = 'handleReadmeContextMenu';
|
|
812
861
|
|
|
813
862
|
const Div$1 = 4;
|
|
814
863
|
const H1$1 = 5;
|
|
@@ -886,47 +935,6 @@ const getExtensionDetailHeaderVirtualDom = extensionDetail => {
|
|
|
886
935
|
|
|
887
936
|
const allowedMarkdownAttributes = ['src', 'id', 'className', 'title', 'alt', 'href', 'target', 'rel'];
|
|
888
937
|
|
|
889
|
-
class AssertionError extends Error {
|
|
890
|
-
constructor(message) {
|
|
891
|
-
super(message);
|
|
892
|
-
this.name = 'AssertionError';
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
const getType = value => {
|
|
896
|
-
switch (typeof value) {
|
|
897
|
-
case 'number':
|
|
898
|
-
return 'number';
|
|
899
|
-
case 'function':
|
|
900
|
-
return 'function';
|
|
901
|
-
case 'string':
|
|
902
|
-
return 'string';
|
|
903
|
-
case 'object':
|
|
904
|
-
if (value === null) {
|
|
905
|
-
return 'null';
|
|
906
|
-
}
|
|
907
|
-
if (Array.isArray(value)) {
|
|
908
|
-
return 'array';
|
|
909
|
-
}
|
|
910
|
-
return 'object';
|
|
911
|
-
case 'boolean':
|
|
912
|
-
return 'boolean';
|
|
913
|
-
default:
|
|
914
|
-
return 'unknown';
|
|
915
|
-
}
|
|
916
|
-
};
|
|
917
|
-
const array = value => {
|
|
918
|
-
const type = getType(value);
|
|
919
|
-
if (type !== 'array') {
|
|
920
|
-
throw new AssertionError('expected value to be of type array');
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
const string = value => {
|
|
924
|
-
const type = getType(value);
|
|
925
|
-
if (type !== 'string') {
|
|
926
|
-
throw new AssertionError('expected value to be of type string');
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
|
|
930
938
|
const Div = 'div';
|
|
931
939
|
const H1 = 'h1';
|
|
932
940
|
const H2 = 'h2';
|
|
@@ -1107,10 +1115,6 @@ const RE_TAG_TEXT = /^[^\s>]+/;
|
|
|
1107
1115
|
const RE_ANY_TEXT = /^[^\n]+/;
|
|
1108
1116
|
const RE_BLOCK_COMMENT_START = /^<!--/;
|
|
1109
1117
|
const RE_SELF_CLOSING = /^\/>/;
|
|
1110
|
-
|
|
1111
|
-
/**
|
|
1112
|
-
* @param {string} text
|
|
1113
|
-
*/
|
|
1114
1118
|
const tokenizeHtml = text => {
|
|
1115
1119
|
string(text);
|
|
1116
1120
|
let state = State.TopLevelContent;
|
|
@@ -1391,12 +1395,20 @@ const getVirtualDomChildCount = markdownDom => {
|
|
|
1391
1395
|
return stack.length;
|
|
1392
1396
|
};
|
|
1393
1397
|
|
|
1398
|
+
const joinBySpace = (...items) => {
|
|
1399
|
+
return items.join(' ');
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
const mergeClassNames = (...classNames) => {
|
|
1403
|
+
return joinBySpace(...classNames.filter(Boolean));
|
|
1404
|
+
};
|
|
1405
|
+
|
|
1394
1406
|
const getExtensionDetailVirtualDom = (extensionDetail, sanitizedReadmeHtml) => {
|
|
1395
1407
|
const markdownDom = getMarkdownVirtualDom(sanitizedReadmeHtml);
|
|
1396
1408
|
const childCount = getVirtualDomChildCount(markdownDom);
|
|
1397
1409
|
const dom = [{
|
|
1398
1410
|
type: Div$1,
|
|
1399
|
-
className:
|
|
1411
|
+
className: mergeClassNames(Viewlet, ExtensionDetail),
|
|
1400
1412
|
childCount: childCount + 1
|
|
1401
1413
|
}, ...getExtensionDetailHeaderVirtualDom(extensionDetail), {
|
|
1402
1414
|
type: Div$1,
|
|
@@ -1420,9 +1432,6 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1420
1432
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1421
1433
|
};
|
|
1422
1434
|
|
|
1423
|
-
/**
|
|
1424
|
-
* @enum {string}
|
|
1425
|
-
*/
|
|
1426
1435
|
const UiStrings = {
|
|
1427
1436
|
Copy: 'Copy',
|
|
1428
1437
|
OpenInNewTab: 'Open in New Tab',
|
|
@@ -1432,6 +1441,9 @@ const UiStrings = {
|
|
|
1432
1441
|
const copy = () => {
|
|
1433
1442
|
return i18nString(UiStrings.Copy);
|
|
1434
1443
|
};
|
|
1444
|
+
const openInNewTab = () => {
|
|
1445
|
+
return i18nString(UiStrings.OpenInNewTab);
|
|
1446
|
+
};
|
|
1435
1447
|
const openImageInNewTab = () => {
|
|
1436
1448
|
return i18nString(UiStrings.OpenImageInNewTab);
|
|
1437
1449
|
};
|
|
@@ -1441,40 +1453,47 @@ const saveImageAs = () => {
|
|
|
1441
1453
|
|
|
1442
1454
|
const None = 0;
|
|
1443
1455
|
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
} else if (props.isImage) {
|
|
1455
|
-
menuEntries.push({
|
|
1456
|
-
id: 'openImageInNewTab',
|
|
1457
|
-
label: openImageInNewTab(),
|
|
1458
|
-
flags: None,
|
|
1459
|
-
command: 'Open.openUrl',
|
|
1460
|
-
args: [props.url]
|
|
1461
|
-
}, {
|
|
1462
|
-
id: 'saveImageAs',
|
|
1463
|
-
label: saveImageAs(),
|
|
1464
|
-
flags: None,
|
|
1465
|
-
command: 'SaveFileAs.saveFileAs',
|
|
1466
|
-
args: ['image.png', props.url]
|
|
1467
|
-
});
|
|
1456
|
+
const getCopyMenuEntry = () => ({
|
|
1457
|
+
id: 'copy',
|
|
1458
|
+
label: copy(),
|
|
1459
|
+
flags: None,
|
|
1460
|
+
command: 'ClipBoard.execCopy'
|
|
1461
|
+
});
|
|
1462
|
+
|
|
1463
|
+
const getImageMenuEntries = props => {
|
|
1464
|
+
if (!props.isImage) {
|
|
1465
|
+
return [];
|
|
1468
1466
|
}
|
|
1469
|
-
|
|
1470
|
-
id: '
|
|
1471
|
-
label:
|
|
1467
|
+
return [{
|
|
1468
|
+
id: 'openImageInNewTab',
|
|
1469
|
+
label: openImageInNewTab(),
|
|
1472
1470
|
flags: None,
|
|
1473
|
-
command: '
|
|
1474
|
-
|
|
1475
|
-
|
|
1471
|
+
command: 'Open.openUrl',
|
|
1472
|
+
args: [props.url || '']
|
|
1473
|
+
}, {
|
|
1474
|
+
id: 'saveImageAs',
|
|
1475
|
+
label: saveImageAs(),
|
|
1476
|
+
flags: None,
|
|
1477
|
+
command: 'SaveFileAs.saveFileAs',
|
|
1478
|
+
args: ['image.png', props.url || '']
|
|
1479
|
+
}];
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1482
|
+
const getLinkMenuEntries = props => {
|
|
1483
|
+
if (!props.isLink) {
|
|
1484
|
+
return [];
|
|
1485
|
+
}
|
|
1486
|
+
return [{
|
|
1487
|
+
id: 'openInNewTab',
|
|
1488
|
+
label: openInNewTab(),
|
|
1489
|
+
flags: None,
|
|
1490
|
+
command: 'Open.openUrl',
|
|
1491
|
+
args: [props.url || '']
|
|
1492
|
+
}];
|
|
1476
1493
|
};
|
|
1477
1494
|
|
|
1495
|
+
const getMenuEntries = props => [...getLinkMenuEntries(props), ...getImageMenuEntries(props), getCopyMenuEntry()];
|
|
1496
|
+
|
|
1478
1497
|
const assetDir = '';
|
|
1479
1498
|
|
|
1480
1499
|
const ExtensionDefaultIcon = `${assetDir}/icons/extensionDefaultIcon.png`;
|
|
@@ -1544,17 +1563,20 @@ const getDescription = extension => {
|
|
|
1544
1563
|
return extension.description;
|
|
1545
1564
|
};
|
|
1546
1565
|
|
|
1547
|
-
const
|
|
1548
|
-
|
|
1566
|
+
const RendererWorker = 1;
|
|
1567
|
+
|
|
1568
|
+
const rpcs = Object.create(null);
|
|
1569
|
+
const set = (id, rpc) => {
|
|
1570
|
+
rpcs[id] = rpc;
|
|
1549
1571
|
};
|
|
1572
|
+
const get = id => {
|
|
1573
|
+
return rpcs[id];
|
|
1574
|
+
};
|
|
1575
|
+
|
|
1550
1576
|
const invoke = (method, ...params) => {
|
|
1551
|
-
const rpc =
|
|
1552
|
-
// @ts-ignore
|
|
1577
|
+
const rpc = get(RendererWorker);
|
|
1553
1578
|
return rpc.invoke(method, ...params);
|
|
1554
1579
|
};
|
|
1555
|
-
const setRpc = rpc => {
|
|
1556
|
-
state.rpc = rpc;
|
|
1557
|
-
};
|
|
1558
1580
|
|
|
1559
1581
|
const getAllExtensions = async platform => {
|
|
1560
1582
|
if (platform === Web) {
|
|
@@ -1630,8 +1652,8 @@ const loadReadmeContent = async path => {
|
|
|
1630
1652
|
};
|
|
1631
1653
|
|
|
1632
1654
|
/**
|
|
1633
|
-
* marked v15.0.
|
|
1634
|
-
* Copyright (c) 2011-
|
|
1655
|
+
* marked v15.0.6 - a markdown parser
|
|
1656
|
+
* Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
|
|
1635
1657
|
* https://github.com/markedjs/marked
|
|
1636
1658
|
*/
|
|
1637
1659
|
|
|
@@ -1837,18 +1859,25 @@ const _punctuation = /[\p{P}\p{S}]/u;
|
|
|
1837
1859
|
const _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
|
|
1838
1860
|
const _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
|
|
1839
1861
|
const punctuation = edit(/^((?![*_])punctSpace)/, 'u').replace(/punctSpace/g, _punctuationOrSpace).getRegex();
|
|
1862
|
+
// GFM allows ~ inside strong and em for strikethrough
|
|
1863
|
+
const _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
|
|
1864
|
+
const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
|
|
1865
|
+
const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
1840
1866
|
// sequences em should skip over [title](link), `code`, <html>
|
|
1841
1867
|
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
|
|
1842
|
-
const
|
|
1843
|
-
const
|
|
1868
|
+
const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
|
|
1869
|
+
const emStrongLDelim = edit(emStrongLDelimCore, 'u').replace(/punct/g, _punctuation).getRegex();
|
|
1870
|
+
const emStrongLDelimGfm = edit(emStrongLDelimCore, 'u').replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
1871
|
+
const emStrongRDelimAstCore = '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
|
|
1844
1872
|
+ '|[^*]+(?=[^*])' // Consume to delim
|
|
1845
1873
|
+ '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
|
|
1846
1874
|
+ '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
|
|
1847
1875
|
+ '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
|
|
1848
1876
|
+ '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
|
|
1849
1877
|
+ '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
|
|
1850
|
-
+ '|notPunctSpace(\\*+)(?=notPunctSpace)'
|
|
1851
|
-
.replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
1878
|
+
+ '|notPunctSpace(\\*+)(?=notPunctSpace)'; // (6) a***a can be either Left or Right Delimiter
|
|
1879
|
+
const emStrongRDelimAst = edit(emStrongRDelimAstCore, 'gu').replace(/notPunctSpace/g, _notPunctuationOrSpace).replace(/punctSpace/g, _punctuationOrSpace).replace(/punct/g, _punctuation).getRegex();
|
|
1880
|
+
const emStrongRDelimAstGfm = edit(emStrongRDelimAstCore, 'gu').replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g, _punctuationOrSpaceGfmStrongEm).replace(/punct/g, _punctuationGfmStrongEm).getRegex();
|
|
1852
1881
|
// (6) Not allowed for _
|
|
1853
1882
|
const emStrongRDelimUnd = edit('^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
|
|
1854
1883
|
+ '|[^_]+(?=[^_])' // Consume to delim
|
|
@@ -1910,7 +1939,8 @@ const inlinePedantic = {
|
|
|
1910
1939
|
*/
|
|
1911
1940
|
const inlineGfm = {
|
|
1912
1941
|
...inlineNormal,
|
|
1913
|
-
|
|
1942
|
+
emStrongRDelimAst: emStrongRDelimAstGfm,
|
|
1943
|
+
emStrongLDelim: emStrongLDelimGfm,
|
|
1914
1944
|
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i').replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),
|
|
1915
1945
|
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
1916
1946
|
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
|
|
@@ -2026,9 +2056,7 @@ function rtrim(str, c, invert) {
|
|
|
2026
2056
|
// Step left until we fail to match the invert condition.
|
|
2027
2057
|
while (suffLen < l) {
|
|
2028
2058
|
const currChar = str.charAt(l - suffLen - 1);
|
|
2029
|
-
if (currChar === c &&
|
|
2030
|
-
suffLen++;
|
|
2031
|
-
} else if (currChar !== c && invert) {
|
|
2059
|
+
if (currChar === c && true) {
|
|
2032
2060
|
suffLen++;
|
|
2033
2061
|
} else {
|
|
2034
2062
|
break;
|
|
@@ -2406,6 +2434,9 @@ class _Tokenizer {
|
|
|
2406
2434
|
if (lastItem) {
|
|
2407
2435
|
lastItem.raw = lastItem.raw.trimEnd();
|
|
2408
2436
|
lastItem.text = lastItem.text.trimEnd();
|
|
2437
|
+
} else {
|
|
2438
|
+
// not a list since there were no items
|
|
2439
|
+
return;
|
|
2409
2440
|
}
|
|
2410
2441
|
list.raw = list.raw.trimEnd();
|
|
2411
2442
|
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
|
@@ -4150,7 +4181,7 @@ const listen = async () => {
|
|
|
4150
4181
|
const rpc = await WebWorkerRpcClient.create({
|
|
4151
4182
|
commandMap: commandMap
|
|
4152
4183
|
});
|
|
4153
|
-
|
|
4184
|
+
set(RendererWorker, rpc);
|
|
4154
4185
|
};
|
|
4155
4186
|
|
|
4156
4187
|
const main = async () => {
|