diff --git a/developer/src/kmc/src/messages/NodeCompilerCallbacks.ts b/developer/src/kmc/src/messages/NodeCompilerCallbacks.ts index 5c1d4c8f75..376ef5b6d9 100644 --- a/developer/src/kmc/src/messages/NodeCompilerCallbacks.ts +++ b/developer/src/kmc/src/messages/NodeCompilerCallbacks.ts @@ -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( diff --git a/developer/src/kmc/src/messages/messages.ts b/developer/src/kmc/src/messages/messages.ts index c2fb3fe025..b2e0a54149 100644 --- a/developer/src/kmc/src/messages/messages.ts +++ b/developer/src/kmc/src/messages/messages.ts @@ -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; }