@@ -96,14 +96,9 @@ 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
-
103
99
interface ModuleResolutionState {
104
100
host : ModuleResolutionHost ;
105
101
compilerOptions : CompilerOptions ;
106
- compilerPathPatterns ?: ( string | Pattern ) [ ] ;
107
102
traceEnabled : boolean ;
108
103
failedLookupLocations : Push < string > ;
109
104
resultFromCache ?: ResolvedModuleWithFailedLookupLocations ;
@@ -957,7 +952,7 @@ namespace ts {
957
952
}
958
953
959
954
function tryLoadModuleUsingPathsIfEligible ( extensions : Extensions , moduleName : string , loader : ResolutionKindSpecificLoader , state : ModuleResolutionState ) {
960
- const { baseUrl, paths } = state . compilerOptions ;
955
+ const { baseUrl, paths, configFile } = state . compilerOptions ;
961
956
if ( paths && ! pathIsRelative ( moduleName ) ) {
962
957
if ( state . traceEnabled ) {
963
958
if ( baseUrl ) {
@@ -966,10 +961,14 @@ namespace ts {
966
961
trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
967
962
}
968
963
const baseDirectory = getPathsBasePath ( state . compilerOptions , state . host ) ! ; // Always defined when 'paths' is defined
969
- if ( ! state . compilerPathPatterns ) {
970
- state . compilerPathPatterns = tryParsePatterns ( paths ) ;
964
+ let pathPatterns : readonly ( string | Pattern ) [ ] | undefined ;
965
+ if ( configFile ?. configFileSpecs ) {
966
+ pathPatterns = configFile . configFileSpecs . pathPatterns ;
967
+ if ( ! pathPatterns ) {
968
+ configFile . configFileSpecs . pathPatterns = pathPatterns = tryParsePatterns ( paths ) ;
969
+ }
971
970
}
972
- return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , state . compilerPathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
971
+ return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , pathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
973
972
}
974
973
}
975
974
@@ -1409,7 +1408,7 @@ namespace ts {
1409
1408
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 ) ;
1410
1409
}
1411
1410
const paths = versionPaths . paths ;
1412
- const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , paths , tryParsePatterns ( paths ) , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1411
+ const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , paths , /*pathPatterns*/ undefined , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1413
1412
if ( result ) {
1414
1413
return removeIgnoredPackageId ( result . value ) ;
1415
1414
}
@@ -1546,7 +1545,7 @@ namespace ts {
1546
1545
}
1547
1546
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists ( packageDirectory , state . host ) ;
1548
1547
const paths = packageInfo . versionPaths . paths ;
1549
- const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , paths , tryParsePatterns ( paths ) , loader , ! packageDirectoryExists , state ) ;
1548
+ const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , paths , /*pathPatterns*/ undefined , loader , ! packageDirectoryExists , state ) ;
1550
1549
if ( fromPaths ) {
1551
1550
return fromPaths . value ;
1552
1551
}
@@ -1556,7 +1555,8 @@ namespace ts {
1556
1555
return loader ( extensions , candidate , ! nodeModulesDirectoryExists , state ) ;
1557
1556
}
1558
1557
1559
- function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : ( string | Pattern ) [ ] , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1558
+ function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : readonly ( string | Pattern ) [ ] | undefined , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1559
+ pathPatterns ||= tryParsePatterns ( paths ) ;
1560
1560
const matchedPattern = matchPatternOrExact ( pathPatterns , moduleName ) ;
1561
1561
if ( matchedPattern ) {
1562
1562
const matchedStar = isString ( matchedPattern ) ? undefined : matchedText ( matchedPattern , moduleName ) ;
0 commit comments