Skip to content

match tsc's behaviour when printing diagnostics context #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/tsc-bulk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ export function findDiagnosticsScopeId(d: DiagnosticTsc, isStrictScope: boolean)
return `.${results.join('.')}`;
}

// if stdout is being piped to another destination, print diagnostics
// without pretty colours. This matches the behaviour of TSC:
// https://github.com/microsoft/TypeScript/blob/0652664e/src/compiler/executeCommandLine.ts#L161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing this reference 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that they tsc considers NO_COLOR=0 to mean no color, but when in Rome 🤷‍♂️

const formatDiagnostics =
process.env.NO_COLOR || !process.stdout.isTTY
? ts.formatDiagnostics
: ts.formatDiagnosticsWithColorAndContext;

export function assertDiagnostics(
configRelatedErrors: readonly DiagnosticTsc[],
projectErrors: readonly DiagnosticTsc[],
Expand All @@ -133,7 +141,7 @@ export function assertDiagnostics(
return 0;
}
if (!bulkConfig) {
log.info(ts.formatDiagnosticsWithColorAndContext(diagnostics, host));
log.info(formatDiagnostics(diagnostics, host));
return diagnostics.length;
}

Expand Down Expand Up @@ -185,7 +193,7 @@ export function assertDiagnostics(
else projectStat.externalErrors.push(dStat);
});

const formattedLog = ts.formatDiagnosticsWithColorAndContext(diagnosticsToShow, host);
const formattedLog = formatDiagnostics(diagnosticsToShow, host);

projectStat.raw = formattedLog;

Expand Down