Skip to content

Commit c758e1a

Browse files
committed
Determine dts change based on outputs
1 parent 800be32 commit c758e1a

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/compiler/builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ namespace ts {
11641164
builderProgram.getState = getState;
11651165
builderProgram.saveEmitState = () => backupBuilderProgramEmitState(state);
11661166
builderProgram.restoreEmitState = (saved) => restoreBuilderProgramEmitState(state, saved);
1167+
builderProgram.hasChangedEmitSignature = () => !!state.hasChangedEmitSignature;
11671168
builderProgram.getAllDependencies = sourceFile => BuilderState.getAllDependencies(state, Debug.checkDefined(state.program), sourceFile);
11681169
builderProgram.getSemanticDiagnostics = getSemanticDiagnostics;
11691170
builderProgram.emit = emit;
@@ -1554,6 +1555,7 @@ namespace ts {
15541555
getSemanticDiagnosticsOfNextAffectedFile: notImplemented,
15551556
emitBuildInfo: notImplemented,
15561557
close: noop,
1558+
hasChangedEmitSignature: returnFalse,
15571559
};
15581560

15591561
function toPath(path: string) {

src/compiler/builderPublic.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace ts {
4242
saveEmitState(): SavedBuildProgramEmitState;
4343
/*@internal*/
4444
restoreEmitState(saved: SavedBuildProgramEmitState): void;
45+
/*@internal*/
46+
hasChangedEmitSignature?(): boolean;
4547
/**
4648
* Returns current program
4749
*/

src/compiler/tsbuildPublic.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -980,24 +980,21 @@ namespace ts {
980980

981981
// Actual Emit
982982
const { host, compilerHost } = state;
983-
let resultFlags = BuildResultFlags.DeclarationOutputUnchanged;
984-
const existingBuildInfo = state.buildInfoCache.get(projectPath)?.buildInfo || undefined;
983+
const hasChangedEmitSignature = program.hasChangedEmitSignature?.();
984+
let resultFlags = hasChangedEmitSignature ? BuildResultFlags.None : BuildResultFlags.DeclarationOutputUnchanged;
985985
const emitterDiagnostics = createDiagnosticCollection();
986986
const emittedOutputs = new Map<Path, string>();
987987
const options = program.getCompilerOptions();
988988
const isIncremental = isIncrementalCompilation(options);
989989
let outputTimeStampMap: ESMap<Path, Date> | undefined;
990990
let now: Date | undefined;
991+
// Check dts write only if hasChangedEmitSignature is not implemented
992+
const checkDtsChange = options.composite && hasChangedEmitSignature === undefined;
991993
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
992994
const path = toPath(state, name);
993995
emittedOutputs.set(toPath(state, name), name);
994-
if (buildInfo) {
995-
setBuildInfo(state, buildInfo, projectPath, options);
996-
// Buildinfo has information on when last dts change time
997-
if (buildInfo.program?.dtsChangeTime !== existingBuildInfo?.program?.dtsChangeTime) {
998-
resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
999-
}
1000-
}
996+
if (checkDtsChange && isDeclarationFileName(name)) resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
997+
if (buildInfo) setBuildInfo(state, buildInfo, projectPath, options);
1001998
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
1002999
if (!isIncremental && state.watch) {
10031000
(outputTimeStampMap ||= getOutputTimeStampMap(state, projectPath)!).set(path, now ||= getCurrentTime(state.host));
@@ -1116,15 +1113,10 @@ namespace ts {
11161113
const emitterDiagnostics = createDiagnosticCollection();
11171114
const emittedOutputs = new Map<Path, string>();
11181115
let resultFlags = BuildResultFlags.DeclarationOutputUnchanged;
1119-
const existingBuildInfo = state.buildInfoCache.get(projectPath)!.buildInfo as BuildInfo;
11201116
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
11211117
emittedOutputs.set(toPath(state, name), name);
1122-
if (buildInfo) {
1123-
setBuildInfo(state, buildInfo, projectPath, config.options);
1124-
if (buildInfo.program?.dtsChangeTime !== existingBuildInfo.program?.dtsChangeTime) {
1125-
resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
1126-
}
1127-
}
1118+
if (isDeclarationFileName(name)) resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
1119+
if (buildInfo) setBuildInfo(state, buildInfo, projectPath, config.options);
11281120
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
11291121
});
11301122

0 commit comments

Comments
 (0)