Skip to content

Commit bd3e854

Browse files
Automatically configure tsc output and provide a new 'diagnosticStyle' option.
1 parent 23ed9f8 commit bd3e854

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

Diff for: src/compiler/commandLineParser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ namespace ts {
5656
category: Diagnostics.Command_line_Options,
5757
description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental
5858
},
59+
{
60+
name: "diagnosticStyle",
61+
type: createMapFromTemplate({
62+
auto: DiagnosticStyle.Auto,
63+
pretty: DiagnosticStyle.Pretty,
64+
simple: DiagnosticStyle.Simple,
65+
}),
66+
},
5967
{
6068
name: "preserveWatchOutput",
6169
type: "boolean",

Diff for: src/compiler/sys.ts

+4
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ namespace ts {
428428
newLine: string;
429429
useCaseSensitiveFileNames: boolean;
430430
write(s: string): void;
431+
writeOutputIsTty?(): boolean;
431432
readFile(path: string, encoding?: string): string | undefined;
432433
getFileSize?(path: string): number;
433434
writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;
@@ -561,6 +562,9 @@ namespace ts {
561562
write(s: string): void {
562563
process.stdout.write(s);
563564
},
565+
writeOutputIsTty() {
566+
return process.stdout.isTTY;
567+
},
564568
readFile,
565569
writeFile,
566570
watchFile: getWatchFile(),

Diff for: src/compiler/tsc.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,18 @@ namespace ts {
1919

2020
let reportDiagnostic = createDiagnosticReporter(sys);
2121
function updateReportDiagnostic(options: CompilerOptions) {
22-
if (options.pretty) {
22+
if (shouldBePretty(options)) {
2323
reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
2424
}
2525
}
2626

27+
function shouldBePretty(options: CompilerOptions) {
28+
if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) {
29+
return !!sys.writeOutputIsTty && sys.writeOutputIsTty();
30+
}
31+
return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty;
32+
}
33+
2734
function padLeft(s: string, length: number) {
2835
while (s.length < length) {
2936
s = " " + s;
@@ -159,7 +166,7 @@ namespace ts {
159166
}
160167

161168
function createWatchStatusReporter(options: CompilerOptions) {
162-
return ts.createWatchStatusReporter(sys, !!options.pretty);
169+
return ts.createWatchStatusReporter(sys, shouldBePretty(options));
163170
}
164171

165172
function createWatchOfConfigFile(configParseResult: ParsedCommandLine, optionsToExtend: CompilerOptions) {

Diff for: src/compiler/types.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -4193,7 +4193,8 @@ namespace ts {
41934193
preserveSymlinks?: boolean;
41944194
/* @internal */ preserveWatchOutput?: boolean;
41954195
project?: string;
4196-
/* @internal */ pretty?: DiagnosticStyle;
4196+
/* @internal */ pretty?: boolean;
4197+
/* @internal */ diagnosticStyle?: DiagnosticStyle;
41974198
reactNamespace?: string;
41984199
jsxFactory?: string;
41994200
removeComments?: boolean;
@@ -4293,8 +4294,9 @@ namespace ts {
42934294

42944295
/* @internal */
42954296
export const enum DiagnosticStyle {
4296-
Simple,
4297+
Auto,
42974298
Pretty,
4299+
Simple,
42984300
}
42994301

43004302
/** Either a parsed command line or a parsed tsconfig.json */

0 commit comments

Comments
 (0)