11import { readFileSync } from 'node:fs'
2- import { dirname , resolve , relative , basename , matchesGlob } from 'node:path'
2+ import { dirname , resolve , basename } from 'node:path'
33import { fileURLToPath } from 'node:url'
44import { createRequire } from 'node:module'
55import { createServer , createLogger , type ViteDevServer } from 'vite'
@@ -18,6 +18,7 @@ import { serveCompatibility } from './server/compatibility.ts'
1818import { serveLint } from './server/linter.ts'
1919import { sendEmail } from './server/email.ts'
2020import { normalizeComponentSources } from './utils/componentSources.ts'
21+ import { createWatchedFileMatcher } from './utils/watchPaths.ts'
2122import type { MaizzleConfig } from './types/index.ts'
2223
2324const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
@@ -166,15 +167,7 @@ function maizzleDevPlugin(
166167
167168 const userWatchPaths = config . server ?. watch ?? [ ]
168169 const watchPaths = [ ...defaultWatchPaths , ...userWatchPaths ]
169- // Strip a leading "./" so chokidar-style relative globs match correctly.
170- const normalizePattern = ( p : string ) => p . replace ( / ^ \. \/ / , '' )
171- // Chokidar emits absolute paths on change. Match against project-relative
172- // form so relative globs like "locales/**" actually hit.
173- const cwd = config . root ?? process . cwd ( )
174- const isWatchedFile = ( file : string ) => {
175- const rel = relative ( cwd , file ) . replace ( / \\ / g, '/' )
176- return watchPaths . some ( p => matchesGlob ( rel , normalizePattern ( p ) ) )
177- }
170+ const isWatchedFile = createWatchedFileMatcher ( watchPaths , config . root ?? process . cwd ( ) )
178171
179172 for ( const watchPath of watchPaths ) {
180173 server . watcher . add ( watchPath )
0 commit comments