@@ -210,7 +210,6 @@ namespace ts {
210
210
originalWriteFile : CompilerHost [ "writeFile" ] | undefined ;
211
211
originalReadFileWithCache : CompilerHost [ "readFile" ] ;
212
212
originalGetSourceFile : CompilerHost [ "getSourceFile" ] ;
213
- buildInfoCache : ESMap < Path , BuildInfo | false > ;
214
213
}
215
214
216
215
interface FileWatcherWithModifiedTime {
@@ -219,6 +218,11 @@ namespace ts {
219
218
modifiedTime : Date | undefined ;
220
219
}
221
220
221
+ interface BuildInfoCacheEntry {
222
+ path : Path ;
223
+ buildInfo : BuildInfo | false | string ;
224
+ }
225
+
222
226
interface SolutionBuilderState < T extends BuilderProgram = BuilderProgram > extends WatchFactory < WatchType , ResolvedConfigFileName > {
223
227
readonly host : SolutionBuilderHost < T > ;
224
228
readonly hostWithWatch : SolutionBuilderWithWatchHost < T > ;
@@ -239,6 +243,7 @@ namespace ts {
239
243
readonly projectStatus : ESMap < ResolvedConfigFilePath , UpToDateStatus > ;
240
244
readonly buildInfoChecked : ESMap < ResolvedConfigFilePath , true > ;
241
245
readonly extendedConfigCache : ESMap < string , ExtendedConfigCacheEntry > ;
246
+ readonly buildInfoCache : ESMap < ResolvedConfigFilePath , BuildInfoCacheEntry > ;
242
247
243
248
readonly builderPrograms : ESMap < ResolvedConfigFilePath , T > ;
244
249
readonly diagnostics : ESMap < ResolvedConfigFilePath , readonly Diagnostic [ ] > ;
@@ -301,7 +306,7 @@ namespace ts {
301
306
compilerHost . resolveTypeReferenceDirectives = ( typeReferenceDirectiveNames , containingFile , redirectedReference , _options , containingFileMode ) =>
302
307
loadWithTypeDirectiveCache < ResolvedTypeReferenceDirective > ( Debug . checkEachDefined ( typeReferenceDirectiveNames ) , containingFile , redirectedReference , containingFileMode , loader ) ;
303
308
}
304
- compilerHost . getBuildInfo = fileName => getBuildInfo ( state , fileName ) ;
309
+ compilerHost . getBuildInfo = ( fileName , configFilePath ) => getBuildInfo ( state , fileName , toResolvedConfigFilePath ( state , configFilePath as ResolvedConfigFileName ) ) ;
305
310
306
311
const { watchFile, watchDirectory, writeLog } = createWatchFactory < ResolvedConfigFileName > ( hostWithWatch , options ) ;
307
312
@@ -324,6 +329,7 @@ namespace ts {
324
329
projectStatus : new Map ( ) ,
325
330
buildInfoChecked : new Map ( ) ,
326
331
extendedConfigCache : new Map ( ) ,
332
+ buildInfoCache : new Map ( ) ,
327
333
328
334
builderPrograms : new Map ( ) ,
329
335
diagnostics : new Map ( ) ,
@@ -487,6 +493,7 @@ namespace ts {
487
493
mutateMapSkippingNewValues ( state . diagnostics , currentProjects , noopOnDelete ) ;
488
494
mutateMapSkippingNewValues ( state . projectPendingBuild , currentProjects , noopOnDelete ) ;
489
495
mutateMapSkippingNewValues ( state . projectErrorsReported , currentProjects , noopOnDelete ) ;
496
+ mutateMapSkippingNewValues ( state . buildInfoCache , currentProjects , noopOnDelete ) ;
490
497
491
498
// Remove watches for the program no longer in the solution
492
499
if ( state . watch ) {
@@ -575,7 +582,6 @@ namespace ts {
575
582
originalWriteFile,
576
583
originalReadFileWithCache,
577
584
originalGetSourceFile,
578
- buildInfoCache : new Map ( ) ,
579
585
} ;
580
586
}
581
587
@@ -978,6 +984,7 @@ namespace ts {
978
984
let newestDeclarationFileContentChangedTime : Date | undefined ;
979
985
const emitterDiagnostics = createDiagnosticCollection ( ) ;
980
986
const emittedOutputs = new Map < Path , string > ( ) ;
987
+ const buildInfo = state . buildInfoCache . get ( projectPath ) ;
981
988
outputFiles . forEach ( ( { name, text, writeByteOrderMark } ) => {
982
989
if ( resultFlags === BuildResultFlags . DeclarationOutputUnchanged && isDeclarationFileName ( name ) ) {
983
990
// Check for unchanged .d.ts files
@@ -991,7 +998,7 @@ namespace ts {
991
998
992
999
const path = toPath ( state , name ) ;
993
1000
emittedOutputs . set ( path , name ) ;
994
- state . cache ?. buildInfoCache . delete ( path ) ;
1001
+ if ( buildInfo ?. path === path ) buildInfo . buildInfo = text ;
995
1002
writeFile ( writeFileCallback ? { writeFile : writeFileCallback } : compilerHost , emitterDiagnostics , name , text , writeByteOrderMark ) ;
996
1003
} ) ;
997
1004
@@ -1010,7 +1017,8 @@ namespace ts {
1010
1017
Debug . assert ( step === BuildStep . EmitBuildInfo ) ;
1011
1018
const emitResult = program . emitBuildInfo ( ( name , data , writeByteOrderMark , onError , sourceFiles ) => {
1012
1019
const path = toPath ( state , name ) ;
1013
- state . cache ?. buildInfoCache . delete ( path ) ;
1020
+ const buildInfo = state . buildInfoCache . get ( projectPath ) ;
1021
+ if ( buildInfo ?. path === path ) buildInfo . buildInfo = data ;
1014
1022
if ( writeFileCallback ) writeFileCallback ( name , data , writeByteOrderMark , onError , sourceFiles ) ;
1015
1023
else state . compilerHost . writeFile ( name , data , writeByteOrderMark , onError , sourceFiles ) ;
1016
1024
} , cancellationToken ) ;
@@ -1110,10 +1118,11 @@ namespace ts {
1110
1118
Debug . assert ( ! ! outputFiles . length ) ;
1111
1119
const emitterDiagnostics = createDiagnosticCollection ( ) ;
1112
1120
const emittedOutputs = new Map < Path , string > ( ) ;
1121
+ const buildInfo = state . buildInfoCache . get ( projectPath ) ;
1113
1122
outputFiles . forEach ( ( { name, text, writeByteOrderMark } ) => {
1114
1123
const path = toPath ( state , name ) ;
1115
1124
emittedOutputs . set ( path , name ) ;
1116
- state . cache ?. buildInfoCache . delete ( path ) ;
1125
+ if ( buildInfo ?. path === path ) buildInfo . buildInfo = text ;
1117
1126
writeFile ( writeFileCallback ? { writeFile : writeFileCallback } : compilerHost , emitterDiagnostics , name , text , writeByteOrderMark ) ;
1118
1127
} ) ;
1119
1128
@@ -1402,13 +1411,17 @@ namespace ts {
1402
1411
} ;
1403
1412
}
1404
1413
1405
- function getBuildInfo ( state : SolutionBuilderState , buildInfoPath : string ) : BuildInfo | undefined {
1414
+ function getBuildInfo ( state : SolutionBuilderState , buildInfoPath : string , resolvedConfigPath : ResolvedConfigFilePath ) : BuildInfo | undefined {
1406
1415
const path = toPath ( state , buildInfoPath ) ;
1407
- const existing = state . cache ?. buildInfoCache . get ( path ) ;
1408
- if ( existing !== undefined ) return existing || undefined ;
1416
+ const existing = state . buildInfoCache . get ( resolvedConfigPath ) ;
1417
+ if ( existing !== undefined && existing . path === path ) {
1418
+ return isString ( existing . buildInfo ) ?
1419
+ existing . buildInfo = ts . getBuildInfo ( existing . buildInfo ) :
1420
+ existing . buildInfo || undefined ;
1421
+ }
1409
1422
const value = state . readFileWithCache ( buildInfoPath ) ;
1410
1423
const buildInfo = value ? ts . getBuildInfo ( value ) : undefined ;
1411
- state . cache ?. buildInfoCache . set ( path , buildInfo || false ) ;
1424
+ state . buildInfoCache . set ( resolvedConfigPath , { path, buildInfo : buildInfo || false } ) ;
1412
1425
return buildInfo ;
1413
1426
}
1414
1427
@@ -1487,7 +1500,7 @@ namespace ts {
1487
1500
} ;
1488
1501
}
1489
1502
1490
- const buildInfo = Debug . checkDefined ( getBuildInfo ( state , buildInfoPath ) ) ;
1503
+ const buildInfo = Debug . checkDefined ( getBuildInfo ( state , buildInfoPath , resolvedPath ) ) ;
1491
1504
if ( ! state . buildInfoChecked . has ( resolvedPath ) ) {
1492
1505
state . buildInfoChecked . set ( resolvedPath , true ) ;
1493
1506
if ( buildInfo && ( buildInfo . bundle || buildInfo . program ) && buildInfo . version !== version ) {
0 commit comments