@@ -47,6 +47,7 @@ import {
47
47
getBaseFileName ,
48
48
getConditions ,
49
49
getContextualTypeFromParent ,
50
+ getDeclarationEmitExtensionForPath ,
50
51
getDirectoryPath ,
51
52
getEffectiveTypeRoots ,
52
53
getEmitModuleResolutionKind ,
@@ -1023,6 +1024,8 @@ function getModulesForPathsPattern(
1023
1024
const expandedPrefixDirectory = fragmentHasPath ? combinePaths ( normalizedPrefixDirectory , normalizedPrefixBase + fragmentDirectory ) : normalizedPrefixDirectory ;
1024
1025
1025
1026
const normalizedSuffix = normalizePath ( parsed . suffix ) ;
1027
+ const declarationExtension = normalizedSuffix && getDeclarationEmitExtensionForPath ( "_" + normalizedSuffix ) ;
1028
+ const matchingSuffixes = declarationExtension ? [ changeExtension ( normalizedSuffix , declarationExtension ) , normalizedSuffix ] : [ normalizedSuffix ] ;
1026
1029
// Need to normalize after combining: If we combinePaths("a", "../b"), we want "b" and not "a/../b".
1027
1030
const baseDirectory = normalizePath ( combinePaths ( packageDirectory , expandedPrefixDirectory ) ) ;
1028
1031
const completePrefix = fragmentHasPath ? baseDirectory : ensureTrailingDirectorySeparator ( baseDirectory ) + normalizedPrefixBase ;
@@ -1035,9 +1038,11 @@ function getModulesForPathsPattern(
1035
1038
// interpreted as "any character" can only return *too many* results as compared to the literal
1036
1039
// interpretation, so we can filter those superfluous results out via `trimPrefixAndSuffix` as we've always
1037
1040
// done.
1038
- const includeGlob = normalizedSuffix ? "**/*" + normalizedSuffix : "./*" ;
1041
+ const includeGlobs = normalizedSuffix
1042
+ ? matchingSuffixes . map ( suffix => "**/*" + suffix )
1043
+ : [ "./*" ] ;
1039
1044
1040
- const matches = mapDefined ( tryReadDirectory ( host , baseDirectory , extensionOptions . extensionsToSearch , /*exclude*/ undefined , [ includeGlob ] ) , match => {
1045
+ const matches = mapDefined ( tryReadDirectory ( host , baseDirectory , extensionOptions . extensionsToSearch , /*exclude*/ undefined , includeGlobs ) , match => {
1041
1046
const trimmedWithPattern = trimPrefixAndSuffix ( match ) ;
1042
1047
if ( trimmedWithPattern ) {
1043
1048
if ( containsSlash ( trimmedWithPattern ) ) {
@@ -1057,8 +1062,10 @@ function getModulesForPathsPattern(
1057
1062
return [ ...matches , ...directories ] ;
1058
1063
1059
1064
function trimPrefixAndSuffix ( path : string ) : string | undefined {
1060
- const inner = withoutStartAndEnd ( normalizePath ( path ) , completePrefix , normalizedSuffix ) ;
1061
- return inner === undefined ? undefined : removeLeadingDirectorySeparator ( inner ) ;
1065
+ return firstDefined ( matchingSuffixes , suffix => {
1066
+ const inner = withoutStartAndEnd ( normalizePath ( path ) , completePrefix , suffix ) ;
1067
+ return inner === undefined ? undefined : removeLeadingDirectorySeparator ( inner ) ;
1068
+ } ) ;
1062
1069
}
1063
1070
}
1064
1071
0 commit comments