Skip to content

Commit dd58bfc

Browse files
authored
Merge pull request #34505 from amcasey/ListFilesOnly
Add listFilesOnly command-line option
2 parents a8dc7af + 7275e9c commit dd58bfc

File tree

11 files changed

+90
-5
lines changed

11 files changed

+90
-5
lines changed

src/compiler/commandLineParser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ namespace ts {
216216
isCommandLineOnly: true,
217217
description: Diagnostics.Print_the_final_configuration_instead_of_building
218218
},
219+
{
220+
name: "listFilesOnly",
221+
type: "boolean",
222+
category: Diagnostics.Command_line_Options,
223+
affectsSemanticDiagnostics: true,
224+
affectsEmit: true,
225+
isCommandLineOnly: true,
226+
description: Diagnostics.Print_names_of_files_that_are_part_of_the_compilation_and_then_stop_processing
227+
},
219228

220229
// Basic
221230
{

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4311,6 +4311,10 @@
43114311
"category": "Message",
43124312
"code": 6502
43134313
},
4314+
"Print names of files that are part of the compilation and then stop processing.": {
4315+
"category": "Message",
4316+
"code": 6503
4317+
},
43144318

43154319
"Variable '{0}' implicitly has an '{1}' type.": {
43164320
"category": "Error",

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,6 +4951,7 @@ namespace ts {
49514951
lib?: string[];
49524952
/*@internal*/listEmittedFiles?: boolean;
49534953
/*@internal*/listFiles?: boolean;
4954+
/*@internal*/listFilesOnly?: boolean;
49544955
locale?: string;
49554956
mapRoot?: string;
49564957
maxNodeModuleJsDepth?: number;

src/compiler/watch.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace ts {
129129
}
130130

131131
export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void) {
132-
if (program.getCompilerOptions().listFiles) {
132+
if (program.getCompilerOptions().listFiles || program.getCompilerOptions().listFilesOnly) {
133133
forEach(program.getSourceFiles(), file => {
134134
writeFileName(file.fileName);
135135
});
@@ -149,6 +149,8 @@ namespace ts {
149149
emitOnlyDtsFiles?: boolean,
150150
customTransformers?: CustomTransformers
151151
) {
152+
const isListFilesOnly = !!program.getCompilerOptions().listFilesOnly;
153+
152154
// First get and report any syntactic errors.
153155
const diagnostics = program.getConfigFileParsingDiagnostics().slice();
154156
const configFileParsingDiagnosticsLength = diagnostics.length;
@@ -158,15 +160,20 @@ namespace ts {
158160
// semantic errors.
159161
if (diagnostics.length === configFileParsingDiagnosticsLength) {
160162
addRange(diagnostics, program.getOptionsDiagnostics(cancellationToken));
161-
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
162163

163-
if (diagnostics.length === configFileParsingDiagnosticsLength) {
164-
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
164+
if (!isListFilesOnly) {
165+
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
166+
167+
if (diagnostics.length === configFileParsingDiagnosticsLength) {
168+
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
169+
}
165170
}
166171
}
167172

168173
// Emit and report any errors we ran into.
169-
const emitResult = program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
174+
const emitResult = isListFilesOnly
175+
? { emitSkipped: true, diagnostics: emptyArray }
176+
: program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
170177
const { emittedFiles, diagnostics: emitDiagnostics } = emitResult;
171178
addRange(diagnostics, emitDiagnostics);
172179

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"unittests/tsbuild/watchMode.ts",
117117
"unittests/tsc/declarationEmit.ts",
118118
"unittests/tsc/incremental.ts",
119+
"unittests/tsc/listFilesOnly.ts",
119120
"unittests/tscWatch/consoleClearing.ts",
120121
"unittests/tscWatch/emit.ts",
121122
"unittests/tscWatch/emitAndErrorUpdates.ts",

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,23 @@ namespace ts {
446446
});
447447
});
448448

449+
it("parse build with listFilesOnly ", () => {
450+
// --lib es6 0.ts
451+
assertParseResult(["--listFilesOnly"],
452+
{
453+
errors: [{
454+
messageText:"Unknown build option '--listFilesOnly'.",
455+
category: Diagnostics.Unknown_build_option_0.category,
456+
code: Diagnostics.Unknown_build_option_0.code,
457+
file: undefined,
458+
start: undefined,
459+
length: undefined,
460+
}],
461+
projects: ["."],
462+
buildOptions: {}
463+
});
464+
});
465+
449466
it("Parse multiple flags with input projects at the end", () => {
450467
// --lib es5,es2015.symbol.wellknown --target es5 0.ts
451468
assertParseResult(["--force", "--verbose", "src", "tests"],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace ts {
2+
describe("unittests:: tsc:: listFilesOnly::", () => {
3+
verifyTsc({
4+
scenario: "listFilesOnly",
5+
subScenario: "combined with watch",
6+
fs: () => loadProjectFromFiles({
7+
"/src/test.ts": utils.dedent`
8+
export const x = 1;`,
9+
}),
10+
commandLineArgs: ["/src/test.ts", "--watch", "--listFilesOnly"]
11+
});
12+
13+
verifyTsc({
14+
scenario: "listFilesOnly",
15+
subScenario: "loose file",
16+
fs: () => loadProjectFromFiles({
17+
"/src/test.ts": utils.dedent`
18+
export const x = 1;`,
19+
}),
20+
commandLineArgs: ["/src/test.ts", "--listFilesOnly"]
21+
});
22+
});
23+
}

src/tsc/executeCommandLine.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ namespace ts {
207207
return sys.exit(ExitStatus.Success);
208208
}
209209

210+
if (commandLine.options.watch && commandLine.options.listFilesOnly) {
211+
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Options_0_and_1_cannot_be_combined, "watch", "listFilesOnly"));
212+
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
213+
}
214+
210215
if (commandLine.options.project) {
211216
if (commandLine.fileNames.length !== 0) {
212217
reportDiagnostic(createCompilerDiagnostic(Diagnostics.Option_project_cannot_be_mixed_with_source_files_on_a_command_line));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"listFilesOnly": true
4+
}
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc /src/test.ts --watch --listFilesOnly
3+
error TS6370: Options 'watch' and 'listFilesOnly' cannot be combined.
4+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
5+
6+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//// [/lib/initial-buildOutput.txt]
2+
/lib/tsc /src/test.ts --listFilesOnly
3+
/lib/lib.d.ts
4+
/src/test.ts
5+
exitCode:: ExitStatus.Success
6+
7+

0 commit comments

Comments
 (0)