diff --git a/packages/vite/src/node/watch.ts b/packages/vite/src/node/watch.ts index e04f6a62769b78..a1718ffb25166a 100644 --- a/packages/vite/src/node/watch.ts +++ b/packages/vite/src/node/watch.ts @@ -45,6 +45,14 @@ class NoopWatcher extends EventEmitter implements FSWatcher { return {} } + ref() { + return this + } + + unref() { + return this + } + async close() { // noop } diff --git a/packages/vite/src/types/chokidar.d.ts b/packages/vite/src/types/chokidar.d.ts index 36ae23279c7349..44d500f6a3ba9c 100644 --- a/packages/vite/src/types/chokidar.d.ts +++ b/packages/vite/src/types/chokidar.d.ts @@ -40,6 +40,19 @@ export class FSWatcher extends EventEmitter implements fs.FSWatcher { */ constructor(options?: WatchOptions) + /** + * When called, requests that the Node.js event loop not exit so long as the fs.FSWatcher is active. + * Calling watcher.ref() multiple times will have no effect. + */ + ref(): this + + /** + * When called, the active fs.FSWatcher object will not require the Node.js event loop to remain active. + * If there is no other activity keeping the event loop running, the process may exit before the fs.FSWatcher object's callback is invoked. + * Calling watcher.unref() multiple times will have no effect. + */ + unref(): this + /** * Add files, directories, or glob patterns for tracking. Takes an array of strings or just one * string.