/**
 * Simple debounced directory watcher for dev auto-restart.
 */
import { watch } from 'fs';
import { dirname } from 'path';
/**
 * Watch a directory recursively for changes and invoke a callback (debounced).
 * Returns the FSWatcher handle for cleanup.
 */
export function watchDirectory(dir, onChange, debounceMs = 500) {
    let timeout;
    return watch(dir, { recursive: true }, () => {
        if (timeout)
            clearTimeout(timeout);
        timeout = setTimeout(onChange, debounceMs);
    });
}
/**
 * Resolve the watch directory from CLI arg.
 * Empty string → auto-detect from process.argv[1] (entry script directory).
 */
export function resolveWatchDir(watchArg) {
    if (watchArg)
        return watchArg;
    return dirname(process.argv[1]);
}
//# sourceMappingURL=file-watcher.js.map