function setup
setup(
testFileLookupPaths: string[],
config: Config,
onEventFunc: (
event: string,
file: string
) => unknown
,
onFinishFunc: ((
path: string,
event: string
) => void) | null | undefined
): { fileWatchers: Record<string, FSWatcher>; killFileWatchers: () => Record<string, FSWatcher>; ready: Promise<void>; }

Starts fs.watch watchers for each lookup path and calls onEventFunc on JS/TS file changes, debounced via a per-file timestamp. Also watches each path's parent directory to detect when a watched directory is renamed or deleted (since fs.watch tracks by inode, not path). Uses config.fsTree to distinguish unlink (tracked file) from unlinkDir (directory) on deletion.

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

import type { Config } from '../types.ts';

// Defined, not invoked: starts real fs.watch watchers on the lookup paths.
async function watch(config: Config, onEvent: (event: string, file: string) => unknown) {
  const watchers = FileWatcher.setup(config.testFileLookupPaths, config, onEvent, null);
  await watchers.ready; // no event is processed before the content-hash seed completes
  return watchers.killFileWatchers; // teardown: closes every watcher, poller and timer
}

Parameters

testFileLookupPaths: string[]
config: Config
onEventFunc: (
event: string,
file: string
) => unknown
onFinishFunc: ((
path: string,
event: string
) => void) | null | undefined

Return Type

{ fileWatchers: Record<string, FSWatcher>; killFileWatchers: () => Record<string, FSWatcher>; ready: Promise<void>; }

Usage

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