UNPKG

@farmfe/core

Version:

Farm is a extremely fast web build tool written in Rust. Farm can start a project in milliseconds and perform HMR within 10ms, making it much faster than similar tools like webpack and vite.

46 lines 1.59 kB
import { existsSync } from 'fs'; import { createWatcher } from './create-watcher.js'; export class ConfigWatcher { constructor(resolvedUserConfig) { this.resolvedUserConfig = resolvedUserConfig; this._close = false; if (!resolvedUserConfig) { throw new Error('Invalid resolvedUserConfig provided to Farm JsConfigWatcher'); } } watch(callback) { async function handle(file) { callback(file); } const watchedFilesSet = new Set([ ...(this.resolvedUserConfig.envFiles ?? []), ...(this.resolvedUserConfig.configFileDependencies ?? []), ...(this.resolvedUserConfig.configFilePath ? [this.resolvedUserConfig.configFilePath] : []) ]); const watchedFiles = Array.from(watchedFilesSet).filter((file) => file && existsSync(file)); const chokidarOptions = { awaitWriteFinish: process.platform === 'linux' ? undefined : { stabilityThreshold: 10, pollInterval: 80 } }; this.watcher = createWatcher(this.resolvedUserConfig, watchedFiles, chokidarOptions); this.watcher.on('change', (path) => { if (this._close) return; if (watchedFiles.includes(path)) { handle([path]); } }); return this; } close() { this._close = true; this.watcher = null; } } //# sourceMappingURL=config-watcher.js.map