@lvce-editor/pty-host 4.2.0 → 5.2.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/ptyHostMain.js +1875 -77
- package/package.json +2 -12
package/dist/ptyHostMain.js
CHANGED
|
@@ -1,14 +1,1116 @@
|
|
|
1
|
-
import { register, execute } from '@lvce-editor/command';
|
|
2
|
-
import { IpcChildWithWebSocket, IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess, IpcChildWithNodeForkedProcess } from '@lvce-editor/ipc';
|
|
3
|
-
import * as JsonRpc from '@lvce-editor/json-rpc';
|
|
4
|
-
import { handleJsonRpcMessage, resolve } from '@lvce-editor/json-rpc';
|
|
5
1
|
import debugModule from 'debug';
|
|
6
2
|
import { spawn } from 'node-pty';
|
|
7
|
-
import { VError } from '@lvce-editor/verror';
|
|
8
3
|
import { Console } from 'node:console';
|
|
9
|
-
import { createWriteStream } from 'node:fs';
|
|
4
|
+
import { createWriteStream, readFileSync } from 'node:fs';
|
|
10
5
|
import { tmpdir } from 'node:os';
|
|
11
|
-
import {
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { Buffer } from 'node:buffer';
|
|
8
|
+
|
|
9
|
+
class CommandNotFoundError extends Error {
|
|
10
|
+
constructor(command) {
|
|
11
|
+
super(`Command not found ${command}`);
|
|
12
|
+
this.name = 'CommandNotFoundError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const commands = Object.create(null);
|
|
16
|
+
const register = commandMap => {
|
|
17
|
+
Object.assign(commands, commandMap);
|
|
18
|
+
};
|
|
19
|
+
const getCommand = key => {
|
|
20
|
+
return commands[key];
|
|
21
|
+
};
|
|
22
|
+
const execute = (command, ...args) => {
|
|
23
|
+
const fn = getCommand(command);
|
|
24
|
+
if (!fn) {
|
|
25
|
+
throw new CommandNotFoundError(command);
|
|
26
|
+
}
|
|
27
|
+
return fn(...args);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const normalizeLine = line => {
|
|
31
|
+
if (line.startsWith('Error: ')) {
|
|
32
|
+
return line.slice('Error: '.length);
|
|
33
|
+
}
|
|
34
|
+
if (line.startsWith('VError: ')) {
|
|
35
|
+
return line.slice('VError: '.length);
|
|
36
|
+
}
|
|
37
|
+
return line;
|
|
38
|
+
};
|
|
39
|
+
const getCombinedMessage = (error, message) => {
|
|
40
|
+
const stringifiedError = normalizeLine(`${error}`);
|
|
41
|
+
if (message) {
|
|
42
|
+
return `${message}: ${stringifiedError}`;
|
|
43
|
+
}
|
|
44
|
+
return stringifiedError;
|
|
45
|
+
};
|
|
46
|
+
const NewLine$4 = '\n';
|
|
47
|
+
const getNewLineIndex$2 = (string, startIndex = undefined) => {
|
|
48
|
+
return string.indexOf(NewLine$4, startIndex);
|
|
49
|
+
};
|
|
50
|
+
const mergeStacks = (parent, child) => {
|
|
51
|
+
if (!child) {
|
|
52
|
+
return parent;
|
|
53
|
+
}
|
|
54
|
+
const parentNewLineIndex = getNewLineIndex$2(parent);
|
|
55
|
+
const childNewLineIndex = getNewLineIndex$2(child);
|
|
56
|
+
if (childNewLineIndex === -1) {
|
|
57
|
+
return parent;
|
|
58
|
+
}
|
|
59
|
+
const parentFirstLine = parent.slice(0, parentNewLineIndex);
|
|
60
|
+
const childRest = child.slice(childNewLineIndex);
|
|
61
|
+
const childFirstLine = normalizeLine(child.slice(0, childNewLineIndex));
|
|
62
|
+
if (parentFirstLine.includes(childFirstLine)) {
|
|
63
|
+
return parentFirstLine + childRest;
|
|
64
|
+
}
|
|
65
|
+
return child;
|
|
66
|
+
};
|
|
67
|
+
class VError extends Error {
|
|
68
|
+
constructor(error, message) {
|
|
69
|
+
const combinedMessage = getCombinedMessage(error, message);
|
|
70
|
+
super(combinedMessage);
|
|
71
|
+
this.name = 'VError';
|
|
72
|
+
if (error instanceof Error) {
|
|
73
|
+
this.stack = mergeStacks(this.stack, error.stack);
|
|
74
|
+
}
|
|
75
|
+
if (error.codeFrame) {
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
this.codeFrame = error.codeFrame;
|
|
78
|
+
}
|
|
79
|
+
if (error.code) {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
this.code = error.code;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class AssertionError extends Error {
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.name = 'AssertionError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const Object$1 = 1;
|
|
93
|
+
const Number$1 = 2;
|
|
94
|
+
const Array$1 = 3;
|
|
95
|
+
const String$1 = 4;
|
|
96
|
+
const Boolean = 5;
|
|
97
|
+
const Function = 6;
|
|
98
|
+
const Null = 7;
|
|
99
|
+
const Unknown = 8;
|
|
100
|
+
const getType = value => {
|
|
101
|
+
switch (typeof value) {
|
|
102
|
+
case 'number':
|
|
103
|
+
return Number$1;
|
|
104
|
+
case 'function':
|
|
105
|
+
return Function;
|
|
106
|
+
case 'string':
|
|
107
|
+
return String$1;
|
|
108
|
+
case 'object':
|
|
109
|
+
if (value === null) {
|
|
110
|
+
return Null;
|
|
111
|
+
}
|
|
112
|
+
if (Array.isArray(value)) {
|
|
113
|
+
return Array$1;
|
|
114
|
+
}
|
|
115
|
+
return Object$1;
|
|
116
|
+
case 'boolean':
|
|
117
|
+
return Boolean;
|
|
118
|
+
default:
|
|
119
|
+
return Unknown;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const object = value => {
|
|
123
|
+
const type = getType(value);
|
|
124
|
+
if (type !== Object$1) {
|
|
125
|
+
throw new AssertionError('expected value to be of type object');
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const number = value => {
|
|
129
|
+
const type = getType(value);
|
|
130
|
+
if (type !== Number$1) {
|
|
131
|
+
throw new AssertionError('expected value to be of type number');
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const array = value => {
|
|
135
|
+
const type = getType(value);
|
|
136
|
+
if (type !== Array$1) {
|
|
137
|
+
throw new AssertionError('expected value to be of type array');
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const string = value => {
|
|
141
|
+
const type = getType(value);
|
|
142
|
+
if (type !== String$1) {
|
|
143
|
+
throw new AssertionError('expected value to be of type string');
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const isMessagePort = value => {
|
|
148
|
+
return value && value instanceof MessagePort;
|
|
149
|
+
};
|
|
150
|
+
const isMessagePortMain = value => {
|
|
151
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
152
|
+
};
|
|
153
|
+
const isOffscreenCanvas = value => {
|
|
154
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
155
|
+
};
|
|
156
|
+
const isInstanceOf = (value, constructorName) => {
|
|
157
|
+
return value?.constructor?.name === constructorName;
|
|
158
|
+
};
|
|
159
|
+
const isSocket = value => {
|
|
160
|
+
return isInstanceOf(value, 'Socket');
|
|
161
|
+
};
|
|
162
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
163
|
+
const isTransferrable = value => {
|
|
164
|
+
for (const fn of transferrables) {
|
|
165
|
+
if (fn(value)) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
};
|
|
171
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
172
|
+
if (!value) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isTransferrable(value)) {
|
|
176
|
+
transferrables.push(value);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(value)) {
|
|
180
|
+
for (const item of value) {
|
|
181
|
+
walkValue(item, transferrables, isTransferrable);
|
|
182
|
+
}
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (typeof value === 'object') {
|
|
186
|
+
for (const property of Object.values(value)) {
|
|
187
|
+
walkValue(property, transferrables, isTransferrable);
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const getTransferrables = value => {
|
|
193
|
+
const transferrables = [];
|
|
194
|
+
walkValue(value, transferrables, isTransferrable);
|
|
195
|
+
return transferrables;
|
|
196
|
+
};
|
|
197
|
+
const removeValues = (value, toRemove) => {
|
|
198
|
+
if (!value) {
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(value)) {
|
|
202
|
+
const newItems = [];
|
|
203
|
+
for (const item of value) {
|
|
204
|
+
if (!toRemove.includes(item)) {
|
|
205
|
+
newItems.push(removeValues(item, toRemove));
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return newItems;
|
|
209
|
+
}
|
|
210
|
+
if (typeof value === 'object') {
|
|
211
|
+
const newObject = Object.create(null);
|
|
212
|
+
for (const [key, property] of Object.entries(value)) {
|
|
213
|
+
if (!toRemove.includes(property)) {
|
|
214
|
+
newObject[key] = removeValues(property, toRemove);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return newObject;
|
|
218
|
+
}
|
|
219
|
+
return value;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
// workaround for electron not supporting transferrable objects
|
|
223
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
224
|
+
// only an empty objected is received in the main process
|
|
225
|
+
const fixElectronParameters = value => {
|
|
226
|
+
const transfer = getTransferrables(value);
|
|
227
|
+
const newValue = removeValues(value, transfer);
|
|
228
|
+
return {
|
|
229
|
+
newValue,
|
|
230
|
+
transfer
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
const getActualDataElectron = event => {
|
|
234
|
+
const {
|
|
235
|
+
data,
|
|
236
|
+
ports
|
|
237
|
+
} = event;
|
|
238
|
+
if (ports.length === 0) {
|
|
239
|
+
return data;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
...data,
|
|
243
|
+
params: [...ports, ...data.params]
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
const attachEvents = that => {
|
|
247
|
+
const handleMessage = (...args) => {
|
|
248
|
+
const data = that.getData(...args);
|
|
249
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
250
|
+
data
|
|
251
|
+
}));
|
|
252
|
+
};
|
|
253
|
+
that.onMessage(handleMessage);
|
|
254
|
+
const handleClose = event => {
|
|
255
|
+
that.dispatchEvent(new Event('close'));
|
|
256
|
+
};
|
|
257
|
+
that.onClose(handleClose);
|
|
258
|
+
};
|
|
259
|
+
class Ipc extends EventTarget {
|
|
260
|
+
constructor(rawIpc) {
|
|
261
|
+
super();
|
|
262
|
+
this._rawIpc = rawIpc;
|
|
263
|
+
attachEvents(this);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
267
|
+
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
268
|
+
const ERR_MODULE_NOT_FOUND$1 = 'ERR_MODULE_NOT_FOUND';
|
|
269
|
+
const NewLine$3 = '\n';
|
|
270
|
+
const joinLines$2 = lines => {
|
|
271
|
+
return lines.join(NewLine$3);
|
|
272
|
+
};
|
|
273
|
+
const RE_AT$1 = /^\s+at/;
|
|
274
|
+
const RE_AT_PROMISE_INDEX$1 = /^\s*at async Promise.all \(index \d+\)$/;
|
|
275
|
+
const isNormalStackLine$1 = line => {
|
|
276
|
+
return RE_AT$1.test(line) && !RE_AT_PROMISE_INDEX$1.test(line);
|
|
277
|
+
};
|
|
278
|
+
const getDetails$1 = lines => {
|
|
279
|
+
const index = lines.findIndex(isNormalStackLine$1);
|
|
280
|
+
if (index === -1) {
|
|
281
|
+
return {
|
|
282
|
+
actualMessage: joinLines$2(lines),
|
|
283
|
+
rest: []
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
let lastIndex = index - 1;
|
|
287
|
+
while (++lastIndex < lines.length) {
|
|
288
|
+
if (!isNormalStackLine$1(lines[lastIndex])) {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
actualMessage: lines[index - 1],
|
|
294
|
+
rest: lines.slice(index, lastIndex)
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
const splitLines$2 = lines => {
|
|
298
|
+
return lines.split(NewLine$3);
|
|
299
|
+
};
|
|
300
|
+
const RE_MESSAGE_CODE_BLOCK_START = /^Error: The module '.*'$/;
|
|
301
|
+
const RE_MESSAGE_CODE_BLOCK_END = /^\s* at/;
|
|
302
|
+
const isMessageCodeBlockStartIndex = line => {
|
|
303
|
+
return RE_MESSAGE_CODE_BLOCK_START.test(line);
|
|
304
|
+
};
|
|
305
|
+
const isMessageCodeBlockEndIndex = line => {
|
|
306
|
+
return RE_MESSAGE_CODE_BLOCK_END.test(line);
|
|
307
|
+
};
|
|
308
|
+
const getMessageCodeBlock = stderr => {
|
|
309
|
+
const lines = splitLines$2(stderr);
|
|
310
|
+
const startIndex = lines.findIndex(isMessageCodeBlockStartIndex);
|
|
311
|
+
const endIndex = startIndex + lines.slice(startIndex).findIndex(isMessageCodeBlockEndIndex, startIndex);
|
|
312
|
+
const relevantLines = lines.slice(startIndex, endIndex);
|
|
313
|
+
const relevantMessage = relevantLines.join(' ').slice('Error: '.length);
|
|
314
|
+
return relevantMessage;
|
|
315
|
+
};
|
|
316
|
+
const isModuleNotFoundMessage = line => {
|
|
317
|
+
return line.includes('[ERR_MODULE_NOT_FOUND]');
|
|
318
|
+
};
|
|
319
|
+
const getModuleNotFoundError = stderr => {
|
|
320
|
+
const lines = splitLines$2(stderr);
|
|
321
|
+
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
322
|
+
const message = lines[messageIndex];
|
|
323
|
+
return {
|
|
324
|
+
message,
|
|
325
|
+
code: ERR_MODULE_NOT_FOUND$1
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
const isModuleNotFoundError = stderr => {
|
|
329
|
+
if (!stderr) {
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
return stderr.includes('ERR_MODULE_NOT_FOUND');
|
|
333
|
+
};
|
|
334
|
+
const isModulesSyntaxError = stderr => {
|
|
335
|
+
if (!stderr) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
return stderr.includes('SyntaxError: Cannot use import statement outside a module');
|
|
339
|
+
};
|
|
340
|
+
const RE_NATIVE_MODULE_ERROR = /^innerError Error: Cannot find module '.*.node'/;
|
|
341
|
+
const RE_NATIVE_MODULE_ERROR_2 = /was compiled against a different Node.js version/;
|
|
342
|
+
const isUnhelpfulNativeModuleError = stderr => {
|
|
343
|
+
return RE_NATIVE_MODULE_ERROR.test(stderr) && RE_NATIVE_MODULE_ERROR_2.test(stderr);
|
|
344
|
+
};
|
|
345
|
+
const getNativeModuleErrorMessage = stderr => {
|
|
346
|
+
const message = getMessageCodeBlock(stderr);
|
|
347
|
+
return {
|
|
348
|
+
message: `Incompatible native node module: ${message}`,
|
|
349
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
const getModuleSyntaxError = () => {
|
|
353
|
+
return {
|
|
354
|
+
message: `ES Modules are not supported in electron`,
|
|
355
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
359
|
+
if (isUnhelpfulNativeModuleError(stderr)) {
|
|
360
|
+
return getNativeModuleErrorMessage(stderr);
|
|
361
|
+
}
|
|
362
|
+
if (isModulesSyntaxError(stderr)) {
|
|
363
|
+
return getModuleSyntaxError();
|
|
364
|
+
}
|
|
365
|
+
if (isModuleNotFoundError(stderr)) {
|
|
366
|
+
return getModuleNotFoundError(stderr);
|
|
367
|
+
}
|
|
368
|
+
const lines = splitLines$2(stderr);
|
|
369
|
+
const {
|
|
370
|
+
actualMessage,
|
|
371
|
+
rest
|
|
372
|
+
} = getDetails$1(lines);
|
|
373
|
+
return {
|
|
374
|
+
message: actualMessage,
|
|
375
|
+
code: '',
|
|
376
|
+
stack: rest
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
class IpcError extends VError {
|
|
380
|
+
// @ts-ignore
|
|
381
|
+
constructor(betterMessage, stdout = '', stderr = '') {
|
|
382
|
+
if (stdout || stderr) {
|
|
383
|
+
// @ts-ignore
|
|
384
|
+
const {
|
|
385
|
+
message,
|
|
386
|
+
code,
|
|
387
|
+
stack
|
|
388
|
+
} = getHelpfulChildProcessError(stdout, stderr);
|
|
389
|
+
const cause = new Error(message);
|
|
390
|
+
// @ts-ignore
|
|
391
|
+
cause.code = code;
|
|
392
|
+
cause.stack = stack;
|
|
393
|
+
super(cause, betterMessage);
|
|
394
|
+
} else {
|
|
395
|
+
super(betterMessage);
|
|
396
|
+
}
|
|
397
|
+
// @ts-ignore
|
|
398
|
+
this.name = 'IpcError';
|
|
399
|
+
// @ts-ignore
|
|
400
|
+
this.stdout = stdout;
|
|
401
|
+
// @ts-ignore
|
|
402
|
+
this.stderr = stderr;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
const listen$b = ({
|
|
406
|
+
messagePort
|
|
407
|
+
}) => {
|
|
408
|
+
if (!isMessagePortMain(messagePort)) {
|
|
409
|
+
throw new IpcError('port must be of type MessagePortMain');
|
|
410
|
+
}
|
|
411
|
+
return messagePort;
|
|
412
|
+
};
|
|
413
|
+
const signal$c = messagePort => {
|
|
414
|
+
messagePort.start();
|
|
415
|
+
};
|
|
416
|
+
class IpcChildWithElectronMessagePort extends Ipc {
|
|
417
|
+
getData = getActualDataElectron;
|
|
418
|
+
send(message) {
|
|
419
|
+
this._rawIpc.postMessage(message);
|
|
420
|
+
}
|
|
421
|
+
sendAndTransfer(message) {
|
|
422
|
+
const {
|
|
423
|
+
newValue,
|
|
424
|
+
transfer
|
|
425
|
+
} = fixElectronParameters(message);
|
|
426
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
427
|
+
}
|
|
428
|
+
dispose() {
|
|
429
|
+
this._rawIpc.close();
|
|
430
|
+
}
|
|
431
|
+
onMessage(callback) {
|
|
432
|
+
this._rawIpc.on('message', callback);
|
|
433
|
+
}
|
|
434
|
+
onClose(callback) {
|
|
435
|
+
this._rawIpc.on('close', callback);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
const wrap$j = messagePort => {
|
|
439
|
+
return new IpcChildWithElectronMessagePort(messagePort);
|
|
440
|
+
};
|
|
441
|
+
const IpcChildWithElectronMessagePort$1 = {
|
|
442
|
+
__proto__: null,
|
|
443
|
+
listen: listen$b,
|
|
444
|
+
signal: signal$c,
|
|
445
|
+
wrap: wrap$j
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
// @ts-ignore
|
|
449
|
+
const getUtilityProcessPortData = event => {
|
|
450
|
+
const {
|
|
451
|
+
data,
|
|
452
|
+
ports
|
|
453
|
+
} = event;
|
|
454
|
+
if (ports.length === 0) {
|
|
455
|
+
return data;
|
|
456
|
+
}
|
|
457
|
+
return {
|
|
458
|
+
...data,
|
|
459
|
+
params: [...ports, ...data.params]
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
const readyMessage = 'ready';
|
|
463
|
+
const listen$a = () => {
|
|
464
|
+
// @ts-ignore
|
|
465
|
+
const {
|
|
466
|
+
parentPort
|
|
467
|
+
} = process;
|
|
468
|
+
if (!parentPort) {
|
|
469
|
+
throw new IpcError('parent port must be defined');
|
|
470
|
+
}
|
|
471
|
+
return parentPort;
|
|
472
|
+
};
|
|
473
|
+
const signal$b = parentPort => {
|
|
474
|
+
parentPort.postMessage(readyMessage);
|
|
475
|
+
};
|
|
476
|
+
class IpcChildWithElectronUtilityProcess extends Ipc {
|
|
477
|
+
getData(event) {
|
|
478
|
+
return getUtilityProcessPortData(event);
|
|
479
|
+
}
|
|
480
|
+
send(message) {
|
|
481
|
+
this._rawIpc.postMessage(message);
|
|
482
|
+
}
|
|
483
|
+
sendAndTransfer(message) {
|
|
484
|
+
const {
|
|
485
|
+
newValue,
|
|
486
|
+
transfer
|
|
487
|
+
} = fixElectronParameters(message);
|
|
488
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
489
|
+
}
|
|
490
|
+
dispose() {
|
|
491
|
+
this._rawIpc.close();
|
|
492
|
+
}
|
|
493
|
+
onClose(callback) {
|
|
494
|
+
this._rawIpc.on('close', callback);
|
|
495
|
+
}
|
|
496
|
+
onMessage(callback) {
|
|
497
|
+
this._rawIpc.on('message', callback);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
const wrap$i = parentPort => {
|
|
501
|
+
return new IpcChildWithElectronUtilityProcess(parentPort);
|
|
502
|
+
};
|
|
503
|
+
const IpcChildWithElectronUtilityProcess$1 = {
|
|
504
|
+
__proto__: null,
|
|
505
|
+
listen: listen$a,
|
|
506
|
+
signal: signal$b,
|
|
507
|
+
wrap: wrap$i
|
|
508
|
+
};
|
|
509
|
+
const getActualData = (message, handle) => {
|
|
510
|
+
if (handle) {
|
|
511
|
+
return {
|
|
512
|
+
...message,
|
|
513
|
+
params: [handle, ...message.params]
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return message;
|
|
517
|
+
};
|
|
518
|
+
const getTransferrablesNode = value => {
|
|
519
|
+
const transferrables = getTransferrables(value);
|
|
520
|
+
if (transferrables.length === 0) {
|
|
521
|
+
throw new Error(`no transferrables found`);
|
|
522
|
+
}
|
|
523
|
+
return transferrables[0];
|
|
524
|
+
};
|
|
525
|
+
const listen$5 = async () => {
|
|
526
|
+
if (!process.send) {
|
|
527
|
+
throw new IpcError('process.send must be defined');
|
|
528
|
+
}
|
|
529
|
+
return process;
|
|
530
|
+
};
|
|
531
|
+
const signal$7 = process => {
|
|
532
|
+
process.send(readyMessage);
|
|
533
|
+
};
|
|
534
|
+
class IpcChildWithNodeForkedProcess extends Ipc {
|
|
535
|
+
getData(message, handle) {
|
|
536
|
+
return getActualData(message, handle);
|
|
537
|
+
}
|
|
538
|
+
onClose(callback) {
|
|
539
|
+
this._rawIpc.on('close', callback);
|
|
540
|
+
}
|
|
541
|
+
send(message) {
|
|
542
|
+
this._rawIpc.send(message);
|
|
543
|
+
}
|
|
544
|
+
onMessage(callback) {
|
|
545
|
+
this._rawIpc.on('message', callback);
|
|
546
|
+
}
|
|
547
|
+
sendAndTransfer(message) {
|
|
548
|
+
const transfer = getTransferrablesNode(message);
|
|
549
|
+
this._rawIpc.send(message, transfer);
|
|
550
|
+
}
|
|
551
|
+
dispose() {
|
|
552
|
+
// ignore
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const wrap$d = process => {
|
|
556
|
+
return new IpcChildWithNodeForkedProcess(process);
|
|
557
|
+
};
|
|
558
|
+
const IpcChildWithNodeForkedProcess$1 = {
|
|
559
|
+
__proto__: null,
|
|
560
|
+
listen: listen$5,
|
|
561
|
+
signal: signal$7,
|
|
562
|
+
wrap: wrap$d
|
|
563
|
+
};
|
|
564
|
+
const Open = 2;
|
|
565
|
+
const Close = 3;
|
|
566
|
+
const addListener = (emitter, type, callback) => {
|
|
567
|
+
if ('addEventListener' in emitter) {
|
|
568
|
+
emitter.addEventListener(type, callback);
|
|
569
|
+
} else {
|
|
570
|
+
emitter.on(type, callback);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
const removeListener = (emitter, type, callback) => {
|
|
574
|
+
if ('removeEventListener' in emitter) {
|
|
575
|
+
emitter.removeEventListener(type, callback);
|
|
576
|
+
} else {
|
|
577
|
+
emitter.off(type, callback);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
581
|
+
const {
|
|
582
|
+
resolve,
|
|
583
|
+
promise
|
|
584
|
+
} = Promise.withResolvers();
|
|
585
|
+
const listenerMap = Object.create(null);
|
|
586
|
+
const cleanup = value => {
|
|
587
|
+
for (const event of Object.keys(eventMap)) {
|
|
588
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
589
|
+
}
|
|
590
|
+
resolve(value);
|
|
591
|
+
};
|
|
592
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
593
|
+
const listener = event => {
|
|
594
|
+
cleanup({
|
|
595
|
+
type,
|
|
596
|
+
event
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
addListener(eventEmitter, event, listener);
|
|
600
|
+
listenerMap[event] = listener;
|
|
601
|
+
}
|
|
602
|
+
return promise;
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// @ts-ignore
|
|
606
|
+
const getFirstWebSocketEvent = async webSocket => {
|
|
607
|
+
// @ts-ignore
|
|
608
|
+
const {
|
|
609
|
+
WebSocket
|
|
610
|
+
} = await import('ws');
|
|
611
|
+
switch (webSocket.readyState) {
|
|
612
|
+
case WebSocket.OPEN:
|
|
613
|
+
return {
|
|
614
|
+
type: Open,
|
|
615
|
+
event: undefined
|
|
616
|
+
};
|
|
617
|
+
case WebSocket.CLOSED:
|
|
618
|
+
return {
|
|
619
|
+
type: Close,
|
|
620
|
+
event: undefined
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
// @ts-ignore
|
|
624
|
+
const {
|
|
625
|
+
type,
|
|
626
|
+
event
|
|
627
|
+
} = await getFirstEvent(webSocket, {
|
|
628
|
+
open: Open,
|
|
629
|
+
close: Close
|
|
630
|
+
});
|
|
631
|
+
return {
|
|
632
|
+
type,
|
|
633
|
+
event
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
// @ts-ignore
|
|
638
|
+
const isWebSocketOpen = async webSocket => {
|
|
639
|
+
// @ts-ignore
|
|
640
|
+
const {
|
|
641
|
+
WebSocket
|
|
642
|
+
} = await import('ws');
|
|
643
|
+
return webSocket.readyState === WebSocket.OPEN;
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
// @ts-ignore
|
|
647
|
+
const serialize = message => {
|
|
648
|
+
return JSON.stringify(message);
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// @ts-ignore
|
|
652
|
+
const deserialize = message => {
|
|
653
|
+
return JSON.parse(message.toString());
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// @ts-ignore
|
|
657
|
+
const handleUpgrade$1 = async (...args) => {
|
|
658
|
+
const module = await Promise.resolve().then(function () { return index; });
|
|
659
|
+
// @ts-ignore
|
|
660
|
+
return module.handleUpgrade(...args);
|
|
661
|
+
};
|
|
662
|
+
const listen$1$1 = async ({
|
|
663
|
+
request,
|
|
664
|
+
handle
|
|
665
|
+
}) => {
|
|
666
|
+
if (!request) {
|
|
667
|
+
throw new IpcError('request must be defined');
|
|
668
|
+
}
|
|
669
|
+
if (!handle) {
|
|
670
|
+
throw new IpcError('handle must be defined');
|
|
671
|
+
}
|
|
672
|
+
const webSocket = await handleUpgrade$1(request, handle);
|
|
673
|
+
webSocket.pause();
|
|
674
|
+
if (!(await isWebSocketOpen(webSocket))) {
|
|
675
|
+
await getFirstWebSocketEvent(webSocket);
|
|
676
|
+
}
|
|
677
|
+
return webSocket;
|
|
678
|
+
};
|
|
679
|
+
const signal$4 = webSocket => {
|
|
680
|
+
webSocket.resume();
|
|
681
|
+
};
|
|
682
|
+
const wrap$9 = webSocket => {
|
|
683
|
+
return {
|
|
684
|
+
webSocket,
|
|
685
|
+
/**
|
|
686
|
+
* @type {any}
|
|
687
|
+
*/
|
|
688
|
+
wrappedListener: undefined,
|
|
689
|
+
// @ts-ignore
|
|
690
|
+
on(event, listener) {
|
|
691
|
+
switch (event) {
|
|
692
|
+
case 'message':
|
|
693
|
+
// @ts-ignore
|
|
694
|
+
const wrappedListener = message => {
|
|
695
|
+
const data = deserialize(message);
|
|
696
|
+
const event = {
|
|
697
|
+
data,
|
|
698
|
+
target: this
|
|
699
|
+
};
|
|
700
|
+
listener(event);
|
|
701
|
+
};
|
|
702
|
+
webSocket.on('message', wrappedListener);
|
|
703
|
+
break;
|
|
704
|
+
case 'close':
|
|
705
|
+
webSocket.on('close', listener);
|
|
706
|
+
break;
|
|
707
|
+
default:
|
|
708
|
+
throw new Error('unknown event listener type');
|
|
709
|
+
}
|
|
710
|
+
},
|
|
711
|
+
// @ts-ignore
|
|
712
|
+
off(event, listener) {
|
|
713
|
+
this.webSocket.off(event, listener);
|
|
714
|
+
},
|
|
715
|
+
// @ts-ignore
|
|
716
|
+
send(message) {
|
|
717
|
+
const stringifiedMessage = serialize(message);
|
|
718
|
+
this.webSocket.send(stringifiedMessage);
|
|
719
|
+
},
|
|
720
|
+
dispose() {
|
|
721
|
+
this.webSocket.close();
|
|
722
|
+
},
|
|
723
|
+
start() {
|
|
724
|
+
throw new Error('start method is deprecated');
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
};
|
|
728
|
+
const IpcChildWithWebSocket = {
|
|
729
|
+
__proto__: null,
|
|
730
|
+
listen: listen$1$1,
|
|
731
|
+
signal: signal$4,
|
|
732
|
+
wrap: wrap$9
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
const Two = '2.0';
|
|
736
|
+
const create$4 = (method, params) => {
|
|
737
|
+
return {
|
|
738
|
+
jsonrpc: Two,
|
|
739
|
+
method,
|
|
740
|
+
params
|
|
741
|
+
};
|
|
742
|
+
};
|
|
743
|
+
const callbacks = Object.create(null);
|
|
744
|
+
const set$1 = (id, fn) => {
|
|
745
|
+
callbacks[id] = fn;
|
|
746
|
+
};
|
|
747
|
+
const get$1 = id => {
|
|
748
|
+
return callbacks[id];
|
|
749
|
+
};
|
|
750
|
+
const remove$1 = id => {
|
|
751
|
+
delete callbacks[id];
|
|
752
|
+
};
|
|
753
|
+
let id = 0;
|
|
754
|
+
const create$3 = () => {
|
|
755
|
+
return ++id;
|
|
756
|
+
};
|
|
757
|
+
const registerPromise = () => {
|
|
758
|
+
const id = create$3();
|
|
759
|
+
const {
|
|
760
|
+
resolve,
|
|
761
|
+
promise
|
|
762
|
+
} = Promise.withResolvers();
|
|
763
|
+
set$1(id, resolve);
|
|
764
|
+
return {
|
|
765
|
+
id,
|
|
766
|
+
promise
|
|
767
|
+
};
|
|
768
|
+
};
|
|
769
|
+
const create$2 = (method, params) => {
|
|
770
|
+
const {
|
|
771
|
+
id,
|
|
772
|
+
promise
|
|
773
|
+
} = registerPromise();
|
|
774
|
+
const message = {
|
|
775
|
+
jsonrpc: Two,
|
|
776
|
+
method,
|
|
777
|
+
params,
|
|
778
|
+
id
|
|
779
|
+
};
|
|
780
|
+
return {
|
|
781
|
+
message,
|
|
782
|
+
promise
|
|
783
|
+
};
|
|
784
|
+
};
|
|
785
|
+
class JsonRpcError extends Error {
|
|
786
|
+
constructor(message) {
|
|
787
|
+
super(message);
|
|
788
|
+
this.name = 'JsonRpcError';
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
const NewLine$2 = '\n';
|
|
792
|
+
const DomException = 'DOMException';
|
|
793
|
+
const ReferenceError$1 = 'ReferenceError';
|
|
794
|
+
const SyntaxError$1 = 'SyntaxError';
|
|
795
|
+
const TypeError$1 = 'TypeError';
|
|
796
|
+
const getErrorConstructor = (message, type) => {
|
|
797
|
+
if (type) {
|
|
798
|
+
switch (type) {
|
|
799
|
+
case DomException:
|
|
800
|
+
return DOMException;
|
|
801
|
+
case TypeError$1:
|
|
802
|
+
return TypeError;
|
|
803
|
+
case SyntaxError$1:
|
|
804
|
+
return SyntaxError;
|
|
805
|
+
case ReferenceError$1:
|
|
806
|
+
return ReferenceError;
|
|
807
|
+
default:
|
|
808
|
+
return Error;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (message.startsWith('TypeError: ')) {
|
|
812
|
+
return TypeError;
|
|
813
|
+
}
|
|
814
|
+
if (message.startsWith('SyntaxError: ')) {
|
|
815
|
+
return SyntaxError;
|
|
816
|
+
}
|
|
817
|
+
if (message.startsWith('ReferenceError: ')) {
|
|
818
|
+
return ReferenceError;
|
|
819
|
+
}
|
|
820
|
+
return Error;
|
|
821
|
+
};
|
|
822
|
+
const constructError = (message, type, name) => {
|
|
823
|
+
const ErrorConstructor = getErrorConstructor(message, type);
|
|
824
|
+
if (ErrorConstructor === DOMException && name) {
|
|
825
|
+
return new ErrorConstructor(message, name);
|
|
826
|
+
}
|
|
827
|
+
if (ErrorConstructor === Error) {
|
|
828
|
+
const error = new Error(message);
|
|
829
|
+
if (name && name !== 'VError') {
|
|
830
|
+
error.name = name;
|
|
831
|
+
}
|
|
832
|
+
return error;
|
|
833
|
+
}
|
|
834
|
+
return new ErrorConstructor(message);
|
|
835
|
+
};
|
|
836
|
+
const joinLines$1 = lines => {
|
|
837
|
+
return lines.join(NewLine$2);
|
|
838
|
+
};
|
|
839
|
+
const splitLines$1 = lines => {
|
|
840
|
+
return lines.split(NewLine$2);
|
|
841
|
+
};
|
|
842
|
+
const getCurrentStack = () => {
|
|
843
|
+
const stackLinesToSkip = 3;
|
|
844
|
+
const currentStack = joinLines$1(splitLines$1(new Error().stack || '').slice(stackLinesToSkip));
|
|
845
|
+
return currentStack;
|
|
846
|
+
};
|
|
847
|
+
const getNewLineIndex$1 = (string, startIndex = undefined) => {
|
|
848
|
+
return string.indexOf(NewLine$2, startIndex);
|
|
849
|
+
};
|
|
850
|
+
const getParentStack = error => {
|
|
851
|
+
let parentStack = error.stack || error.data || error.message || '';
|
|
852
|
+
if (parentStack.startsWith(' at')) {
|
|
853
|
+
parentStack = error.message + NewLine$2 + parentStack;
|
|
854
|
+
}
|
|
855
|
+
return parentStack;
|
|
856
|
+
};
|
|
857
|
+
const MethodNotFound = -32601;
|
|
858
|
+
const Custom = -32001;
|
|
859
|
+
const restoreJsonRpcError = error => {
|
|
860
|
+
const currentStack = getCurrentStack();
|
|
861
|
+
if (error && error instanceof Error) {
|
|
862
|
+
if (typeof error.stack === 'string') {
|
|
863
|
+
error.stack = error.stack + NewLine$2 + currentStack;
|
|
864
|
+
}
|
|
865
|
+
return error;
|
|
866
|
+
}
|
|
867
|
+
if (error && error.code && error.code === MethodNotFound) {
|
|
868
|
+
const restoredError = new JsonRpcError(error.message);
|
|
869
|
+
const parentStack = getParentStack(error);
|
|
870
|
+
restoredError.stack = parentStack + NewLine$2 + currentStack;
|
|
871
|
+
return restoredError;
|
|
872
|
+
}
|
|
873
|
+
if (error && error.message) {
|
|
874
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
875
|
+
if (error.data) {
|
|
876
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
877
|
+
restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
|
|
878
|
+
} else if (error.data.stack) {
|
|
879
|
+
restoredError.stack = error.data.stack;
|
|
880
|
+
}
|
|
881
|
+
if (error.data.codeFrame) {
|
|
882
|
+
// @ts-ignore
|
|
883
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
884
|
+
}
|
|
885
|
+
if (error.data.code) {
|
|
886
|
+
// @ts-ignore
|
|
887
|
+
restoredError.code = error.data.code;
|
|
888
|
+
}
|
|
889
|
+
if (error.data.type) {
|
|
890
|
+
// @ts-ignore
|
|
891
|
+
restoredError.name = error.data.type;
|
|
892
|
+
}
|
|
893
|
+
} else {
|
|
894
|
+
if (error.stack) {
|
|
895
|
+
const lowerStack = restoredError.stack || '';
|
|
896
|
+
// @ts-ignore
|
|
897
|
+
const indexNewLine = getNewLineIndex$1(lowerStack);
|
|
898
|
+
const parentStack = getParentStack(error);
|
|
899
|
+
// @ts-ignore
|
|
900
|
+
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
901
|
+
}
|
|
902
|
+
if (error.codeFrame) {
|
|
903
|
+
// @ts-ignore
|
|
904
|
+
restoredError.codeFrame = error.codeFrame;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return restoredError;
|
|
908
|
+
}
|
|
909
|
+
if (typeof error === 'string') {
|
|
910
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
911
|
+
}
|
|
912
|
+
return new Error(`JsonRpc Error: ${error}`);
|
|
913
|
+
};
|
|
914
|
+
const unwrapJsonRpcResult = responseMessage => {
|
|
915
|
+
if ('error' in responseMessage) {
|
|
916
|
+
const restoredError = restoreJsonRpcError(responseMessage.error);
|
|
917
|
+
throw restoredError;
|
|
918
|
+
}
|
|
919
|
+
if ('result' in responseMessage) {
|
|
920
|
+
return responseMessage.result;
|
|
921
|
+
}
|
|
922
|
+
throw new JsonRpcError('unexpected response message');
|
|
923
|
+
};
|
|
924
|
+
const warn$1 = (...args) => {
|
|
925
|
+
console.warn(...args);
|
|
926
|
+
};
|
|
927
|
+
const resolve = (id, response) => {
|
|
928
|
+
const fn = get$1(id);
|
|
929
|
+
if (!fn) {
|
|
930
|
+
console.log(response);
|
|
931
|
+
warn$1(`callback ${id} may already be disposed`);
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
fn(response);
|
|
935
|
+
remove$1(id);
|
|
936
|
+
};
|
|
937
|
+
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
938
|
+
const getErrorType = prettyError => {
|
|
939
|
+
if (prettyError && prettyError.type) {
|
|
940
|
+
return prettyError.type;
|
|
941
|
+
}
|
|
942
|
+
if (prettyError && prettyError.constructor && prettyError.constructor.name) {
|
|
943
|
+
return prettyError.constructor.name;
|
|
944
|
+
}
|
|
945
|
+
return undefined;
|
|
946
|
+
};
|
|
947
|
+
const isAlreadyStack = line => {
|
|
948
|
+
return line.trim().startsWith('at ');
|
|
949
|
+
};
|
|
950
|
+
const getStack = prettyError => {
|
|
951
|
+
const stackString = prettyError.stack || '';
|
|
952
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
953
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
954
|
+
return stackString.slice(newLineIndex + 1);
|
|
955
|
+
}
|
|
956
|
+
return stackString;
|
|
957
|
+
};
|
|
958
|
+
const getErrorProperty = (error, prettyError) => {
|
|
959
|
+
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
960
|
+
return {
|
|
961
|
+
code: MethodNotFound,
|
|
962
|
+
message: error.message,
|
|
963
|
+
data: error.stack
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
return {
|
|
967
|
+
code: Custom,
|
|
968
|
+
message: prettyError.message,
|
|
969
|
+
data: {
|
|
970
|
+
stack: getStack(prettyError),
|
|
971
|
+
codeFrame: prettyError.codeFrame,
|
|
972
|
+
type: getErrorType(prettyError),
|
|
973
|
+
code: prettyError.code,
|
|
974
|
+
name: prettyError.name
|
|
975
|
+
}
|
|
976
|
+
};
|
|
977
|
+
};
|
|
978
|
+
const create$1$1 = (id, error) => {
|
|
979
|
+
return {
|
|
980
|
+
jsonrpc: Two,
|
|
981
|
+
id,
|
|
982
|
+
error
|
|
983
|
+
};
|
|
984
|
+
};
|
|
985
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
986
|
+
const prettyError = preparePrettyError(error);
|
|
987
|
+
logError(error, prettyError);
|
|
988
|
+
const errorProperty = getErrorProperty(error, prettyError);
|
|
989
|
+
return create$1$1(id, errorProperty);
|
|
990
|
+
};
|
|
991
|
+
const create$5 = (message, result) => {
|
|
992
|
+
return {
|
|
993
|
+
jsonrpc: Two,
|
|
994
|
+
id: message.id,
|
|
995
|
+
result: result ?? null
|
|
996
|
+
};
|
|
997
|
+
};
|
|
998
|
+
const getSuccessResponse = (message, result) => {
|
|
999
|
+
const resultProperty = result ?? null;
|
|
1000
|
+
return create$5(message, resultProperty);
|
|
1001
|
+
};
|
|
1002
|
+
const getErrorResponseSimple = (id, error) => {
|
|
1003
|
+
return {
|
|
1004
|
+
jsonrpc: Two,
|
|
1005
|
+
id,
|
|
1006
|
+
error: {
|
|
1007
|
+
code: Custom,
|
|
1008
|
+
// @ts-ignore
|
|
1009
|
+
message: error.message,
|
|
1010
|
+
data: error
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
};
|
|
1014
|
+
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1015
|
+
try {
|
|
1016
|
+
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1017
|
+
return getSuccessResponse(message, result);
|
|
1018
|
+
} catch (error) {
|
|
1019
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
1020
|
+
return getErrorResponseSimple(message.id, error);
|
|
1021
|
+
}
|
|
1022
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1023
|
+
}
|
|
1024
|
+
};
|
|
1025
|
+
const defaultPreparePrettyError = error => {
|
|
1026
|
+
return error;
|
|
1027
|
+
};
|
|
1028
|
+
const defaultLogError = () => {
|
|
1029
|
+
// ignore
|
|
1030
|
+
};
|
|
1031
|
+
const defaultRequiresSocket = () => {
|
|
1032
|
+
return false;
|
|
1033
|
+
};
|
|
1034
|
+
const defaultResolve = resolve;
|
|
1035
|
+
|
|
1036
|
+
// TODO maybe remove this in v6 or v7, only accept options object to simplify the code
|
|
1037
|
+
const normalizeParams = args => {
|
|
1038
|
+
if (args.length === 1) {
|
|
1039
|
+
const options = args[0];
|
|
1040
|
+
return {
|
|
1041
|
+
ipc: options.ipc,
|
|
1042
|
+
message: options.message,
|
|
1043
|
+
execute: options.execute,
|
|
1044
|
+
resolve: options.resolve || defaultResolve,
|
|
1045
|
+
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1046
|
+
logError: options.logError || defaultLogError,
|
|
1047
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
ipc: args[0],
|
|
1052
|
+
message: args[1],
|
|
1053
|
+
execute: args[2],
|
|
1054
|
+
resolve: args[3],
|
|
1055
|
+
preparePrettyError: args[4],
|
|
1056
|
+
logError: args[5],
|
|
1057
|
+
requiresSocket: args[6]
|
|
1058
|
+
};
|
|
1059
|
+
};
|
|
1060
|
+
const handleJsonRpcMessage = async (...args) => {
|
|
1061
|
+
const options = normalizeParams(args);
|
|
1062
|
+
const {
|
|
1063
|
+
message,
|
|
1064
|
+
ipc,
|
|
1065
|
+
execute,
|
|
1066
|
+
resolve,
|
|
1067
|
+
preparePrettyError,
|
|
1068
|
+
logError,
|
|
1069
|
+
requiresSocket
|
|
1070
|
+
} = options;
|
|
1071
|
+
if ('id' in message) {
|
|
1072
|
+
if ('method' in message) {
|
|
1073
|
+
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1074
|
+
try {
|
|
1075
|
+
ipc.send(response);
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1078
|
+
ipc.send(errorResponse);
|
|
1079
|
+
}
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
resolve(message.id, message);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
if ('method' in message) {
|
|
1086
|
+
await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
throw new JsonRpcError('unexpected message');
|
|
1090
|
+
};
|
|
1091
|
+
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
1092
|
+
const {
|
|
1093
|
+
message,
|
|
1094
|
+
promise
|
|
1095
|
+
} = create$2(method, params);
|
|
1096
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1097
|
+
ipc.sendAndTransfer(message);
|
|
1098
|
+
} else {
|
|
1099
|
+
ipc.send(message);
|
|
1100
|
+
}
|
|
1101
|
+
const responseMessage = await promise;
|
|
1102
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
1103
|
+
};
|
|
1104
|
+
const send = (transport, method, ...params) => {
|
|
1105
|
+
const message = create$4(method, params);
|
|
1106
|
+
transport.send(message);
|
|
1107
|
+
};
|
|
1108
|
+
const invoke = (ipc, method, ...params) => {
|
|
1109
|
+
return invokeHelper(ipc, method, params, false);
|
|
1110
|
+
};
|
|
1111
|
+
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
1112
|
+
return invokeHelper(ipc, method, params, true);
|
|
1113
|
+
};
|
|
12
1114
|
|
|
13
1115
|
const createRpc = ipc => {
|
|
14
1116
|
const rpc = {
|
|
@@ -18,13 +1120,13 @@ const createRpc = ipc => {
|
|
|
18
1120
|
* @deprecated
|
|
19
1121
|
*/
|
|
20
1122
|
send(method, ...params) {
|
|
21
|
-
|
|
1123
|
+
send(ipc, method, ...params);
|
|
22
1124
|
},
|
|
23
1125
|
invoke(method, ...params) {
|
|
24
|
-
return
|
|
1126
|
+
return invoke(ipc, method, ...params);
|
|
25
1127
|
},
|
|
26
1128
|
invokeAndTransfer(method, ...params) {
|
|
27
|
-
return
|
|
1129
|
+
return invokeAndTransfer(ipc, method, ...params);
|
|
28
1130
|
},
|
|
29
1131
|
async dispose() {
|
|
30
1132
|
await ipc?.dispose();
|
|
@@ -62,14 +1164,14 @@ const listen$2 = async (module, options) => {
|
|
|
62
1164
|
const ipc = module.wrap(rawIpc);
|
|
63
1165
|
return ipc;
|
|
64
1166
|
};
|
|
65
|
-
const create$
|
|
1167
|
+
const create$k = async ({
|
|
66
1168
|
commandMap,
|
|
67
1169
|
messagePort,
|
|
68
1170
|
requiresSocket
|
|
69
1171
|
}) => {
|
|
70
1172
|
// TODO create a commandMap per rpc instance
|
|
71
1173
|
register(commandMap);
|
|
72
|
-
const ipc = await listen$2(IpcChildWithElectronMessagePort, {
|
|
1174
|
+
const ipc = await listen$2(IpcChildWithElectronMessagePort$1, {
|
|
73
1175
|
messagePort
|
|
74
1176
|
});
|
|
75
1177
|
if (requiresSocket) {
|
|
@@ -81,37 +1183,37 @@ const create$e = async ({
|
|
|
81
1183
|
};
|
|
82
1184
|
const ElectronMessagePortRpcClient = {
|
|
83
1185
|
__proto__: null,
|
|
84
|
-
create: create$
|
|
1186
|
+
create: create$k
|
|
85
1187
|
};
|
|
86
|
-
const create$
|
|
1188
|
+
const create$j = async ({
|
|
87
1189
|
commandMap
|
|
88
1190
|
}) => {
|
|
89
1191
|
// TODO create a commandMap per rpc instance
|
|
90
1192
|
register(commandMap);
|
|
91
|
-
const ipc = await listen$2(IpcChildWithElectronUtilityProcess);
|
|
1193
|
+
const ipc = await listen$2(IpcChildWithElectronUtilityProcess$1);
|
|
92
1194
|
handleIpc(ipc);
|
|
93
1195
|
const rpc = createRpc(ipc);
|
|
94
1196
|
return rpc;
|
|
95
1197
|
};
|
|
96
1198
|
const ElectronUtilityProcessRpcClient = {
|
|
97
1199
|
__proto__: null,
|
|
98
|
-
create: create$
|
|
1200
|
+
create: create$j
|
|
99
1201
|
};
|
|
100
|
-
const create$
|
|
1202
|
+
const create$a = async ({
|
|
101
1203
|
commandMap
|
|
102
1204
|
}) => {
|
|
103
1205
|
// TODO create a commandMap per rpc instance
|
|
104
1206
|
register(commandMap);
|
|
105
|
-
const ipc = await listen$2(IpcChildWithNodeForkedProcess);
|
|
1207
|
+
const ipc = await listen$2(IpcChildWithNodeForkedProcess$1);
|
|
106
1208
|
handleIpc(ipc);
|
|
107
1209
|
const rpc = createRpc(ipc);
|
|
108
1210
|
return rpc;
|
|
109
1211
|
};
|
|
110
1212
|
const NodeForkedProcessRpcClient = {
|
|
111
1213
|
__proto__: null,
|
|
112
|
-
create: create$
|
|
1214
|
+
create: create$a
|
|
113
1215
|
};
|
|
114
|
-
const create$
|
|
1216
|
+
const create$8 = async ({
|
|
115
1217
|
commandMap,
|
|
116
1218
|
request,
|
|
117
1219
|
handle,
|
|
@@ -132,60 +1234,7 @@ const create$5 = async ({
|
|
|
132
1234
|
};
|
|
133
1235
|
const NodeWebSocketRpcClient = {
|
|
134
1236
|
__proto__: null,
|
|
135
|
-
create: create$
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
class AssertionError extends Error {
|
|
139
|
-
constructor(message) {
|
|
140
|
-
super(message);
|
|
141
|
-
this.name = 'AssertionError';
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const getType = value => {
|
|
145
|
-
switch (typeof value) {
|
|
146
|
-
case 'number':
|
|
147
|
-
return 'number';
|
|
148
|
-
case 'function':
|
|
149
|
-
return 'function';
|
|
150
|
-
case 'string':
|
|
151
|
-
return 'string';
|
|
152
|
-
case 'object':
|
|
153
|
-
if (value === null) {
|
|
154
|
-
return 'null';
|
|
155
|
-
}
|
|
156
|
-
if (Array.isArray(value)) {
|
|
157
|
-
return 'array';
|
|
158
|
-
}
|
|
159
|
-
return 'object';
|
|
160
|
-
case 'boolean':
|
|
161
|
-
return 'boolean';
|
|
162
|
-
default:
|
|
163
|
-
return 'unknown';
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
const object = value => {
|
|
167
|
-
const type = getType(value);
|
|
168
|
-
if (type !== 'object') {
|
|
169
|
-
throw new AssertionError('expected value to be of type object');
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const number = value => {
|
|
173
|
-
const type = getType(value);
|
|
174
|
-
if (type !== 'number') {
|
|
175
|
-
throw new AssertionError('expected value to be of type number');
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const array = value => {
|
|
179
|
-
const type = getType(value);
|
|
180
|
-
if (type !== 'array') {
|
|
181
|
-
throw new AssertionError('expected value to be of type array');
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
const string = value => {
|
|
185
|
-
const type = getType(value);
|
|
186
|
-
if (type !== 'string') {
|
|
187
|
-
throw new AssertionError('expected value to be of type string');
|
|
188
|
-
}
|
|
1237
|
+
create: create$8
|
|
189
1238
|
};
|
|
190
1239
|
|
|
191
1240
|
const METHODS_THAT_REQUIRE_SOCKET = new Set(['Terminal.create']);
|
|
@@ -422,7 +1471,7 @@ const listen = async () => {
|
|
|
422
1471
|
});
|
|
423
1472
|
};
|
|
424
1473
|
|
|
425
|
-
const NewLine = '\n';
|
|
1474
|
+
const NewLine$1 = '\n';
|
|
426
1475
|
|
|
427
1476
|
const Error$1 = 1;
|
|
428
1477
|
const Success = 0;
|
|
@@ -434,7 +1483,7 @@ const Success = 0;
|
|
|
434
1483
|
* @returns
|
|
435
1484
|
*/
|
|
436
1485
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
437
|
-
return string.indexOf(NewLine, startIndex);
|
|
1486
|
+
return string.indexOf(NewLine$1, startIndex);
|
|
438
1487
|
};
|
|
439
1488
|
|
|
440
1489
|
const EPIPE = 'EPIPE';
|
|
@@ -490,6 +1539,722 @@ const error = (...args) => {
|
|
|
490
1539
|
console.error(...args);
|
|
491
1540
|
};
|
|
492
1541
|
|
|
1542
|
+
var lib$1 = {};
|
|
1543
|
+
|
|
1544
|
+
var picocolors = {exports: {}};
|
|
1545
|
+
|
|
1546
|
+
var hasRequiredPicocolors;
|
|
1547
|
+
|
|
1548
|
+
function requirePicocolors () {
|
|
1549
|
+
if (hasRequiredPicocolors) return picocolors.exports;
|
|
1550
|
+
hasRequiredPicocolors = 1;
|
|
1551
|
+
let p = process || {},
|
|
1552
|
+
argv = p.argv || [],
|
|
1553
|
+
env = p.env || {};
|
|
1554
|
+
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
1555
|
+
let formatter = (open, close, replace = open) => input => {
|
|
1556
|
+
let string = "" + input,
|
|
1557
|
+
index = string.indexOf(close, open.length);
|
|
1558
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
1559
|
+
};
|
|
1560
|
+
let replaceClose = (string, close, replace, index) => {
|
|
1561
|
+
let result = "",
|
|
1562
|
+
cursor = 0;
|
|
1563
|
+
do {
|
|
1564
|
+
result += string.substring(cursor, index) + replace;
|
|
1565
|
+
cursor = index + close.length;
|
|
1566
|
+
index = string.indexOf(close, cursor);
|
|
1567
|
+
} while (~index);
|
|
1568
|
+
return result + string.substring(cursor);
|
|
1569
|
+
};
|
|
1570
|
+
let createColors = (enabled = isColorSupported) => {
|
|
1571
|
+
let f = enabled ? formatter : () => String;
|
|
1572
|
+
return {
|
|
1573
|
+
isColorSupported: enabled,
|
|
1574
|
+
reset: f("\x1b[0m", "\x1b[0m"),
|
|
1575
|
+
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
1576
|
+
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
1577
|
+
italic: f("\x1b[3m", "\x1b[23m"),
|
|
1578
|
+
underline: f("\x1b[4m", "\x1b[24m"),
|
|
1579
|
+
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
1580
|
+
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
1581
|
+
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
1582
|
+
black: f("\x1b[30m", "\x1b[39m"),
|
|
1583
|
+
red: f("\x1b[31m", "\x1b[39m"),
|
|
1584
|
+
green: f("\x1b[32m", "\x1b[39m"),
|
|
1585
|
+
yellow: f("\x1b[33m", "\x1b[39m"),
|
|
1586
|
+
blue: f("\x1b[34m", "\x1b[39m"),
|
|
1587
|
+
magenta: f("\x1b[35m", "\x1b[39m"),
|
|
1588
|
+
cyan: f("\x1b[36m", "\x1b[39m"),
|
|
1589
|
+
white: f("\x1b[37m", "\x1b[39m"),
|
|
1590
|
+
gray: f("\x1b[90m", "\x1b[39m"),
|
|
1591
|
+
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|
1592
|
+
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|
1593
|
+
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
1594
|
+
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
1595
|
+
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
1596
|
+
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
1597
|
+
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
1598
|
+
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
1599
|
+
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|
1600
|
+
redBright: f("\x1b[91m", "\x1b[39m"),
|
|
1601
|
+
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|
1602
|
+
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|
1603
|
+
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|
1604
|
+
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|
1605
|
+
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|
1606
|
+
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|
1607
|
+
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|
1608
|
+
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|
1609
|
+
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|
1610
|
+
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|
1611
|
+
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|
1612
|
+
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|
1613
|
+
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|
1614
|
+
bgWhiteBright: f("\x1b[107m", "\x1b[49m")
|
|
1615
|
+
};
|
|
1616
|
+
};
|
|
1617
|
+
picocolors.exports = createColors();
|
|
1618
|
+
picocolors.exports.createColors = createColors;
|
|
1619
|
+
return picocolors.exports;
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
var jsTokens = {};
|
|
1623
|
+
|
|
1624
|
+
var hasRequiredJsTokens;
|
|
1625
|
+
|
|
1626
|
+
function requireJsTokens () {
|
|
1627
|
+
if (hasRequiredJsTokens) return jsTokens;
|
|
1628
|
+
hasRequiredJsTokens = 1;
|
|
1629
|
+
// Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
|
|
1630
|
+
// License: MIT. (See LICENSE.)
|
|
1631
|
+
|
|
1632
|
+
Object.defineProperty(jsTokens, "__esModule", {
|
|
1633
|
+
value: true
|
|
1634
|
+
});
|
|
1635
|
+
|
|
1636
|
+
// This regex comes from regex.coffee, and is inserted here by generate-index.js
|
|
1637
|
+
// (run `npm run build`).
|
|
1638
|
+
jsTokens.default = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
|
|
1639
|
+
jsTokens.matchToToken = function (match) {
|
|
1640
|
+
var token = {
|
|
1641
|
+
type: "invalid",
|
|
1642
|
+
value: match[0],
|
|
1643
|
+
closed: undefined
|
|
1644
|
+
};
|
|
1645
|
+
if (match[1]) token.type = "string", token.closed = !!(match[3] || match[4]);else if (match[5]) token.type = "comment";else if (match[6]) token.type = "comment", token.closed = !!match[7];else if (match[8]) token.type = "regex";else if (match[9]) token.type = "number";else if (match[10]) token.type = "name";else if (match[11]) token.type = "punctuator";else if (match[12]) token.type = "whitespace";
|
|
1646
|
+
return token;
|
|
1647
|
+
};
|
|
1648
|
+
return jsTokens;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
var lib = {};
|
|
1652
|
+
|
|
1653
|
+
var identifier = {};
|
|
1654
|
+
|
|
1655
|
+
var hasRequiredIdentifier;
|
|
1656
|
+
|
|
1657
|
+
function requireIdentifier () {
|
|
1658
|
+
if (hasRequiredIdentifier) return identifier;
|
|
1659
|
+
hasRequiredIdentifier = 1;
|
|
1660
|
+
|
|
1661
|
+
Object.defineProperty(identifier, "__esModule", {
|
|
1662
|
+
value: true
|
|
1663
|
+
});
|
|
1664
|
+
identifier.isIdentifierChar = isIdentifierChar;
|
|
1665
|
+
identifier.isIdentifierName = isIdentifierName;
|
|
1666
|
+
identifier.isIdentifierStart = isIdentifierStart;
|
|
1667
|
+
let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u0870-\u0887\u0889-\u088e\u08a0-\u08c9\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c5d\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cdd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u1711\u171f-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4c\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c8a\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7cd\ua7d0\ua7d1\ua7d3\ua7d5-\ua7dc\ua7f2-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
|
|
1668
|
+
let nonASCIIidentifierChars = "\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u0897-\u089f\u08ca-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3c\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0cf3\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ece\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u180f-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf-\u1ace\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\u30fb\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f\uff65";
|
|
1669
|
+
const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
|
1670
|
+
const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
|
1671
|
+
nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
|
1672
|
+
const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
|
|
1673
|
+
const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
1674
|
+
function isInAstralSet(code, set) {
|
|
1675
|
+
let pos = 0x10000;
|
|
1676
|
+
for (let i = 0, length = set.length; i < length; i += 2) {
|
|
1677
|
+
pos += set[i];
|
|
1678
|
+
if (pos > code) return false;
|
|
1679
|
+
pos += set[i + 1];
|
|
1680
|
+
if (pos >= code) return true;
|
|
1681
|
+
}
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
function isIdentifierStart(code) {
|
|
1685
|
+
if (code < 65) return code === 36;
|
|
1686
|
+
if (code <= 90) return true;
|
|
1687
|
+
if (code < 97) return code === 95;
|
|
1688
|
+
if (code <= 122) return true;
|
|
1689
|
+
if (code <= 0xffff) {
|
|
1690
|
+
return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
|
|
1691
|
+
}
|
|
1692
|
+
return isInAstralSet(code, astralIdentifierStartCodes);
|
|
1693
|
+
}
|
|
1694
|
+
function isIdentifierChar(code) {
|
|
1695
|
+
if (code < 48) return code === 36;
|
|
1696
|
+
if (code < 58) return true;
|
|
1697
|
+
if (code < 65) return false;
|
|
1698
|
+
if (code <= 90) return true;
|
|
1699
|
+
if (code < 97) return code === 95;
|
|
1700
|
+
if (code <= 122) return true;
|
|
1701
|
+
if (code <= 0xffff) {
|
|
1702
|
+
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
|
|
1703
|
+
}
|
|
1704
|
+
return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
|
|
1705
|
+
}
|
|
1706
|
+
function isIdentifierName(name) {
|
|
1707
|
+
let isFirst = true;
|
|
1708
|
+
for (let i = 0; i < name.length; i++) {
|
|
1709
|
+
let cp = name.charCodeAt(i);
|
|
1710
|
+
if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) {
|
|
1711
|
+
const trail = name.charCodeAt(++i);
|
|
1712
|
+
if ((trail & 0xfc00) === 0xdc00) {
|
|
1713
|
+
cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
if (isFirst) {
|
|
1717
|
+
isFirst = false;
|
|
1718
|
+
if (!isIdentifierStart(cp)) {
|
|
1719
|
+
return false;
|
|
1720
|
+
}
|
|
1721
|
+
} else if (!isIdentifierChar(cp)) {
|
|
1722
|
+
return false;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return !isFirst;
|
|
1726
|
+
}
|
|
1727
|
+
return identifier;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
var keyword = {};
|
|
1731
|
+
|
|
1732
|
+
var hasRequiredKeyword;
|
|
1733
|
+
|
|
1734
|
+
function requireKeyword () {
|
|
1735
|
+
if (hasRequiredKeyword) return keyword;
|
|
1736
|
+
hasRequiredKeyword = 1;
|
|
1737
|
+
|
|
1738
|
+
Object.defineProperty(keyword, "__esModule", {
|
|
1739
|
+
value: true
|
|
1740
|
+
});
|
|
1741
|
+
keyword.isKeyword = isKeyword;
|
|
1742
|
+
keyword.isReservedWord = isReservedWord;
|
|
1743
|
+
keyword.isStrictBindOnlyReservedWord = isStrictBindOnlyReservedWord;
|
|
1744
|
+
keyword.isStrictBindReservedWord = isStrictBindReservedWord;
|
|
1745
|
+
keyword.isStrictReservedWord = isStrictReservedWord;
|
|
1746
|
+
const reservedWords = {
|
|
1747
|
+
keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
|
|
1748
|
+
strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
|
|
1749
|
+
strictBind: ["eval", "arguments"]
|
|
1750
|
+
};
|
|
1751
|
+
const keywords = new Set(reservedWords.keyword);
|
|
1752
|
+
const reservedWordsStrictSet = new Set(reservedWords.strict);
|
|
1753
|
+
const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
|
|
1754
|
+
function isReservedWord(word, inModule) {
|
|
1755
|
+
return inModule && word === "await" || word === "enum";
|
|
1756
|
+
}
|
|
1757
|
+
function isStrictReservedWord(word, inModule) {
|
|
1758
|
+
return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
|
|
1759
|
+
}
|
|
1760
|
+
function isStrictBindOnlyReservedWord(word) {
|
|
1761
|
+
return reservedWordsStrictBindSet.has(word);
|
|
1762
|
+
}
|
|
1763
|
+
function isStrictBindReservedWord(word, inModule) {
|
|
1764
|
+
return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
|
|
1765
|
+
}
|
|
1766
|
+
function isKeyword(word) {
|
|
1767
|
+
return keywords.has(word);
|
|
1768
|
+
}
|
|
1769
|
+
return keyword;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
var hasRequiredLib$1;
|
|
1773
|
+
|
|
1774
|
+
function requireLib$1 () {
|
|
1775
|
+
if (hasRequiredLib$1) return lib;
|
|
1776
|
+
hasRequiredLib$1 = 1;
|
|
1777
|
+
(function (exports) {
|
|
1778
|
+
|
|
1779
|
+
Object.defineProperty(exports, "__esModule", {
|
|
1780
|
+
value: true
|
|
1781
|
+
});
|
|
1782
|
+
Object.defineProperty(exports, "isIdentifierChar", {
|
|
1783
|
+
enumerable: true,
|
|
1784
|
+
get: function () {
|
|
1785
|
+
return _identifier.isIdentifierChar;
|
|
1786
|
+
}
|
|
1787
|
+
});
|
|
1788
|
+
Object.defineProperty(exports, "isIdentifierName", {
|
|
1789
|
+
enumerable: true,
|
|
1790
|
+
get: function () {
|
|
1791
|
+
return _identifier.isIdentifierName;
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
Object.defineProperty(exports, "isIdentifierStart", {
|
|
1795
|
+
enumerable: true,
|
|
1796
|
+
get: function () {
|
|
1797
|
+
return _identifier.isIdentifierStart;
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
1800
|
+
Object.defineProperty(exports, "isKeyword", {
|
|
1801
|
+
enumerable: true,
|
|
1802
|
+
get: function () {
|
|
1803
|
+
return _keyword.isKeyword;
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
Object.defineProperty(exports, "isReservedWord", {
|
|
1807
|
+
enumerable: true,
|
|
1808
|
+
get: function () {
|
|
1809
|
+
return _keyword.isReservedWord;
|
|
1810
|
+
}
|
|
1811
|
+
});
|
|
1812
|
+
Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
|
|
1813
|
+
enumerable: true,
|
|
1814
|
+
get: function () {
|
|
1815
|
+
return _keyword.isStrictBindOnlyReservedWord;
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
Object.defineProperty(exports, "isStrictBindReservedWord", {
|
|
1819
|
+
enumerable: true,
|
|
1820
|
+
get: function () {
|
|
1821
|
+
return _keyword.isStrictBindReservedWord;
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
Object.defineProperty(exports, "isStrictReservedWord", {
|
|
1825
|
+
enumerable: true,
|
|
1826
|
+
get: function () {
|
|
1827
|
+
return _keyword.isStrictReservedWord;
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
var _identifier = requireIdentifier();
|
|
1831
|
+
var _keyword = requireKeyword();
|
|
1832
|
+
} (lib));
|
|
1833
|
+
return lib;
|
|
1834
|
+
}
|
|
1835
|
+
|
|
1836
|
+
var hasRequiredLib;
|
|
1837
|
+
|
|
1838
|
+
function requireLib () {
|
|
1839
|
+
if (hasRequiredLib) return lib$1;
|
|
1840
|
+
hasRequiredLib = 1;
|
|
1841
|
+
|
|
1842
|
+
Object.defineProperty(lib$1, '__esModule', {
|
|
1843
|
+
value: true
|
|
1844
|
+
});
|
|
1845
|
+
var picocolors = /*@__PURE__*/ requirePicocolors();
|
|
1846
|
+
var jsTokens = requireJsTokens();
|
|
1847
|
+
var helperValidatorIdentifier = requireLib$1();
|
|
1848
|
+
function isColorSupported() {
|
|
1849
|
+
return typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? false : picocolors.isColorSupported;
|
|
1850
|
+
}
|
|
1851
|
+
const compose = (f, g) => v => f(g(v));
|
|
1852
|
+
function buildDefs(colors) {
|
|
1853
|
+
return {
|
|
1854
|
+
keyword: colors.cyan,
|
|
1855
|
+
capitalized: colors.yellow,
|
|
1856
|
+
jsxIdentifier: colors.yellow,
|
|
1857
|
+
punctuator: colors.yellow,
|
|
1858
|
+
number: colors.magenta,
|
|
1859
|
+
string: colors.green,
|
|
1860
|
+
regex: colors.magenta,
|
|
1861
|
+
comment: colors.gray,
|
|
1862
|
+
invalid: compose(compose(colors.white, colors.bgRed), colors.bold),
|
|
1863
|
+
gutter: colors.gray,
|
|
1864
|
+
marker: compose(colors.red, colors.bold),
|
|
1865
|
+
message: compose(colors.red, colors.bold),
|
|
1866
|
+
reset: colors.reset
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
const defsOn = buildDefs(picocolors.createColors(true));
|
|
1870
|
+
const defsOff = buildDefs(picocolors.createColors(false));
|
|
1871
|
+
function getDefs(enabled) {
|
|
1872
|
+
return enabled ? defsOn : defsOff;
|
|
1873
|
+
}
|
|
1874
|
+
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
|
|
1875
|
+
const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
|
|
1876
|
+
const BRACKET = /^[()[\]{}]$/;
|
|
1877
|
+
let tokenize;
|
|
1878
|
+
{
|
|
1879
|
+
const JSX_TAG = /^[a-z][\w-]*$/i;
|
|
1880
|
+
const getTokenType = function (token, offset, text) {
|
|
1881
|
+
if (token.type === "name") {
|
|
1882
|
+
if (helperValidatorIdentifier.isKeyword(token.value) || helperValidatorIdentifier.isStrictReservedWord(token.value, true) || sometimesKeywords.has(token.value)) {
|
|
1883
|
+
return "keyword";
|
|
1884
|
+
}
|
|
1885
|
+
if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) {
|
|
1886
|
+
return "jsxIdentifier";
|
|
1887
|
+
}
|
|
1888
|
+
if (token.value[0] !== token.value[0].toLowerCase()) {
|
|
1889
|
+
return "capitalized";
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (token.type === "punctuator" && BRACKET.test(token.value)) {
|
|
1893
|
+
return "bracket";
|
|
1894
|
+
}
|
|
1895
|
+
if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
|
|
1896
|
+
return "punctuator";
|
|
1897
|
+
}
|
|
1898
|
+
return token.type;
|
|
1899
|
+
};
|
|
1900
|
+
tokenize = function* (text) {
|
|
1901
|
+
let match;
|
|
1902
|
+
while (match = jsTokens.default.exec(text)) {
|
|
1903
|
+
const token = jsTokens.matchToToken(match);
|
|
1904
|
+
yield {
|
|
1905
|
+
type: getTokenType(token, match.index, text),
|
|
1906
|
+
value: token.value
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
}
|
|
1911
|
+
function highlight(text) {
|
|
1912
|
+
if (text === "") return "";
|
|
1913
|
+
const defs = getDefs(true);
|
|
1914
|
+
let highlighted = "";
|
|
1915
|
+
for (const {
|
|
1916
|
+
type,
|
|
1917
|
+
value
|
|
1918
|
+
} of tokenize(text)) {
|
|
1919
|
+
if (type in defs) {
|
|
1920
|
+
highlighted += value.split(NEWLINE$1).map(str => defs[type](str)).join("\n");
|
|
1921
|
+
} else {
|
|
1922
|
+
highlighted += value;
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
return highlighted;
|
|
1926
|
+
}
|
|
1927
|
+
let deprecationWarningShown = false;
|
|
1928
|
+
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
|
|
1929
|
+
function getMarkerLines(loc, source, opts) {
|
|
1930
|
+
const startLoc = Object.assign({
|
|
1931
|
+
column: 0,
|
|
1932
|
+
line: -1
|
|
1933
|
+
}, loc.start);
|
|
1934
|
+
const endLoc = Object.assign({}, startLoc, loc.end);
|
|
1935
|
+
const {
|
|
1936
|
+
linesAbove = 2,
|
|
1937
|
+
linesBelow = 3
|
|
1938
|
+
} = opts || {};
|
|
1939
|
+
const startLine = startLoc.line;
|
|
1940
|
+
const startColumn = startLoc.column;
|
|
1941
|
+
const endLine = endLoc.line;
|
|
1942
|
+
const endColumn = endLoc.column;
|
|
1943
|
+
let start = Math.max(startLine - (linesAbove + 1), 0);
|
|
1944
|
+
let end = Math.min(source.length, endLine + linesBelow);
|
|
1945
|
+
if (startLine === -1) {
|
|
1946
|
+
start = 0;
|
|
1947
|
+
}
|
|
1948
|
+
if (endLine === -1) {
|
|
1949
|
+
end = source.length;
|
|
1950
|
+
}
|
|
1951
|
+
const lineDiff = endLine - startLine;
|
|
1952
|
+
const markerLines = {};
|
|
1953
|
+
if (lineDiff) {
|
|
1954
|
+
for (let i = 0; i <= lineDiff; i++) {
|
|
1955
|
+
const lineNumber = i + startLine;
|
|
1956
|
+
if (!startColumn) {
|
|
1957
|
+
markerLines[lineNumber] = true;
|
|
1958
|
+
} else if (i === 0) {
|
|
1959
|
+
const sourceLength = source[lineNumber - 1].length;
|
|
1960
|
+
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
|
|
1961
|
+
} else if (i === lineDiff) {
|
|
1962
|
+
markerLines[lineNumber] = [0, endColumn];
|
|
1963
|
+
} else {
|
|
1964
|
+
const sourceLength = source[lineNumber - i].length;
|
|
1965
|
+
markerLines[lineNumber] = [0, sourceLength];
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
} else {
|
|
1969
|
+
if (startColumn === endColumn) {
|
|
1970
|
+
if (startColumn) {
|
|
1971
|
+
markerLines[startLine] = [startColumn, 0];
|
|
1972
|
+
} else {
|
|
1973
|
+
markerLines[startLine] = true;
|
|
1974
|
+
}
|
|
1975
|
+
} else {
|
|
1976
|
+
markerLines[startLine] = [startColumn, endColumn - startColumn];
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return {
|
|
1980
|
+
start,
|
|
1981
|
+
end,
|
|
1982
|
+
markerLines
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
function codeFrameColumns(rawLines, loc, opts = {}) {
|
|
1986
|
+
const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode;
|
|
1987
|
+
const defs = getDefs(shouldHighlight);
|
|
1988
|
+
const lines = rawLines.split(NEWLINE);
|
|
1989
|
+
const {
|
|
1990
|
+
start,
|
|
1991
|
+
end,
|
|
1992
|
+
markerLines
|
|
1993
|
+
} = getMarkerLines(loc, lines, opts);
|
|
1994
|
+
const hasColumns = loc.start && typeof loc.start.column === "number";
|
|
1995
|
+
const numberMaxWidth = String(end).length;
|
|
1996
|
+
const highlightedLines = shouldHighlight ? highlight(rawLines) : rawLines;
|
|
1997
|
+
let frame = highlightedLines.split(NEWLINE, end).slice(start, end).map((line, index) => {
|
|
1998
|
+
const number = start + 1 + index;
|
|
1999
|
+
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
|
|
2000
|
+
const gutter = ` ${paddedNumber} |`;
|
|
2001
|
+
const hasMarker = markerLines[number];
|
|
2002
|
+
const lastMarkerLine = !markerLines[number + 1];
|
|
2003
|
+
if (hasMarker) {
|
|
2004
|
+
let markerLine = "";
|
|
2005
|
+
if (Array.isArray(hasMarker)) {
|
|
2006
|
+
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
|
|
2007
|
+
const numberOfMarkers = hasMarker[1] || 1;
|
|
2008
|
+
markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join("");
|
|
2009
|
+
if (lastMarkerLine && opts.message) {
|
|
2010
|
+
markerLine += " " + defs.message(opts.message);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return [defs.marker(">"), defs.gutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
|
|
2014
|
+
} else {
|
|
2015
|
+
return ` ${defs.gutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
|
|
2016
|
+
}
|
|
2017
|
+
}).join("\n");
|
|
2018
|
+
if (opts.message && !hasColumns) {
|
|
2019
|
+
frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
|
|
2020
|
+
}
|
|
2021
|
+
if (shouldHighlight) {
|
|
2022
|
+
return defs.reset(frame);
|
|
2023
|
+
} else {
|
|
2024
|
+
return frame;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
function index(rawLines, lineNumber, colNumber, opts = {}) {
|
|
2028
|
+
if (!deprecationWarningShown) {
|
|
2029
|
+
deprecationWarningShown = true;
|
|
2030
|
+
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
|
|
2031
|
+
if (process.emitWarning) {
|
|
2032
|
+
process.emitWarning(message, "DeprecationWarning");
|
|
2033
|
+
} else {
|
|
2034
|
+
const deprecationError = new Error(message);
|
|
2035
|
+
deprecationError.name = "DeprecationWarning";
|
|
2036
|
+
console.warn(new Error(message));
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
colNumber = Math.max(colNumber, 0);
|
|
2040
|
+
const location = {
|
|
2041
|
+
start: {
|
|
2042
|
+
column: colNumber,
|
|
2043
|
+
line: lineNumber
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
2046
|
+
return codeFrameColumns(rawLines, location, opts);
|
|
2047
|
+
}
|
|
2048
|
+
lib$1.codeFrameColumns = codeFrameColumns;
|
|
2049
|
+
lib$1.default = index;
|
|
2050
|
+
lib$1.highlight = highlight;
|
|
2051
|
+
return lib$1;
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
var libExports = requireLib();
|
|
2055
|
+
|
|
2056
|
+
const NewLine = '\n';
|
|
2057
|
+
const splitLines = lines => {
|
|
2058
|
+
return lines.split(NewLine);
|
|
2059
|
+
};
|
|
2060
|
+
const RE_AT = /^\s+at/;
|
|
2061
|
+
const RE_AT_PROMISE_INDEX = /^\s*at async Promise.all \(index \d+\)$/;
|
|
2062
|
+
const RE_OBJECT_AS = /^\s*at (async )?Object\.\w+ \[as ([\w\.]+)\]/;
|
|
2063
|
+
const RE_GET_RESPONSE = /^\s*at async getResponse/;
|
|
2064
|
+
const RE_WEBSOCKET_HANDLE_MESSAGE = /^\s*at async WebSocket.handleMessage/;
|
|
2065
|
+
const RE_EXECUTE_COMMAND_ASYNC = /^\s*at executeCommandAsync/;
|
|
2066
|
+
const RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT = /^\s*at async MessagePort\.handleOtherMessagesFromMessagePort/;
|
|
2067
|
+
const RE_ASSERT = /^\s*at .*\/Assert\.js/;
|
|
2068
|
+
const isInternalLine = line => {
|
|
2069
|
+
return line.includes('node:') || RE_AT_PROMISE_INDEX.test(line) || line.includes('node_modules/ws');
|
|
2070
|
+
};
|
|
2071
|
+
const isRelevantLine = line => {
|
|
2072
|
+
return !isInternalLine(line);
|
|
2073
|
+
};
|
|
2074
|
+
const isApplicationUsefulLine = (line, index) => {
|
|
2075
|
+
if (index === 0) {
|
|
2076
|
+
if (RE_ASSERT.test(line)) {
|
|
2077
|
+
return false;
|
|
2078
|
+
}
|
|
2079
|
+
return true;
|
|
2080
|
+
}
|
|
2081
|
+
if (RE_GET_RESPONSE.test(line)) {
|
|
2082
|
+
return false;
|
|
2083
|
+
}
|
|
2084
|
+
if (RE_WEBSOCKET_HANDLE_MESSAGE.test(line)) {
|
|
2085
|
+
return false;
|
|
2086
|
+
}
|
|
2087
|
+
if (RE_EXECUTE_COMMAND_ASYNC.test(line)) {
|
|
2088
|
+
return false;
|
|
2089
|
+
}
|
|
2090
|
+
if (RE_HANDLE_OTHER_MESSAGES_FROM_MESSAGE_PORT.test(line)) {
|
|
2091
|
+
return false;
|
|
2092
|
+
}
|
|
2093
|
+
return true;
|
|
2094
|
+
};
|
|
2095
|
+
const isNormalStackLine = line => {
|
|
2096
|
+
return RE_AT.test(line) && !RE_AT_PROMISE_INDEX.test(line);
|
|
2097
|
+
};
|
|
2098
|
+
const cleanLine = line => {
|
|
2099
|
+
if (line.startsWith(' at exports.')) {
|
|
2100
|
+
return ' at ' + line.slice(' at exports.'.length);
|
|
2101
|
+
}
|
|
2102
|
+
if (line.startsWith(' at async exports.')) {
|
|
2103
|
+
return ' at async ' + line.slice(' at async exports.'.length);
|
|
2104
|
+
}
|
|
2105
|
+
if (line.startsWith(' at async Module.')) {
|
|
2106
|
+
return ' at async ' + line.slice(' at async Module.'.length);
|
|
2107
|
+
}
|
|
2108
|
+
if (line.startsWith(' at Module.')) {
|
|
2109
|
+
return ' at ' + line.slice(' at Module.'.length);
|
|
2110
|
+
}
|
|
2111
|
+
const objectMatch = line.match(RE_OBJECT_AS);
|
|
2112
|
+
if (objectMatch) {
|
|
2113
|
+
const rest = line.slice(objectMatch[0].length);
|
|
2114
|
+
if (objectMatch[1]) {
|
|
2115
|
+
return ' at ' + objectMatch[1] + objectMatch[2] + rest;
|
|
2116
|
+
}
|
|
2117
|
+
return ' at ' + objectMatch[2] + rest;
|
|
2118
|
+
}
|
|
2119
|
+
return line;
|
|
2120
|
+
};
|
|
2121
|
+
const getDetails = lines => {
|
|
2122
|
+
const index = lines.findIndex(isNormalStackLine);
|
|
2123
|
+
return {
|
|
2124
|
+
custom: lines.slice(0, index),
|
|
2125
|
+
actualStack: lines.slice(index).map(cleanLine)
|
|
2126
|
+
};
|
|
2127
|
+
};
|
|
2128
|
+
const RE_PATH_1 = /^\/(.*)(\d+)$/;
|
|
2129
|
+
const mergeCustom = (custom, relevantStack) => {
|
|
2130
|
+
if (custom.length === 0) {
|
|
2131
|
+
return relevantStack;
|
|
2132
|
+
}
|
|
2133
|
+
const firstLine = custom[0];
|
|
2134
|
+
if (RE_PATH_1.test(firstLine)) {
|
|
2135
|
+
return [` at ${firstLine}`, ...relevantStack];
|
|
2136
|
+
}
|
|
2137
|
+
return relevantStack;
|
|
2138
|
+
};
|
|
2139
|
+
const cleanStack = stack => {
|
|
2140
|
+
const lines = splitLines(stack);
|
|
2141
|
+
const {
|
|
2142
|
+
custom,
|
|
2143
|
+
actualStack
|
|
2144
|
+
} = getDetails(lines);
|
|
2145
|
+
const relevantStack = actualStack.filter(isRelevantLine).filter(isApplicationUsefulLine);
|
|
2146
|
+
const merged = mergeCustom(custom, relevantStack);
|
|
2147
|
+
return merged;
|
|
2148
|
+
};
|
|
2149
|
+
const Utf8 = 'utf8';
|
|
2150
|
+
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
2151
|
+
const getActualPath = fileUri => {
|
|
2152
|
+
if (fileUri.startsWith('file://')) {
|
|
2153
|
+
return fileURLToPath(fileUri);
|
|
2154
|
+
}
|
|
2155
|
+
return fileUri;
|
|
2156
|
+
};
|
|
2157
|
+
const joinLines = lines => {
|
|
2158
|
+
return lines.join(NewLine);
|
|
2159
|
+
};
|
|
2160
|
+
const warn = (...args) => {
|
|
2161
|
+
console.warn(...args);
|
|
2162
|
+
};
|
|
2163
|
+
const RE_MODULE_NOT_FOUND_STACK = /Cannot find package '([^']+)' imported from (.+)$/;
|
|
2164
|
+
const prepareModuleNotFoundError = error => {
|
|
2165
|
+
const {
|
|
2166
|
+
message
|
|
2167
|
+
} = error;
|
|
2168
|
+
const match = message.match(RE_MODULE_NOT_FOUND_STACK);
|
|
2169
|
+
if (!match) {
|
|
2170
|
+
return {
|
|
2171
|
+
message,
|
|
2172
|
+
stack: error.stack,
|
|
2173
|
+
codeFrame: ''
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
const notFoundModule = match[1];
|
|
2177
|
+
const importedFrom = match[2];
|
|
2178
|
+
const rawLines = readFileSync(importedFrom, Utf8);
|
|
2179
|
+
let line = 0;
|
|
2180
|
+
let column = 0;
|
|
2181
|
+
const splittedLines = splitLines(rawLines);
|
|
2182
|
+
for (let i = 0; i < splittedLines.length; i++) {
|
|
2183
|
+
const splittedLine = splittedLines[i];
|
|
2184
|
+
const index = splittedLine.indexOf(notFoundModule);
|
|
2185
|
+
if (index !== -1) {
|
|
2186
|
+
line = i + 1;
|
|
2187
|
+
column = index;
|
|
2188
|
+
break;
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
const location = {
|
|
2192
|
+
start: {
|
|
2193
|
+
line,
|
|
2194
|
+
column
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
const codeFrame = libExports.codeFrameColumns(rawLines, location);
|
|
2198
|
+
const stackLines = splitLines(error.stack);
|
|
2199
|
+
const newStackLines = [stackLines[0], ` at ${importedFrom}:${line}:${column}`, ...stackLines.slice(1)];
|
|
2200
|
+
const newStack = joinLines(newStackLines);
|
|
2201
|
+
return {
|
|
2202
|
+
message,
|
|
2203
|
+
stack: newStack,
|
|
2204
|
+
codeFrame
|
|
2205
|
+
};
|
|
2206
|
+
};
|
|
2207
|
+
const prepare = error => {
|
|
2208
|
+
try {
|
|
2209
|
+
if (error && error.code === ERR_MODULE_NOT_FOUND) {
|
|
2210
|
+
return prepareModuleNotFoundError(error);
|
|
2211
|
+
}
|
|
2212
|
+
const {
|
|
2213
|
+
message
|
|
2214
|
+
} = error;
|
|
2215
|
+
if (error && error.cause && typeof error.cause === 'function') {
|
|
2216
|
+
const cause = error.cause();
|
|
2217
|
+
if (cause) {
|
|
2218
|
+
error = cause;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
const lines = cleanStack(error.stack);
|
|
2222
|
+
const file = lines[0];
|
|
2223
|
+
let codeFrame = '';
|
|
2224
|
+
if (error.codeFrame) {
|
|
2225
|
+
codeFrame = error.codeFrame;
|
|
2226
|
+
} else if (file) {
|
|
2227
|
+
let match = file.match(/\((.*):(\d+):(\d+)\)$/);
|
|
2228
|
+
if (!match) {
|
|
2229
|
+
match = file.match(/at (.*):(\d+):(\d+)$/);
|
|
2230
|
+
}
|
|
2231
|
+
if (match) {
|
|
2232
|
+
const [_, path, line, column] = match;
|
|
2233
|
+
const actualPath = getActualPath(path);
|
|
2234
|
+
const rawLines = readFileSync(actualPath, Utf8);
|
|
2235
|
+
const location = {
|
|
2236
|
+
start: {
|
|
2237
|
+
line: Number.parseInt(line),
|
|
2238
|
+
column: Number.parseInt(column)
|
|
2239
|
+
}
|
|
2240
|
+
};
|
|
2241
|
+
codeFrame = libExports.codeFrameColumns(rawLines, location);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
const relevantStack = joinLines(lines);
|
|
2245
|
+
return {
|
|
2246
|
+
message,
|
|
2247
|
+
stack: relevantStack,
|
|
2248
|
+
codeFrame,
|
|
2249
|
+
type: error.constructor.name,
|
|
2250
|
+
code: error.code
|
|
2251
|
+
};
|
|
2252
|
+
} catch (otherError) {
|
|
2253
|
+
warn(`ErrorHandling Error: ${otherError}`);
|
|
2254
|
+
return error;
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
|
|
493
2258
|
const firstErrorLine = error => {
|
|
494
2259
|
if (error.stack) {
|
|
495
2260
|
return error.stack.slice(0, getNewLineIndex(error.stack));
|
|
@@ -507,7 +2272,7 @@ const handleUncaughtExceptionMonitor$1 = error$1 => {
|
|
|
507
2272
|
const prettyError = prepare(error$1);
|
|
508
2273
|
error(
|
|
509
2274
|
// @ts-ignore
|
|
510
|
-
prettyError.codeFrame + NewLine + prettyError.stack + NewLine);
|
|
2275
|
+
prettyError.codeFrame + NewLine$1 + prettyError.stack + NewLine$1);
|
|
511
2276
|
setExitCode(Error$1);
|
|
512
2277
|
};
|
|
513
2278
|
|
|
@@ -528,3 +2293,36 @@ const main = async () => {
|
|
|
528
2293
|
};
|
|
529
2294
|
|
|
530
2295
|
main();
|
|
2296
|
+
|
|
2297
|
+
const createWebSocketServer = async () => {
|
|
2298
|
+
const _ws = await import('ws');
|
|
2299
|
+
// workaround for jest or node bug
|
|
2300
|
+
const WebSocketServer = _ws.WebSocketServer ? _ws.WebSocketServer :
|
|
2301
|
+
// @ts-ignore
|
|
2302
|
+
_ws.default.WebSocketServer;
|
|
2303
|
+
const webSocketServer = new WebSocketServer({
|
|
2304
|
+
noServer: true
|
|
2305
|
+
|
|
2306
|
+
// TODO not sure if ws compress is working at all
|
|
2307
|
+
// perMessageDeflate: true
|
|
2308
|
+
});
|
|
2309
|
+
return webSocketServer;
|
|
2310
|
+
};
|
|
2311
|
+
const doSocketUpgrade = (webSocketServer, request, socket) => {
|
|
2312
|
+
const {
|
|
2313
|
+
promise,
|
|
2314
|
+
resolve
|
|
2315
|
+
} = Promise.withResolvers();
|
|
2316
|
+
webSocketServer.handleUpgrade(request, socket, Buffer.alloc(0), resolve);
|
|
2317
|
+
return promise;
|
|
2318
|
+
};
|
|
2319
|
+
const handleUpgrade = async (request, socket) => {
|
|
2320
|
+
const webSocketServer = await createWebSocketServer();
|
|
2321
|
+
const webSocket = await doSocketUpgrade(webSocketServer, request, socket);
|
|
2322
|
+
return webSocket;
|
|
2323
|
+
};
|
|
2324
|
+
|
|
2325
|
+
const index = {
|
|
2326
|
+
__proto__: null,
|
|
2327
|
+
handleUpgrade
|
|
2328
|
+
};
|