@lvce-editor/file-system-process 4.1.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 +311 -316
- 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
|
-
};
|
|
205
|
-
|
|
206
|
-
// @ts-ignore
|
|
207
|
-
const isEnoentErrorLinux = error => {
|
|
208
|
-
return Boolean(error && error.code === ENOENT);
|
|
209
106
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
112
|
};
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const rpcs = Object.create(null);
|
|
224
|
-
const set$2 = (id, rpc) => {
|
|
225
|
-
rpcs[id] = rpc;
|
|
226
|
-
};
|
|
227
|
-
const get$1 = id => {
|
|
228
|
-
return rpcs[id];
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const create$3 = rpcId => {
|
|
232
|
-
return {
|
|
233
|
-
async dispose() {
|
|
234
|
-
const rpc = get$1(rpcId);
|
|
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$2(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;
|
|
@@ -1436,7 +1301,7 @@ const create$9 = async ({
|
|
|
1436
1301
|
}) => {
|
|
1437
1302
|
// TODO create a commandMap per rpc instance
|
|
1438
1303
|
register(commandMap);
|
|
1439
|
-
const ipc = await listen$
|
|
1304
|
+
const ipc = await listen$1(IpcChildWithNodeForkedProcess$1);
|
|
1440
1305
|
handleIpc(ipc);
|
|
1441
1306
|
const rpc = createRpc(ipc);
|
|
1442
1307
|
return rpc;
|
|
@@ -1453,7 +1318,7 @@ const create$7 = async ({
|
|
|
1453
1318
|
}) => {
|
|
1454
1319
|
// TODO create a commandMap per rpc instance
|
|
1455
1320
|
register(commandMap);
|
|
1456
|
-
const ipc = await listen$
|
|
1321
|
+
const ipc = await listen$1(IpcChildWithWebSocket, {
|
|
1457
1322
|
handle,
|
|
1458
1323
|
request
|
|
1459
1324
|
});
|
|
@@ -1473,7 +1338,7 @@ const create$6 = async ({
|
|
|
1473
1338
|
}) => {
|
|
1474
1339
|
// TODO create a commandMap per rpc instance
|
|
1475
1340
|
register(commandMap);
|
|
1476
|
-
const ipc = await listen$
|
|
1341
|
+
const ipc = await listen$1(IpcChildWithNodeWorker$1);
|
|
1477
1342
|
handleIpc(ipc);
|
|
1478
1343
|
const rpc = createRpc(ipc);
|
|
1479
1344
|
return rpc;
|
|
@@ -1482,32 +1347,241 @@ const NodeWorkerRpcClient = {
|
|
|
1482
1347
|
__proto__: null,
|
|
1483
1348
|
create: create$6
|
|
1484
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
|
+
};
|
|
1369
|
+
|
|
1370
|
+
const FileSystemProcess = 210;
|
|
1371
|
+
const MainProcess = -5;
|
|
1372
|
+
const SharedProcess = 1492;
|
|
1373
|
+
|
|
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];
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1386
|
+
const create$1 = rpcId => {
|
|
1387
|
+
return {
|
|
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
|
|
1396
|
+
return rpc.invoke(method, ...params);
|
|
1397
|
+
},
|
|
1398
|
+
// @ts-ignore
|
|
1399
|
+
invokeAndTransfer(method, ...params) {
|
|
1400
|
+
const rpc = get(rpcId);
|
|
1401
|
+
// @ts-ignore
|
|
1402
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1403
|
+
},
|
|
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);
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
};
|
|
1485
1421
|
|
|
1486
1422
|
const {
|
|
1487
|
-
invoke: invoke$
|
|
1423
|
+
invoke: invoke$1,
|
|
1488
1424
|
set: set$1
|
|
1489
|
-
} = create$
|
|
1425
|
+
} = create$1(MainProcess);
|
|
1490
1426
|
|
|
1491
1427
|
const {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
invokeAndTransfer: invokeAndTransfer$1,
|
|
1428
|
+
invoke,
|
|
1429
|
+
invokeAndTransfer,
|
|
1495
1430
|
set
|
|
1496
|
-
} = create$
|
|
1431
|
+
} = create$1(SharedProcess);
|
|
1497
1432
|
|
|
1498
|
-
const
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
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);
|
|
1504
1578
|
};
|
|
1505
1579
|
|
|
1506
1580
|
const trash$2 = async path => {
|
|
1507
1581
|
if (!existsSync(path)) {
|
|
1508
1582
|
return;
|
|
1509
1583
|
}
|
|
1510
|
-
await invoke$
|
|
1584
|
+
await invoke$1('Trash.trash', path);
|
|
1511
1585
|
};
|
|
1512
1586
|
|
|
1513
1587
|
// @ts-ignore
|
|
@@ -1529,6 +1603,8 @@ const getElectronRunAsNode = () => {
|
|
|
1529
1603
|
const isElectron = Boolean(getElectronRunAsNode()) || 'electron' in process.versions;
|
|
1530
1604
|
|
|
1531
1605
|
const trash = async path => {
|
|
1606
|
+
// TODO pass iselectron as parameter
|
|
1607
|
+
// TODO only accept file uris
|
|
1532
1608
|
if (!path || path.trim() === '') {
|
|
1533
1609
|
throw new Error('Path cannot be empty');
|
|
1534
1610
|
}
|
|
@@ -1777,55 +1853,12 @@ const unwatchFile = uri => {
|
|
|
1777
1853
|
// TODO
|
|
1778
1854
|
};
|
|
1779
1855
|
|
|
1780
|
-
const NodeWorker = 1;
|
|
1781
|
-
const NodeForkedProcess = 2;
|
|
1782
|
-
const ElectronUtilityProcess = 3;
|
|
1783
|
-
const ElectronMessagePort = 4;
|
|
1784
|
-
const WebSocket = 6;
|
|
1785
|
-
const Auto = argv => {
|
|
1786
|
-
if (argv.includes('--ipc-type=node-worker')) {
|
|
1787
|
-
return NodeWorker;
|
|
1788
|
-
}
|
|
1789
|
-
if (argv.includes('--ipc-type=node-forked-process')) {
|
|
1790
|
-
return NodeForkedProcess;
|
|
1791
|
-
}
|
|
1792
|
-
if (argv.includes('--ipc-type=electron-utility-process')) {
|
|
1793
|
-
return ElectronUtilityProcess;
|
|
1794
|
-
}
|
|
1795
|
-
throw new Error(`[file-system-process] unknown ipc type`);
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
const getModule = method => {
|
|
1799
|
-
switch (method) {
|
|
1800
|
-
case ElectronMessagePort:
|
|
1801
|
-
return ElectronMessagePortRpcClient.create;
|
|
1802
|
-
case ElectronUtilityProcess:
|
|
1803
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1804
|
-
case NodeForkedProcess:
|
|
1805
|
-
return NodeForkedProcessRpcClient.create;
|
|
1806
|
-
case NodeWorker:
|
|
1807
|
-
return NodeWorkerRpcClient.create;
|
|
1808
|
-
case WebSocket:
|
|
1809
|
-
return NodeWebSocketRpcClient.create;
|
|
1810
|
-
default:
|
|
1811
|
-
throw new Error('unexpected ipc type');
|
|
1812
|
-
}
|
|
1813
|
-
};
|
|
1814
|
-
|
|
1815
|
-
const listen$1 = async ({
|
|
1816
|
-
method,
|
|
1817
|
-
...params
|
|
1818
|
-
}) => {
|
|
1819
|
-
const create = getModule(method);
|
|
1820
|
-
const rpc = await create(params);
|
|
1821
|
-
return rpc;
|
|
1822
|
-
};
|
|
1823
|
-
|
|
1824
1856
|
const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
1825
1857
|
object(messagePort);
|
|
1826
|
-
const rpc = await
|
|
1858
|
+
const rpc = await ElectronMessagePortRpcClient.create({
|
|
1859
|
+
commandMap: {},
|
|
1827
1860
|
messagePort,
|
|
1828
|
-
|
|
1861
|
+
requiresSocket: false
|
|
1829
1862
|
});
|
|
1830
1863
|
if (rpcId) {
|
|
1831
1864
|
set$2(rpcId, rpc);
|
|
@@ -1838,75 +1871,16 @@ const requiresSocket = method => {
|
|
|
1838
1871
|
const handleWebSocket = async (handle, request) => {
|
|
1839
1872
|
object(handle);
|
|
1840
1873
|
object(request);
|
|
1841
|
-
await
|
|
1874
|
+
await NodeWebSocketRpcClient.create({
|
|
1875
|
+
commandMap: {},
|
|
1842
1876
|
handle,
|
|
1843
|
-
method: WebSocket,
|
|
1844
1877
|
request,
|
|
1845
1878
|
requiresSocket
|
|
1846
1879
|
});
|
|
1847
1880
|
};
|
|
1848
1881
|
|
|
1849
|
-
const state = {
|
|
1850
|
-
id: 0
|
|
1851
|
-
};
|
|
1852
|
-
const create = () => {
|
|
1853
|
-
return ++state.id;
|
|
1854
|
-
};
|
|
1855
|
-
|
|
1856
|
-
const {
|
|
1857
|
-
invoke,
|
|
1858
|
-
invokeAndTransfer} = SharedProcess;
|
|
1859
|
-
|
|
1860
|
-
const ports = Object.create(null);
|
|
1861
|
-
const getPortTuple$1 = async () => {
|
|
1862
|
-
const id1 = create();
|
|
1863
|
-
const id2 = create();
|
|
1864
|
-
// @ts-ignore
|
|
1865
|
-
await invoke('TemporaryMessagePort.getPortTuple3', id1, id2, FileSystemProcess);
|
|
1866
|
-
const port1 = ports[id1];
|
|
1867
|
-
const port2 = ports[id2];
|
|
1868
|
-
delete ports[id1];
|
|
1869
|
-
delete ports[id2];
|
|
1870
|
-
return {
|
|
1871
|
-
port1,
|
|
1872
|
-
port2
|
|
1873
|
-
};
|
|
1874
|
-
};
|
|
1875
|
-
const handlePorts = (port1, port2, id1, id2) => {
|
|
1876
|
-
number(id1);
|
|
1877
|
-
number(id2);
|
|
1878
|
-
object(port1);
|
|
1879
|
-
object(port2);
|
|
1880
|
-
ports[id1] = port1;
|
|
1881
|
-
ports[id2] = port2;
|
|
1882
|
-
};
|
|
1883
|
-
|
|
1884
|
-
const getPortTuple = async () => {
|
|
1885
|
-
const {
|
|
1886
|
-
port1,
|
|
1887
|
-
port2
|
|
1888
|
-
} = await getPortTuple$1();
|
|
1889
|
-
return {
|
|
1890
|
-
port1,
|
|
1891
|
-
port2
|
|
1892
|
-
};
|
|
1893
|
-
};
|
|
1894
|
-
|
|
1895
|
-
const createMainProcessRpc = async () => {
|
|
1896
|
-
const rpc = await LazyTransferElectronMessagePortRpc.create({
|
|
1897
|
-
commandMap: {},
|
|
1898
|
-
getPortTuple,
|
|
1899
|
-
async send(port) {
|
|
1900
|
-
await invokeAndTransfer(
|
|
1901
|
-
// @ts-ignore
|
|
1902
|
-
'TemporaryMessagePort.sendToElectron', port, MainProcess, FileSystemProcess);
|
|
1903
|
-
}
|
|
1904
|
-
});
|
|
1905
|
-
set$1(rpc);
|
|
1906
|
-
};
|
|
1907
|
-
|
|
1908
1882
|
const initialize = async () => {
|
|
1909
|
-
|
|
1883
|
+
// TODO this function is not needed anymore
|
|
1910
1884
|
};
|
|
1911
1885
|
|
|
1912
1886
|
const commandMap = {
|
|
@@ -1933,11 +1907,32 @@ const commandMap = {
|
|
|
1933
1907
|
'TemporaryMessagePort.handlePorts': handlePorts
|
|
1934
1908
|
};
|
|
1935
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
|
+
|
|
1936
1934
|
const listen = async argv => {
|
|
1937
|
-
await
|
|
1938
|
-
commandMap: commandMap,
|
|
1939
|
-
method: Auto(argv)
|
|
1940
|
-
});
|
|
1935
|
+
await Promise.all([initializeParentProcessRpc(argv), initializeMainProcessRpc()]);
|
|
1941
1936
|
};
|
|
1942
1937
|
|
|
1943
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
|
}
|