@@ -2,6 +2,8 @@ package tsoptions
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
6
+ "path/filepath"
5
7
"reflect"
6
8
"regexp"
7
9
"slices"
@@ -1432,32 +1434,41 @@ func getFileNamesFromConfigSpecs(
1432
1434
extraFileExtensions []fileExtensionInfo ,
1433
1435
) []string {
1434
1436
extraFileExtensions = []fileExtensionInfo {}
1437
+
1438
+ if basePath == "" {
1439
+ basePath , _ = os .Getwd ()
1440
+ } else if ! filepath .IsAbs (basePath ) {
1441
+ basePath , _ = filepath .Abs (basePath )
1442
+ }
1443
+
1435
1444
basePath = tspath .NormalizePath (basePath )
1436
- keyMappper := func (value string ) string { return tspath .GetCanonicalFileName (value , host .UseCaseSensitiveFileNames ()) }
1437
- // Literal file names (provided via the "files" array in tsconfig.json) are stored in a
1438
- // file map with a possibly case insensitive key. We use this map later when when including
1439
- // wildcard paths.
1440
- var literalFileMap collections.OrderedMap [string , string ]
1441
- // Wildcard paths (provided via the "includes" array in tsconfig.json) are stored in a
1442
- // file map with a possibly case insensitive key. We use this map to store paths matched
1443
- // via wildcard, and to handle extension priority.
1444
- var wildcardFileMap collections.OrderedMap [string , string ]
1445
- // Wildcard paths of json files (provided via the "includes" array in tsconfig.json) are stored in a
1446
- // file map with a possibly case insensitive key. We use this map to store paths matched
1447
- // via wildcard of *.json kind
1448
- var wildCardJsonFileMap collections.OrderedMap [string , string ]
1449
- validatedFilesSpec := configFileSpecs .validatedFilesSpec
1450
- validatedIncludeSpecs := configFileSpecs .validatedIncludeSpecs
1451
- validatedExcludeSpecs := configFileSpecs .validatedExcludeSpecs
1452
- // Rather than re-query this for each file and filespec, we query the supported extensions
1453
- // once and store it on the expansion context.
1454
- supportedExtensions := GetSupportedExtensions (options , extraFileExtensions )
1455
- supportedExtensionsWithJsonIfResolveJsonModule := GetSupportedExtensionsWithJsonIfResolveJsonModule (options , supportedExtensions )
1456
- // Literal files are always included verbatim. An "include" or "exclude" specification cannot
1457
- // remove a literal file.
1445
+ keyMapper := func (value string ) string { return tspath .GetCanonicalFileName (value , host .UseCaseSensitiveFileNames ()) }
1446
+
1447
+ var (
1448
+ literalFileMap collections.OrderedMap [string , string ]
1449
+ wildcardFileMap collections.OrderedMap [string , string ]
1450
+ wildCardJsonFileMap collections.OrderedMap [string , string ]
1451
+ )
1452
+
1453
+ var (
1454
+ validatedFilesSpec = configFileSpecs .validatedFilesSpec
1455
+ validatedIncludeSpecs = configFileSpecs .validatedIncludeSpecs
1456
+ validatedExcludeSpecs = configFileSpecs .validatedExcludeSpecs
1457
+ )
1458
+
1459
+ var (
1460
+ supportedExtensions = GetSupportedExtensions (options , extraFileExtensions )
1461
+ supportedExtensionsWithJsonIfResolveJsonModule = GetSupportedExtensionsWithJsonIfResolveJsonModule (options , supportedExtensions )
1462
+ )
1463
+
1458
1464
for _ , fileName := range validatedFilesSpec {
1459
1465
file := tspath .GetNormalizedAbsolutePath (fileName , basePath )
1460
- literalFileMap .Set (keyMappper (fileName ), file )
1466
+
1467
+ if ! filepath .IsAbs (file ) {
1468
+ panic (fmt .Sprintf ("Path %q is not absolute (base: %q)" , file , basePath ))
1469
+ }
1470
+
1471
+ literalFileMap .Set (keyMapper (fileName ), file )
1461
1472
}
1462
1473
1463
1474
var jsonOnlyIncludeRegexes []* regexp2.Regexp
@@ -1467,7 +1478,7 @@ func getFileNamesFromConfigSpecs(
1467
1478
if tspath .FileExtensionIs (file , tspath .ExtensionJson ) {
1468
1479
if jsonOnlyIncludeRegexes == nil {
1469
1480
includes := core .Filter (validatedIncludeSpecs , func (include string ) bool { return strings .HasSuffix (include , tspath .ExtensionJson ) })
1470
- includeFilePatterns := core .Map (getRegularExpressionsForWildcards (includes , basePath , "files" ), func (pattern string ) string { return fmt . Sprintf ( "^%s$" , pattern ) })
1481
+ includeFilePatterns := core .Map (getRegularExpressionsForWildcards (includes , basePath , "files" ), func (pattern string ) string { return "^" + pattern + "$" })
1471
1482
if includeFilePatterns != nil {
1472
1483
jsonOnlyIncludeRegexes = core .Map (includeFilePatterns , func (pattern string ) * regexp2.Regexp {
1473
1484
return getRegexFromPattern (pattern , host .UseCaseSensitiveFileNames ())
@@ -1478,28 +1489,18 @@ func getFileNamesFromConfigSpecs(
1478
1489
}
1479
1490
includeIndex := core .FindIndex (jsonOnlyIncludeRegexes , func (re * regexp2.Regexp ) bool { return core .Must (re .MatchString (file )) })
1480
1491
if includeIndex != - 1 {
1481
- key := keyMappper (file )
1492
+ key := keyMapper (file )
1482
1493
if ! literalFileMap .Has (key ) && ! wildCardJsonFileMap .Has (key ) {
1483
1494
wildCardJsonFileMap .Set (key , file )
1484
1495
}
1485
1496
}
1486
1497
continue
1487
1498
}
1488
- // If we have already included a literal or wildcard path with a
1489
- // higher priority extension, we should skip this file.
1490
- //
1491
- // This handles cases where we may encounter both <file>.ts and
1492
- // <file>.d.ts (or <file>.js if "allowJs" is enabled) in the same
1493
- // directory when they are compilation outputs.
1494
- if hasFileWithHigherPriorityExtension (file , literalFileMap , wildcardFileMap , supportedExtensions , keyMappper ) {
1499
+ if hasFileWithHigherPriorityExtension (file , literalFileMap , wildcardFileMap , supportedExtensions , keyMapper ) {
1495
1500
continue
1496
1501
}
1497
- // We may have included a wildcard path with a lower priority
1498
- // extension due to the user-defined order of entries in the
1499
- // "include" array. If there is a lower priority extension in the
1500
- // same directory, we should remove it.
1501
- removeWildcardFilesWithLowerPriorityExtension (file , wildcardFileMap , supportedExtensions , keyMappper )
1502
- key := keyMappper (file )
1502
+ removeWildcardFilesWithLowerPriorityExtension (file , wildcardFileMap , supportedExtensions , keyMapper )
1503
+ key := keyMapper (file )
1503
1504
if ! literalFileMap .Has (key ) && ! wildcardFileMap .Has (key ) {
1504
1505
wildcardFileMap .Set (key , file )
1505
1506
}
0 commit comments