@lvce-editor/file-system-process 2.1.0 → 2.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/index.js +58 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -194,7 +194,7 @@ const isEnoentError = error => {
|
|
|
194
194
|
};
|
|
195
195
|
|
|
196
196
|
const rpcs = Object.create(null);
|
|
197
|
-
const set$
|
|
197
|
+
const set$f = (id, rpc) => {
|
|
198
198
|
rpcs[id] = rpc;
|
|
199
199
|
};
|
|
200
200
|
const get$1 = id => {
|
|
@@ -218,19 +218,22 @@ const create$6 = rpcId => {
|
|
|
218
218
|
return rpc.invokeAndTransfer(method, ...params);
|
|
219
219
|
},
|
|
220
220
|
set(rpc) {
|
|
221
|
-
set$
|
|
221
|
+
set$f(rpcId, rpc);
|
|
222
|
+
},
|
|
223
|
+
async dispose() {
|
|
224
|
+
const rpc = get$1(rpcId);
|
|
225
|
+
await rpc.dispose();
|
|
222
226
|
}
|
|
223
227
|
};
|
|
224
228
|
};
|
|
225
229
|
const MainProcess$1 = -5;
|
|
226
230
|
const {
|
|
227
|
-
invoke: invoke$
|
|
228
|
-
set: set$
|
|
229
|
-
} = create$6(MainProcess$1);
|
|
231
|
+
invoke: invoke$6,
|
|
232
|
+
set: set$6} = create$6(MainProcess$1);
|
|
230
233
|
const MainProcess = {
|
|
231
234
|
__proto__: null,
|
|
232
|
-
invoke: invoke$
|
|
233
|
-
set: set$
|
|
235
|
+
invoke: invoke$6,
|
|
236
|
+
set: set$6
|
|
234
237
|
};
|
|
235
238
|
|
|
236
239
|
const {
|
|
@@ -865,7 +868,7 @@ const listen$3 = async () => {
|
|
|
865
868
|
parentPort
|
|
866
869
|
} = await import('node:worker_threads');
|
|
867
870
|
if (!parentPort) {
|
|
868
|
-
throw new IpcError('parentPort is required');
|
|
871
|
+
throw new IpcError('parentPort is required for node worker threads ipc');
|
|
869
872
|
}
|
|
870
873
|
return parentPort;
|
|
871
874
|
};
|
|
@@ -1000,8 +1003,6 @@ const handleUpgrade$1 = async (...args) => {
|
|
|
1000
1003
|
// @ts-ignore
|
|
1001
1004
|
return module.handleUpgrade(...args);
|
|
1002
1005
|
};
|
|
1003
|
-
|
|
1004
|
-
// @ts-ignore
|
|
1005
1006
|
const listen$1$1 = async ({
|
|
1006
1007
|
request,
|
|
1007
1008
|
handle
|
|
@@ -1022,8 +1023,6 @@ const listen$1$1 = async ({
|
|
|
1022
1023
|
const signal$4 = webSocket => {
|
|
1023
1024
|
webSocket.resume();
|
|
1024
1025
|
};
|
|
1025
|
-
|
|
1026
|
-
// @ts-ignore
|
|
1027
1026
|
const wrap$9 = webSocket => {
|
|
1028
1027
|
return {
|
|
1029
1028
|
webSocket,
|
|
@@ -1178,6 +1177,16 @@ const constructError = (message, type, name) => {
|
|
|
1178
1177
|
}
|
|
1179
1178
|
return new ErrorConstructor(message);
|
|
1180
1179
|
};
|
|
1180
|
+
const joinLines = lines => {
|
|
1181
|
+
return lines.join(NewLine);
|
|
1182
|
+
};
|
|
1183
|
+
const splitLines = lines => {
|
|
1184
|
+
return lines.split(NewLine);
|
|
1185
|
+
};
|
|
1186
|
+
const getCurrentStack = () => {
|
|
1187
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
|
|
1188
|
+
return currentStack;
|
|
1189
|
+
};
|
|
1181
1190
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
1182
1191
|
return string.indexOf(NewLine, startIndex);
|
|
1183
1192
|
};
|
|
@@ -1188,19 +1197,16 @@ const getParentStack = error => {
|
|
|
1188
1197
|
}
|
|
1189
1198
|
return parentStack;
|
|
1190
1199
|
};
|
|
1191
|
-
const joinLines = lines => {
|
|
1192
|
-
return lines.join(NewLine);
|
|
1193
|
-
};
|
|
1194
1200
|
const MethodNotFound = -32601;
|
|
1195
1201
|
const Custom = -32001;
|
|
1196
|
-
const splitLines = lines => {
|
|
1197
|
-
return lines.split(NewLine);
|
|
1198
|
-
};
|
|
1199
1202
|
const restoreJsonRpcError = error => {
|
|
1203
|
+
const currentStack = getCurrentStack();
|
|
1200
1204
|
if (error && error instanceof Error) {
|
|
1205
|
+
if (typeof error.stack === 'string') {
|
|
1206
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
1207
|
+
}
|
|
1201
1208
|
return error;
|
|
1202
1209
|
}
|
|
1203
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
1204
1210
|
if (error && error.code && error.code === MethodNotFound) {
|
|
1205
1211
|
const restoredError = new JsonRpcError(error.message);
|
|
1206
1212
|
const parentStack = getParentStack(error);
|
|
@@ -1281,6 +1287,17 @@ const getErrorType = prettyError => {
|
|
|
1281
1287
|
}
|
|
1282
1288
|
return undefined;
|
|
1283
1289
|
};
|
|
1290
|
+
const isAlreadyStack = line => {
|
|
1291
|
+
return line.trim().startsWith('at ');
|
|
1292
|
+
};
|
|
1293
|
+
const getStack = prettyError => {
|
|
1294
|
+
const stackString = prettyError.stack || '';
|
|
1295
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
1296
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
1297
|
+
return stackString.slice(newLineIndex + 1);
|
|
1298
|
+
}
|
|
1299
|
+
return stackString;
|
|
1300
|
+
};
|
|
1284
1301
|
const getErrorProperty = (error, prettyError) => {
|
|
1285
1302
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
1286
1303
|
return {
|
|
@@ -1293,7 +1310,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1293
1310
|
code: Custom,
|
|
1294
1311
|
message: prettyError.message,
|
|
1295
1312
|
data: {
|
|
1296
|
-
stack: prettyError
|
|
1313
|
+
stack: getStack(prettyError),
|
|
1297
1314
|
codeFrame: prettyError.codeFrame,
|
|
1298
1315
|
type: getErrorType(prettyError),
|
|
1299
1316
|
code: prettyError.code,
|
|
@@ -1301,18 +1318,18 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1301
1318
|
}
|
|
1302
1319
|
};
|
|
1303
1320
|
};
|
|
1304
|
-
const create$1 = (
|
|
1321
|
+
const create$1 = (id, error) => {
|
|
1305
1322
|
return {
|
|
1306
1323
|
jsonrpc: Two,
|
|
1307
|
-
id
|
|
1324
|
+
id,
|
|
1308
1325
|
error
|
|
1309
1326
|
};
|
|
1310
1327
|
};
|
|
1311
|
-
const getErrorResponse = (
|
|
1328
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
1312
1329
|
const prettyError = preparePrettyError(error);
|
|
1313
1330
|
logError(error, prettyError);
|
|
1314
1331
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1315
|
-
return create$1(
|
|
1332
|
+
return create$1(id, errorProperty);
|
|
1316
1333
|
};
|
|
1317
1334
|
const create = (message, result) => {
|
|
1318
1335
|
return {
|
|
@@ -1325,12 +1342,27 @@ const getSuccessResponse = (message, result) => {
|
|
|
1325
1342
|
const resultProperty = result ?? null;
|
|
1326
1343
|
return create(message, resultProperty);
|
|
1327
1344
|
};
|
|
1345
|
+
const getErrorResponseSimple = (id, error) => {
|
|
1346
|
+
return {
|
|
1347
|
+
jsonrpc: Two,
|
|
1348
|
+
id,
|
|
1349
|
+
error: {
|
|
1350
|
+
code: Custom,
|
|
1351
|
+
// @ts-ignore
|
|
1352
|
+
message: error.message,
|
|
1353
|
+
data: error
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
};
|
|
1328
1357
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
1329
1358
|
try {
|
|
1330
1359
|
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
1331
1360
|
return getSuccessResponse(message, result);
|
|
1332
1361
|
} catch (error) {
|
|
1333
|
-
|
|
1362
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
1363
|
+
return getErrorResponseSimple(message.id, error);
|
|
1364
|
+
}
|
|
1365
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1334
1366
|
}
|
|
1335
1367
|
};
|
|
1336
1368
|
const defaultPreparePrettyError = error => {
|
|
@@ -1385,7 +1417,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1385
1417
|
try {
|
|
1386
1418
|
ipc.send(response);
|
|
1387
1419
|
} catch (error) {
|
|
1388
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
1420
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
1389
1421
|
ipc.send(errorResponse);
|
|
1390
1422
|
}
|
|
1391
1423
|
return;
|