@@ -12,7 +12,6 @@ import {
1212 type ExternalObject ,
1313 type JsCompatSourceOwned ,
1414 type JsCompilation ,
15- type JsModule ,
1615 type JsPathData ,
1716 JsRspackSeverity ,
1817 type JsRuntimeModule
@@ -53,7 +52,7 @@ import { LogType, Logger } from "./logging/Logger";
5352import { StatsFactory } from "./stats/StatsFactory" ;
5453import { StatsPrinter } from "./stats/StatsPrinter" ;
5554import { type AssetInfo , JsAssetInfo } from "./util/AssetInfo" ;
56- import MergeCaller from "./util/MergeCaller " ;
55+ import { AsyncTask } from "./util/AsyncTask " ;
5756import { createReadonlyMap } from "./util/createReadonlyMap" ;
5857import { createFakeCompilationDependencies } from "./util/fake" ;
5958import type { InputFileSystem } from "./util/fs" ;
@@ -1075,27 +1074,31 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
10751074 ) ;
10761075 }
10771076
1078- #rebuildModuleCaller = ( ( compilation : Compilation ) =>
1079- new MergeCaller (
1080- ( args : Array < [ string , ( err : Error , m : Module ) => void ] > ) => {
1081- compilation . #inner. rebuildModule (
1082- args . map ( item => item [ 0 ] ) ,
1083- ( err : Error , modules : JsModule [ ] ) => {
1084- for ( const [ id , callback ] of args ) {
1085- const m = modules . find ( item => item . moduleIdentifier === id ) ;
1086- if ( m ) {
1087- callback ( err , Module . __from_binding ( m ) ) ;
1088- } else {
1089- callback ( err || new Error ( "module no found" ) , null as any ) ;
1090- }
1091- }
1077+ #rebuildModuleTask = new AsyncTask < string , Module > (
1078+ ( moduleIdentifiers , doneWork ) => {
1079+ this . #inner. rebuildModule (
1080+ moduleIdentifiers ,
1081+ ( err : Error | null , modules : binding . JsModule [ ] ) => {
1082+ /*
1083+ * TODO:
1084+ * batch all call parameters, once a module is failed, we cannot know which module
1085+ * is failed to rebuild, we have to make all modules failed, this should be improved
1086+ * in the future
1087+ */
1088+ if ( err ) {
1089+ doneWork ( new Array ( moduleIdentifiers . length ) . fill ( [ err , null ] ) ) ;
1090+ } else {
1091+ doneWork (
1092+ modules . map ( jsModule => [ null , Module . __from_binding ( jsModule ) ] )
1093+ ) ;
10921094 }
1093- ) ;
1094- }
1095- ) ) ( this ) ;
1095+ }
1096+ ) ;
1097+ }
1098+ ) ;
10961099
1097- rebuildModule ( m : Module , f : ( err : Error , m : Module ) => void ) {
1098- this . #rebuildModuleCaller . push ( [ m . identifier ( ) , f ] ) ;
1100+ rebuildModule ( m : Module , f : ( err : Error | null , m : Module | null ) => void ) {
1101+ this . #rebuildModuleTask . exec ( m . identifier ( ) , f ) ;
10991102 }
11001103
11011104 addRuntimeModule ( chunk : Chunk , runtimeModule : RuntimeModule ) {
@@ -1248,7 +1251,7 @@ class AddIncludeDispatcher {
12481251 this . #cbs = [ ] ;
12491252 this . #inner( args , ( wholeErr , results ) => {
12501253 if ( this . #args. length !== 0 ) {
1251- queueMicrotask ( this . #execute) ;
1254+ queueMicrotask ( this . #execute. bind ( this ) ) ;
12521255 }
12531256
12541257 if ( wholeErr ) {
@@ -1281,7 +1284,7 @@ class AddIncludeDispatcher {
12811284 callback : ( err ?: null | WebpackError , module ?: Module ) => void
12821285 ) {
12831286 if ( this . #args. length === 0 ) {
1284- queueMicrotask ( this . #execute) ;
1287+ queueMicrotask ( this . #execute. bind ( this ) ) ;
12851288 }
12861289
12871290 this . #args. push ( [ context , dependency , options as any ] ) ;
0 commit comments