@@ -79,9 +79,9 @@ import {
7979 normalizeSlashes ,
8080 PackageId ,
8181 packageIdToString ,
82+ ParsedPatterns ,
8283 Path ,
8384 pathIsRelative ,
84- Pattern ,
8585 patternText ,
8686 readJson ,
8787 removeExtension ,
@@ -1559,7 +1559,7 @@ function tryLoadModuleUsingOptionalResolutionSettings(extensions: Extensions, mo
15591559}
15601560
15611561function tryLoadModuleUsingPathsIfEligible ( extensions : Extensions , moduleName : string , loader : ResolutionKindSpecificLoader , state : ModuleResolutionState ) {
1562- const { baseUrl, paths, configFile } = state . compilerOptions ;
1562+ const { baseUrl, paths } = state . compilerOptions ;
15631563 if ( paths && ! pathIsRelative ( moduleName ) ) {
15641564 if ( state . traceEnabled ) {
15651565 if ( baseUrl ) {
@@ -1568,7 +1568,8 @@ function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: s
15681568 trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
15691569 }
15701570 const baseDirectory = getPathsBasePath ( state . compilerOptions , state . host ) ! ; // Always defined when 'paths' is defined
1571- const pathPatterns = configFile ?. configFileSpecs ? configFile . configFileSpecs . pathPatterns ??= tryParsePatterns ( paths ) : undefined ;
1571+ // TODO: do we need to sort by aggregate length?
1572+ const pathPatterns = tryParsePatterns ( paths ) ;
15721573 return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , pathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
15731574 }
15741575}
@@ -2524,7 +2525,9 @@ function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: st
25242525 if ( state . traceEnabled ) {
25252526 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 ) ;
25262527 }
2527- const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , /*pathPatterns*/ undefined , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
2528+ // TODO: do we need to sort by aggregate length?
2529+ const pathPatterns = tryParsePatterns ( versionPaths . paths ) ;
2530+ const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , pathPatterns , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
25282531 if ( result ) {
25292532 return removeIgnoredPackageId ( result . value ) ;
25302533 }
@@ -3118,22 +3121,17 @@ function loadModuleFromSpecificNodeModulesDirectory(extensions: Extensions, modu
31183121 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 , rest ) ;
31193122 }
31203123 const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists ( packageDirectory , state . host ) ;
3121- const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , versionPaths . paths , /*pathPatterns*/ undefined , loader , ! packageDirectoryExists , state ) ;
3124+ // TODO: do we need to sort by aggregate length?
3125+ const pathPatterns = tryParsePatterns ( versionPaths . paths ) ;
3126+ const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , versionPaths . paths , pathPatterns , loader , ! packageDirectoryExists , state ) ;
31223127 if ( fromPaths ) {
31233128 return fromPaths . value ;
31243129 }
31253130 }
31263131 return loader ( extensions , candidate , ! nodeModulesDirectoryExists , state ) ;
31273132}
31283133
3129- const pathsToPatternsCache = new WeakMap < MapLike < string [ ] > , readonly ( string | Pattern ) [ ] > ( ) ;
3130-
3131- function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : readonly ( string | Pattern ) [ ] | undefined , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
3132- pathPatterns ??= pathsToPatternsCache . get ( paths ) ;
3133- if ( pathPatterns === undefined ) {
3134- pathsToPatternsCache . set ( paths , pathPatterns = tryParsePatterns ( paths ) ) ;
3135- }
3136-
3134+ function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : ParsedPatterns , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
31373135 const matchedPattern = matchPatternOrExact ( pathPatterns , moduleName ) ;
31383136 if ( matchedPattern ) {
31393137 const matchedStar = isString ( matchedPattern ) ? undefined : matchedText ( matchedPattern , moduleName ) ;
0 commit comments