@@ -531,7 +531,7 @@ namespace ts {
531
531
includeSpecs = [ "**/*" ] ;
532
532
}
533
533
534
- return expandFiles ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors ) ;
534
+ return matchFileNames ( fileNames , includeSpecs , excludeSpecs , basePath , options , host , errors ) ;
535
535
}
536
536
}
537
537
@@ -589,14 +589,14 @@ namespace ts {
589
589
* Expands an array of file specifications.
590
590
*
591
591
* @param fileNames The literal file names to include.
592
- * @param includeSpecs The file specifications to expand .
593
- * @param excludeSpecs The file specifications to exclude.
592
+ * @param include The wildcard file specifications to include .
593
+ * @param exclude The wildcard file specifications to exclude.
594
594
* @param basePath The base path for any relative file specifications.
595
595
* @param options Compiler options.
596
596
* @param host The host used to resolve files and directories.
597
597
* @param errors An array for diagnostic reporting.
598
598
*/
599
- export function expandFiles ( fileNames : string [ ] , includeSpecs : string [ ] , excludeSpecs : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors ? : Diagnostic [ ] ) : ExpandResult {
599
+ function matchFileNames ( fileNames : string [ ] , include : string [ ] , exclude : string [ ] , basePath : string , options : CompilerOptions , host : ParseConfigHost , errors : Diagnostic [ ] ) : ExpandResult {
600
600
basePath = normalizePath ( basePath ) ;
601
601
basePath = removeTrailingDirectorySeparator ( basePath ) ;
602
602
@@ -615,11 +615,19 @@ namespace ts {
615
615
// via wildcard, and to handle extension priority.
616
616
const wildcardFileMap : Map < string > = { } ;
617
617
618
+ if ( include ) {
619
+ include = validateSpecs ( include , errors , /*allowTrailingRecursion*/ false ) ;
620
+ }
621
+
622
+ if ( exclude ) {
623
+ exclude = validateSpecs ( exclude , errors , /*allowTrailingRecursion*/ true ) ;
624
+ }
625
+
618
626
// Wildcard directories (provided as part of a wildcard path) are stored in a
619
627
// file map that marks whether it was a regular wildcard match (with a `*` or `?` token),
620
628
// or a recursive directory. This information is used by filesystem watchers to monitor for
621
629
// new entries in these paths.
622
- const wildcardDirectories : Map < WatchDirectoryFlags > = getWildcardDirectories ( includeSpecs , basePath , host . useCaseSensitiveFileNames ) ;
630
+ const wildcardDirectories : Map < WatchDirectoryFlags > = getWildcardDirectories ( include , exclude , basePath , host . useCaseSensitiveFileNames ) ;
623
631
624
632
// Rather than requery this for each file and filespec, we query the supported extensions
625
633
// once and store it on the expansion context.
@@ -634,13 +642,8 @@ namespace ts {
634
642
}
635
643
}
636
644
637
- if ( includeSpecs ) {
638
- includeSpecs = validateSpecs ( includeSpecs , errors , /*allowTrailingRecursion*/ false ) ;
639
- if ( excludeSpecs ) {
640
- excludeSpecs = validateSpecs ( excludeSpecs , errors , /*allowTrailingRecursion*/ true ) ;
641
- }
642
-
643
- for ( const file of host . readDirectory ( basePath , supportedExtensions , excludeSpecs , includeSpecs ) ) {
645
+ if ( include && include . length > 0 ) {
646
+ for ( const file of host . readDirectory ( basePath , supportedExtensions , exclude , include ) ) {
644
647
// If we have already included a literal or wildcard path with a
645
648
// higher priority extension, we should skip this file.
646
649
//
@@ -677,10 +680,10 @@ namespace ts {
677
680
const validSpecs : string [ ] = [ ] ;
678
681
for ( const spec of specs ) {
679
682
if ( ! allowTrailingRecursion && invalidTrailingRecursionPattern . test ( spec ) ) {
680
- errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0 , spec ) ) ;
683
+ errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0 , spec ) ) ;
681
684
}
682
685
else if ( invalidMultipleRecursionPatterns . test ( spec ) ) {
683
- errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0 , spec ) ) ;
686
+ errors . push ( createCompilerDiagnostic ( Diagnostics . File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0 , spec ) ) ;
684
687
}
685
688
else {
686
689
validSpecs . push ( spec ) ;
@@ -696,7 +699,7 @@ namespace ts {
696
699
/**
697
700
* Gets directories in a set of include patterns that should be watched for changes.
698
701
*/
699
- function getWildcardDirectories ( includes : string [ ] , path : string , useCaseSensitiveFileNames : boolean ) {
702
+ function getWildcardDirectories ( include : string [ ] , exclude : string [ ] , path : string , useCaseSensitiveFileNames : boolean ) {
700
703
// We watch a directory recursively if it contains a wildcard anywhere in a directory segment
701
704
// of the pattern:
702
705
//
@@ -708,11 +711,16 @@ namespace ts {
708
711
//
709
712
// /a/b/* - Watch /a/b directly to catch any new file
710
713
// /a/b/a?z - Watch /a/b directly to catch any new file matching a?z
714
+ const excludeRegExp = getRegularExpressionForWildcard ( exclude , path , "exclude" , useCaseSensitiveFileNames ) ;
711
715
const wildcardDirectories : Map < WatchDirectoryFlags > = { } ;
712
- if ( includes !== undefined ) {
716
+ if ( include !== undefined ) {
713
717
const recursiveKeys : string [ ] = [ ] ;
714
- for ( const include of includes ) {
715
- const name = combinePaths ( path , include ) ;
718
+ for ( const file of include ) {
719
+ const name = combinePaths ( path , file ) ;
720
+ if ( excludeRegExp && excludeRegExp . test ( name ) ) {
721
+ continue ;
722
+ }
723
+
716
724
const match = wildcardDirectoryPattern . exec ( name ) ;
717
725
if ( match ) {
718
726
const key = useCaseSensitiveFileNames ? match [ 0 ] : match [ 0 ] . toLowerCase ( ) ;
0 commit comments