paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
11.01k stars 582 forks source link

Make `closed` private #1357

Closed benmccann closed 1 month ago

benmccann commented 1 month ago

Describe the bug

In v3 close() returned Promise<void>. https://github.com/paulmillr/chokidar/pull/1356 was just merged which turns it to Promise<void> | undefined, but this doesn't feel like the correct solution to me. The only way it can return undefined is if the user does watcher.closed = true followed by watcher.close().

Expected behavior

I don't think the user should be able to directly set watcher.closed as it skips all of the other cleanup. It also makes migration from v3 to v4 more difficult by changing the type signature of close()

Additional context

See https://github.com/paulmillr/chokidar/pull/1356 and the issue it closed https://github.com/paulmillr/chokidar/issues/1355 for more details. There was an unresolved question about this on the PR https://github.com/paulmillr/chokidar/pull/1356#discussion_r1765000077, but unfortunately I didn't have a chance to chime in.

43081j commented 1 month ago

Whatever the internal logic of it, we should return a promise I think

Returning undefined right now is like leaking the underlying internal logic. It should be hidden away