Client library for the wch daemon.
Compatible with wchd v0.10
Track a directory indefinitely.
Resolves to true
if successful.
Stop tracking a directory.
Resolves to true
if successful.
This method must be called before any other actions are processed. Whenever not connected, actions are stored in the offline queue.
If the returned promise is rejected, you need to manually call connect
again if you wish to retry. Though, not all errors will reject the promise.
When the wchd
server is unreachable, the promise will stay pending while
the client waits for the server to be restarted.
The connected
and connecting
properties reflect the current state
of the connection.
Force disconnect from the wchd
server.
Stream changes to matching paths within a directory.
The data
event is emitted for every change. Listeners are passed an object representing the affected file.
The close
event is emitted when the stream has its destroy
method called.
The stream manages its subscription as expected whenever the client loses its connection to the server.
The stream is created by the readable-stream library to ensure reliable behavior between NodeJS versions.
Note: You should always handle error
events on a stream,
or your process will easily crash.
Fetch matching paths within a directory.
The query
argument is not yet documented.
The resolved object has the following properties:
root: string
clock: string
files: Object[]
Note: The dir
argument must be within a tracked directory.
Pass a wch-style query to get the expression
property of the equivalent Watchman-style query.
Note: This method doesn't communicate with the server.
Fetch the list of tracked directories.
In addition to events provided by plugins, there are several events provided by the client library.
The socket is attempting to connect (to the wchd
server).
The socket has connected. Emits on reconnect, too.
The wchd
server is unreachable.
The socket lost its connection.
The socket met an error.
Plugins may also use this event to broadcast errors.
Listeners are passed an Error
object.
Note: You should always listen for this event.