@module-federation/runtime 0.0.6 → 0.0.8
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/README.md +513 -124
- package/dist/helpers.cjs.js +2 -1
- package/dist/helpers.esm.js +3 -2
- package/dist/index.cjs.js +208 -104
- package/dist/index.esm.js +207 -106
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +147 -111
- package/dist/share.esm.js +147 -111
- package/dist/src/core.d.ts +39 -7
- package/dist/src/global.d.ts +3 -6
- package/dist/src/helpers.d.ts +4 -3
- package/dist/src/index.d.ts +3 -1
- package/dist/src/module/index.d.ts +4 -10
- package/dist/src/type/config.d.ts +8 -2
- package/dist/src/type/plugin.d.ts +1 -1
- package/dist/src/utils/plugin.d.ts +1 -1
- package/dist/src/utils/share.d.ts +12 -3
- package/dist/types.cjs.d.ts +1 -0
- package/package.json +4 -4
- package/dist/type.cjs.d.ts +0 -1
- /package/dist/{type.cjs.js → types.cjs.js} +0 -0
- /package/dist/{type.esm.js → types.esm.js} +0 -0
package/dist/share.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function getBuilderId() {
|
|
2
|
+
//@ts-ignore
|
|
2
3
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
3
4
|
}
|
|
4
5
|
function isDebugMode() {
|
|
5
|
-
return Boolean(
|
|
6
|
+
return Boolean("");
|
|
6
7
|
}
|
|
7
8
|
function isBrowserEnv() {
|
|
8
9
|
return typeof window !== 'undefined';
|
|
@@ -86,69 +87,71 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
86
87
|
}
|
|
87
88
|
return target;
|
|
88
89
|
}
|
|
89
|
-
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5, _nativeGlobal___FEDERATION__6;
|
|
90
90
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
91
91
|
const nativeGlobal = new Function('return this')();
|
|
92
|
+
const Global = nativeGlobal;
|
|
93
|
+
function definePropertyGlobalVal(target, key, val) {
|
|
94
|
+
Object.defineProperty(target, key, {
|
|
95
|
+
value: val,
|
|
96
|
+
configurable: false,
|
|
97
|
+
writable: true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function includeOwnProperty(target, key) {
|
|
101
|
+
return Object.hasOwnProperty.call(target, key);
|
|
102
|
+
}
|
|
92
103
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
93
104
|
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
94
105
|
// If there is no loading content on the global object, this section defines the loading object.
|
|
95
|
-
if (!
|
|
96
|
-
|
|
97
|
-
value: {},
|
|
98
|
-
configurable: false
|
|
99
|
-
});
|
|
106
|
+
if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
107
|
+
definePropertyGlobalVal(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});
|
|
100
108
|
}
|
|
101
109
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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__;
|
|
110
|
+
function setGlobalDefaultVal(target) {
|
|
111
|
+
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
|
|
112
|
+
if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
|
|
113
|
+
definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
|
|
135
114
|
}
|
|
136
|
-
|
|
115
|
+
if (!includeOwnProperty(target, '__FEDERATION__')) {
|
|
116
|
+
definePropertyGlobalVal(target, '__FEDERATION__', {
|
|
117
|
+
__GLOBAL_PLUGIN__: [],
|
|
118
|
+
__INSTANCES__: [],
|
|
119
|
+
moduleInfo: {},
|
|
120
|
+
__SHARE__: {},
|
|
121
|
+
__MANIFEST_LOADING__: {},
|
|
122
|
+
__PRELOADED_MAP__: new Map()
|
|
123
|
+
});
|
|
124
|
+
definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
|
|
125
|
+
}
|
|
126
|
+
var ___GLOBAL_PLUGIN__;
|
|
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 ___PRELOADED_MAP__;
|
|
137
|
+
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
138
|
+
}
|
|
139
|
+
setGlobalDefaultVal(globalThis);
|
|
140
|
+
setGlobalDefaultVal(nativeGlobal);
|
|
137
141
|
function resetFederationGlobalInfo() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
142
|
+
globalThis.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
143
|
+
globalThis.__FEDERATION__.__INSTANCES__ = [];
|
|
144
|
+
globalThis.__FEDERATION__.moduleInfo = {};
|
|
145
|
+
globalThis.__FEDERATION__.__SHARE__ = {};
|
|
146
|
+
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
144
147
|
}
|
|
145
148
|
function getGlobalFederationInstance(name, version) {
|
|
146
149
|
const buildId = getBuilderId();
|
|
147
|
-
return
|
|
150
|
+
return globalThis.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
|
|
148
151
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
149
152
|
return true;
|
|
150
153
|
}
|
|
151
|
-
if (GMInstance.options.name === name && !version) {
|
|
154
|
+
if (GMInstance.options.name === name && !GMInstance.options.version && !version) {
|
|
152
155
|
return true;
|
|
153
156
|
}
|
|
154
157
|
if (GMInstance.options.name === name && version && GMInstance.options.version === version) {
|
|
@@ -158,15 +161,15 @@ function getGlobalFederationInstance(name, version) {
|
|
|
158
161
|
});
|
|
159
162
|
}
|
|
160
163
|
function setGlobalFederationInstance(FederationInstance) {
|
|
161
|
-
|
|
164
|
+
globalThis.__FEDERATION__.__INSTANCES__.push(FederationInstance);
|
|
162
165
|
}
|
|
163
166
|
function getGlobalFederationConstructor() {
|
|
164
|
-
return
|
|
167
|
+
return globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
165
168
|
}
|
|
166
169
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
167
170
|
if (isDebugMode()) {
|
|
168
|
-
|
|
169
|
-
|
|
171
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
172
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.8";
|
|
170
173
|
}
|
|
171
174
|
}
|
|
172
175
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -181,7 +184,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
181
184
|
}
|
|
182
185
|
return res;
|
|
183
186
|
}
|
|
184
|
-
const getGlobalSnapshot = ()=>
|
|
187
|
+
const getGlobalSnapshot = ()=>nativeGlobal.__FEDERATION__.moduleInfo;
|
|
185
188
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
186
189
|
// Check if the remote is included in the hostSnapshot
|
|
187
190
|
const moduleKey = getFMId(moduleInfo);
|
|
@@ -199,25 +202,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
|
|
|
199
202
|
"version"
|
|
200
203
|
]);
|
|
201
204
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
202
|
-
const getModuleInfoWithoutVersion = getInfoWithoutType(
|
|
205
|
+
const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
|
|
203
206
|
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
|
|
204
207
|
return getModuleInfoWithoutVersion;
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
return;
|
|
208
211
|
};
|
|
209
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo,
|
|
212
|
+
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
|
|
210
213
|
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
211
214
|
const moduleKey = getFMId(remoteInfo);
|
|
212
|
-
|
|
213
|
-
return
|
|
215
|
+
nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
216
|
+
return nativeGlobal.__FEDERATION__.moduleInfo;
|
|
214
217
|
};
|
|
215
218
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
216
|
-
|
|
219
|
+
nativeGlobal.__FEDERATION__.moduleInfo = _extends$1({}, nativeGlobal.__FEDERATION__.moduleInfo, moduleInfos);
|
|
217
220
|
return ()=>{
|
|
218
221
|
const keys = Object.keys(moduleInfos);
|
|
219
222
|
for (const key of keys){
|
|
220
|
-
delete
|
|
223
|
+
delete nativeGlobal.__FEDERATION__.moduleInfo[key];
|
|
221
224
|
}
|
|
222
225
|
};
|
|
223
226
|
};
|
|
@@ -234,7 +237,7 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
234
237
|
// If a plugin is not registered, it is added to the global plugins.
|
|
235
238
|
// If a plugin is already registered, a warning message is logged.
|
|
236
239
|
const registerGlobalPlugins = (plugins)=>{
|
|
237
|
-
const { __GLOBAL_PLUGIN__ } =
|
|
240
|
+
const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
|
|
238
241
|
plugins.forEach((plugin)=>{
|
|
239
242
|
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
240
243
|
__GLOBAL_PLUGIN__.push(plugin);
|
|
@@ -243,9 +246,9 @@ const registerGlobalPlugins = (plugins)=>{
|
|
|
243
246
|
}
|
|
244
247
|
});
|
|
245
248
|
};
|
|
246
|
-
const getGlobalHostPlugins = ()=>
|
|
247
|
-
const getPreloaded = (id)=>
|
|
248
|
-
const setPreloaded = (id)=>
|
|
249
|
+
const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
250
|
+
const getPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
251
|
+
const setPreloaded = (id)=>globalThis.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
249
252
|
|
|
250
253
|
const DEFAULT_SCOPE = 'default';
|
|
251
254
|
const DEFAULT_REMOTE_TYPE = 'global';
|
|
@@ -615,14 +618,16 @@ function formatShare(shareArgs, from) {
|
|
|
615
618
|
deps: [],
|
|
616
619
|
useIn: [],
|
|
617
620
|
from,
|
|
618
|
-
shareConfig: {
|
|
619
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
620
|
-
singleton: false,
|
|
621
|
-
eager: false
|
|
622
|
-
},
|
|
623
621
|
loading: null
|
|
624
622
|
}, shareArgs, {
|
|
623
|
+
shareConfig: _extends({
|
|
624
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
625
|
+
singleton: false,
|
|
626
|
+
eager: false,
|
|
627
|
+
strictVersion: false
|
|
628
|
+
}, shareArgs.shareConfig),
|
|
625
629
|
get,
|
|
630
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
626
631
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
627
632
|
'default'
|
|
628
633
|
],
|
|
@@ -639,15 +644,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
639
644
|
}, {});
|
|
640
645
|
}
|
|
641
646
|
function versionLt(a, b) {
|
|
642
|
-
|
|
647
|
+
const transformInvalidVersion = (version)=>{
|
|
648
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
649
|
+
if (isNumberVersion) {
|
|
650
|
+
const splitArr = version.split('.');
|
|
651
|
+
let validVersion = version;
|
|
652
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
653
|
+
validVersion += '.0';
|
|
654
|
+
}
|
|
655
|
+
return validVersion;
|
|
656
|
+
}
|
|
657
|
+
return version;
|
|
658
|
+
};
|
|
659
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
643
660
|
return true;
|
|
644
661
|
} else {
|
|
645
662
|
return false;
|
|
646
663
|
}
|
|
647
664
|
}
|
|
648
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
649
|
-
const
|
|
650
|
-
const versions = globalShares[scope][pkgName];
|
|
665
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
666
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
651
667
|
const callback = cb || function(prev, cur) {
|
|
652
668
|
return versionLt(prev, cur);
|
|
653
669
|
};
|
|
@@ -658,20 +674,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
658
674
|
if (callback(prev, cur)) {
|
|
659
675
|
return cur;
|
|
660
676
|
}
|
|
677
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
678
|
+
if (prev === '0') {
|
|
679
|
+
return cur;
|
|
680
|
+
}
|
|
661
681
|
return prev;
|
|
662
682
|
}, 0);
|
|
663
683
|
};
|
|
664
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
665
|
-
const
|
|
666
|
-
const versions = globalShares[scope][pkgName];
|
|
684
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
685
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
667
686
|
const callback = function(prev, cur) {
|
|
668
687
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
669
688
|
};
|
|
670
|
-
return findVersion(scope, pkgName, callback);
|
|
689
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
671
690
|
}
|
|
672
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
673
|
-
const
|
|
674
|
-
const versions = globalShares[scope][pkgName];
|
|
691
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
692
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
693
|
const callback = function(prev, cur) {
|
|
676
694
|
if (versions[cur].loaded) {
|
|
677
695
|
if (versions[prev].loaded) {
|
|
@@ -685,45 +703,63 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
685
703
|
}
|
|
686
704
|
return versionLt(prev, cur);
|
|
687
705
|
};
|
|
688
|
-
return findVersion(scope, pkgName, callback);
|
|
706
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
707
|
+
}
|
|
708
|
+
function getFindShareFunction(strategy) {
|
|
709
|
+
if (strategy === 'loaded-first') {
|
|
710
|
+
return findSingletonVersionOrderByLoaded;
|
|
711
|
+
}
|
|
712
|
+
return findSingletonVersionOrderByVersion;
|
|
689
713
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
714
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
715
|
+
if (!localShareScopeMap) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
694
718
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
695
719
|
const scopes = Array.isArray(scope) ? scope : [
|
|
696
720
|
scope
|
|
697
721
|
];
|
|
698
722
|
for (const sc of scopes){
|
|
699
|
-
if (shareConfig &&
|
|
723
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
700
724
|
const { requiredVersion } = shareConfig;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
725
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
726
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
727
|
+
//@ts-ignore
|
|
728
|
+
const defaultResolver = ()=>{
|
|
729
|
+
if (shareConfig.singleton) {
|
|
730
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
731
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
732
|
+
if (shareConfig.strictVersion) {
|
|
733
|
+
error(msg);
|
|
734
|
+
} else {
|
|
735
|
+
warn(msg);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
739
|
+
} else {
|
|
740
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
741
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
742
|
+
}
|
|
743
|
+
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
744
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
745
|
+
}
|
|
746
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
747
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
748
|
+
return versionValue;
|
|
749
|
+
}
|
|
724
750
|
}
|
|
725
751
|
}
|
|
726
|
-
}
|
|
752
|
+
};
|
|
753
|
+
const params = {
|
|
754
|
+
shareScopeMap: localShareScopeMap,
|
|
755
|
+
scope: sc,
|
|
756
|
+
pkgName,
|
|
757
|
+
version: maxOrSingletonVersion,
|
|
758
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
759
|
+
resolver: defaultResolver
|
|
760
|
+
};
|
|
761
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
762
|
+
return resolveShared.resolver();
|
|
727
763
|
}
|
|
728
764
|
}
|
|
729
765
|
}
|
|
@@ -731,4 +767,4 @@ function getGlobalShareScope() {
|
|
|
731
767
|
return Global.__FEDERATION__.__SHARE__;
|
|
732
768
|
}
|
|
733
769
|
|
|
734
|
-
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k,
|
|
770
|
+
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, getGlobalShareScope as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getBuilderId as x, addUniqueItem as y, setGlobalFederationConstructor as z };
|
package/dist/src/core.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
|
-
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, Shared, ShareInfos, UserOptions, RemoteInfo } from './type';
|
|
2
|
+
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions } from './type';
|
|
3
3
|
import { Module, ModuleOptions } from './module';
|
|
4
4
|
import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
|
|
5
|
+
import { Federation } from './global';
|
|
5
6
|
import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
|
|
6
7
|
interface LoadRemoteMatch {
|
|
7
8
|
id: string;
|
|
@@ -32,6 +33,26 @@ export declare class FederationHost {
|
|
|
32
33
|
origin: FederationHost;
|
|
33
34
|
}>;
|
|
34
35
|
afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
|
|
36
|
+
beforeInitContainer: AsyncWaterfallHook<{
|
|
37
|
+
shareScope: ShareScopeMap[string];
|
|
38
|
+
initScope: InitScope;
|
|
39
|
+
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
40
|
+
remoteInfo: RemoteInfo;
|
|
41
|
+
origin: FederationHost;
|
|
42
|
+
}>;
|
|
43
|
+
initContainerShareScopeMap: AsyncWaterfallHook<{
|
|
44
|
+
shareScope: ShareScopeMap[string];
|
|
45
|
+
options: Options;
|
|
46
|
+
origin: FederationHost;
|
|
47
|
+
}>;
|
|
48
|
+
initContainer: AsyncWaterfallHook<{
|
|
49
|
+
shareScope: ShareScopeMap[string];
|
|
50
|
+
initScope: InitScope;
|
|
51
|
+
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
52
|
+
remoteInfo: RemoteInfo;
|
|
53
|
+
remoteEntryExports: RemoteEntryExports;
|
|
54
|
+
origin: FederationHost;
|
|
55
|
+
}>;
|
|
35
56
|
onLoad: AsyncHook<[{
|
|
36
57
|
id: string;
|
|
37
58
|
expose: string;
|
|
@@ -52,7 +73,9 @@ export declare class FederationHost {
|
|
|
52
73
|
errorLoadRemote: AsyncHook<[{
|
|
53
74
|
id: string;
|
|
54
75
|
error: unknown;
|
|
55
|
-
|
|
76
|
+
from: 'build' | 'runtime';
|
|
77
|
+
origin: FederationHost;
|
|
78
|
+
}], unknown>;
|
|
56
79
|
beforeLoadShare: AsyncWaterfallHook<{
|
|
57
80
|
pkgName: string;
|
|
58
81
|
shareInfo?: Shared | undefined;
|
|
@@ -60,6 +83,14 @@ export declare class FederationHost {
|
|
|
60
83
|
origin: FederationHost;
|
|
61
84
|
}>;
|
|
62
85
|
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
|
|
86
|
+
resolveShare: SyncWaterfallHook<{
|
|
87
|
+
shareScopeMap: ShareScopeMap;
|
|
88
|
+
scope: string;
|
|
89
|
+
pkgName: string;
|
|
90
|
+
version: string;
|
|
91
|
+
GlobalFederation: Federation;
|
|
92
|
+
resolver: () => Shared | undefined;
|
|
93
|
+
}>;
|
|
63
94
|
beforePreloadRemote: AsyncHook<{
|
|
64
95
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
65
96
|
options: Options;
|
|
@@ -83,6 +114,7 @@ export declare class FederationHost {
|
|
|
83
114
|
name: string;
|
|
84
115
|
moduleCache: Map<string, Module>;
|
|
85
116
|
snapshotHandler: SnapshotHandler;
|
|
117
|
+
shareScopeMap: ShareScopeMap;
|
|
86
118
|
loaderHook: PluginSystem<{
|
|
87
119
|
getModuleInfo: SyncHook<[{
|
|
88
120
|
target: Record<string, any>;
|
|
@@ -96,16 +128,15 @@ export declare class FederationHost {
|
|
|
96
128
|
}], void | HTMLScriptElement>;
|
|
97
129
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
98
130
|
}>;
|
|
99
|
-
loadingShare: {
|
|
100
|
-
[key: string]: Promise<any>;
|
|
101
|
-
};
|
|
102
131
|
constructor(userOptions: UserOptions);
|
|
132
|
+
private _setGlobalShareScopeMap;
|
|
103
133
|
initOptions(userOptions: UserOptions): Options;
|
|
104
134
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
105
|
-
loadShareSync<T>(pkgName: string): () => T | never;
|
|
135
|
+
loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
|
|
106
136
|
private _getRemoteModuleAndOptions;
|
|
107
137
|
loadRemote<T>(id: string, options?: {
|
|
108
138
|
loadFactory?: boolean;
|
|
139
|
+
from: 'build' | 'runtime';
|
|
109
140
|
}): Promise<T | null>;
|
|
110
141
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
111
142
|
/**
|
|
@@ -113,7 +144,8 @@ export declare class FederationHost {
|
|
|
113
144
|
* It accepts one argument, the name of the share scope.
|
|
114
145
|
* If the share scope does not exist, it creates one.
|
|
115
146
|
*/
|
|
116
|
-
initializeSharing(shareScopeName?: string):
|
|
147
|
+
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
|
|
148
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
|
|
117
149
|
private formatOptions;
|
|
118
150
|
private registerPlugins;
|
|
119
151
|
private setShared;
|
package/dist/src/global.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FederationHost } from './core';
|
|
3
|
-
import { RemoteEntryExports,
|
|
3
|
+
import { RemoteEntryExports, GlobalShareScopeMap, Remote, Optional } from './type';
|
|
4
4
|
import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
|
|
5
5
|
import { FederationRuntimePlugin } from './type/plugin';
|
|
6
6
|
export interface Federation {
|
|
@@ -9,19 +9,16 @@ export interface Federation {
|
|
|
9
9
|
moduleInfo: GlobalModuleInfo;
|
|
10
10
|
__DEBUG_CONSTRUCTOR__?: typeof FederationHost;
|
|
11
11
|
__INSTANCES__: Array<FederationHost>;
|
|
12
|
-
__SHARE__:
|
|
12
|
+
__SHARE__: GlobalShareScopeMap;
|
|
13
13
|
__MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
|
|
14
|
-
__SHARE_SCOPE_LOADING__: Record<string, boolean | Promise<boolean>>;
|
|
15
14
|
__PRELOADED_MAP__: Map<string, boolean>;
|
|
16
15
|
}
|
|
17
16
|
export declare const nativeGlobal: typeof global;
|
|
17
|
+
export declare const Global: typeof globalThis;
|
|
18
18
|
declare global {
|
|
19
19
|
var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
|
|
20
20
|
}
|
|
21
21
|
export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
|
|
22
|
-
export declare const Global: {
|
|
23
|
-
readonly __FEDERATION__: Federation;
|
|
24
|
-
};
|
|
25
22
|
export declare function resetFederationGlobalInfo(): void;
|
|
26
23
|
export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
|
|
27
24
|
export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
|
package/dist/src/helpers.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded } from './global';
|
|
3
|
-
import {
|
|
2
|
+
import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global';
|
|
3
|
+
import { getRegisteredShare, getGlobalShareScope } from './utils/share';
|
|
4
4
|
interface IShareUtils {
|
|
5
|
-
|
|
5
|
+
getRegisteredShare: typeof getRegisteredShare;
|
|
6
6
|
getGlobalShareScope: typeof getGlobalShareScope;
|
|
7
7
|
}
|
|
8
8
|
interface IGlobalUtils {
|
|
9
|
+
Global: typeof Global;
|
|
9
10
|
nativeGlobal: typeof global;
|
|
10
11
|
resetFederationGlobalInfo: typeof resetFederationGlobalInfo;
|
|
11
12
|
getGlobalFederationInstance: typeof getGlobalFederationInstance;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { FederationHost } from './core';
|
|
2
|
-
import { UserOptions } from './type';
|
|
2
|
+
import { UserOptions, FederationRuntimePlugin } from './type';
|
|
3
3
|
export { FederationHost } from './core';
|
|
4
4
|
export { registerGlobalPlugins } from './global';
|
|
5
|
+
export { loadScript } from '@module-federation/sdk';
|
|
5
6
|
export type { Federation } from './global';
|
|
7
|
+
export type { FederationRuntimePlugin };
|
|
6
8
|
export declare function init(options: UserOptions): FederationHost;
|
|
7
9
|
export declare function loadRemote(...args: Parameters<FederationHost['loadRemote']>): ReturnType<FederationHost['loadRemote']>;
|
|
8
10
|
export declare function loadShare(...args: Parameters<FederationHost['loadShare']>): ReturnType<FederationHost['loadShare']>;
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
import { FederationHost } from '../core';
|
|
2
|
-
import { RemoteEntryExports,
|
|
2
|
+
import { RemoteEntryExports, RemoteInfo } from '../type';
|
|
3
3
|
export type ModuleOptions = ConstructorParameters<typeof Module>[0];
|
|
4
|
-
type HostInfo = Remote;
|
|
5
4
|
declare class Module {
|
|
6
|
-
hostInfo: HostInfo;
|
|
7
5
|
remoteInfo: RemoteInfo;
|
|
8
6
|
inited: boolean;
|
|
9
|
-
shared: ShareInfos;
|
|
10
7
|
remoteEntryExports?: RemoteEntryExports;
|
|
11
8
|
lib: RemoteEntryExports | undefined;
|
|
12
|
-
|
|
13
|
-
constructor({
|
|
14
|
-
hostInfo: HostInfo;
|
|
9
|
+
host: FederationHost;
|
|
10
|
+
constructor({ remoteInfo, host, }: {
|
|
15
11
|
remoteInfo: RemoteInfo;
|
|
16
|
-
|
|
17
|
-
plugins: Options['plugins'];
|
|
18
|
-
loaderHook: FederationHost['loaderHook'];
|
|
12
|
+
host: FederationHost;
|
|
19
13
|
});
|
|
20
14
|
getEntry(): Promise<RemoteEntryExports>;
|
|
21
15
|
get(expose: string, options?: {
|
|
@@ -29,6 +29,7 @@ export interface SharedConfig {
|
|
|
29
29
|
singleton?: boolean;
|
|
30
30
|
requiredVersion: false | string;
|
|
31
31
|
eager?: boolean;
|
|
32
|
+
strictVersion?: boolean;
|
|
32
33
|
}
|
|
33
34
|
type SharedBaseArgs = {
|
|
34
35
|
version: string;
|
|
@@ -57,13 +58,16 @@ export type Shared = {
|
|
|
57
58
|
eager?: boolean;
|
|
58
59
|
strategy: 'version-first' | 'loaded-first';
|
|
59
60
|
};
|
|
60
|
-
export type
|
|
61
|
+
export type ShareScopeMap = {
|
|
61
62
|
[scope: string]: {
|
|
62
63
|
[pkgName: string]: {
|
|
63
64
|
[sharedVersion: string]: Shared;
|
|
64
65
|
};
|
|
65
66
|
};
|
|
66
67
|
};
|
|
68
|
+
export type GlobalShareScopeMap = {
|
|
69
|
+
[instanceName: string]: ShareScopeMap;
|
|
70
|
+
};
|
|
67
71
|
export type ShareInfos = {
|
|
68
72
|
[pkgName: string]: Shared;
|
|
69
73
|
};
|
|
@@ -86,9 +90,11 @@ export type LoadModuleOptions = {
|
|
|
86
90
|
};
|
|
87
91
|
export type RemoteEntryInitOptions = {
|
|
88
92
|
version: string;
|
|
93
|
+
hostId: string;
|
|
89
94
|
};
|
|
95
|
+
export type InitScope = Array<Record<string, never>>;
|
|
90
96
|
export type RemoteEntryExports = {
|
|
91
97
|
get: (id: string) => () => Promise<Module>;
|
|
92
|
-
init: (shareScope:
|
|
98
|
+
init: (shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
93
99
|
};
|
|
94
100
|
export {};
|
|
@@ -9,7 +9,7 @@ type SnapshotLifeCycle = SnapshotHandler['hooks']['lifecycle'];
|
|
|
9
9
|
type SnapshotLifeCycleCyclePartial = Partial<{
|
|
10
10
|
[k in keyof SnapshotLifeCycle]: Parameters<SnapshotLifeCycle[k]['on']>[0];
|
|
11
11
|
}>;
|
|
12
|
-
type ModuleLifeCycle = Module['loaderHook']['lifecycle'];
|
|
12
|
+
type ModuleLifeCycle = Module['host']['loaderHook']['lifecycle'];
|
|
13
13
|
type ModuleLifeCycleCyclePartial = Partial<{
|
|
14
14
|
[k in keyof ModuleLifeCycle]: Parameters<ModuleLifeCycle[k]['on']>[0];
|
|
15
15
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FederationHost } from '../core';
|
|
2
2
|
import { UserOptions } from '../type';
|
|
3
3
|
import { Module } from '../module';
|
|
4
|
-
export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['loaderHook']>): void;
|
|
4
|
+
export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | Module['host']['loaderHook']>): void;
|