@@ -15,6 +15,7 @@ use rspack_core::BoxDependency;
15
15
use rspack_core:: Compilation ;
16
16
use rspack_core:: CompilationId ;
17
17
use rspack_core:: EntryOptions ;
18
+ use rspack_core:: FactorizeInfo ;
18
19
use rspack_core:: ModuleIdentifier ;
19
20
use rspack_error:: Diagnostic ;
20
21
use rspack_napi:: napi:: bindgen_prelude:: * ;
@@ -760,49 +761,53 @@ impl JsCompilation {
760
761
let module_graph = compilation. get_module_graph ( ) ;
761
762
let results = dependency_ids
762
763
. into_iter ( )
763
- . map (
764
- |dependency_id| match module_graph. get_module_by_dependency_id ( & dependency_id) {
764
+ . map ( |dependency_id| {
765
+ if let Some ( dependency) = module_graph. dependency_by_id ( & dependency_id) {
766
+ if let Some ( factorize_info) = FactorizeInfo :: get_from ( dependency) {
767
+ if let Some ( diagnostic) = factorize_info. diagnostics ( ) . first ( ) {
768
+ return Either :: A ( diagnostic. to_string ( ) ) ;
769
+ }
770
+ }
771
+ }
772
+
773
+ match module_graph. get_module_by_dependency_id ( & dependency_id) {
765
774
Some ( module) => {
766
775
let js_module =
767
776
JsModuleWrapper :: new ( module. identifier ( ) , None , compilation. compiler_id ( ) ) ;
768
- ( Either :: B ( ( ) ) , Either :: B ( js_module) )
777
+ Either :: B ( js_module)
769
778
}
770
- None => (
771
- Either :: A ( format ! (
772
- "Module created by {:?} cannot be found" ,
773
- dependency_id
774
- ) ) ,
775
- Either :: A ( ( ) ) ,
776
- ) ,
777
- } ,
778
- )
779
- . collect :: < Vec < ( Either < String , ( ) > , Either < ( ) , JsModuleWrapper > ) > > ( ) ;
779
+ None => Either :: A ( "build failed with unknown error" . to_string ( ) ) ,
780
+ }
781
+ } )
782
+ . collect :: < Vec < Either < String , JsModuleWrapper > > > ( ) ;
780
783
781
784
Ok ( JsAddIncludeCallbackArgs ( results) )
782
785
} )
783
786
}
784
787
}
785
788
786
- pub struct JsAddIncludeCallbackArgs ( Vec < ( Either < String , ( ) > , Either < ( ) , JsModuleWrapper > ) > ) ;
789
+ pub struct JsAddIncludeCallbackArgs ( Vec < Either < String , JsModuleWrapper > > ) ;
787
790
788
791
impl ToNapiValue for JsAddIncludeCallbackArgs {
789
792
unsafe fn to_napi_value ( env : sys:: napi_env , val : Self ) -> Result < sys:: napi_value > {
790
793
let env_wrapper = Env :: from_raw ( env) ;
791
794
let mut js_array = env_wrapper. create_array ( 0 ) ?;
792
- for ( error, module) in val. 0 {
793
- let js_error = match error {
794
- Either :: A ( val) => env_wrapper. create_string ( & val) ?. into_unknown ( ) ,
795
- Either :: B ( _) => env_wrapper. get_undefined ( ) ?. into_unknown ( ) ,
796
- } ;
797
- let js_module = match module {
798
- Either :: A ( _) => env_wrapper. get_undefined ( ) ?. into_unknown ( ) ,
799
- Either :: B ( val) => {
800
- let napi_val = ToNapiValue :: to_napi_value ( env, val) ?;
801
- Unknown :: from_napi_value ( env, napi_val) ?
795
+
796
+ for result in val. 0 {
797
+ let js_result = match result {
798
+ Either :: A ( msg) => vec ! [
799
+ env_wrapper. create_string( & msg) ?. into_unknown( ) ,
800
+ env_wrapper. get_undefined( ) ?. into_unknown( ) ,
801
+ ] ,
802
+ Either :: B ( module) => {
803
+ let napi_val = ToNapiValue :: to_napi_value ( env, module) ?;
804
+ let js_module = Unknown :: from_napi_value ( env, napi_val) ?;
805
+ vec ! [ env_wrapper. get_undefined( ) ?. into_unknown( ) , js_module]
802
806
}
803
807
} ;
804
- js_array. insert ( vec ! [ js_error , js_module ] ) ?;
808
+ js_array. insert ( js_result ) ?;
805
809
}
810
+
806
811
ToNapiValue :: to_napi_value ( env, js_array)
807
812
}
808
813
}
0 commit comments