import type { BuildConfig } from 'bun'; import path from 'node:path'; import type { StxOptions } from '@stacksjs/stx'; import type { WatchEventType } from 'node:fs'; /** * Debounce a function */ declare function debounce any>(fn: T, delay: number): (...args: Parameters) => void; /** * Create a file watcher for stx templates * * @param options - Watch options * @returns Watcher instance * * @example * ```typescript * const watcher = createWatcher({ * paths: ['./src'], * onChange: (event) => console.log('Changed:', event.path), * }) * * // Later, stop watching * watcher.close() * ``` */ export declare function createWatcher(options?: WatchOptions): WatcherInstance; /** * Watch files and automatically rebuild on changes * * @param options - Watch and build options * @returns Watcher instance * * @example * ```typescript * const watcher = await watchAndBuild({ * entrypoints: ['./src/index.stx'], * outdir: './dist', * onRebuild: (result) => { * if (result.success) { * console.log(`Rebuilt in ${result.duration}ms`) * } else { * console.error('Build failed:', result.errors) * } * }, * }) * ``` */ export declare function watchAndBuild(options: WatchAndBuildOptions): Promise; /** * Start watch mode from CLI * This is used internally by the stx CLI */ export declare function startWatchMode(args: { entrypoints: string[] outdir: string verbose?: boolean stxOptions?: StxOptions }): Promise; /** * Watch mode options */ export declare interface WatchOptions { paths?: string[] patterns?: string[] extensions?: string[] ignore?: string[] debounce?: number onChange?: (event: WatchEvent) => void onError?: (error: Error) => void verbose?: boolean } /** * Watch and build options */ export declare interface WatchAndBuildOptions extends WatchOptions { entrypoints: string[] outdir?: string buildConfig?: Partial stxOptions?: StxOptions onRebuild?: (result: WatchBuildResult) => void } /** * Watch event details */ export declare interface WatchEvent { type: WatchEventType path: string timestamp: number } /** * Watch build result */ export declare interface WatchBuildResult { success: boolean outputs?: string[] errors?: Error[] duration: number triggeredBy: string[] } /** * Watcher instance */ export declare interface WatcherInstance { close: () => void getWatchedPaths: () => string[] addPath: (path: string) => void removePath: (path: string) => void isWatching: () => boolean } export default createWatcher;