* @param {VirtualProvider} provider The VFS provider * @param {string} path The path to watch (provider-relative) * @param {object} [options] Options * @param {number} [options.interval] Polling interval in ms (default: 100) * @param {boolean} [options.persistent] Keep process alive (def
(provider, path, options = kEmptyObject)
| 49 | * @param {AbortSignal} [options.signal] AbortSignal for cancellation |
| 50 | */ |
| 51 | constructor(provider, path, options = kEmptyObject) { |
| 52 | super(); |
| 53 | |
| 54 | this.#vfs = provider; |
| 55 | this.#path = path; |
| 56 | this.#interval = options.interval ?? 100; |
| 57 | this.#persistent = options.persistent !== false; |
| 58 | this.#recursive = options.recursive === true; |
| 59 | this.#encoding = options.encoding; |
| 60 | this.#trackedFiles = new SafeMap(); // path -> { stats, relativePath } |
| 61 | this.#signal = options.signal; |
| 62 | |
| 63 | // Handle AbortSignal |
| 64 | if (this.#signal) { |
| 65 | if (this.#signal.aborted) { |
| 66 | this.close(); |
| 67 | return; |
| 68 | } |
| 69 | this.#abortHandler = () => this.close(); |
| 70 | this.#signal.addEventListener('abort', this.#abortHandler, { once: true }); |
| 71 | } |
| 72 | |
| 73 | // Get initial stats |
| 74 | this.#lastStats = this.#getStats(); |
| 75 | |
| 76 | // If watching a directory, build file list |
| 77 | if (this.#lastStats?.isDirectory()) { |
| 78 | if (this.#recursive) { |
| 79 | this.#buildFileList(this.#path, ''); |
| 80 | } else { |
| 81 | this.#buildChildList(this.#path); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Start polling |
| 86 | this.#startPolling(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Encodes a filename according to the watcher's encoding option. |
nothing calls this directly
no test coverage detected