@@ -1026,12 +1026,13 @@ namespace ts {
1026
1026
type ResolutionKindSpecificLoader = ( extensions : Extensions , candidate : string , onlyRecordFailures : boolean , state : ModuleResolutionState ) => Resolved | undefined ;
1027
1027
1028
1028
/**
1029
- * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'paths' and 'rootDirs' - they are used to
1029
+ * Any module resolution kind can be augmented with optional settings: 'baseUrl', 'resolveFromOutDir', ' paths' and 'rootDirs' - they are used to
1030
1030
* mitigate differences between design time structure of the project and its runtime counterpart so the same import name
1031
1031
* can be resolved successfully by TypeScript compiler and runtime module loader.
1032
1032
* If these settings are set then loading procedure will try to use them to resolve module name and it can of failure it will
1033
1033
* fallback to standard resolution routine.
1034
1034
*
1035
+ * 'resolveFromOutDir': TODO document the semantics
1035
1036
* - baseUrl - this setting controls how non-relative module names are resolved. If this setting is specified then non-relative
1036
1037
* names will be resolved relative to baseUrl: i.e. if baseUrl is '/a/b' then candidate location to resolve module name 'c/d' will
1037
1038
* be '/a/b/c/d'
@@ -1088,6 +1089,9 @@ namespace ts {
1088
1089
function tryLoadModuleUsingOptionalResolutionSettings ( extensions : Extensions , moduleName : string , containingDirectory : string , loader : ResolutionKindSpecificLoader ,
1089
1090
state : ModuleResolutionState ) : Resolved | undefined {
1090
1091
1092
+ const resolvedFromOutDir = tryLoadModuleUsingOutDirIfEligible ( extensions , moduleName , containingDirectory , loader , state ) ;
1093
+ if ( resolvedFromOutDir ) return resolvedFromOutDir ;
1094
+
1091
1095
const resolved = tryLoadModuleUsingPathsIfEligible ( extensions , moduleName , loader , state ) ;
1092
1096
if ( resolved ) return resolved . value ;
1093
1097
@@ -1114,6 +1118,39 @@ namespace ts {
1114
1118
}
1115
1119
}
1116
1120
1121
+ function tryLoadModuleUsingOutDirIfEligible ( extensions : Extensions , moduleName : string , containingDirectory : string , loader : ResolutionKindSpecificLoader , state : ModuleResolutionState ) : Resolved | undefined {
1122
+ const { resolveFromOutDir, outDir } = state . compilerOptions ;
1123
+ if ( ! resolveFromOutDir ) {
1124
+ // FIXME: wire the new option through
1125
+ // return undefined
1126
+ }
1127
+ if ( ! outDir ) {
1128
+ return undefined ;
1129
+ }
1130
+ if ( state . traceEnabled ) {
1131
+ trace ( state . host , Diagnostics . resolveFromOutDir_option_is_set_using_it_to_resolve_relative_module_name_0 , moduleName ) ;
1132
+ }
1133
+
1134
+ let normalizedPrefix = normalizePath ( outDir ) ;
1135
+
1136
+ let candidate = normalizePath ( combinePaths ( containingDirectory , moduleName ) ) ;
1137
+ const suffix = candidate . substr ( normalizedPrefix . length ) ;
1138
+ candidate = combinePaths ( normalizePath ( outDir ) , suffix ) ;
1139
+ if ( state . traceEnabled ) {
1140
+ trace ( state . host , Diagnostics . Loading_0_from_the_out_dir_1_candidate_location_2 , suffix , outDir , candidate ) ;
1141
+ }
1142
+
1143
+ const resolvedFileName = loader ( extensions , candidate , ! directoryProbablyExists ( containingDirectory , state . host ) , state ) ;
1144
+ if ( resolvedFileName ) {
1145
+ return resolvedFileName ;
1146
+ }
1147
+
1148
+ if ( state . traceEnabled ) {
1149
+ trace ( state . host , Diagnostics . Module_resolution_using_outDir_has_failed ) ;
1150
+ }
1151
+ return undefined ;
1152
+ }
1153
+
1117
1154
function tryLoadModuleUsingRootDirs ( extensions : Extensions , moduleName : string , containingDirectory : string , loader : ResolutionKindSpecificLoader ,
1118
1155
state : ModuleResolutionState ) : Resolved | undefined {
1119
1156
0 commit comments