(folder)
| 119 | } |
| 120 | |
| 121 | #watchFolder(folder) { |
| 122 | const { readdirSync } = lazyLoadFsSync(); |
| 123 | |
| 124 | try { |
| 125 | const files = readdirSync(folder, { |
| 126 | withFileTypes: true, |
| 127 | }); |
| 128 | |
| 129 | for (const file of files) { |
| 130 | if (this.#closed) { |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | const f = pathJoin(folder, file.name); |
| 135 | const relativePath = pathRelative(this.#rootPath, f); |
| 136 | |
| 137 | // Skip watching ignored paths entirely to avoid kernel resource pressure |
| 138 | if (this.#ignoreMatcher?.(relativePath)) { |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | if (!this.#files.has(f)) { |
| 143 | this.emit('change', 'rename', relativePath); |
| 144 | |
| 145 | if (file.isSymbolicLink()) { |
| 146 | this.#symbolicFiles.add(f); |
| 147 | } |
| 148 | |
| 149 | try { |
| 150 | this.#watchFile(f); |
| 151 | if (file.isDirectory() && !file.isSymbolicLink()) { |
| 152 | this.#watchFolder(f); |
| 153 | } |
| 154 | } catch (err) { |
| 155 | // Ignore ENOENT |
| 156 | if (err.code !== 'ENOENT') { |
| 157 | throw err; |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } catch (error) { |
| 163 | if (error.code !== 'ENOENT') { |
| 164 | this.emit('error', error); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | #watchFile(file) { |
| 170 | if (this.#closed) { |
no test coverage detected