@@ -12,16 +12,17 @@ use crate::{
12
12
SharedPluginDriver ,
13
13
} ;
14
14
15
+ #[ derive( Clone ) ]
15
16
pub struct AfterResolveResult {
16
17
pub resource : String ,
17
- // context: Context ,
18
+ pub context : String ,
18
19
// dependencies
19
20
// layer
20
21
// resolve_options
21
22
// file_dependencies: HashSet<String>,
22
23
// missing_dependencies: HashSet<String>,
23
24
// context_dependencies: HashSet<String>,
24
- // request: String,
25
+ pub request : String ,
25
26
// mode
26
27
// recursive: bool,
27
28
pub reg_exp : Option < RspackRegex > ,
@@ -37,7 +38,7 @@ pub struct AfterResolveResult {
37
38
}
38
39
39
40
define_hook ! ( ContextModuleFactoryBeforeResolve : AsyncSeriesBail ( data: & mut ModuleFactoryCreateData ) -> bool ) ;
40
- define_hook ! ( ContextModuleFactoryAfterResolve : AsyncSeriesBail ( data: & mut AfterResolveResult ) -> bool ) ;
41
+ define_hook ! ( ContextModuleFactoryAfterResolve : AsyncSeriesWaterfall ( data: AfterResolveResult ) -> Option < AfterResolveResult > ) ;
41
42
42
43
#[ derive( Debug , Default ) ]
43
44
pub struct ContextModuleFactoryHooks {
@@ -205,8 +206,7 @@ impl ContextModuleFactory {
205
206
Err ( err) => ( Err ( err) , false ) ,
206
207
} ;
207
208
208
- let mut context_module_options = None ;
209
- let module = match resource_data {
209
+ let ( module, context_module_options) = match resource_data {
210
210
Ok ( ResolveResult :: Resource ( resource) ) => {
211
211
let options = ContextModuleOptions {
212
212
addon : loader_request. to_string ( ) ,
@@ -216,11 +216,11 @@ impl ContextModuleFactory {
216
216
resolve_options : data. resolve_options . clone ( ) ,
217
217
context_options : dependency. options ( ) . clone ( ) ,
218
218
} ;
219
- context_module_options = Some ( options. clone ( ) ) ;
220
- Box :: new ( ContextModule :: new (
221
- options,
219
+ let module = Box :: new ( ContextModule :: new (
220
+ options. clone ( ) ,
222
221
plugin_driver. resolver_factory . clone ( ) ,
223
- ) )
222
+ ) ) ;
223
+ ( module, Some ( options) )
224
224
}
225
225
Ok ( ResolveResult :: Ignored ) => {
226
226
let ident = format ! ( "{}/{}" , data. context, specifier) ;
@@ -254,28 +254,32 @@ impl ContextModuleFactory {
254
254
& self ,
255
255
context_module_options : & mut ContextModuleOptions ,
256
256
) -> Result < Option < ModuleFactoryResult > > {
257
- let mut after_resolve_result = AfterResolveResult {
257
+ let context_options = & context_module_options. context_options ;
258
+ let after_resolve_result = AfterResolveResult {
258
259
resource : context_module_options. resource . to_owned ( ) ,
259
- reg_exp : context_module_options. context_options . reg_exp . clone ( ) ,
260
+ context : context_options. context . to_owned ( ) ,
261
+ request : context_options. request . to_owned ( ) ,
262
+ reg_exp : context_options. reg_exp . clone ( ) ,
260
263
} ;
261
264
262
- if let Some ( false ) = self
265
+ match self
263
266
. plugin_driver
264
267
. context_module_factory_hooks
265
268
. after_resolve
266
- . call ( & mut after_resolve_result)
269
+ . call ( after_resolve_result)
267
270
. await ?
268
271
{
269
- return Ok ( None ) ;
270
- }
271
-
272
- context_module_options. resource = after_resolve_result. resource ;
273
- context_module_options. context_options . reg_exp = after_resolve_result. reg_exp ;
272
+ Some ( after_resolve_result) => {
273
+ context_module_options. resource = after_resolve_result. resource ;
274
+ context_module_options. context_options . reg_exp = after_resolve_result. reg_exp ;
274
275
275
- let module = ContextModule :: new (
276
- context_module_options. clone ( ) ,
277
- self . loader_resolver_factory . clone ( ) ,
278
- ) ;
279
- Ok ( Some ( ModuleFactoryResult :: new_with_module ( Box :: new ( module) ) ) )
276
+ let module = ContextModule :: new (
277
+ context_module_options. clone ( ) ,
278
+ self . loader_resolver_factory . clone ( ) ,
279
+ ) ;
280
+ Ok ( Some ( ModuleFactoryResult :: new_with_module ( Box :: new ( module) ) ) )
281
+ }
282
+ None => Ok ( None ) ,
283
+ }
280
284
}
281
285
}
0 commit comments