Skip to content

Commit dd96e33

Browse files
committed
Dont call getModifiedTimes if dts change
1 parent cb7aca3 commit dd96e33

16 files changed

+36
-74
lines changed

src/compiler/tsbuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ namespace ts {
6767
type: UpToDateStatusType.UpToDate | UpToDateStatusType.UpToDateWithUpstreamTypes;
6868
newestInputFileTime?: Date;
6969
newestInputFileName?: string;
70-
newestDeclarationFileContentChangedTime?: Date;
70+
newestDeclarationFileContentChangedTime: Date | undefined;
7171
oldestOutputFileName: string;
7272
}
7373

src/compiler/tsbuildPublic.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ namespace ts {
6868
return getOrCreateValueFromConfigFileMap<ESMap<string, T>>(configFileMap, resolved, () => new Map());
6969
}
7070

71-
function newer(date1: Date, date2: Date): Date {
72-
return date2 > date1 ? date2 : date1;
71+
function newer(date1: Date | undefined, date2: Date): Date | undefined {
72+
return date1 ? date2 > date1 ? date2 : date1 : date2;
7373
}
7474

7575
export type ReportEmitErrorSummary = (errorCount: number, filesInError: (ReportFileInError | undefined)[]) => void;
@@ -962,35 +962,28 @@ namespace ts {
962962
// Actual Emit
963963
const { host, compilerHost } = state;
964964
let resultFlags = BuildResultFlags.DeclarationOutputUnchanged;
965-
let newestDeclarationFileContentChangedTime = minimumDate;
966-
let anyDtsChanged = false;
965+
let newestDeclarationFileContentChangedTime: Date | undefined;
967966
const emitterDiagnostics = createDiagnosticCollection();
968967
const emittedOutputs = new Map<Path, string>();
969968
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
970-
let priorChangeTime: Date | undefined;
971-
if (!anyDtsChanged && isDeclarationFileName(name)) {
969+
if (resultFlags === BuildResultFlags.DeclarationOutputUnchanged && isDeclarationFileName(name)) {
972970
// Check for unchanged .d.ts files
973971
if (state.readFileWithCache(name) === text) {
974-
priorChangeTime = getModifiedTime(host, name);
972+
newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, getModifiedTime(host, name));
975973
}
976974
else {
977975
resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
978-
anyDtsChanged = true;
979976
}
980977
}
981978

982979
emittedOutputs.set(toPath(state, name), name);
983980
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
984-
if (priorChangeTime !== undefined) {
985-
newestDeclarationFileContentChangedTime = newer(priorChangeTime, newestDeclarationFileContentChangedTime);
986-
}
987981
});
988982

989983
finishEmit(
990984
emitterDiagnostics,
991985
emittedOutputs,
992986
newestDeclarationFileContentChangedTime,
993-
/*newestDeclarationFileContentChangedTimeIsMaximumDate*/ anyDtsChanged,
994987
outputFiles.length ? outputFiles[0].name : getFirstProjectOutput(config, !host.useCaseSensitiveFileNames()),
995988
resultFlags
996989
);
@@ -1018,8 +1011,7 @@ namespace ts {
10181011
function finishEmit(
10191012
emitterDiagnostics: DiagnosticCollection,
10201013
emittedOutputs: ESMap<Path, string>,
1021-
priorNewestUpdateTime: Date,
1022-
newestDeclarationFileContentChangedTimeIsMaximumDate: boolean,
1014+
newestDeclarationFileContentChangedTime: Date | undefined,
10231015
oldestOutputFileName: string,
10241016
resultFlags: BuildResultFlags
10251017
) {
@@ -1042,13 +1034,12 @@ namespace ts {
10421034
}
10431035

10441036
// Update time stamps for rest of the outputs
1045-
const newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(state, config, priorNewestUpdateTime, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, emittedOutputs);
1037+
const anyDtsChange = !(resultFlags & BuildResultFlags.DeclarationOutputUnchanged);
1038+
newestDeclarationFileContentChangedTime = updateOutputTimestampsWorker(state, config, anyDtsChange, Diagnostics.Updating_unchanged_output_timestamps_of_project_0, newestDeclarationFileContentChangedTime, emittedOutputs);
10461039
state.diagnostics.delete(projectPath);
10471040
state.projectStatus.set(projectPath, {
10481041
type: UpToDateStatusType.UpToDate,
1049-
newestDeclarationFileContentChangedTime: newestDeclarationFileContentChangedTimeIsMaximumDate ?
1050-
maximumDate :
1051-
newestDeclarationFileContentChangedTime,
1042+
newestDeclarationFileContentChangedTime: anyDtsChange ? undefined : newestDeclarationFileContentChangedTime,
10521043
oldestOutputFileName
10531044
});
10541045
afterProgramDone(state, program, config);
@@ -1107,8 +1098,7 @@ namespace ts {
11071098
const emitDiagnostics = finishEmit(
11081099
emitterDiagnostics,
11091100
emittedOutputs,
1110-
minimumDate,
1111-
/*newestDeclarationFileContentChangedTimeIsMaximumDate*/ false,
1101+
/*newestDeclarationFileContentChangedTime*/ undefined,
11121102
outputFiles[0].name,
11131103
BuildResultFlags.DeclarationOutputUnchanged
11141104
);
@@ -1419,7 +1409,7 @@ namespace ts {
14191409
// Now see if all outputs are newer than the newest input
14201410
let oldestOutputFileName = "(none)";
14211411
let oldestOutputFileTime = maximumDate;
1422-
let newestDeclarationFileContentChangedTime = minimumDate;
1412+
let newestDeclarationFileContentChangedTime;
14231413
if (!force) {
14241414
for (const output of outputs) {
14251415
// Output is missing; can stop checking
@@ -1548,8 +1538,8 @@ namespace ts {
15481538
return actual;
15491539
}
15501540

1551-
function updateOutputTimestampsWorker(state: SolutionBuilderState, proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: ESMap<Path, string>) {
1552-
if (proj.options.noEmit) return priorNewestUpdateTime;
1541+
function updateOutputTimestampsWorker(state: SolutionBuilderState, proj: ParsedCommandLine, anyDtsChange: boolean, verboseMessage: DiagnosticMessage, newestDeclarationFileContentChangedTime?: Date, skipOutputs?: ESMap<Path, string>) {
1542+
if (proj.options.noEmit) return undefined;
15531543
const { host } = state;
15541544
const outputs = getAllProjectOutputs(proj, !host.useCaseSensitiveFileNames());
15551545
if (!skipOutputs || outputs.length !== skipOutputs.size) {
@@ -1565,22 +1555,22 @@ namespace ts {
15651555
reportStatus(state, verboseMessage, proj.options.configFilePath!);
15661556
}
15671557

1568-
if (isDeclarationFileName(file)) {
1569-
priorNewestUpdateTime = newer(priorNewestUpdateTime, getModifiedTime(host, file));
1558+
if (!anyDtsChange && isDeclarationFileName(file)) {
1559+
newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, getModifiedTime(host, file));
15701560
}
15711561

15721562
host.setModifiedTime(file, now);
15731563
}
15741564
}
15751565

1576-
return priorNewestUpdateTime;
1566+
return newestDeclarationFileContentChangedTime;
15771567
}
15781568

15791569
function updateOutputTimestamps(state: SolutionBuilderState, proj: ParsedCommandLine, resolvedPath: ResolvedConfigFilePath) {
15801570
if (state.options.dry) {
15811571
return reportStatus(state, Diagnostics.A_non_dry_build_would_update_timestamps_for_output_of_project_0, proj.options.configFilePath!);
15821572
}
1583-
const priorNewestUpdateTime = updateOutputTimestampsWorker(state, proj, minimumDate, Diagnostics.Updating_output_timestamps_of_project_0);
1573+
const priorNewestUpdateTime = updateOutputTimestampsWorker(state, proj, /*anyDtsChange*/ false, Diagnostics.Updating_output_timestamps_of_project_0);
15841574
state.projectStatus.set(resolvedPath, {
15851575
type: UpToDateStatusType.UpToDate,
15861576
newestDeclarationFileContentChangedTime: priorNewestUpdateTime,

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/inferred-type-from-transitive-module-with-isolatedModules.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ getModifiedTime:: {
298298
"/src/index.ts": 1,
299299
"/src/lazyIndex.ts": 1,
300300
"/src/obj/bar.js": 1,
301-
"/src/obj/lazyIndex.d.ts": 1,
302-
"/src/obj/bundling.d.ts": 1
301+
"/src/obj/lazyIndex.d.ts": 1
303302
}
304303

305304
setModifiedTime:: {
@@ -464,8 +463,7 @@ getModifiedTime:: {
464463
"/src/index.ts": 1,
465464
"/src/lazyIndex.ts": 1,
466465
"/src/obj/bar.js": 1,
467-
"/src/obj/lazyIndex.d.ts": 1,
468-
"/src/obj/bundling.d.ts": 1
466+
"/src/obj/lazyIndex.d.ts": 1
469467
}
470468

471469
setModifiedTime:: {

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/inferred-type-from-transitive-module.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ getModifiedTime:: {
297297
"/src/global.d.ts": 1,
298298
"/src/index.ts": 1,
299299
"/src/lazyIndex.ts": 1,
300-
"/src/obj/bar.js": 1,
301-
"/src/obj/bundling.d.ts": 1
300+
"/src/obj/bar.js": 1
302301
}
303302

304303
setModifiedTime:: {
@@ -462,8 +461,7 @@ getModifiedTime:: {
462461
"/src/global.d.ts": 1,
463462
"/src/index.ts": 1,
464463
"/src/lazyIndex.ts": 1,
465-
"/src/obj/bar.js": 1,
466-
"/src/obj/bundling.d.ts": 1
464+
"/src/obj/bar.js": 1
467465
}
468466

469467
setModifiedTime:: {

tests/baselines/reference/tsbuild/inferredTypeFromTransitiveModule/reports-errors-in-files-affected-by-change-in-signature-with-isolatedModules.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,7 @@ getModifiedTime:: {
796796
"/src/global.d.ts": 1,
797797
"/src/index.ts": 1,
798798
"/src/lazyIndex.ts": 1,
799-
"/src/obj/bar.js": 1,
800-
"/src/obj/bundling.d.ts": 1
799+
"/src/obj/bar.js": 1
801800
}
802801

803802
setModifiedTime:: {

tests/baselines/reference/tsbuild/sample1/explainFiles.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ getModifiedTime:: {
538538
"/src/core/index.ts": 1,
539539
"/src/core/some_decl.d.ts": 1,
540540
"/src/core/anotherModule.js": 1,
541-
"/src/core/anotherModule.d.ts": 1,
542541
"/src/logic/index.ts": 1,
543542
"/src/logic/index.js": 1,
544543
"/src/logic/index.js.map": 1,

tests/baselines/reference/tsbuild/sample1/listEmittedFiles.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ getModifiedTime:: {
463463
"/src/core/index.ts": 1,
464464
"/src/core/some_decl.d.ts": 1,
465465
"/src/core/anotherModule.js": 1,
466-
"/src/core/anotherModule.d.ts": 1,
467466
"/src/logic/index.ts": 1,
468467
"/src/logic/index.js": 1,
469468
"/src/logic/index.js.map": 1,

tests/baselines/reference/tsbuild/sample1/listFiles.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ getModifiedTime:: {
464464
"/src/core/index.ts": 1,
465465
"/src/core/some_decl.d.ts": 1,
466466
"/src/core/anotherModule.js": 1,
467-
"/src/core/anotherModule.d.ts": 1,
468467
"/src/logic/index.ts": 1,
469468
"/src/logic/index.js": 1,
470469
"/src/logic/index.js.map": 1,

tests/baselines/reference/tsbuild/sample1/sample.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ getModifiedTime:: {
781781
"/src/core/index.ts": 1,
782782
"/src/core/some_decl.d.ts": 1,
783783
"/src/core/anotherModule.js": 1,
784-
"/src/core/anotherModule.d.ts": 1,
785784
"/src/logic/index.ts": 1,
786785
"/src/logic/index.js": 1,
787786
"/src/logic/index.js.map": 1,

tests/baselines/reference/tsbuildWatch/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,8 +1034,7 @@ directoryExists:: {
10341034
getModifiedTimes:: {
10351035
"/user/username/projects/myproject/packages/pkg2/const.cts": 1,
10361036
"/user/username/projects/myproject/packages/pkg2/index.cts": 1,
1037-
"/user/username/projects/myproject/packages/pkg2/build/const.cjs": 1,
1038-
"/user/username/projects/myproject/packages/pkg2/build/const.d.cts": 1
1037+
"/user/username/projects/myproject/packages/pkg2/build/const.cjs": 1
10391038
}
10401039

10411040
setModifiedTimes:: {

0 commit comments

Comments
 (0)