* Subscribe to changes at the given file or directory.
(
includes: string[],
excludes: string[],
listener?: (evt?: FileWatchEvent) => void
)
| 172 | * Subscribe to changes at the given file or directory. |
| 173 | */ |
| 174 | public async watch( |
| 175 | includes: string[], |
| 176 | excludes: string[], |
| 177 | listener?: (evt?: FileWatchEvent) => void |
| 178 | ): Promise<{ dispose: () => Promise<void> }> { |
| 179 | const watcherId = cuid(); |
| 180 | |
| 181 | await this.channel.send('fs/watch', { watcherId, includes, excludes }); |
| 182 | |
| 183 | this.channel.on('fs/watch-event', ({ data }) => { |
| 184 | if (data.watcherId === watcherId && listener) { |
| 185 | const evt = { ...data } as FSWatchEvent; |
| 186 | // @ts-ignore |
| 187 | delete evt.watcherId; |
| 188 | listener(evt); |
| 189 | } |
| 190 | }); |
| 191 | |
| 192 | return { |
| 193 | dispose: () => this.channel.send('fs/unwatch', { watcherId }), |
| 194 | }; |
| 195 | } |
| 196 | } |
no test coverage detected