File tree Expand file tree Collapse file tree 1 file changed +34
-8
lines changed
packages/runtime/src/module Expand file tree Collapse file tree 1 file changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -122,19 +122,45 @@ class Module {
122
122
`${ getFMId ( this . remoteInfo ) } remote don't export ${ expose } .` ,
123
123
) ;
124
124
125
+ const wrapModuleFactory = this . wraperFactory ( moduleFactory , id ) ;
126
+
125
127
if ( ! loadFactory ) {
126
- return moduleFactory ;
128
+ return wrapModuleFactory ;
127
129
}
128
- const exposeContent = await moduleFactory ( ) ;
129
-
130
- // This parameter is used for bridge debugging
131
- Object . defineProperty ( exposeContent , Symbol . for ( 'mf_module_id' ) , {
132
- value : id ,
133
- enumerable : false ,
134
- } ) ;
130
+ const exposeContent = await wrapModuleFactory ( ) ;
135
131
136
132
return exposeContent ;
137
133
}
134
+
135
+ private wraperFactory (
136
+ moduleFactory : ( ) => any | ( ( ) => Promise < any > ) ,
137
+ id : string ,
138
+ ) {
139
+ function defineModuleId ( res : any , id : string ) {
140
+ if ( res && typeof res === 'object' ) {
141
+ Object . defineProperty ( res , Symbol . for ( 'mf_module_id' ) , {
142
+ value : id ,
143
+ enumerable : false ,
144
+ } ) ;
145
+ }
146
+ }
147
+
148
+ if ( moduleFactory instanceof Promise ) {
149
+ return async ( ) => {
150
+ const res = await moduleFactory ( ) ;
151
+ // This parameter is used for bridge debugging
152
+ defineModuleId ( res , id ) ;
153
+ return res ;
154
+ } ;
155
+ } else {
156
+ return ( ) => {
157
+ const res = moduleFactory ( ) ;
158
+ // This parameter is used for bridge debugging
159
+ defineModuleId ( res , id ) ;
160
+ return res ;
161
+ } ;
162
+ }
163
+ }
138
164
}
139
165
140
166
export { Module } ;
You can’t perform that action at this time.
0 commit comments