@lvce-editor/file-system-process 3.4.0 → 3.6.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 +50 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -558,6 +558,47 @@ const getFolderSize = async uri => {
|
|
|
558
558
|
return total;
|
|
559
559
|
};
|
|
560
560
|
|
|
561
|
+
const fileWacherEvents = Object.create(null);
|
|
562
|
+
const setupWatcher = async (watcherId, uri, onChange) => {
|
|
563
|
+
try {
|
|
564
|
+
const path = fileURLToPath(uri);
|
|
565
|
+
// TODO
|
|
566
|
+
const watcher = fs.watch(path, {});
|
|
567
|
+
const watcherEvents = [];
|
|
568
|
+
fileWacherEvents[watcherId] = watcherEvents;
|
|
569
|
+
for await (const event of watcher) {
|
|
570
|
+
watcherEvents.push(event);
|
|
571
|
+
onChange();
|
|
572
|
+
}
|
|
573
|
+
} catch (error) {
|
|
574
|
+
if (error && error.code === 'ENOENT') {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
console.error(error);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// TODO when socket closes, dispose file watcher for this socket
|
|
582
|
+
const watchFile = async (socket, watcherId, uri) => {
|
|
583
|
+
assertUri(uri);
|
|
584
|
+
fileWacherEvents[watcherId] = [];
|
|
585
|
+
// TODO await promise?
|
|
586
|
+
const onChange = () => {
|
|
587
|
+
// TODO handle error
|
|
588
|
+
socket.send({
|
|
589
|
+
jsonrpc: '2.0',
|
|
590
|
+
method: 'FileSystem.executeWatchCallback',
|
|
591
|
+
params: [watcherId]
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
596
|
+
setupWatcher(watcherId, uri, onChange);
|
|
597
|
+
};
|
|
598
|
+
const unwatchFile = uri => {
|
|
599
|
+
// TODO
|
|
600
|
+
};
|
|
601
|
+
|
|
561
602
|
const isMessagePort = value => {
|
|
562
603
|
return value && value instanceof MessagePort;
|
|
563
604
|
};
|
|
@@ -1611,7 +1652,7 @@ const createRpc = ipc => {
|
|
|
1611
1652
|
};
|
|
1612
1653
|
return rpc;
|
|
1613
1654
|
};
|
|
1614
|
-
const requiresSocket = () => {
|
|
1655
|
+
const requiresSocket$1 = () => {
|
|
1615
1656
|
return false;
|
|
1616
1657
|
};
|
|
1617
1658
|
const preparePrettyError = error => {
|
|
@@ -1621,7 +1662,7 @@ const logError = () => {
|
|
|
1621
1662
|
// handled by renderer worker
|
|
1622
1663
|
};
|
|
1623
1664
|
const handleMessage = event => {
|
|
1624
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1665
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1625
1666
|
const actualExecute = event?.target?.execute || execute;
|
|
1626
1667
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1627
1668
|
};
|
|
@@ -1783,13 +1824,17 @@ const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
|
1783
1824
|
}
|
|
1784
1825
|
};
|
|
1785
1826
|
|
|
1827
|
+
const requiresSocket = method => {
|
|
1828
|
+
return method === 'FileSystem.watchFile';
|
|
1829
|
+
};
|
|
1786
1830
|
const handleWebSocket = async (handle, request) => {
|
|
1787
1831
|
object(handle);
|
|
1788
1832
|
object(request);
|
|
1789
1833
|
await listen$1({
|
|
1790
1834
|
method: WebSocket,
|
|
1791
1835
|
request,
|
|
1792
|
-
handle
|
|
1836
|
+
handle,
|
|
1837
|
+
requiresSocket
|
|
1793
1838
|
});
|
|
1794
1839
|
};
|
|
1795
1840
|
|
|
@@ -1877,6 +1922,8 @@ const commandMap = {
|
|
|
1877
1922
|
'FileSystem.remove': remove$1,
|
|
1878
1923
|
'FileSystem.rename': rename,
|
|
1879
1924
|
'FileSystem.stat': stat,
|
|
1925
|
+
'FileSystem.unwatchFile': unwatchFile,
|
|
1926
|
+
'FileSystem.watchFile': watchFile,
|
|
1880
1927
|
'FileSystem.writeFile': writeFile,
|
|
1881
1928
|
'HandleElectronMessagePort.handleElectronMessagePort': handleElectronMessagePort,
|
|
1882
1929
|
'HandleWebSocket.handleWebSocket': handleWebSocket,
|