mirror of
https://github.com/keymanapp/keyman.git
synced 2026-08-07 09:25:33 +00:00
parent
53e2ae0ac2
commit
d5aeecd7d3
2 changed files with 31 additions and 3 deletions
|
|
@ -9,9 +9,6 @@ import { CompilerCallbacks, CompilerSchema, CompilerEvent,
|
|||
import { InfrastructureMessages } from './messages.js';
|
||||
import chalk from 'chalk';
|
||||
import supportsColor from 'supports-color';
|
||||
/**
|
||||
* Concrete implementation for CLI use
|
||||
*/
|
||||
|
||||
const color = chalk.default;
|
||||
const severityColors: {[value in CompilerErrorSeverity]: chalk.Chalk} = {
|
||||
|
|
@ -22,10 +19,20 @@ const severityColors: {[value in CompilerErrorSeverity]: chalk.Chalk} = {
|
|||
[CompilerErrorSeverity.Fatal]: color.redBright,
|
||||
};
|
||||
|
||||
/**
|
||||
* Maximum messages that will be emitted before suppressing further messages.
|
||||
* We may in the future make this user configurable?
|
||||
*/
|
||||
const MaxMessagesDefault = 100;
|
||||
|
||||
/**
|
||||
* Concrete implementation for CLI use
|
||||
*/
|
||||
export class NodeCompilerCallbacks implements CompilerCallbacks {
|
||||
/* NodeCompilerCallbacks */
|
||||
|
||||
messages: CompilerEvent[] = [];
|
||||
messageCount = 0;
|
||||
|
||||
constructor(private options: CompilerCallbackOptions) {
|
||||
color.enabled = this.options.color ?? (supportsColor.stdout ? supportsColor.stdout.hasBasic : false);
|
||||
|
|
@ -33,6 +40,7 @@ export class NodeCompilerCallbacks implements CompilerCallbacks {
|
|||
|
||||
clear() {
|
||||
this.messages = [];
|
||||
this.messageCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -102,6 +110,23 @@ export class NodeCompilerCallbacks implements CompilerCallbacks {
|
|||
return;
|
||||
}
|
||||
|
||||
// We don't use this.messages.length because we only want to count visible
|
||||
// messages, and there's no point in recalculating the total for every
|
||||
// message emitted.
|
||||
this.messageCount++;
|
||||
if(this.messageCount > MaxMessagesDefault) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.messageCount == MaxMessagesDefault) {
|
||||
// We've hit our event limit so we'll suppress further messages, and emit
|
||||
// our little informational message so users know what's going on. Note
|
||||
// that this message will not be included in the this.messages array, and
|
||||
// that will continue to collect all messages; this only affects the
|
||||
// console emission of messages.
|
||||
event = InfrastructureMessages.Info_TooManyMessages({count: MaxMessagesDefault});
|
||||
}
|
||||
|
||||
const severityColor = severityColors[CompilerError.severity(event.code)] ?? color.reset;
|
||||
const messageColor = this.messageSpecialColor(event) ?? color.reset;
|
||||
process.stdout.write(
|
||||
|
|
|
|||
|
|
@ -61,5 +61,8 @@ export class InfrastructureMessages {
|
|||
`Project ${o.filename} failed to build.`)});
|
||||
static INFO_ProjectNotBuiltSuccessfully = SevInfo | 0x000C;
|
||||
|
||||
static Info_TooManyMessages = (o:{count:number}) => m(this.INFO_TooManyMessages,
|
||||
`More than ${o.count} warnings or errors received; suppressing further messages.`);
|
||||
static INFO_TooManyMessages = SevInfo | 0x000D;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue