@@ -68,10 +68,6 @@ namespace ts {
68
68
return getOrCreateValueFromConfigFileMap ( configFileMap , resolved , ( ) => new Map ( ) ) ;
69
69
}
70
70
71
- function newer ( date1 : Date | undefined , date2 : Date ) : Date | undefined {
72
- return date1 ? date2 > date1 ? date2 : date1 : date2 ;
73
- }
74
-
75
71
/*@internal */
76
72
export function getCurrentTime ( host : { now ?( ) : Date ; } ) {
77
73
return host . now ? host . now ( ) : new Date ( ) ;
@@ -987,33 +983,23 @@ namespace ts {
987
983
// Actual Emit
988
984
const { host, compilerHost } = state ;
989
985
let resultFlags = BuildResultFlags . DeclarationOutputUnchanged ;
990
- let newestDeclarationFileContentChangedTime : Date | undefined ;
986
+ const existingBuildInfo = state . buildInfoCache . get ( projectPath ) ?. buildInfo | | undefined ;
991
987
const emitterDiagnostics = createDiagnosticCollection ( ) ;
992
988
const emittedOutputs = new Map < Path , string > ( ) ;
993
- const isOutFile = outFile ( config . options ) ;
994
989
outputFiles . forEach ( ( { name, text, writeByteOrderMark, buildInfo } ) => {
995
- if ( resultFlags === BuildResultFlags . DeclarationOutputUnchanged && isDeclarationFileName ( name ) ) {
996
- // Check for unchanged .d.ts files
997
- if ( state . readFileWithCache ( name ) === text ) {
998
- if ( config . options . composite && isOutFile ) {
999
- newestDeclarationFileContentChangedTime = newer ( newestDeclarationFileContentChangedTime , ts . getModifiedTime ( host , name ) ) ;
1000
- }
1001
- }
1002
- else {
990
+ emittedOutputs . set ( toPath ( state , name ) , name ) ;
991
+ if ( buildInfo ) {
992
+ setBuildInfo ( state , buildInfo , projectPath , program ! . getCompilerOptions ( ) ) ;
993
+ if ( buildInfo . program ?. dtsChangeTime !== existingBuildInfo ?. program ?. dtsChangeTime ) {
1003
994
resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
1004
995
}
1005
996
}
1006
-
1007
- const path = toPath ( state , name ) ;
1008
- emittedOutputs . set ( path , name ) ;
1009
- if ( buildInfo ) setBuildInfo ( state , buildInfo , projectPath , program ! . getCompilerOptions ( ) ) ;
1010
997
writeFile ( writeFileCallback ? { writeFile : writeFileCallback } : compilerHost , emitterDiagnostics , name , text , writeByteOrderMark ) ;
1011
998
} ) ;
1012
999
1013
1000
finishEmit (
1014
1001
emitterDiagnostics ,
1015
1002
emittedOutputs ,
1016
- newestDeclarationFileContentChangedTime ,
1017
1003
outputFiles . length ? outputFiles [ 0 ] . name : getFirstProjectOutput ( config , ! host . useCaseSensitiveFileNames ( ) ) ,
1018
1004
resultFlags
1019
1005
) ;
@@ -1045,7 +1031,6 @@ namespace ts {
1045
1031
function finishEmit (
1046
1032
emitterDiagnostics : DiagnosticCollection ,
1047
1033
emittedOutputs : ESMap < Path , string > ,
1048
- newestDeclarationFileContentChangedTime : Date | undefined ,
1049
1034
oldestOutputFileName : string ,
1050
1035
resultFlags : BuildResultFlags
1051
1036
) {
@@ -1068,12 +1053,11 @@ namespace ts {
1068
1053
}
1069
1054
1070
1055
// Update time stamps for rest of the outputs
1071
- const anyDtsChange = ! ( resultFlags & BuildResultFlags . DeclarationOutputUnchanged ) ;
1072
- newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker ( state , config , anyDtsChange , Diagnostics . Updating_unchanged_output_timestamps_of_project_0 , newestDeclarationFileContentChangedTime , emittedOutputs ) ;
1056
+ updateOutputTimestampsWorker ( state , config , Diagnostics . Updating_unchanged_output_timestamps_of_project_0 , emittedOutputs ) ;
1073
1057
state . diagnostics . delete ( projectPath ) ;
1074
1058
state . projectStatus . set ( projectPath , {
1075
1059
type : UpToDateStatusType . UpToDate ,
1076
- newestDeclarationFileContentChangedTime : newestDeclarationFileContentChangedTime || getDtsChangeTime ( state , config . options , projectPath ) ,
1060
+ newestDeclarationFileContentChangedTime : getDtsChangeTime ( state , config . options , projectPath ) ,
1077
1061
oldestOutputFileName
1078
1062
} ) ;
1079
1063
afterProgramDone ( state , program , config ) ;
@@ -1124,19 +1108,24 @@ namespace ts {
1124
1108
Debug . assert ( ! ! outputFiles . length ) ;
1125
1109
const emitterDiagnostics = createDiagnosticCollection ( ) ;
1126
1110
const emittedOutputs = new Map < Path , string > ( ) ;
1111
+ let resultFlags = BuildResultFlags . DeclarationOutputUnchanged ;
1112
+ const existingBuildInfo = state . buildInfoCache . get ( projectPath ) ! . buildInfo as BuildInfo ;
1127
1113
outputFiles . forEach ( ( { name, text, writeByteOrderMark, buildInfo } ) => {
1128
- const path = toPath ( state , name ) ;
1129
- emittedOutputs . set ( path , name ) ;
1130
- if ( buildInfo ) setBuildInfo ( state , buildInfo , projectPath , config . options ) ;
1114
+ emittedOutputs . set ( toPath ( state , name ) , name ) ;
1115
+ if ( buildInfo ) {
1116
+ setBuildInfo ( state , buildInfo , projectPath , config . options ) ;
1117
+ if ( buildInfo . program ?. dtsChangeTime !== existingBuildInfo . program ?. dtsChangeTime ) {
1118
+ resultFlags &= ~ BuildResultFlags . DeclarationOutputUnchanged ;
1119
+ }
1120
+ }
1131
1121
writeFile ( writeFileCallback ? { writeFile : writeFileCallback } : compilerHost , emitterDiagnostics , name , text , writeByteOrderMark ) ;
1132
1122
} ) ;
1133
1123
1134
1124
const emitDiagnostics = finishEmit (
1135
1125
emitterDiagnostics ,
1136
1126
emittedOutputs ,
1137
- /*newestDeclarationFileContentChangedTime*/ undefined ,
1138
1127
outputFiles [ 0 ] . name ,
1139
- BuildResultFlags . DeclarationOutputUnchanged
1128
+ resultFlags
1140
1129
) ;
1141
1130
return { emitSkipped : false , diagnostics : emitDiagnostics } ;
1142
1131
}
@@ -1718,13 +1707,24 @@ namespace ts {
1718
1707
return actual ;
1719
1708
}
1720
1709
1721
- function updateOutputTimestampsWorker ( state : SolutionBuilderState , proj : ParsedCommandLine , anyDtsChange : boolean , verboseMessage : DiagnosticMessage , newestDeclarationFileContentChangedTime ?: Date , skipOutputs ?: ESMap < Path , string > ) {
1722
- if ( proj . options . noEmit ) return undefined ;
1723
-
1710
+ function updateOutputTimestampsWorker (
1711
+ state : SolutionBuilderState ,
1712
+ proj : ParsedCommandLine ,
1713
+ verboseMessage : DiagnosticMessage ,
1714
+ skipOutputs ?: ESMap < Path , string >
1715
+ ) {
1716
+ if ( proj . options . noEmit ) return ;
1724
1717
const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( proj . options ) ;
1718
+ if ( buildInfoPath ) {
1719
+ if ( ! skipOutputs ?. has ( toPath ( state , buildInfoPath ) ) ) {
1720
+ if ( ! ! state . options . verbose ) reportStatus ( state , verboseMessage , proj . options . configFilePath ! ) ;
1721
+ state . host . setModifiedTime ( buildInfoPath , getCurrentTime ( state . host ) ) ;
1722
+ }
1723
+ return ;
1724
+ }
1725
+
1725
1726
const { host } = state ;
1726
1727
const outputs = getAllProjectOutputs ( proj , ! host . useCaseSensitiveFileNames ( ) ) ;
1727
- const isOutFile = outFile ( proj . options ) ;
1728
1728
if ( ! skipOutputs || outputs . length !== skipOutputs . size ) {
1729
1729
let reportVerbose = ! ! state . options . verbose ;
1730
1730
let now : Date | undefined ;
@@ -1733,26 +1733,18 @@ namespace ts {
1733
1733
continue ;
1734
1734
}
1735
1735
1736
- if ( proj . options . composite && isOutFile && ! anyDtsChange && isDeclarationFileName ( file ) ) {
1737
- newestDeclarationFileContentChangedTime = newer ( newestDeclarationFileContentChangedTime , ts . getModifiedTime ( host , file ) ) ;
1736
+ if ( reportVerbose ) {
1737
+ reportVerbose = false ;
1738
+ reportStatus ( state , verboseMessage , proj . options . configFilePath ! ) ;
1738
1739
}
1739
1740
1740
- if ( ! buildInfoPath || file === buildInfoPath ) {
1741
- if ( reportVerbose ) {
1742
- reportVerbose = false ;
1743
- reportStatus ( state , verboseMessage , proj . options . configFilePath ! ) ;
1744
- }
1745
-
1746
- host . setModifiedTime ( file , now ||= getCurrentTime ( state . host ) ) ;
1747
- }
1741
+ host . setModifiedTime ( file , now ||= getCurrentTime ( state . host ) ) ;
1748
1742
}
1749
1743
}
1750
-
1751
- return newestDeclarationFileContentChangedTime ;
1752
1744
}
1753
1745
1754
1746
function getDtsChangeTime ( state : SolutionBuilderState , options : CompilerOptions , resolvedConfigPath : ResolvedConfigFilePath ) {
1755
- if ( ! options . composite || outFile ( options ) ) return undefined ;
1747
+ if ( ! options . composite ) return undefined ;
1756
1748
const buildInfoPath = getTsBuildInfoEmitOutputFilePath ( options ) ! ;
1757
1749
const buildInfo = getBuildInfo ( state , buildInfoPath , resolvedConfigPath , /*modifiedTime*/ undefined ) ;
1758
1750
return buildInfo ?. program ?. dtsChangeTime ? new Date ( buildInfo . program . dtsChangeTime ) : undefined ;
@@ -1762,10 +1754,10 @@ namespace ts {
1762
1754
if ( state . options . dry ) {
1763
1755
return reportStatus ( state , Diagnostics . A_non_dry_build_would_update_timestamps_for_output_of_project_0 , proj . options . configFilePath ! ) ;
1764
1756
}
1765
- const priorNewestUpdateTime = updateOutputTimestampsWorker ( state , proj , /*anyDtsChange*/ false , Diagnostics . Updating_output_timestamps_of_project_0 ) ;
1757
+ updateOutputTimestampsWorker ( state , proj , Diagnostics . Updating_output_timestamps_of_project_0 ) ;
1766
1758
state . projectStatus . set ( resolvedPath , {
1767
1759
type : UpToDateStatusType . UpToDate ,
1768
- newestDeclarationFileContentChangedTime : priorNewestUpdateTime || getDtsChangeTime ( state , proj . options , resolvedPath ) ,
1760
+ newestDeclarationFileContentChangedTime : getDtsChangeTime ( state , proj . options , resolvedPath ) ,
1769
1761
oldestOutputFileName : getFirstProjectOutput ( proj , ! state . host . useCaseSensitiveFileNames ( ) )
1770
1762
} ) ;
1771
1763
}
0 commit comments