@module-federation/runtime 0.0.0-next-20240103032717 → 0.0.0-next-20240104022642
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/helpers.cjs.js +2 -1
- package/dist/helpers.esm.js +3 -2
- package/dist/index.cjs.js +170 -69
- package/dist/index.esm.js +169 -71
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +142 -107
- package/dist/share.esm.js +142 -107
- package/dist/src/core.d.ts +21 -8
- package/dist/src/global.d.ts +3 -6
- package/dist/src/helpers.d.ts +4 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/src/type/config.d.ts +6 -2
- 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,4 +1,5 @@
|
|
|
1
1
|
function getBuilderId() {
|
|
2
|
+
//@ts-ignore
|
|
2
3
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
3
4
|
}
|
|
4
5
|
function isDebugMode() {
|
|
@@ -86,65 +87,67 @@ 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
|
}
|
|
@@ -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.7';
|
|
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,62 @@ 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
714
|
// Details about shared resources
|
|
691
715
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
692
|
-
function
|
|
693
|
-
|
|
716
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
717
|
+
if (!localShareScopeMap) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
694
720
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
695
721
|
const scopes = Array.isArray(scope) ? scope : [
|
|
696
722
|
scope
|
|
697
723
|
];
|
|
698
724
|
for (const sc of scopes){
|
|
699
|
-
if (shareConfig &&
|
|
725
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
700
726
|
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
|
-
return versionValue;
|
|
727
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
728
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
729
|
+
//@ts-ignore
|
|
730
|
+
const defaultResolver = ()=>{
|
|
731
|
+
if (shareConfig.singleton) {
|
|
732
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
733
|
+
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})`;
|
|
734
|
+
if (shareConfig.strictVersion) {
|
|
735
|
+
error(msg);
|
|
736
|
+
} else {
|
|
737
|
+
warn(msg);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
741
|
+
} else {
|
|
742
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
743
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
744
|
+
}
|
|
745
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
746
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
747
|
+
return versionValue;
|
|
748
|
+
}
|
|
724
749
|
}
|
|
725
750
|
}
|
|
726
|
-
}
|
|
751
|
+
};
|
|
752
|
+
const params = {
|
|
753
|
+
shareScopeMap: localShareScopeMap,
|
|
754
|
+
scope: sc,
|
|
755
|
+
pkgName,
|
|
756
|
+
version: maxOrSingletonVersion,
|
|
757
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
758
|
+
resolver: defaultResolver
|
|
759
|
+
};
|
|
760
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
761
|
+
return resolveShared.resolver();
|
|
727
762
|
}
|
|
728
763
|
}
|
|
729
764
|
}
|
|
@@ -731,4 +766,4 @@ function getGlobalShareScope() {
|
|
|
731
766
|
return Global.__FEDERATION__.__SHARE__;
|
|
732
767
|
}
|
|
733
768
|
|
|
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,
|
|
769
|
+
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, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo,
|
|
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;
|
|
@@ -33,14 +34,14 @@ export declare class FederationHost {
|
|
|
33
34
|
}>;
|
|
34
35
|
afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
|
|
35
36
|
beforeInitContainer: AsyncWaterfallHook<{
|
|
36
|
-
shareScope:
|
|
37
|
+
shareScope: ShareScopeMap[string];
|
|
37
38
|
initScope: InitScope;
|
|
38
39
|
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
39
40
|
remoteInfo: RemoteInfo;
|
|
40
41
|
origin: FederationHost;
|
|
41
42
|
}>;
|
|
42
43
|
initContainer: AsyncWaterfallHook<{
|
|
43
|
-
shareScope:
|
|
44
|
+
shareScope: ShareScopeMap[string];
|
|
44
45
|
initScope: InitScope;
|
|
45
46
|
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
46
47
|
remoteInfo: RemoteInfo;
|
|
@@ -67,6 +68,8 @@ export declare class FederationHost {
|
|
|
67
68
|
errorLoadRemote: AsyncHook<[{
|
|
68
69
|
id: string;
|
|
69
70
|
error: unknown;
|
|
71
|
+
from: 'build' | 'runtime';
|
|
72
|
+
origin: FederationHost;
|
|
70
73
|
}], void>;
|
|
71
74
|
beforeLoadShare: AsyncWaterfallHook<{
|
|
72
75
|
pkgName: string;
|
|
@@ -75,6 +78,14 @@ export declare class FederationHost {
|
|
|
75
78
|
origin: FederationHost;
|
|
76
79
|
}>;
|
|
77
80
|
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
|
|
81
|
+
resolveShare: SyncWaterfallHook<{
|
|
82
|
+
shareScopeMap: ShareScopeMap;
|
|
83
|
+
scope: string;
|
|
84
|
+
pkgName: string;
|
|
85
|
+
version: string;
|
|
86
|
+
GlobalFederation: Federation;
|
|
87
|
+
resolver: () => Shared | undefined;
|
|
88
|
+
}>;
|
|
78
89
|
beforePreloadRemote: AsyncHook<{
|
|
79
90
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
80
91
|
options: Options;
|
|
@@ -94,10 +105,12 @@ export declare class FederationHost {
|
|
|
94
105
|
origin: FederationHost;
|
|
95
106
|
}, false | void | Promise<false | void>>;
|
|
96
107
|
}>;
|
|
108
|
+
releaseNumber: string;
|
|
97
109
|
version: string;
|
|
98
110
|
name: string;
|
|
99
111
|
moduleCache: Map<string, Module>;
|
|
100
112
|
snapshotHandler: SnapshotHandler;
|
|
113
|
+
shareScopeMap: ShareScopeMap;
|
|
101
114
|
loaderHook: PluginSystem<{
|
|
102
115
|
getModuleInfo: SyncHook<[{
|
|
103
116
|
target: Record<string, any>;
|
|
@@ -111,16 +124,15 @@ export declare class FederationHost {
|
|
|
111
124
|
}], void | HTMLScriptElement>;
|
|
112
125
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
113
126
|
}>;
|
|
114
|
-
loadingShare: {
|
|
115
|
-
[key: string]: Promise<any>;
|
|
116
|
-
};
|
|
117
127
|
constructor(userOptions: UserOptions);
|
|
128
|
+
private _setGlobalShareScopeMap;
|
|
118
129
|
initOptions(userOptions: UserOptions): Options;
|
|
119
130
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
120
|
-
loadShareSync<T>(pkgName: string): () => T | never;
|
|
131
|
+
loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
|
|
121
132
|
private _getRemoteModuleAndOptions;
|
|
122
133
|
loadRemote<T>(id: string, options?: {
|
|
123
134
|
loadFactory?: boolean;
|
|
135
|
+
from: 'build' | 'runtime';
|
|
124
136
|
}): Promise<T | null>;
|
|
125
137
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
126
138
|
/**
|
|
@@ -128,7 +140,8 @@ export declare class FederationHost {
|
|
|
128
140
|
* It accepts one argument, the name of the share scope.
|
|
129
141
|
* If the share scope does not exist, it creates one.
|
|
130
142
|
*/
|
|
131
|
-
initializeSharing(shareScopeName?: string):
|
|
143
|
+
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
|
|
144
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
|
|
132
145
|
private formatOptions;
|
|
133
146
|
private registerPlugins;
|
|
134
147
|
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
|
@@ -2,6 +2,7 @@ import { FederationHost } from './core';
|
|
|
2
2
|
import { UserOptions } 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';
|
|
6
7
|
export declare function init(options: UserOptions): FederationHost;
|
|
7
8
|
export declare function loadRemote(...args: Parameters<FederationHost['loadRemote']>): ReturnType<FederationHost['loadRemote']>;
|
|
@@ -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
|
};
|
|
@@ -90,6 +94,6 @@ export type RemoteEntryInitOptions = {
|
|
|
90
94
|
export type InitScope = Array<Record<string, never>>;
|
|
91
95
|
export type RemoteEntryExports = {
|
|
92
96
|
get: (id: string) => () => Promise<Module>;
|
|
93
|
-
init: (shareScope:
|
|
97
|
+
init: (shareScope: ShareScopeMap[string], initScope?: Array<Record<string, any>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
94
98
|
};
|
|
95
99
|
export {};
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Federation } from '../global';
|
|
2
|
+
import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap } from '../type';
|
|
3
|
+
import { SyncWaterfallHook } from './hooks';
|
|
2
4
|
export declare function formatShare(shareArgs: ShareArgs, from: string): Shared;
|
|
3
5
|
export declare function formatShareConfigs(shareArgs: {
|
|
4
6
|
[pkgName: string]: ShareArgs;
|
|
5
7
|
}, from: string): ShareInfos;
|
|
6
|
-
export declare function
|
|
7
|
-
|
|
8
|
+
export declare function getRegisteredShare(localShareScopeMap: ShareScopeMap, pkgName: string, shareInfo: ShareInfos[keyof ShareInfos], resolveShare: SyncWaterfallHook<{
|
|
9
|
+
shareScopeMap: ShareScopeMap;
|
|
10
|
+
scope: string;
|
|
11
|
+
pkgName: string;
|
|
12
|
+
version: string;
|
|
13
|
+
GlobalFederation: Federation;
|
|
14
|
+
resolver: () => Shared | undefined;
|
|
15
|
+
}>): Shared | void;
|
|
16
|
+
export declare function getGlobalShareScope(): GlobalShareScopeMap;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/types";
|
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-20240104022642",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"helpers": [
|
|
40
40
|
"./dist/helpers.cjs.d.ts"
|
|
41
41
|
],
|
|
42
|
-
"
|
|
43
|
-
"./dist/
|
|
42
|
+
"types": [
|
|
43
|
+
"./dist/types.cjs.d.ts"
|
|
44
44
|
]
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
48
|
+
"@module-federation/sdk": "0.0.0-next-20240104022642"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/dist/type.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/type/index";
|
|
File without changes
|
|
File without changes
|