@@ -3771,7 +3771,7 @@ function specToDiagnostic(spec: CompilerOptionsValue, disallowTrailingRecursion?
3771
3771
/**
3772
3772
* Gets directories in a set of include patterns that should be watched for changes.
3773
3773
*/
3774
- function getWildcardDirectories ( { validatedIncludeSpecs : include , validatedExcludeSpecs : exclude } : ConfigFileSpecs , path : string , useCaseSensitiveFileNames : boolean ) : MapLike < WatchDirectoryFlags > {
3774
+ function getWildcardDirectories ( { validatedIncludeSpecs : include , validatedExcludeSpecs : exclude } : ConfigFileSpecs , basePath : string , useCaseSensitiveFileNames : boolean ) : MapLike < WatchDirectoryFlags > {
3775
3775
// We watch a directory recursively if it contains a wildcard anywhere in a directory segment
3776
3776
// of the pattern:
3777
3777
//
@@ -3784,23 +3784,26 @@ function getWildcardDirectories({ validatedIncludeSpecs: include, validatedExclu
3784
3784
//
3785
3785
// /a/b/* - Watch /a/b directly to catch any new file
3786
3786
// /a/b/a?z - Watch /a/b directly to catch any new file matching a?z
3787
- const rawExcludeRegex = getRegularExpressionForWildcard ( exclude , path , "exclude" ) ;
3787
+ const rawExcludeRegex = getRegularExpressionForWildcard ( exclude , basePath , "exclude" ) ;
3788
3788
const excludeRegex = rawExcludeRegex && new RegExp ( rawExcludeRegex , useCaseSensitiveFileNames ? "" : "i" ) ;
3789
3789
const wildcardDirectories : MapLike < WatchDirectoryFlags > = { } ;
3790
+ const wildCardKeyToPath = new Map < CanonicalKey , string > ( ) ;
3790
3791
if ( include !== undefined ) {
3791
- const recursiveKeys : string [ ] = [ ] ;
3792
+ const recursiveKeys : CanonicalKey [ ] = [ ] ;
3792
3793
for ( const file of include ) {
3793
- const spec = normalizePath ( combinePaths ( path , file ) ) ;
3794
+ const spec = normalizePath ( combinePaths ( basePath , file ) ) ;
3794
3795
if ( excludeRegex && excludeRegex . test ( spec ) ) {
3795
3796
continue ;
3796
3797
}
3797
3798
3798
3799
const match = getWildcardDirectoryFromSpec ( spec , useCaseSensitiveFileNames ) ;
3799
3800
if ( match ) {
3800
- const { key, flags } = match ;
3801
- const existingFlags = wildcardDirectories [ key ] ;
3801
+ const { key, path, flags } = match ;
3802
+ const existingPath = wildCardKeyToPath . get ( key ) ;
3803
+ const existingFlags = existingPath !== undefined ? wildcardDirectories [ existingPath ] : undefined ;
3802
3804
if ( existingFlags === undefined || existingFlags < flags ) {
3803
- wildcardDirectories [ key ] = flags ;
3805
+ wildcardDirectories [ existingPath !== undefined ? existingPath : path ] = flags ;
3806
+ if ( existingPath === undefined ) wildCardKeyToPath . set ( key , path ) ;
3804
3807
if ( flags === WatchDirectoryFlags . Recursive ) {
3805
3808
recursiveKeys . push ( key ) ;
3806
3809
}
@@ -3809,11 +3812,12 @@ function getWildcardDirectories({ validatedIncludeSpecs: include, validatedExclu
3809
3812
}
3810
3813
3811
3814
// Remove any subpaths under an existing recursively watched directory.
3812
- for ( const key in wildcardDirectories ) {
3813
- if ( hasProperty ( wildcardDirectories , key ) ) {
3815
+ for ( const path in wildcardDirectories ) {
3816
+ if ( hasProperty ( wildcardDirectories , path ) ) {
3814
3817
for ( const recursiveKey of recursiveKeys ) {
3815
- if ( key !== recursiveKey && containsPath ( recursiveKey , key , path , ! useCaseSensitiveFileNames ) ) {
3816
- delete wildcardDirectories [ key ] ;
3818
+ const key = toCanonicalKey ( path , useCaseSensitiveFileNames ) ;
3819
+ if ( key !== recursiveKey && containsPath ( recursiveKey , key , basePath , ! useCaseSensitiveFileNames ) ) {
3820
+ delete wildcardDirectories [ path ] ;
3817
3821
}
3818
3822
}
3819
3823
}
@@ -3823,7 +3827,12 @@ function getWildcardDirectories({ validatedIncludeSpecs: include, validatedExclu
3823
3827
return wildcardDirectories ;
3824
3828
}
3825
3829
3826
- function getWildcardDirectoryFromSpec ( spec : string , useCaseSensitiveFileNames : boolean ) : { key : string ; flags : WatchDirectoryFlags ; } | undefined {
3830
+ type CanonicalKey = string & { __canonicalKey : never ; } ;
3831
+ function toCanonicalKey ( path : string , useCaseSensitiveFileNames : boolean ) : CanonicalKey {
3832
+ return ( useCaseSensitiveFileNames ? path : toFileNameLowerCase ( path ) ) as CanonicalKey ;
3833
+ }
3834
+
3835
+ function getWildcardDirectoryFromSpec ( spec : string , useCaseSensitiveFileNames : boolean ) : { key : CanonicalKey ; path : string ; flags : WatchDirectoryFlags ; } | undefined {
3827
3836
const match = wildcardDirectoryPattern . exec ( spec ) ;
3828
3837
if ( match ) {
3829
3838
// We check this with a few `indexOf` calls because 3 `indexOf`/`lastIndexOf` calls is
@@ -3834,15 +3843,18 @@ function getWildcardDirectoryFromSpec(spec: string, useCaseSensitiveFileNames: b
3834
3843
const starWildcardIndex = spec . indexOf ( "*" ) ;
3835
3844
const lastDirectorySeperatorIndex = spec . lastIndexOf ( directorySeparator ) ;
3836
3845
return {
3837
- key : useCaseSensitiveFileNames ? match [ 0 ] : toFileNameLowerCase ( match [ 0 ] ) ,
3846
+ key : toCanonicalKey ( match [ 0 ] , useCaseSensitiveFileNames ) ,
3847
+ path : match [ 0 ] ,
3838
3848
flags : ( questionWildcardIndex !== - 1 && questionWildcardIndex < lastDirectorySeperatorIndex )
3839
3849
|| ( starWildcardIndex !== - 1 && starWildcardIndex < lastDirectorySeperatorIndex )
3840
3850
? WatchDirectoryFlags . Recursive : WatchDirectoryFlags . None ,
3841
3851
} ;
3842
3852
}
3843
3853
if ( isImplicitGlob ( spec . substring ( spec . lastIndexOf ( directorySeparator ) + 1 ) ) ) {
3854
+ const path = removeTrailingDirectorySeparator ( spec ) ;
3844
3855
return {
3845
- key : removeTrailingDirectorySeparator ( useCaseSensitiveFileNames ? spec : toFileNameLowerCase ( spec ) ) ,
3856
+ key : toCanonicalKey ( path , useCaseSensitiveFileNames ) ,
3857
+ path,
3846
3858
flags : WatchDirectoryFlags . Recursive ,
3847
3859
} ;
3848
3860
}
0 commit comments