@@ -62,9 +62,9 @@ namespace ts {
62
62
*/
63
63
outSignature ?: string ;
64
64
/**
65
- * Time when d.ts was modified
65
+ * Name of the file whose dts was the latest to change
66
66
*/
67
- dtsChangeTime : number | undefined ;
67
+ latestChangedDtsFile : string | undefined ;
68
68
}
69
69
70
70
export const enum BuilderFileEmit {
@@ -112,7 +112,7 @@ namespace ts {
112
112
/**
113
113
* Records if change in dts emit was detected
114
114
*/
115
- hasChangedEmitSignature ?: boolean ;
115
+ hasChangedEmitSignature ?: boolean ;
116
116
/**
117
117
* Files pending to be emitted
118
118
*/
@@ -141,7 +141,7 @@ namespace ts {
141
141
"programEmitComplete" |
142
142
"emitSignatures" |
143
143
"outSignature" |
144
- "dtsChangeTime " |
144
+ "latestChangedDtsFile " |
145
145
"hasChangedEmitSignature"
146
146
> & { changedFilesSet : BuilderProgramState [ "changedFilesSet" ] | undefined } ;
147
147
@@ -167,7 +167,7 @@ namespace ts {
167
167
state . outSignature = oldState ?. outSignature ;
168
168
}
169
169
state . changedFilesSet = new Set ( ) ;
170
- state . dtsChangeTime = compilerOptions . composite ? oldState ?. dtsChangeTime : undefined ;
170
+ state . latestChangedDtsFile = compilerOptions . composite ? oldState ?. latestChangedDtsFile : undefined ;
171
171
172
172
const useOldState = BuilderState . canReuseOldState ( state . referencedMap , oldState ) ;
173
173
const oldCompilerOptions = useOldState ? oldState ! . compilerOptions : undefined ;
@@ -301,7 +301,7 @@ namespace ts {
301
301
programEmitComplete : state . programEmitComplete ,
302
302
emitSignatures : state . emitSignatures && new Map ( state . emitSignatures ) ,
303
303
outSignature : state . outSignature ,
304
- dtsChangeTime : state . dtsChangeTime ,
304
+ latestChangedDtsFile : state . latestChangedDtsFile ,
305
305
hasChangedEmitSignature : state . hasChangedEmitSignature ,
306
306
changedFilesSet : outFilePath ? new Set ( state . changedFilesSet ) : undefined ,
307
307
} ;
@@ -315,7 +315,7 @@ namespace ts {
315
315
state . programEmitComplete = savedEmitState . programEmitComplete ;
316
316
state . emitSignatures = savedEmitState . emitSignatures ;
317
317
state . outSignature = savedEmitState . outSignature ;
318
- state . dtsChangeTime = savedEmitState . dtsChangeTime ;
318
+ state . latestChangedDtsFile = savedEmitState . latestChangedDtsFile ;
319
319
state . hasChangedEmitSignature = savedEmitState . hasChangedEmitSignature ;
320
320
if ( savedEmitState . changedFilesSet ) state . changedFilesSet = savedEmitState . changedFilesSet ;
321
321
}
@@ -795,15 +795,16 @@ namespace ts {
795
795
affectedFilesPendingEmit ?: ProgramBuilderInfoFilePendingEmit [ ] ;
796
796
changeFileSet ?: readonly ProgramBuildInfoFileId [ ] ;
797
797
emitSignatures ?: readonly ProgramBuildInfoEmitSignature [ ] ;
798
- dtsChangeTime ?: number ;
798
+ // Because this is only output file in the program, we dont need fileId to deduplicate name
799
+ latestChangedDtsFile ?: string ;
799
800
}
800
801
801
802
export interface ProgramBundleEmitBuildInfo {
802
803
fileNames : readonly string [ ] ;
803
804
fileInfos : readonly string [ ] ;
804
805
options : CompilerOptions | undefined ;
805
806
outSignature ?: string ;
806
- dtsChangeTime ?: number ;
807
+ latestChangedDtsFile ?: string ;
807
808
}
808
809
809
810
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo ;
@@ -815,13 +816,13 @@ namespace ts {
815
816
/**
816
817
* Gets the program information to be emitted in buildInfo so that we can use it to create new program
817
818
*/
818
- function getProgramBuildInfo ( state : BuilderProgramState , getCanonicalFileName : GetCanonicalFileName , host : BuilderProgramHost ) : ProgramBuildInfo | undefined {
819
+ function getProgramBuildInfo ( state : BuilderProgramState , getCanonicalFileName : GetCanonicalFileName ) : ProgramBuildInfo | undefined {
819
820
const outFilePath = outFile ( state . compilerOptions ) ;
820
821
if ( outFilePath && ! state . compilerOptions . composite ) return ;
821
822
const currentDirectory = Debug . checkDefined ( state . program ) . getCurrentDirectory ( ) ;
822
823
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( getTsBuildInfoEmitOutputFilePath ( state . compilerOptions ) ! , currentDirectory ) ) ;
823
- // Update the dtsChange time in buildInfo
824
- state . dtsChangeTime = state . hasChangedEmitSignature ? getCurrentTime ( host ) . getTime ( ) : state . dtsChangeTime ;
824
+ // Convert the file name to Path here if we set the fileName instead to optimize multiple d.ts file emits and having to compute Canonical path
825
+ const latestChangedDtsFile = state . latestChangedDtsFile ? relativeToBuildInfoEnsuringAbsolutePath ( state . latestChangedDtsFile ) : undefined ;
825
826
if ( outFilePath ) {
826
827
const fileNames : string [ ] = [ ] ;
827
828
const fileInfos : string [ ] = [ ] ;
@@ -836,7 +837,7 @@ namespace ts {
836
837
fileInfos,
837
838
options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions , "affectsBundleEmitBuildInfo" ) ,
838
839
outSignature : state . outSignature ,
839
- dtsChangeTime : state . dtsChangeTime ,
840
+ latestChangedDtsFile ,
840
841
} ;
841
842
return result ;
842
843
}
@@ -939,7 +940,7 @@ namespace ts {
939
940
affectedFilesPendingEmit,
940
941
changeFileSet,
941
942
emitSignatures,
942
- dtsChangeTime : state . dtsChangeTime ,
943
+ latestChangedDtsFile ,
943
944
} ;
944
945
return result ;
945
946
@@ -1137,7 +1138,7 @@ namespace ts {
1137
1138
*/
1138
1139
const computeHash = maybeBind ( host , host . createHash ) ;
1139
1140
const state = createBuilderProgramState ( newProgram , getCanonicalFileName , oldState , host . disableUseFileVersionAsSignature ) ;
1140
- newProgram . getProgramBuildInfo = ( ) => getProgramBuildInfo ( state , getCanonicalFileName , host ) ;
1141
+ newProgram . getProgramBuildInfo = ( ) => getProgramBuildInfo ( state , getCanonicalFileName ) ;
1141
1142
1142
1143
// To ensure that we arent storing any references to old program or new program without state
1143
1144
newProgram = undefined ! ; // TODO: GH#18217
@@ -1149,6 +1150,7 @@ namespace ts {
1149
1150
builderProgram . getState = getState ;
1150
1151
builderProgram . saveEmitState = ( ) => backupBuilderProgramEmitState ( state ) ;
1151
1152
builderProgram . restoreEmitState = ( saved ) => restoreBuilderProgramEmitState ( state , saved ) ;
1153
+ builderProgram . hasChangedEmitSignature = ( ) => ! ! state . hasChangedEmitSignature ;
1152
1154
builderProgram . getAllDependencies = sourceFile => BuilderState . getAllDependencies ( state , Debug . checkDefined ( state . program ) , sourceFile ) ;
1153
1155
builderProgram . getSemanticDiagnostics = getSemanticDiagnostics ;
1154
1156
builderProgram . emit = emit ;
@@ -1279,18 +1281,20 @@ namespace ts {
1279
1281
const filePath = sourceFiles [ 0 ] . resolvedPath ;
1280
1282
const oldSignature = state . emitSignatures ?. get ( filePath ) ;
1281
1283
emitSignature ??= computeSignature ( text , computeHash , data ) ;
1282
- if ( emitSignature !== oldSignature ) {
1283
- ( state . emitSignatures ??= new Map ( ) ) . set ( filePath , emitSignature ) ;
1284
- state . hasChangedEmitSignature = true ;
1285
- }
1284
+ // Dont write dts files if they didn't change
1285
+ if ( emitSignature === oldSignature ) return ;
1286
+ ( state . emitSignatures ??= new Map ( ) ) . set ( filePath , emitSignature ) ;
1287
+ state . hasChangedEmitSignature = true ;
1288
+ state . latestChangedDtsFile = fileName ;
1286
1289
}
1287
1290
}
1288
1291
else if ( state . compilerOptions . composite ) {
1289
1292
const newSignature = computeSignature ( text , computeHash , data ) ;
1290
- if ( newSignature !== state . outSignature ) {
1291
- state . outSignature = newSignature ;
1292
- state . hasChangedEmitSignature = true ;
1293
- }
1293
+ // Dont write dts files if they didn't change
1294
+ if ( newSignature === state . outSignature ) return ;
1295
+ state . outSignature = newSignature ;
1296
+ state . hasChangedEmitSignature = true ;
1297
+ state . latestChangedDtsFile = fileName ;
1294
1298
}
1295
1299
}
1296
1300
if ( writeFile ) writeFile ( fileName , text , writeByteOrderMark , onError , sourceFiles , data ) ;
@@ -1472,11 +1476,12 @@ namespace ts {
1472
1476
let state : ReusableBuilderProgramState ;
1473
1477
let filePaths : Path [ ] | undefined ;
1474
1478
let filePathsSetList : Set < Path > [ ] | undefined ;
1479
+ const latestChangedDtsFile = program . latestChangedDtsFile ? toAbsolutePath ( program . latestChangedDtsFile ) : undefined ;
1475
1480
if ( isProgramBundleEmitBuildInfo ( program ) ) {
1476
1481
state = {
1477
1482
fileInfos : new Map ( ) ,
1478
1483
compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
1479
- dtsChangeTime : program . dtsChangeTime ,
1484
+ latestChangedDtsFile ,
1480
1485
outSignature : program . outSignature ,
1481
1486
} ;
1482
1487
}
@@ -1506,7 +1511,7 @@ namespace ts {
1506
1511
affectedFilesPendingEmitKind : program . affectedFilesPendingEmit && arrayToMap ( program . affectedFilesPendingEmit , value => toFilePath ( value [ 0 ] ) , value => value [ 1 ] ) ,
1507
1512
affectedFilesPendingEmitIndex : program . affectedFilesPendingEmit && 0 ,
1508
1513
changedFilesSet : new Set ( map ( program . changeFileSet , toFilePath ) ) ,
1509
- dtsChangeTime : program . dtsChangeTime ,
1514
+ latestChangedDtsFile ,
1510
1515
emitSignatures : emitSignatures ?. size ? emitSignatures : undefined ,
1511
1516
} ;
1512
1517
}
@@ -1534,6 +1539,7 @@ namespace ts {
1534
1539
getSemanticDiagnosticsOfNextAffectedFile : notImplemented ,
1535
1540
emitBuildInfo : notImplemented ,
1536
1541
close : noop ,
1542
+ hasChangedEmitSignature : returnFalse ,
1537
1543
} ;
1538
1544
1539
1545
function toPath ( path : string ) {
0 commit comments