UNPKG

@pulzar/core

Version:

Next-generation Node.js framework for ultra-fast web applications with zero-reflection DI, GraphQL, WebSockets, events, and edge runtime support

51 lines 1.75 kB
import { watch } from "fs"; import { join } from "path"; export class HotReloadManager { watchers = new Map(); options; constructor(options = {}) { this.options = { enabled: options.enabled ?? false, watchPaths: options.watchPaths ?? ["src"], ignorePaths: options.ignorePaths ?? ["node_modules", "dist"], debounceMs: options.debounceMs ?? 300, }; } start() { if (!this.options.enabled) return; this.options.watchPaths.forEach((path) => { this.watchDirectory(path); }); } stop() { this.watchers.forEach((watcher) => watcher.close()); this.watchers.clear(); } watchDirectory(dirPath) { const watcher = watch(dirPath, { recursive: true }, (eventType, filename) => { if (!filename) return; const fullPath = join(dirPath, filename); // Check if file should be ignored if (this.shouldIgnore(fullPath)) return; console.log(`[Hot Reload] ${eventType}: ${filename}`); // Emit reload event this.emitReloadEvent(fullPath, eventType); }); this.watchers.set(dirPath, watcher); } shouldIgnore(path) { return this.options.ignorePaths.some((ignorePath) => path.includes(ignorePath)); } emitReloadEvent(path, eventType) { // In a real implementation, this would trigger a reload // For now, just log the event console.log(`[Hot Reload] Reloading due to ${eventType} on ${path}`); } } export function createHotReloadManager(options) { return new HotReloadManager(options); } //# sourceMappingURL=hot-reload.js.map