@@ -121,18 +121,18 @@ export class SharedHandler {
121
121
// 2. Searches globally for a matching share, if found, it uses it directly
122
122
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
123
123
124
- const shareInfo = getTargetSharedOptions ( {
124
+ const shareOptions = getTargetSharedOptions ( {
125
125
pkgName,
126
126
extraOptions,
127
127
shareInfos : host . options . shared ,
128
128
} ) ;
129
129
130
- if ( shareInfo ?. scope ) {
130
+ if ( shareOptions ?. scope ) {
131
131
await Promise . all (
132
- shareInfo . scope . map ( async ( shareScope ) => {
132
+ shareOptions . scope . map ( async ( shareScope ) => {
133
133
await Promise . all (
134
134
this . initializeSharing ( shareScope , {
135
- strategy : shareInfo . strategy ,
135
+ strategy : shareOptions . strategy ,
136
136
} ) ,
137
137
) ;
138
138
return ;
@@ -141,24 +141,24 @@ export class SharedHandler {
141
141
}
142
142
const loadShareRes = await this . hooks . lifecycle . beforeLoadShare . emit ( {
143
143
pkgName,
144
- shareInfo,
144
+ shareInfo : shareOptions ,
145
145
shared : host . options . shared ,
146
146
origin : host ,
147
147
} ) ;
148
148
149
- const { shareInfo : shareInfoRes } = loadShareRes ;
149
+ const { shareInfo : shareOptionsRes } = loadShareRes ;
150
150
151
151
// Assert that shareInfoRes exists, if not, throw an error
152
152
assert (
153
- shareInfoRes ,
153
+ shareOptionsRes ,
154
154
`Cannot find ${ pkgName } Share in the ${ host . options . name } . Please ensure that the ${ pkgName } Share parameters have been injected` ,
155
155
) ;
156
156
157
157
// Retrieve from cache
158
158
const registeredShared = getRegisteredShare (
159
159
this . shareScopeMap ,
160
160
pkgName ,
161
- shareInfoRes ,
161
+ shareOptionsRes ,
162
162
this . hooks . lifecycle . resolveShare ,
163
163
) ;
164
164
@@ -187,20 +187,9 @@ export class SharedHandler {
187
187
} else if ( registeredShared ) {
188
188
const asyncLoadProcess = async ( ) => {
189
189
const factory = await registeredShared . get ( ) ;
190
- shareInfoRes . lib = factory ;
191
- shareInfoRes . loaded = true ;
192
- addUseIn ( shareInfoRes ) ;
193
- const gShared = getRegisteredShare (
194
- this . shareScopeMap ,
195
- pkgName ,
196
- shareInfoRes ,
197
- this . hooks . lifecycle . resolveShare ,
198
- ) ;
199
- if ( gShared ) {
200
- gShared . lib = factory ;
201
- gShared . loaded = true ;
202
- addUseIn ( gShared ) ;
203
- }
190
+ addUseIn ( registeredShared ) ;
191
+ registeredShared . loaded = true ;
192
+ registeredShared . lib = factory ;
204
193
return factory as ( ) => T ;
205
194
} ;
206
195
const loading = asyncLoadProcess ( ) ;
@@ -218,27 +207,28 @@ export class SharedHandler {
218
207
return false ;
219
208
}
220
209
const asyncLoadProcess = async ( ) => {
221
- const factory = await shareInfoRes . get ( ) ;
222
- shareInfoRes . lib = factory ;
223
- shareInfoRes . loaded = true ;
224
- addUseIn ( shareInfoRes ) ;
210
+ const factory = await shareOptionsRes . get ( ) ;
211
+ shareOptionsRes . lib = factory ;
212
+ shareOptionsRes . loaded = true ;
213
+ addUseIn ( shareOptionsRes ) ;
225
214
const gShared = getRegisteredShare (
226
215
this . shareScopeMap ,
227
216
pkgName ,
228
- shareInfoRes ,
217
+ shareOptionsRes ,
229
218
this . hooks . lifecycle . resolveShare ,
230
219
) ;
231
220
if ( gShared ) {
232
221
gShared . lib = factory ;
233
222
gShared . loaded = true ;
223
+ gShared . from = shareOptionsRes . from ;
234
224
}
235
225
return factory as ( ) => T ;
236
226
} ;
237
227
const loading = asyncLoadProcess ( ) ;
238
228
this . setShared ( {
239
229
pkgName,
240
230
loaded : false ,
241
- shared : shareInfoRes ,
231
+ shared : shareOptionsRes ,
242
232
from : host . options . name ,
243
233
lib : null ,
244
234
loading,
@@ -367,21 +357,21 @@ export class SharedHandler {
367
357
} ,
368
358
) : ( ) => T | never {
369
359
const { host } = this ;
370
- const shareInfo = getTargetSharedOptions ( {
360
+ const shareOptions = getTargetSharedOptions ( {
371
361
pkgName,
372
362
extraOptions,
373
363
shareInfos : host . options . shared ,
374
364
} ) ;
375
365
376
- if ( shareInfo ?. scope ) {
377
- shareInfo . scope . forEach ( ( shareScope ) => {
378
- this . initializeSharing ( shareScope , { strategy : shareInfo . strategy } ) ;
366
+ if ( shareOptions ?. scope ) {
367
+ shareOptions . scope . forEach ( ( shareScope ) => {
368
+ this . initializeSharing ( shareScope , { strategy : shareOptions . strategy } ) ;
379
369
} ) ;
380
370
}
381
371
const registeredShared = getRegisteredShare (
382
372
this . shareScopeMap ,
383
373
pkgName ,
384
- shareInfo ,
374
+ shareOptions ,
385
375
this . hooks . lifecycle . resolveShare ,
386
376
) ;
387
377
@@ -398,7 +388,7 @@ export class SharedHandler {
398
388
if ( ! registeredShared . loaded ) {
399
389
registeredShared . loaded = true ;
400
390
if ( registeredShared . from === host . options . name ) {
401
- shareInfo . loaded = true ;
391
+ shareOptions . loaded = true ;
402
392
}
403
393
}
404
394
return registeredShared . lib as ( ) => T ;
@@ -419,15 +409,15 @@ export class SharedHandler {
419
409
}
420
410
}
421
411
422
- if ( shareInfo . lib ) {
423
- if ( ! shareInfo . loaded ) {
424
- shareInfo . loaded = true ;
412
+ if ( shareOptions . lib ) {
413
+ if ( ! shareOptions . loaded ) {
414
+ shareOptions . loaded = true ;
425
415
}
426
- return shareInfo . lib as ( ) => T ;
416
+ return shareOptions . lib as ( ) => T ;
427
417
}
428
418
429
- if ( shareInfo . get ) {
430
- const module = shareInfo . get ( ) ;
419
+ if ( shareOptions . get ) {
420
+ const module = shareOptions . get ( ) ;
431
421
432
422
if ( module instanceof Promise ) {
433
423
const errorCode =
@@ -440,16 +430,16 @@ export class SharedHandler {
440
430
) ;
441
431
}
442
432
443
- shareInfo . lib = module ;
433
+ shareOptions . lib = module ;
444
434
445
435
this . setShared ( {
446
436
pkgName,
447
437
loaded : true ,
448
438
from : host . options . name ,
449
- lib : shareInfo . lib ,
450
- shared : shareInfo ,
439
+ lib : shareOptions . lib ,
440
+ shared : shareOptions ,
451
441
} ) ;
452
- return shareInfo . lib as ( ) => T ;
442
+ return shareOptions . lib as ( ) => T ;
453
443
}
454
444
455
445
throw new Error (
@@ -522,6 +512,12 @@ export class SharedHandler {
522
512
if ( loading && ! registeredShared . loading ) {
523
513
registeredShared . loading = loading ;
524
514
}
515
+ if ( loaded && ! registeredShared . loaded ) {
516
+ registeredShared . loaded = loaded ;
517
+ }
518
+ if ( from && registeredShared . from !== from ) {
519
+ registeredShared . from = from ;
520
+ }
525
521
} ) ;
526
522
}
527
523
0 commit comments