@@ -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,52 @@ 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
+ filePath := tspath .ToPath (strings .TrimPrefix (str , "File '" ), t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
537
+ if _ , has := t .packageJsonCache [filePath ]; has {
538
+ return msg
539
+ } else {
540
+ t .packageJsonCache [filePath ] = false
541
+ return fmt .Sprintf ("File '%s' does not exist." , filePath )
542
+ }
522
543
}
544
+ if str := strings .TrimSuffix (msg , "' exists according to earlier cached lookups" ); str != msg {
545
+ filePath := tspath .ToPath (strings .TrimPrefix (str , "File '" ), t .currentDirectory , t .fs .UseCaseSensitiveFileNames ())
546
+ if _ , has := t .packageJsonCache [filePath ]; has {
547
+ return msg
548
+ } else {
549
+ t .packageJsonCache [filePath ] = true
550
+ return fmt .Sprintf ("Found 'package.json' at '%s'." , filePath )
551
+ }
552
+ }
553
+ return msg
554
+ }
555
+
556
+ func (t * tracer ) string () string {
557
+ return t .builder .String ()
558
+ }
559
+
560
+ func createCompilerHost (fs vfs.FS , defaultLibraryPath string , currentDirectory string ) * cachedCompilerHost {
561
+ tracer := tracer {fs : fs , currentDirectory : currentDirectory , packageJsonCache : make (map [tspath.Path ]bool )}
523
562
return & cachedCompilerHost {
524
- CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , trace ),
563
+ CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , tracer . trace ),
525
564
tracer : & tracer ,
526
565
}
527
566
}
0 commit comments