@lvce-editor/file-system-process 3.2.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 +52 -20
- 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) {
|
|
@@ -265,6 +271,8 @@ const ErrorWorker$1 = 3308;
|
|
|
265
271
|
const SyntaxHighlightingWorker$1 = 3309;
|
|
266
272
|
const ClipBoardWorker$1 = 3400;
|
|
267
273
|
const ClipBoardProcess$1 = 3401;
|
|
274
|
+
const ExtensionDetailWorker = 3402;
|
|
275
|
+
const ProblemsWorker = 3403;
|
|
268
276
|
const RpcId = {
|
|
269
277
|
__proto__: null,
|
|
270
278
|
ClipBoardProcess: ClipBoardProcess$1,
|
|
@@ -276,11 +284,13 @@ const RpcId = {
|
|
|
276
284
|
EmbedsProcess: EmbedsProcess$1,
|
|
277
285
|
EmbedsWorker,
|
|
278
286
|
ErrorWorker: ErrorWorker$1,
|
|
287
|
+
ExtensionDetailWorker,
|
|
279
288
|
ExtensionHostWorker,
|
|
280
289
|
FileSystemProcess: FileSystemProcess$1,
|
|
281
290
|
FileSystemWorker: FileSystemWorker$1,
|
|
282
291
|
MainProcess: MainProcess$1,
|
|
283
292
|
MarkdownWorker: MarkdownWorker$1,
|
|
293
|
+
ProblemsWorker,
|
|
284
294
|
RendererProcess: RendererProcess$1,
|
|
285
295
|
RendererWorker: RendererWorker$1,
|
|
286
296
|
SearchProcess: SearchProcess$1,
|
|
@@ -292,7 +302,7 @@ const RpcId = {
|
|
|
292
302
|
};
|
|
293
303
|
const {
|
|
294
304
|
invoke: invoke$1$1,
|
|
295
|
-
invokeAndTransfer: invokeAndTransfer$1$1} = create$
|
|
305
|
+
invokeAndTransfer: invokeAndTransfer$1$1} = create$6(SharedProcess$1);
|
|
296
306
|
const SharedProcess = {
|
|
297
307
|
__proto__: null,
|
|
298
308
|
invoke: invoke$1$1,
|
|
@@ -365,11 +375,6 @@ const trash = async path => {
|
|
|
365
375
|
}
|
|
366
376
|
};
|
|
367
377
|
|
|
368
|
-
const assertUri = uri => {
|
|
369
|
-
if (!uri.startsWith('file://')) {
|
|
370
|
-
throw new Error(`path must be a valid file uri`);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
378
|
const copy = async (sourceUri, targetUri) => {
|
|
374
379
|
try {
|
|
375
380
|
assertUri(sourceUri);
|
|
@@ -416,6 +421,20 @@ const writeFile = async (uri, content, encoding = Utf8) => {
|
|
|
416
421
|
throw new VError(error, `Failed to write to file "${uri}"`);
|
|
417
422
|
}
|
|
418
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
|
+
};
|
|
419
438
|
const isOkayToRemove = path => {
|
|
420
439
|
if (path === '/') {
|
|
421
440
|
return false;
|
|
@@ -474,6 +493,11 @@ const mkdir = async uri => {
|
|
|
474
493
|
throw new VError(error, `Failed to create directory "${uri}"`);
|
|
475
494
|
}
|
|
476
495
|
};
|
|
496
|
+
const exists = async uri => {
|
|
497
|
+
assertUri(uri);
|
|
498
|
+
const path = fileURLToPath(uri);
|
|
499
|
+
return existsSync(path);
|
|
500
|
+
};
|
|
477
501
|
const fallbackRename = async (oldUri, newUri) => {
|
|
478
502
|
try {
|
|
479
503
|
const oldPath = fileURLToPath(oldUri);
|
|
@@ -1272,7 +1296,8 @@ const splitLines = lines => {
|
|
|
1272
1296
|
return lines.split(NewLine);
|
|
1273
1297
|
};
|
|
1274
1298
|
const getCurrentStack = () => {
|
|
1275
|
-
const
|
|
1299
|
+
const stackLinesToSkip = 3;
|
|
1300
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
1276
1301
|
return currentStack;
|
|
1277
1302
|
};
|
|
1278
1303
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
@@ -1543,6 +1568,12 @@ const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
|
1543
1568
|
return invokeHelper(ipc, method, params, true);
|
|
1544
1569
|
};
|
|
1545
1570
|
|
|
1571
|
+
class CommandNotFoundError extends Error {
|
|
1572
|
+
constructor(command) {
|
|
1573
|
+
super(`Command not found ${command}`);
|
|
1574
|
+
this.name = 'CommandNotFoundError';
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1546
1577
|
const commands = Object.create(null);
|
|
1547
1578
|
const register = commandMap => {
|
|
1548
1579
|
Object.assign(commands, commandMap);
|
|
@@ -1553,7 +1584,7 @@ const getCommand = key => {
|
|
|
1553
1584
|
const execute = (command, ...args) => {
|
|
1554
1585
|
const fn = getCommand(command);
|
|
1555
1586
|
if (!fn) {
|
|
1556
|
-
throw new
|
|
1587
|
+
throw new CommandNotFoundError(command);
|
|
1557
1588
|
}
|
|
1558
1589
|
return fn(...args);
|
|
1559
1590
|
};
|
|
@@ -1610,7 +1641,7 @@ const listen$2 = async (module, options) => {
|
|
|
1610
1641
|
const ipc = module.wrap(rawIpc);
|
|
1611
1642
|
return ipc;
|
|
1612
1643
|
};
|
|
1613
|
-
const create$
|
|
1644
|
+
const create$k = async ({
|
|
1614
1645
|
commandMap,
|
|
1615
1646
|
messagePort,
|
|
1616
1647
|
requiresSocket
|
|
@@ -1629,9 +1660,9 @@ const create$g = async ({
|
|
|
1629
1660
|
};
|
|
1630
1661
|
const ElectronMessagePortRpcClient = {
|
|
1631
1662
|
__proto__: null,
|
|
1632
|
-
create: create$
|
|
1663
|
+
create: create$k
|
|
1633
1664
|
};
|
|
1634
|
-
const create$
|
|
1665
|
+
const create$j = async ({
|
|
1635
1666
|
commandMap
|
|
1636
1667
|
}) => {
|
|
1637
1668
|
// TODO create a commandMap per rpc instance
|
|
@@ -1643,9 +1674,9 @@ const create$f = async ({
|
|
|
1643
1674
|
};
|
|
1644
1675
|
const ElectronUtilityProcessRpcClient = {
|
|
1645
1676
|
__proto__: null,
|
|
1646
|
-
create: create$
|
|
1677
|
+
create: create$j
|
|
1647
1678
|
};
|
|
1648
|
-
const create$
|
|
1679
|
+
const create$a = async ({
|
|
1649
1680
|
commandMap
|
|
1650
1681
|
}) => {
|
|
1651
1682
|
// TODO create a commandMap per rpc instance
|
|
@@ -1657,9 +1688,9 @@ const create$9 = async ({
|
|
|
1657
1688
|
};
|
|
1658
1689
|
const NodeForkedProcessRpcClient = {
|
|
1659
1690
|
__proto__: null,
|
|
1660
|
-
create: create$
|
|
1691
|
+
create: create$a
|
|
1661
1692
|
};
|
|
1662
|
-
const create$
|
|
1693
|
+
const create$8 = async ({
|
|
1663
1694
|
commandMap,
|
|
1664
1695
|
request,
|
|
1665
1696
|
handle,
|
|
@@ -1680,9 +1711,9 @@ const create$7 = async ({
|
|
|
1680
1711
|
};
|
|
1681
1712
|
const NodeWebSocketRpcClient = {
|
|
1682
1713
|
__proto__: null,
|
|
1683
|
-
create: create$
|
|
1714
|
+
create: create$8
|
|
1684
1715
|
};
|
|
1685
|
-
const create$
|
|
1716
|
+
const create$7 = async ({
|
|
1686
1717
|
commandMap
|
|
1687
1718
|
}) => {
|
|
1688
1719
|
// TODO create a commandMap per rpc instance
|
|
@@ -1694,7 +1725,7 @@ const create$6 = async ({
|
|
|
1694
1725
|
};
|
|
1695
1726
|
const NodeWorkerRpcClient = {
|
|
1696
1727
|
__proto__: null,
|
|
1697
|
-
create: create$
|
|
1728
|
+
create: create$7
|
|
1698
1729
|
};
|
|
1699
1730
|
|
|
1700
1731
|
const NodeWorker = 1;
|
|
@@ -1833,9 +1864,10 @@ const initialize = async () => {
|
|
|
1833
1864
|
};
|
|
1834
1865
|
|
|
1835
1866
|
const commandMap = {
|
|
1867
|
+
'FileSystem.appendFile': appendFile,
|
|
1836
1868
|
'FileSystem.chmod': chmod,
|
|
1837
1869
|
'FileSystem.copy': copy,
|
|
1838
|
-
'FileSystem.exists':
|
|
1870
|
+
'FileSystem.exists': exists,
|
|
1839
1871
|
'FileSystem.getFolderSize': getFolderSize,
|
|
1840
1872
|
'FileSystem.getPathSeparator': getPathSeparator,
|
|
1841
1873
|
'FileSystem.mkdir': mkdir,
|