@lvce-editor/extension-detail-view 2.2.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 +660 -647
- package/package.json +1 -1
|
@@ -1,3 +1,59 @@
|
|
|
1
|
+
const normalizeLine = line => {
|
|
2
|
+
if (line.startsWith('Error: ')) {
|
|
3
|
+
return line.slice('Error: '.length);
|
|
4
|
+
}
|
|
5
|
+
if (line.startsWith('VError: ')) {
|
|
6
|
+
return line.slice('VError: '.length);
|
|
7
|
+
}
|
|
8
|
+
return line;
|
|
9
|
+
};
|
|
10
|
+
const getCombinedMessage = (error, message) => {
|
|
11
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
12
|
+
if (message) {
|
|
13
|
+
return `${message}: ${stringifiedError}`;
|
|
14
|
+
}
|
|
15
|
+
return stringifiedError;
|
|
16
|
+
};
|
|
17
|
+
const NewLine$2 = '\n';
|
|
18
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
19
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
20
|
+
};
|
|
21
|
+
const mergeStacks = (parent, child) => {
|
|
22
|
+
if (!child) {
|
|
23
|
+
return parent;
|
|
24
|
+
}
|
|
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;
|
|
37
|
+
};
|
|
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
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
1
57
|
class AssertionError extends Error {
|
|
2
58
|
constructor(message) {
|
|
3
59
|
super(message);
|
|
@@ -39,754 +95,697 @@ const string = value => {
|
|
|
39
95
|
}
|
|
40
96
|
};
|
|
41
97
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
jsonrpc: Two,
|
|
46
|
-
method,
|
|
47
|
-
params
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
const state$1 = {
|
|
51
|
-
callbacks: Object.create(null)
|
|
52
|
-
};
|
|
53
|
-
const set = (id, fn) => {
|
|
54
|
-
state$1.callbacks[id] = fn;
|
|
98
|
+
const isMessagePort = value => {
|
|
99
|
+
return value && value instanceof MessagePort;
|
|
55
100
|
};
|
|
56
|
-
const
|
|
57
|
-
return
|
|
101
|
+
const isMessagePortMain = value => {
|
|
102
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
58
103
|
};
|
|
59
|
-
const
|
|
60
|
-
|
|
104
|
+
const isOffscreenCanvas = value => {
|
|
105
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
61
106
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return ++id;
|
|
107
|
+
const isInstanceOf = (value, constructorName) => {
|
|
108
|
+
return value?.constructor?.name === constructorName;
|
|
65
109
|
};
|
|
66
|
-
const
|
|
67
|
-
|
|
110
|
+
const isSocket = value => {
|
|
111
|
+
return isInstanceOf(value, 'Socket');
|
|
68
112
|
};
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return
|
|
77
|
-
id,
|
|
78
|
-
promise
|
|
79
|
-
};
|
|
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
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
80
121
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
122
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
123
|
+
if (!value) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (isTransferrable(value)) {
|
|
127
|
+
transferrables.push(value);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
for (const item of value) {
|
|
132
|
+
walkValue(item, transferrables, isTransferrable);
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (typeof value === 'object') {
|
|
137
|
+
for (const property of Object.values(value)) {
|
|
138
|
+
walkValue(property, transferrables, isTransferrable);
|
|
139
|
+
}
|
|
86
140
|
return;
|
|
87
141
|
}
|
|
88
|
-
fn(response);
|
|
89
|
-
remove(id);
|
|
90
142
|
};
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
143
|
+
const getTransferrables = value => {
|
|
144
|
+
const transferrables = [];
|
|
145
|
+
walkValue(value, transferrables, isTransferrable);
|
|
146
|
+
return transferrables;
|
|
147
|
+
};
|
|
148
|
+
const attachEvents = that => {
|
|
149
|
+
const handleMessage = (...args) => {
|
|
150
|
+
const data = that.getData(...args);
|
|
151
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
152
|
+
data
|
|
153
|
+
}));
|
|
101
154
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
155
|
+
that.onMessage(handleMessage);
|
|
156
|
+
const handleClose = event => {
|
|
157
|
+
that.dispatchEvent(new Event('close'));
|
|
105
158
|
};
|
|
159
|
+
that.onClose(handleClose);
|
|
106
160
|
};
|
|
107
|
-
class
|
|
108
|
-
constructor(
|
|
109
|
-
super(
|
|
110
|
-
this.
|
|
161
|
+
class Ipc extends EventTarget {
|
|
162
|
+
constructor(rawIpc) {
|
|
163
|
+
super();
|
|
164
|
+
this._rawIpc = rawIpc;
|
|
165
|
+
attachEvents(this);
|
|
111
166
|
}
|
|
112
167
|
}
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
if (type) {
|
|
120
|
-
switch (type) {
|
|
121
|
-
case DomException:
|
|
122
|
-
return DOMException;
|
|
123
|
-
case TypeError$1:
|
|
124
|
-
return TypeError;
|
|
125
|
-
case SyntaxError$1:
|
|
126
|
-
return SyntaxError;
|
|
127
|
-
case ReferenceError$1:
|
|
128
|
-
return ReferenceError;
|
|
129
|
-
default:
|
|
130
|
-
return Error;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (message.startsWith('TypeError: ')) {
|
|
134
|
-
return TypeError;
|
|
135
|
-
}
|
|
136
|
-
if (message.startsWith('SyntaxError: ')) {
|
|
137
|
-
return SyntaxError;
|
|
138
|
-
}
|
|
139
|
-
if (message.startsWith('ReferenceError: ')) {
|
|
140
|
-
return ReferenceError;
|
|
141
|
-
}
|
|
142
|
-
return Error;
|
|
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);
|
|
143
174
|
};
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
+
};
|
|
148
187
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
188
|
+
let lastIndex = index - 1;
|
|
189
|
+
while (++lastIndex < lines.length) {
|
|
190
|
+
if (!isNormalStackLine(lines[lastIndex])) {
|
|
191
|
+
break;
|
|
153
192
|
}
|
|
154
|
-
return error;
|
|
155
193
|
}
|
|
156
|
-
return
|
|
194
|
+
return {
|
|
195
|
+
actualMessage: lines[index - 1],
|
|
196
|
+
rest: lines.slice(index, lastIndex)
|
|
197
|
+
};
|
|
157
198
|
};
|
|
158
|
-
const
|
|
159
|
-
return
|
|
199
|
+
const splitLines$1 = lines => {
|
|
200
|
+
return lines.split(NewLine$1);
|
|
160
201
|
};
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return parentStack;
|
|
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);
|
|
167
206
|
};
|
|
168
|
-
const
|
|
169
|
-
return
|
|
207
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
208
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
170
209
|
};
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
|
|
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;
|
|
175
217
|
};
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
return error;
|
|
179
|
-
}
|
|
180
|
-
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(1));
|
|
181
|
-
if (error && error.code && error.code === MethodNotFound) {
|
|
182
|
-
const restoredError = new JsonRpcError(error.message);
|
|
183
|
-
const parentStack = getParentStack(error);
|
|
184
|
-
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
185
|
-
return restoredError;
|
|
186
|
-
}
|
|
187
|
-
if (error && error.message) {
|
|
188
|
-
const restoredError = constructError(error.message, error.type, error.name);
|
|
189
|
-
if (error.data) {
|
|
190
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
191
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
|
|
192
|
-
} else if (error.data.stack) {
|
|
193
|
-
restoredError.stack = error.data.stack;
|
|
194
|
-
}
|
|
195
|
-
if (error.data.codeFrame) {
|
|
196
|
-
// @ts-ignore
|
|
197
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
198
|
-
}
|
|
199
|
-
if (error.data.code) {
|
|
200
|
-
// @ts-ignore
|
|
201
|
-
restoredError.code = error.data.code;
|
|
202
|
-
}
|
|
203
|
-
if (error.data.type) {
|
|
204
|
-
// @ts-ignore
|
|
205
|
-
restoredError.name = error.data.type;
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
if (error.stack) {
|
|
209
|
-
const lowerStack = restoredError.stack || '';
|
|
210
|
-
// @ts-ignore
|
|
211
|
-
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
212
|
-
const parentStack = getParentStack(error);
|
|
213
|
-
// @ts-ignore
|
|
214
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
215
|
-
}
|
|
216
|
-
if (error.codeFrame) {
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
restoredError.codeFrame = error.codeFrame;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return restoredError;
|
|
222
|
-
}
|
|
223
|
-
if (typeof error === 'string') {
|
|
224
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
225
|
-
}
|
|
226
|
-
return new Error(`JsonRpc Error: ${error}`);
|
|
218
|
+
const isModuleNotFoundMessage = line => {
|
|
219
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
227
220
|
};
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
throw new JsonRpcError('unexpected response message');
|
|
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
|
+
};
|
|
237
229
|
};
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return prettyError.type;
|
|
242
|
-
}
|
|
243
|
-
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
244
|
-
return prettyError.constructor.name;
|
|
230
|
+
const isModuleNotFoundError = stderr => {
|
|
231
|
+
if (!stderr) {
|
|
232
|
+
return false;
|
|
245
233
|
}
|
|
246
|
-
return
|
|
234
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
247
235
|
};
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
return
|
|
251
|
-
code: MethodNotFound,
|
|
252
|
-
message: error.message,
|
|
253
|
-
data: error.stack
|
|
254
|
-
};
|
|
236
|
+
const isModulesSyntaxError = stderr => {
|
|
237
|
+
if (!stderr) {
|
|
238
|
+
return false;
|
|
255
239
|
}
|
|
240
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
241
|
+
};
|
|
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);
|
|
246
|
+
};
|
|
247
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
248
|
+
const message = getMessageCodeBlock(stderr);
|
|
256
249
|
return {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
data: {
|
|
260
|
-
stack: prettyError.stack,
|
|
261
|
-
codeFrame: prettyError.codeFrame,
|
|
262
|
-
type: getErrorType(prettyError),
|
|
263
|
-
code: prettyError.code,
|
|
264
|
-
name: prettyError.name
|
|
265
|
-
}
|
|
250
|
+
message: `Incompatible native node module: ${message}`,
|
|
251
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
266
252
|
};
|
|
267
253
|
};
|
|
268
|
-
const
|
|
254
|
+
const getModuleSyntaxError = () => {
|
|
269
255
|
return {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
error
|
|
256
|
+
message: `ES Modules are not supported in electron`,
|
|
257
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
273
258
|
};
|
|
274
259
|
};
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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);
|
|
282
275
|
return {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
276
|
+
message: actualMessage,
|
|
277
|
+
code: '',
|
|
278
|
+
stack: rest
|
|
286
279
|
};
|
|
287
280
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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);
|
|
298
|
+
}
|
|
299
|
+
// @ts-ignore
|
|
300
|
+
this.name = 'IpcError';
|
|
301
|
+
// @ts-ignore
|
|
302
|
+
this.stdout = stdout;
|
|
303
|
+
// @ts-ignore
|
|
304
|
+
this.stderr = stderr;
|
|
298
305
|
}
|
|
306
|
+
}
|
|
307
|
+
const readyMessage = 'ready';
|
|
308
|
+
const getData$2 = event => {
|
|
309
|
+
return event.data;
|
|
299
310
|
};
|
|
300
|
-
const
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
311
|
+
const listen$7 = () => {
|
|
312
|
+
// @ts-ignore
|
|
313
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
314
|
+
throw new TypeError('module is not in web worker scope');
|
|
315
|
+
}
|
|
316
|
+
return globalThis;
|
|
305
317
|
};
|
|
306
|
-
const
|
|
307
|
-
|
|
318
|
+
const signal$8 = global => {
|
|
319
|
+
global.postMessage(readyMessage);
|
|
308
320
|
};
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
class IpcChildWithModuleWorker extends Ipc {
|
|
322
|
+
getData(event) {
|
|
323
|
+
return getData$2(event);
|
|
324
|
+
}
|
|
325
|
+
send(message) {
|
|
326
|
+
// @ts-ignore
|
|
327
|
+
this._rawIpc.postMessage(message);
|
|
328
|
+
}
|
|
329
|
+
sendAndTransfer(message) {
|
|
330
|
+
const transfer = getTransferrables(message);
|
|
331
|
+
// @ts-ignore
|
|
332
|
+
this._rawIpc.postMessage(message, transfer);
|
|
333
|
+
}
|
|
334
|
+
dispose() {
|
|
335
|
+
// ignore
|
|
324
336
|
}
|
|
337
|
+
onClose(callback) {
|
|
338
|
+
// ignore
|
|
339
|
+
}
|
|
340
|
+
onMessage(callback) {
|
|
341
|
+
this._rawIpc.addEventListener('message', callback);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const wrap$f = global => {
|
|
345
|
+
return new IpcChildWithModuleWorker(global);
|
|
346
|
+
};
|
|
347
|
+
const withResolvers = () => {
|
|
348
|
+
let _resolve;
|
|
349
|
+
const promise = new Promise(resolve => {
|
|
350
|
+
_resolve = resolve;
|
|
351
|
+
});
|
|
325
352
|
return {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
resolve: args[3],
|
|
330
|
-
preparePrettyError: args[4],
|
|
331
|
-
logError: args[5],
|
|
332
|
-
requiresSocket: args[6]
|
|
353
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
354
|
+
resolve: _resolve,
|
|
355
|
+
promise
|
|
333
356
|
};
|
|
334
357
|
};
|
|
335
|
-
const
|
|
336
|
-
const options = normalizeParams(args);
|
|
358
|
+
const waitForFirstMessage = async port => {
|
|
337
359
|
const {
|
|
338
|
-
message,
|
|
339
|
-
ipc,
|
|
340
|
-
execute,
|
|
341
360
|
resolve,
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return;
|
|
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;
|
|
369
|
+
};
|
|
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');
|
|
359
377
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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;
|
|
363
388
|
}
|
|
364
|
-
|
|
389
|
+
return globalThis;
|
|
365
390
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
promise
|
|
370
|
-
} = create$2(method, params);
|
|
371
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
372
|
-
ipc.sendAndTransfer(message);
|
|
373
|
-
} else {
|
|
374
|
-
ipc.send(message);
|
|
391
|
+
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
392
|
+
getData(event) {
|
|
393
|
+
return getData$2(event);
|
|
375
394
|
}
|
|
376
|
-
|
|
377
|
-
|
|
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);
|
|
378
417
|
};
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
418
|
+
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
419
|
+
__proto__: null,
|
|
420
|
+
listen: listen$6,
|
|
421
|
+
wrap: wrap$e
|
|
382
422
|
};
|
|
383
|
-
|
|
384
|
-
|
|
423
|
+
|
|
424
|
+
const Two = '2.0';
|
|
425
|
+
const create$4 = (method, params) => {
|
|
426
|
+
return {
|
|
427
|
+
jsonrpc: Two,
|
|
428
|
+
method,
|
|
429
|
+
params
|
|
430
|
+
};
|
|
385
431
|
};
|
|
386
|
-
const
|
|
387
|
-
|
|
432
|
+
const callbacks = Object.create(null);
|
|
433
|
+
const set$1 = (id, fn) => {
|
|
434
|
+
callbacks[id] = fn;
|
|
388
435
|
};
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const register = commandMap => {
|
|
392
|
-
Object.assign(commands, commandMap);
|
|
436
|
+
const get$1 = id => {
|
|
437
|
+
return callbacks[id];
|
|
393
438
|
};
|
|
394
|
-
const
|
|
395
|
-
|
|
439
|
+
const remove = id => {
|
|
440
|
+
delete callbacks[id];
|
|
396
441
|
};
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
throw new Error(`command not found ${command}`);
|
|
401
|
-
}
|
|
402
|
-
return fn(...args);
|
|
442
|
+
let id = 0;
|
|
443
|
+
const create$3 = () => {
|
|
444
|
+
return ++id;
|
|
403
445
|
};
|
|
404
|
-
|
|
405
|
-
const
|
|
406
|
-
|
|
446
|
+
const registerPromise = () => {
|
|
447
|
+
const id = create$3();
|
|
448
|
+
const {
|
|
449
|
+
resolve,
|
|
450
|
+
promise
|
|
451
|
+
} = Promise.withResolvers();
|
|
452
|
+
set$1(id, resolve);
|
|
453
|
+
return {
|
|
454
|
+
id,
|
|
455
|
+
promise
|
|
456
|
+
};
|
|
407
457
|
};
|
|
408
|
-
const
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
|
414
468
|
};
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
469
|
+
return {
|
|
470
|
+
message,
|
|
471
|
+
promise
|
|
418
472
|
};
|
|
419
|
-
that.onClose(handleClose);
|
|
420
473
|
};
|
|
421
|
-
class
|
|
422
|
-
constructor(
|
|
423
|
-
super();
|
|
424
|
-
this.
|
|
425
|
-
attachEvents(this);
|
|
474
|
+
class JsonRpcError extends Error {
|
|
475
|
+
constructor(message) {
|
|
476
|
+
super(message);
|
|
477
|
+
this.name = 'JsonRpcError';
|
|
426
478
|
}
|
|
427
479
|
}
|
|
428
|
-
const
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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;
|
|
440
498
|
}
|
|
441
|
-
return;
|
|
442
499
|
}
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
walkValue(property, transferrables, isTransferrable);
|
|
446
|
-
}
|
|
447
|
-
return;
|
|
500
|
+
if (message.startsWith('TypeError: ')) {
|
|
501
|
+
return TypeError;
|
|
448
502
|
}
|
|
503
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
504
|
+
return SyntaxError;
|
|
505
|
+
}
|
|
506
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
507
|
+
return ReferenceError;
|
|
508
|
+
}
|
|
509
|
+
return Error;
|
|
449
510
|
};
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const isInstanceOf = (value, constructorName) => {
|
|
460
|
-
return value?.constructor?.name === constructorName;
|
|
461
|
-
};
|
|
462
|
-
const isSocket = value => {
|
|
463
|
-
return isInstanceOf(value, 'Socket');
|
|
464
|
-
};
|
|
465
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
466
|
-
const isTransferrable = value => {
|
|
467
|
-
for (const fn of transferrables) {
|
|
468
|
-
if (fn(value)) {
|
|
469
|
-
return true;
|
|
511
|
+
const constructError = (message, type, name) => {
|
|
512
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
513
|
+
if (ErrorConstructor === DOMException && name) {
|
|
514
|
+
return new ErrorConstructor(message, name);
|
|
515
|
+
}
|
|
516
|
+
if (ErrorConstructor === Error) {
|
|
517
|
+
const error = new Error(message);
|
|
518
|
+
if (name && name !== 'VError') {
|
|
519
|
+
error.name = name;
|
|
470
520
|
}
|
|
521
|
+
return error;
|
|
471
522
|
}
|
|
472
|
-
return
|
|
523
|
+
return new ErrorConstructor(message);
|
|
473
524
|
};
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
walkValue(value, transferrables, isTransferrable);
|
|
477
|
-
return transferrables;
|
|
525
|
+
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
526
|
+
return string.indexOf(NewLine, startIndex);
|
|
478
527
|
};
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
if (
|
|
482
|
-
|
|
528
|
+
const getParentStack = error => {
|
|
529
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
530
|
+
if (parentStack.startsWith(' at')) {
|
|
531
|
+
parentStack = error.message + NewLine + parentStack;
|
|
483
532
|
}
|
|
484
|
-
return
|
|
533
|
+
return parentStack;
|
|
485
534
|
};
|
|
486
|
-
const
|
|
487
|
-
|
|
535
|
+
const joinLines = lines => {
|
|
536
|
+
return lines.join(NewLine);
|
|
488
537
|
};
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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;
|
|
492
546
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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;
|
|
496
553
|
}
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
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;
|
|
501
589
|
}
|
|
502
|
-
|
|
503
|
-
|
|
590
|
+
if (typeof error === 'string') {
|
|
591
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
504
592
|
}
|
|
505
|
-
|
|
506
|
-
|
|
593
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
594
|
+
};
|
|
595
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
596
|
+
if ('error' in responseMessage) {
|
|
597
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
598
|
+
throw restoredError;
|
|
507
599
|
}
|
|
508
|
-
|
|
509
|
-
|
|
600
|
+
if ('result' in responseMessage) {
|
|
601
|
+
return responseMessage.result;
|
|
510
602
|
}
|
|
511
|
-
|
|
512
|
-
const wrap$5 = global => {
|
|
513
|
-
return new IpcChildWithModuleWorker(global);
|
|
603
|
+
throw new JsonRpcError('unexpected response message');
|
|
514
604
|
};
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
518
|
-
const NewLine$1 = '\n';
|
|
519
|
-
const joinLines = lines => {
|
|
520
|
-
return lines.join(NewLine$1);
|
|
605
|
+
const warn = (...args) => {
|
|
606
|
+
console.warn(...args);
|
|
521
607
|
};
|
|
522
|
-
const
|
|
523
|
-
|
|
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;
|
|
614
|
+
}
|
|
615
|
+
fn(response);
|
|
616
|
+
remove(id);
|
|
524
617
|
};
|
|
525
|
-
const
|
|
526
|
-
|
|
618
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
619
|
+
const getErrorType = prettyError => {
|
|
620
|
+
if (prettyError && prettyError.type) {
|
|
621
|
+
return prettyError.type;
|
|
622
|
+
}
|
|
623
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
624
|
+
return prettyError.constructor.name;
|
|
625
|
+
}
|
|
626
|
+
return undefined;
|
|
527
627
|
};
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
+
};
|
|
635
|
+
}
|
|
532
636
|
return {
|
|
533
|
-
|
|
534
|
-
|
|
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
|
|
645
|
+
}
|
|
535
646
|
};
|
|
536
647
|
};
|
|
537
|
-
const
|
|
538
|
-
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
539
|
-
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
540
|
-
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
541
|
-
const RE_AT = /^\s+at/;
|
|
542
|
-
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
543
|
-
const isUnhelpfulNativeModuleError = stderr => {
|
|
544
|
-
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
545
|
-
};
|
|
546
|
-
const isMessageCodeBlockStartIndex = line => {
|
|
547
|
-
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
548
|
-
};
|
|
549
|
-
const isMessageCodeBlockEndIndex = line => {
|
|
550
|
-
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
551
|
-
};
|
|
552
|
-
const getMessageCodeBlock = stderr => {
|
|
553
|
-
const lines = splitLines(stderr);
|
|
554
|
-
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
555
|
-
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
556
|
-
const relevantLines = lines.slice(startIndex, endIndex);
|
|
557
|
-
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
558
|
-
return relevantMessage;
|
|
559
|
-
};
|
|
560
|
-
const getNativeModuleErrorMessage = stderr => {
|
|
561
|
-
const message = getMessageCodeBlock(stderr);
|
|
648
|
+
const create$1 = (message, error) => {
|
|
562
649
|
return {
|
|
563
|
-
|
|
564
|
-
|
|
650
|
+
jsonrpc: Two,
|
|
651
|
+
id: message.id,
|
|
652
|
+
error
|
|
565
653
|
};
|
|
566
654
|
};
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
return
|
|
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);
|
|
572
660
|
};
|
|
573
|
-
const
|
|
661
|
+
const create$5 = (message, result) => {
|
|
574
662
|
return {
|
|
575
|
-
|
|
576
|
-
|
|
663
|
+
jsonrpc: Two,
|
|
664
|
+
id: message.id,
|
|
665
|
+
result: result ?? null
|
|
577
666
|
};
|
|
578
667
|
};
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
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);
|
|
582
678
|
}
|
|
583
|
-
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
584
679
|
};
|
|
585
|
-
const
|
|
586
|
-
return
|
|
680
|
+
const defaultPreparePrettyError = error => {
|
|
681
|
+
return error;
|
|
682
|
+
};
|
|
683
|
+
const defaultLogError = () => {
|
|
684
|
+
// ignore
|
|
685
|
+
};
|
|
686
|
+
const defaultRequiresSocket = () => {
|
|
687
|
+
return false;
|
|
587
688
|
};
|
|
588
|
-
const
|
|
589
|
-
|
|
590
|
-
|
|
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];
|
|
591
695
|
return {
|
|
592
|
-
|
|
593
|
-
|
|
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
|
|
594
703
|
};
|
|
595
704
|
}
|
|
596
|
-
let lastIndex = index - 1;
|
|
597
|
-
while (++lastIndex < lines.length) {
|
|
598
|
-
if (!isNormalStackLine(lines[lastIndex])) {
|
|
599
|
-
break;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
705
|
return {
|
|
603
|
-
|
|
604
|
-
|
|
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]
|
|
605
713
|
};
|
|
606
714
|
};
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
return getNativeModuleErrorMessage(stderr);
|
|
610
|
-
}
|
|
611
|
-
if (isModulesSyntaxError(stderr)) {
|
|
612
|
-
return getModuleSyntaxError();
|
|
613
|
-
}
|
|
614
|
-
if (isModuleNotFoundError(stderr)) {
|
|
615
|
-
return getModuleNotFoundError(stderr);
|
|
616
|
-
}
|
|
617
|
-
const lines = splitLines(stderr);
|
|
715
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
716
|
+
const options = normalizeParams(args);
|
|
618
717
|
const {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
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;
|
|
736
|
+
}
|
|
737
|
+
resolve(message.id, message);
|
|
738
|
+
return;
|
|
631
739
|
}
|
|
632
|
-
if (
|
|
633
|
-
|
|
740
|
+
if ('method' in message) {
|
|
741
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
742
|
+
return;
|
|
634
743
|
}
|
|
635
|
-
|
|
744
|
+
throw new JsonRpcError('unexpected message');
|
|
636
745
|
};
|
|
637
|
-
const
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
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);
|
|
641
755
|
}
|
|
642
|
-
|
|
756
|
+
const responseMessage = await promise;
|
|
757
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
643
758
|
};
|
|
644
|
-
const
|
|
645
|
-
const
|
|
646
|
-
|
|
759
|
+
const send = (transport, method, ...params) => {
|
|
760
|
+
const message = create$4(method, params);
|
|
761
|
+
transport.send(message);
|
|
647
762
|
};
|
|
648
|
-
const
|
|
649
|
-
|
|
650
|
-
return parent;
|
|
651
|
-
}
|
|
652
|
-
const parentNewLineIndex = getNewLineIndex(parent);
|
|
653
|
-
const childNewLineIndex = getNewLineIndex(child);
|
|
654
|
-
if (childNewLineIndex === -1) {
|
|
655
|
-
return parent;
|
|
656
|
-
}
|
|
657
|
-
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
658
|
-
const childRest = child.slice(childNewLineIndex);
|
|
659
|
-
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
660
|
-
if (parentFirstLine.includes(childFirstLine)) {
|
|
661
|
-
return parentFirstLine + childRest;
|
|
662
|
-
}
|
|
663
|
-
return child;
|
|
763
|
+
const invoke$1 = (ipc, method, ...params) => {
|
|
764
|
+
return invokeHelper(ipc, method, params, false);
|
|
664
765
|
};
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const combinedMessage = getCombinedMessage(error, message);
|
|
668
|
-
super(combinedMessage);
|
|
669
|
-
this.name = 'VError';
|
|
670
|
-
if (error instanceof Error) {
|
|
671
|
-
this.stack = mergeStacks(this.stack, error.stack);
|
|
672
|
-
}
|
|
673
|
-
if (error.codeFrame) {
|
|
674
|
-
// @ts-ignore
|
|
675
|
-
this.codeFrame = error.codeFrame;
|
|
676
|
-
}
|
|
677
|
-
if (error.code) {
|
|
678
|
-
// @ts-ignore
|
|
679
|
-
this.code = error.code;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
class IpcError extends VError {
|
|
684
|
-
// @ts-ignore
|
|
685
|
-
constructor(betterMessage, stdout = '', stderr = '') {
|
|
686
|
-
if (stdout || stderr) {
|
|
687
|
-
// @ts-ignore
|
|
688
|
-
const {
|
|
689
|
-
message,
|
|
690
|
-
code,
|
|
691
|
-
stack
|
|
692
|
-
} = getHelpfulChildProcessError(stdout, stderr);
|
|
693
|
-
const cause = new Error(message);
|
|
694
|
-
// @ts-ignore
|
|
695
|
-
cause.code = code;
|
|
696
|
-
cause.stack = stack;
|
|
697
|
-
super(cause, betterMessage);
|
|
698
|
-
} else {
|
|
699
|
-
super(betterMessage);
|
|
700
|
-
}
|
|
701
|
-
// @ts-ignore
|
|
702
|
-
this.name = 'IpcError';
|
|
703
|
-
// @ts-ignore
|
|
704
|
-
this.stdout = stdout;
|
|
705
|
-
// @ts-ignore
|
|
706
|
-
this.stderr = stderr;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
const withResolvers = () => {
|
|
710
|
-
let _resolve;
|
|
711
|
-
const promise = new Promise(resolve => {
|
|
712
|
-
_resolve = resolve;
|
|
713
|
-
});
|
|
714
|
-
return {
|
|
715
|
-
resolve: _resolve,
|
|
716
|
-
promise
|
|
717
|
-
};
|
|
766
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
767
|
+
return invokeHelper(ipc, method, params, true);
|
|
718
768
|
};
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
} = withResolvers();
|
|
724
|
-
port.addEventListener('message', resolve, {
|
|
725
|
-
once: true
|
|
726
|
-
});
|
|
727
|
-
const event = await promise;
|
|
728
|
-
// @ts-ignore
|
|
729
|
-
return event.data;
|
|
769
|
+
|
|
770
|
+
const commands = Object.create(null);
|
|
771
|
+
const register = commandMap => {
|
|
772
|
+
Object.assign(commands, commandMap);
|
|
730
773
|
};
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
signal$2(parentIpcRaw);
|
|
734
|
-
const parentIpc = wrap$5(parentIpcRaw);
|
|
735
|
-
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
736
|
-
if (firstMessage.method !== 'initialize') {
|
|
737
|
-
throw new IpcError('unexpected first message');
|
|
738
|
-
}
|
|
739
|
-
const type = firstMessage.params[0];
|
|
740
|
-
if (type === 'message-port') {
|
|
741
|
-
parentIpc.send({
|
|
742
|
-
jsonrpc: '2.0',
|
|
743
|
-
id: firstMessage.id,
|
|
744
|
-
result: null
|
|
745
|
-
});
|
|
746
|
-
parentIpc.dispose();
|
|
747
|
-
const port = firstMessage.params[1];
|
|
748
|
-
return port;
|
|
749
|
-
}
|
|
750
|
-
return globalThis;
|
|
774
|
+
const getCommand = key => {
|
|
775
|
+
return commands[key];
|
|
751
776
|
};
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
getData(event) {
|
|
757
|
-
return getData$1(event);
|
|
758
|
-
}
|
|
759
|
-
send(message) {
|
|
760
|
-
this._rawIpc.postMessage(message);
|
|
761
|
-
}
|
|
762
|
-
sendAndTransfer(message) {
|
|
763
|
-
const transfer = getTransferrables(message);
|
|
764
|
-
this._rawIpc.postMessage(message, transfer);
|
|
765
|
-
}
|
|
766
|
-
dispose() {
|
|
767
|
-
if (this._rawIpc.close) {
|
|
768
|
-
this._rawIpc.close();
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
onClose(callback) {
|
|
772
|
-
// ignore
|
|
773
|
-
}
|
|
774
|
-
onMessage(callback) {
|
|
775
|
-
this._rawIpc.addEventListener('message', callback);
|
|
776
|
-
this._rawIpc.start();
|
|
777
|
+
const execute = (command, ...args) => {
|
|
778
|
+
const fn = getCommand(command);
|
|
779
|
+
if (!fn) {
|
|
780
|
+
throw new Error(`command not found ${command}`);
|
|
777
781
|
}
|
|
778
|
-
|
|
779
|
-
const wrap$4 = port => {
|
|
780
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
781
|
-
};
|
|
782
|
-
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
783
|
-
__proto__: null,
|
|
784
|
-
listen: listen$1$1,
|
|
785
|
-
wrap: wrap$4
|
|
782
|
+
return fn(...args);
|
|
786
783
|
};
|
|
787
784
|
|
|
788
785
|
const createRpc = ipc => {
|
|
789
786
|
const rpc = {
|
|
787
|
+
// @ts-ignore
|
|
788
|
+
ipc,
|
|
790
789
|
/**
|
|
791
790
|
* @deprecated
|
|
792
791
|
*/
|
|
@@ -812,7 +811,9 @@ const logError = () => {
|
|
|
812
811
|
// handled by renderer worker
|
|
813
812
|
};
|
|
814
813
|
const handleMessage = event => {
|
|
815
|
-
|
|
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);
|
|
816
817
|
};
|
|
817
818
|
const handleIpc = ipc => {
|
|
818
819
|
if ('addEventListener' in ipc) {
|
|
@@ -1562,17 +1563,20 @@ const getDescription = extension => {
|
|
|
1562
1563
|
return extension.description;
|
|
1563
1564
|
};
|
|
1564
1565
|
|
|
1565
|
-
const
|
|
1566
|
-
|
|
1566
|
+
const RendererWorker = 1;
|
|
1567
|
+
|
|
1568
|
+
const rpcs = Object.create(null);
|
|
1569
|
+
const set = (id, rpc) => {
|
|
1570
|
+
rpcs[id] = rpc;
|
|
1567
1571
|
};
|
|
1572
|
+
const get = id => {
|
|
1573
|
+
return rpcs[id];
|
|
1574
|
+
};
|
|
1575
|
+
|
|
1568
1576
|
const invoke = (method, ...params) => {
|
|
1569
|
-
const rpc =
|
|
1570
|
-
// @ts-ignore
|
|
1577
|
+
const rpc = get(RendererWorker);
|
|
1571
1578
|
return rpc.invoke(method, ...params);
|
|
1572
1579
|
};
|
|
1573
|
-
const setRpc = rpc => {
|
|
1574
|
-
state.rpc = rpc;
|
|
1575
|
-
};
|
|
1576
1580
|
|
|
1577
1581
|
const getAllExtensions = async platform => {
|
|
1578
1582
|
if (platform === Web) {
|
|
@@ -1648,8 +1652,8 @@ const loadReadmeContent = async path => {
|
|
|
1648
1652
|
};
|
|
1649
1653
|
|
|
1650
1654
|
/**
|
|
1651
|
-
* marked v15.0.
|
|
1652
|
-
* Copyright (c) 2011-
|
|
1655
|
+
* marked v15.0.6 - a markdown parser
|
|
1656
|
+
* Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
|
|
1653
1657
|
* https://github.com/markedjs/marked
|
|
1654
1658
|
*/
|
|
1655
1659
|
|
|
@@ -1855,18 +1859,25 @@ const _punctuation = /[\p{P}\p{S}]/u;
|
|
|
1855
1859
|
const _punctuationOrSpace = /[\s\p{P}\p{S}]/u;
|
|
1856
1860
|
const _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
|
|
1857
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;
|
|
1858
1866
|
// sequences em should skip over [title](link), `code`, <html>
|
|
1859
1867
|
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
|
|
1860
|
-
const
|
|
1861
|
-
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
|
|
1862
1872
|
+ '|[^*]+(?=[^*])' // Consume to delim
|
|
1863
1873
|
+ '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
|
|
1864
1874
|
+ '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
|
|
1865
1875
|
+ '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
|
|
1866
1876
|
+ '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
|
|
1867
1877
|
+ '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
|
|
1868
|
-
+ '|notPunctSpace(\\*+)(?=notPunctSpace)'
|
|
1869
|
-
.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();
|
|
1870
1881
|
// (6) Not allowed for _
|
|
1871
1882
|
const emStrongRDelimUnd = edit('^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
|
|
1872
1883
|
+ '|[^_]+(?=[^_])' // Consume to delim
|
|
@@ -1928,7 +1939,8 @@ const inlinePedantic = {
|
|
|
1928
1939
|
*/
|
|
1929
1940
|
const inlineGfm = {
|
|
1930
1941
|
...inlineNormal,
|
|
1931
|
-
|
|
1942
|
+
emStrongRDelimAst: emStrongRDelimAstGfm,
|
|
1943
|
+
emStrongLDelim: emStrongLDelimGfm,
|
|
1932
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(),
|
|
1933
1945
|
_backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
|
|
1934
1946
|
del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
|
|
@@ -2044,9 +2056,7 @@ function rtrim(str, c, invert) {
|
|
|
2044
2056
|
// Step left until we fail to match the invert condition.
|
|
2045
2057
|
while (suffLen < l) {
|
|
2046
2058
|
const currChar = str.charAt(l - suffLen - 1);
|
|
2047
|
-
if (currChar === c &&
|
|
2048
|
-
suffLen++;
|
|
2049
|
-
} else if (currChar !== c && invert) {
|
|
2059
|
+
if (currChar === c && true) {
|
|
2050
2060
|
suffLen++;
|
|
2051
2061
|
} else {
|
|
2052
2062
|
break;
|
|
@@ -2424,6 +2434,9 @@ class _Tokenizer {
|
|
|
2424
2434
|
if (lastItem) {
|
|
2425
2435
|
lastItem.raw = lastItem.raw.trimEnd();
|
|
2426
2436
|
lastItem.text = lastItem.text.trimEnd();
|
|
2437
|
+
} else {
|
|
2438
|
+
// not a list since there were no items
|
|
2439
|
+
return;
|
|
2427
2440
|
}
|
|
2428
2441
|
list.raw = list.raw.trimEnd();
|
|
2429
2442
|
// Item child tokens handled here at end because we needed to have the final item to trim it first
|
|
@@ -4168,7 +4181,7 @@ const listen = async () => {
|
|
|
4168
4181
|
const rpc = await WebWorkerRpcClient.create({
|
|
4169
4182
|
commandMap: commandMap
|
|
4170
4183
|
});
|
|
4171
|
-
|
|
4184
|
+
set(RendererWorker, rpc);
|
|
4172
4185
|
};
|
|
4173
4186
|
|
|
4174
4187
|
const main = async () => {
|