function toWatchableRoot
toWatchableRoot(lookupPath: string): string

Maps a lookup path to a path fs.watch can actually watch. A real file or directory is returned as-is; a glob is walked up to the deepest ancestor directory that exists — its base dir — which fs.watch can watch recursively (test/x/!(plugin).ts collapses to test/x).

import * as FileWatcher from './file-watcher.ts';

FileWatcher.toWatchableRoot('/tmp'); // '/tmp' — a real path is watchable as-is
FileWatcher.toWatchableRoot('/tmp/absent/!(skip)-test.ts'); // '/tmp' — a glob collapses to its deepest existing ancestor

Parameters

lookupPath: string

Return Type

string

Usage

import { toWatchableRoot } from "lib/setup/file-watcher.ts";