1- import type { Stats } from 'node:fs' ;
21import chokidar , { type FSWatcher } from 'chokidar' ;
3- import type { Logger } from './logger/logger.js' ;
4- import { createProject , type Project } from './project.js' ;
5-
6- interface RunnerArgs {
7- project : string ;
8- clean : boolean ;
9- }
2+ import { type Project } from './project.js' ;
103
114export interface Watcher {
125 /** Exported for testing purposes */
@@ -27,36 +20,17 @@ export interface Watcher {
2720 * @throws {WriteDtsFileError }
2821 * @throws {WatchInitializationError }
2922 */
30- export async function runCMKInWatchMode ( args : RunnerArgs , logger : Logger ) : Promise < Watcher > {
23+ export async function runCMKInWatchMode ( rootDir : string ) : Promise < void > {
3124 const fsWatchers : FSWatcher [ ] = [ ] ;
32- const project = createProject ( args ) ;
3325
3426 // Watch project files and report diagnostics on changes
3527 const readyPromises : Promise < void > [ ] = [ ] ;
36- for ( const wildcardDirectory of project . config . wildcardDirectories ) {
28+ for ( const wildcardDirectory of [ { fileName : rootDir } ] ) {
3729 const { promise, resolve } = promiseWithResolvers < void > ( ) ;
3830 readyPromises . push ( promise ) ;
3931 fsWatchers . push (
4032 chokidar
41- . watch ( wildcardDirectory . fileName , {
42- ignored : ( fileName : string , stats ?: Stats ) => {
43- // The ignored function is called twice for the same path. The first time with stats undefined,
44- // and the second time with stats provided.
45- // In the first call, we can't determine if the path is a directory or file.
46- // So we include it in the watch target considering it might be a directory.
47- if ( ! stats ) return false ;
48-
49- // In the second call, we include directories or files that match wildcards in the watch target.
50- // However, `dtsOutDir` is excluded from the watch target.
51- if ( stats . isDirectory ( ) ) {
52- return fileName === project . config . dtsOutDir ;
53- } else {
54- return ! project . isWildcardMatchedFile ( fileName ) ;
55- }
56- } ,
57- ignoreInitial : true ,
58- ...( wildcardDirectory . recursive ? { } : { depth : 0 } ) ,
59- } )
33+ . watch ( wildcardDirectory . fileName , { ignoreInitial : true } )
6034 . on ( 'change' , ( fileName ) => {
6135 console . log ( 'change event: ' , fileName ) ;
6236 if ( fileName . endsWith ( 'a.module.css' ) ) {
@@ -70,8 +44,6 @@ export async function runCMKInWatchMode(args: RunnerArgs, logger: Logger): Promi
7044 ) ;
7145 }
7246 await Promise . all ( readyPromises ) ;
73-
74- return { project } ;
7547}
7648
7749function promiseWithResolvers < T > ( ) {
0 commit comments