Skip to content

Commit

Permalink
Changes to generation of .tsbuildinfo:
Browse files Browse the repository at this point in the history
- 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
sheetalkamat committed Feb 28, 2019
1 parent ed35741 commit d53efdf
Showing 89 changed files with 21,665 additions and 21,844 deletions.
7 changes: 7 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
@@ -331,6 +331,13 @@ namespace ts {
category: Diagnostics.Basic_Options,
description: Diagnostics.Enable_project_compilation,
},
{
name: "incremental",
type: "boolean",
isTSConfigOnly: true,
category: Diagnostics.Basic_Options,
description: Diagnostics.Enable_incremental_compilation,
},
{
name: "removeComments",
type: "boolean",
6 changes: 5 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
@@ -4020,10 +4020,14 @@
"category": "Message",
"code": 6376
},
"Cannot write file '{0}' because it will overwrite '.tsbuildinfo' of referenced project '{1}'": {
"Cannot write file '{0}' because it will overwrite '.tsbuildinfo' file generated by referenced project '{1}'": {
"category": "Error",
"code": 6377
},
"Enable incremental compilation": {
"category": "Message",
"code": 6378
},

"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
37 changes: 23 additions & 14 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
namespace ts {
/*@internal*/
export const infoFile = ".tsbuildinfo";
const brackets = createBracketsMap();
const syntheticParent: TextRange = { pos: -1, end: -1 };

/*@internal*/
export function isBuildInfoFile(file: string) {
return endsWith(file, `/${infoFile}`);
return fileExtensionIs(file, Extension.TsBuildInfo);
}

/*@internal*/
@@ -47,37 +45,49 @@ namespace ts {
}
}
if (includeBuildInfo) {
const buildInfoPath = getOutputPathForBuildInfo(host.getCompilerOptions(), host.getProjectReferences());
const buildInfoPath = getOutputPathForBuildInfo(host.getCompilerOptions());
if (buildInfoPath) return action({ buildInfoPath }, /*sourceFileOrBundle*/ undefined);
}
}
}

/*@internal*/
export function getOutputPathForBuildInfo(options: CompilerOptions, projectReferences: ReadonlyArray<ProjectReference> | undefined) {
if (!options.composite && !length(projectReferences)) return undefined;
export function getOutputPathForBuildInfo(options: CompilerOptions) {
const configFile = options.configFilePath;
if (!configFile || !options.incremental && !options.composite) return undefined;
// TODO:: Add outFile like tsBuildInfoFile option
const outPath = options.outFile || options.out;
if (outPath) return combinePaths(getDirectoryPath(outPath), infoFile);
if (options.outDir) return combinePaths(options.outDir, infoFile);
return options.configFilePath && combinePaths(getDirectoryPath(options.configFilePath), infoFile);
let buildInfoExtensionLess: string;
if (outPath) {
buildInfoExtensionLess = removeFileExtension(outPath);
}
else {
const configFileExtensionLess = removeFileExtension(configFile);
buildInfoExtensionLess = options.outDir ?
options.rootDir ?
resolvePath(options.outDir, getRelativePathFromDirectory(options.rootDir, configFileExtensionLess, /*ignoreCase*/ true)) :
combinePaths(options.outDir, getBaseFileName(configFileExtensionLess)) :
configFileExtensionLess;
}
return buildInfoExtensionLess + Extension.TsBuildInfo;
}

/*@internal*/
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean, projectReferences: ReadonlyArray<ProjectReference> | undefined): EmitFileNames {
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames {
const outPath = options.outFile || options.out!;
const jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(outPath) + Extension.Dts : undefined;
const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
const buildInfoPath = getOutputPathForBuildInfo(options, projectReferences);
const buildInfoPath = getOutputPathForBuildInfo(options);
return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath };
}

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

/*@internal*/
export function emitUsingBuildInfo(config: ParsedCommandLine, host: EmitUsingBuildInfoHost, getCommandLine: (ref: ProjectReference) => ParsedCommandLine | undefined): EmitUsingBuildInfoResult {
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false, config.projectReferences);
const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle(config.options, /*forceDtsPaths*/ false);
const buildInfoText = host.readFile(Debug.assertDefined(buildInfoPath));
if (!buildInfoText) return buildInfoPath!;
const jsFileText = host.readFile(Debug.assertDefined(jsFilePath));
@@ -570,7 +580,6 @@ namespace ts {
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle);
const emitHost: EmitHost = {
getPrependNodes: memoize(() => [...prependNodes, ownPrependInput]),
getProjectReferences: () => config.projectReferences,
getCanonicalFileName: host.getCanonicalFileName,
getCommonSourceDirectory: () => buildInfo.bundle!.commonSourceDirectory,
getCompilerOptions: () => config.options,
2 changes: 2 additions & 0 deletions src/compiler/moduleSpecifiers.ts
Original file line number Diff line number Diff line change
@@ -437,6 +437,8 @@ namespace ts.moduleSpecifiers {
case Extension.Jsx:
case Extension.Json:
return ext;
case Extension.TsBuildInfo:
return Debug.fail(`Extension ${Extension.TsBuildInfo} is unsupported:: FileName:: ${fileName}`);
default:
return Debug.assertNever(ext);
}
10 changes: 4 additions & 6 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
@@ -1410,7 +1410,6 @@ namespace ts {
function getEmitHost(writeFileCallback?: WriteFileCallback): EmitHost {
return {
getPrependNodes,
getProjectReferences,
getCanonicalFileName,
getCommonSourceDirectory: program.getCommonSourceDirectory,
getCompilerOptions: program.getCompilerOptions,
@@ -2942,7 +2941,7 @@ namespace ts {
}

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

const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true, resolvedRefOpts.projectReferences);
const { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } = getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true);
const node = createInputFiles(readFile, jsFilePath!, sourceMapFilePath, declarationFilePath!, declarationMapPath, buildInfoPath);
(nodes || (nodes = [])).push(node);
}
6 changes: 3 additions & 3 deletions src/compiler/tsbuild.ts
Original file line number Diff line number Diff line change
@@ -307,7 +307,7 @@ namespace ts {

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

let outputs: string[] | undefined = [];
const addOutput = (path: string | undefined) => path && (outputs || (outputs = [])).push(path);
@@ -1217,7 +1217,7 @@ namespace ts {
function getOldProgram(proj: ResolvedConfigFileName, parsed: ParsedCommandLine) {
const value = builderPrograms.getValue(proj);
if (value) return value;
const buildInfoPath = getOutputPathForBuildInfo(parsed.options, parsed.projectReferences);
const buildInfoPath = getOutputPathForBuildInfo(parsed.options);
if (!buildInfoPath) return undefined;
const content = readFileWithCache(buildInfoPath);
if (!content) return undefined;
@@ -1488,7 +1488,7 @@ namespace ts {
outputs.push(...getOutputFileNames(inputFile, project));
}
if (!ignoreBuildInfo) {
const buildInfoPath = getOutputPathForBuildInfo(project.options, project.projectReferences);
const buildInfoPath = getOutputPathForBuildInfo(project.options);
if (buildInfoPath) outputs.push(buildInfoPath);
}
return outputs;
5 changes: 3 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
@@ -4646,6 +4646,7 @@ namespace ts {
reactNamespace?: string;
jsxFactory?: string;
composite?: boolean;
incremental?: boolean;
removeComments?: boolean;
rootDir?: string;
rootDirs?: string[];
@@ -5056,7 +5057,8 @@ namespace ts {
Dts = ".d.ts",
Js = ".js",
Jsx = ".jsx",
Json = ".json"
Json = ".json",
TsBuildInfo = ".tsbuildinfo"
}

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

getPrependNodes(): ReadonlyArray<InputFiles | UnparsedSource>;
getProjectReferences(): ReadonlyArray<ProjectReference> | undefined;

writeFile: WriteFileCallback;
getProgramBuildInfo(): ProgramBuildInfo | undefined;
1 change: 1 addition & 0 deletions src/services/stringCompletions.ts
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ namespace ts.Completions.StringCompletions {
case Extension.Jsx: return ScriptElementKindModifier.jsxModifier;
case Extension.Ts: return ScriptElementKindModifier.tsModifier;
case Extension.Tsx: return ScriptElementKindModifier.tsxModifier;
case Extension.TsBuildInfo: return Debug.fail(`Extension ${Extension.TsBuildInfo} is unsupported.`);
case undefined: return ScriptElementKindModifier.none;
default:
return Debug.assertNever(extension);
Loading

0 comments on commit d53efdf

Please sign in to comment.