You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sets the websocket endpoint and returns a promise that resolves
886
886
when the tauri node fs connection is open. It ensures the socket remains
@@ -893,7 +893,7 @@ open across failures and automatically reconnects as necessary.
893
893
- Promise<void>
894
894
895
895
896
-
###`fs.forceUseNodeWSEndpoint(use)`
896
+
## `fs.forceUseNodeWSEndpoint(use)`
897
897
898
898
Forces the usage of the Node WebSocket endpoint.
899
899
Throws an error if the Node WebSocket endpoint is not set.
@@ -908,7 +908,7 @@ Throws an error if the Node WebSocket endpoint is not set.
908
908
909
909
---
910
910
911
-
###`fs.preferNodeWSEndpoint(use)`
911
+
## `fs.preferNodeWSEndpoint(use)`
912
912
913
913
Sets the preference to use the Node WebSocket endpoint if available.
914
914
Throws an error if the Node WebSocket endpoint is not set.
@@ -923,3 +923,88 @@ To always force the library to use the Node WebSocket endpoint for all FS APIs,
923
923
- Throws an error if the Node WebSocket endpoint has not been set.
924
924
- Call `fs.setNodeWSEndpoint(websocketEndpoint)` before calling this this API.
925
925
926
+
## `fs.watchAsync(pathToWatch, gitIgnorePaths)`
927
+
928
+
Watch a specific path asynchronously for filesystem changes.
929
+
930
+
This function returns a promise that resolves an `EventEmitter` that will emit the following events:
931
+
932
+
-`fs.WATCH_EVENTS.ADD_FILE`: When a file is created.
933
+
-`fs.WATCH_EVENTS.ADD_DIR`: When a directory is created.
934
+
-`fs.WATCH_EVENTS.UNLINK_FILE`: When a file is deleted.
935
+
-`fs.WATCH_EVENTS.UNLINK_DIR`: When a directory is deleted.
936
+
-`fs.WATCH_EVENTS.CHANGE`: When a file is changed.
937
+
938
+
The watcher will ignore all files matching patterns in the provided gitignore.
939
+
940
+
941
+
> **NOTE:** Behavior differs between paths within `/tauri/` and other paths. Within Tauri, every file and folder modification is emitted as a distinct event. However, for other paths, the events are aggregated to the nearest discernible parent directory.
942
+
> **Examples:**
943
+
>
944
+
> 1.**Within Tauri Paths:**
945
+
> If you rename a parent directory named `parentDir` to `newDir` containing two files (`file1.txt` and `file2.txt`), you will receive six separate events:
946
+
> - 2 Events for `UNLINK_DIR``parentDir` and `ADD_DIR``newDir`
947
+
> - 2 Event for the `UNLINK_FILE``parentDir/file1.txt` and `parentDir/file2.txt` due to its parent's renaming.
948
+
> - 2 Event for the `ADD_FILE``newDir/file1.txt` and `newDir/file2.txt` due to its parent's renaming.
949
+
> 2.**Other Paths:**
950
+
> Using the same scenario as above (renaming `parentDir` with two files inside), you will receive just two event(`UNLINK_DIR` and `ADD_DIR`) indicating the change in the `parentDir`. The individual changes to `file1.txt` and `file2.txt` are aggregated under the parent directory's event.
951
+
>
952
+
> This means developers working with Tauri paths should design their event handlers to accommodate individual events for each file and directory change.
953
+
954
+
955
+
### Parameters
956
+
957
+
-**pathToWatch** (string): The path to watch for filesystem changes.
958
+
959
+
-**gitIgnorePaths** (string or Array<string>, optional, default=""): The patterns to ignore, either provided as a string (representing the content of a `.gitignore` file) or an array of individual patterns. The watcher will adhere to the standard `.gitignore` specification as detailed at [git-scm](https://git-scm.com/docs/gitignore). It's important to note that if a parent directory is excluded from watching, its child directories will also be excluded, regardless of any `un-ignore` patterns in git ignore file (e.g., `!node_modules/dont_ignore_dir`).
960
+
961
+
### Returns
962
+
963
+
-**EventEmitter**: The event emitter that will notify of filesystem changes.
964
+
965
+
### Example
966
+
967
+
```javascript
968
+
// In the below watcher, we provide a gitignore formatted text to ignore 'node_modules' folder
969
+
// See https://git-scm.com/docs/gitignore for details.
Stops watching for filesystem changes on a previously set path.
985
+
986
+
Once you've stopped watching using `unwatchAsync`, any further operations on the event emitter will throw an error. If you wish to start watching again, you will need to call `fs.watchAsync`.
987
+
988
+
-**Parameters**
989
+
-`eventEmitter` - The event emitter returned by `fs.watchAsync` that you wish to stop watching.
990
+
-**Throws**
991
+
- Throws an error (`Errors.EINVAL`) if the watcher is already closed or if operations are attempted after closing.
0 commit comments