@module-federation/runtime 0.0.0-next-20231229091919 → 0.0.0-next-20240102023857
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +4 -4
- package/dist/index.esm.js +4 -4
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +62 -68
- package/dist/share.esm.js +62 -68
- package/dist/src/global.d.ts +3 -1
- package/dist/src/utils/hooks/pluginSystem.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -82,7 +82,7 @@ function registerPlugins(plugins, hookInstances) {
|
|
|
82
82
|
if (plugins && plugins.length > 0) {
|
|
83
83
|
plugins.forEach((plugin)=>{
|
|
84
84
|
hookInstances.forEach((hookInstance)=>{
|
|
85
|
-
hookInstance.
|
|
85
|
+
hookInstance.applyPlugin(plugin);
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
}
|
|
@@ -400,7 +400,7 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
400
400
|
}
|
|
401
401
|
|
|
402
402
|
class PluginSystem {
|
|
403
|
-
|
|
403
|
+
applyPlugin(plugin) {
|
|
404
404
|
share.assert(share.isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
405
405
|
// The plugin's name is mandatory and must be unique
|
|
406
406
|
const pluginName = plugin.name;
|
|
@@ -433,7 +433,7 @@ class PluginSystem {
|
|
|
433
433
|
});
|
|
434
434
|
Object.keys(registerPlugins).forEach((pluginName)=>{
|
|
435
435
|
share.assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
|
|
436
|
-
this.
|
|
436
|
+
this.applyPlugin(registerPlugins[pluginName]);
|
|
437
437
|
});
|
|
438
438
|
}
|
|
439
439
|
constructor(lifecycle){
|
|
@@ -1538,7 +1538,7 @@ class FederationHost {
|
|
|
1538
1538
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1539
1539
|
afterPreloadRemote: new AsyncHook()
|
|
1540
1540
|
});
|
|
1541
|
-
this.version = '0.0.
|
|
1541
|
+
this.version = '0.0.5';
|
|
1542
1542
|
this.moduleCache = new Map();
|
|
1543
1543
|
this.loaderHook = new PluginSystem({
|
|
1544
1544
|
// FIXME: may not be suitable
|
package/dist/index.esm.js
CHANGED
|
@@ -79,7 +79,7 @@ function registerPlugins(plugins, hookInstances) {
|
|
|
79
79
|
if (plugins && plugins.length > 0) {
|
|
80
80
|
plugins.forEach((plugin)=>{
|
|
81
81
|
hookInstances.forEach((hookInstance)=>{
|
|
82
|
-
hookInstance.
|
|
82
|
+
hookInstance.applyPlugin(plugin);
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
}
|
|
@@ -397,7 +397,7 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
class PluginSystem {
|
|
400
|
-
|
|
400
|
+
applyPlugin(plugin) {
|
|
401
401
|
assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
402
402
|
// The plugin's name is mandatory and must be unique
|
|
403
403
|
const pluginName = plugin.name;
|
|
@@ -430,7 +430,7 @@ class PluginSystem {
|
|
|
430
430
|
});
|
|
431
431
|
Object.keys(registerPlugins).forEach((pluginName)=>{
|
|
432
432
|
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
|
|
433
|
-
this.
|
|
433
|
+
this.applyPlugin(registerPlugins[pluginName]);
|
|
434
434
|
});
|
|
435
435
|
}
|
|
436
436
|
constructor(lifecycle){
|
|
@@ -1535,7 +1535,7 @@ class FederationHost {
|
|
|
1535
1535
|
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1536
1536
|
afterPreloadRemote: new AsyncHook()
|
|
1537
1537
|
});
|
|
1538
|
-
this.version = '0.0.
|
|
1538
|
+
this.version = '0.0.5';
|
|
1539
1539
|
this.moduleCache = new Map();
|
|
1540
1540
|
this.loaderHook = new PluginSystem({
|
|
1541
1541
|
// FIXME: may not be suitable
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -88,71 +88,65 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
88
88
|
}
|
|
89
89
|
return target;
|
|
90
90
|
}
|
|
91
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
91
92
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
92
93
|
const nativeGlobal = new Function('return this')();
|
|
93
|
-
const Global = nativeGlobal;
|
|
94
|
-
function definePropertyGlobalVal(target, key, val) {
|
|
95
|
-
Object.defineProperty(target, key, {
|
|
96
|
-
value: val,
|
|
97
|
-
configurable: false,
|
|
98
|
-
writable: true
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
function includeOwnProperty(target, key) {
|
|
102
|
-
return Object.hasOwnProperty.call(target, key);
|
|
103
|
-
}
|
|
104
94
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
105
95
|
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
106
96
|
// If there is no loading content on the global object, this section defines the loading object.
|
|
107
|
-
if (!
|
|
108
|
-
|
|
97
|
+
if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
98
|
+
Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
|
|
99
|
+
value: {},
|
|
100
|
+
configurable: false
|
|
101
|
+
});
|
|
109
102
|
}
|
|
110
103
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
104
|
+
//
|
|
105
|
+
if (nativeGlobal.__VMOK__) {
|
|
106
|
+
nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
|
|
107
|
+
} else if (!nativeGlobal.__FEDERATION__) {
|
|
108
|
+
nativeGlobal.__FEDERATION__ = {
|
|
109
|
+
__GLOBAL_PLUGIN__: [],
|
|
110
|
+
__INSTANCES__: [],
|
|
111
|
+
moduleInfo: {},
|
|
112
|
+
__SHARE__: {},
|
|
113
|
+
__MANIFEST_LOADING__: {},
|
|
114
|
+
__SHARE_SCOPE_LOADING__: {},
|
|
115
|
+
__PRELOADED_MAP__: new Map()
|
|
116
|
+
};
|
|
117
|
+
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
|
|
118
|
+
}
|
|
119
|
+
var ___GLOBAL_PLUGIN__;
|
|
120
|
+
(___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
121
|
+
var ___INSTANCES__;
|
|
122
|
+
(___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = [];
|
|
123
|
+
var _moduleInfo;
|
|
124
|
+
(_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {};
|
|
125
|
+
var ___SHARE__;
|
|
126
|
+
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
|
|
127
|
+
var ___MANIFEST_LOADING__;
|
|
128
|
+
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
129
|
+
var ___SHARE_SCOPE_LOADING__;
|
|
130
|
+
(___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
131
|
+
var ___PRELOADED_MAP__;
|
|
132
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
|
|
133
|
+
const Global = {
|
|
134
|
+
get __FEDERATION__ () {
|
|
135
|
+
const globalThisVal = new Function('return globalThis')();
|
|
136
|
+
return globalThisVal.__FEDERATION__;
|
|
127
137
|
}
|
|
128
|
-
|
|
129
|
-
(___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
130
|
-
var ___INSTANCES__;
|
|
131
|
-
(___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = [];
|
|
132
|
-
var _moduleInfo;
|
|
133
|
-
(_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {};
|
|
134
|
-
var ___SHARE__;
|
|
135
|
-
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
136
|
-
var ___MANIFEST_LOADING__;
|
|
137
|
-
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
138
|
-
var ___SHARE_SCOPE_LOADING__;
|
|
139
|
-
(___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
140
|
-
var ___PRELOADED_MAP__;
|
|
141
|
-
(___PRELOADED_MAP__ = (_target___FEDERATION__6 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__6.__PRELOADED_MAP__ = new Map();
|
|
142
|
-
}
|
|
143
|
-
setGlobalDefaultVal(globalThis);
|
|
144
|
-
setGlobalDefaultVal(nativeGlobal);
|
|
138
|
+
};
|
|
145
139
|
function resetFederationGlobalInfo() {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
141
|
+
nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
|
|
142
|
+
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
143
|
+
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
144
|
+
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
145
|
+
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
152
146
|
}
|
|
153
147
|
function getGlobalFederationInstance(name, version) {
|
|
154
148
|
const buildId = getBuilderId();
|
|
155
|
-
return
|
|
149
|
+
return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
|
|
156
150
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
157
151
|
return true;
|
|
158
152
|
}
|
|
@@ -166,15 +160,15 @@ function getGlobalFederationInstance(name, version) {
|
|
|
166
160
|
});
|
|
167
161
|
}
|
|
168
162
|
function setGlobalFederationInstance(FederationInstance) {
|
|
169
|
-
|
|
163
|
+
Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
|
|
170
164
|
}
|
|
171
165
|
function getGlobalFederationConstructor() {
|
|
172
|
-
return
|
|
166
|
+
return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
173
167
|
}
|
|
174
168
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
175
169
|
if (isDebugMode()) {
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
171
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.5';
|
|
178
172
|
}
|
|
179
173
|
}
|
|
180
174
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -189,7 +183,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
189
183
|
}
|
|
190
184
|
return res;
|
|
191
185
|
}
|
|
192
|
-
const getGlobalSnapshot = ()=>
|
|
186
|
+
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
|
|
193
187
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
194
188
|
// Check if the remote is included in the hostSnapshot
|
|
195
189
|
const moduleKey = getFMId(moduleInfo);
|
|
@@ -207,25 +201,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
|
|
|
207
201
|
"version"
|
|
208
202
|
]);
|
|
209
203
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
210
|
-
const getModuleInfoWithoutVersion = getInfoWithoutType(
|
|
204
|
+
const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
|
|
211
205
|
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
|
|
212
206
|
return getModuleInfoWithoutVersion;
|
|
213
207
|
}
|
|
214
208
|
}
|
|
215
209
|
return;
|
|
216
210
|
};
|
|
217
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo,
|
|
211
|
+
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
|
|
218
212
|
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
219
213
|
const moduleKey = getFMId(remoteInfo);
|
|
220
|
-
|
|
221
|
-
return
|
|
214
|
+
Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
215
|
+
return Global.__FEDERATION__.moduleInfo;
|
|
222
216
|
};
|
|
223
217
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
224
|
-
|
|
218
|
+
Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
|
|
225
219
|
return ()=>{
|
|
226
220
|
const keys = Object.keys(moduleInfos);
|
|
227
221
|
for (const key of keys){
|
|
228
|
-
delete
|
|
222
|
+
delete Global.__FEDERATION__.moduleInfo[key];
|
|
229
223
|
}
|
|
230
224
|
};
|
|
231
225
|
};
|
|
@@ -242,7 +236,7 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
242
236
|
// If a plugin is not registered, it is added to the global plugins.
|
|
243
237
|
// If a plugin is already registered, a warning message is logged.
|
|
244
238
|
const registerGlobalPlugins = (plugins)=>{
|
|
245
|
-
const { __GLOBAL_PLUGIN__ } =
|
|
239
|
+
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
|
|
246
240
|
plugins.forEach((plugin)=>{
|
|
247
241
|
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
248
242
|
__GLOBAL_PLUGIN__.push(plugin);
|
|
@@ -251,9 +245,9 @@ const registerGlobalPlugins = (plugins)=>{
|
|
|
251
245
|
}
|
|
252
246
|
});
|
|
253
247
|
};
|
|
254
|
-
const getGlobalHostPlugins = ()=>
|
|
255
|
-
const getPreloaded = (id)=>
|
|
256
|
-
const setPreloaded = (id)=>
|
|
248
|
+
const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
249
|
+
const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
250
|
+
const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
257
251
|
|
|
258
252
|
const DEFAULT_SCOPE = 'default';
|
|
259
253
|
const DEFAULT_REMOTE_TYPE = 'global';
|
package/dist/share.esm.js
CHANGED
|
@@ -86,71 +86,65 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
86
86
|
}
|
|
87
87
|
return target;
|
|
88
88
|
}
|
|
89
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
89
90
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
90
91
|
const nativeGlobal = new Function('return this')();
|
|
91
|
-
const Global = nativeGlobal;
|
|
92
|
-
function definePropertyGlobalVal(target, key, val) {
|
|
93
|
-
Object.defineProperty(target, key, {
|
|
94
|
-
value: val,
|
|
95
|
-
configurable: false,
|
|
96
|
-
writable: true
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function includeOwnProperty(target, key) {
|
|
100
|
-
return Object.hasOwnProperty.call(target, key);
|
|
101
|
-
}
|
|
102
92
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
103
93
|
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
104
94
|
// If there is no loading content on the global object, this section defines the loading object.
|
|
105
|
-
if (!
|
|
106
|
-
|
|
95
|
+
if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
96
|
+
Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
|
|
97
|
+
value: {},
|
|
98
|
+
configurable: false
|
|
99
|
+
});
|
|
107
100
|
}
|
|
108
101
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
102
|
+
//
|
|
103
|
+
if (nativeGlobal.__VMOK__) {
|
|
104
|
+
nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
|
|
105
|
+
} else if (!nativeGlobal.__FEDERATION__) {
|
|
106
|
+
nativeGlobal.__FEDERATION__ = {
|
|
107
|
+
__GLOBAL_PLUGIN__: [],
|
|
108
|
+
__INSTANCES__: [],
|
|
109
|
+
moduleInfo: {},
|
|
110
|
+
__SHARE__: {},
|
|
111
|
+
__MANIFEST_LOADING__: {},
|
|
112
|
+
__SHARE_SCOPE_LOADING__: {},
|
|
113
|
+
__PRELOADED_MAP__: new Map()
|
|
114
|
+
};
|
|
115
|
+
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
|
|
116
|
+
}
|
|
117
|
+
var ___GLOBAL_PLUGIN__;
|
|
118
|
+
(___GLOBAL_PLUGIN__ = (_nativeGlobal___FEDERATION__ = nativeGlobal.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _nativeGlobal___FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
119
|
+
var ___INSTANCES__;
|
|
120
|
+
(___INSTANCES__ = (_nativeGlobal___FEDERATION__1 = nativeGlobal.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _nativeGlobal___FEDERATION__1.__INSTANCES__ = [];
|
|
121
|
+
var _moduleInfo;
|
|
122
|
+
(_moduleInfo = (_nativeGlobal___FEDERATION__2 = nativeGlobal.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _nativeGlobal___FEDERATION__2.moduleInfo = {};
|
|
123
|
+
var ___SHARE__;
|
|
124
|
+
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
|
|
125
|
+
var ___MANIFEST_LOADING__;
|
|
126
|
+
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
127
|
+
var ___SHARE_SCOPE_LOADING__;
|
|
128
|
+
(___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
129
|
+
var ___PRELOADED_MAP__;
|
|
130
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__6 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__6.__PRELOADED_MAP__ = new Map();
|
|
131
|
+
const Global = {
|
|
132
|
+
get __FEDERATION__ () {
|
|
133
|
+
const globalThisVal = new Function('return globalThis')();
|
|
134
|
+
return globalThisVal.__FEDERATION__;
|
|
125
135
|
}
|
|
126
|
-
|
|
127
|
-
(___GLOBAL_PLUGIN__ = (_target___FEDERATION__ = target.__FEDERATION__).__GLOBAL_PLUGIN__) != null ? ___GLOBAL_PLUGIN__ : _target___FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
128
|
-
var ___INSTANCES__;
|
|
129
|
-
(___INSTANCES__ = (_target___FEDERATION__1 = target.__FEDERATION__).__INSTANCES__) != null ? ___INSTANCES__ : _target___FEDERATION__1.__INSTANCES__ = [];
|
|
130
|
-
var _moduleInfo;
|
|
131
|
-
(_moduleInfo = (_target___FEDERATION__2 = target.__FEDERATION__).moduleInfo) != null ? _moduleInfo : _target___FEDERATION__2.moduleInfo = {};
|
|
132
|
-
var ___SHARE__;
|
|
133
|
-
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
134
|
-
var ___MANIFEST_LOADING__;
|
|
135
|
-
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
136
|
-
var ___SHARE_SCOPE_LOADING__;
|
|
137
|
-
(___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
138
|
-
var ___PRELOADED_MAP__;
|
|
139
|
-
(___PRELOADED_MAP__ = (_target___FEDERATION__6 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__6.__PRELOADED_MAP__ = new Map();
|
|
140
|
-
}
|
|
141
|
-
setGlobalDefaultVal(globalThis);
|
|
142
|
-
setGlobalDefaultVal(nativeGlobal);
|
|
136
|
+
};
|
|
143
137
|
function resetFederationGlobalInfo() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
138
|
+
nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
139
|
+
nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
|
|
140
|
+
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
141
|
+
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
142
|
+
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
143
|
+
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
150
144
|
}
|
|
151
145
|
function getGlobalFederationInstance(name, version) {
|
|
152
146
|
const buildId = getBuilderId();
|
|
153
|
-
return
|
|
147
|
+
return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
|
|
154
148
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
155
149
|
return true;
|
|
156
150
|
}
|
|
@@ -164,15 +158,15 @@ function getGlobalFederationInstance(name, version) {
|
|
|
164
158
|
});
|
|
165
159
|
}
|
|
166
160
|
function setGlobalFederationInstance(FederationInstance) {
|
|
167
|
-
|
|
161
|
+
Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
|
|
168
162
|
}
|
|
169
163
|
function getGlobalFederationConstructor() {
|
|
170
|
-
return
|
|
164
|
+
return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
171
165
|
}
|
|
172
166
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
173
167
|
if (isDebugMode()) {
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
169
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.5';
|
|
176
170
|
}
|
|
177
171
|
}
|
|
178
172
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -187,7 +181,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
187
181
|
}
|
|
188
182
|
return res;
|
|
189
183
|
}
|
|
190
|
-
const getGlobalSnapshot = ()=>
|
|
184
|
+
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
|
|
191
185
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
192
186
|
// Check if the remote is included in the hostSnapshot
|
|
193
187
|
const moduleKey = getFMId(moduleInfo);
|
|
@@ -205,25 +199,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
|
|
|
205
199
|
"version"
|
|
206
200
|
]);
|
|
207
201
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
208
|
-
const getModuleInfoWithoutVersion = getInfoWithoutType(
|
|
202
|
+
const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
|
|
209
203
|
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
|
|
210
204
|
return getModuleInfoWithoutVersion;
|
|
211
205
|
}
|
|
212
206
|
}
|
|
213
207
|
return;
|
|
214
208
|
};
|
|
215
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo,
|
|
209
|
+
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
|
|
216
210
|
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
217
211
|
const moduleKey = getFMId(remoteInfo);
|
|
218
|
-
|
|
219
|
-
return
|
|
212
|
+
Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
213
|
+
return Global.__FEDERATION__.moduleInfo;
|
|
220
214
|
};
|
|
221
215
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
222
|
-
|
|
216
|
+
Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
|
|
223
217
|
return ()=>{
|
|
224
218
|
const keys = Object.keys(moduleInfos);
|
|
225
219
|
for (const key of keys){
|
|
226
|
-
delete
|
|
220
|
+
delete Global.__FEDERATION__.moduleInfo[key];
|
|
227
221
|
}
|
|
228
222
|
};
|
|
229
223
|
};
|
|
@@ -240,7 +234,7 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
240
234
|
// If a plugin is not registered, it is added to the global plugins.
|
|
241
235
|
// If a plugin is already registered, a warning message is logged.
|
|
242
236
|
const registerGlobalPlugins = (plugins)=>{
|
|
243
|
-
const { __GLOBAL_PLUGIN__ } =
|
|
237
|
+
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
|
|
244
238
|
plugins.forEach((plugin)=>{
|
|
245
239
|
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
246
240
|
__GLOBAL_PLUGIN__.push(plugin);
|
|
@@ -249,9 +243,9 @@ const registerGlobalPlugins = (plugins)=>{
|
|
|
249
243
|
}
|
|
250
244
|
});
|
|
251
245
|
};
|
|
252
|
-
const getGlobalHostPlugins = ()=>
|
|
253
|
-
const getPreloaded = (id)=>
|
|
254
|
-
const setPreloaded = (id)=>
|
|
246
|
+
const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
247
|
+
const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
248
|
+
const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
255
249
|
|
|
256
250
|
const DEFAULT_SCOPE = 'default';
|
|
257
251
|
const DEFAULT_REMOTE_TYPE = 'global';
|
package/dist/src/global.d.ts
CHANGED
|
@@ -15,11 +15,13 @@ export interface Federation {
|
|
|
15
15
|
__PRELOADED_MAP__: Map<string, boolean>;
|
|
16
16
|
}
|
|
17
17
|
export declare const nativeGlobal: typeof global;
|
|
18
|
-
export declare const Global: typeof globalThis;
|
|
19
18
|
declare global {
|
|
20
19
|
var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
|
|
21
20
|
}
|
|
22
21
|
export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
|
|
22
|
+
export declare const Global: {
|
|
23
|
+
readonly __FEDERATION__: Federation;
|
|
24
|
+
};
|
|
23
25
|
export declare function resetFederationGlobalInfo(): void;
|
|
24
26
|
export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
|
|
25
27
|
export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
|
|
@@ -9,7 +9,7 @@ export declare class PluginSystem<T extends Record<string, any>> {
|
|
|
9
9
|
lifecycleKeys: Array<keyof T>;
|
|
10
10
|
registerPlugins: Record<string, Plugin<T>>;
|
|
11
11
|
constructor(lifecycle: T);
|
|
12
|
-
|
|
12
|
+
applyPlugin(plugin: Plugin<T>): void;
|
|
13
13
|
removePlugin(pluginName: string): void;
|
|
14
14
|
inherit<T extends PluginSystem<any>>({ lifecycle, registerPlugins, }: T): void;
|
|
15
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240102023857",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
48
|
+
"@module-federation/sdk": "0.0.0-next-20240102023857"
|
|
49
49
|
}
|
|
50
50
|
}
|