@@ -262,8 +262,7 @@ function isInDirectoryPath(dirComponents: Readonly<PathPathComponents>, fileOrDi
262
262
}
263
263
264
264
function canWatchAffectedPackageJsonOrNodeModulesOfAtTypes ( fileOrDirPath : Path ) {
265
- const fileOrDirPathComponents = getPathComponents ( fileOrDirPath ) ;
266
- return fileOrDirPathComponents . length > perceivedOsRootLengthForWatching ( fileOrDirPathComponents , fileOrDirPathComponents . length ) + 1 ;
265
+ return canWatchDirectoryOrFile ( getPathComponents ( fileOrDirPath ) ) ;
267
266
}
268
267
269
268
/** @internal */
@@ -309,17 +308,31 @@ export function getDirectoryToWatchFailedLookupLocation(
309
308
) ;
310
309
}
311
310
311
+ function getDirectoryToWatchFailedLookupLocationNodeModules (
312
+ dirPathComponents : Readonly < PathPathComponents > ,
313
+ ) {
314
+ // If directory path contains node module, get the most parent node_modules directory for watching
315
+ const indexOfNodeModules = dirPathComponents . indexOf ( "node_modules" as Path ) ;
316
+ if ( indexOfNodeModules !== - 1 ) {
317
+ // If the directory is node_modules use it to watch, always watch it recursively
318
+ return canWatchDirectoryOrFile ( dirPathComponents , indexOfNodeModules + 1 ) ?
319
+ indexOfNodeModules + 1 :
320
+ false ;
321
+ }
322
+ return undefined ;
323
+ }
324
+
312
325
function getDirectoryToWatchFromFailedLookupLocationDirectory (
313
326
dirComponents : readonly string [ ] ,
314
327
dirPathComponents : Readonly < PathPathComponents > ,
315
328
rootPathComponents : Readonly < PathPathComponents > ,
316
329
) : DirectoryOfFailedLookupWatch | undefined {
317
330
// If directory path contains node module, get the most parent node_modules directory for watching
318
- const indexOfNodeModules = dirPathComponents . indexOf ( "node_modules" as Path ) ;
319
- if ( indexOfNodeModules !== - 1 ) {
331
+ const nodeModulesWatchLength = getDirectoryToWatchFailedLookupLocationNodeModules ( dirPathComponents ) ;
332
+ if ( nodeModulesWatchLength !== undefined ) {
320
333
// If the directory is node_modules use it to watch, always watch it recursively
321
- return canWatchDirectoryOrFile ( dirPathComponents , indexOfNodeModules + 1 ) ?
322
- getDirectoryOfFailedLookupWatch ( dirComponents , dirPathComponents , indexOfNodeModules + 1 ) :
334
+ return nodeModulesWatchLength ?
335
+ getDirectoryOfFailedLookupWatch ( dirComponents , dirPathComponents , nodeModulesWatchLength ) :
323
336
undefined ;
324
337
}
325
338
// Use some ancestor of the root directory
0 commit comments