@@ -18,14 +18,14 @@ class CssWatcher {
1818 this . patterns = patterns ;
1919 // Ignore hidden files by default
2020 this . ignorePatterns = [ '**/.*' , ...ignore ] ;
21- this . setupWatcher ( ) ;
22- }
23- setupWatcher ( ) {
24- // Set up chokidar with appropriate options
2521 const cwd = process . cwd ( ) ;
22+ this . setupWatcher ( cwd ) ;
23+ this . initialScan ( cwd ) ;
24+ }
25+ setupWatcher ( cwd ) {
2626 this . watcher = chokidar_1 . default . watch ( cwd , {
2727 persistent : true ,
28- ignoreInitial : false , // This ensures we get the initial scan
28+ ignoreInitial : true , // We need to do our initial scan synchronously
2929 ignored : ( path , stats ) => {
3030 return ( micromatch_1 . default . isMatch ( path , this . ignorePatterns ) ||
3131 ! ! ( ( stats === null || stats === void 0 ? void 0 : stats . isFile ( ) ) && ! micromatch_1 . default . isMatch ( path , this . patterns ) ) ) ;
@@ -39,7 +39,6 @@ class CssWatcher {
3939 // Setup event handlers
4040 this . watcher
4141 . on ( 'add' , ( filePath ) => {
42- console . log ( '!!' , filePath ) ;
4342 this . updateClassesForFile ( filePath ) ;
4443 } )
4544 . on ( 'change' , ( filePath ) => {
@@ -53,9 +52,9 @@ class CssWatcher {
5352 console . error ( `Watcher error: ${ error } ` ) ;
5453 } ) ;
5554 }
56- async updateClassesForFile ( filePath ) {
55+ updateClassesForFile ( filePath ) {
5756 try {
58- const content = await fs_1 . default . promises . readFile ( filePath , 'utf8' ) ;
57+ const content = fs_1 . default . readFileSync ( filePath , 'utf8' ) ;
5958 const fileClasses = ( 0 , css_extractor_1 . extractClassesFromCss ) ( content ) ;
6059 this . state . fileClasses . set ( filePath , new Set ( fileClasses ) ) ;
6160 this . state . lastUpdate = Date . now ( ) ;
@@ -65,6 +64,25 @@ class CssWatcher {
6564 this . state . fileClasses . delete ( filePath ) ;
6665 }
6766 }
67+ initialScan ( cwd ) {
68+ const dirs = [ cwd ] ;
69+ for ( const dir of dirs ) {
70+ const entries = fs_1 . default . readdirSync ( dir ) ;
71+ for ( const entry of entries ) {
72+ const fullPath = `${ dir } /${ entry } ` ;
73+ if ( micromatch_1 . default . isMatch ( fullPath , this . ignorePatterns ) ) {
74+ continue ;
75+ }
76+ const stats = fs_1 . default . statSync ( fullPath ) ;
77+ if ( stats . isDirectory ( ) ) {
78+ dirs . push ( fullPath ) ;
79+ }
80+ else if ( stats . isFile ( ) && micromatch_1 . default . isMatch ( fullPath , this . patterns ) ) {
81+ this . updateClassesForFile ( fullPath ) ;
82+ }
83+ }
84+ }
85+ }
6886 hasClass ( className ) {
6987 for ( const classes of this . state . fileClasses . values ( ) ) {
7088 if ( classes . has ( className ) ) {
0 commit comments