@lvce-editor/file-system-process 3.3.0 → 3.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 +42 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -61,6 +61,12 @@ const string = value => {
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
const assertUri = uri => {
|
|
65
|
+
if (!uri.startsWith('file://')) {
|
|
66
|
+
throw new Error(`path must be a valid file uri`);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
64
70
|
const Utf8 = 'utf8';
|
|
65
71
|
|
|
66
72
|
const ENOENT = 'ENOENT';
|
|
@@ -220,7 +226,7 @@ const get$1 = id => {
|
|
|
220
226
|
|
|
221
227
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
222
228
|
|
|
223
|
-
const create$
|
|
229
|
+
const create$6 = rpcId => {
|
|
224
230
|
return {
|
|
225
231
|
// @ts-ignore
|
|
226
232
|
invoke(method, ...params) {
|
|
@@ -296,7 +302,7 @@ const RpcId = {
|
|
|
296
302
|
};
|
|
297
303
|
const {
|
|
298
304
|
invoke: invoke$1$1,
|
|
299
|
-
invokeAndTransfer: invokeAndTransfer$1$1} = create$
|
|
305
|
+
invokeAndTransfer: invokeAndTransfer$1$1} = create$6(SharedProcess$1);
|
|
300
306
|
const SharedProcess = {
|
|
301
307
|
__proto__: null,
|
|
302
308
|
invoke: invoke$1$1,
|
|
@@ -369,11 +375,6 @@ const trash = async path => {
|
|
|
369
375
|
}
|
|
370
376
|
};
|
|
371
377
|
|
|
372
|
-
const assertUri = uri => {
|
|
373
|
-
if (!uri.startsWith('file://')) {
|
|
374
|
-
throw new Error(`path must be a valid file uri`);
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
378
|
const copy = async (sourceUri, targetUri) => {
|
|
378
379
|
try {
|
|
379
380
|
assertUri(sourceUri);
|
|
@@ -420,6 +421,20 @@ const writeFile = async (uri, content, encoding = Utf8) => {
|
|
|
420
421
|
throw new VError(error, `Failed to write to file "${uri}"`);
|
|
421
422
|
}
|
|
422
423
|
};
|
|
424
|
+
const appendFile = async (uri, content) => {
|
|
425
|
+
try {
|
|
426
|
+
assertUri(uri);
|
|
427
|
+
string(uri);
|
|
428
|
+
string(content);
|
|
429
|
+
const path = fileURLToPath(uri);
|
|
430
|
+
await fs.appendFile(path, content);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
if (isEnoentError(error)) {
|
|
433
|
+
throw new FileNotFoundError(uri);
|
|
434
|
+
}
|
|
435
|
+
throw new VError(error, `Failed to append to file "${uri}"`);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
423
438
|
const isOkayToRemove = path => {
|
|
424
439
|
if (path === '/') {
|
|
425
440
|
return false;
|
|
@@ -1281,7 +1296,8 @@ const splitLines = lines => {
|
|
|
1281
1296
|
return lines.split(NewLine);
|
|
1282
1297
|
};
|
|
1283
1298
|
const getCurrentStack = () => {
|
|
1284
|
-
const
|
|
1299
|
+
const stackLinesToSkip = 3;
|
|
1300
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
1285
1301
|
return currentStack;
|
|
1286
1302
|
};
|
|
1287
1303
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
@@ -1552,6 +1568,12 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
|
1552
1568
|
return invokeHelper(ipc, method, params, true);
|
|
1553
1569
|
};
|
|
1554
1570
|
|
|
1571
|
+
class CommandNotFoundError extends Error {
|
|
1572
|
+
constructor(command) {
|
|
1573
|
+
super(`Command not found ${command}`);
|
|
1574
|
+
this.name = 'CommandNotFoundError';
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1555
1577
|
const commands = Object.create(null);
|
|
1556
1578
|
const register = commandMap => {
|
|
1557
1579
|
Object.assign(commands, commandMap);
|
|
@@ -1562,7 +1584,7 @@ const getCommand = key => {
|
|
|
1562
1584
|
const execute = (command, ...args) => {
|
|
1563
1585
|
const fn = getCommand(command);
|
|
1564
1586
|
if (!fn) {
|
|
1565
|
-
throw new
|
|
1587
|
+
throw new CommandNotFoundError(command);
|
|
1566
1588
|
}
|
|
1567
1589
|
return fn(...args);
|
|
1568
1590
|
};
|
|
@@ -1619,7 +1641,7 @@ const listen$2 = async (module, options) => {
|
|
|
1619
1641
|
const ipc = module.wrap(rawIpc);
|
|
1620
1642
|
return ipc;
|
|
1621
1643
|
};
|
|
1622
|
-
const create$
|
|
1644
|
+
const create$k = async ({
|
|
1623
1645
|
commandMap,
|
|
1624
1646
|
messagePort,
|
|
1625
1647
|
requiresSocket
|
|
@@ -1638,9 +1660,9 @@ const create$j = async ({
|
|
|
1638
1660
|
};
|
|
1639
1661
|
const ElectronMessagePortRpcClient = {
|
|
1640
1662
|
__proto__: null,
|
|
1641
|
-
create: create$
|
|
1663
|
+
create: create$k
|
|
1642
1664
|
};
|
|
1643
|
-
const create$
|
|
1665
|
+
const create$j = async ({
|
|
1644
1666
|
commandMap
|
|
1645
1667
|
}) => {
|
|
1646
1668
|
// TODO create a commandMap per rpc instance
|
|
@@ -1652,9 +1674,9 @@ const create$i = async ({
|
|
|
1652
1674
|
};
|
|
1653
1675
|
const ElectronUtilityProcessRpcClient = {
|
|
1654
1676
|
__proto__: null,
|
|
1655
|
-
create: create$
|
|
1677
|
+
create: create$j
|
|
1656
1678
|
};
|
|
1657
|
-
const create$
|
|
1679
|
+
const create$a = async ({
|
|
1658
1680
|
commandMap
|
|
1659
1681
|
}) => {
|
|
1660
1682
|
// TODO create a commandMap per rpc instance
|
|
@@ -1666,9 +1688,9 @@ const create$9 = async ({
|
|
|
1666
1688
|
};
|
|
1667
1689
|
const NodeForkedProcessRpcClient = {
|
|
1668
1690
|
__proto__: null,
|
|
1669
|
-
create: create$
|
|
1691
|
+
create: create$a
|
|
1670
1692
|
};
|
|
1671
|
-
const create$
|
|
1693
|
+
const create$8 = async ({
|
|
1672
1694
|
commandMap,
|
|
1673
1695
|
request,
|
|
1674
1696
|
handle,
|
|
@@ -1689,9 +1711,9 @@ const create$7 = async ({
|
|
|
1689
1711
|
};
|
|
1690
1712
|
const NodeWebSocketRpcClient = {
|
|
1691
1713
|
__proto__: null,
|
|
1692
|
-
create: create$
|
|
1714
|
+
create: create$8
|
|
1693
1715
|
};
|
|
1694
|
-
const create$
|
|
1716
|
+
const create$7 = async ({
|
|
1695
1717
|
commandMap
|
|
1696
1718
|
}) => {
|
|
1697
1719
|
// TODO create a commandMap per rpc instance
|
|
@@ -1703,7 +1725,7 @@ const create$6 = async ({
|
|
|
1703
1725
|
};
|
|
1704
1726
|
const NodeWorkerRpcClient = {
|
|
1705
1727
|
__proto__: null,
|
|
1706
|
-
create: create$
|
|
1728
|
+
create: create$7
|
|
1707
1729
|
};
|
|
1708
1730
|
|
|
1709
1731
|
const NodeWorker = 1;
|
|
@@ -1842,6 +1864,7 @@ const initialize = async () => {
|
|
|
1842
1864
|
};
|
|
1843
1865
|
|
|
1844
1866
|
const commandMap = {
|
|
1867
|
+
'FileSystem.appendFile': appendFile,
|
|
1845
1868
|
'FileSystem.chmod': chmod,
|
|
1846
1869
|
'FileSystem.copy': copy,
|
|
1847
1870
|
'FileSystem.exists': exists,
|