mirror of
https://github.com/ezolenko/rollup-plugin-typescript2.git
synced 2025-12-08 19:06:16 +00:00
- per https://www.typescriptlang.org/tsconfig#pretty - TS 2.9 changed the default to `true`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-9.html#--pretty-output-by-default - so this is a legacy remnant of older versions of TS - this is why `tsc` by default pretty prints, even when `pretty` is unset - only if it is _explicitly_ set to `false` does it not do that - so change rpt2's diagnostic printing to be `pretty` by default as well - I think this is a pretty _big_ DX improvement, to be honest - I always thought something was up with the error reporting, but saw that there was code for `pretty`, so didn't quite connect the dots until now - that while there was code for it, the default was wrong, and so unless I set `pretty: true`, I wasn't getting easier to read printing - and given that `pretty: true` is the default, that's a redundant / unnecessary option to set in `tsconfig` that I normally wouldn't ever re-set
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { red, white, yellow } from "colors/safe";
|
|
|
|
import { tsModule } from "./tsproxy";
|
|
import { IContext } from "./context";
|
|
import { IDiagnostics } from "./tscache";
|
|
|
|
export function printDiagnostics(context: IContext, diagnostics: IDiagnostics[], pretty = true): void
|
|
{
|
|
diagnostics.forEach((diagnostic) =>
|
|
{
|
|
let print;
|
|
let color;
|
|
let category;
|
|
switch (diagnostic.category)
|
|
{
|
|
case tsModule.DiagnosticCategory.Message:
|
|
print = context.info;
|
|
color = white;
|
|
category = "";
|
|
break;
|
|
case tsModule.DiagnosticCategory.Error:
|
|
print = context.error;
|
|
color = red;
|
|
category = "error";
|
|
break;
|
|
case tsModule.DiagnosticCategory.Warning:
|
|
default:
|
|
print = context.warn;
|
|
color = yellow;
|
|
category = "warning";
|
|
break;
|
|
}
|
|
|
|
const type = diagnostic.type + " ";
|
|
|
|
if (pretty)
|
|
print.call(context, `${diagnostic.formatted}`);
|
|
else
|
|
{
|
|
if (diagnostic.fileLine !== undefined)
|
|
print.call(context, `${diagnostic.fileLine}: ${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
|
|
else
|
|
print.call(context, `${type}${category} TS${diagnostic.code}: ${color(diagnostic.flatMessage)}`);
|
|
}
|
|
});
|
|
}
|