@@ -384,49 +384,12 @@ namespace fakes {
384
384
return text ;
385
385
}
386
386
387
- export class SolutionBuilderHost extends CompilerHost implements ts . SolutionBuilderHost < ts . BuilderProgram > {
388
- createProgram ( rootNames : ReadonlyArray < string > | undefined , options : ts . CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: ts . EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: ReadonlyArray < ts . Diagnostic > , projectReferences ?: ReadonlyArray < ts . ProjectReference > | undefined ) {
389
- const program = ts . createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames , options , host , oldProgram , configFileParsingDiagnostics , projectReferences ) ;
390
- const originalGetProgramBuildInfo = program . getProgramBuildInfo . bind ( program ) ;
391
- program . getProgramBuildInfo = ( ) => {
392
- const program = originalGetProgramBuildInfo ( ) as ts . ProgramBuildInfo | undefined ;
393
- if ( ! program ) return program ;
394
- // Fix lib signatures
395
- for ( const path of ts . getOwnKeys ( program . fileInfos ) ) {
396
- if ( ts . startsWith ( path , "/lib/" ) ) {
397
- const currentValue = program . fileInfos [ path ] ;
398
- ts . Debug . assert ( currentValue . signature === currentValue . version ) ;
399
- program . fileInfos [ path ] = { version : path , signature : path } ;
400
- }
401
- }
402
-
403
- // reference Map
404
- if ( program . referencedMap ) {
405
- const referencedMap : ts . MapLike < string [ ] > = { } ;
406
- for ( const path of ts . getOwnKeys ( program . referencedMap ) . sort ( ) ) {
407
- referencedMap [ path ] = program . referencedMap [ path ] . sort ( ) ;
408
- }
409
- program . referencedMap = referencedMap ;
410
- }
411
-
412
- // exportedModulesMap
413
- if ( program . exportedModulesMap ) {
414
- const exportedModulesMap : ts . MapLike < string [ ] > = { } ;
415
- for ( const path of ts . getOwnKeys ( program . exportedModulesMap ) . sort ( ) ) {
416
- exportedModulesMap [ path ] = program . exportedModulesMap [ path ] . sort ( ) ;
417
- }
418
- program . exportedModulesMap = exportedModulesMap ;
419
- }
420
-
421
- // semanticDiagnosticsPerFile
422
- if ( program . semanticDiagnosticsPerFile ) {
423
- program . semanticDiagnosticsPerFile . sort ( ) ;
424
- }
387
+ function compareProgramBuildInfoDiagnostic ( a : ts . ProgramBuildInfoDiagnostic , b : ts . ProgramBuildInfoDiagnostic ) {
388
+ return ts . compareStringsCaseSensitive ( ts . isString ( a ) ? a : a [ 0 ] , ts . isString ( b ) ? b : b [ 0 ] ) ;
389
+ }
425
390
426
- return program ;
427
- } ;
428
- return program ;
429
- }
391
+ export class SolutionBuilderHost extends CompilerHost implements ts . SolutionBuilderHost < ts . BuilderProgram > {
392
+ createProgram = ts . createEmitAndSemanticDiagnosticsBuilderProgram ;
430
393
431
394
readFile ( path : string ) {
432
395
const value = super . readFile ( path ) ;
@@ -447,6 +410,48 @@ namespace fakes {
447
410
return ts . getBuildInfoText ( buildInfo ) ;
448
411
}
449
412
413
+ public writeFile ( fileName : string , content : string , writeByteOrderMark : boolean ) {
414
+ if ( ts . isBuildInfoFile ( fileName ) ) {
415
+ const buildInfo = JSON . parse ( content ) as ts . BuildInfo ;
416
+ if ( buildInfo . program ) {
417
+ // Fix lib signatures
418
+ for ( const path of ts . getOwnKeys ( buildInfo . program . fileInfos ) ) {
419
+ if ( ts . startsWith ( path , "/lib/" ) ) {
420
+ const currentValue = buildInfo . program . fileInfos [ path ] ;
421
+ ts . Debug . assert ( currentValue . signature === currentValue . version ) ;
422
+ buildInfo . program . fileInfos [ path ] = { version : path , signature : path } ;
423
+ }
424
+ }
425
+
426
+ // reference Map
427
+ if ( buildInfo . program . referencedMap ) {
428
+ const referencedMap : ts . MapLike < string [ ] > = { } ;
429
+ for ( const path of ts . getOwnKeys ( buildInfo . program . referencedMap ) . sort ( ) ) {
430
+ referencedMap [ path ] = buildInfo . program . referencedMap [ path ] . sort ( ) ;
431
+ }
432
+ buildInfo . program . referencedMap = referencedMap ;
433
+ }
434
+
435
+ // exportedModulesMap
436
+ if ( buildInfo . program . exportedModulesMap ) {
437
+ const exportedModulesMap : ts . MapLike < string [ ] > = { } ;
438
+ for ( const path of ts . getOwnKeys ( buildInfo . program . exportedModulesMap ) . sort ( ) ) {
439
+ exportedModulesMap [ path ] = buildInfo . program . exportedModulesMap [ path ] . sort ( ) ;
440
+ }
441
+ buildInfo . program . exportedModulesMap = exportedModulesMap ;
442
+ }
443
+
444
+ // semanticDiagnosticsPerFile
445
+ if ( buildInfo . program . semanticDiagnosticsPerFile ) {
446
+ buildInfo . program . semanticDiagnosticsPerFile . sort ( compareProgramBuildInfoDiagnostic ) ;
447
+ }
448
+
449
+ content = ts . getBuildInfoText ( buildInfo ) ;
450
+ }
451
+ }
452
+ super . writeFile ( fileName , content , writeByteOrderMark ) ;
453
+ }
454
+
450
455
now ( ) {
451
456
return new Date ( this . sys . vfs . time ( ) ) ;
452
457
}
0 commit comments