@@ -15,6 +15,12 @@ import (
15
15
"github.com/microsoft/typescript-go/internal/tspath"
16
16
)
17
17
18
+ type libResolution struct {
19
+ libraryName string
20
+ resolution * module.ResolvedModule
21
+ trace []string
22
+ }
23
+
18
24
type LibFile struct {
19
25
Name string
20
26
path string
@@ -41,7 +47,7 @@ type fileLoader struct {
41
47
dtsDirectories collections.Set [tspath.Path ]
42
48
43
49
pathForLibFileCache collections.SyncMap [string , * LibFile ]
44
- pathForLibFileResolutions collections.SyncMap [tspath.Path , module. ModeAwareCache [ * module. ResolvedModule ] ]
50
+ pathForLibFileResolutions collections.SyncMap [tspath.Path , * libResolution ]
45
51
}
46
52
47
53
type processedFiles struct {
@@ -208,15 +214,20 @@ func processAllProgramFiles(
208
214
}
209
215
}
210
216
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 ,
217
223
}
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
+ }
220
231
221
232
return processedFiles {
222
233
resolver : loader .resolver ,
@@ -261,15 +272,17 @@ func (p *fileLoader) addAutomaticTypeDirectiveTasks() {
261
272
func (p * fileLoader ) resolveAutomaticTypeDirectives (containingFileName string ) (
262
273
toParse []resolvedRef ,
263
274
typeResolutionsInFile module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ],
275
+ typeResolutionsTrace []string ,
264
276
) {
265
277
automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (p .opts .Config .CompilerOptions (), p .opts .Host )
266
278
if len (automaticTypeDirectiveNames ) != 0 {
267
279
toParse = make ([]resolvedRef , 0 , len (automaticTypeDirectiveNames ))
268
280
typeResolutionsInFile = make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (automaticTypeDirectiveNames ))
269
281
for _ , name := range automaticTypeDirectiveNames {
270
282
resolutionMode := core .ModuleKindNodeNext
271
- resolved := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
283
+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
272
284
typeResolutionsInFile [module.ModeAwareCacheKey {Name : name , Mode : resolutionMode }] = resolved
285
+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
273
286
if resolved .IsResolved () {
274
287
toParse = append (toParse , resolvedRef {
275
288
fileName : resolved .ResolvedFileName ,
@@ -279,7 +292,7 @@ func (p *fileLoader) resolveAutomaticTypeDirectives(containingFileName string) (
279
292
}
280
293
}
281
294
}
282
- return toParse , typeResolutionsInFile
295
+ return toParse , typeResolutionsInFile , typeResolutionsTrace
283
296
}
284
297
285
298
func (p * fileLoader ) addProjectReferenceTasks (singleThreaded bool ) {
@@ -399,11 +412,13 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
399
412
meta := t .metadata
400
413
401
414
typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
415
+ var typeResolutionsTrace []string
402
416
for _ , ref := range file .TypeReferenceDirectives {
403
417
redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
404
418
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 )
406
420
typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
421
+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
407
422
408
423
if resolved .IsResolved () {
409
424
t .addSubTask (resolvedRef {
@@ -416,6 +431,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
416
431
}
417
432
418
433
t .typeResolutionsInFile = typeResolutionsInFile
434
+ t .typeResolutionsTrace = typeResolutionsTrace
419
435
}
420
436
421
437
const externalHelpersModuleNameText = "tslib" // TODO(jakebailey): dedupe
@@ -461,6 +477,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
461
477
462
478
if len (moduleNames ) != 0 {
463
479
resolutionsInFile := make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
480
+ var resolutionsTrace []string
464
481
465
482
for index , entry := range moduleNames {
466
483
moduleName := entry .Text ()
@@ -469,8 +486,9 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
469
486
}
470
487
471
488
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 )
473
490
resolutionsInFile [module.ModeAwareCacheKey {Name : moduleName , Mode : mode }] = resolvedModule
491
+ resolutionsTrace = append (resolutionsTrace , trace ... )
474
492
475
493
if ! resolvedModule .IsResolved () {
476
494
continue
@@ -507,6 +525,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
507
525
}
508
526
509
527
t .resolutionsInFile = resolutionsInFile
528
+ t .resolutionsTrace = resolutionsTrace
510
529
}
511
530
}
512
531
@@ -533,12 +552,14 @@ func (p *fileLoader) pathForLibFile(name string) *LibFile {
533
552
if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () {
534
553
libraryName := getLibraryNameFromLibFileName (name )
535
554
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 )
537
556
if resolution .IsResolved () {
538
557
path = resolution .ResolvedFileName
539
558
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 ,
542
563
})
543
564
}
544
565
}
0 commit comments