@@ -219,16 +219,20 @@ export function getDirectoryPath(posixPath: string): string {
219219 return dir ;
220220}
221221
222+ function isNodeModulesSegment ( lookupKey : string ) : boolean {
223+ return lookupKey === NODE_MODULES || lookupKey . endsWith ( `/${ NODE_MODULES } ` ) ;
224+ }
225+
222226/**
223227 * Determines whether a file path lookup key or any of its parent directories are present in watchedFiles.
224228 */
225- function isPathWatched ( fileLookupKey : string , watchedFiles : Set < string > ) : boolean {
229+ function isPathWatched ( fileLookupKey : string , watchedFiles : ReadonlySet < string > ) : boolean {
226230 if ( watchedFiles . has ( fileLookupKey ) ) {
227231 return true ;
228232 }
229233
230234 let current = fileLookupKey ;
231- while ( true ) {
235+ while ( ! isNodeModulesSegment ( current ) ) {
232236 const parent = getDirectoryPath ( current ) ;
233237 if ( parent === current ) {
234238 break ;
@@ -1111,8 +1115,8 @@ function createChokidarIgnored(
11111115 } ) ?? [ ] ;
11121116
11131117 // When watching a directory (e.g. projectRoot via NG_BUILD_WATCH_ROOT), prune `node_modules`
1114- // directories unless explicitly added to `watchedFiles`. Explicitly added files inside
1115- // `node_modules` do not end with `/node_modules` and remain watchable .
1118+ // directories and any unwatched descendants inside `node_modules` (since Chokidar 6 keeps
1119+ // ancestor directories of explicitly watched package files un-ignored to traverse to them) .
11161120 return [
11171121 ...customIgnored ,
11181122 ( filePath : string ) => {
@@ -1122,11 +1126,15 @@ function createChokidarIgnored(
11221126
11231127 const posixPath = toPosixPathNormalized ( filePath ) ;
11241128 const lookupKey = toLookupKey ( posixPath , isCaseSensitive ) ;
1129+ if (
1130+ ! isNodeModulesSegment ( lookupKey ) &&
1131+ ! lookupKey . includes ( `/${ NODE_MODULES } /` ) &&
1132+ ! lookupKey . startsWith ( `${ NODE_MODULES } /` )
1133+ ) {
1134+ return false ;
1135+ }
11251136
1126- return (
1127- ( lookupKey === NODE_MODULES || lookupKey . endsWith ( `/${ NODE_MODULES } ` ) ) &&
1128- ! watchedFiles . has ( lookupKey )
1129- ) ;
1137+ return ! isPathWatched ( lookupKey , watchedFiles ) ;
11301138 } ,
11311139 ] ;
11321140}
0 commit comments