@lvce-editor/file-system-process 2.2.0 → 2.4.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 +44 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,37 +12,45 @@ class AssertionError extends Error {
|
|
|
12
12
|
this.name = 'AssertionError';
|
|
13
13
|
}
|
|
14
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;
|
|
15
23
|
const getType = value => {
|
|
16
24
|
switch (typeof value) {
|
|
17
25
|
case 'number':
|
|
18
|
-
return
|
|
26
|
+
return Number;
|
|
19
27
|
case 'function':
|
|
20
|
-
return
|
|
28
|
+
return Function;
|
|
21
29
|
case 'string':
|
|
22
|
-
return
|
|
30
|
+
return String;
|
|
23
31
|
case 'object':
|
|
24
32
|
if (value === null) {
|
|
25
|
-
return
|
|
33
|
+
return Null;
|
|
26
34
|
}
|
|
27
35
|
if (Array.isArray(value)) {
|
|
28
|
-
return
|
|
36
|
+
return Array$1;
|
|
29
37
|
}
|
|
30
|
-
return
|
|
38
|
+
return Object$1;
|
|
31
39
|
case 'boolean':
|
|
32
|
-
return
|
|
40
|
+
return Boolean$1;
|
|
33
41
|
default:
|
|
34
|
-
return
|
|
42
|
+
return Unknown$1;
|
|
35
43
|
}
|
|
36
44
|
};
|
|
37
45
|
const object = value => {
|
|
38
46
|
const type = getType(value);
|
|
39
|
-
if (type !==
|
|
47
|
+
if (type !== Object$1) {
|
|
40
48
|
throw new AssertionError('expected value to be of type object');
|
|
41
49
|
}
|
|
42
50
|
};
|
|
43
51
|
const string = value => {
|
|
44
52
|
const type = getType(value);
|
|
45
|
-
if (type !==
|
|
53
|
+
if (type !== String) {
|
|
46
54
|
throw new AssertionError('expected value to be of type string');
|
|
47
55
|
}
|
|
48
56
|
};
|
|
@@ -130,6 +138,7 @@ const Socket = 8;
|
|
|
130
138
|
const Symlink = 9;
|
|
131
139
|
const Unknown = 12;
|
|
132
140
|
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
133
142
|
const getDirentType = dirent => {
|
|
134
143
|
if (dirent.isFile()) {
|
|
135
144
|
return File;
|
|
@@ -177,12 +186,15 @@ const getFolderSizeInternal = async path => {
|
|
|
177
186
|
|
|
178
187
|
// @ts-ignore
|
|
179
188
|
const isEnoentErrorWindows = error => {
|
|
180
|
-
|
|
189
|
+
if (!error || !error.message) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
return error.message.includes('The system cannot find the path specified.');
|
|
181
193
|
};
|
|
182
194
|
|
|
183
195
|
// @ts-ignore
|
|
184
196
|
const isEnoentErrorLinux = error => {
|
|
185
|
-
return error.code === ENOENT;
|
|
197
|
+
return Boolean(error && error.code === ENOENT);
|
|
186
198
|
};
|
|
187
199
|
|
|
188
200
|
// @ts-ignore
|
|
@@ -194,7 +206,7 @@ const isEnoentError = error => {
|
|
|
194
206
|
};
|
|
195
207
|
|
|
196
208
|
const rpcs = Object.create(null);
|
|
197
|
-
const set$
|
|
209
|
+
const set$g = (id, rpc) => {
|
|
198
210
|
rpcs[id] = rpc;
|
|
199
211
|
};
|
|
200
212
|
const get$1 = id => {
|
|
@@ -203,7 +215,7 @@ const get$1 = id => {
|
|
|
203
215
|
|
|
204
216
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
205
217
|
|
|
206
|
-
const create$
|
|
218
|
+
const create$5 = rpcId => {
|
|
207
219
|
return {
|
|
208
220
|
// @ts-ignore
|
|
209
221
|
invoke(method, ...params) {
|
|
@@ -218,7 +230,7 @@ const create$6 = rpcId => {
|
|
|
218
230
|
return rpc.invokeAndTransfer(method, ...params);
|
|
219
231
|
},
|
|
220
232
|
set(rpc) {
|
|
221
|
-
set$
|
|
233
|
+
set$g(rpcId, rpc);
|
|
222
234
|
},
|
|
223
235
|
async dispose() {
|
|
224
236
|
const rpc = get$1(rpcId);
|
|
@@ -229,7 +241,7 @@ const create$6 = rpcId => {
|
|
|
229
241
|
const MainProcess$1 = -5;
|
|
230
242
|
const {
|
|
231
243
|
invoke: invoke$6,
|
|
232
|
-
set: set$6} = create$
|
|
244
|
+
set: set$6} = create$5(MainProcess$1);
|
|
233
245
|
const MainProcess = {
|
|
234
246
|
__proto__: null,
|
|
235
247
|
invoke: invoke$6,
|
|
@@ -262,12 +274,15 @@ const getTrashFn = isElectron => {
|
|
|
262
274
|
};
|
|
263
275
|
|
|
264
276
|
const getElectronRunAsNode = () => {
|
|
265
|
-
return process.env.ELECTRON_RUN_AS_NODE;
|
|
277
|
+
return process.env.ELECTRON_RUN_AS_NODE || '';
|
|
266
278
|
};
|
|
267
279
|
|
|
268
280
|
const isElectron = Boolean(getElectronRunAsNode()) || 'electron' in process.versions;
|
|
269
281
|
|
|
270
282
|
const trash = async path => {
|
|
283
|
+
if (!path || path.trim() === '') {
|
|
284
|
+
throw new Error('Path cannot be empty');
|
|
285
|
+
}
|
|
271
286
|
try {
|
|
272
287
|
const fn = getTrashFn(isElectron);
|
|
273
288
|
await fn(path);
|
|
@@ -1077,7 +1092,7 @@ const IpcChildWithWebSocket = {
|
|
|
1077
1092
|
};
|
|
1078
1093
|
|
|
1079
1094
|
const Two = '2.0';
|
|
1080
|
-
const create$4
|
|
1095
|
+
const create$4 = (method, params) => {
|
|
1081
1096
|
return {
|
|
1082
1097
|
jsonrpc: Two,
|
|
1083
1098
|
method,
|
|
@@ -1445,7 +1460,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
1445
1460
|
return unwrapJsonRpcResult(responseMessage);
|
|
1446
1461
|
};
|
|
1447
1462
|
const send = (transport, method, ...params) => {
|
|
1448
|
-
const message = create$4
|
|
1463
|
+
const message = create$4(method, params);
|
|
1449
1464
|
transport.send(message);
|
|
1450
1465
|
};
|
|
1451
1466
|
const invoke = (ipc, method, ...params) => {
|
|
@@ -1522,7 +1537,7 @@ const listen$2 = async (module, options) => {
|
|
|
1522
1537
|
const ipc = module.wrap(rawIpc);
|
|
1523
1538
|
return ipc;
|
|
1524
1539
|
};
|
|
1525
|
-
const create$
|
|
1540
|
+
const create$g = async ({
|
|
1526
1541
|
commandMap,
|
|
1527
1542
|
messagePort,
|
|
1528
1543
|
requiresSocket
|
|
@@ -1541,9 +1556,9 @@ const create$e = async ({
|
|
|
1541
1556
|
};
|
|
1542
1557
|
const ElectronMessagePortRpcClient = {
|
|
1543
1558
|
__proto__: null,
|
|
1544
|
-
create: create$
|
|
1559
|
+
create: create$g
|
|
1545
1560
|
};
|
|
1546
|
-
const create$
|
|
1561
|
+
const create$f = async ({
|
|
1547
1562
|
commandMap
|
|
1548
1563
|
}) => {
|
|
1549
1564
|
// TODO create a commandMap per rpc instance
|
|
@@ -1555,9 +1570,9 @@ const create$d = async ({
|
|
|
1555
1570
|
};
|
|
1556
1571
|
const ElectronUtilityProcessRpcClient = {
|
|
1557
1572
|
__proto__: null,
|
|
1558
|
-
create: create$
|
|
1573
|
+
create: create$f
|
|
1559
1574
|
};
|
|
1560
|
-
const create$
|
|
1575
|
+
const create$9 = async ({
|
|
1561
1576
|
commandMap
|
|
1562
1577
|
}) => {
|
|
1563
1578
|
// TODO create a commandMap per rpc instance
|
|
@@ -1569,9 +1584,9 @@ const create$7 = async ({
|
|
|
1569
1584
|
};
|
|
1570
1585
|
const NodeForkedProcessRpcClient = {
|
|
1571
1586
|
__proto__: null,
|
|
1572
|
-
create: create$
|
|
1587
|
+
create: create$9
|
|
1573
1588
|
};
|
|
1574
|
-
const create$
|
|
1589
|
+
const create$7 = async ({
|
|
1575
1590
|
commandMap,
|
|
1576
1591
|
request,
|
|
1577
1592
|
handle,
|
|
@@ -1592,9 +1607,9 @@ const create$5 = async ({
|
|
|
1592
1607
|
};
|
|
1593
1608
|
const NodeWebSocketRpcClient = {
|
|
1594
1609
|
__proto__: null,
|
|
1595
|
-
create: create$
|
|
1610
|
+
create: create$7
|
|
1596
1611
|
};
|
|
1597
|
-
const create$
|
|
1612
|
+
const create$6 = async ({
|
|
1598
1613
|
commandMap
|
|
1599
1614
|
}) => {
|
|
1600
1615
|
// TODO create a commandMap per rpc instance
|
|
@@ -1606,7 +1621,7 @@ const create$4 = async ({
|
|
|
1606
1621
|
};
|
|
1607
1622
|
const NodeWorkerRpcClient = {
|
|
1608
1623
|
__proto__: null,
|
|
1609
|
-
create: create$
|
|
1624
|
+
create: create$6
|
|
1610
1625
|
};
|
|
1611
1626
|
|
|
1612
1627
|
const NodeWorker = 1;
|