@lvce-editor/file-system-process 3.3.0 → 3.5.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.
Files changed (2) hide show
  1. package/dist/index.js +51 -19
  2. 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$8 = rpcId => {
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$8(SharedProcess$1);
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;
@@ -543,6 +558,13 @@ const getFolderSize = async uri => {
543
558
  return total;
544
559
  };
545
560
 
561
+ const watchFile = uri => {
562
+ // TODO
563
+ };
564
+ const unwatchFile = uri => {
565
+ // TODO
566
+ };
567
+
546
568
  const isMessagePort = value => {
547
569
  return value && value instanceof MessagePort;
548
570
  };
@@ -1281,7 +1303,8 @@ const splitLines = lines => {
1281
1303
  return lines.split(NewLine);
1282
1304
  };
1283
1305
  const getCurrentStack = () => {
1284
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
1306
+ const stackLinesToSkip = 3;
1307
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
1285
1308
  return currentStack;
1286
1309
  };
1287
1310
  const getNewLineIndex = (string, startIndex = undefined) => {
@@ -1552,6 +1575,12 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
1552
1575
  return invokeHelper(ipc, method, params, true);
1553
1576
  };
1554
1577
 
1578
+ class CommandNotFoundError extends Error {
1579
+ constructor(command) {
1580
+ super(`Command not found ${command}`);
1581
+ this.name = 'CommandNotFoundError';
1582
+ }
1583
+ }
1555
1584
  const commands = Object.create(null);
1556
1585
  const register = commandMap => {
1557
1586
  Object.assign(commands, commandMap);
@@ -1562,7 +1591,7 @@ const getCommand = key => {
1562
1591
  const execute = (command, ...args) => {
1563
1592
  const fn = getCommand(command);
1564
1593
  if (!fn) {
1565
- throw new Error(`command not found ${command}`);
1594
+ throw new CommandNotFoundError(command);
1566
1595
  }
1567
1596
  return fn(...args);
1568
1597
  };
@@ -1619,7 +1648,7 @@ const listen$2 = async (module, options) => {
1619
1648
  const ipc = module.wrap(rawIpc);
1620
1649
  return ipc;
1621
1650
  };
1622
- const create$j = async ({
1651
+ const create$k = async ({
1623
1652
  commandMap,
1624
1653
  messagePort,
1625
1654
  requiresSocket
@@ -1638,9 +1667,9 @@ const create$j = async ({
1638
1667
  };
1639
1668
  const ElectronMessagePortRpcClient = {
1640
1669
  __proto__: null,
1641
- create: create$j
1670
+ create: create$k
1642
1671
  };
1643
- const create$i = async ({
1672
+ const create$j = async ({
1644
1673
  commandMap
1645
1674
  }) => {
1646
1675
  // TODO create a commandMap per rpc instance
@@ -1652,9 +1681,9 @@ const create$i = async ({
1652
1681
  };
1653
1682
  const ElectronUtilityProcessRpcClient = {
1654
1683
  __proto__: null,
1655
- create: create$i
1684
+ create: create$j
1656
1685
  };
1657
- const create$9 = async ({
1686
+ const create$a = async ({
1658
1687
  commandMap
1659
1688
  }) => {
1660
1689
  // TODO create a commandMap per rpc instance
@@ -1666,9 +1695,9 @@ const create$9 = async ({
1666
1695
  };
1667
1696
  const NodeForkedProcessRpcClient = {
1668
1697
  __proto__: null,
1669
- create: create$9
1698
+ create: create$a
1670
1699
  };
1671
- const create$7 = async ({
1700
+ const create$8 = async ({
1672
1701
  commandMap,
1673
1702
  request,
1674
1703
  handle,
@@ -1689,9 +1718,9 @@ const create$7 = async ({
1689
1718
  };
1690
1719
  const NodeWebSocketRpcClient = {
1691
1720
  __proto__: null,
1692
- create: create$7
1721
+ create: create$8
1693
1722
  };
1694
- const create$6 = async ({
1723
+ const create$7 = async ({
1695
1724
  commandMap
1696
1725
  }) => {
1697
1726
  // TODO create a commandMap per rpc instance
@@ -1703,7 +1732,7 @@ const create$6 = async ({
1703
1732
  };
1704
1733
  const NodeWorkerRpcClient = {
1705
1734
  __proto__: null,
1706
- create: create$6
1735
+ create: create$7
1707
1736
  };
1708
1737
 
1709
1738
  const NodeWorker = 1;
@@ -1842,6 +1871,7 @@ const initialize = async () => {
1842
1871
  };
1843
1872
 
1844
1873
  const commandMap = {
1874
+ 'FileSystem.appendFile': appendFile,
1845
1875
  'FileSystem.chmod': chmod,
1846
1876
  'FileSystem.copy': copy,
1847
1877
  'FileSystem.exists': exists,
@@ -1854,6 +1884,8 @@ const commandMap = {
1854
1884
  'FileSystem.remove': remove$1,
1855
1885
  'FileSystem.rename': rename,
1856
1886
  'FileSystem.stat': stat,
1887
+ 'FileSystem.unwatchFile': unwatchFile,
1888
+ 'FileSystem.watchFile': watchFile,
1857
1889
  'FileSystem.writeFile': writeFile,
1858
1890
  'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
1859
1891
  'HandleWebSocket.handleWebSocket': handleWebSocket,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-system-process",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "File System Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",