Skip to content

Commit 58efc2e

Browse files
committed
Merge pull request microsoft#7883 from Microsoft/listEmittedFiles2
Add option to list the emitted files as part of the compiler output.
2 parents b9c4b02 + 097adc6 commit 58efc2e

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ namespace ts {
336336
type: "boolean",
337337
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
338338
},
339+
{
340+
name: "listEmittedFiles",
341+
type: "boolean"
342+
},
339343
{
340344
name: "lib",
341345
type: "list",

src/compiler/emitter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
380380
const languageVersion = getEmitScriptTarget(compilerOptions);
381381
const modulekind = getEmitModuleKind(compilerOptions);
382382
const sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
383+
const emittedFilesList: string[] = compilerOptions.listEmittedFiles ? [] : undefined;
383384
const emitterDiagnostics = createDiagnosticCollection();
384385
let emitSkipped = false;
385386
const newLine = host.getNewLine();
@@ -390,6 +391,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
390391
return {
391392
emitSkipped,
392393
diagnostics: emitterDiagnostics.getDiagnostics(),
394+
emittedFiles: emittedFilesList,
393395
sourceMaps: sourceMapDataList
394396
};
395397

@@ -8233,6 +8235,16 @@ const _super = (function (geti, seti) {
82338235
if (declarationFilePath) {
82348236
emitSkipped = writeDeclarationFile(declarationFilePath, sourceFiles, isBundledEmit, host, resolver, emitterDiagnostics) || emitSkipped;
82358237
}
8238+
8239+
if (!emitSkipped && emittedFilesList) {
8240+
emittedFilesList.push(jsFilePath);
8241+
if (sourceMapFilePath) {
8242+
emittedFilesList.push(sourceMapFilePath);
8243+
}
8244+
if (declarationFilePath) {
8245+
emittedFilesList.push(declarationFilePath);
8246+
}
8247+
}
82368248
}
82378249
}
82388250
}

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ namespace ts {
10061006
let declarationDiagnostics: Diagnostic[] = [];
10071007

10081008
if (options.noEmit) {
1009-
return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emitSkipped: true };
1009+
return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: undefined, emitSkipped: true };
10101010
}
10111011

10121012
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
@@ -1026,6 +1026,7 @@ namespace ts {
10261026
return {
10271027
diagnostics: concatenate(diagnostics, declarationDiagnostics),
10281028
sourceMaps: undefined,
1029+
emittedFiles: undefined,
10291030
emitSkipped: true
10301031
};
10311032
}

src/compiler/tsc.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ namespace ts {
1414
}
1515
}
1616

17+
function reportEmittedFiles(files: string[], host: CompilerHost): void {
18+
if (!files || files.length == 0) {
19+
return;
20+
}
21+
22+
const currentDir = sys.getCurrentDirectory();
23+
24+
for (const file of files) {
25+
const filepath = getNormalizedAbsolutePath(file, currentDir);
26+
27+
sys.write(`TSFILE: ${filepath}${sys.newLine}`);
28+
}
29+
}
30+
1731
/**
1832
* Checks to see if the locale is in the appropriate format,
1933
* and if it is, attempts to set the appropriate language.
@@ -108,7 +122,6 @@ namespace ts {
108122
sys.write(output);
109123
}
110124

111-
112125
const redForegroundEscapeSequence = "\u001b[91m";
113126
const yellowForegroundEscapeSequence = "\u001b[93m";
114127
const blueForegroundEscapeSequence = "\u001b[93m";
@@ -597,6 +610,8 @@ namespace ts {
597610

598611
reportDiagnostics(sortAndDeduplicateDiagnostics(diagnostics), compilerHost);
599612

613+
reportEmittedFiles(emitOutput.emittedFiles, compilerHost);
614+
600615
if (emitOutput.emitSkipped && diagnostics.length > 0) {
601616
// If the emitter didn't emit anything, then pass that value along.
602617
return ExitStatus.DiagnosticsPresent_OutputsSkipped;

src/compiler/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ namespace ts {
17091709
emitSkipped: boolean;
17101710
/** Contains declaration emit diagnostics */
17111711
diagnostics: Diagnostic[];
1712+
emittedFiles: string[]; // Array of files the compiler wrote to disk
17121713
/* @internal */ sourceMaps: SourceMapData[]; // Array of sourceMapData if compiler emitted sourcemaps
17131714
}
17141715

@@ -2460,6 +2461,7 @@ namespace ts {
24602461
allowJs?: boolean;
24612462
noImplicitUseStrict?: boolean;
24622463
strictNullChecks?: boolean;
2464+
listEmittedFiles?: boolean;
24632465
lib?: string[];
24642466
/* @internal */ stripInternal?: boolean;
24652467

0 commit comments

Comments
 (0)