You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 6.3KB

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