22// See LICENSE in the project root for license information.
33
44import { NewlineKind } from '@rushstack/node-core-library' ;
5+ import type { IDaemonOperationHeaderPayload } from '@rushstack/rush-daemon-protocol' ;
56import { CollatedTerminal , StreamCollator } from '@rushstack/stream-collator' ;
67import type { CollatedWriter } from '@rushstack/stream-collator' ;
78import { TextRewriterTransform } from '@rushstack/terminal' ;
89import type { ITerminalChunk , TerminalWritable } from '@rushstack/terminal' ;
910
11+ import { OperationHeaderTracker } from './OperationHeaderTracker' ;
1012import { formatDaemonOperationHeader } from './RendererHeader' ;
1113
1214/** Options for {@link OperationStreamRegistry}. @beta */
@@ -29,16 +31,12 @@ export interface IOperationStreamRegistryOptions {
2931export class OperationStreamRegistry {
3032 private readonly _collator : StreamCollator ;
3133 private readonly _collatedTerminal : CollatedTerminal ;
32- private readonly _writers : Map < string , CollatedWriter > ;
34+ private readonly _headers : OperationHeaderTracker = new OperationHeaderTracker ( ) ;
35+ private readonly _writers : Map < string , CollatedWriter > = new Map ( ) ;
3336 private readonly _quiet : boolean ;
34- private _completedOperations : number ;
35- private _totalOperations : number ;
3637
3738 public constructor ( options : IOperationStreamRegistryOptions ) {
38- this . _writers = new Map ( ) ;
3939 this . _quiet = options . quiet ;
40- this . _completedOperations = 0 ;
41- this . _totalOperations = 0 ;
4240 const transform : TextRewriterTransform = new TextRewriterTransform ( {
4341 destination : options . destination ,
4442 normalizeNewlines : NewlineKind . OsDefault ,
@@ -53,7 +51,12 @@ export class OperationStreamRegistry {
5351
5452 /** Increments the total-operation count shown in headers. */
5553 public registerOperation ( ) : void {
56- this . _totalOperations += 1 ;
54+ this . _headers . registerOperation ( ) ;
55+ }
56+
57+ /** Records engine-authoritative counters before an operation's stream activates. */
58+ public setOperationHeader ( header : IDaemonOperationHeaderPayload ) : void {
59+ this . _headers . setOperationHeader ( header ) ;
5760 }
5861
5962 /** Writes one raw chunk to the operation's collated stream. */
@@ -78,11 +81,13 @@ export class OperationStreamRegistry {
7881 if ( writer === undefined ) {
7982 return ;
8083 }
81- this . _completedOperations += 1 ;
84+ const counters : IDaemonOperationHeaderPayload = this . _headers . takeOperationHeader (
85+ writer . taskName
86+ ) ;
8287 const header : string = formatDaemonOperationHeader (
8388 writer . taskName ,
84- this . _completedOperations ,
85- this . _totalOperations
89+ counters . completedOperations ,
90+ counters . totalOperations
8691 ) ;
8792 this . _collatedTerminal . writeStdoutLine ( `\n${ header } ` ) ;
8893 if ( ! this . _quiet ) {
0 commit comments