@@ -60,11 +60,14 @@ namespace ts {
60
60
watcher : FileWatcher ;
61
61
/** ref count keeping this directory watch alive */
62
62
refCount : number ;
63
+ /** is the directory watched being non recursive */
64
+ nonRecursive ?: boolean ;
63
65
}
64
66
65
67
interface DirectoryOfFailedLookupWatch {
66
68
dir : string ;
67
69
dirPath : Path ;
70
+ nonRecursive ?: boolean ;
68
71
ignore ?: true ;
69
72
}
70
73
@@ -251,7 +254,6 @@ namespace ts {
251
254
perDirectoryResolution = createMap ( ) ;
252
255
perDirectoryCache . set ( dirPath , perDirectoryResolution ) ;
253
256
}
254
-
255
257
const resolvedModules : R [ ] = [ ] ;
256
258
const compilerOptions = resolutionHost . getCompilationSettings ( ) ;
257
259
const hasInvalidatedNonRelativeUnresolvedImport = logChanges && isFileWithInvalidatedNonRelativeUnresolvedImports ( path ) ;
@@ -393,6 +395,7 @@ namespace ts {
393
395
394
396
function getDirectoryToWatchFailedLookupLocation ( failedLookupLocation : string , failedLookupLocationPath : Path ) : DirectoryOfFailedLookupWatch {
395
397
if ( isInDirectoryPath ( rootPath , failedLookupLocationPath ) ) {
398
+ // Always watch root directory recursively
396
399
return { dir : rootDir ! , dirPath : rootPath } ; // TODO: GH#18217
397
400
}
398
401
@@ -409,11 +412,12 @@ namespace ts {
409
412
dirPath = getDirectoryPath ( dirPath ) ;
410
413
}
411
414
412
- // If the directory is node_modules use it to watch
415
+ // If the directory is node_modules use it to watch, always watch it recursively
413
416
if ( isNodeModulesDirectory ( dirPath ) ) {
414
417
return filterFSRootDirectoriesToWatch ( { dir, dirPath } , getDirectoryPath ( dirPath ) ) ;
415
418
}
416
419
420
+ let nonRecursive = true ;
417
421
// Use some ancestor of the root directory
418
422
let subDirectoryPath : Path | undefined , subDirectory : string | undefined ;
419
423
if ( rootPath !== undefined ) {
@@ -422,14 +426,15 @@ namespace ts {
422
426
if ( parentPath === dirPath ) {
423
427
break ;
424
428
}
429
+ nonRecursive = false ;
425
430
subDirectoryPath = dirPath ;
426
431
subDirectory = dir ;
427
432
dirPath = parentPath ;
428
433
dir = getDirectoryPath ( dir ) ;
429
434
}
430
435
}
431
436
432
- return filterFSRootDirectoriesToWatch ( { dir : subDirectory || dir , dirPath : subDirectoryPath || dirPath } , dirPath ) ;
437
+ return filterFSRootDirectoriesToWatch ( { dir : subDirectory || dir , dirPath : subDirectoryPath || dirPath , nonRecursive } , dirPath ) ;
433
438
}
434
439
435
440
function isPathWithDefaultFailedLookupExtension ( path : Path ) {
@@ -452,7 +457,7 @@ namespace ts {
452
457
let setAtRoot = false ;
453
458
for ( const failedLookupLocation of failedLookupLocations ) {
454
459
const failedLookupLocationPath = resolutionHost . toPath ( failedLookupLocation ) ;
455
- const { dir, dirPath, ignore } = getDirectoryToWatchFailedLookupLocation ( failedLookupLocation , failedLookupLocationPath ) ;
460
+ const { dir, dirPath, nonRecursive , ignore } = getDirectoryToWatchFailedLookupLocation ( failedLookupLocation , failedLookupLocationPath ) ;
456
461
if ( ! ignore ) {
457
462
// If the failed lookup location path is not one of the supported extensions,
458
463
// store it in the custom path
@@ -464,23 +469,25 @@ namespace ts {
464
469
setAtRoot = true ;
465
470
}
466
471
else {
467
- setDirectoryWatcher ( dir , dirPath ) ;
472
+ setDirectoryWatcher ( dir , dirPath , nonRecursive ) ;
468
473
}
469
474
}
470
475
}
471
476
472
477
if ( setAtRoot ) {
478
+ // This is always recursive
473
479
setDirectoryWatcher ( rootDir ! , rootPath ) ; // TODO: GH#18217
474
480
}
475
481
}
476
482
477
- function setDirectoryWatcher ( dir : string , dirPath : Path ) {
483
+ function setDirectoryWatcher ( dir : string , dirPath : Path , nonRecursive ?: boolean ) {
478
484
const dirWatcher = directoryWatchesOfFailedLookups . get ( dirPath ) ;
479
485
if ( dirWatcher ) {
486
+ Debug . assert ( ! ! nonRecursive === ! ! dirWatcher . nonRecursive ) ;
480
487
dirWatcher . refCount ++ ;
481
488
}
482
489
else {
483
- directoryWatchesOfFailedLookups . set ( dirPath , { watcher : createDirectoryWatcher ( dir , dirPath ) , refCount : 1 } ) ;
490
+ directoryWatchesOfFailedLookups . set ( dirPath , { watcher : createDirectoryWatcher ( dir , dirPath , nonRecursive ) , refCount : 1 , nonRecursive } ) ;
484
491
}
485
492
}
486
493
@@ -530,7 +537,7 @@ namespace ts {
530
537
dirWatcher . refCount -- ;
531
538
}
532
539
533
- function createDirectoryWatcher ( directory : string , dirPath : Path ) {
540
+ function createDirectoryWatcher ( directory : string , dirPath : Path , nonRecursive : boolean | undefined ) {
534
541
return resolutionHost . watchDirectoryOfFailedLookupLocation ( directory , fileOrDirectory => {
535
542
const fileOrDirectoryPath = resolutionHost . toPath ( fileOrDirectory ) ;
536
543
if ( cachedDirectoryStructureHost ) {
@@ -541,7 +548,7 @@ namespace ts {
541
548
if ( ! allFilesHaveInvalidatedResolution && invalidateResolutionOfFailedLookupLocation ( fileOrDirectoryPath , dirPath === fileOrDirectoryPath ) ) {
542
549
resolutionHost . onInvalidatedResolution ( ) ;
543
550
}
544
- } , WatchDirectoryFlags . Recursive ) ;
551
+ } , nonRecursive ? WatchDirectoryFlags . None : WatchDirectoryFlags . Recursive ) ;
545
552
}
546
553
547
554
function removeResolutionsOfFileFromCache ( cache : Map < Map < ResolutionWithFailedLookupLocations > > , filePath : Path ) {
0 commit comments