mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Merge pull request #34505 from amcasey/ListFilesOnly
Add listFilesOnly command-line option
This commit is contained in:
commit
dd58bfc514
@ -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
|
||||
{
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -4951,6 +4951,7 @@ namespace ts {
|
||||
lib?: string[];
|
||||
/*@internal*/listEmittedFiles?: boolean;
|
||||
/*@internal*/listFiles?: boolean;
|
||||
/*@internal*/listFilesOnly?: boolean;
|
||||
locale?: string;
|
||||
mapRoot?: string;
|
||||
maxNodeModuleJsDepth?: number;
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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"],
|
||||
|
||||
23
src/testRunner/unittests/tsc/listFilesOnly.ts
Normal file
23
src/testRunner/unittests/tsc/listFilesOnly.ts
Normal 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"]
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -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));
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"listFilesOnly": true
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
//// [/lib/initial-buildOutput.txt]
|
||||
/lib/tsc /src/test.ts --listFilesOnly
|
||||
/lib/lib.d.ts
|
||||
/src/test.ts
|
||||
exitCode:: ExitStatus.Success
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user