@@ -7,11 +7,10 @@ export default function (): FederationRuntimePlugin {
7
7
url : string ;
8
8
attrs ?: Record < string , any > ;
9
9
} ) {
10
- // Updated type
11
- var url = args . url ;
12
- var attrs = args . attrs ;
10
+ const url = args . url ;
11
+ const attrs = args . attrs ;
13
12
if ( typeof window !== 'undefined' ) {
14
- var script = document . createElement ( 'script' ) ;
13
+ const script = document . createElement ( 'script' ) ;
15
14
script . src = url ;
16
15
script . async = true ;
17
16
delete attrs ?. [ 'crossorigin' ] ;
@@ -26,20 +25,21 @@ export default function (): FederationRuntimePlugin {
26
25
from : string ;
27
26
origin : any ;
28
27
} ) {
29
- var id = args . id ;
30
- var error = args . error ;
31
- var from = args . from ;
28
+ const id = args . id ;
29
+ const error = args . error ;
30
+ const from = args . from ;
31
+ //@ts -ignore
32
+ globalThis . moduleGraphDirty = true ;
32
33
console . error ( id , 'offline' ) ;
33
- var pg = function ( ) {
34
+ const pg = function ( ) {
34
35
console . error ( id , 'offline' , error ) ;
35
36
return null ;
36
37
} ;
37
38
38
39
( pg as any ) . getInitialProps = function ( ctx : any ) {
39
- // Type assertion to add getInitialProps
40
40
return { } ;
41
41
} ;
42
- var mod ;
42
+ let mod ;
43
43
if ( from === 'build' ) {
44
44
mod = function ( ) {
45
45
return {
@@ -70,15 +70,16 @@ export default function (): FederationRuntimePlugin {
70
70
return args ;
71
71
}
72
72
73
- var moduleCache = args . origin . moduleCache ;
74
- var name = args . origin . name ;
75
- var gs ;
73
+ const moduleCache = args . origin . moduleCache ;
74
+ const name = args . origin . name ;
75
+ let gs ;
76
76
try {
77
77
gs = new Function ( 'return globalThis' ) ( ) ;
78
78
} catch ( e ) {
79
79
gs = globalThis ; // fallback for browsers without 'unsafe-eval' CSP policy enabled
80
80
}
81
- var attachedRemote = gs [ name ] ;
81
+ //@ts -ignore
82
+ const attachedRemote = gs [ name ] ;
82
83
if ( attachedRemote ) {
83
84
moduleCache . set ( name , attachedRemote ) ;
84
85
}
@@ -89,10 +90,10 @@ export default function (): FederationRuntimePlugin {
89
90
return args ;
90
91
} ,
91
92
beforeRequest : function ( args : any ) {
92
- var options = args . options ;
93
- var id = args . id ;
94
- var remoteName = id . split ( '/' ) . shift ( ) ;
95
- var remote = options . remotes . find ( function ( remote : any ) {
93
+ const options = args . options ;
94
+ const id = args . id ;
95
+ const remoteName = id . split ( '/' ) . shift ( ) ;
96
+ const remote = options . remotes . find ( function ( remote : any ) {
96
97
return remote . name === remoteName ;
97
98
} ) ;
98
99
if ( ! remote ) return args ;
@@ -106,41 +107,41 @@ export default function (): FederationRuntimePlugin {
106
107
return args ;
107
108
} ,
108
109
onLoad : function ( args : any ) {
109
- var exposeModuleFactory = args . exposeModuleFactory ;
110
- var exposeModule = args . exposeModule ;
111
- var id = args . id ;
112
- var moduleOrFactory = exposeModuleFactory || exposeModule ;
113
- if ( ! moduleOrFactory ) return args ; // Ensure moduleOrFactory is defined
110
+ const exposeModuleFactory = args . exposeModuleFactory ;
111
+ const exposeModule = args . exposeModule ;
112
+ const id = args . id ;
113
+ const moduleOrFactory = exposeModuleFactory || exposeModule ;
114
+ if ( ! moduleOrFactory ) return args ;
114
115
115
116
if ( typeof window === 'undefined' ) {
116
- var exposedModuleExports : any ;
117
+ let exposedModuleExports : any ;
117
118
try {
118
119
exposedModuleExports = moduleOrFactory ( ) ;
119
120
} catch ( e ) {
120
121
exposedModuleExports = moduleOrFactory ;
121
122
}
122
123
123
- var handler : ProxyHandler < any > = {
124
+ const handler : ProxyHandler < any > = {
124
125
get : function ( target , prop , receiver ) {
125
- // Check if accessing a static property of the function itself
126
126
if (
127
127
target === exposedModuleExports &&
128
128
typeof exposedModuleExports [ prop ] === 'function'
129
129
) {
130
130
return function ( this : unknown ) {
131
131
globalThis . usedChunks . add ( id ) ;
132
+ //eslint-disable-next-line
132
133
return exposedModuleExports [ prop ] . apply ( this , arguments ) ;
133
134
} ;
134
135
}
135
136
136
- var originalMethod = target [ prop ] ;
137
+ const originalMethod = target [ prop ] ;
137
138
if ( typeof originalMethod === 'function' ) {
138
- var proxiedFunction = function ( this : unknown ) {
139
+ const proxiedFunction = function ( this : unknown ) {
139
140
globalThis . usedChunks . add ( id ) ;
141
+ //eslint-disable-next-line
140
142
return originalMethod . apply ( this , arguments ) ;
141
143
} ;
142
144
143
- // Copy all enumerable properties from the original method to the proxied function
144
145
Object . keys ( originalMethod ) . forEach ( function ( prop ) {
145
146
Object . defineProperty ( proxiedFunction , prop , {
146
147
value : originalMethod [ prop ] ,
@@ -158,12 +159,9 @@ export default function (): FederationRuntimePlugin {
158
159
} ;
159
160
160
161
if ( typeof exposedModuleExports === 'function' ) {
161
- // If the module export is a function, we create a proxy that can handle both its
162
- // call (as a function) and access to its properties (including static methods).
163
162
exposedModuleExports = new Proxy ( exposedModuleExports , handler ) ;
164
163
165
- // Proxy static properties specifically
166
- var staticProps = Object . getOwnPropertyNames ( exposedModuleExports ) ;
164
+ const staticProps = Object . getOwnPropertyNames ( exposedModuleExports ) ;
167
165
staticProps . forEach ( function ( prop ) {
168
166
if ( typeof exposedModuleExports [ prop ] === 'function' ) {
169
167
exposedModuleExports [ prop ] = new Proxy (
@@ -176,7 +174,6 @@ export default function (): FederationRuntimePlugin {
176
174
return exposedModuleExports ;
177
175
} ;
178
176
} else {
179
- // For objects, just wrap the exported object itself
180
177
exposedModuleExports = new Proxy ( exposedModuleExports , handler ) ;
181
178
}
182
179
@@ -194,23 +191,22 @@ export default function (): FederationRuntimePlugin {
194
191
) {
195
192
return args ;
196
193
}
197
- var shareScopeMap = args . shareScopeMap ;
198
- var scope = args . scope ;
199
- var pkgName = args . pkgName ;
200
- var version = args . version ;
201
- var GlobalFederation = args . GlobalFederation ;
202
- var host = GlobalFederation [ '__INSTANCES__' ] [ 0 ] ;
194
+ const shareScopeMap = args . shareScopeMap ;
195
+ const scope = args . scope ;
196
+ const pkgName = args . pkgName ;
197
+ const version = args . version ;
198
+ const GlobalFederation = args . GlobalFederation ;
199
+ const host = GlobalFederation [ '__INSTANCES__' ] [ 0 ] ;
203
200
if ( ! host ) {
204
201
return args ;
205
202
}
206
203
207
204
if ( ! host . options . shared [ pkgName ] ) {
208
205
return args ;
209
206
}
210
- //handle react host next remote, disable resolving when not next host
211
207
args . resolver = function ( ) {
212
208
shareScopeMap [ scope ] [ pkgName ] [ version ] =
213
- host . options . shared [ pkgName ] [ 0 ] ; // replace local share scope manually with desired module
209
+ host . options . shared [ pkgName ] [ 0 ] ;
214
210
return shareScopeMap [ scope ] [ pkgName ] [ version ] ;
215
211
} ;
216
212
return args ;
0 commit comments