@@ -195,51 +195,7 @@ namespace ts {
195195 return undefined ;
196196 }
197197
198- function tryLoadTypeDeclarationFile ( searchPath : string , failedLookupLocations : string [ ] , state : ModuleResolutionState ) {
199- let typesFile : string ;
200- const packageJsonPath = combinePaths ( searchPath , "package.json" ) ;
201- if ( state . host . fileExists ( packageJsonPath ) ) {
202- if ( state . traceEnabled ) {
203- trace ( state . host , Diagnostics . Found_package_json_at_0 , packageJsonPath ) ;
204- }
205- typesFile = tryReadTypesSection ( packageJsonPath , searchPath , state ) ;
206- if ( ! typesFile ) {
207- if ( state . traceEnabled ) {
208- trace ( state . host , Diagnostics . package_json_does_not_have_types_field ) ;
209- }
210- }
211- }
212- else {
213- if ( state . traceEnabled ) {
214- trace ( state . host , Diagnostics . File_0_does_not_exist , packageJsonPath ) ;
215- }
216- failedLookupLocations . push ( packageJsonPath ) ;
217- }
218-
219- if ( ! typesFile ) {
220- typesFile = "index.d.ts" ;
221- }
222-
223- const combinedPath = normalizePath ( combinePaths ( searchPath , typesFile ) ) ;
224- if ( state . host . fileExists ( combinedPath ) ) {
225- if ( state . traceEnabled ) {
226- trace ( state . host , Diagnostics . File_0_exist_use_it_as_a_name_resolution_result , combinedPath ) ;
227- }
228- return combinedPath ;
229- }
230- else {
231- if ( state . traceEnabled ) {
232- trace ( state . host , Diagnostics . File_0_does_not_exist , combinedPath ) ;
233- }
234- failedLookupLocations . push ( combinedPath ) ;
235- return undefined ;
236- }
237- }
238-
239- function getEffectiveTypesPrimarySearchPaths ( options : CompilerOptions ) : string [ ] {
240- return options . typesSearchPaths || defaultLibrarySearchPaths ;
241- }
242-
198+ const typeReferenceExtensions = [ ".d.ts" ] ;
243199 export function resolveTypeReferenceDirective ( typeReferenceDirectiveName : string , containingFile : string , compilationRoot : string , options : CompilerOptions , host : ModuleResolutionHost ) : ResolvedTypeReferenceDirectiveWithFailedLookupLocations {
244200 const traceEnabled = isTraceEnabled ( options , host ) ;
245201 const moduleResolutionState : ModuleResolutionState = {
@@ -254,12 +210,17 @@ namespace ts {
254210 }
255211 const failedLookupLocations : string [ ] = [ ] ;
256212 // Check primary library paths
257- for ( const searchPath of getEffectiveTypesPrimarySearchPaths ( options ) ) {
213+ const effectivePrimarySearchPaths = options . typesSearchPaths || defaultLibrarySearchPaths ;
214+ for ( const searchPath of effectivePrimarySearchPaths ) {
258215 const primaryPath = combinePaths ( compilationRoot , searchPath ) ;
259216 if ( traceEnabled ) {
260217 trace ( host , Diagnostics . Resolving_with_primary_search_path_0 , primaryPath ) ;
261218 }
262- const resolvedFile = tryLoadTypeDeclarationFile ( combinePaths ( primaryPath , typeReferenceDirectiveName ) , failedLookupLocations , moduleResolutionState ) ;
219+ const candidate = combinePaths ( primaryPath , typeReferenceDirectiveName ) ;
220+ const candidateDirectory = getDirectoryPath ( candidate ) ;
221+ const resolvedFile = loadNodeModuleFromDirectory ( typeReferenceExtensions , candidate , failedLookupLocations ,
222+ ! directoryProbablyExists ( candidateDirectory , host ) , moduleResolutionState ) ;
223+
263224 if ( resolvedFile ) {
264225 if ( traceEnabled ) {
265226 trace ( host , Diagnostics . Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2 , typeReferenceDirectiveName , resolvedFile , true ) ;
0 commit comments