@module-federation/runtime 0.0.0-next-20231220085130 → 0.0.0-next-20231221061836
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 +144 -68
- package/dist/index.esm.js +143 -70
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +70 -47
- package/dist/share.esm.js +70 -47
- package/dist/src/core.d.ts +15 -5
- package/dist/src/global.d.ts +2 -3
- 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 +5 -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.cjs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
function getBuilderId() {
|
|
4
|
+
//@ts-ignore
|
|
4
5
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
5
6
|
}
|
|
6
7
|
function isDebugMode() {
|
|
@@ -88,7 +89,7 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
88
89
|
}
|
|
89
90
|
return target;
|
|
90
91
|
}
|
|
91
|
-
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5
|
|
92
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
|
|
92
93
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
93
94
|
const nativeGlobal = new Function('return this')();
|
|
94
95
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
@@ -111,7 +112,6 @@ if (nativeGlobal.__VMOK__) {
|
|
|
111
112
|
moduleInfo: {},
|
|
112
113
|
__SHARE__: {},
|
|
113
114
|
__MANIFEST_LOADING__: {},
|
|
114
|
-
__SHARE_SCOPE_LOADING__: {},
|
|
115
115
|
__PRELOADED_MAP__: new Map()
|
|
116
116
|
};
|
|
117
117
|
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
|
|
@@ -126,10 +126,8 @@ var ___SHARE__;
|
|
|
126
126
|
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
|
|
127
127
|
var ___MANIFEST_LOADING__;
|
|
128
128
|
(___MANIFEST_LOADING__ = (_nativeGlobal___FEDERATION__4 = nativeGlobal.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _nativeGlobal___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
129
|
-
var ___SHARE_SCOPE_LOADING__;
|
|
130
|
-
(___SHARE_SCOPE_LOADING__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _nativeGlobal___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
131
129
|
var ___PRELOADED_MAP__;
|
|
132
|
-
(___PRELOADED_MAP__ = (
|
|
130
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
133
131
|
const Global = {
|
|
134
132
|
get __FEDERATION__ () {
|
|
135
133
|
const globalThisVal = new Function('return globalThis')();
|
|
@@ -142,7 +140,6 @@ function resetFederationGlobalInfo() {
|
|
|
142
140
|
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
143
141
|
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
144
142
|
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
145
|
-
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
146
143
|
}
|
|
147
144
|
function getGlobalFederationInstance(name, version) {
|
|
148
145
|
const buildId = getBuilderId();
|
|
@@ -168,7 +165,7 @@ function getGlobalFederationConstructor() {
|
|
|
168
165
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
169
166
|
if (isDebugMode()) {
|
|
170
167
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
171
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.
|
|
168
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4';
|
|
172
169
|
}
|
|
173
170
|
}
|
|
174
171
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -625,6 +622,7 @@ function formatShare(shareArgs, from) {
|
|
|
625
622
|
loading: null
|
|
626
623
|
}, shareArgs, {
|
|
627
624
|
get,
|
|
625
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
628
626
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
629
627
|
'default'
|
|
630
628
|
],
|
|
@@ -641,15 +639,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
641
639
|
}, {});
|
|
642
640
|
}
|
|
643
641
|
function versionLt(a, b) {
|
|
644
|
-
|
|
642
|
+
const transformInvalidVersion = (version)=>{
|
|
643
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
644
|
+
if (isNumberVersion) {
|
|
645
|
+
const splitArr = version.split('.');
|
|
646
|
+
let validVersion = version;
|
|
647
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
648
|
+
validVersion += '.0';
|
|
649
|
+
}
|
|
650
|
+
return validVersion;
|
|
651
|
+
}
|
|
652
|
+
return version;
|
|
653
|
+
};
|
|
654
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
645
655
|
return true;
|
|
646
656
|
} else {
|
|
647
657
|
return false;
|
|
648
658
|
}
|
|
649
659
|
}
|
|
650
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
651
|
-
const
|
|
652
|
-
const versions = globalShares[scope][pkgName];
|
|
660
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
661
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
653
662
|
const callback = cb || function(prev, cur) {
|
|
654
663
|
return versionLt(prev, cur);
|
|
655
664
|
};
|
|
@@ -660,20 +669,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
660
669
|
if (callback(prev, cur)) {
|
|
661
670
|
return cur;
|
|
662
671
|
}
|
|
672
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
673
|
+
if (prev === '0') {
|
|
674
|
+
return cur;
|
|
675
|
+
}
|
|
663
676
|
return prev;
|
|
664
677
|
}, 0);
|
|
665
678
|
};
|
|
666
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
667
|
-
const
|
|
668
|
-
const versions = globalShares[scope][pkgName];
|
|
679
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
680
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
669
681
|
const callback = function(prev, cur) {
|
|
670
682
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
671
683
|
};
|
|
672
|
-
return findVersion(scope, pkgName, callback);
|
|
684
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
673
685
|
}
|
|
674
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
675
|
-
const
|
|
676
|
-
const versions = globalShares[scope][pkgName];
|
|
686
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
687
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
677
688
|
const callback = function(prev, cur) {
|
|
678
689
|
if (versions[cur].loaded) {
|
|
679
690
|
if (versions[prev].loaded) {
|
|
@@ -687,45 +698,57 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
687
698
|
}
|
|
688
699
|
return versionLt(prev, cur);
|
|
689
700
|
};
|
|
690
|
-
return findVersion(scope, pkgName, callback);
|
|
701
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
702
|
+
}
|
|
703
|
+
function getFindShareFunction(strategy) {
|
|
704
|
+
if (strategy === 'loaded-first') {
|
|
705
|
+
return findSingletonVersionOrderByLoaded;
|
|
706
|
+
}
|
|
707
|
+
return findSingletonVersionOrderByVersion;
|
|
691
708
|
}
|
|
692
709
|
// Details about shared resources
|
|
693
710
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
694
|
-
function
|
|
695
|
-
|
|
711
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
712
|
+
if (!localShareScopeMap) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
696
715
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
697
716
|
const scopes = Array.isArray(scope) ? scope : [
|
|
698
717
|
scope
|
|
699
718
|
];
|
|
700
719
|
for (const sc of scopes){
|
|
701
|
-
if (shareConfig &&
|
|
720
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
702
721
|
const { requiredVersion } = shareConfig;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
// eslint-disable-next-line max-depth
|
|
722
|
-
for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
|
|
723
|
-
// eslint-disable-next-line max-depth
|
|
724
|
-
if (satisfy(versionKey, requiredVersion)) {
|
|
725
|
-
return versionValue;
|
|
722
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
723
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
724
|
+
//@ts-ignore
|
|
725
|
+
const defaultResolver = ()=>{
|
|
726
|
+
if (shareConfig.singleton) {
|
|
727
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
728
|
+
warn(`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})`);
|
|
729
|
+
}
|
|
730
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
731
|
+
} else {
|
|
732
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
733
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
734
|
+
}
|
|
735
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
736
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
737
|
+
return versionValue;
|
|
738
|
+
}
|
|
726
739
|
}
|
|
727
740
|
}
|
|
728
|
-
}
|
|
741
|
+
};
|
|
742
|
+
const params = {
|
|
743
|
+
shareScopeMap: localShareScopeMap,
|
|
744
|
+
scope: sc,
|
|
745
|
+
pkgName,
|
|
746
|
+
version: maxOrSingletonVersion,
|
|
747
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
748
|
+
resolver: defaultResolver
|
|
749
|
+
};
|
|
750
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
751
|
+
return resolveShared.resolver();
|
|
729
752
|
}
|
|
730
753
|
}
|
|
731
754
|
}
|
|
@@ -746,12 +769,12 @@ exports.getFMId = getFMId;
|
|
|
746
769
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
747
770
|
exports.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
748
771
|
exports.getGlobalHostPlugins = getGlobalHostPlugins;
|
|
749
|
-
exports.getGlobalShare = getGlobalShare;
|
|
750
772
|
exports.getGlobalShareScope = getGlobalShareScope;
|
|
751
773
|
exports.getGlobalSnapshot = getGlobalSnapshot;
|
|
752
774
|
exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
|
|
753
775
|
exports.getInfoWithoutType = getInfoWithoutType;
|
|
754
776
|
exports.getPreloaded = getPreloaded;
|
|
777
|
+
exports.getRegisteredShare = getRegisteredShare;
|
|
755
778
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
756
779
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
757
780
|
exports.globalLoading = globalLoading;
|
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,7 +87,7 @@ 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
|
|
90
|
+
var _nativeGlobal___FEDERATION__, _nativeGlobal___FEDERATION__1, _nativeGlobal___FEDERATION__2, _nativeGlobal___FEDERATION__3, _nativeGlobal___FEDERATION__4, _nativeGlobal___FEDERATION__5;
|
|
90
91
|
// export const nativeGlobal: typeof global = new Function('return this')();
|
|
91
92
|
const nativeGlobal = new Function('return this')();
|
|
92
93
|
// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.
|
|
@@ -109,7 +110,6 @@ if (nativeGlobal.__VMOK__) {
|
|
|
109
110
|
moduleInfo: {},
|
|
110
111
|
__SHARE__: {},
|
|
111
112
|
__MANIFEST_LOADING__: {},
|
|
112
|
-
__SHARE_SCOPE_LOADING__: {},
|
|
113
113
|
__PRELOADED_MAP__: new Map()
|
|
114
114
|
};
|
|
115
115
|
nativeGlobal.__VMOK__ = nativeGlobal.__FEDERATION__;
|
|
@@ -124,10 +124,8 @@ var ___SHARE__;
|
|
|
124
124
|
(___SHARE__ = (_nativeGlobal___FEDERATION__3 = nativeGlobal.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _nativeGlobal___FEDERATION__3.__SHARE__ = {};
|
|
125
125
|
var ___MANIFEST_LOADING__;
|
|
126
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
127
|
var ___PRELOADED_MAP__;
|
|
130
|
-
(___PRELOADED_MAP__ = (
|
|
128
|
+
(___PRELOADED_MAP__ = (_nativeGlobal___FEDERATION__5 = nativeGlobal.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _nativeGlobal___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
131
129
|
const Global = {
|
|
132
130
|
get __FEDERATION__ () {
|
|
133
131
|
const globalThisVal = new Function('return globalThis')();
|
|
@@ -140,7 +138,6 @@ function resetFederationGlobalInfo() {
|
|
|
140
138
|
nativeGlobal.__FEDERATION__.moduleInfo = {};
|
|
141
139
|
nativeGlobal.__FEDERATION__.__SHARE__ = {};
|
|
142
140
|
nativeGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
143
|
-
nativeGlobal.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
144
141
|
}
|
|
145
142
|
function getGlobalFederationInstance(name, version) {
|
|
146
143
|
const buildId = getBuilderId();
|
|
@@ -166,7 +163,7 @@ function getGlobalFederationConstructor() {
|
|
|
166
163
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
167
164
|
if (isDebugMode()) {
|
|
168
165
|
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
169
|
-
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.
|
|
166
|
+
Global.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = '0.0.4';
|
|
170
167
|
}
|
|
171
168
|
}
|
|
172
169
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -623,6 +620,7 @@ function formatShare(shareArgs, from) {
|
|
|
623
620
|
loading: null
|
|
624
621
|
}, shareArgs, {
|
|
625
622
|
get,
|
|
623
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
626
624
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
627
625
|
'default'
|
|
628
626
|
],
|
|
@@ -639,15 +637,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
639
637
|
}, {});
|
|
640
638
|
}
|
|
641
639
|
function versionLt(a, b) {
|
|
642
|
-
|
|
640
|
+
const transformInvalidVersion = (version)=>{
|
|
641
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
642
|
+
if (isNumberVersion) {
|
|
643
|
+
const splitArr = version.split('.');
|
|
644
|
+
let validVersion = version;
|
|
645
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
646
|
+
validVersion += '.0';
|
|
647
|
+
}
|
|
648
|
+
return validVersion;
|
|
649
|
+
}
|
|
650
|
+
return version;
|
|
651
|
+
};
|
|
652
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
643
653
|
return true;
|
|
644
654
|
} else {
|
|
645
655
|
return false;
|
|
646
656
|
}
|
|
647
657
|
}
|
|
648
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
649
|
-
const
|
|
650
|
-
const versions = globalShares[scope][pkgName];
|
|
658
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
659
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
651
660
|
const callback = cb || function(prev, cur) {
|
|
652
661
|
return versionLt(prev, cur);
|
|
653
662
|
};
|
|
@@ -658,20 +667,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
658
667
|
if (callback(prev, cur)) {
|
|
659
668
|
return cur;
|
|
660
669
|
}
|
|
670
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
671
|
+
if (prev === '0') {
|
|
672
|
+
return cur;
|
|
673
|
+
}
|
|
661
674
|
return prev;
|
|
662
675
|
}, 0);
|
|
663
676
|
};
|
|
664
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
665
|
-
const
|
|
666
|
-
const versions = globalShares[scope][pkgName];
|
|
677
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
678
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
667
679
|
const callback = function(prev, cur) {
|
|
668
680
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
669
681
|
};
|
|
670
|
-
return findVersion(scope, pkgName, callback);
|
|
682
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
671
683
|
}
|
|
672
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
673
|
-
const
|
|
674
|
-
const versions = globalShares[scope][pkgName];
|
|
684
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
685
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
686
|
const callback = function(prev, cur) {
|
|
676
687
|
if (versions[cur].loaded) {
|
|
677
688
|
if (versions[prev].loaded) {
|
|
@@ -685,45 +696,57 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
685
696
|
}
|
|
686
697
|
return versionLt(prev, cur);
|
|
687
698
|
};
|
|
688
|
-
return findVersion(scope, pkgName, callback);
|
|
699
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
700
|
+
}
|
|
701
|
+
function getFindShareFunction(strategy) {
|
|
702
|
+
if (strategy === 'loaded-first') {
|
|
703
|
+
return findSingletonVersionOrderByLoaded;
|
|
704
|
+
}
|
|
705
|
+
return findSingletonVersionOrderByVersion;
|
|
689
706
|
}
|
|
690
707
|
// Details about shared resources
|
|
691
708
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
692
|
-
function
|
|
693
|
-
|
|
709
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
710
|
+
if (!localShareScopeMap) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
694
713
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
695
714
|
const scopes = Array.isArray(scope) ? scope : [
|
|
696
715
|
scope
|
|
697
716
|
];
|
|
698
717
|
for (const sc of scopes){
|
|
699
|
-
if (shareConfig &&
|
|
718
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
700
719
|
const { requiredVersion } = shareConfig;
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
if (
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
}
|
|
719
|
-
// eslint-disable-next-line max-depth
|
|
720
|
-
for (const [versionKey, versionValue] of Object.entries(globalShares[sc][pkgName])){
|
|
721
|
-
// eslint-disable-next-line max-depth
|
|
722
|
-
if (satisfy(versionKey, requiredVersion)) {
|
|
723
|
-
return versionValue;
|
|
720
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
721
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
722
|
+
//@ts-ignore
|
|
723
|
+
const defaultResolver = ()=>{
|
|
724
|
+
if (shareConfig.singleton) {
|
|
725
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
726
|
+
warn(`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})`);
|
|
727
|
+
}
|
|
728
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
729
|
+
} else {
|
|
730
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
731
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
732
|
+
}
|
|
733
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
734
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
735
|
+
return versionValue;
|
|
736
|
+
}
|
|
724
737
|
}
|
|
725
738
|
}
|
|
726
|
-
}
|
|
739
|
+
};
|
|
740
|
+
const params = {
|
|
741
|
+
shareScopeMap: localShareScopeMap,
|
|
742
|
+
scope: sc,
|
|
743
|
+
pkgName,
|
|
744
|
+
version: maxOrSingletonVersion,
|
|
745
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
746
|
+
resolver: defaultResolver
|
|
747
|
+
};
|
|
748
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
749
|
+
return resolveShared.resolver();
|
|
727
750
|
}
|
|
728
751
|
}
|
|
729
752
|
}
|
|
@@ -731,4 +754,4 @@ function getGlobalShareScope() {
|
|
|
731
754
|
return Global.__FEDERATION__.__SHARE__;
|
|
732
755
|
}
|
|
733
756
|
|
|
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,
|
|
757
|
+
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;
|
|
@@ -60,6 +61,14 @@ export declare class FederationHost {
|
|
|
60
61
|
origin: FederationHost;
|
|
61
62
|
}>;
|
|
62
63
|
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
|
|
64
|
+
resolveShare: SyncWaterfallHook<{
|
|
65
|
+
shareScopeMap: ShareScopeMap;
|
|
66
|
+
scope: string;
|
|
67
|
+
pkgName: string;
|
|
68
|
+
version: string;
|
|
69
|
+
GlobalFederation: Federation;
|
|
70
|
+
resolver: () => Shared | undefined;
|
|
71
|
+
}>;
|
|
63
72
|
beforePreloadRemote: AsyncHook<{
|
|
64
73
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
65
74
|
options: Options;
|
|
@@ -79,10 +88,12 @@ export declare class FederationHost {
|
|
|
79
88
|
origin: FederationHost;
|
|
80
89
|
}, false | void | Promise<false | void>>;
|
|
81
90
|
}>;
|
|
91
|
+
releaseNumber: string;
|
|
82
92
|
version: string;
|
|
83
93
|
name: string;
|
|
84
94
|
moduleCache: Map<string, Module>;
|
|
85
95
|
snapshotHandler: SnapshotHandler;
|
|
96
|
+
shareScopeMap: ShareScopeMap;
|
|
86
97
|
loaderHook: PluginSystem<{
|
|
87
98
|
getModuleInfo: SyncHook<[{
|
|
88
99
|
target: Record<string, any>;
|
|
@@ -96,10 +107,8 @@ export declare class FederationHost {
|
|
|
96
107
|
}], void | HTMLScriptElement>;
|
|
97
108
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
98
109
|
}>;
|
|
99
|
-
loadingShare: {
|
|
100
|
-
[key: string]: Promise<any>;
|
|
101
|
-
};
|
|
102
110
|
constructor(userOptions: UserOptions);
|
|
111
|
+
private _setGlobalShareScopeMap;
|
|
103
112
|
initOptions(userOptions: UserOptions): Options;
|
|
104
113
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
105
114
|
loadShareSync<T>(pkgName: string): () => T | never;
|
|
@@ -113,7 +122,8 @@ export declare class FederationHost {
|
|
|
113
122
|
* It accepts one argument, the name of the share scope.
|
|
114
123
|
* If the share scope does not exist, it creates one.
|
|
115
124
|
*/
|
|
116
|
-
initializeSharing(shareScopeName?: string):
|
|
125
|
+
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
|
|
126
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
|
|
117
127
|
private formatOptions;
|
|
118
128
|
private registerPlugins;
|
|
119
129
|
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,9 +9,8 @@ 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;
|
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?: {
|
|
@@ -57,13 +57,16 @@ export type Shared = {
|
|
|
57
57
|
eager?: boolean;
|
|
58
58
|
strategy: 'version-first' | 'loaded-first';
|
|
59
59
|
};
|
|
60
|
-
export type
|
|
60
|
+
export type ShareScopeMap = {
|
|
61
61
|
[scope: string]: {
|
|
62
62
|
[pkgName: string]: {
|
|
63
63
|
[sharedVersion: string]: Shared;
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
|
+
export type GlobalShareScopeMap = {
|
|
68
|
+
[instanceName: string]: ShareScopeMap;
|
|
69
|
+
};
|
|
67
70
|
export type ShareInfos = {
|
|
68
71
|
[pkgName: string]: Shared;
|
|
69
72
|
};
|
|
@@ -89,6 +92,6 @@ export type RemoteEntryInitOptions = {
|
|
|
89
92
|
};
|
|
90
93
|
export type RemoteEntryExports = {
|
|
91
94
|
get: (id: string) => () => Promise<Module>;
|
|
92
|
-
init: (shareScope:
|
|
95
|
+
init: (shareScope: ShareScopeMap[string], initScope?: Array<Record<string, any>>, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
93
96
|
};
|
|
94
97
|
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-20231221061836",
|
|
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-20231221061836"
|
|
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
|