@@ -952,7 +952,7 @@ namespace ts {
952952 }
953953
954954 function tryLoadModuleUsingPathsIfEligible ( extensions : Extensions , moduleName : string , loader : ResolutionKindSpecificLoader , state : ModuleResolutionState ) {
955- const { baseUrl, paths } = state . compilerOptions ;
955+ const { baseUrl, paths, configFile } = state . compilerOptions ;
956956 if ( paths && ! pathIsRelative ( moduleName ) ) {
957957 if ( state . traceEnabled ) {
958958 if ( baseUrl ) {
@@ -961,7 +961,8 @@ namespace ts {
961961 trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
962962 }
963963 const baseDirectory = getPathsBasePath ( state . compilerOptions , state . host ) ! ; // Always defined when 'paths' is defined
964- return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , loader , /*onlyRecordFailures*/ false , state ) ;
964+ const pathPatterns = configFile ?. configFileSpecs ? configFile . configFileSpecs . pathPatterns ||= tryParsePatterns ( paths ) : undefined ;
965+ return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , pathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
965966 }
966967 }
967968
@@ -1400,7 +1401,7 @@ namespace ts {
14001401 if ( state . traceEnabled ) {
14011402 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 ) ;
14021403 }
1403- const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1404+ const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , /*pathPatterns*/ undefined , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
14041405 if ( result ) {
14051406 return removeIgnoredPackageId ( result . value ) ;
14061407 }
@@ -1536,7 +1537,7 @@ namespace ts {
15361537 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 ) ;
15371538 }
15381539 const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists ( packageDirectory , state . host ) ;
1539- const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , packageInfo . versionPaths . paths , loader , ! packageDirectoryExists , state ) ;
1540+ const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , packageInfo . versionPaths . paths , /*pathPatterns*/ undefined , loader , ! packageDirectoryExists , state ) ;
15401541 if ( fromPaths ) {
15411542 return fromPaths . value ;
15421543 }
@@ -1546,8 +1547,9 @@ namespace ts {
15461547 return loader ( extensions , candidate , ! nodeModulesDirectoryExists , state ) ;
15471548 }
15481549
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 ) ;
1550+ function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : readonly ( string | Pattern ) [ ] | undefined , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1551+ pathPatterns ||= tryParsePatterns ( paths ) ;
1552+ const matchedPattern = matchPatternOrExact ( pathPatterns , moduleName ) ;
15511553 if ( matchedPattern ) {
15521554 const matchedStar = isString ( matchedPattern ) ? undefined : matchedText ( matchedPattern , moduleName ) ;
15531555 const matchedPatternText = isString ( matchedPattern ) ? matchedPattern : patternText ( matchedPattern ) ;
0 commit comments