@@ -2,45 +2,26 @@ import { getFMId, safeToString, assert } from '../utils';
2
2
import { getRemoteEntry } from '../utils/load' ;
3
3
import { FederationHost } from '../core' ;
4
4
import { Global } from '../global' ;
5
- import {
6
- RemoteEntryExports ,
7
- Options ,
8
- Remote ,
9
- ShareInfos ,
10
- RemoteInfo ,
11
- } from '../type' ;
12
- import { composeKeyWithSeparator } from '@module-federation/sdk' ;
5
+ import { RemoteEntryExports , RemoteInfo , InitScope } from '../type' ;
13
6
14
7
export type ModuleOptions = ConstructorParameters < typeof Module > [ 0 ] ;
15
8
16
- type HostInfo = Remote ;
17
-
18
9
class Module {
19
- hostInfo : HostInfo ;
20
10
remoteInfo : RemoteInfo ;
21
11
inited = false ;
22
- shared : ShareInfos = { } ;
23
12
remoteEntryExports ?: RemoteEntryExports ;
24
13
lib : RemoteEntryExports | undefined = undefined ;
25
- loaderHook : FederationHost [ 'loaderHook' ] ;
26
- // loading: Record<string, undefined | Promise<RemoteEntryExports | void>> = {};
14
+ host : FederationHost ;
27
15
28
16
constructor ( {
29
- hostInfo,
30
17
remoteInfo,
31
- shared,
32
- loaderHook,
18
+ host,
33
19
} : {
34
- hostInfo : HostInfo ;
35
20
remoteInfo : RemoteInfo ;
36
- shared : ShareInfos ;
37
- plugins : Options [ 'plugins' ] ;
38
- loaderHook : FederationHost [ 'loaderHook' ] ;
21
+ host : FederationHost ;
39
22
} ) {
40
- this . hostInfo = hostInfo ;
41
23
this . remoteInfo = remoteInfo ;
42
- this . shared = shared ;
43
- this . loaderHook = loaderHook ;
24
+ this . host = host ;
44
25
}
45
26
46
27
async getEntry ( ) : Promise < RemoteEntryExports > {
@@ -53,7 +34,7 @@ class Module {
53
34
remoteInfo : this . remoteInfo ,
54
35
remoteEntryExports : this . remoteEntryExports ,
55
36
createScriptHook : ( url : string ) => {
56
- const res = this . loaderHook . lifecycle . createScript . emit ( { url } ) ;
37
+ const res = this . host . loaderHook . lifecycle . createScript . emit ( { url } ) ;
57
38
if ( res instanceof HTMLScriptElement ) {
58
39
return res ;
59
40
}
@@ -84,29 +65,31 @@ class Module {
84
65
globalShareScope [ remoteShareScope ] = { } ;
85
66
}
86
67
const shareScope = globalShareScope [ remoteShareScope ] ;
68
+ const initScope : InitScope = [ ] ;
87
69
88
- // TODO: compat logic , it could be moved after providing startup hooks
89
70
const remoteEntryInitOptions = {
90
71
version : this . remoteInfo . version || '' ,
91
- // @ts -ignore it will be passed by startup hooks
92
- region : this . hostInfo . region ,
93
72
} ;
94
- remoteEntryExports . init ( shareScope , [ ] , remoteEntryInitOptions ) ;
95
- const federationInstance = Global . __FEDERATION__ . __INSTANCES__ . find (
96
- ( i ) =>
97
- i . options . id ===
98
- composeKeyWithSeparator (
99
- this . remoteInfo . name ,
100
- this . remoteInfo . buildVersion ,
101
- ) ,
102
- ) ;
103
- if ( federationInstance ) {
104
- federationInstance . initOptions ( {
105
- ...remoteEntryInitOptions ,
106
- remotes : [ ] ,
107
- name : this . remoteInfo . name ,
73
+
74
+ const initContainerOptions =
75
+ await this . host . hooks . lifecycle . beforeInitContainer . emit ( {
76
+ shareScope,
77
+ remoteEntryInitOptions,
78
+ initScope,
79
+ remoteInfo : this . remoteInfo ,
80
+ origin : this . host ,
108
81
} ) ;
109
- }
82
+
83
+ remoteEntryExports . init (
84
+ initContainerOptions . shareScope ,
85
+ initContainerOptions . initScope ,
86
+ initContainerOptions . remoteEntryInitOptions ,
87
+ ) ;
88
+
89
+ await this . host . hooks . lifecycle . initContainer . emit ( {
90
+ ...initContainerOptions ,
91
+ remoteEntryExports,
92
+ } ) ;
110
93
}
111
94
112
95
this . lib = remoteEntryExports ;
0 commit comments