@lvce-editor/file-watcher-process 1.1.0 → 1.3.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 +49 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import * as sysPath from 'path';
|
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
9
9
|
import { resolve, join, relative, sep } from 'node:path';
|
|
10
10
|
import { type } from 'os';
|
|
11
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
11
12
|
import { ElectronMessagePortRpcClient, ElectronUtilityProcessRpcClient, NodeWorkerRpcClient, NodeForkedProcessRpcClient } from '@lvce-editor/rpc';
|
|
12
13
|
|
|
13
14
|
const SharedProcess = 1;
|
|
@@ -1592,13 +1593,23 @@ function watch(paths, options = {}) {
|
|
|
1592
1593
|
}
|
|
1593
1594
|
|
|
1594
1595
|
const normalizeEvent = (eventName, path) => {
|
|
1596
|
+
const uri = pathToFileURL(path).toString();
|
|
1595
1597
|
return {
|
|
1596
1598
|
eventName,
|
|
1597
|
-
|
|
1599
|
+
uri
|
|
1598
1600
|
};
|
|
1599
1601
|
};
|
|
1600
1602
|
|
|
1601
|
-
const
|
|
1603
|
+
const waitForWatcherToBeReady = async watcher => {
|
|
1604
|
+
const {
|
|
1605
|
+
resolve,
|
|
1606
|
+
promise
|
|
1607
|
+
} = Promise.withResolvers();
|
|
1608
|
+
watcher.on('ready', resolve);
|
|
1609
|
+
await promise;
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
const watchFolder = async uri => {
|
|
1602
1613
|
const callBackInternal = async (eventName, path, stats) => {
|
|
1603
1614
|
const event = normalizeEvent(eventName, path);
|
|
1604
1615
|
await invoke('FileWatcher.handleChange', event);
|
|
@@ -1606,19 +1617,48 @@ const watchFolder = async path => {
|
|
|
1606
1617
|
const callback = (eventName, path, stats) => {
|
|
1607
1618
|
void callBackInternal(eventName, path);
|
|
1608
1619
|
};
|
|
1620
|
+
const path = fileURLToPath(uri);
|
|
1609
1621
|
const watcher = watch(path);
|
|
1610
1622
|
watcher.on('all', callback);
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1623
|
+
await waitForWatcherToBeReady(watcher);
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
const normalizeEvent2 = (id, eventName, path) => {
|
|
1627
|
+
const uri = pathToFileURL(path).toString();
|
|
1628
|
+
return {
|
|
1629
|
+
eventName,
|
|
1630
|
+
uri,
|
|
1631
|
+
id
|
|
1632
|
+
};
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1635
|
+
const watchFolders = async ({
|
|
1636
|
+
roots,
|
|
1637
|
+
id,
|
|
1638
|
+
exclude
|
|
1639
|
+
}) => {
|
|
1640
|
+
const callBackInternal = async (eventName, path, stats) => {
|
|
1641
|
+
const event = normalizeEvent2(id, eventName, path);
|
|
1642
|
+
await invoke('FileWatcher.handleChange', event);
|
|
1643
|
+
};
|
|
1644
|
+
const callback = (eventName, path, stats) => {
|
|
1645
|
+
void callBackInternal(eventName, path);
|
|
1646
|
+
};
|
|
1647
|
+
const watchers = roots.map(root => {
|
|
1648
|
+
const path = fileURLToPath(root);
|
|
1649
|
+
const watcher = watch(path);
|
|
1650
|
+
return watcher;
|
|
1651
|
+
});
|
|
1652
|
+
for (const watcher of watchers) {
|
|
1653
|
+
watcher.on('all', callback);
|
|
1654
|
+
}
|
|
1655
|
+
await Promise.all(watchers.map(waitForWatcherToBeReady));
|
|
1617
1656
|
};
|
|
1618
1657
|
|
|
1619
1658
|
const commandMap = {
|
|
1620
1659
|
'FileWatcher.watchFile': watchFile,
|
|
1621
|
-
'FileWatcher.watchFolder': watchFolder
|
|
1660
|
+
'FileWatcher.watchFolder': watchFolder,
|
|
1661
|
+
'FileWatcher.watchFolders': watchFolders
|
|
1622
1662
|
};
|
|
1623
1663
|
|
|
1624
1664
|
const NodeWorker = 1;
|