Skip to content

Commit 882fb8c

Browse files
committed
Instead of storing time in buildinfo store filename which was last updated to get modified time stamp from
1 parent c758e1a commit 882fb8c

File tree

187 files changed

+2904
-4044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+2904
-4044
lines changed

src/compiler/builder.ts

+2-18
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ namespace ts {
6161
* Hash of d.ts emit with --out
6262
*/
6363
outSignature?: string;
64-
/**
65-
* Time when d.ts was modified
66-
*/
67-
dtsChangeTime: number | undefined;
6864
/**
6965
* Name of the file whose dts was the latest to change
7066
*/
@@ -145,7 +141,6 @@ namespace ts {
145141
"programEmitComplete" |
146142
"emitSignatures" |
147143
"outSignature" |
148-
"dtsChangeTime" |
149144
"dtsChangeFile" |
150145
"hasChangedEmitSignature"
151146
> & { changedFilesSet: BuilderProgramState["changedFilesSet"] | undefined };
@@ -172,7 +167,6 @@ namespace ts {
172167
state.outSignature = oldState?.outSignature;
173168
}
174169
state.changedFilesSet = new Set();
175-
state.dtsChangeTime = compilerOptions.composite ? oldState?.dtsChangeTime : undefined;
176170
state.dtsChangeFile = compilerOptions.composite ? oldState?.dtsChangeFile : undefined;
177171

178172
const useOldState = BuilderState.canReuseOldState(state.referencedMap, oldState);
@@ -307,7 +301,6 @@ namespace ts {
307301
programEmitComplete: state.programEmitComplete,
308302
emitSignatures: state.emitSignatures && new Map(state.emitSignatures),
309303
outSignature: state.outSignature,
310-
dtsChangeTime: state.dtsChangeTime,
311304
dtsChangeFile: state.dtsChangeFile,
312305
hasChangedEmitSignature: state.hasChangedEmitSignature,
313306
changedFilesSet: outFilePath ? new Set(state.changedFilesSet) : undefined,
@@ -322,7 +315,6 @@ namespace ts {
322315
state.programEmitComplete = savedEmitState.programEmitComplete;
323316
state.emitSignatures = savedEmitState.emitSignatures;
324317
state.outSignature = savedEmitState.outSignature;
325-
state.dtsChangeTime = savedEmitState.dtsChangeTime;
326318
state.dtsChangeFile = savedEmitState.dtsChangeFile;
327319
state.hasChangedEmitSignature = savedEmitState.hasChangedEmitSignature;
328320
if (savedEmitState.changedFilesSet) state.changedFilesSet = savedEmitState.changedFilesSet;
@@ -803,7 +795,6 @@ namespace ts {
803795
affectedFilesPendingEmit?: ProgramBuilderInfoFilePendingEmit[];
804796
changeFileSet?: readonly ProgramBuildInfoFileId[];
805797
emitSignatures?: readonly ProgramBuildInfoEmitSignature[];
806-
dtsChangeTime?: number;
807798
// Because this is only output file in the program, we dont need fileId to deduplicate name
808799
dtsChangeFile?: string;
809800
}
@@ -813,7 +804,6 @@ namespace ts {
813804
fileInfos: readonly string[];
814805
options: CompilerOptions | undefined;
815806
outSignature?: string;
816-
dtsChangeTime?: number;
817807
dtsChangeFile?: string;
818808
}
819809

@@ -826,13 +816,11 @@ namespace ts {
826816
/**
827817
* Gets the program information to be emitted in buildInfo so that we can use it to create new program
828818
*/
829-
function getProgramBuildInfo(state: BuilderProgramState, getCanonicalFileName: GetCanonicalFileName, host: BuilderProgramHost): ProgramBuildInfo | undefined {
819+
function getProgramBuildInfo(state: BuilderProgramState, getCanonicalFileName: GetCanonicalFileName): ProgramBuildInfo | undefined {
830820
const outFilePath = outFile(state.compilerOptions);
831821
if (outFilePath && !state.compilerOptions.composite) return;
832822
const currentDirectory = Debug.checkDefined(state.program).getCurrentDirectory();
833823
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getTsBuildInfoEmitOutputFilePath(state.compilerOptions)!, currentDirectory));
834-
// Update the dtsChange time in buildInfo
835-
state.dtsChangeTime = state.hasChangedEmitSignature ? getCurrentTime(host).getTime() : state.dtsChangeTime;
836824
// 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
837825
const dtsChangeFile = state.dtsChangeFile ? relativeToBuildInfoEnsuringAbsolutePath(state.dtsChangeFile) : undefined;
838826
if (outFilePath) {
@@ -849,7 +837,6 @@ namespace ts {
849837
fileInfos,
850838
options: convertToProgramBuildInfoCompilerOptions(state.compilerOptions, "affectsBundleEmitBuildInfo"),
851839
outSignature: state.outSignature,
852-
dtsChangeTime: state.dtsChangeTime,
853840
dtsChangeFile,
854841
};
855842
return result;
@@ -953,7 +940,6 @@ namespace ts {
953940
affectedFilesPendingEmit,
954941
changeFileSet,
955942
emitSignatures,
956-
dtsChangeTime: state.dtsChangeTime,
957943
dtsChangeFile,
958944
};
959945
return result;
@@ -1152,7 +1138,7 @@ namespace ts {
11521138
*/
11531139
const computeHash = maybeBind(host, host.createHash);
11541140
const state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState, host.disableUseFileVersionAsSignature);
1155-
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName, host);
1141+
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName);
11561142

11571143
// To ensure that we arent storing any references to old program or new program without state
11581144
newProgram = undefined!; // TODO: GH#18217
@@ -1495,7 +1481,6 @@ namespace ts {
14951481
state = {
14961482
fileInfos: new Map(),
14971483
compilerOptions: program.options ? convertToOptionsWithAbsolutePaths(program.options, toAbsolutePath) : {},
1498-
dtsChangeTime: program.dtsChangeTime,
14991484
dtsChangeFile,
15001485
outSignature: program.outSignature,
15011486
};
@@ -1526,7 +1511,6 @@ namespace ts {
15261511
affectedFilesPendingEmitKind: program.affectedFilesPendingEmit && arrayToMap(program.affectedFilesPendingEmit, value => toFilePath(value[0]), value => value[1]),
15271512
affectedFilesPendingEmitIndex: program.affectedFilesPendingEmit && 0,
15281513
changedFilesSet: new Set(map(program.changeFileSet, toFilePath)),
1529-
dtsChangeTime: program.dtsChangeTime,
15301514
dtsChangeFile,
15311515
emitSignatures: emitSignatures?.size ? emitSignatures : undefined,
15321516
};

src/compiler/emitter.ts

-2
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ namespace ts {
712712
useCaseSensitiveFileNames(): boolean;
713713
getNewLine(): string;
714714
createHash?(data: string): string;
715-
now?(): Date;
716715
getBuildInfo?(fileName: string, configFilePath: string | undefined): BuildInfo | undefined;
717716
}
718717

@@ -832,7 +831,6 @@ namespace ts {
832831
if (newBuildInfo.program && changedDtsText !== undefined && config.options.composite) {
833832
// Update the output signature
834833
(newBuildInfo.program as ProgramBundleEmitBuildInfo).outSignature = computeSignature(changedDtsText, createHash, changedDtsData);
835-
newBuildInfo.program.dtsChangeTime = getCurrentTime(host).getTime();
836834
}
837835
// Update sourceFileInfo
838836
const { js, dts, sourceFiles } = buildInfo.bundle!;

src/compiler/tsbuildPublic.ts

+44-25
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ namespace ts {
224224
path: Path;
225225
buildInfo: BuildInfo | false;
226226
modifiedTime: Date;
227+
dtsChangeTime?: Date | false;
227228
}
228229

229230
interface SolutionBuilderState<T extends BuilderProgram = BuilderProgram> extends WatchFactory<WatchType, ResolvedConfigFileName> {
@@ -980,21 +981,17 @@ namespace ts {
980981

981982
// Actual Emit
982983
const { host, compilerHost } = state;
983-
const hasChangedEmitSignature = program.hasChangedEmitSignature?.();
984-
let resultFlags = hasChangedEmitSignature ? BuildResultFlags.None : BuildResultFlags.DeclarationOutputUnchanged;
984+
const resultFlags = program.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;
993991
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
994992
const path = toPath(state, name);
995993
emittedOutputs.set(toPath(state, name), name);
996-
if (checkDtsChange && isDeclarationFileName(name)) resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
997-
if (buildInfo) setBuildInfo(state, buildInfo, projectPath, options);
994+
if (buildInfo) setBuildInfo(state, buildInfo, projectPath, options, resultFlags);
998995
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
999996
if (!isIncremental && state.watch) {
1000997
(outputTimeStampMap ||= getOutputTimeStampMap(state, projectPath)!).set(path, now ||= getCurrentTime(state.host));
@@ -1014,7 +1011,7 @@ namespace ts {
10141011
Debug.assertIsDefined(program);
10151012
Debug.assert(step === BuildStep.EmitBuildInfo);
10161013
const emitResult = program.emitBuildInfo((name, text, writeByteOrderMark, onError, sourceFiles, data) => {
1017-
if (data?.buildInfo) setBuildInfo(state, data.buildInfo, projectPath, program!.getCompilerOptions());
1014+
if (data?.buildInfo) setBuildInfo(state, data.buildInfo, projectPath, program!.getCompilerOptions(), BuildResultFlags.DeclarationOutputUnchanged);
10181015
if (writeFileCallback) writeFileCallback(name, text, writeByteOrderMark, onError, sourceFiles, data);
10191016
else state.compilerHost.writeFile(name, text, writeByteOrderMark, onError, sourceFiles, data);
10201017
}, cancellationToken);
@@ -1113,10 +1110,15 @@ namespace ts {
11131110
const emitterDiagnostics = createDiagnosticCollection();
11141111
const emittedOutputs = new Map<Path, string>();
11151112
let resultFlags = BuildResultFlags.DeclarationOutputUnchanged;
1113+
const existingBuildInfo = state.buildInfoCache.get(projectPath)!.buildInfo as BuildInfo;
11161114
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
11171115
emittedOutputs.set(toPath(state, name), name);
1118-
if (isDeclarationFileName(name)) resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
1119-
if (buildInfo) setBuildInfo(state, buildInfo, projectPath, config.options);
1116+
if (buildInfo) {
1117+
if ((buildInfo.program as ProgramBundleEmitBuildInfo)?.outSignature !== (existingBuildInfo.program as ProgramBundleEmitBuildInfo)?.outSignature) {
1118+
resultFlags &= ~BuildResultFlags.DeclarationOutputUnchanged;
1119+
}
1120+
setBuildInfo(state, buildInfo, projectPath, config.options, resultFlags);
1121+
}
11201122
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
11211123
});
11221124

@@ -1456,15 +1458,28 @@ namespace ts {
14561458
return result;
14571459
}
14581460

1459-
function setBuildInfo(state: SolutionBuilderState, buildInfo: BuildInfo, resolvedConfigPath: ResolvedConfigFilePath, options: CompilerOptions) {
1461+
function setBuildInfo(
1462+
state: SolutionBuilderState,
1463+
buildInfo: BuildInfo,
1464+
resolvedConfigPath: ResolvedConfigFilePath,
1465+
options: CompilerOptions,
1466+
resultFlags: BuildResultFlags,
1467+
) {
14601468
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options)!;
14611469
const existing = getBuildInfoCacheEntry(state, buildInfoPath, resolvedConfigPath);
1470+
const modifiedTime = getCurrentTime(state.host);
14621471
if (existing) {
14631472
existing.buildInfo = buildInfo;
1464-
existing.modifiedTime = getCurrentTime(state.host);
1473+
existing.modifiedTime = modifiedTime;
1474+
if (!(resultFlags & BuildResultFlags.DeclarationOutputUnchanged)) existing.dtsChangeTime = modifiedTime;
14651475
}
14661476
else {
1467-
state.buildInfoCache.set(resolvedConfigPath, { path: toPath(state, buildInfoPath), buildInfo, modifiedTime: getCurrentTime(state.host) });
1477+
state.buildInfoCache.set(resolvedConfigPath, {
1478+
path: toPath(state, buildInfoPath),
1479+
buildInfo,
1480+
modifiedTime,
1481+
dtsChangeTime: resultFlags & BuildResultFlags.DeclarationOutputUnchanged ? undefined : modifiedTime,
1482+
});
14681483
}
14691484
}
14701485

@@ -1474,17 +1489,19 @@ namespace ts {
14741489
return existing?.path === path ? existing : undefined;
14751490
}
14761491

1477-
function getBuildInfo(state: SolutionBuilderState, buildInfoPath: string, resolvedConfigPath: ResolvedConfigFilePath, modifiedTime: Date | undefined): BuildInfo | undefined {
1492+
function getOrCreateBuildInfoCacheEntry(state: SolutionBuilderState, buildInfoPath: string, resolvedConfigPath: ResolvedConfigFilePath, modifiedTime: Date | undefined) {
14781493
const path = toPath(state, buildInfoPath);
1479-
const existing = state.buildInfoCache.get(resolvedConfigPath);
1480-
if (existing !== undefined && existing.path === path) {
1481-
return existing.buildInfo || undefined;
1482-
}
1494+
let result = state.buildInfoCache.get(resolvedConfigPath);
1495+
if (result && result.path === path) return result;
14831496
const value = state.readFileWithCache(buildInfoPath);
14841497
const buildInfo = value ? ts.getBuildInfo(value) : undefined;
14851498
Debug.assert(modifiedTime || !buildInfo);
1486-
state.buildInfoCache.set(resolvedConfigPath, { path, buildInfo: buildInfo || false, modifiedTime: modifiedTime || missingFileModifiedTime });
1487-
return buildInfo;
1499+
state.buildInfoCache.set(resolvedConfigPath, result = { path, buildInfo: buildInfo || false, modifiedTime: modifiedTime || missingFileModifiedTime });
1500+
return result;
1501+
}
1502+
1503+
function getBuildInfo(state: SolutionBuilderState, buildInfoPath: string, resolvedConfigPath: ResolvedConfigFilePath, modifiedTime: Date | undefined): BuildInfo | undefined {
1504+
return getOrCreateBuildInfoCacheEntry(state, buildInfoPath, resolvedConfigPath, modifiedTime).buildInfo || undefined;
14881505
}
14891506

14901507
function checkConfigFileUpToDateStatus(state: SolutionBuilderState, configFile: string, oldestOutputFileTime: Date, oldestOutputFileName: string): Status.OutOfDateWithSelf | undefined {
@@ -1555,7 +1572,6 @@ namespace ts {
15551572
let buildInfoTime: Date | undefined;
15561573
let buildInfoProgram: ProgramBuildInfo | undefined;
15571574
let buildInfoVersionMap: ESMap<Path, string> | undefined;
1558-
let newestDeclarationFileContentChangedTime;
15591575
if (buildInfoPath) {
15601576
const buildInfoCacheEntry = getBuildInfoCacheEntry(state, buildInfoPath, resolvedPath);
15611577
buildInfoTime = buildInfoCacheEntry?.modifiedTime || ts.getModifiedTime(host, buildInfoPath);
@@ -1595,8 +1611,6 @@ namespace ts {
15951611

15961612
oldestOutputFileTime = buildInfoTime;
15971613
oldestOutputFileName = buildInfoPath;
1598-
// Get the last dtsChange time from build info
1599-
newestDeclarationFileContentChangedTime = buildInfo.program?.dtsChangeTime ? new Date(buildInfo.program.dtsChangeTime) : undefined;
16001614
}
16011615

16021616
// Check input files
@@ -1756,7 +1770,7 @@ namespace ts {
17561770
pseudoInputUpToDate ?
17571771
UpToDateStatusType.UpToDateWithInputFileText :
17581772
UpToDateStatusType.UpToDate,
1759-
newestDeclarationFileContentChangedTime,
1773+
newestDeclarationFileContentChangedTime: getDtsChangeTime(state, project.options, resolvedPath),
17601774
newestInputFileTime,
17611775
newestInputFileName,
17621776
oldestOutputFileName: oldestOutputFileName!
@@ -1849,8 +1863,13 @@ namespace ts {
18491863
function getDtsChangeTime(state: SolutionBuilderState, options: CompilerOptions, resolvedConfigPath: ResolvedConfigFilePath) {
18501864
if (!options.composite) return undefined;
18511865
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options)!;
1852-
const buildInfo = getBuildInfo(state, buildInfoPath, resolvedConfigPath, /*modifiedTime*/ undefined);
1853-
return buildInfo?.program?.dtsChangeTime ? new Date(buildInfo.program.dtsChangeTime) : undefined;
1866+
const entry = getOrCreateBuildInfoCacheEntry(state, buildInfoPath, resolvedConfigPath, /*modifiedTime*/ undefined);
1867+
if (entry.dtsChangeTime !== undefined) return entry.dtsChangeTime || undefined;
1868+
const dtsChangeTime = entry.buildInfo && entry.buildInfo.program && entry.buildInfo.program.dtsChangeFile ?
1869+
state.host.getModifiedTime(getNormalizedAbsolutePath(entry.buildInfo.program.dtsChangeFile, getDirectoryPath(entry.path))) :
1870+
undefined;
1871+
entry.dtsChangeTime = dtsChangeTime || false;
1872+
return dtsChangeTime;
18541873
}
18551874

18561875
function updateOutputTimestamps(state: SolutionBuilderState, proj: ParsedCommandLine, resolvedPath: ResolvedConfigFilePath) {

src/compiler/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6981,7 +6981,6 @@ namespace ts {
69816981
// For testing:
69826982
/*@internal*/ disableUseFileVersionAsSignature?: boolean;
69836983
/*@internal*/ storeFilesChangingSignatureDuringEmit?: boolean;
6984-
/*@internal*/ now?(): Date;
69856984
}
69866985

69876986
/** true if --out otherwise source file name */

src/compiler/watch.ts

-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ namespace ts {
596596
readDirectory: maybeBind(host, host.readDirectory),
597597
disableUseFileVersionAsSignature: host.disableUseFileVersionAsSignature,
598598
storeFilesChangingSignatureDuringEmit: host.storeFilesChangingSignatureDuringEmit,
599-
now: maybeBind(host, host.now),
600599
};
601600

602601
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) {

src/compiler/watchPublic.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace ts {
3030
host.createHash = maybeBind(system, system.createHash);
3131
host.disableUseFileVersionAsSignature = system.disableUseFileVersionAsSignature;
3232
host.storeFilesChangingSignatureDuringEmit = system.storeFilesChangingSignatureDuringEmit;
33-
host.now = maybeBind(system, system.now);
3433
setGetSourceFileAsHashVersioned(host, system);
3534
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, host.getCurrentDirectory(), host.getCanonicalFileName));
3635
return host;

src/testRunner/unittests/tsbuild/helpers.ts

-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ interface Symbol {
263263
toFileName(s) :
264264
[toFileName(s[0]), s[1]]
265265
),
266-
dtsChangeTime: buildInfo.program.dtsChangeTime,
267266
dtsChangeFile: buildInfo.program.dtsChangeFile,
268267
};
269268
}
@@ -545,7 +544,6 @@ interface Symbol {
545544
options: { ...readableBuildInfo.program.options, noEmit: undefined },
546545
exportedModulesMap: undefined,
547546
affectedFilesPendingEmit: undefined,
548-
dtsChangeTime: readableBuildInfo.program.dtsChangeTime ? "FakeTime" : undefined,
549547
dtsChangeFile: readableBuildInfo.program.dtsChangeFile ? "FakeFileName" : undefined,
550548
},
551549
size: undefined, // Size doesnt need to be equal

0 commit comments

Comments
 (0)