Skip to content

Commit 35470b3

Browse files
committed
Make tsbuildInfoFile as commandline option to tsc (and not tsc -b)
1 parent 722afc1 commit 35470b3

24 files changed

+125
-57
lines changed

src/compiler/builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ namespace ts {
792792
state,
793793
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
794794
// Otherwise just affected file
795-
affected.emitBuildInfo(writeFile || host.writeFile, cancellationToken),
795+
affected.emitBuildInfo(writeFile || maybeBind(host, host.writeFile), cancellationToken),
796796
affected,
797797
/*isPendingEmitFile*/ false,
798798
/*isBuildInfoEmit*/ true
@@ -820,7 +820,7 @@ namespace ts {
820820
state,
821821
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
822822
// Otherwise just affected file
823-
Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers),
823+
Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers),
824824
affected,
825825
isPendingEmitFile
826826
);
@@ -862,7 +862,7 @@ namespace ts {
862862
};
863863
}
864864
}
865-
return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
865+
return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
866866
}
867867

868868
/**

src/compiler/commandLineParser.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ namespace ts {
343343
type: "string",
344344
isFilePath: true,
345345
paramType: Diagnostics.FILE,
346-
isTSConfigOnly: true,
347346
category: Diagnostics.Basic_Options,
348347
description: Diagnostics.Specify_file_to_store_incremental_compilation_information,
349348
},

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3072,7 +3072,7 @@
30723072
"category": "Error",
30733073
"code": 5073
30743074
},
3075-
"Option '--incremental' can only be specified when using tsconfig.": {
3075+
"Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.": {
30763076
"category": "Error",
30773077
"code": 5074
30783078
},

src/compiler/emitter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ namespace ts {
5454
/*@internal*/
5555
export function getOutputPathForBuildInfo(options: CompilerOptions) {
5656
const configFile = options.configFilePath;
57-
if (!configFile || !isIncrementalCompilation(options)) return undefined;
57+
if (!isIncrementalCompilation(options)) return undefined;
5858
if (options.tsBuildInfoFile) return options.tsBuildInfoFile;
5959
const outPath = options.outFile || options.out;
6060
let buildInfoExtensionLess: string;
6161
if (outPath) {
6262
buildInfoExtensionLess = removeFileExtension(outPath);
6363
}
6464
else {
65+
if (!configFile) return undefined;
6566
const configFileExtensionLess = removeFileExtension(configFile);
6667
buildInfoExtensionLess = options.outDir ?
6768
options.rootDir ?

src/compiler/program.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ namespace ts {
198198
getDirectories: (path: string) => system.getDirectories(path),
199199
realpath,
200200
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth),
201-
createDirectory: d => system.createDirectory(d)
201+
createDirectory: d => system.createDirectory(d),
202+
createHash: maybeBind(system, system.createHash)
202203
};
203204
return compilerHost;
204205
}
@@ -320,7 +321,10 @@ namespace ts {
320321
};
321322
}
322323

323-
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic> {
324+
// tslint:disable unified-signatures
325+
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
326+
/*@internal*/ export function getPreEmitDiagnostics(program: BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
327+
export function getPreEmitDiagnostics(program: Program | BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic> {
324328
const diagnostics = [
325329
...program.getConfigFileParsingDiagnostics(),
326330
...program.getOptionsDiagnostics(cancellationToken),
@@ -335,6 +339,7 @@ namespace ts {
335339

336340
return sortAndDeduplicateDiagnostics(diagnostics);
337341
}
342+
// tslint:enable unified-signatures
338343

339344
export interface FormatDiagnosticsHost {
340345
getCurrentDirectory(): string;
@@ -2722,10 +2727,6 @@ namespace ts {
27222727
createDiagnosticForOptionName(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option, "paths");
27232728
}
27242729

2725-
if (options.incremental && !options.configFilePath) {
2726-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_when_using_tsconfig));
2727-
}
2728-
27292730
if (options.composite) {
27302731
if (options.declaration === false) {
27312732
createDiagnosticForOptionName(Diagnostics.Composite_projects_may_not_disable_declaration_emit, "declaration");
@@ -2740,6 +2741,9 @@ namespace ts {
27402741
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "tsBuildInfoFile", "incremental", "composite");
27412742
}
27422743
}
2744+
else if (options.incremental && !options.outFile && !options.out && !options.configFilePath) {
2745+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
2746+
}
27432747

27442748
verifyProjectReferences();
27452749

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ namespace ts {
375375
options: { incremental: true }
376376
});
377377
});
378+
379+
it("parse --tsBuildInfoFile", () => {
380+
// --lib es6 0.ts
381+
assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "0.ts"],
382+
{
383+
errors: [],
384+
fileNames: ["0.ts"],
385+
options: { tsBuildInfoFile: "build.tsbuildinfo" }
386+
});
387+
});
378388
});
379389

380390
describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => {
@@ -466,7 +476,7 @@ namespace ts {
466476
});
467477
});
468478

469-
it("parse build with --incremental ", () => {
479+
it("parse build with --incremental", () => {
470480
// --lib es6 0.ts
471481
assertParseResult(["--incremental", "tests"],
472482
{
@@ -476,6 +486,23 @@ namespace ts {
476486
});
477487
});
478488

489+
it("parse build with --tsBuildInfoFile", () => {
490+
// --lib es6 0.ts
491+
assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "tests"],
492+
{
493+
errors: [{
494+
messageText: "Unknown build option '--tsBuildInfoFile'.",
495+
category: Diagnostics.Unknown_build_option_0.category,
496+
code: Diagnostics.Unknown_build_option_0.code,
497+
file: undefined,
498+
start: undefined,
499+
length: undefined
500+
}],
501+
projects: ["build.tsbuildinfo", "tests"],
502+
buildOptions: { }
503+
});
504+
});
505+
479506
describe("Combining options that make no sense together", () => {
480507
function verifyInvalidCombination(flag1: keyof BuildOptions, flag2: keyof BuildOptions) {
481508
it(`--${flag1} and --${flag2} together is invalid`, () => {

src/tsc/tsc.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ namespace ts {
165165
reportWatchModeWithoutSysSupport();
166166
createWatchOfFilesAndCompilerOptions(commandLine.fileNames, commandLineOptions);
167167
}
168+
else if (isIncrementalCompilation(commandLineOptions)) {
169+
performIncrementalCompilation(commandLine);
170+
}
168171
else {
169172
performCompilation(commandLine.fileNames, /*references*/ undefined, commandLineOptions);
170173
}
@@ -265,34 +268,22 @@ namespace ts {
265268
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
266269
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, currentDirectory, getCanonicalFileName));
267270
enableStatistics(options);
268-
const oldProgram = readBuilderProgram(options, path => host.readFile(path));
269271
const configFileParsingDiagnostics = getConfigFileParsingDiagnostics(config);
270-
const programOptions: CreateProgramOptions = {
271-
rootNames: fileNames,
272+
const builderProgram = createEmitAndSemanticDiagnosticsBuilderProgram(
273+
fileNames,
272274
options,
273-
projectReferences,
274275
host,
275-
configFileParsingDiagnostics: getConfigFileParsingDiagnostics(config),
276-
};
277-
const program = createProgram(programOptions);
278-
const builderProgram = createEmitAndSemanticDiagnosticsBuilderProgram(
279-
program,
280-
{
281-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
282-
createHash: maybeBind(sys, sys.createHash),
283-
writeFile: (path, data, writeByteOrderMark) => sys.writeFile(path, data, writeByteOrderMark)
284-
},
285-
oldProgram,
286-
configFileParsingDiagnostics
276+
readBuilderProgram(options, path => host.readFile(path)),
277+
configFileParsingDiagnostics,
278+
projectReferences
287279
);
288-
289280
const exitStatus = emitFilesAndReportErrors(
290281
builderProgram,
291282
reportDiagnostic,
292283
s => sys.write(s + sys.newLine),
293284
createReportErrorSummary(options)
294285
);
295-
reportStatistics(program);
286+
reportStatistics(builderProgram.getProgram());
296287
return sys.exit(exitStatus);
297288
}
298289

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [a.ts]
2+
const x = 10;
3+
4+
5+
//// [a.js]
6+
var x = 10;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== /a.ts ===
2+
const x = 10;
3+
>x : Symbol(x, Decl(a.ts, 0, 5))
4+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
=== /a.ts ===
2+
const x = 10;
3+
>x : 10
4+
>10 : 10
5+

0 commit comments

Comments
 (0)