@@ -96,9 +96,14 @@ namespace ts {
96
96
} ;
97
97
}
98
98
99
+ function tryParsePatterns ( paths : MapLike < string [ ] > ) : ( string | Pattern ) [ ] {
100
+ return mapDefined ( getOwnKeys ( paths ) , path => tryParsePattern ( path ) ) ;
101
+ }
102
+
99
103
interface ModuleResolutionState {
100
104
host : ModuleResolutionHost ;
101
105
compilerOptions : CompilerOptions ;
106
+ compilerPathPatterns ?: ( string | Pattern ) [ ] ;
102
107
traceEnabled : boolean ;
103
108
failedLookupLocations : Push < string > ;
104
109
resultFromCache ?: ResolvedModuleWithFailedLookupLocations ;
@@ -961,7 +966,10 @@ namespace ts {
961
966
trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
962
967
}
963
968
const baseDirectory = getPathsBasePath ( state . compilerOptions , state . host ) ! ; // Always defined when 'paths' is defined
964
- return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , loader , /*onlyRecordFailures*/ false , state ) ;
969
+ if ( ! state . compilerPathPatterns ) {
970
+ state . compilerPathPatterns = tryParsePatterns ( paths ) ;
971
+ }
972
+ return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , state . compilerPathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
965
973
}
966
974
}
967
975
@@ -1400,7 +1408,8 @@ namespace ts {
1400
1408
if ( state . traceEnabled ) {
1401
1409
trace ( state . host , Diagnostics . package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2 , versionPaths . version , version , moduleName ) ;
1402
1410
}
1403
- const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1411
+ const paths = versionPaths . paths ;
1412
+ const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , paths , tryParsePatterns ( paths ) , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1404
1413
if ( result ) {
1405
1414
return removeIgnoredPackageId ( result . value ) ;
1406
1415
}
@@ -1536,7 +1545,8 @@ namespace ts {
1536
1545
trace ( state . host , Diagnostics . package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2 , packageInfo . versionPaths . version , version , rest ) ;
1537
1546
}
1538
1547
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists ( packageDirectory , state . host ) ;
1539
- const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , packageInfo . versionPaths . paths , loader , ! packageDirectoryExists , state ) ;
1548
+ const paths = packageInfo . versionPaths . paths ;
1549
+ const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , paths , tryParsePatterns ( paths ) , loader , ! packageDirectoryExists , state ) ;
1540
1550
if ( fromPaths ) {
1541
1551
return fromPaths . value ;
1542
1552
}
@@ -1546,8 +1556,8 @@ namespace ts {
1546
1556
return loader ( extensions , candidate , ! nodeModulesDirectoryExists , state ) ;
1547
1557
}
1548
1558
1549
- function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1550
- const matchedPattern = matchPatternOrExact ( getOwnKeys ( paths ) , moduleName ) ;
1559
+ function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : ( string | Pattern ) [ ] , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1560
+ const matchedPattern = matchPatternOrExact ( pathPatterns , moduleName ) ;
1551
1561
if ( matchedPattern ) {
1552
1562
const matchedStar = isString ( matchedPattern ) ? undefined : matchedText ( matchedPattern , moduleName ) ;
1553
1563
const matchedPatternText = isString ( matchedPattern ) ? matchedPattern : patternText ( matchedPattern ) ;
0 commit comments