1
1
use std:: collections:: HashMap ;
2
2
use std:: fmt:: Debug ;
3
+ use std:: sync:: Arc ;
3
4
4
5
use napi:: bindgen_prelude:: Either4 ;
5
6
use napi_derive:: napi;
6
- use rspack_core :: ExternalItemFnCtx ;
7
+ use rspack_binding_values :: JsResolver ;
7
8
use rspack_core:: { ExternalItem , ExternalItemFnResult , ExternalItemValue } ;
9
+ use rspack_core:: { ExternalItemFnCtx , ResolveOptionsWithDependencyType , ResolverFactory } ;
8
10
use rspack_napi:: threadsafe_function:: ThreadsafeFunction ;
9
11
use rspack_regex:: RspackRegex ;
10
12
@@ -68,15 +70,47 @@ pub struct ContextInfo {
68
70
pub issuer : String ,
69
71
}
70
72
71
- #[ derive( Debug , Clone ) ]
72
- #[ napi( object ) ]
73
+ #[ derive( Debug ) ]
74
+ #[ napi]
73
75
pub struct RawExternalItemFnCtx {
76
+ request : String ,
77
+ context : String ,
78
+ dependency_type : String ,
79
+ context_info : ContextInfo ,
80
+ resolve_options_with_dependency_type : ResolveOptionsWithDependencyType ,
81
+ resolver_factory : Arc < ResolverFactory > ,
82
+ }
83
+
84
+ #[ derive( Debug ) ]
85
+ #[ napi( object) ]
86
+ pub struct RawExternalItemFnCtxData {
74
87
pub request : String ,
75
88
pub context : String ,
76
89
pub dependency_type : String ,
77
90
pub context_info : ContextInfo ,
78
91
}
79
92
93
+ #[ napi]
94
+ impl RawExternalItemFnCtx {
95
+ #[ napi]
96
+ pub fn data ( & self ) -> RawExternalItemFnCtxData {
97
+ RawExternalItemFnCtxData {
98
+ request : self . request . clone ( ) ,
99
+ context : self . context . clone ( ) ,
100
+ dependency_type : self . dependency_type . clone ( ) ,
101
+ context_info : self . context_info . clone ( ) ,
102
+ }
103
+ }
104
+
105
+ #[ napi]
106
+ pub fn get_resolver ( & self ) -> JsResolver {
107
+ JsResolver :: new (
108
+ self . resolver_factory . clone ( ) ,
109
+ self . resolve_options_with_dependency_type . clone ( ) ,
110
+ )
111
+ }
112
+ }
113
+
80
114
impl From < ExternalItemFnCtx > for RawExternalItemFnCtx {
81
115
fn from ( value : ExternalItemFnCtx ) -> Self {
82
116
Self {
@@ -86,6 +120,8 @@ impl From<ExternalItemFnCtx> for RawExternalItemFnCtx {
86
120
context_info : ContextInfo {
87
121
issuer : value. context_info . issuer ,
88
122
} ,
123
+ resolve_options_with_dependency_type : value. resolve_options_with_dependency_type ,
124
+ resolver_factory : value. resolver_factory ,
89
125
}
90
126
}
91
127
}
0 commit comments