1- import { type Compiler } from "webpack" ;
1+ import { type Compiler , ProgressPlugin } from "webpack" ;
22import { type CLIPluginOptions } from "../types" ;
33
44export class CLIPlugin {
@@ -21,17 +21,51 @@ export class CLIPlugin {
2121 }
2222 }
2323
24+ static #progressStates: [ number , ...string [ ] ] [ ] = [ ] ;
25+
2426 setupProgressPlugin ( compiler : Compiler ) {
2527 const { ProgressPlugin } = compiler . webpack || require ( "webpack" ) ;
2628 const progressPlugin = Boolean (
2729 compiler . options . plugins . find ( ( plugin ) => plugin instanceof ProgressPlugin ) ,
2830 ) ;
2931
30- if ( ! progressPlugin ) {
31- new ProgressPlugin ( {
32- profile : this . options . progress === "profile" ,
33- } ) . apply ( compiler ) ;
32+ if ( progressPlugin ) {
33+ return ;
3434 }
35+
36+ const isProfile = this . options . progress === "profile" ;
37+
38+ const options : ConstructorParameters < typeof ProgressPlugin > [ 0 ] = {
39+ profile : isProfile ,
40+ } ;
41+
42+ if ( this . options . isMultiCompiler && ProgressPlugin . createDefaultHandler ) {
43+ const handler = ProgressPlugin . createDefaultHandler (
44+ isProfile ,
45+ compiler . getInfrastructureLogger ( "webpack.Progress" ) ,
46+ ) ;
47+ const idx = CLIPlugin . #progressStates. length ;
48+
49+ CLIPlugin . #progressStates[ idx ] = [ 0 ] ;
50+
51+ options . handler = ( p : number , msg : string , ...args : string [ ] ) => {
52+ CLIPlugin . #progressStates[ idx ] = [ p , msg , ...args ] ;
53+
54+ let sum = 0 ;
55+
56+ for ( const [ p ] of CLIPlugin . #progressStates) {
57+ sum += p ;
58+ }
59+
60+ handler (
61+ sum / CLIPlugin . #progressStates. length ,
62+ `[${ compiler . name ? compiler . name : idx } ] ${ msg } ` ,
63+ ...args ,
64+ ) ;
65+ } ;
66+ }
67+
68+ new ProgressPlugin ( options ) . apply ( compiler ) ;
3569 }
3670
3771 setupHelpfulOutput ( compiler : Compiler ) {
0 commit comments