|
| 1 | +/** |
| 2 | + * @flow strict |
| 3 | + * @format |
| 4 | + */ |
| 5 | + |
| 6 | +declare module 'chokidar' { |
| 7 | + import type {Stats} from 'fs'; |
| 8 | + |
| 9 | + declare export class FSWatcher extends events$EventEmitter { |
| 10 | + options: WatchOptions; |
| 11 | + |
| 12 | + /** |
| 13 | + * Constructs a new FSWatcher instance with optional WatchOptions parameter. |
| 14 | + */ |
| 15 | + constructor(options?: WatchOptions): this; |
| 16 | + |
| 17 | + /** |
| 18 | + * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one |
| 19 | + * string. |
| 20 | + */ |
| 21 | + add(paths: string | $ReadOnlyArray<string>): this; |
| 22 | + |
| 23 | + /** |
| 24 | + * Stop watching files, directories, or glob patterns. Takes an array of strings or just one |
| 25 | + * string. |
| 26 | + */ |
| 27 | + unwatch(paths: string | $ReadOnlyArray<string>): this; |
| 28 | + |
| 29 | + /** |
| 30 | + * Returns an object representing all the paths on the file system being watched by this |
| 31 | + * `FSWatcher` instance. The object's keys are all the directories (using absolute paths unless |
| 32 | + * the `cwd` option was used), and the values are arrays of the names of the items contained in |
| 33 | + * each directory. |
| 34 | + */ |
| 35 | + getWatched(): { |
| 36 | + [directory: string]: string[], |
| 37 | + }; |
| 38 | + |
| 39 | + /** |
| 40 | + * Removes all listeners from watched files. |
| 41 | + */ |
| 42 | + close(): Promise<void>; |
| 43 | + |
| 44 | + on( |
| 45 | + event: 'add' | 'addDir' | 'change', |
| 46 | + listener: (path: string, stats?: Stats) => void, |
| 47 | + ): this; |
| 48 | + |
| 49 | + on( |
| 50 | + event: 'all', |
| 51 | + listener: ( |
| 52 | + eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', |
| 53 | + path: string, |
| 54 | + stats?: Stats, |
| 55 | + ) => void, |
| 56 | + ): this; |
| 57 | + |
| 58 | + /** |
| 59 | + * Error occurred |
| 60 | + */ |
| 61 | + on(event: 'error', listener: (error: Error) => void): this; |
| 62 | + |
| 63 | + /** |
| 64 | + * Exposes the native Node `fs.FSWatcher events` |
| 65 | + */ |
| 66 | + on( |
| 67 | + event: 'raw', |
| 68 | + listener: (eventName: string, path: string, details: any) => void, |
| 69 | + ): this; |
| 70 | + |
| 71 | + /** |
| 72 | + * Fires when the initial scan is complete |
| 73 | + */ |
| 74 | + on(event: 'ready', listener: () => void): this; |
| 75 | + |
| 76 | + on(event: 'unlink' | 'unlinkDir', listener: (path: string) => void): this; |
| 77 | + |
| 78 | + on(event: string, listener: (...args: any[]) => void): this; |
| 79 | + } |
| 80 | + |
| 81 | + declare export interface WatchOptions { |
| 82 | + /** |
| 83 | + * Indicates whether the process should continue to run as long as files are being watched. If |
| 84 | + * set to `false` when using `fsevents` to watch, no more events will be emitted after `ready`, |
| 85 | + * even if the process continues to run. |
| 86 | + */ |
| 87 | + persistent?: boolean; |
| 88 | + |
| 89 | + /** |
| 90 | + * ([anymatch](https://github.com/micromatch/anymatch)-compatible definition) Defines files/paths to |
| 91 | + * be ignored. The whole relative or absolute path is tested, not just filename. If a function |
| 92 | + * with two arguments is provided, it gets called twice per path - once with a single argument |
| 93 | + * (the path), second time with two arguments (the path and the |
| 94 | + * [`Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object of that path). |
| 95 | + */ |
| 96 | + ignored?: string | Array<string>; |
| 97 | + |
| 98 | + /** |
| 99 | + * If set to `false` then `add`/`addDir` events are also emitted for matching paths while |
| 100 | + * instantiating the watching as chokidar discovers these file paths (before the `ready` event). |
| 101 | + */ |
| 102 | + ignoreInitial?: boolean; |
| 103 | + |
| 104 | + /** |
| 105 | + * When `false`, only the symlinks themselves will be watched for changes instead of following |
| 106 | + * the link references and bubbling events through the link's path. |
| 107 | + */ |
| 108 | + followSymlinks?: boolean; |
| 109 | + |
| 110 | + /** |
| 111 | + * The base directory from which watch `paths` are to be derived. Paths emitted with events will |
| 112 | + * be relative to this. |
| 113 | + */ |
| 114 | + cwd?: string; |
| 115 | + |
| 116 | + /** |
| 117 | + * If set to true then the strings passed to .watch() and .add() are treated as literal path |
| 118 | + * names, even if they look like globs. Default: false. |
| 119 | + */ |
| 120 | + disableGlobbing?: boolean; |
| 121 | + |
| 122 | + /** |
| 123 | + * Whether to use fs.watchFile (backed by polling), or fs.watch. If polling leads to high CPU |
| 124 | + * utilization, consider setting this to `false`. It is typically necessary to **set this to |
| 125 | + * `true` to successfully watch files over a network**, and it may be necessary to successfully |
| 126 | + * watch files in other non-standard situations. Setting to `true` explicitly on OS X overrides |
| 127 | + * the `useFsEvents` default. |
| 128 | + */ |
| 129 | + usePolling?: boolean; |
| 130 | + |
| 131 | + /** |
| 132 | + * Whether to use the `fsevents` watching interface if available. When set to `true` explicitly |
| 133 | + * and `fsevents` is available this supercedes the `usePolling` setting. When set to `false` on |
| 134 | + * OS X, `usePolling: true` becomes the default. |
| 135 | + */ |
| 136 | + useFsEvents?: boolean; |
| 137 | + |
| 138 | + /** |
| 139 | + * If relying upon the [`Stats`](https://nodejs.org/api/fs.html#fs_class_fs_stats) object that |
| 140 | + * may get passed with `add`, `addDir`, and `change` events, set this to `true` to ensure it is |
| 141 | + * provided even in cases where it wasn't already available from the underlying watch events. |
| 142 | + */ |
| 143 | + alwaysStat?: boolean; |
| 144 | + |
| 145 | + /** |
| 146 | + * If set, limits how many levels of subdirectories will be traversed. |
| 147 | + */ |
| 148 | + depth?: number; |
| 149 | + |
| 150 | + /** |
| 151 | + * Interval of file system polling. |
| 152 | + */ |
| 153 | + interval?: number; |
| 154 | + |
| 155 | + /** |
| 156 | + * Interval of file system polling for binary files. ([see list of binary extensions](https://gi |
| 157 | + * thub.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json)) |
| 158 | + */ |
| 159 | + binaryInterval?: number; |
| 160 | + |
| 161 | + /** |
| 162 | + * Indicates whether to watch files that don't have read permissions if possible. If watching |
| 163 | + * fails due to `EPERM` or `EACCES` with this set to `true`, the errors will be suppressed |
| 164 | + * silently. |
| 165 | + */ |
| 166 | + ignorePermissionErrors?: boolean; |
| 167 | + |
| 168 | + /** |
| 169 | + * `true` if `useFsEvents` and `usePolling` are `false`). Automatically filters out artifacts |
| 170 | + * that occur when using editors that use "atomic writes" instead of writing directly to the |
| 171 | + * source file. If a file is re-added within 100 ms of being deleted, Chokidar emits a `change` |
| 172 | + * event rather than `unlink` then `add`. If the default of 100 ms does not work well for you, |
| 173 | + * you can override it by setting `atomic` to a custom value, in milliseconds. |
| 174 | + */ |
| 175 | + atomic?: boolean | number; |
| 176 | + |
| 177 | + /** |
| 178 | + * can be set to an object in order to adjust timing params: |
| 179 | + */ |
| 180 | + awaitWriteFinish?: AwaitWriteFinishOptions | boolean; |
| 181 | + } |
| 182 | + |
| 183 | + declare export interface AwaitWriteFinishOptions { |
| 184 | + /** |
| 185 | + * Amount of time in milliseconds for a file size to remain constant before emitting its event. |
| 186 | + */ |
| 187 | + stabilityThreshold?: number; |
| 188 | + |
| 189 | + /** |
| 190 | + * File size polling interval. |
| 191 | + */ |
| 192 | + pollInterval?: number; |
| 193 | + } |
| 194 | + |
| 195 | + /** |
| 196 | + * produces an instance of `FSWatcher`. |
| 197 | + */ |
| 198 | + declare export function watch( |
| 199 | + paths: string | $ReadOnlyArray<string>, |
| 200 | + options?: WatchOptions, |
| 201 | + ): FSWatcher; |
| 202 | +} |
0 commit comments