@lvce-editor/file-system-process 5.0.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/index.js +95 -110
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -747,6 +747,27 @@ const IpcChildWithWebSocket = {
|
|
|
747
747
|
wrap: wrap$9
|
|
748
748
|
};
|
|
749
749
|
|
|
750
|
+
class CommandNotFoundError extends Error {
|
|
751
|
+
constructor(command) {
|
|
752
|
+
super(`Command not found ${command}`);
|
|
753
|
+
this.name = 'CommandNotFoundError';
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
const commands = Object.create(null);
|
|
757
|
+
const register = commandMap => {
|
|
758
|
+
Object.assign(commands, commandMap);
|
|
759
|
+
};
|
|
760
|
+
const getCommand = key => {
|
|
761
|
+
return commands[key];
|
|
762
|
+
};
|
|
763
|
+
const execute = (command, ...args) => {
|
|
764
|
+
const fn = getCommand(command);
|
|
765
|
+
if (!fn) {
|
|
766
|
+
throw new CommandNotFoundError(command);
|
|
767
|
+
}
|
|
768
|
+
return fn(...args);
|
|
769
|
+
};
|
|
770
|
+
|
|
750
771
|
const Two$1 = '2.0';
|
|
751
772
|
const callbacks = Object.create(null);
|
|
752
773
|
const get$1 = id => {
|
|
@@ -771,12 +792,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
771
792
|
switch (type) {
|
|
772
793
|
case DomException:
|
|
773
794
|
return DOMException;
|
|
774
|
-
case TypeError$1:
|
|
775
|
-
return TypeError;
|
|
776
|
-
case SyntaxError$1:
|
|
777
|
-
return SyntaxError;
|
|
778
795
|
case ReferenceError$1:
|
|
779
796
|
return ReferenceError;
|
|
797
|
+
case SyntaxError$1:
|
|
798
|
+
return SyntaxError;
|
|
799
|
+
case TypeError$1:
|
|
800
|
+
return TypeError;
|
|
780
801
|
default:
|
|
781
802
|
return Error;
|
|
782
803
|
}
|
|
@@ -932,27 +953,27 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
932
953
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
933
954
|
return {
|
|
934
955
|
code: MethodNotFound,
|
|
935
|
-
|
|
936
|
-
|
|
956
|
+
data: error.stack,
|
|
957
|
+
message: error.message
|
|
937
958
|
};
|
|
938
959
|
}
|
|
939
960
|
return {
|
|
940
961
|
code: Custom,
|
|
941
|
-
message: prettyError.message,
|
|
942
962
|
data: {
|
|
943
|
-
stack: getStack(prettyError),
|
|
944
|
-
codeFrame: prettyError.codeFrame,
|
|
945
|
-
type: getErrorType(prettyError),
|
|
946
963
|
code: prettyError.code,
|
|
947
|
-
|
|
948
|
-
|
|
964
|
+
codeFrame: prettyError.codeFrame,
|
|
965
|
+
name: prettyError.name,
|
|
966
|
+
stack: getStack(prettyError),
|
|
967
|
+
type: getErrorType(prettyError)
|
|
968
|
+
},
|
|
969
|
+
message: prettyError.message
|
|
949
970
|
};
|
|
950
971
|
};
|
|
951
972
|
const create$1$1 = (id, error) => {
|
|
952
973
|
return {
|
|
953
|
-
|
|
974
|
+
error,
|
|
954
975
|
id,
|
|
955
|
-
|
|
976
|
+
jsonrpc: Two$1
|
|
956
977
|
};
|
|
957
978
|
};
|
|
958
979
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
@@ -961,27 +982,27 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
961
982
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
962
983
|
return create$1$1(id, errorProperty);
|
|
963
984
|
};
|
|
964
|
-
const create$
|
|
985
|
+
const create$c = (message, result) => {
|
|
965
986
|
return {
|
|
966
|
-
jsonrpc: Two$1,
|
|
967
987
|
id: message.id,
|
|
988
|
+
jsonrpc: Two$1,
|
|
968
989
|
result: result ?? null
|
|
969
990
|
};
|
|
970
991
|
};
|
|
971
992
|
const getSuccessResponse = (message, result) => {
|
|
972
993
|
const resultProperty = result ?? null;
|
|
973
|
-
return create$
|
|
994
|
+
return create$c(message, resultProperty);
|
|
974
995
|
};
|
|
975
996
|
const getErrorResponseSimple = (id, error) => {
|
|
976
997
|
return {
|
|
977
|
-
jsonrpc: Two$1,
|
|
978
|
-
id,
|
|
979
998
|
error: {
|
|
980
999
|
code: Custom,
|
|
1000
|
+
data: error,
|
|
981
1001
|
// @ts-ignore
|
|
982
|
-
message: error.message
|
|
983
|
-
|
|
984
|
-
|
|
1002
|
+
message: error.message
|
|
1003
|
+
},
|
|
1004
|
+
id,
|
|
1005
|
+
jsonrpc: Two$1
|
|
985
1006
|
};
|
|
986
1007
|
};
|
|
987
1008
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -1011,35 +1032,35 @@ const normalizeParams = args => {
|
|
|
1011
1032
|
if (args.length === 1) {
|
|
1012
1033
|
const options = args[0];
|
|
1013
1034
|
return {
|
|
1035
|
+
execute: options.execute,
|
|
1014
1036
|
ipc: options.ipc,
|
|
1037
|
+
logError: options.logError || defaultLogError,
|
|
1015
1038
|
message: options.message,
|
|
1016
|
-
execute: options.execute,
|
|
1017
|
-
resolve: options.resolve || defaultResolve,
|
|
1018
1039
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
1019
|
-
|
|
1020
|
-
|
|
1040
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
1041
|
+
resolve: options.resolve || defaultResolve
|
|
1021
1042
|
};
|
|
1022
1043
|
}
|
|
1023
1044
|
return {
|
|
1045
|
+
execute: args[2],
|
|
1024
1046
|
ipc: args[0],
|
|
1047
|
+
logError: args[5],
|
|
1025
1048
|
message: args[1],
|
|
1026
|
-
execute: args[2],
|
|
1027
|
-
resolve: args[3],
|
|
1028
1049
|
preparePrettyError: args[4],
|
|
1029
|
-
|
|
1030
|
-
|
|
1050
|
+
requiresSocket: args[6],
|
|
1051
|
+
resolve: args[3]
|
|
1031
1052
|
};
|
|
1032
1053
|
};
|
|
1033
1054
|
const handleJsonRpcMessage = async (...args) => {
|
|
1034
1055
|
const options = normalizeParams(args);
|
|
1035
1056
|
const {
|
|
1036
|
-
message,
|
|
1037
|
-
ipc,
|
|
1038
1057
|
execute,
|
|
1039
|
-
|
|
1040
|
-
preparePrettyError,
|
|
1058
|
+
ipc,
|
|
1041
1059
|
logError,
|
|
1042
|
-
|
|
1060
|
+
message,
|
|
1061
|
+
preparePrettyError,
|
|
1062
|
+
requiresSocket,
|
|
1063
|
+
resolve
|
|
1043
1064
|
} = options;
|
|
1044
1065
|
if ('id' in message) {
|
|
1045
1066
|
if ('method' in message) {
|
|
@@ -1062,36 +1083,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1062
1083
|
throw new JsonRpcError('unexpected message');
|
|
1063
1084
|
};
|
|
1064
1085
|
|
|
1065
|
-
class CommandNotFoundError extends Error {
|
|
1066
|
-
constructor(command) {
|
|
1067
|
-
super(`Command not found ${command}`);
|
|
1068
|
-
this.name = 'CommandNotFoundError';
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
const commands = Object.create(null);
|
|
1072
|
-
const register = commandMap => {
|
|
1073
|
-
Object.assign(commands, commandMap);
|
|
1074
|
-
};
|
|
1075
|
-
const getCommand = key => {
|
|
1076
|
-
return commands[key];
|
|
1077
|
-
};
|
|
1078
|
-
const execute = (command, ...args) => {
|
|
1079
|
-
const fn = getCommand(command);
|
|
1080
|
-
if (!fn) {
|
|
1081
|
-
throw new CommandNotFoundError(command);
|
|
1082
|
-
}
|
|
1083
|
-
return fn(...args);
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
1086
|
const Two = '2.0';
|
|
1087
|
-
|
|
1087
|
+
|
|
1088
|
+
const create$b = (method, params) => {
|
|
1088
1089
|
return {
|
|
1089
1090
|
jsonrpc: Two,
|
|
1090
1091
|
method,
|
|
1091
1092
|
params
|
|
1092
1093
|
};
|
|
1093
1094
|
};
|
|
1094
|
-
|
|
1095
|
+
|
|
1096
|
+
const create$a = (id, method, params) => {
|
|
1095
1097
|
const message = {
|
|
1096
1098
|
id,
|
|
1097
1099
|
jsonrpc: Two,
|
|
@@ -1100,15 +1102,14 @@ const create$r = (id, method, params) => {
|
|
|
1100
1102
|
};
|
|
1101
1103
|
return message;
|
|
1102
1104
|
};
|
|
1105
|
+
|
|
1103
1106
|
let id = 0;
|
|
1104
|
-
const create$
|
|
1107
|
+
const create$9 = () => {
|
|
1105
1108
|
return ++id;
|
|
1106
1109
|
};
|
|
1107
1110
|
|
|
1108
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
1109
|
-
|
|
1110
1111
|
const registerPromise = map => {
|
|
1111
|
-
const id = create$
|
|
1112
|
+
const id = create$9();
|
|
1112
1113
|
const {
|
|
1113
1114
|
promise,
|
|
1114
1115
|
resolve
|
|
@@ -1120,13 +1121,12 @@ const registerPromise = map => {
|
|
|
1120
1121
|
};
|
|
1121
1122
|
};
|
|
1122
1123
|
|
|
1123
|
-
// @ts-ignore
|
|
1124
1124
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
1125
1125
|
const {
|
|
1126
1126
|
id,
|
|
1127
1127
|
promise
|
|
1128
1128
|
} = registerPromise(callbacks);
|
|
1129
|
-
const message = create$
|
|
1129
|
+
const message = create$a(id, method, params);
|
|
1130
1130
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1131
1131
|
ipc.sendAndTransfer(message);
|
|
1132
1132
|
} else {
|
|
@@ -1162,12 +1162,13 @@ const createRpc = ipc => {
|
|
|
1162
1162
|
* @deprecated
|
|
1163
1163
|
*/
|
|
1164
1164
|
send(method, ...params) {
|
|
1165
|
-
const message = create$
|
|
1165
|
+
const message = create$b(method, params);
|
|
1166
1166
|
ipc.send(message);
|
|
1167
1167
|
}
|
|
1168
1168
|
};
|
|
1169
1169
|
return rpc;
|
|
1170
1170
|
};
|
|
1171
|
+
|
|
1171
1172
|
const requiresSocket$1 = () => {
|
|
1172
1173
|
return false;
|
|
1173
1174
|
};
|
|
@@ -1182,6 +1183,7 @@ const handleMessage = event => {
|
|
|
1182
1183
|
const actualExecute = event?.target?.execute || execute;
|
|
1183
1184
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1184
1185
|
};
|
|
1186
|
+
|
|
1185
1187
|
const handleIpc = ipc => {
|
|
1186
1188
|
if ('addEventListener' in ipc) {
|
|
1187
1189
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -1190,6 +1192,7 @@ const handleIpc = ipc => {
|
|
|
1190
1192
|
ipc.on('message', handleMessage);
|
|
1191
1193
|
}
|
|
1192
1194
|
};
|
|
1195
|
+
|
|
1193
1196
|
const listen$1 = async (module, options) => {
|
|
1194
1197
|
const rawIpc = await module.listen(options);
|
|
1195
1198
|
if (module.signal) {
|
|
@@ -1198,7 +1201,8 @@ const listen$1 = async (module, options) => {
|
|
|
1198
1201
|
const ipc = module.wrap(rawIpc);
|
|
1199
1202
|
return ipc;
|
|
1200
1203
|
};
|
|
1201
|
-
|
|
1204
|
+
|
|
1205
|
+
const create$8 = async ({
|
|
1202
1206
|
commandMap,
|
|
1203
1207
|
messagePort,
|
|
1204
1208
|
requiresSocket
|
|
@@ -1215,11 +1219,8 @@ const create$p = async ({
|
|
|
1215
1219
|
const rpc = createRpc(ipc);
|
|
1216
1220
|
return rpc;
|
|
1217
1221
|
};
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
create: create$p
|
|
1221
|
-
};
|
|
1222
|
-
const create$o = async ({
|
|
1222
|
+
|
|
1223
|
+
const create$7 = async ({
|
|
1223
1224
|
commandMap
|
|
1224
1225
|
}) => {
|
|
1225
1226
|
// TODO create a commandMap per rpc instance
|
|
@@ -1229,12 +1230,6 @@ const create$o = async ({
|
|
|
1229
1230
|
const rpc = createRpc(ipc);
|
|
1230
1231
|
return rpc;
|
|
1231
1232
|
};
|
|
1232
|
-
const ElectronUtilityProcessRpcClient = {
|
|
1233
|
-
__proto__: null,
|
|
1234
|
-
create: create$o
|
|
1235
|
-
};
|
|
1236
|
-
|
|
1237
|
-
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
1238
1233
|
|
|
1239
1234
|
const createSharedLazyRpc = factory => {
|
|
1240
1235
|
let rpcPromise;
|
|
@@ -1263,7 +1258,8 @@ const createSharedLazyRpc = factory => {
|
|
|
1263
1258
|
}
|
|
1264
1259
|
};
|
|
1265
1260
|
};
|
|
1266
|
-
|
|
1261
|
+
|
|
1262
|
+
const create$6 = async ({
|
|
1267
1263
|
commandMap,
|
|
1268
1264
|
getPortTuple,
|
|
1269
1265
|
send
|
|
@@ -1273,30 +1269,28 @@ const create$k = async ({
|
|
|
1273
1269
|
port2
|
|
1274
1270
|
} = await getPortTuple();
|
|
1275
1271
|
await send(port1);
|
|
1276
|
-
const rpc = create$
|
|
1272
|
+
const rpc = create$8({
|
|
1277
1273
|
commandMap,
|
|
1278
1274
|
messagePort: port2
|
|
1279
1275
|
});
|
|
1280
1276
|
return rpc;
|
|
1281
1277
|
};
|
|
1282
|
-
|
|
1278
|
+
|
|
1279
|
+
const create$5 = async ({
|
|
1283
1280
|
commandMap,
|
|
1284
1281
|
getPortTuple,
|
|
1285
1282
|
send
|
|
1286
1283
|
}) => {
|
|
1287
1284
|
return createSharedLazyRpc(() => {
|
|
1288
|
-
return create$
|
|
1285
|
+
return create$6({
|
|
1289
1286
|
commandMap,
|
|
1290
1287
|
getPortTuple,
|
|
1291
1288
|
send
|
|
1292
1289
|
});
|
|
1293
1290
|
});
|
|
1294
1291
|
};
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
create: create$j
|
|
1298
|
-
};
|
|
1299
|
-
const create$9 = async ({
|
|
1292
|
+
|
|
1293
|
+
const create$4 = async ({
|
|
1300
1294
|
commandMap
|
|
1301
1295
|
}) => {
|
|
1302
1296
|
// TODO create a commandMap per rpc instance
|
|
@@ -1306,11 +1300,8 @@ const create$9 = async ({
|
|
|
1306
1300
|
const rpc = createRpc(ipc);
|
|
1307
1301
|
return rpc;
|
|
1308
1302
|
};
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
create: create$9
|
|
1312
|
-
};
|
|
1313
|
-
const create$7 = async ({
|
|
1303
|
+
|
|
1304
|
+
const create$3 = async ({
|
|
1314
1305
|
commandMap,
|
|
1315
1306
|
handle,
|
|
1316
1307
|
request,
|
|
@@ -1329,11 +1320,8 @@ const create$7 = async ({
|
|
|
1329
1320
|
const rpc = createRpc(ipc);
|
|
1330
1321
|
return rpc;
|
|
1331
1322
|
};
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
create: create$7
|
|
1335
|
-
};
|
|
1336
|
-
const create$6 = async ({
|
|
1323
|
+
|
|
1324
|
+
const create$2 = async ({
|
|
1337
1325
|
commandMap
|
|
1338
1326
|
}) => {
|
|
1339
1327
|
// TODO create a commandMap per rpc instance
|
|
@@ -1343,10 +1331,7 @@ const create$6 = async ({
|
|
|
1343
1331
|
const rpc = createRpc(ipc);
|
|
1344
1332
|
return rpc;
|
|
1345
1333
|
};
|
|
1346
|
-
|
|
1347
|
-
__proto__: null,
|
|
1348
|
-
create: create$6
|
|
1349
|
-
};
|
|
1334
|
+
|
|
1350
1335
|
const createMockRpc = ({
|
|
1351
1336
|
commandMap
|
|
1352
1337
|
}) => {
|
|
@@ -1367,10 +1352,6 @@ const createMockRpc = ({
|
|
|
1367
1352
|
return mockRpc;
|
|
1368
1353
|
};
|
|
1369
1354
|
|
|
1370
|
-
const FileSystemProcess = 210;
|
|
1371
|
-
const MainProcess = -5;
|
|
1372
|
-
const SharedProcess = 1492;
|
|
1373
|
-
|
|
1374
1355
|
const rpcs = Object.create(null);
|
|
1375
1356
|
const set$2 = (id, rpc) => {
|
|
1376
1357
|
rpcs[id] = rpc;
|
|
@@ -1419,6 +1400,10 @@ const create$1 = rpcId => {
|
|
|
1419
1400
|
};
|
|
1420
1401
|
};
|
|
1421
1402
|
|
|
1403
|
+
const FileSystemProcess = 210;
|
|
1404
|
+
const MainProcess = -5;
|
|
1405
|
+
const SharedProcess = 1492;
|
|
1406
|
+
|
|
1422
1407
|
const {
|
|
1423
1408
|
invoke: invoke$1,
|
|
1424
1409
|
set: set$1
|
|
@@ -1472,7 +1457,7 @@ const getPortTuple = async () => {
|
|
|
1472
1457
|
};
|
|
1473
1458
|
|
|
1474
1459
|
const initializeMainProcessRpc = async () => {
|
|
1475
|
-
const rpc = await
|
|
1460
|
+
const rpc = await create$5({
|
|
1476
1461
|
commandMap: {},
|
|
1477
1462
|
getPortTuple,
|
|
1478
1463
|
async send(port) {
|
|
@@ -1855,7 +1840,7 @@ const unwatchFile = uri => {
|
|
|
1855
1840
|
|
|
1856
1841
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
1857
1842
|
object(messagePort);
|
|
1858
|
-
const rpc = await
|
|
1843
|
+
const rpc = await create$8({
|
|
1859
1844
|
commandMap: {},
|
|
1860
1845
|
messagePort,
|
|
1861
1846
|
requiresSocket: false
|
|
@@ -1871,7 +1856,7 @@ const requiresSocket = method => {
|
|
|
1871
1856
|
const handleWebSocket = async (handle, request) => {
|
|
1872
1857
|
object(handle);
|
|
1873
1858
|
object(request);
|
|
1874
|
-
await
|
|
1859
|
+
await create$3({
|
|
1875
1860
|
commandMap: {},
|
|
1876
1861
|
handle,
|
|
1877
1862
|
request,
|
|
@@ -1909,17 +1894,17 @@ const commandMap = {
|
|
|
1909
1894
|
|
|
1910
1895
|
const getRpc = argv => {
|
|
1911
1896
|
if (argv.includes('--ipc-type=node-worker')) {
|
|
1912
|
-
return
|
|
1897
|
+
return create$2({
|
|
1913
1898
|
commandMap: commandMap
|
|
1914
1899
|
});
|
|
1915
1900
|
}
|
|
1916
1901
|
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1917
|
-
return
|
|
1902
|
+
return create$4({
|
|
1918
1903
|
commandMap: commandMap
|
|
1919
1904
|
});
|
|
1920
1905
|
}
|
|
1921
1906
|
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1922
|
-
return
|
|
1907
|
+
return create$7({
|
|
1923
1908
|
commandMap: commandMap
|
|
1924
1909
|
});
|
|
1925
1910
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-system-process",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "File System Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"file-system-process": "bin/fileSystemProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"trash": "^10.1.
|
|
22
|
-
"ws": "^8.
|
|
21
|
+
"trash": "^10.1.1",
|
|
22
|
+
"ws": "^8.21.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=24"
|