@module-federation/runtime 0.0.0-next-20231229074949 → 0.0.0-next-20231230034830
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 +1 -1
- package/dist/helpers.esm.js +2 -2
- package/dist/index.cjs.js +156 -74
- package/dist/index.esm.js +155 -76
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +136 -115
- package/dist/share.esm.js +136 -115
- package/dist/src/core.d.ts +18 -5
- package/dist/src/global.d.ts +5 -4
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/module/index.d.ts +4 -2
- package/dist/src/type/config.d.ts +6 -2
- package/dist/src/utils/hooks/pluginSystem.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,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,73 +87,61 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
86
87
|
}
|
|
87
88
|
return target;
|
|
88
89
|
}
|
|
90
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
|
|
89
91
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
90
92
|
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
93
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
103
94
|
// The sandbox in the microfrontend does not replicate the value of 'configurable'.
|
|
104
95
|
// If there is no loading content on the global object, this section defines the loading object.
|
|
105
|
-
if (!
|
|
106
|
-
|
|
96
|
+
if (!Object.hasOwnProperty.call(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
97
|
+
Object.defineProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__', {
|
|
98
|
+
value: {},
|
|
99
|
+
configurable: false
|
|
100
|
+
});
|
|
107
101
|
}
|
|
108
102
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
103
|
+
//
|
|
104
|
+
if (nativeGlobal.__VMOK__) {
|
|
105
|
+
nativeGlobal.__FEDERATION__ = nativeGlobal.__VMOK__;
|
|
106
|
+
} else if (!nativeGlobal.__FEDERATION__) {
|
|
107
|
+
nativeGlobal.__FEDERATION__ = {
|
|
108
|
+
__GLOBAL_PLUGIN__: [],
|
|
109
|
+
__INSTANCES__: [],
|
|
110
|
+
moduleInfo: {},
|
|
111
|
+
__SHARE__: {},
|
|
112
|
+
__MANIFEST_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 ___PRELOADED_MAP__;
|
|
128
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
129
|
+
const Global = {
|
|
130
|
+
get __FEDERATION__ () {
|
|
131
|
+
const globalThisVal = new Function('return globalThis')();
|
|
132
|
+
return globalThisVal.__FEDERATION__;
|
|
127
133
|
}
|
|
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);
|
|
134
|
+
};
|
|
145
135
|
function resetFederationGlobalInfo() {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
136
|
+
nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
137
|
+
nativeGlobal.__FEDERATION__.__INSTANCES__ = [];
|
|
138
|
+
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
139
|
+
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
140
|
+
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
152
141
|
}
|
|
153
142
|
function getGlobalFederationInstance(name, version) {
|
|
154
143
|
const buildId = getBuilderId();
|
|
155
|
-
return
|
|
144
|
+
return Global.__FEDERATION__.__INSTANCES__.find((GMInstance)=>{
|
|
156
145
|
if (buildId && GMInstance.options.id === getBuilderId()) {
|
|
157
146
|
return true;
|
|
158
147
|
}
|
|
@@ -166,15 +155,15 @@ function getGlobalFederationInstance(name, version) {
|
|
|
166
155
|
});
|
|
167
156
|
}
|
|
168
157
|
function setGlobalFederationInstance(FederationInstance) {
|
|
169
|
-
|
|
158
|
+
Global.__FEDERATION__.__INSTANCES__.push(FederationInstance);
|
|
170
159
|
}
|
|
171
160
|
function getGlobalFederationConstructor() {
|
|
172
|
-
return
|
|
161
|
+
return Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
|
|
173
162
|
}
|
|
174
163
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
175
164
|
if (isDebugMode()) {
|
|
176
|
-
|
|
177
|
-
|
|
165
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
166
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.5';
|
|
178
167
|
}
|
|
179
168
|
}
|
|
180
169
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -189,7 +178,7 @@ function getInfoWithoutType(target, key, getModuleInfoHook) {
|
|
|
189
178
|
}
|
|
190
179
|
return res;
|
|
191
180
|
}
|
|
192
|
-
const getGlobalSnapshot = ()=>
|
|
181
|
+
const getGlobalSnapshot = ()=>Global.__FEDERATION__.moduleInfo;
|
|
193
182
|
const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHook)=>{
|
|
194
183
|
// Check if the remote is included in the hostSnapshot
|
|
195
184
|
const moduleKey = getFMId(moduleInfo);
|
|
@@ -207,25 +196,25 @@ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot, getModuleInfoHo
|
|
|
207
196
|
"version"
|
|
208
197
|
]);
|
|
209
198
|
const moduleKeyWithoutVersion = getFMId(resModuleInfo);
|
|
210
|
-
const getModuleInfoWithoutVersion = getInfoWithoutType(
|
|
199
|
+
const getModuleInfoWithoutVersion = getInfoWithoutType(Global.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion, getModuleInfoHook).value;
|
|
211
200
|
if ((getModuleInfoWithoutVersion == null ? void 0 : getModuleInfoWithoutVersion.version) === version) {
|
|
212
201
|
return getModuleInfoWithoutVersion;
|
|
213
202
|
}
|
|
214
203
|
}
|
|
215
204
|
return;
|
|
216
205
|
};
|
|
217
|
-
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo,
|
|
206
|
+
const getGlobalSnapshotInfoByModuleInfo = (moduleInfo, extraOptions)=>getTargetSnapshotInfoByModuleInfo(moduleInfo, Global.__FEDERATION__.moduleInfo, extraOptions == null ? void 0 : extraOptions.getModuleInfoHook);
|
|
218
207
|
const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo)=>{
|
|
219
208
|
const moduleKey = getFMId(remoteInfo);
|
|
220
|
-
|
|
221
|
-
return
|
|
209
|
+
Global.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
|
|
210
|
+
return Global.__FEDERATION__.moduleInfo;
|
|
222
211
|
};
|
|
223
212
|
const addGlobalSnapshot = (moduleInfos)=>{
|
|
224
|
-
|
|
213
|
+
Global.__FEDERATION__.moduleInfo = _extends$1({}, Global.__FEDERATION__.moduleInfo, moduleInfos);
|
|
225
214
|
return ()=>{
|
|
226
215
|
const keys = Object.keys(moduleInfos);
|
|
227
216
|
for (const key of keys){
|
|
228
|
-
delete
|
|
217
|
+
delete Global.__FEDERATION__.moduleInfo[key];
|
|
229
218
|
}
|
|
230
219
|
};
|
|
231
220
|
};
|
|
@@ -242,7 +231,7 @@ const getRemoteEntryExports = (name, globalName)=>{
|
|
|
242
231
|
// If a plugin is not registered, it is added to the global plugins.
|
|
243
232
|
// If a plugin is already registered, a warning message is logged.
|
|
244
233
|
const registerGlobalPlugins = (plugins)=>{
|
|
245
|
-
const { __GLOBAL_PLUGIN__ } =
|
|
234
|
+
const { __GLOBAL_PLUGIN__ } = Global.__FEDERATION__;
|
|
246
235
|
plugins.forEach((plugin)=>{
|
|
247
236
|
if (__GLOBAL_PLUGIN__.findIndex((p)=>p.name === plugin.name) === -1) {
|
|
248
237
|
__GLOBAL_PLUGIN__.push(plugin);
|
|
@@ -251,9 +240,9 @@ const registerGlobalPlugins = (plugins)=>{
|
|
|
251
240
|
}
|
|
252
241
|
});
|
|
253
242
|
};
|
|
254
|
-
const getGlobalHostPlugins = ()=>
|
|
255
|
-
const getPreloaded = (id)=>
|
|
256
|
-
const setPreloaded = (id)=>
|
|
243
|
+
const getGlobalHostPlugins = ()=>Global.__FEDERATION__.__GLOBAL_PLUGIN__;
|
|
244
|
+
const getPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.get(id);
|
|
245
|
+
const setPreloaded = (id)=>Global.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
|
|
257
246
|
|
|
258
247
|
const DEFAULT_SCOPE = 'default';
|
|
259
248
|
const DEFAULT_REMOTE_TYPE = 'global';
|
|
@@ -623,14 +612,16 @@ function formatShare(shareArgs, from) {
|
|
|
623
612
|
deps: [],
|
|
624
613
|
useIn: [],
|
|
625
614
|
from,
|
|
626
|
-
shareConfig: {
|
|
627
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
628
|
-
singleton: false,
|
|
629
|
-
eager: false
|
|
630
|
-
},
|
|
631
615
|
loading: null
|
|
632
616
|
}, shareArgs, {
|
|
617
|
+
shareConfig: _extends({
|
|
618
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
619
|
+
singleton: false,
|
|
620
|
+
eager: false,
|
|
621
|
+
strictVersion: false
|
|
622
|
+
}, shareArgs.shareConfig),
|
|
633
623
|
get,
|
|
624
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
634
625
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
635
626
|
'default'
|
|
636
627
|
],
|
|
@@ -647,15 +638,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
647
638
|
}, {});
|
|
648
639
|
}
|
|
649
640
|
function versionLt(a, b) {
|
|
650
|
-
|
|
641
|
+
const transformInvalidVersion = (version)=>{
|
|
642
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
643
|
+
if (isNumberVersion) {
|
|
644
|
+
const splitArr = version.split('.');
|
|
645
|
+
let validVersion = version;
|
|
646
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
647
|
+
validVersion += '.0';
|
|
648
|
+
}
|
|
649
|
+
return validVersion;
|
|
650
|
+
}
|
|
651
|
+
return version;
|
|
652
|
+
};
|
|
653
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
651
654
|
return true;
|
|
652
655
|
} else {
|
|
653
656
|
return false;
|
|
654
657
|
}
|
|
655
658
|
}
|
|
656
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
657
|
-
const
|
|
658
|
-
const versions = globalShares[scope][pkgName];
|
|
659
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
660
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
659
661
|
const callback = cb || function(prev, cur) {
|
|
660
662
|
return versionLt(prev, cur);
|
|
661
663
|
};
|
|
@@ -666,20 +668,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
666
668
|
if (callback(prev, cur)) {
|
|
667
669
|
return cur;
|
|
668
670
|
}
|
|
671
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
672
|
+
if (prev === '0') {
|
|
673
|
+
return cur;
|
|
674
|
+
}
|
|
669
675
|
return prev;
|
|
670
676
|
}, 0);
|
|
671
677
|
};
|
|
672
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
673
|
-
const
|
|
674
|
-
const versions = globalShares[scope][pkgName];
|
|
678
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
679
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
680
|
const callback = function(prev, cur) {
|
|
676
681
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
677
682
|
};
|
|
678
|
-
return findVersion(scope, pkgName, callback);
|
|
683
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
679
684
|
}
|
|
680
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
681
|
-
const
|
|
682
|
-
const versions = globalShares[scope][pkgName];
|
|
685
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
686
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
683
687
|
const callback = function(prev, cur) {
|
|
684
688
|
if (versions[cur].loaded) {
|
|
685
689
|
if (versions[prev].loaded) {
|
|
@@ -693,45 +697,62 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
693
697
|
}
|
|
694
698
|
return versionLt(prev, cur);
|
|
695
699
|
};
|
|
696
|
-
return findVersion(scope, pkgName, callback);
|
|
700
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
701
|
+
}
|
|
702
|
+
function getFindShareFunction(strategy) {
|
|
703
|
+
if (strategy === 'loaded-first') {
|
|
704
|
+
return findSingletonVersionOrderByLoaded;
|
|
705
|
+
}
|
|
706
|
+
return findSingletonVersionOrderByVersion;
|
|
697
707
|
}
|
|
698
708
|
// Details about shared resources
|
|
699
709
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
700
|
-
function
|
|
701
|
-
|
|
710
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
711
|
+
if (!localShareScopeMap) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
702
714
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
703
715
|
const scopes = Array.isArray(scope) ? scope : [
|
|
704
716
|
scope
|
|
705
717
|
];
|
|
706
718
|
for (const sc of scopes){
|
|
707
|
-
if (shareConfig &&
|
|
719
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
708
720
|
const { requiredVersion } = shareConfig;
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
return versionValue;
|
|
721
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
722
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
723
|
+
//@ts-ignore
|
|
724
|
+
const defaultResolver = ()=>{
|
|
725
|
+
if (shareConfig.singleton) {
|
|
726
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
727
|
+
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})`;
|
|
728
|
+
if (shareConfig.strictVersion) {
|
|
729
|
+
error(msg);
|
|
730
|
+
} else {
|
|
731
|
+
warn(msg);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
735
|
+
} else {
|
|
736
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
737
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
738
|
+
}
|
|
739
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
740
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
741
|
+
return versionValue;
|
|
742
|
+
}
|
|
732
743
|
}
|
|
733
744
|
}
|
|
734
|
-
}
|
|
745
|
+
};
|
|
746
|
+
const params = {
|
|
747
|
+
shareScopeMap: localShareScopeMap,
|
|
748
|
+
scope: sc,
|
|
749
|
+
pkgName,
|
|
750
|
+
version: maxOrSingletonVersion,
|
|
751
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
752
|
+
resolver: defaultResolver
|
|
753
|
+
};
|
|
754
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
755
|
+
return resolveShared.resolver();
|
|
735
756
|
}
|
|
736
757
|
}
|
|
737
758
|
}
|
|
@@ -739,4 +760,4 @@ function getGlobalShareScope() {
|
|
|
739
760
|
return Global.__FEDERATION__.__SHARE__;
|
|
740
761
|
}
|
|
741
762
|
|
|
742
|
-
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,
|
|
763
|
+
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, addUniqueItem as u, formatShareConfigs as v, warn as w, isBrowserEnv as x, getBuilderId 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, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap } 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;
|
|
@@ -52,6 +53,8 @@ export declare class FederationHost {
|
|
|
52
53
|
errorLoadRemote: AsyncHook<[{
|
|
53
54
|
id: string;
|
|
54
55
|
error: unknown;
|
|
56
|
+
from: 'build' | 'runtime';
|
|
57
|
+
origin: FederationHost;
|
|
55
58
|
}], void>;
|
|
56
59
|
beforeLoadShare: AsyncWaterfallHook<{
|
|
57
60
|
pkgName: string;
|
|
@@ -60,6 +63,14 @@ export declare class FederationHost {
|
|
|
60
63
|
origin: FederationHost;
|
|
61
64
|
}>;
|
|
62
65
|
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
|
|
66
|
+
resolveShare: SyncWaterfallHook<{
|
|
67
|
+
shareScopeMap: ShareScopeMap;
|
|
68
|
+
scope: string;
|
|
69
|
+
pkgName: string;
|
|
70
|
+
version: string;
|
|
71
|
+
GlobalFederation: Federation;
|
|
72
|
+
resolver: () => Shared | undefined;
|
|
73
|
+
}>;
|
|
63
74
|
beforePreloadRemote: AsyncHook<{
|
|
64
75
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
65
76
|
options: Options;
|
|
@@ -79,10 +90,12 @@ export declare class FederationHost {
|
|
|
79
90
|
origin: FederationHost;
|
|
80
91
|
}, false | void | Promise<false | void>>;
|
|
81
92
|
}>;
|
|
93
|
+
releaseNumber: string;
|
|
82
94
|
version: string;
|
|
83
95
|
name: string;
|
|
84
96
|
moduleCache: Map<string, Module>;
|
|
85
97
|
snapshotHandler: SnapshotHandler;
|
|
98
|
+
shareScopeMap: ShareScopeMap;
|
|
86
99
|
loaderHook: PluginSystem<{
|
|
87
100
|
getModuleInfo: SyncHook<[{
|
|
88
101
|
target: Record<string, any>;
|
|
@@ -96,16 +109,15 @@ export declare class FederationHost {
|
|
|
96
109
|
}], void | HTMLScriptElement>;
|
|
97
110
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
98
111
|
}>;
|
|
99
|
-
loadingShare: {
|
|
100
|
-
[key: string]: Promise<any>;
|
|
101
|
-
};
|
|
102
112
|
constructor(userOptions: UserOptions);
|
|
113
|
+
private _setGlobalShareScopeMap;
|
|
103
114
|
initOptions(userOptions: UserOptions): Options;
|
|
104
115
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
105
116
|
loadShareSync<T>(pkgName: string): () => T | never;
|
|
106
117
|
private _getRemoteModuleAndOptions;
|
|
107
118
|
loadRemote<T>(id: string, options?: {
|
|
108
119
|
loadFactory?: boolean;
|
|
120
|
+
from: 'build' | 'runtime';
|
|
109
121
|
}): Promise<T | null>;
|
|
110
122
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
111
123
|
/**
|
|
@@ -113,7 +125,8 @@ export declare class FederationHost {
|
|
|
113
125
|
* It accepts one argument, the name of the share scope.
|
|
114
126
|
* If the share scope does not exist, it creates one.
|
|
115
127
|
*/
|
|
116
|
-
initializeSharing(shareScopeName?: string):
|
|
128
|
+
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
|
|
129
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
|
|
117
130
|
private formatOptions;
|
|
118
131
|
private registerPlugins;
|
|
119
132
|
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,17 +9,18 @@ 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;
|
|
18
|
-
export declare const Global: typeof globalThis;
|
|
19
17
|
declare global {
|
|
20
18
|
var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
|
|
21
19
|
}
|
|
22
20
|
export declare const globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
|
|
21
|
+
export declare const Global: {
|
|
22
|
+
readonly __FEDERATION__: Federation;
|
|
23
|
+
};
|
|
23
24
|
export declare function resetFederationGlobalInfo(): void;
|
|
24
25
|
export declare function getGlobalFederationInstance(name: string, version: string | undefined): FederationHost | undefined;
|
|
25
26
|
export declare function setGlobalFederationInstance(FederationInstance: FederationHost): void;
|
package/dist/src/helpers.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { resetFederationGlobalInfo, getGlobalFederationInstance, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded } from './global';
|
|
3
|
-
import {
|
|
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 {
|
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']>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FederationHost } from '../core';
|
|
2
|
-
import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo } from '../type';
|
|
2
|
+
import { RemoteEntryExports, Options, Remote, ShareInfos, RemoteInfo, ShareScopeMap } from '../type';
|
|
3
3
|
export type ModuleOptions = ConstructorParameters<typeof Module>[0];
|
|
4
4
|
type HostInfo = Remote;
|
|
5
5
|
declare class Module {
|
|
@@ -10,12 +10,14 @@ declare class Module {
|
|
|
10
10
|
remoteEntryExports?: RemoteEntryExports;
|
|
11
11
|
lib: RemoteEntryExports | undefined;
|
|
12
12
|
loaderHook: FederationHost['loaderHook'];
|
|
13
|
-
|
|
13
|
+
shareScopeMap: ShareScopeMap;
|
|
14
|
+
constructor({ hostInfo, remoteInfo, shared, loaderHook, shareScopeMap, }: {
|
|
14
15
|
hostInfo: HostInfo;
|
|
15
16
|
remoteInfo: RemoteInfo;
|
|
16
17
|
shared: ShareInfos;
|
|
17
18
|
plugins: Options['plugins'];
|
|
18
19
|
loaderHook: FederationHost['loaderHook'];
|
|
20
|
+
shareScopeMap: ShareScopeMap;
|
|
19
21
|
});
|
|
20
22
|
getEntry(): Promise<RemoteEntryExports>;
|
|
21
23
|
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
|
};
|
|
@@ -89,6 +93,6 @@ export type RemoteEntryInitOptions = {
|
|
|
89
93
|
};
|
|
90
94
|
export type RemoteEntryExports = {
|
|
91
95
|
get: (id: string) => () => Promise<Module>;
|
|
92
|
-
init: (shareScope:
|
|
96
|
+
init: (shareScope: ShareScopeMap[string], initScope?: Array<Record<string, any>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
93
97
|
};
|
|
94
98
|
export {};
|
|
@@ -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
|
}
|
|
@@ -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-20231230034830",
|
|
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-20231230034830"
|
|
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
|