mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Make tsbuildInfoFile as commandline option to tsc (and not tsc -b)
This commit is contained in:
@@ -792,7 +792,7 @@ namespace ts {
|
||||
state,
|
||||
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
|
||||
// Otherwise just affected file
|
||||
affected.emitBuildInfo(writeFile || host.writeFile, cancellationToken),
|
||||
affected.emitBuildInfo(writeFile || maybeBind(host, host.writeFile), cancellationToken),
|
||||
affected,
|
||||
/*isPendingEmitFile*/ false,
|
||||
/*isBuildInfoEmit*/ true
|
||||
@@ -820,7 +820,7 @@ namespace ts {
|
||||
state,
|
||||
// When whole program is affected, do emit only once (eg when --out or --outFile is specified)
|
||||
// Otherwise just affected file
|
||||
Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers),
|
||||
Debug.assertDefined(state.program).emit(affected === state.program ? undefined : affected as SourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers),
|
||||
affected,
|
||||
isPendingEmitFile
|
||||
);
|
||||
@@ -862,7 +862,7 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
}
|
||||
return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || host.writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
|
||||
return Debug.assertDefined(state.program).emit(targetSourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -343,7 +343,6 @@ namespace ts {
|
||||
type: "string",
|
||||
isFilePath: true,
|
||||
paramType: Diagnostics.FILE,
|
||||
isTSConfigOnly: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Specify_file_to_store_incremental_compilation_information,
|
||||
},
|
||||
|
||||
@@ -3072,7 +3072,7 @@
|
||||
"category": "Error",
|
||||
"code": 5073
|
||||
},
|
||||
"Option '--incremental' can only be specified when using tsconfig.": {
|
||||
"Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.": {
|
||||
"category": "Error",
|
||||
"code": 5074
|
||||
},
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace ts {
|
||||
/*@internal*/
|
||||
export function getOutputPathForBuildInfo(options: CompilerOptions) {
|
||||
const configFile = options.configFilePath;
|
||||
if (!configFile || !isIncrementalCompilation(options)) return undefined;
|
||||
if (!isIncrementalCompilation(options)) return undefined;
|
||||
if (options.tsBuildInfoFile) return options.tsBuildInfoFile;
|
||||
const outPath = options.outFile || options.out;
|
||||
let buildInfoExtensionLess: string;
|
||||
@@ -62,6 +62,7 @@ namespace ts {
|
||||
buildInfoExtensionLess = removeFileExtension(outPath);
|
||||
}
|
||||
else {
|
||||
if (!configFile) return undefined;
|
||||
const configFileExtensionLess = removeFileExtension(configFile);
|
||||
buildInfoExtensionLess = options.outDir ?
|
||||
options.rootDir ?
|
||||
|
||||
+10
-6
@@ -198,7 +198,8 @@ namespace ts {
|
||||
getDirectories: (path: string) => system.getDirectories(path),
|
||||
realpath,
|
||||
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth),
|
||||
createDirectory: d => system.createDirectory(d)
|
||||
createDirectory: d => system.createDirectory(d),
|
||||
createHash: maybeBind(system, system.createHash)
|
||||
};
|
||||
return compilerHost;
|
||||
}
|
||||
@@ -320,7 +321,10 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic> {
|
||||
// tslint:disable unified-signatures
|
||||
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
|
||||
/*@internal*/ export function getPreEmitDiagnostics(program: BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic>;
|
||||
export function getPreEmitDiagnostics(program: Program | BuilderProgram, sourceFile?: SourceFile, cancellationToken?: CancellationToken): ReadonlyArray<Diagnostic> {
|
||||
const diagnostics = [
|
||||
...program.getConfigFileParsingDiagnostics(),
|
||||
...program.getOptionsDiagnostics(cancellationToken),
|
||||
@@ -335,6 +339,7 @@ namespace ts {
|
||||
|
||||
return sortAndDeduplicateDiagnostics(diagnostics);
|
||||
}
|
||||
// tslint:enable unified-signatures
|
||||
|
||||
export interface FormatDiagnosticsHost {
|
||||
getCurrentDirectory(): string;
|
||||
@@ -2722,10 +2727,6 @@ namespace ts {
|
||||
createDiagnosticForOptionName(Diagnostics.Option_paths_cannot_be_used_without_specifying_baseUrl_option, "paths");
|
||||
}
|
||||
|
||||
if (options.incremental && !options.configFilePath) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_when_using_tsconfig));
|
||||
}
|
||||
|
||||
if (options.composite) {
|
||||
if (options.declaration === false) {
|
||||
createDiagnosticForOptionName(Diagnostics.Composite_projects_may_not_disable_declaration_emit, "declaration");
|
||||
@@ -2740,6 +2741,9 @@ namespace ts {
|
||||
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "tsBuildInfoFile", "incremental", "composite");
|
||||
}
|
||||
}
|
||||
else if (options.incremental && !options.outFile && !options.out && !options.configFilePath) {
|
||||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
|
||||
}
|
||||
|
||||
verifyProjectReferences();
|
||||
|
||||
|
||||
@@ -375,6 +375,16 @@ namespace ts {
|
||||
options: { incremental: true }
|
||||
});
|
||||
});
|
||||
|
||||
it("parse --tsBuildInfoFile", () => {
|
||||
// --lib es6 0.ts
|
||||
assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "0.ts"],
|
||||
{
|
||||
errors: [],
|
||||
fileNames: ["0.ts"],
|
||||
options: { tsBuildInfoFile: "build.tsbuildinfo" }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("unittests:: config:: commandLineParsing:: parseBuildOptions", () => {
|
||||
@@ -466,7 +476,7 @@ namespace ts {
|
||||
});
|
||||
});
|
||||
|
||||
it("parse build with --incremental ", () => {
|
||||
it("parse build with --incremental", () => {
|
||||
// --lib es6 0.ts
|
||||
assertParseResult(["--incremental", "tests"],
|
||||
{
|
||||
@@ -476,6 +486,23 @@ namespace ts {
|
||||
});
|
||||
});
|
||||
|
||||
it("parse build with --tsBuildInfoFile", () => {
|
||||
// --lib es6 0.ts
|
||||
assertParseResult(["--tsBuildInfoFile", "build.tsbuildinfo", "tests"],
|
||||
{
|
||||
errors: [{
|
||||
messageText: "Unknown build option '--tsBuildInfoFile'.",
|
||||
category: Diagnostics.Unknown_build_option_0.category,
|
||||
code: Diagnostics.Unknown_build_option_0.code,
|
||||
file: undefined,
|
||||
start: undefined,
|
||||
length: undefined
|
||||
}],
|
||||
projects: ["build.tsbuildinfo", "tests"],
|
||||
buildOptions: { }
|
||||
});
|
||||
});
|
||||
|
||||
describe("Combining options that make no sense together", () => {
|
||||
function verifyInvalidCombination(flag1: keyof BuildOptions, flag2: keyof BuildOptions) {
|
||||
it(`--${flag1} and --${flag2} together is invalid`, () => {
|
||||
|
||||
+10
-19
@@ -165,6 +165,9 @@ namespace ts {
|
||||
reportWatchModeWithoutSysSupport();
|
||||
createWatchOfFilesAndCompilerOptions(commandLine.fileNames, commandLineOptions);
|
||||
}
|
||||
else if (isIncrementalCompilation(commandLineOptions)) {
|
||||
performIncrementalCompilation(commandLine);
|
||||
}
|
||||
else {
|
||||
performCompilation(commandLine.fileNames, /*references*/ undefined, commandLineOptions);
|
||||
}
|
||||
@@ -265,34 +268,22 @@ namespace ts {
|
||||
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
|
||||
changeCompilerHostLikeToUseCache(host, fileName => toPath(fileName, currentDirectory, getCanonicalFileName));
|
||||
enableStatistics(options);
|
||||
const oldProgram = readBuilderProgram(options, path => host.readFile(path));
|
||||
const configFileParsingDiagnostics = getConfigFileParsingDiagnostics(config);
|
||||
const programOptions: CreateProgramOptions = {
|
||||
rootNames: fileNames,
|
||||
options,
|
||||
projectReferences,
|
||||
host,
|
||||
configFileParsingDiagnostics: getConfigFileParsingDiagnostics(config),
|
||||
};
|
||||
const program = createProgram(programOptions);
|
||||
const builderProgram = createEmitAndSemanticDiagnosticsBuilderProgram(
|
||||
program,
|
||||
{
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
createHash: maybeBind(sys, sys.createHash),
|
||||
writeFile: (path, data, writeByteOrderMark) => sys.writeFile(path, data, writeByteOrderMark)
|
||||
},
|
||||
oldProgram,
|
||||
configFileParsingDiagnostics
|
||||
fileNames,
|
||||
options,
|
||||
host,
|
||||
readBuilderProgram(options, path => host.readFile(path)),
|
||||
configFileParsingDiagnostics,
|
||||
projectReferences
|
||||
);
|
||||
|
||||
const exitStatus = emitFilesAndReportErrors(
|
||||
builderProgram,
|
||||
reportDiagnostic,
|
||||
s => sys.write(s + sys.newLine),
|
||||
createReportErrorSummary(options)
|
||||
);
|
||||
reportStatistics(program);
|
||||
reportStatistics(builderProgram.getProgram());
|
||||
return sys.exit(exitStatus);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
//// [a.ts]
|
||||
const x = 10;
|
||||
|
||||
|
||||
//// [a.js]
|
||||
var x = 10;
|
||||
@@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
const x = 10;
|
||||
>x : Symbol(x, Decl(a.ts, 0, 5))
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
=== /a.ts ===
|
||||
const x = 10;
|
||||
>x : 10
|
||||
>10 : 10
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.
|
||||
|
||||
|
||||
!!! error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single file or when option `--tsBuildInfoFile` is specified.
|
||||
==== tests/cases/compiler/incrementalInvalid.ts (0 errors) ====
|
||||
const x = 10;
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [incrementalInvalid.ts]
|
||||
const x = 10;
|
||||
|
||||
|
||||
|
||||
//// [incrementalInvalid.js]
|
||||
var x = 10;
|
||||
@@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/incrementalInvalid.ts ===
|
||||
const x = 10;
|
||||
>x : Symbol(x, Decl(incrementalInvalid.ts, 0, 5))
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/incrementalInvalid.ts ===
|
||||
const x = 10;
|
||||
>x : 10
|
||||
>10 : 10
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
//// [incrementalOut.ts]
|
||||
const x = 10;
|
||||
|
||||
|
||||
|
||||
//// [output.js]
|
||||
var x = 10;
|
||||
@@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/incrementalOut.ts ===
|
||||
const x = 10;
|
||||
>x : Symbol(x, Decl(incrementalOut.ts, 0, 5))
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
=== tests/cases/compiler/incrementalOut.ts ===
|
||||
const x = 10;
|
||||
>x : 10
|
||||
>10 : 10
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
error TS5074: Option '--incremental' can only be specified when using tsconfig.
|
||||
|
||||
|
||||
!!! error TS5074: Option '--incremental' can only be specified when using tsconfig.
|
||||
==== tests/cases/compiler/invalidIncremental.ts (0 errors) ====
|
||||
const x = 10;
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//// [invalidIncremental.ts]
|
||||
const x = 10;
|
||||
|
||||
|
||||
|
||||
//// [invalidIncremental.js]
|
||||
var x = 10;
|
||||
@@ -1,5 +0,0 @@
|
||||
=== tests/cases/compiler/invalidIncremental.ts ===
|
||||
const x = 10;
|
||||
>x : Symbol(x, Decl(invalidIncremental.ts, 0, 5))
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
=== tests/cases/compiler/invalidIncremental.ts ===
|
||||
const x = 10;
|
||||
>x : 10
|
||||
>10 : 10
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// @incremental: true
|
||||
|
||||
// @Filename: /a.ts
|
||||
const x = 10;
|
||||
|
||||
// @Filename: /tsconfig.json
|
||||
{ }
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// @incremental: true
|
||||
// @out: output.js
|
||||
|
||||
const x = 10;
|
||||
|
||||
Reference in New Issue
Block a user