function handleWatchEvent
handleWatchEvent(
config: Config,
extensions: string[],
event: string,
filePath: string,
onEventFunc: (
event: string,
file: string
) => unknown
,
onFinishFunc: ((
path: string,
event: string
) => void) | null | undefined
): Promise<void>

Routes a file-system event to fsTree mutation and optional rebuild trigger. unlinkDir bypasses the extension filter so deleted directories always clean up fsTree. When a build is already in progress, queues the event as a pending trigger (last-write-wins).

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

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

// Defined, not invoked: mutates the live fsTree and dispatches a rebuild.
function onSave(config: Config, rebuild: (event: string, file: string) => Promise<void>) {
  return FileWatcher.handleWatchEvent(config, ['js', 'ts'], 'change', '/proj/test/cart-test.ts', rebuild, null);
}

Parameters

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

Return Type

Promise<void>

Usage

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