@@ -223,7 +223,7 @@ func CompileFilesEx(
223
223
Errors : errors ,
224
224
}, harnessOptions )
225
225
result .Symlinks = symlinks
226
- result .Trace = host .tracer .String ()
226
+ result .Trace = host .tracer .string ()
227
227
result .Repeat = func (testConfig TestConfiguration ) * CompilationResult {
228
228
newHarnessOptions := * harnessOptions
229
229
newCompilerOptions := compilerOptions .Clone ()
@@ -474,7 +474,7 @@ func getOptionValue(t *testing.T, option *tsoptions.CommandLineOption, value str
474
474
475
475
type cachedCompilerHost struct {
476
476
compiler.CompilerHost
477
- tracer * strings. Builder
477
+ tracer * tracer
478
478
}
479
479
480
480
var sourceFileCache collections.SyncMap [SourceFileCacheKey , * ast.SourceFile ]
@@ -515,13 +515,74 @@ func (h *cachedCompilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast
515
515
return result
516
516
}
517
517
518
- func createCompilerHost (fs vfs.FS , defaultLibraryPath string , currentDirectory string ) * cachedCompilerHost {
519
- var tracer strings.Builder
520
- trace := func (msg string ) {
521
- fmt .Fprintln (& tracer , strings .Replace (msg , "'" + core .Version ()+ "'" , "'" + FakeTSVersion + "'" , 1 ))
518
+ type tracer struct {
519
+ fs vfs.FS
520
+ currentDirectory string
521
+ packageJsonCache map [tspath.Path ]bool
522
+ builder strings.Builder
523
+ }
524
+
525
+ func (t * tracer ) trace (msg string ) {
526
+ fmt .Fprintln (& t .builder , t .sanitizeTrace (msg ))
527
+ }
528
+
529
+ func (t * tracer ) sanitizeTrace (msg string ) string {
530
+ // Version
531
+ if str := strings .Replace (msg , "'" + core .Version ()+ "'" , "'" + FakeTSVersion + "'" , 1 ); str != msg {
532
+ return str
533
+ }
534
+ // caching of fs in trace to be replaces with non caching version
535
+ if str := strings .TrimSuffix (msg , "' does not exist according to earlier cached lookups." ); str != msg {
536
+ file := strings .TrimPrefix (str , "File '" )
537
+ filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
538
+ if _ , has := t .packageJsonCache [filePath ]; has {
539
+ return msg
540
+ } else {
541
+ t .packageJsonCache [filePath ] = false
542
+ return fmt .Sprintf ("File '%s' does not exist." , file )
543
+ }
522
544
}
545
+ if str := strings .TrimSuffix (msg , "' does not exist." ); str != msg {
546
+ file := strings .TrimPrefix (str , "File '" )
547
+ filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
548
+ if _ , has := t .packageJsonCache [filePath ]; ! has {
549
+ t .packageJsonCache [filePath ] = false
550
+ return msg
551
+ } else {
552
+ return fmt .Sprintf ("File '%s' does not exist according to earlier cached lookups." , file )
553
+ }
554
+ }
555
+ if str := strings .TrimSuffix (msg , "' exists according to earlier cached lookups." ); str != msg {
556
+ file := strings .TrimPrefix (str , "File '" )
557
+ filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
558
+ if _ , has := t .packageJsonCache [filePath ]; has {
559
+ return msg
560
+ } else {
561
+ t .packageJsonCache [filePath ] = true
562
+ return fmt .Sprintf ("Found 'package.json' at '%s'." , file )
563
+ }
564
+ }
565
+ if str := strings .TrimPrefix (msg , "Found 'package.json' at '" ); str != msg {
566
+ file := strings .TrimSuffix (str , "'." )
567
+ filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
568
+ if _ , has := t .packageJsonCache [filePath ]; ! has {
569
+ t .packageJsonCache [filePath ] = true
570
+ return msg
571
+ } else {
572
+ return fmt .Sprintf ("File '%s' exists according to earlier cached lookups." , file )
573
+ }
574
+ }
575
+ return msg
576
+ }
577
+
578
+ func (t * tracer ) string () string {
579
+ return t .builder .String ()
580
+ }
581
+
582
+ func createCompilerHost (fs vfs.FS , defaultLibraryPath string , currentDirectory string ) * cachedCompilerHost {
583
+ tracer := tracer {fs : fs , currentDirectory : currentDirectory , packageJsonCache : make (map [tspath.Path ]bool )}
523
584
return & cachedCompilerHost {
524
- CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , trace ),
585
+ CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , tracer . trace ),
525
586
tracer : & tracer ,
526
587
}
527
588
}
0 commit comments