Skip to content

Commit d53efdf

Browse files
committed
Changes to generation of .tsbuildinfo:
- If composite or incremental then only the .tsbuildinfo will be generated - if --out or --outFile the file is outputFile.tsbuildinfo - if rootDir and outDir then outdir/relativePathOfConfigFromRootDir/configname.tsbuildinfo - if just outDir then outDir/configname.tsbuild - otherwise config.tsbuildinfo next to configFile
1 parent ed35741 commit d53efdf

File tree

89 files changed

+21665
-21844
lines changed

Some content is hidden

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

89 files changed

+21665
-21844
lines changed

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@ namespace ts {
331331
category: Diagnostics.Basic_Options,
332332
description: Diagnostics.Enable_project_compilation,
333333
},
334+
{
335+
name: "incremental",
336+
type: "boolean",
337+
isTSConfigOnly: true,
338+
category: Diagnostics.Basic_Options,
339+
description: Diagnostics.Enable_incremental_compilation,
340+
},
334341
{
335342
name: "removeComments",
336343
type: "boolean",

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4020,10 +4020,14 @@
40204020
"category": "Message",
40214021
"code": 6376
40224022
},
4023-
"Cannot write file '{0}' because it will overwrite '.tsbuildinfo' of referenced project '{1}'": {
4023+
"Cannot write file '{0}' because it will overwrite '.tsbuildinfo' file generated by referenced project '{1}'": {
40244024
"category": "Error",
40254025
"code": 6377
40264026
},
4027+
"Enable incremental compilation": {
4028+
"category": "Message",
4029+
"code": 6378
4030+
},
40274031

40284032
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
40294033
"category": "Message",

src/compiler/emitter.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
namespace ts {
2-
/*@internal*/
3-
export const infoFile = ".tsbuildinfo";
42
const brackets = createBracketsMap();
53
const syntheticParent: TextRange = { pos: -1, end: -1 };
64

75
/*@internal*/
86
export function isBuildInfoFile(file: string) {
9-
return endsWith(file, `/${infoFile}`);
7+
return fileExtensionIs(file, Extension.TsBuildInfo);
108
}
119

1210
/*@internal*/
@@ -47,37 +45,49 @@ namespace ts {
4745
}
4846
}
4947
if (includeBuildInfo) {
50-
const buildInfoPath = getOutputPathForBuildInfo(host.getCompilerOptions(), host.getProjectReferences());
48+
const buildInfoPath = getOutputPathForBuildInfo(host.getCompilerOptions());
5149
if (buildInfoPath) return action({ buildInfoPath }, /*sourceFileOrBundle*/ undefined);
5250
}
5351
}
5452
}
5553

5654
/*@internal*/
57-
export function getOutputPathForBuildInfo(options: CompilerOptions, projectReferences: ReadonlyArray<ProjectReference> | undefined) {
58-
if (!options.composite && !length(projectReferences)) return undefined;
55+
export function getOutputPathForBuildInfo(options: CompilerOptions) {
56+
const configFile = options.configFilePath;
57+
if (!configFile || !options.incremental && !options.composite) return undefined;
58+
// TODO:: Add outFile like tsBuildInfoFile option
5959
const outPath = options.outFile || options.out;
60-
if (outPath) return combinePaths(getDirectoryPath(outPath), infoFile);
61-
if (options.outDir) return combinePaths(options.outDir, infoFile);
62-
return options.configFilePath && combinePaths(getDirectoryPath(options.configFilePath), infoFile);
60+
let buildInfoExtensionLess: string;
61+
if (outPath) {
62+
buildInfoExtensionLess = removeFileExtension(outPath);
63+
}
64+
else {
65+
const configFileExtensionLess = removeFileExtension(configFile);
66+
buildInfoExtensionLess = options.outDir ?
67+
options.rootDir ?
68+
resolvePath(options.outDir, getRelativePathFromDirectory(options.rootDir, configFileExtensionLess, /*ignoreCase*/ true)) :
69+
combinePaths(options.outDir, getBaseFileName(configFileExtensionLess)) :
70+
configFileExtensionLess;
71+
}
72+
return buildInfoExtensionLess + Extension.TsBuildInfo;
6373
}
6474

6575
/*@internal*/
66-
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean, projectReferences: ReadonlyArray<ProjectReference> | undefined): EmitFileNames {
76+
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames {
6777
const outPath = options.outFile || options.out!;
6878
const jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
6979
const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
7080
const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(outPath) + Extension.Dts : undefined;
7181
const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
72-
const buildInfoPath = getOutputPathForBuildInfo(options, projectReferences);
82+
const buildInfoPath = getOutputPathForBuildInfo(options);
7383
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath };
7484
}
7585

7686
/*@internal*/
7787
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean): EmitFileNames {
7888
const options = host.getCompilerOptions();
7989
if (sourceFile.kind === SyntaxKind.Bundle) {
80-
return getOutputPathsForBundle(options, forceDtsPaths, host.getProjectReferences());
90+
return getOutputPathsForBundle(options, forceDtsPaths);
8191
}
8292
else {
8393
const ownOutputFilePath = getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -535,7 +545,7 @@ namespace ts {
535545

536546
/*@internal*/
537547
export function emitUsingBuildInfo(config: ParsedCommandLine, host: EmitUsingBuildInfoHost, getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined): EmitUsingBuildInfoResult {
538-
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false, config.projectReferences);
548+
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false);
539549
const buildInfoText = host.readFile(Debug.assertDefined(buildInfoPath));
540550
if (!buildInfoText) return buildInfoPath!;
541551
const jsFileText = host.readFile(Debug.assertDefined(jsFilePath));
@@ -570,7 +580,6 @@ namespace ts {
570580
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle);
571581
const emitHost: EmitHost = {
572582
getPrependNodes: memoize(() => [...prependNodes, ownPrependInput]),
573-
getProjectReferences: () => config.projectReferences,
574583
getCanonicalFileName: host.getCanonicalFileName,
575584
getCommonSourceDirectory: () => buildInfo.bundle!.commonSourceDirectory,
576585
getCompilerOptions: () => config.options,

src/compiler/moduleSpecifiers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ namespace ts.moduleSpecifiers {
437437
case Extension.Jsx:
438438
case Extension.Json:
439439
return ext;
440+
case Extension.TsBuildInfo:
441+
return Debug.fail(`Extension ${Extension.TsBuildInfo} is unsupported:: FileName:: ${fileName}`);
440442
default:
441443
return Debug.assertNever(ext);
442444
}

src/compiler/program.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,6 @@ namespace ts {
14101410
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
14111411
return {
14121412
getPrependNodes,
1413-
getProjectReferences,
14141413
getCanonicalFileName,
14151414
getCommonSourceDirectory: program.getCommonSourceDirectory,
14161415
getCompilerOptions: program.getCompilerOptions,
@@ -2942,7 +2941,7 @@ namespace ts {
29422941
}
29432942

29442943
function verifyProjectReferences() {
2945-
const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getOutputPathForBuildInfo(options, projectReferences) : undefined;
2944+
const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getOutputPathForBuildInfo(options) : undefined;
29462945
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, index, parent) => {
29472946
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index];
29482947
const parentFile = parent && parent.sourceFile as JsonSourceFile;
@@ -2969,9 +2968,8 @@ namespace ts {
29692968
createDiagnosticForReference(parentFile, index, Diagnostics.Cannot_prepend_project_0_because_it_does_not_have_outFile_set, ref.path);
29702969
}
29712970
}
2972-
const refBuildInfoPath = getOutputPathForBuildInfo(options, resolvedRef.commandLine.projectReferences);
2973-
if (refBuildInfoPath && refBuildInfoPath === buildInfoPath) {
2974-
createDiagnosticForReference(parentFile, index, Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_of_referenced_project_1, buildInfoPath, ref.path);
2971+
if (!parent && buildInfoPath && buildInfoPath === getOutputPathForBuildInfo(options)) {
2972+
createDiagnosticForReference(parentFile, index, Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, buildInfoPath, ref.path);
29752973
hasEmitBlockingDiagnostics.set(toPath(buildInfoPath), true);
29762974
}
29772975
});
@@ -3168,7 +3166,7 @@ namespace ts {
31683166
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
31693167
if (!out) continue;
31703168

3171-
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true, resolvedRefOpts.projectReferences);
3169+
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true);
31723170
const node = createInputFiles(readFile, jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath, buildInfoPath);
31733171
(nodes || (nodes = [])).push(node);
31743172
}

src/compiler/tsbuild.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace ts {
307307

308308
function getOutFileOutputs(project: ParsedCommandLine, ignoreBuildInfo?: boolean): ReadonlyArray<string> {
309309
Debug.assert(!!project.options.outFile || !!project.options.out, "outFile must be set");
310-
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(project.options, /*forceDtsPaths*/ false, project.projectReferences);
310+
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(project.options, /*forceDtsPaths*/ false);
311311

312312
let outputs: string[] | undefined = [];
313313
const addOutput = (path: string | undefined) => path && (outputs || (outputs = [])).push(path);
@@ -1217,7 +1217,7 @@ namespace ts {
12171217
function getOldProgram(proj: ResolvedConfigFileName, parsed: ParsedCommandLine) {
12181218
const value = builderPrograms.getValue(proj);
12191219
if (value) return value;
1220-
const buildInfoPath = getOutputPathForBuildInfo(parsed.options, parsed.projectReferences);
1220+
const buildInfoPath = getOutputPathForBuildInfo(parsed.options);
12211221
if (!buildInfoPath) return undefined;
12221222
const content = readFileWithCache(buildInfoPath);
12231223
if (!content) return undefined;
@@ -1488,7 +1488,7 @@ namespace ts {
14881488
outputs.push(...getOutputFileNames(inputFile, project));
14891489
}
14901490
if (!ignoreBuildInfo) {
1491-
const buildInfoPath = getOutputPathForBuildInfo(project.options, project.projectReferences);
1491+
const buildInfoPath = getOutputPathForBuildInfo(project.options);
14921492
if (buildInfoPath) outputs.push(buildInfoPath);
14931493
}
14941494
return outputs;

src/compiler/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4646,6 +4646,7 @@ namespace ts {
46464646
reactNamespace?: string;
46474647
jsxFactory?: string;
46484648
composite?: boolean;
4649+
incremental?: boolean;
46494650
removeComments?: boolean;
46504651
rootDir?: string;
46514652
rootDirs?: string[];
@@ -5056,7 +5057,8 @@ namespace ts {
50565057
Dts = ".d.ts",
50575058
Js = ".js",
50585059
Jsx = ".jsx",
5059-
Json = ".json"
5060+
Json = ".json",
5061+
TsBuildInfo = ".tsbuildinfo"
50605062
}
50615063

50625064
export interface ResolvedModuleWithFailedLookupLocations {
@@ -5345,7 +5347,6 @@ namespace ts {
53455347
isEmitBlocked(emitFileName: string): boolean;
53465348

53475349
getPrependNodes(): ReadonlyArray<InputFiles | UnparsedSource>;
5348-
getProjectReferences(): ReadonlyArray<ProjectReference> | undefined;
53495350

53505351
writeFile: WriteFileCallback;
53515352
getProgramBuildInfo(): ProgramBuildInfo | undefined;

src/services/stringCompletions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ namespace ts.Completions.StringCompletions {
7171
case Extension.Jsx: return ScriptElementKindModifier.jsxModifier;
7272
case Extension.Ts: return ScriptElementKindModifier.tsModifier;
7373
case Extension.Tsx: return ScriptElementKindModifier.tsxModifier;
74+
case Extension.TsBuildInfo: return Debug.fail(`Extension ${Extension.TsBuildInfo} is unsupported.`);
7475
case undefined: return ScriptElementKindModifier.none;
7576
default:
7677
return Debug.assertNever(extension);

0 commit comments

Comments
 (0)