@lvce-editor/file-system-process 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +349 -346
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -6,72 +6,6 @@ import { join } from 'node:path';
|
|
|
6
6
|
import _trash from 'trash';
|
|
7
7
|
import { Buffer } from 'node:buffer';
|
|
8
8
|
|
|
9
|
-
class AssertionError extends Error {
|
|
10
|
-
constructor(message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.name = 'AssertionError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const Object$1 = 1;
|
|
16
|
-
const Number = 2;
|
|
17
|
-
const Array$1 = 3;
|
|
18
|
-
const String = 4;
|
|
19
|
-
const Boolean$1 = 5;
|
|
20
|
-
const Function = 6;
|
|
21
|
-
const Null = 7;
|
|
22
|
-
const Unknown$1 = 8;
|
|
23
|
-
const getType = value => {
|
|
24
|
-
switch (typeof value) {
|
|
25
|
-
case 'number':
|
|
26
|
-
return Number;
|
|
27
|
-
case 'function':
|
|
28
|
-
return Function;
|
|
29
|
-
case 'string':
|
|
30
|
-
return String;
|
|
31
|
-
case 'object':
|
|
32
|
-
if (value === null) {
|
|
33
|
-
return Null;
|
|
34
|
-
}
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
return Array$1;
|
|
37
|
-
}
|
|
38
|
-
return Object$1;
|
|
39
|
-
case 'boolean':
|
|
40
|
-
return Boolean$1;
|
|
41
|
-
default:
|
|
42
|
-
return Unknown$1;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const object = value => {
|
|
46
|
-
const type = getType(value);
|
|
47
|
-
if (type !== Object$1) {
|
|
48
|
-
throw new AssertionError('expected value to be of type object');
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const number = value => {
|
|
52
|
-
const type = getType(value);
|
|
53
|
-
if (type !== Number) {
|
|
54
|
-
throw new AssertionError('expected value to be of type number');
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const string = value => {
|
|
58
|
-
const type = getType(value);
|
|
59
|
-
if (type !== String) {
|
|
60
|
-
throw new AssertionError('expected value to be of type string');
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const assertUri = uri => {
|
|
65
|
-
if (!uri.startsWith('file://')) {
|
|
66
|
-
throw new Error(`path must be a valid file uri`);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const Utf8 = 'utf8';
|
|
71
|
-
|
|
72
|
-
const ENOENT = 'ENOENT';
|
|
73
|
-
const EXDEV = 'EXDEV';
|
|
74
|
-
|
|
75
9
|
const normalizeLine = line => {
|
|
76
10
|
if (line.startsWith('Error: ')) {
|
|
77
11
|
return line.slice('Error: '.length);
|
|
@@ -128,128 +62,59 @@ class VError extends Error {
|
|
|
128
62
|
}
|
|
129
63
|
}
|
|
130
64
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return path;
|
|
136
|
-
};
|
|
137
|
-
class FileNotFoundError extends VError {
|
|
138
|
-
constructor(path) {
|
|
139
|
-
super(`File not found: '${getDisplayPath(path)}'`);
|
|
140
|
-
this.code = ENOENT;
|
|
65
|
+
class AssertionError extends Error {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = 'AssertionError';
|
|
141
69
|
}
|
|
142
70
|
}
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (dirent.isSocket()) {
|
|
164
|
-
return Socket;
|
|
165
|
-
}
|
|
166
|
-
if (dirent.isBlockDevice()) {
|
|
167
|
-
return BlockDevice;
|
|
168
|
-
}
|
|
169
|
-
if (dirent.isCharacterDevice()) {
|
|
170
|
-
return CharacterDevice;
|
|
171
|
-
}
|
|
172
|
-
if (dirent.isFIFO()) {
|
|
173
|
-
return Fifo;
|
|
174
|
-
}
|
|
175
|
-
return Unknown;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const getFolderSizeInternal = async path => {
|
|
179
|
-
if (path === '/') {
|
|
180
|
-
throw new Error('Invalid path for folder size');
|
|
181
|
-
}
|
|
182
|
-
let total = 0;
|
|
183
|
-
try {
|
|
184
|
-
const stats = await fs.stat(path);
|
|
185
|
-
total += stats.size;
|
|
186
|
-
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
187
|
-
const dirents = await fs.readdir(path);
|
|
188
|
-
for (const dirent of dirents) {
|
|
189
|
-
total += await getFolderSizeInternal(join(path, dirent));
|
|
71
|
+
const Object$1 = 1;
|
|
72
|
+
const Number = 2;
|
|
73
|
+
const Array$1 = 3;
|
|
74
|
+
const String = 4;
|
|
75
|
+
const Boolean$1 = 5;
|
|
76
|
+
const Function = 6;
|
|
77
|
+
const Null = 7;
|
|
78
|
+
const Unknown$1 = 8;
|
|
79
|
+
const getType = value => {
|
|
80
|
+
switch (typeof value) {
|
|
81
|
+
case 'number':
|
|
82
|
+
return Number;
|
|
83
|
+
case 'function':
|
|
84
|
+
return Function;
|
|
85
|
+
case 'string':
|
|
86
|
+
return String;
|
|
87
|
+
case 'object':
|
|
88
|
+
if (value === null) {
|
|
89
|
+
return Null;
|
|
190
90
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
return Array$1;
|
|
93
|
+
}
|
|
94
|
+
return Object$1;
|
|
95
|
+
case 'boolean':
|
|
96
|
+
return Boolean$1;
|
|
97
|
+
default:
|
|
98
|
+
return Unknown$1;
|
|
194
99
|
}
|
|
195
|
-
return total;
|
|
196
100
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return false;
|
|
101
|
+
const object = value => {
|
|
102
|
+
const type = getType(value);
|
|
103
|
+
if (type !== Object$1) {
|
|
104
|
+
throw new AssertionError('expected value to be of type object');
|
|
202
105
|
}
|
|
203
|
-
return error.message.includes('The system cannot find the path specified.');
|
|
204
106
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// @ts-ignore
|
|
212
|
-
const isEnoentError = error => {
|
|
213
|
-
if (!error) {
|
|
214
|
-
return false;
|
|
107
|
+
const number = value => {
|
|
108
|
+
const type = getType(value);
|
|
109
|
+
if (type !== Number) {
|
|
110
|
+
throw new AssertionError('expected value to be of type number');
|
|
215
111
|
}
|
|
216
|
-
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const FileSystemProcess = 210;
|
|
220
|
-
const MainProcess = -5;
|
|
221
|
-
const SharedProcess$1 = 1492;
|
|
222
|
-
|
|
223
|
-
const rpcs = Object.create(null);
|
|
224
|
-
const set$1 = (id, rpc) => {
|
|
225
|
-
rpcs[id] = rpc;
|
|
226
|
-
};
|
|
227
|
-
const get$1 = id => {
|
|
228
|
-
return rpcs[id];
|
|
229
112
|
};
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
await rpc.dispose();
|
|
236
|
-
},
|
|
237
|
-
// @ts-ignore
|
|
238
|
-
invoke(method, ...params) {
|
|
239
|
-
const rpc = get$1(rpcId);
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
return rpc.invoke(method, ...params);
|
|
242
|
-
},
|
|
243
|
-
// @ts-ignore
|
|
244
|
-
invokeAndTransfer(method, ...params) {
|
|
245
|
-
const rpc = get$1(rpcId);
|
|
246
|
-
// @ts-ignore
|
|
247
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
248
|
-
},
|
|
249
|
-
set(rpc) {
|
|
250
|
-
set$1(rpcId, rpc);
|
|
251
|
-
}
|
|
252
|
-
};
|
|
113
|
+
const string = value => {
|
|
114
|
+
const type = getType(value);
|
|
115
|
+
if (type !== String) {
|
|
116
|
+
throw new AssertionError('expected value to be of type string');
|
|
117
|
+
}
|
|
253
118
|
};
|
|
254
119
|
|
|
255
120
|
const isMessagePort = value => {
|
|
@@ -884,10 +749,10 @@ const IpcChildWithWebSocket = {
|
|
|
884
749
|
|
|
885
750
|
const Two$1 = '2.0';
|
|
886
751
|
const callbacks = Object.create(null);
|
|
887
|
-
const get = id => {
|
|
752
|
+
const get$1 = id => {
|
|
888
753
|
return callbacks[id];
|
|
889
754
|
};
|
|
890
|
-
const remove$
|
|
755
|
+
const remove$2 = id => {
|
|
891
756
|
delete callbacks[id];
|
|
892
757
|
};
|
|
893
758
|
class JsonRpcError extends Error {
|
|
@@ -1033,14 +898,14 @@ const warn = (...args) => {
|
|
|
1033
898
|
console.warn(...args);
|
|
1034
899
|
};
|
|
1035
900
|
const resolve = (id, response) => {
|
|
1036
|
-
const fn = get(id);
|
|
901
|
+
const fn = get$1(id);
|
|
1037
902
|
if (!fn) {
|
|
1038
903
|
console.log(response);
|
|
1039
904
|
warn(`callback ${id} may already be disposed`);
|
|
1040
905
|
return;
|
|
1041
906
|
}
|
|
1042
907
|
fn(response);
|
|
1043
|
-
remove$
|
|
908
|
+
remove$2(id);
|
|
1044
909
|
};
|
|
1045
910
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
1046
911
|
const getErrorType = prettyError => {
|
|
@@ -1083,7 +948,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1083
948
|
}
|
|
1084
949
|
};
|
|
1085
950
|
};
|
|
1086
|
-
const create$1 = (id, error) => {
|
|
951
|
+
const create$1$1 = (id, error) => {
|
|
1087
952
|
return {
|
|
1088
953
|
jsonrpc: Two$1,
|
|
1089
954
|
id,
|
|
@@ -1094,7 +959,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
1094
959
|
const prettyError = preparePrettyError(error);
|
|
1095
960
|
logError(error, prettyError);
|
|
1096
961
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1097
|
-
return create$1(id, errorProperty);
|
|
962
|
+
return create$1$1(id, errorProperty);
|
|
1098
963
|
};
|
|
1099
964
|
const create$2 = (message, result) => {
|
|
1100
965
|
return {
|
|
@@ -1325,7 +1190,7 @@ const handleIpc = ipc => {
|
|
|
1325
1190
|
ipc.on('message', handleMessage);
|
|
1326
1191
|
}
|
|
1327
1192
|
};
|
|
1328
|
-
const listen$
|
|
1193
|
+
const listen$1 = async (module, options) => {
|
|
1329
1194
|
const rawIpc = await module.listen(options);
|
|
1330
1195
|
if (module.signal) {
|
|
1331
1196
|
module.signal(rawIpc);
|
|
@@ -1340,7 +1205,7 @@ const create$p = async ({
|
|
|
1340
1205
|
}) => {
|
|
1341
1206
|
// TODO create a commandMap per rpc instance
|
|
1342
1207
|
register(commandMap);
|
|
1343
|
-
const ipc = await listen$
|
|
1208
|
+
const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
|
|
1344
1209
|
messagePort
|
|
1345
1210
|
});
|
|
1346
1211
|
if (requiresSocket) {
|
|
@@ -1359,7 +1224,7 @@ const create$o = async ({
|
|
|
1359
1224
|
}) => {
|
|
1360
1225
|
// TODO create a commandMap per rpc instance
|
|
1361
1226
|
register(commandMap);
|
|
1362
|
-
const ipc = await listen$
|
|
1227
|
+
const ipc = await listen$1(IpcChildWithElectronUtilityProcess$1);
|
|
1363
1228
|
handleIpc(ipc);
|
|
1364
1229
|
const rpc = createRpc(ipc);
|
|
1365
1230
|
return rpc;
|
|
@@ -1368,6 +1233,36 @@ const ElectronUtilityProcessRpcClient = {
|
|
|
1368
1233
|
__proto__: null,
|
|
1369
1234
|
create: create$o
|
|
1370
1235
|
};
|
|
1236
|
+
|
|
1237
|
+
/* eslint-disable @typescript-eslint/no-misused-promises */
|
|
1238
|
+
|
|
1239
|
+
const createSharedLazyRpc = factory => {
|
|
1240
|
+
let rpcPromise;
|
|
1241
|
+
const getOrCreate = () => {
|
|
1242
|
+
if (!rpcPromise) {
|
|
1243
|
+
rpcPromise = factory();
|
|
1244
|
+
}
|
|
1245
|
+
return rpcPromise;
|
|
1246
|
+
};
|
|
1247
|
+
return {
|
|
1248
|
+
async dispose() {
|
|
1249
|
+
const rpc = await getOrCreate();
|
|
1250
|
+
await rpc.dispose();
|
|
1251
|
+
},
|
|
1252
|
+
async invoke(method, ...params) {
|
|
1253
|
+
const rpc = await getOrCreate();
|
|
1254
|
+
return rpc.invoke(method, ...params);
|
|
1255
|
+
},
|
|
1256
|
+
async invokeAndTransfer(method, ...params) {
|
|
1257
|
+
const rpc = await getOrCreate();
|
|
1258
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1259
|
+
},
|
|
1260
|
+
async send(method, ...params) {
|
|
1261
|
+
const rpc = await getOrCreate();
|
|
1262
|
+
rpc.send(method, ...params);
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
};
|
|
1371
1266
|
const create$k = async ({
|
|
1372
1267
|
commandMap,
|
|
1373
1268
|
getPortTuple,
|
|
@@ -1384,16 +1279,29 @@ const create$k = async ({
|
|
|
1384
1279
|
});
|
|
1385
1280
|
return rpc;
|
|
1386
1281
|
};
|
|
1387
|
-
const
|
|
1282
|
+
const create$j = async ({
|
|
1283
|
+
commandMap,
|
|
1284
|
+
getPortTuple,
|
|
1285
|
+
send
|
|
1286
|
+
}) => {
|
|
1287
|
+
return createSharedLazyRpc(() => {
|
|
1288
|
+
return create$k({
|
|
1289
|
+
commandMap,
|
|
1290
|
+
getPortTuple,
|
|
1291
|
+
send
|
|
1292
|
+
});
|
|
1293
|
+
});
|
|
1294
|
+
};
|
|
1295
|
+
const LazyTransferElectronMessagePortRpc = {
|
|
1388
1296
|
__proto__: null,
|
|
1389
|
-
create: create$
|
|
1297
|
+
create: create$j
|
|
1390
1298
|
};
|
|
1391
1299
|
const create$9 = async ({
|
|
1392
1300
|
commandMap
|
|
1393
1301
|
}) => {
|
|
1394
1302
|
// TODO create a commandMap per rpc instance
|
|
1395
1303
|
register(commandMap);
|
|
1396
|
-
const ipc = await listen$
|
|
1304
|
+
const ipc = await listen$1(IpcChildWithNodeForkedProcess$1);
|
|
1397
1305
|
handleIpc(ipc);
|
|
1398
1306
|
const rpc = createRpc(ipc);
|
|
1399
1307
|
return rpc;
|
|
@@ -1410,7 +1318,7 @@ const create$7 = async ({
|
|
|
1410
1318
|
}) => {
|
|
1411
1319
|
// TODO create a commandMap per rpc instance
|
|
1412
1320
|
register(commandMap);
|
|
1413
|
-
const ipc = await listen$
|
|
1321
|
+
const ipc = await listen$1(IpcChildWithWebSocket, {
|
|
1414
1322
|
handle,
|
|
1415
1323
|
request
|
|
1416
1324
|
});
|
|
@@ -1430,7 +1338,7 @@ const create$6 = async ({
|
|
|
1430
1338
|
}) => {
|
|
1431
1339
|
// TODO create a commandMap per rpc instance
|
|
1432
1340
|
register(commandMap);
|
|
1433
|
-
const ipc = await listen$
|
|
1341
|
+
const ipc = await listen$1(IpcChildWithNodeWorker$1);
|
|
1434
1342
|
handleIpc(ipc);
|
|
1435
1343
|
const rpc = createRpc(ipc);
|
|
1436
1344
|
return rpc;
|
|
@@ -1439,62 +1347,240 @@ const NodeWorkerRpcClient = {
|
|
|
1439
1347
|
__proto__: null,
|
|
1440
1348
|
create: create$6
|
|
1441
1349
|
};
|
|
1350
|
+
const createMockRpc = ({
|
|
1351
|
+
commandMap
|
|
1352
|
+
}) => {
|
|
1353
|
+
const invocations = [];
|
|
1354
|
+
const invoke = (method, ...params) => {
|
|
1355
|
+
invocations.push([method, ...params]);
|
|
1356
|
+
const command = commandMap[method];
|
|
1357
|
+
if (!command) {
|
|
1358
|
+
throw new Error(`command ${method} not found`);
|
|
1359
|
+
}
|
|
1360
|
+
return command(...params);
|
|
1361
|
+
};
|
|
1362
|
+
const mockRpc = {
|
|
1363
|
+
invocations,
|
|
1364
|
+
invoke,
|
|
1365
|
+
invokeAndTransfer: invoke
|
|
1366
|
+
};
|
|
1367
|
+
return mockRpc;
|
|
1368
|
+
};
|
|
1442
1369
|
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
invokeAndTransfer: invokeAndTransfer$1,
|
|
1447
|
-
set
|
|
1448
|
-
} = create$3(SharedProcess$1);
|
|
1370
|
+
const FileSystemProcess = 210;
|
|
1371
|
+
const MainProcess = -5;
|
|
1372
|
+
const SharedProcess = 1492;
|
|
1449
1373
|
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1374
|
+
const rpcs = Object.create(null);
|
|
1375
|
+
const set$2 = (id, rpc) => {
|
|
1376
|
+
rpcs[id] = rpc;
|
|
1377
|
+
};
|
|
1378
|
+
const get = id => {
|
|
1379
|
+
return rpcs[id];
|
|
1380
|
+
};
|
|
1381
|
+
const remove$1 = id => {
|
|
1382
|
+
delete rpcs[id];
|
|
1456
1383
|
};
|
|
1457
1384
|
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
let factory;
|
|
1461
|
-
const createRpc = async () => {
|
|
1462
|
-
const rpc = await factory();
|
|
1463
|
-
set$1(rpcId, rpc);
|
|
1464
|
-
};
|
|
1465
|
-
const ensureRpc = async () => {
|
|
1466
|
-
if (!rpcPromise) {
|
|
1467
|
-
rpcPromise = createRpc();
|
|
1468
|
-
}
|
|
1469
|
-
await rpcPromise;
|
|
1470
|
-
};
|
|
1385
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1386
|
+
const create$1 = rpcId => {
|
|
1471
1387
|
return {
|
|
1472
|
-
async
|
|
1473
|
-
|
|
1474
|
-
|
|
1388
|
+
async dispose() {
|
|
1389
|
+
const rpc = get(rpcId);
|
|
1390
|
+
await rpc.dispose();
|
|
1391
|
+
},
|
|
1392
|
+
// @ts-ignore
|
|
1393
|
+
invoke(method, ...params) {
|
|
1394
|
+
const rpc = get(rpcId);
|
|
1395
|
+
// @ts-ignore
|
|
1475
1396
|
return rpc.invoke(method, ...params);
|
|
1476
1397
|
},
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
const rpc = get
|
|
1398
|
+
// @ts-ignore
|
|
1399
|
+
invokeAndTransfer(method, ...params) {
|
|
1400
|
+
const rpc = get(rpcId);
|
|
1401
|
+
// @ts-ignore
|
|
1480
1402
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1481
1403
|
},
|
|
1482
|
-
|
|
1483
|
-
|
|
1404
|
+
registerMockRpc(commandMap) {
|
|
1405
|
+
const mockRpc = createMockRpc({
|
|
1406
|
+
commandMap
|
|
1407
|
+
});
|
|
1408
|
+
set$2(rpcId, mockRpc);
|
|
1409
|
+
// @ts-ignore
|
|
1410
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1411
|
+
remove$1(rpcId);
|
|
1412
|
+
};
|
|
1413
|
+
// @ts-ignore
|
|
1414
|
+
return mockRpc;
|
|
1415
|
+
},
|
|
1416
|
+
set(rpc) {
|
|
1417
|
+
set$2(rpcId, rpc);
|
|
1484
1418
|
}
|
|
1485
1419
|
};
|
|
1486
1420
|
};
|
|
1487
1421
|
|
|
1488
1422
|
const {
|
|
1489
1423
|
invoke: invoke$1,
|
|
1490
|
-
|
|
1491
|
-
} =
|
|
1424
|
+
set: set$1
|
|
1425
|
+
} = create$1(MainProcess);
|
|
1426
|
+
|
|
1427
|
+
const {
|
|
1428
|
+
invoke,
|
|
1429
|
+
invokeAndTransfer,
|
|
1430
|
+
set
|
|
1431
|
+
} = create$1(SharedProcess);
|
|
1432
|
+
|
|
1433
|
+
const state = {
|
|
1434
|
+
id: 0
|
|
1435
|
+
};
|
|
1436
|
+
const create = () => {
|
|
1437
|
+
return ++state.id;
|
|
1438
|
+
};
|
|
1439
|
+
|
|
1440
|
+
const ports = Object.create(null);
|
|
1441
|
+
const getPortTuple$1 = async () => {
|
|
1442
|
+
const id1 = create();
|
|
1443
|
+
const id2 = create();
|
|
1444
|
+
await invoke('TemporaryMessagePort.getPortTuple3', id1, id2, FileSystemProcess);
|
|
1445
|
+
const port1 = ports[id1];
|
|
1446
|
+
const port2 = ports[id2];
|
|
1447
|
+
delete ports[id1];
|
|
1448
|
+
delete ports[id2];
|
|
1449
|
+
return {
|
|
1450
|
+
port1,
|
|
1451
|
+
port2
|
|
1452
|
+
};
|
|
1453
|
+
};
|
|
1454
|
+
const handlePorts = (port1, port2, id1, id2) => {
|
|
1455
|
+
number(id1);
|
|
1456
|
+
number(id2);
|
|
1457
|
+
object(port1);
|
|
1458
|
+
object(port2);
|
|
1459
|
+
ports[id1] = port1;
|
|
1460
|
+
ports[id2] = port2;
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
const getPortTuple = async () => {
|
|
1464
|
+
const {
|
|
1465
|
+
port1,
|
|
1466
|
+
port2
|
|
1467
|
+
} = await getPortTuple$1();
|
|
1468
|
+
return {
|
|
1469
|
+
port1,
|
|
1470
|
+
port2
|
|
1471
|
+
};
|
|
1472
|
+
};
|
|
1473
|
+
|
|
1474
|
+
const initializeMainProcessRpc = async () => {
|
|
1475
|
+
const rpc = await LazyTransferElectronMessagePortRpc.create({
|
|
1476
|
+
commandMap: {},
|
|
1477
|
+
getPortTuple,
|
|
1478
|
+
async send(port) {
|
|
1479
|
+
await invokeAndTransfer('TemporaryMessagePort.sendToElectron', port, MainProcess, FileSystemProcess);
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
set$1(rpc);
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
const assertUri = uri => {
|
|
1486
|
+
if (!uri.startsWith('file://')) {
|
|
1487
|
+
throw new Error(`path must be a valid file uri`);
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
const Utf8 = 'utf8';
|
|
1492
|
+
|
|
1493
|
+
const ENOENT = 'ENOENT';
|
|
1494
|
+
const EXDEV = 'EXDEV';
|
|
1495
|
+
|
|
1496
|
+
const getDisplayPath = path => {
|
|
1497
|
+
if (path === '') {
|
|
1498
|
+
return '<empty string>';
|
|
1499
|
+
}
|
|
1500
|
+
return path;
|
|
1501
|
+
};
|
|
1502
|
+
class FileNotFoundError extends VError {
|
|
1503
|
+
constructor(path) {
|
|
1504
|
+
super(`File not found: '${getDisplayPath(path)}'`);
|
|
1505
|
+
this.code = ENOENT;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
const BlockDevice = 1;
|
|
1510
|
+
const CharacterDevice = 2;
|
|
1511
|
+
const Directory = 3;
|
|
1512
|
+
const Fifo = 6;
|
|
1513
|
+
const File = 7;
|
|
1514
|
+
const Socket = 8;
|
|
1515
|
+
const Symlink = 9;
|
|
1516
|
+
const Unknown = 12;
|
|
1517
|
+
|
|
1518
|
+
const getDirentType = dirent => {
|
|
1519
|
+
if (dirent.isFile()) {
|
|
1520
|
+
return File;
|
|
1521
|
+
}
|
|
1522
|
+
if (dirent.isDirectory()) {
|
|
1523
|
+
return Directory;
|
|
1524
|
+
}
|
|
1525
|
+
if (dirent.isSymbolicLink()) {
|
|
1526
|
+
return Symlink;
|
|
1527
|
+
}
|
|
1528
|
+
if (dirent.isSocket()) {
|
|
1529
|
+
return Socket;
|
|
1530
|
+
}
|
|
1531
|
+
if (dirent.isBlockDevice()) {
|
|
1532
|
+
return BlockDevice;
|
|
1533
|
+
}
|
|
1534
|
+
if (dirent.isCharacterDevice()) {
|
|
1535
|
+
return CharacterDevice;
|
|
1536
|
+
}
|
|
1537
|
+
if (dirent.isFIFO()) {
|
|
1538
|
+
return Fifo;
|
|
1539
|
+
}
|
|
1540
|
+
return Unknown;
|
|
1541
|
+
};
|
|
1542
|
+
|
|
1543
|
+
const getFolderSizeInternal = async path => {
|
|
1544
|
+
if (path === '/') {
|
|
1545
|
+
throw new Error('Invalid path for folder size');
|
|
1546
|
+
}
|
|
1547
|
+
let total = 0;
|
|
1548
|
+
try {
|
|
1549
|
+
const stats = await fs.stat(path);
|
|
1550
|
+
total += stats.size;
|
|
1551
|
+
if (stats.isDirectory() && !stats.isSymbolicLink()) {
|
|
1552
|
+
const dirents = await fs.readdir(path);
|
|
1553
|
+
for (const dirent of dirents) {
|
|
1554
|
+
total += await getFolderSizeInternal(join(path, dirent));
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
} catch {
|
|
1558
|
+
return 0;
|
|
1559
|
+
}
|
|
1560
|
+
return total;
|
|
1561
|
+
};
|
|
1562
|
+
|
|
1563
|
+
const isEnoentErrorWindows = error => {
|
|
1564
|
+
if (!error || !error.message) {
|
|
1565
|
+
return false;
|
|
1566
|
+
}
|
|
1567
|
+
return error.message.includes('The system cannot find the path specified.');
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
const isEnoentErrorLinux = error => {
|
|
1571
|
+
return Boolean(error && error.code === ENOENT);
|
|
1572
|
+
};
|
|
1573
|
+
const isEnoentError = error => {
|
|
1574
|
+
if (!error) {
|
|
1575
|
+
return false;
|
|
1576
|
+
}
|
|
1577
|
+
return isEnoentErrorLinux(error) || isEnoentErrorWindows(error);
|
|
1578
|
+
};
|
|
1492
1579
|
|
|
1493
1580
|
const trash$2 = async path => {
|
|
1494
1581
|
if (!existsSync(path)) {
|
|
1495
1582
|
return;
|
|
1496
1583
|
}
|
|
1497
|
-
// @ts-ignore
|
|
1498
1584
|
await invoke$1('Trash.trash', path);
|
|
1499
1585
|
};
|
|
1500
1586
|
|
|
@@ -1517,6 +1603,8 @@ const getElectronRunAsNode = () => {
|
|
|
1517
1603
|
const isElectron = Boolean(getElectronRunAsNode()) || 'electron' in process.versions;
|
|
1518
1604
|
|
|
1519
1605
|
const trash = async path => {
|
|
1606
|
+
// TODO pass iselectron as parameter
|
|
1607
|
+
// TODO only accept file uris
|
|
1520
1608
|
if (!path || path.trim() === '') {
|
|
1521
1609
|
throw new Error('Path cannot be empty');
|
|
1522
1610
|
}
|
|
@@ -1765,58 +1853,15 @@ const unwatchFile = uri => {
|
|
|
1765
1853
|
// TODO
|
|
1766
1854
|
};
|
|
1767
1855
|
|
|
1768
|
-
const NodeWorker = 1;
|
|
1769
|
-
const NodeForkedProcess = 2;
|
|
1770
|
-
const ElectronUtilityProcess = 3;
|
|
1771
|
-
const ElectronMessagePort = 4;
|
|
1772
|
-
const WebSocket = 6;
|
|
1773
|
-
const Auto = argv => {
|
|
1774
|
-
if (argv.includes('--ipc-type=node-worker')) {
|
|
1775
|
-
return NodeWorker;
|
|
1776
|
-
}
|
|
1777
|
-
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1778
|
-
return NodeForkedProcess;
|
|
1779
|
-
}
|
|
1780
|
-
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1781
|
-
return ElectronUtilityProcess;
|
|
1782
|
-
}
|
|
1783
|
-
throw new Error(`[file-system-process] unknown ipc type`);
|
|
1784
|
-
};
|
|
1785
|
-
|
|
1786
|
-
const getModule = method => {
|
|
1787
|
-
switch (method) {
|
|
1788
|
-
case ElectronMessagePort:
|
|
1789
|
-
return ElectronMessagePortRpcClient.create;
|
|
1790
|
-
case ElectronUtilityProcess:
|
|
1791
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1792
|
-
case NodeForkedProcess:
|
|
1793
|
-
return NodeForkedProcessRpcClient.create;
|
|
1794
|
-
case NodeWorker:
|
|
1795
|
-
return NodeWorkerRpcClient.create;
|
|
1796
|
-
case WebSocket:
|
|
1797
|
-
return NodeWebSocketRpcClient.create;
|
|
1798
|
-
default:
|
|
1799
|
-
throw new Error('unexpected ipc type');
|
|
1800
|
-
}
|
|
1801
|
-
};
|
|
1802
|
-
|
|
1803
|
-
const listen$1 = async ({
|
|
1804
|
-
method,
|
|
1805
|
-
...params
|
|
1806
|
-
}) => {
|
|
1807
|
-
const create = getModule(method);
|
|
1808
|
-
const rpc = await create(params);
|
|
1809
|
-
return rpc;
|
|
1810
|
-
};
|
|
1811
|
-
|
|
1812
1856
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
1813
1857
|
object(messagePort);
|
|
1814
|
-
const rpc = await
|
|
1858
|
+
const rpc = await ElectronMessagePortRpcClient.create({
|
|
1859
|
+
commandMap: {},
|
|
1815
1860
|
messagePort,
|
|
1816
|
-
|
|
1861
|
+
requiresSocket: false
|
|
1817
1862
|
});
|
|
1818
1863
|
if (rpcId) {
|
|
1819
|
-
set$
|
|
1864
|
+
set$2(rpcId, rpc);
|
|
1820
1865
|
}
|
|
1821
1866
|
};
|
|
1822
1867
|
|
|
@@ -1826,79 +1871,16 @@ const requiresSocket = method => {
|
|
|
1826
1871
|
const handleWebSocket = async (handle, request) => {
|
|
1827
1872
|
object(handle);
|
|
1828
1873
|
object(request);
|
|
1829
|
-
await
|
|
1874
|
+
await NodeWebSocketRpcClient.create({
|
|
1875
|
+
commandMap: {},
|
|
1830
1876
|
handle,
|
|
1831
|
-
method: WebSocket,
|
|
1832
1877
|
request,
|
|
1833
1878
|
requiresSocket
|
|
1834
1879
|
});
|
|
1835
1880
|
};
|
|
1836
1881
|
|
|
1837
|
-
const state = {
|
|
1838
|
-
id: 0
|
|
1839
|
-
};
|
|
1840
|
-
const create = () => {
|
|
1841
|
-
return ++state.id;
|
|
1842
|
-
};
|
|
1843
|
-
|
|
1844
|
-
const {
|
|
1845
|
-
invoke,
|
|
1846
|
-
invokeAndTransfer} = SharedProcess;
|
|
1847
|
-
|
|
1848
|
-
const ports = Object.create(null);
|
|
1849
|
-
const getPortTuple$1 = async () => {
|
|
1850
|
-
const id1 = create();
|
|
1851
|
-
const id2 = create();
|
|
1852
|
-
// @ts-ignore
|
|
1853
|
-
await invoke('TemporaryMessagePort.getPortTuple3', id1, id2, FileSystemProcess);
|
|
1854
|
-
const port1 = ports[id1];
|
|
1855
|
-
const port2 = ports[id2];
|
|
1856
|
-
delete ports[id1];
|
|
1857
|
-
delete ports[id2];
|
|
1858
|
-
return {
|
|
1859
|
-
port1,
|
|
1860
|
-
port2
|
|
1861
|
-
};
|
|
1862
|
-
};
|
|
1863
|
-
const handlePorts = (port1, port2, id1, id2) => {
|
|
1864
|
-
number(id1);
|
|
1865
|
-
number(id2);
|
|
1866
|
-
object(port1);
|
|
1867
|
-
object(port2);
|
|
1868
|
-
ports[id1] = port1;
|
|
1869
|
-
ports[id2] = port2;
|
|
1870
|
-
};
|
|
1871
|
-
|
|
1872
|
-
const getPortTuple = async () => {
|
|
1873
|
-
const {
|
|
1874
|
-
port1,
|
|
1875
|
-
port2
|
|
1876
|
-
} = await getPortTuple$1();
|
|
1877
|
-
return {
|
|
1878
|
-
port1,
|
|
1879
|
-
port2
|
|
1880
|
-
};
|
|
1881
|
-
};
|
|
1882
|
-
|
|
1883
|
-
const createMainProcessRpc = async () => {
|
|
1884
|
-
try {
|
|
1885
|
-
const rpc = TransferElectronMessagePortRpc.create({
|
|
1886
|
-
commandMap: {},
|
|
1887
|
-
getPortTuple,
|
|
1888
|
-
async send(port) {
|
|
1889
|
-
await invokeAndTransfer(
|
|
1890
|
-
// @ts-ignore
|
|
1891
|
-
'TemporaryMessagePort.sendToElectron', port, MainProcess, FileSystemProcess);
|
|
1892
|
-
}
|
|
1893
|
-
});
|
|
1894
|
-
return rpc;
|
|
1895
|
-
} catch (error) {
|
|
1896
|
-
throw new VError(error, `Failed to create main process rpc`);
|
|
1897
|
-
}
|
|
1898
|
-
};
|
|
1899
|
-
|
|
1900
1882
|
const initialize = async () => {
|
|
1901
|
-
|
|
1883
|
+
// TODO this function is not needed anymore
|
|
1902
1884
|
};
|
|
1903
1885
|
|
|
1904
1886
|
const commandMap = {
|
|
@@ -1925,11 +1907,32 @@ const commandMap = {
|
|
|
1925
1907
|
'TemporaryMessagePort.handlePorts': handlePorts
|
|
1926
1908
|
};
|
|
1927
1909
|
|
|
1910
|
+
const getRpc = argv => {
|
|
1911
|
+
if (argv.includes('--ipc-type=node-worker')) {
|
|
1912
|
+
return NodeWorkerRpcClient.create({
|
|
1913
|
+
commandMap: commandMap
|
|
1914
|
+
});
|
|
1915
|
+
}
|
|
1916
|
+
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1917
|
+
return NodeForkedProcessRpcClient.create({
|
|
1918
|
+
commandMap: commandMap
|
|
1919
|
+
});
|
|
1920
|
+
}
|
|
1921
|
+
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1922
|
+
return ElectronUtilityProcessRpcClient.create({
|
|
1923
|
+
commandMap: commandMap
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
throw new Error(`[file-system-process] unknown ipc type`);
|
|
1927
|
+
};
|
|
1928
|
+
const initializeParentProcessRpc = async argv => {
|
|
1929
|
+
const rpc = await getRpc(argv);
|
|
1930
|
+
// TODO we don't know at this point if we have been launched by shared process or electron main process
|
|
1931
|
+
set(rpc);
|
|
1932
|
+
};
|
|
1933
|
+
|
|
1928
1934
|
const listen = async argv => {
|
|
1929
|
-
await
|
|
1930
|
-
commandMap: commandMap,
|
|
1931
|
-
method: Auto(argv)
|
|
1932
|
-
});
|
|
1935
|
+
await Promise.all([initializeParentProcessRpc(argv), initializeMainProcessRpc()]);
|
|
1933
1936
|
};
|
|
1934
1937
|
|
|
1935
1938
|
const main = async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/file-system-process",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "File System Process",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lvce Editor",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"file-system-process": "bin/fileSystemProcess.js"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"trash": "^10.0
|
|
21
|
+
"trash": "^10.1.0",
|
|
22
22
|
"ws": "^8.19.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
25
|
+
"node": ">=24"
|
|
26
26
|
}
|
|
27
27
|
}
|