Skip to content

Commit 7356020

Browse files
committed
Write buildInfo irrespective of incremental if invoked from tsc --b
1 parent 64d29c6 commit 7356020

File tree

171 files changed

+2606
-294
lines changed

Some content is hidden

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

171 files changed

+2606
-294
lines changed

src/compiler/builder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
HostForComputeHash,
5757
isArray,
5858
isDeclarationFileName,
59+
isIncrementalCompilation,
5960
isJsonSourceFile,
6061
isNumber,
6162
isString,
@@ -376,7 +377,7 @@ function createBuilderProgramState(
376377
}
377378
else {
378379
// We arent using old state, so atleast emit buildInfo with current information
379-
state.buildInfoEmitPending = true;
380+
state.buildInfoEmitPending = isIncrementalCompilation(compilerOptions);
380381
}
381382

382383
// Update changed files and copy semantic diagnostics if we can
@@ -1190,6 +1191,9 @@ function getBuildInfo(state: BuilderProgramStateWithDefinedProgram): BuildInfo {
11901191
const fileNames: string[] = [];
11911192
const fileNameToFileId = new Map<string, ProgramBuildInfoFileId>();
11921193
const rootFileNames = new Set(state.program.getRootFileNames().map(f => toPath(f, currentDirectory, state.program.getCanonicalFileName)));
1194+
1195+
if (!isIncrementalCompilation(state.compilerOptions)) return createBuildInfo(/*program*/ undefined);
1196+
11931197
const root: ProgramBuildInfoRoot[] = [];
11941198
if (state.compilerOptions.outFile) {
11951199
// Copy all fileInfo, version and impliedFormat

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,6 +4617,10 @@
46174617
"category": "Error",
46184618
"code": 5110
46194619
},
4620+
"Option 'tsBuildInfoFile' cannot be specified without specifying option 'incremental' or 'composite' or if not running 'tsc -b'.": {
4621+
"category": "Error",
4622+
"code": 5111
4623+
},
46204624

46214625
"Generates a sourcemap for each corresponding '.d.ts' file.": {
46224626
"category": "Message",

src/compiler/emitter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ export function forEachEmittedFile<T>(
480480

481481
export function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions) {
482482
const configFile = options.configFilePath;
483-
if (!isIncrementalCompilation(options)) return undefined;
483+
if (!canEmitTsBuildInfo(options)) return undefined;
484484
if (options.tsBuildInfoFile) return options.tsBuildInfoFile;
485485
const outPath = options.outFile;
486486
let buildInfoExtensionLess: string;
@@ -499,6 +499,11 @@ export function getTsBuildInfoEmitOutputFilePath(options: CompilerOptions) {
499499
return buildInfoExtensionLess + Extension.TsBuildInfo;
500500
}
501501

502+
/** @internal */
503+
export function canEmitTsBuildInfo(options: CompilerOptions) {
504+
return isIncrementalCompilation(options) || !!options.tscBuild;
505+
}
506+
502507
/** @internal */
503508
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames {
504509
const outPath = options.outFile!;

src/compiler/program.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AsExpression,
99
BuilderProgram,
1010
CancellationToken,
11+
canEmitTsBuildInfo,
1112
canHaveDecorators,
1213
canHaveIllegalDecorators,
1314
chainDiagnosticMessages,
@@ -195,7 +196,6 @@ import {
195196
isImportEqualsDeclaration,
196197
isImportSpecifier,
197198
isImportTypeNode,
198-
isIncrementalCompilation,
199199
isInJSFile,
200200
isJSDocImportTag,
201201
isLiteralImportTypeNode,
@@ -4324,8 +4324,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
43244324

43254325
const outputFile = options.outFile;
43264326
if (options.tsBuildInfoFile) {
4327-
if (!isIncrementalCompilation(options)) {
4328-
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "tsBuildInfoFile", "incremental", "composite");
4327+
if (!canEmitTsBuildInfo(options)) {
4328+
createDiagnosticForOptionName(Diagnostics.Option_tsBuildInfoFile_cannot_be_specified_without_specifying_option_incremental_or_composite_or_if_not_running_tsc_b, "tsBuildInfoFile");
43294329
}
43304330
}
43314331
else if (options.incremental && !outputFile && !options.configFilePath) {

src/compiler/tsbuildPublic.ts

Lines changed: 78 additions & 84 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7411,6 +7411,7 @@ export interface CompilerOptions {
74117411
esModuleInterop?: boolean;
74127412
/** @internal */ showConfig?: boolean;
74137413
useDefineForClassFields?: boolean;
7414+
/** @internal */ tscBuild?: boolean;
74147415

74157416
[option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined;
74167417
}

src/testRunner/unittests/helpers/baseline.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,11 @@ export type ReadableProgramBuildInfo = ReadableProgramMultiFileEmitBuildInfo | R
206206
export function isReadableProgramBundleEmitBuildInfo(info: ReadableProgramBuildInfo | undefined): info is ReadableProgramBundleEmitBuildInfo {
207207
return !!info && !!info.options?.outFile;
208208
}
209+
210+
export function isReadableProgramMultiFileEmitBuildInfo(info: ReadableProgramBuildInfo | undefined): info is ReadableProgramMultiFileEmitBuildInfo {
211+
return !!info && !info.options?.outFile;
212+
}
213+
209214
export type ReadableBuildInfo = Omit<ts.BuildInfo, "program"> & { program: ReadableProgramBuildInfo | undefined; size: number; };
210215
function generateBuildInfoProgramBaseline(sys: ts.System, buildInfoPath: string, buildInfo: ts.BuildInfo) {
211216
let program: ReadableProgramBuildInfo | undefined;

src/testRunner/unittests/helpers/tsc.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
CommandLineProgram,
1111
generateSourceMapBaselineFiles,
1212
isReadableProgramBundleEmitBuildInfo,
13+
isReadableProgramMultiFileEmitBuildInfo,
1314
ReadableBuildInfo,
1415
ReadableProgramBuildInfoFileInfo,
1516
ReadableProgramBundleEmitBuildInfo,
@@ -307,6 +308,7 @@ function verifyTscEditDiscrepancies({
307308
`FileInfos:: File:: ${outputFile}`,
308309
);
309310
if (!isReadableProgramBundleEmitBuildInfo(incrementalReadableBuildInfo?.program)) {
311+
// Should not be with --outFile
310312
ts.Debug.assert(!isReadableProgramBundleEmitBuildInfo(cleanReadableBuildInfo?.program));
311313
// Verify that incrementally pending affected file emit are in clean build since clean build can contain more files compared to incremental depending of noEmitOnError option
312314
if (incrementalReadableBuildInfo?.program?.affectedFilesPendingEmit) {
@@ -337,7 +339,8 @@ function verifyTscEditDiscrepancies({
337339
}
338340
}
339341
else {
340-
ts.Debug.assert(isReadableProgramBundleEmitBuildInfo(cleanReadableBuildInfo?.program));
342+
// Should not be without --outFile
343+
ts.Debug.assert(!isReadableProgramMultiFileEmitBuildInfo(cleanReadableBuildInfo?.program));
341344
// Verify that incrementally pending affected file emit are in clean build since clean build can contain more files compared to incremental depending of noEmitOnError option
342345
if (incrementalReadableBuildInfo?.program?.pendingEmit) {
343346
if (cleanReadableBuildInfo?.program?.pendingEmit === undefined) {

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ describe("unittests:: tsbuild:: outFile::", () => {
249249
caption: "Make non incremental build with change in file that doesnt affect dts",
250250
edit: fs => appendText(fs, "/src/first/first_PART1.ts", "console.log(s);"),
251251
commandLineArgs: ["--b", "/src/third", "--verbose"],
252+
discrepancyExplanation: () => [
253+
"Clean build is non incremental so it will have non incremental tsbuildInfo for third project",
254+
"The incremental build does not build third so will only update timestamps for third tsbuildInfo and hence its from incremental build before",
255+
],
252256
},
253257
{
254258
caption: "Make incremental build with change in file that doesnt affect dts",

src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { noop } from "../../_namespaces/ts.js";
12
import { dedent } from "../../_namespaces/Utils.js";
23
import * as vfs from "../../_namespaces/vfs.js";
34
import { jsonToReadableText } from "../helpers.js";
@@ -90,6 +91,57 @@ describe("unittests:: tsbuild:: with rootDir of project reference in parentDirec
9091
edits: noChangeOnlyRuns,
9192
});
9293

94+
verifyTsc({
95+
scenario: "projectReferenceWithRootDirInParent",
96+
subScenario: "reports error for same tsbuildinfo file without incremental",
97+
fs: () => projFs,
98+
commandLineArgs: ["--b", "/src/src/main", "--verbose"],
99+
modifyFs: fs => {
100+
fs.writeFileSync(
101+
"/src/src/main/tsconfig.json",
102+
jsonToReadableText({
103+
compilerOptions: { outDir: "../../dist/" },
104+
references: [{ path: "../other" }],
105+
}),
106+
);
107+
fs.writeFileSync(
108+
"/src/src/other/tsconfig.json",
109+
jsonToReadableText({
110+
compilerOptions: { composite: true, outDir: "../../dist/" },
111+
}),
112+
);
113+
},
114+
});
115+
116+
verifyTsc({
117+
scenario: "projectReferenceWithRootDirInParent",
118+
subScenario: "reports error for same tsbuildinfo file without incremental with tsc",
119+
fs: () => projFs,
120+
commandLineArgs: ["--b", "/src/src/other", "--verbose"],
121+
modifyFs: fs => {
122+
fs.writeFileSync(
123+
"/src/src/main/tsconfig.json",
124+
jsonToReadableText({
125+
compilerOptions: { outDir: "../../dist/" },
126+
references: [{ path: "../other" }],
127+
}),
128+
);
129+
fs.writeFileSync(
130+
"/src/src/other/tsconfig.json",
131+
jsonToReadableText({
132+
compilerOptions: { composite: true, outDir: "../../dist/" },
133+
}),
134+
);
135+
},
136+
edits: [
137+
{
138+
caption: "Running tsc on main",
139+
edit: noop,
140+
commandLineArgs: ["-p", "/src/src/main"],
141+
},
142+
],
143+
});
144+
93145
verifyTsc({
94146
scenario: "projectReferenceWithRootDirInParent",
95147
subScenario: "reports no error when tsbuildinfo differ",

0 commit comments

Comments
 (0)