@@ -15,6 +15,12 @@ import (
1515 "github.com/microsoft/typescript-go/internal/tspath"
1616)
1717
18+ type libResolution struct {
19+ libraryName string
20+ resolution * module.ResolvedModule
21+ trace []string
22+ }
23+
1824type LibFile struct {
1925 Name string
2026 path string
@@ -41,7 +47,7 @@ type fileLoader struct {
4147 dtsDirectories collections.Set [tspath.Path ]
4248
4349 pathForLibFileCache collections.SyncMap [string , * LibFile ]
44- pathForLibFileResolutions collections.SyncMap [tspath.Path , module. ModeAwareCache [ * module. ResolvedModule ] ]
50+ pathForLibFileResolutions collections.SyncMap [tspath.Path , * libResolution ]
4551}
4652
4753type processedFiles struct {
@@ -208,15 +214,20 @@ func processAllProgramFiles(
208214 }
209215 }
210216
211- loader .pathForLibFileResolutions .Range ( func ( key tspath. Path , value module. ModeAwareCache [ * module. ResolvedModule ]) bool {
212- resolvedModules [ key ] = value
213- for _ , resolvedModule := range value {
214- for _ , diag := range resolvedModule . ResolutionDiagnostics {
215- fileLoadDiagnostics . Add ( diag )
216- }
217+ keys := slices . Collect ( loader .pathForLibFileResolutions .Keys ())
218+ slices . Sort ( keys )
219+ for _ , key := range keys {
220+ value , _ := loader . pathForLibFileResolutions . Load ( key )
221+ resolvedModules [ key ] = module. ModeAwareCache [ * module. ResolvedModule ]{
222+ module. ModeAwareCacheKey { Name : value . libraryName , Mode : core . ModuleKindCommonJS }: value . resolution ,
217223 }
218- return true
219- })
224+ for _ , trace := range value .trace {
225+ opts .Host .Trace (trace )
226+ }
227+ for _ , diag := range value .resolution .ResolutionDiagnostics {
228+ fileLoadDiagnostics .Add (diag )
229+ }
230+ }
220231
221232 return processedFiles {
222233 resolver : loader .resolver ,
@@ -261,15 +272,17 @@ func (p *fileLoader) addAutomaticTypeDirectiveTasks() {
261272func (p * fileLoader ) resolveAutomaticTypeDirectives (containingFileName string ) (
262273 toParse []resolvedRef ,
263274 typeResolutionsInFile module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ],
275+ typeResolutionsTrace []string ,
264276) {
265277 automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (p .opts .Config .CompilerOptions (), p .opts .Host )
266278 if len (automaticTypeDirectiveNames ) != 0 {
267279 toParse = make ([]resolvedRef , 0 , len (automaticTypeDirectiveNames ))
268280 typeResolutionsInFile = make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (automaticTypeDirectiveNames ))
269281 for _ , name := range automaticTypeDirectiveNames {
270282 resolutionMode := core .ModuleKindNodeNext
271- resolved := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
283+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
272284 typeResolutionsInFile [module.ModeAwareCacheKey {Name : name , Mode : resolutionMode }] = resolved
285+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
273286 if resolved .IsResolved () {
274287 toParse = append (toParse , resolvedRef {
275288 fileName : resolved .ResolvedFileName ,
@@ -279,7 +292,7 @@ func (p *fileLoader) resolveAutomaticTypeDirectives(containingFileName string) (
279292 }
280293 }
281294 }
282- return toParse , typeResolutionsInFile
295+ return toParse , typeResolutionsInFile , typeResolutionsTrace
283296}
284297
285298func (p * fileLoader ) addProjectReferenceTasks (singleThreaded bool ) {
@@ -399,11 +412,13 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
399412 meta := t .metadata
400413
401414 typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
415+ var typeResolutionsTrace []string
402416 for _ , ref := range file .TypeReferenceDirectives {
403417 redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
404418 resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , meta , module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect ))
405- resolved := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
419+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
406420 typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
421+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
407422
408423 if resolved .IsResolved () {
409424 t .addSubTask (resolvedRef {
@@ -416,6 +431,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
416431 }
417432
418433 t .typeResolutionsInFile = typeResolutionsInFile
434+ t .typeResolutionsTrace = typeResolutionsTrace
419435}
420436
421437const externalHelpersModuleNameText = "tslib" // TODO(jakebailey): dedupe
@@ -461,6 +477,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
461477
462478 if len (moduleNames ) != 0 {
463479 resolutionsInFile := make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
480+ var resolutionsTrace []string
464481
465482 for index , entry := range moduleNames {
466483 moduleName := entry .Text ()
@@ -469,8 +486,9 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
469486 }
470487
471488 mode := getModeForUsageLocation (file .FileName (), meta , entry , optionsForFile )
472- resolvedModule := p .resolver .ResolveModuleName (moduleName , file .FileName (), mode , redirect )
489+ resolvedModule , trace := p .resolver .ResolveModuleName (moduleName , file .FileName (), mode , redirect )
473490 resolutionsInFile [module.ModeAwareCacheKey {Name : moduleName , Mode : mode }] = resolvedModule
491+ resolutionsTrace = append (resolutionsTrace , trace ... )
474492
475493 if ! resolvedModule .IsResolved () {
476494 continue
@@ -507,6 +525,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
507525 }
508526
509527 t .resolutionsInFile = resolutionsInFile
528+ t .resolutionsTrace = resolutionsTrace
510529 }
511530}
512531
@@ -533,12 +552,14 @@ func (p *fileLoader) pathForLibFile(name string) *LibFile {
533552 if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () {
534553 libraryName := getLibraryNameFromLibFileName (name )
535554 resolveFrom := getInferredLibraryNameResolveFrom (p .opts .Config .CompilerOptions (), p .opts .Host .GetCurrentDirectory (), name )
536- resolution := p .resolver .ResolveModuleName (libraryName , resolveFrom , core .ModuleKindCommonJS , nil )
555+ resolution , trace := p .resolver .ResolveModuleName (libraryName , resolveFrom , core .ModuleKindCommonJS , nil )
537556 if resolution .IsResolved () {
538557 path = resolution .ResolvedFileName
539558 replaced = true
540- p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), module.ModeAwareCache [* module.ResolvedModule ]{
541- module.ModeAwareCacheKey {Name : libraryName , Mode : core .ModuleKindCommonJS }: resolution ,
559+ p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), & libResolution {
560+ libraryName : libraryName ,
561+ resolution : resolution ,
562+ trace : trace ,
542563 })
543564 }
544565 }
0 commit comments