Merge pull request #34505 from amcasey/ListFilesOnly

Add listFilesOnly command-line option
This commit is contained in:
Andrew Casey 2019-10-17 18:28:34 -07:00 committed by GitHub
commit dd58bfc514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 90 additions and 5 deletions

View File

@ -216,6 +216,15 @@ namespace ts {
isCommandLineOnly: true,
description: Diagnostics.Print_the_final_configuration_instead_of_building
},
{
name: "listFilesOnly",
type: "boolean",
category: Diagnostics.Command_line_Options,
affectsSemanticDiagnostics: true,
affectsEmit: true,
isCommandLineOnly: true,
description: Diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing
},
// Basic
{

View File

@ -4311,6 +4311,10 @@
"category": "Message",
"code": 6502
},
"Print names of files that are part of the compilation and then stop processing.": {
"category": "Message",
"code": 6503
},
"Variable '{0}' implicitly has an '{1}' type.": {
"category": "Error",

View File

@ -4951,6 +4951,7 @@ namespace ts {
lib?: string[];
/*@internal*/listEmittedFiles?: boolean;
/*@internal*/listFiles?: boolean;
/*@internal*/listFilesOnly?: boolean;
locale?: string;
mapRoot?: string;
maxNodeModuleJsDepth?: number;

View File

@ -129,7 +129,7 @@ namespace ts {
}
export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void) {
if (program.getCompilerOptions().listFiles) {
if (program.getCompilerOptions().listFiles || program.getCompilerOptions().listFilesOnly) {
forEach(program.getSourceFiles(), file => {
writeFileName(file.fileName);
});
@ -149,6 +149,8 @@ namespace ts {
emitOnlyDtsFiles?: boolean,
customTransformers?: CustomTransformers
) {
const isListFilesOnly = !!program.getCompilerOptions().listFilesOnly;
// First get and report any syntactic errors.
const diagnostics = program.getConfigFileParsingDiagnostics().slice();
const configFileParsingDiagnosticsLength = diagnostics.length;
@ -158,15 +160,20 @@ namespace ts {
// semantic errors.
if (diagnostics.length === configFileParsingDiagnosticsLength) {
addRange(diagnostics, program.getOptionsDiagnostics(cancellationToken));
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
if (diagnostics.length === configFileParsingDiagnosticsLength) {
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
if (!isListFilesOnly) {
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
if (diagnostics.length === configFileParsingDiagnosticsLength) {
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
}
}
}
// Emit and report any errors we ran into.
const emitResult = program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
const emitResult = isListFilesOnly
? { emitSkipped: true, diagnostics: emptyArray }
: program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
const { emittedFiles, diagnostics: emitDiagnostics } = emitResult;
addRange(diagnostics, emitDiagnostics);

View File

@ -116,6 +116,7 @@
"unittests/tsbuild/watchMode.ts",
"unittests/tsc/declarationEmit.ts",
"unittests/tsc/incremental.ts",
"unittests/tsc/listFilesOnly.ts",
"unittests/tscWatch/consoleClearing.ts",
"unittests/tscWatch/emit.ts",
"unittests/tscWatch/emitAndErrorUpdates.ts",

View File

@ -446,6 +446,23 @@ namespace ts {
});
});
it("parse build with listFilesOnly ", () => {
// --lib es6 0.ts
assertParseResult(["--listFilesOnly"],
{
errors: [{
messageText:"Unknown build option '--listFilesOnly'.",
category: Diagnostics.Unknown_build_option_0.category,
code: Diagnostics.Unknown_build_option_0.code,
file: undefined,
start: undefined,
length: undefined,
}],
projects: ["."],
buildOptions: {}
});
});
it("Parse multiple flags with input projects at the end", () => {
// --lib es5,es2015.symbol.wellknown --target es5 0.ts
assertParseResult(["--force", "--verbose", "src", "tests"],

View File

@ -0,0 +1,23 @@
namespace ts {
describe("unittests:: tsc:: listFilesOnly::", () => {
verifyTsc({
scenario: "listFilesOnly",
subScenario: "combined with watch",
fs: () => loadProjectFromFiles({
"/src/test.ts": utils.dedent`
export const x = 1;`,
}),
commandLineArgs: ["/src/test.ts", "--watch", "--listFilesOnly"]
});
verifyTsc({
scenario: "listFilesOnly",
subScenario: "loose file",
fs: () => loadProjectFromFiles({
"/src/test.ts": utils.dedent`
export const x = 1;`,
}),
commandLineArgs: ["/src/test.ts", "--listFilesOnly"]
});
});
}

View File

@ -207,6 +207,11 @@ namespace ts {
return sys.exit(ExitStatus.Success);
}
if (commandLine.options.watch && commandLine.options.listFilesOnly) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "listFilesOnly"));
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
}
if (commandLine.options.project) {
if (commandLine.fileNames.length !== 0) {
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));

View File

@ -0,0 +1,5 @@
{
"compilerOptions": {
"listFilesOnly": true
}
}

View File

@ -0,0 +1,6 @@
//// [/lib/initial-buildOutput.txt]
/lib/tsc /src/test.ts --watch --listFilesOnly
error TS6370: Options 'watch' and 'listFilesOnly' cannot be combined.
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped

View File

@ -0,0 +1,7 @@
//// [/lib/initial-buildOutput.txt]
/lib/tsc /src/test.ts --listFilesOnly
/lib/lib.d.ts
/src/test.ts
exitCode:: ExitStatus.Success