@lvce-editor/file-watcher-process 1.2.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.
Files changed (2) hide show
  1. package/dist/index.js +44 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1600,6 +1600,15 @@ const normalizeEvent = (eventName, path) => {
1600
1600
  };
1601
1601
  };
1602
1602
 
1603
+ const waitForWatcherToBeReady = async watcher => {
1604
+ const {
1605
+ resolve,
1606
+ promise
1607
+ } = Promise.withResolvers();
1608
+ watcher.on('ready', resolve);
1609
+ await promise;
1610
+ };
1611
+
1603
1612
  const watchFolder = async uri => {
1604
1613
  const callBackInternal = async (eventName, path, stats) => {
1605
1614
  const event = normalizeEvent(eventName, path);
@@ -1611,17 +1620,45 @@ const watchFolder = async uri => {
1611
1620
  const path = fileURLToPath(uri);
1612
1621
  const watcher = watch(path);
1613
1622
  watcher.on('all', callback);
1614
- const {
1615
- resolve,
1616
- promise
1617
- } = Promise.withResolvers();
1618
- watcher.on('ready', resolve);
1619
- await promise;
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));
1620
1656
  };
1621
1657
 
1622
1658
  const commandMap = {
1623
1659
  'FileWatcher.watchFile': watchFile,
1624
- 'FileWatcher.watchFolder': watchFolder
1660
+ 'FileWatcher.watchFolder': watchFolder,
1661
+ 'FileWatcher.watchFolders': watchFolders
1625
1662
  };
1626
1663
 
1627
1664
  const NodeWorker = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-watcher-process",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "File Watcher Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",