Automatically configure tsc output and provide a new 'diagnosticStyle' option.
This commit is contained in:
parent
23ed9f8423
commit
bd3e854b31
4 changed files with 25 additions and 4 deletions
|
@ -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",
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue