Skip to content

Commit e6a3ee8

Browse files
committed
Handle force build as separate upto date status
1 parent 6e0c916 commit e6a3ee8

File tree

4 files changed

+45
-50
lines changed

4 files changed

+45
-50
lines changed

src/compiler/tsbuild.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace ts {
2626
/**
2727
* Projects with no outputs (i.e. "solution" files)
2828
*/
29-
ContainerOnly
29+
ContainerOnly,
30+
ForceBuild,
3031
}
3132

3233
export type UpToDateStatus =
@@ -40,7 +41,8 @@ namespace ts {
4041
| Status.UpstreamBlocked
4142
| Status.ComputingUpstream
4243
| Status.TsVersionOutOfDate
43-
| Status.ContainerOnly;
44+
| Status.ContainerOnly
45+
| Status.ForceBuild;
4446

4547
export namespace Status {
4648
/**
@@ -138,6 +140,10 @@ namespace ts {
138140
outOfDateOutputFileName: string;
139141
newerProjectName: string;
140142
}
143+
144+
export interface ForceBuild {
145+
type: UpToDateStatusType.ForceBuild;
146+
}
141147
}
142148

143149
export function resolveConfigFileProjectName(project: string): ResolvedConfigFileName {

src/compiler/tsbuildPublic.ts

+36-38
Original file line numberDiff line numberDiff line change
@@ -1470,45 +1470,45 @@ namespace ts {
14701470
}
14711471
}
14721472

1473+
if (force) return { type: UpToDateStatusType.ForceBuild };
1474+
14731475
// Collect the expected outputs of this project
14741476
const outputs = getAllProjectOutputs(project, !host.useCaseSensitiveFileNames());
14751477

14761478
// Now see if all outputs are newer than the newest input
14771479
let oldestOutputFileName = "(none)";
14781480
let oldestOutputFileTime = maximumDate;
14791481
let newestDeclarationFileContentChangedTime;
1480-
if (!force) {
1481-
for (const output of outputs) {
1482-
// Output is missing; can stop checking
1483-
const outputTime = ts.getModifiedTime(host, output);
1484-
if (outputTime === missingFileModifiedTime) {
1485-
return {
1486-
type: UpToDateStatusType.OutputMissing,
1487-
missingOutputFileName: output
1488-
};
1489-
}
1482+
for (const output of outputs) {
1483+
// Output is missing; can stop checking
1484+
const outputTime = ts.getModifiedTime(host, output);
1485+
if (outputTime === missingFileModifiedTime) {
1486+
return {
1487+
type: UpToDateStatusType.OutputMissing,
1488+
missingOutputFileName: output
1489+
};
1490+
}
14901491

1491-
if (outputTime < oldestOutputFileTime) {
1492-
oldestOutputFileTime = outputTime;
1493-
oldestOutputFileName = output;
1494-
}
1492+
if (outputTime < oldestOutputFileTime) {
1493+
oldestOutputFileTime = outputTime;
1494+
oldestOutputFileName = output;
1495+
}
14951496

1496-
// If an output is older than the newest input, we can stop checking
1497-
if (outputTime < newestInputFileTime) {
1498-
return {
1499-
type: UpToDateStatusType.OutOfDateWithSelf,
1500-
outOfDateOutputFileName: oldestOutputFileName,
1501-
newerInputFileName: newestInputFileName
1502-
};
1503-
}
1497+
// If an output is older than the newest input, we can stop checking
1498+
if (outputTime < newestInputFileTime) {
1499+
return {
1500+
type: UpToDateStatusType.OutOfDateWithSelf,
1501+
outOfDateOutputFileName: oldestOutputFileName,
1502+
newerInputFileName: newestInputFileName
1503+
};
1504+
}
15041505

1505-
// Keep track of when the most recent time a .d.ts file was changed.
1506-
// In addition to file timestamps, we also keep track of when a .d.ts file
1507-
// had its file touched but not had its contents changed - this allows us
1508-
// to skip a downstream typecheck
1509-
if (isDeclarationFileName(output)) {
1510-
newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, outputTime);
1511-
}
1506+
// Keep track of when the most recent time a .d.ts file was changed.
1507+
// In addition to file timestamps, we also keep track of when a .d.ts file
1508+
// had its file touched but not had its contents changed - this allows us
1509+
// to skip a downstream typecheck
1510+
if (isDeclarationFileName(output)) {
1511+
newestDeclarationFileContentChangedTime = newer(newestDeclarationFileContentChangedTime, outputTime);
15121512
}
15131513
}
15141514

@@ -1557,7 +1557,7 @@ namespace ts {
15571557
);
15581558
if (dependentPackageFileStatus) return dependentPackageFileStatus;
15591559

1560-
if (!force && !state.buildInfoChecked.has(resolvedPath)) {
1560+
if (!state.buildInfoChecked.has(resolvedPath)) {
15611561
state.buildInfoChecked.set(resolvedPath, true);
15621562
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(project.options);
15631563
if (buildInfoPath) {
@@ -2079,14 +2079,6 @@ namespace ts {
20792079
}
20802080

20812081
function reportUpToDateStatus(state: SolutionBuilderState, configFileName: string, status: UpToDateStatus) {
2082-
if (state.options.force && (status.type === UpToDateStatusType.UpToDate || status.type === UpToDateStatusType.UpToDateWithUpstreamTypes)) {
2083-
return reportStatus(
2084-
state,
2085-
Diagnostics.Project_0_is_being_forcibly_rebuilt,
2086-
relName(state, configFileName)
2087-
);
2088-
}
2089-
20902082
switch (status.type) {
20912083
case UpToDateStatusType.OutOfDateWithSelf:
20922084
return reportStatus(
@@ -2167,6 +2159,12 @@ namespace ts {
21672159
status.version,
21682160
version
21692161
);
2162+
case UpToDateStatusType.ForceBuild:
2163+
return reportStatus(
2164+
state,
2165+
Diagnostics.Project_0_is_being_forcibly_rebuilt,
2166+
relName(state, configFileName)
2167+
);
21702168
case UpToDateStatusType.ContainerOnly:
21712169
// Don't report status on "solution" projects
21722170
// falls through

tests/baselines/reference/tsbuild/sample1/always-builds-under-with-force-option.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,8 @@ getModifiedTime:: {
117117
"/src/core/anotherModule.ts": 1,
118118
"/src/core/index.ts": 1,
119119
"/src/core/some_decl.d.ts": 1,
120-
"/src/core/tsconfig.json": 1,
121120
"/src/logic/index.ts": 1,
122-
"/src/logic/tsconfig.json": 1,
123-
"/src/tests/index.ts": 1,
124-
"/src/tests/tsconfig.json": 1
121+
"/src/tests/index.ts": 1
125122
}
126123

127124
setModifiedTime:: {}
@@ -430,14 +427,11 @@ getModifiedTime:: {
430427
"/src/core/anotherModule.ts": 1,
431428
"/src/core/index.ts": 1,
432429
"/src/core/some_decl.d.ts": 1,
433-
"/src/core/tsconfig.json": 1,
434430
"/src/core/anotherModule.d.ts": 1,
435431
"/src/core/index.d.ts": 1,
436432
"/src/logic/index.ts": 1,
437-
"/src/logic/tsconfig.json": 1,
438433
"/src/logic/index.d.ts": 1,
439434
"/src/tests/index.ts": 1,
440-
"/src/tests/tsconfig.json": 1,
441435
"/src/tests/index.d.ts": 1
442436
}
443437

tests/baselines/reference/tsbuild/sample1/rebuilds-from-start-if-force-option-is-set.js

-3
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,11 @@ getModifiedTime:: {
407407
"/src/core/anotherModule.ts": 1,
408408
"/src/core/index.ts": 1,
409409
"/src/core/some_decl.d.ts": 1,
410-
"/src/core/tsconfig.json": 1,
411410
"/src/core/anotherModule.d.ts": 1,
412411
"/src/core/index.d.ts": 1,
413412
"/src/logic/index.ts": 1,
414-
"/src/logic/tsconfig.json": 1,
415413
"/src/logic/index.d.ts": 1,
416414
"/src/tests/index.ts": 1,
417-
"/src/tests/tsconfig.json": 1,
418415
"/src/tests/index.d.ts": 1
419416
}
420417

0 commit comments

Comments
 (0)