From bd3e854b31781edfd03f087faf6de21b2bf1b783 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 13 Apr 2018 20:51:09 -0700 Subject: [PATCH 1/6] Automatically configure tsc output and provide a new 'diagnosticStyle' option. --- src/compiler/commandLineParser.ts | 8 ++++++++ src/compiler/sys.ts | 4 ++++ src/compiler/tsc.ts | 11 +++++++++-- src/compiler/types.ts | 6 ++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 470bd11149223..252ea9e8df0a0 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -56,6 +56,14 @@ namespace ts { category: Diagnostics.Command_line_Options, description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental }, + { + name: "diagnosticStyle", + type: createMapFromTemplate({ + auto: DiagnosticStyle.Auto, + pretty: DiagnosticStyle.Pretty, + simple: DiagnosticStyle.Simple, + }), + }, { name: "preserveWatchOutput", type: "boolean", diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index c37315a2e5601..2a4616732dd9e 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -428,6 +428,7 @@ namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTty?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; @@ -561,6 +562,9 @@ namespace ts { write(s: string): void { process.stdout.write(s); }, + writeOutputIsTty() { + return process.stdout.isTTY; + }, readFile, writeFile, watchFile: getWatchFile(), diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index f16ca98c93dac..5012b73e98a76 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -19,11 +19,18 @@ namespace ts { let reportDiagnostic = createDiagnosticReporter(sys); function updateReportDiagnostic(options: CompilerOptions) { - if (options.pretty) { + if (shouldBePretty(options)) { reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true); } } + function shouldBePretty(options: CompilerOptions) { + if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) { + return !!sys.writeOutputIsTty && sys.writeOutputIsTty(); + } + return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty; + } + function padLeft(s: string, length: number) { while (s.length < length) { s = " " + s; @@ -159,7 +166,7 @@ namespace ts { } function createWatchStatusReporter(options: CompilerOptions) { - return ts.createWatchStatusReporter(sys, !!options.pretty); + return ts.createWatchStatusReporter(sys, shouldBePretty(options)); } function createWatchOfConfigFile(configParseResult: ParsedCommandLine, optionsToExtend: CompilerOptions) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 987d403e7cd9e..802c175b573cc 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4193,7 +4193,8 @@ namespace ts { preserveSymlinks?: boolean; /* @internal */ preserveWatchOutput?: boolean; project?: string; - /* @internal */ pretty?: DiagnosticStyle; + /* @internal */ pretty?: boolean; + /* @internal */ diagnosticStyle?: DiagnosticStyle; reactNamespace?: string; jsxFactory?: string; removeComments?: boolean; @@ -4293,8 +4294,9 @@ namespace ts { /* @internal */ export const enum DiagnosticStyle { - Simple, + Auto, Pretty, + Simple, } /** Either a parsed command line or a parsed tsconfig.json */ From 7fd1dda13cf520a48671f553ba36a4e3e4f55350 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 13 Apr 2018 20:59:06 -0700 Subject: [PATCH 2/6] Accepted baselines --- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2e8e3f3871df3..dfe2f6130789b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2888,6 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTty?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 378949d5b5b07..6963bd95f72a8 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2888,6 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; + writeOutputIsTty?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; From 299002d597eed0daa56a444730ea5cdaff682ac3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Sat, 14 Apr 2018 11:53:27 -0700 Subject: [PATCH 3/6] Fix spacing. --- src/compiler/commandLineParser.ts | 16 ++++++++-------- src/compiler/tsc.ts | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 252ea9e8df0a0..2de922b4159f1 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -56,14 +56,14 @@ namespace ts { category: Diagnostics.Command_line_Options, description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental }, - { - name: "diagnosticStyle", - type: createMapFromTemplate({ - auto: DiagnosticStyle.Auto, - pretty: DiagnosticStyle.Pretty, - simple: DiagnosticStyle.Simple, - }), - }, + { + name: "diagnosticStyle", + type: createMapFromTemplate({ + auto: DiagnosticStyle.Auto, + pretty: DiagnosticStyle.Pretty, + simple: DiagnosticStyle.Simple, + }), + }, { name: "preserveWatchOutput", type: "boolean", diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 5012b73e98a76..56c3c323f30a2 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -27,7 +27,7 @@ namespace ts { function shouldBePretty(options: CompilerOptions) { if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) { return !!sys.writeOutputIsTty && sys.writeOutputIsTty(); - } + } return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty; } From 6953fa17328809c0b4db08e9a91adb2196957496 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Apr 2018 17:06:50 -0700 Subject: [PATCH 4/6] flags--; --- src/compiler/commandLineParser.ts | 8 -------- src/compiler/tsc.ts | 4 ++-- src/compiler/types.ts | 8 -------- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 2de922b4159f1..470bd11149223 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -56,14 +56,6 @@ namespace ts { category: Diagnostics.Command_line_Options, description: Diagnostics.Stylize_errors_and_messages_using_color_and_context_experimental }, - { - name: "diagnosticStyle", - type: createMapFromTemplate({ - auto: DiagnosticStyle.Auto, - pretty: DiagnosticStyle.Pretty, - simple: DiagnosticStyle.Simple, - }), - }, { name: "preserveWatchOutput", type: "boolean", diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 56c3c323f30a2..b2bffd83ca740 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -25,10 +25,10 @@ namespace ts { } function shouldBePretty(options: CompilerOptions) { - if ((typeof options.pretty === "undefined" && typeof options.diagnosticStyle === "undefined") || options.diagnosticStyle === DiagnosticStyle.Auto) { + if ((typeof options.pretty === "undefined")) { return !!sys.writeOutputIsTty && sys.writeOutputIsTty(); } - return options.diagnosticStyle === DiagnosticStyle.Pretty || options.pretty; + return options.pretty; } function padLeft(s: string, length: number) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 802c175b573cc..8962a7d028059 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4194,7 +4194,6 @@ namespace ts { /* @internal */ preserveWatchOutput?: boolean; project?: string; /* @internal */ pretty?: boolean; - /* @internal */ diagnosticStyle?: DiagnosticStyle; reactNamespace?: string; jsxFactory?: string; removeComments?: boolean; @@ -4292,13 +4291,6 @@ namespace ts { JSX, } - /* @internal */ - export const enum DiagnosticStyle { - Auto, - Pretty, - Simple, - } - /** Either a parsed command line or a parsed tsconfig.json */ export interface ParsedCommandLine { options: CompilerOptions; From 320cb40f123d1fa1eb91cd55d9555f8c4e9d81d3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Apr 2018 10:56:14 -0700 Subject: [PATCH 5/6] Address CR feedback. --- src/compiler/sys.ts | 4 ++-- src/compiler/tsc.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 2a4616732dd9e..be95e06eb46cb 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -428,7 +428,7 @@ namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; - writeOutputIsTty?(): boolean; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; @@ -562,7 +562,7 @@ namespace ts { write(s: string): void { process.stdout.write(s); }, - writeOutputIsTty() { + writeOutputIsTTY() { return process.stdout.isTTY; }, readFile, diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index b2bffd83ca740..3c73eba86ef1a 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -25,8 +25,8 @@ namespace ts { } function shouldBePretty(options: CompilerOptions) { - if ((typeof options.pretty === "undefined")) { - return !!sys.writeOutputIsTty && sys.writeOutputIsTty(); + if (typeof options.pretty === "undefined") { + return !!sys.writeOutputIsTTY && sys.writeOutputIsTTY(); } return options.pretty; } From 25bb58124bf165354f897a817940cbdbff2c9093 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Apr 2018 12:42:59 -0700 Subject: [PATCH 6/6] Accepted baselines. --- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index dfe2f6130789b..be11525ffb76d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2888,7 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; - writeOutputIsTty?(): boolean; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 6963bd95f72a8..c0cab668854c6 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2888,7 +2888,7 @@ declare namespace ts { newLine: string; useCaseSensitiveFileNames: boolean; write(s: string): void; - writeOutputIsTty?(): boolean; + writeOutputIsTTY?(): boolean; readFile(path: string, encoding?: string): string | undefined; getFileSize?(path: string): number; writeFile(path: string, data: string, writeByteOrderMark?: boolean): void;