@module-federation/runtime 0.0.0-next-20240102023857 → 0.0.0-next-20240102063242
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 +153 -71
- package/dist/index.esm.js +152 -73
- package/dist/package.json +2 -2
- package/dist/share.cjs.js +80 -51
- package/dist/share.esm.js +80 -51
- package/dist/src/core.d.ts +18 -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 +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.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();
|
|
@@ -617,14 +614,16 @@ function formatShare(shareArgs, from) {
|
|
|
617
614
|
deps: [],
|
|
618
615
|
useIn: [],
|
|
619
616
|
from,
|
|
620
|
-
shareConfig: {
|
|
621
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
622
|
-
singleton: false,
|
|
623
|
-
eager: false
|
|
624
|
-
},
|
|
625
617
|
loading: null
|
|
626
618
|
}, shareArgs, {
|
|
619
|
+
shareConfig: _extends({
|
|
620
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
621
|
+
singleton: false,
|
|
622
|
+
eager: false,
|
|
623
|
+
strictVersion: false
|
|
624
|
+
}, shareArgs.shareConfig),
|
|
627
625
|
get,
|
|
626
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
628
627
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
629
628
|
'default'
|
|
630
629
|
],
|
|
@@ -641,15 +640,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
641
640
|
}, {});
|
|
642
641
|
}
|
|
643
642
|
function versionLt(a, b) {
|
|
644
|
-
|
|
643
|
+
const transformInvalidVersion = (version)=>{
|
|
644
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
645
|
+
if (isNumberVersion) {
|
|
646
|
+
const splitArr = version.split('.');
|
|
647
|
+
let validVersion = version;
|
|
648
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
649
|
+
validVersion += '.0';
|
|
650
|
+
}
|
|
651
|
+
return validVersion;
|
|
652
|
+
}
|
|
653
|
+
return version;
|
|
654
|
+
};
|
|
655
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
645
656
|
return true;
|
|
646
657
|
} else {
|
|
647
658
|
return false;
|
|
648
659
|
}
|
|
649
660
|
}
|
|
650
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
651
|
-
const
|
|
652
|
-
const versions = globalShares[scope][pkgName];
|
|
661
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
662
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
653
663
|
const callback = cb || function(prev, cur) {
|
|
654
664
|
return versionLt(prev, cur);
|
|
655
665
|
};
|
|
@@ -660,20 +670,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
660
670
|
if (callback(prev, cur)) {
|
|
661
671
|
return cur;
|
|
662
672
|
}
|
|
673
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
674
|
+
if (prev === '0') {
|
|
675
|
+
return cur;
|
|
676
|
+
}
|
|
663
677
|
return prev;
|
|
664
678
|
}, 0);
|
|
665
679
|
};
|
|
666
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
667
|
-
const
|
|
668
|
-
const versions = globalShares[scope][pkgName];
|
|
680
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
681
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
669
682
|
const callback = function(prev, cur) {
|
|
670
683
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
671
684
|
};
|
|
672
|
-
return findVersion(scope, pkgName, callback);
|
|
685
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
673
686
|
}
|
|
674
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
675
|
-
const
|
|
676
|
-
const versions = globalShares[scope][pkgName];
|
|
687
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
688
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
677
689
|
const callback = function(prev, cur) {
|
|
678
690
|
if (versions[cur].loaded) {
|
|
679
691
|
if (versions[prev].loaded) {
|
|
@@ -687,45 +699,62 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
687
699
|
}
|
|
688
700
|
return versionLt(prev, cur);
|
|
689
701
|
};
|
|
690
|
-
return findVersion(scope, pkgName, callback);
|
|
702
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
703
|
+
}
|
|
704
|
+
function getFindShareFunction(strategy) {
|
|
705
|
+
if (strategy === 'loaded-first') {
|
|
706
|
+
return findSingletonVersionOrderByLoaded;
|
|
707
|
+
}
|
|
708
|
+
return findSingletonVersionOrderByVersion;
|
|
691
709
|
}
|
|
692
710
|
// Details about shared resources
|
|
693
711
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
694
|
-
function
|
|
695
|
-
|
|
712
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
713
|
+
if (!localShareScopeMap) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
696
716
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
697
717
|
const scopes = Array.isArray(scope) ? scope : [
|
|
698
718
|
scope
|
|
699
719
|
];
|
|
700
720
|
for (const sc of scopes){
|
|
701
|
-
if (shareConfig &&
|
|
721
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
702
722
|
const { requiredVersion } = shareConfig;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
if (
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
return versionValue;
|
|
723
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
724
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
725
|
+
//@ts-ignore
|
|
726
|
+
const defaultResolver = ()=>{
|
|
727
|
+
if (shareConfig.singleton) {
|
|
728
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
729
|
+
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})`;
|
|
730
|
+
if (shareConfig.strictVersion) {
|
|
731
|
+
error(msg);
|
|
732
|
+
} else {
|
|
733
|
+
warn(msg);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
737
|
+
} else {
|
|
738
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
739
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
740
|
+
}
|
|
741
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
742
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
743
|
+
return versionValue;
|
|
744
|
+
}
|
|
726
745
|
}
|
|
727
746
|
}
|
|
728
|
-
}
|
|
747
|
+
};
|
|
748
|
+
const params = {
|
|
749
|
+
shareScopeMap: localShareScopeMap,
|
|
750
|
+
scope: sc,
|
|
751
|
+
pkgName,
|
|
752
|
+
version: maxOrSingletonVersion,
|
|
753
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
754
|
+
resolver: defaultResolver
|
|
755
|
+
};
|
|
756
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
757
|
+
return resolveShared.resolver();
|
|
729
758
|
}
|
|
730
759
|
}
|
|
731
760
|
}
|
|
@@ -746,12 +775,12 @@ exports.getFMId = getFMId;
|
|
|
746
775
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
747
776
|
exports.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
748
777
|
exports.getGlobalHostPlugins = getGlobalHostPlugins;
|
|
749
|
-
exports.getGlobalShare = getGlobalShare;
|
|
750
778
|
exports.getGlobalShareScope = getGlobalShareScope;
|
|
751
779
|
exports.getGlobalSnapshot = getGlobalSnapshot;
|
|
752
780
|
exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
|
|
753
781
|
exports.getInfoWithoutType = getInfoWithoutType;
|
|
754
782
|
exports.getPreloaded = getPreloaded;
|
|
783
|
+
exports.getRegisteredShare = getRegisteredShare;
|
|
755
784
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
756
785
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
757
786
|
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();
|
|
@@ -615,14 +612,16 @@ function formatShare(shareArgs, from) {
|
|
|
615
612
|
deps: [],
|
|
616
613
|
useIn: [],
|
|
617
614
|
from,
|
|
618
|
-
shareConfig: {
|
|
619
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
620
|
-
singleton: false,
|
|
621
|
-
eager: false
|
|
622
|
-
},
|
|
623
615
|
loading: null
|
|
624
616
|
}, shareArgs, {
|
|
617
|
+
shareConfig: _extends({
|
|
618
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
619
|
+
singleton: false,
|
|
620
|
+
eager: false,
|
|
621
|
+
strictVersion: false
|
|
622
|
+
}, shareArgs.shareConfig),
|
|
625
623
|
get,
|
|
624
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
626
625
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
627
626
|
'default'
|
|
628
627
|
],
|
|
@@ -639,15 +638,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
639
638
|
}, {});
|
|
640
639
|
}
|
|
641
640
|
function versionLt(a, b) {
|
|
642
|
-
|
|
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)}`)) {
|
|
643
654
|
return true;
|
|
644
655
|
} else {
|
|
645
656
|
return false;
|
|
646
657
|
}
|
|
647
658
|
}
|
|
648
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
649
|
-
const
|
|
650
|
-
const versions = globalShares[scope][pkgName];
|
|
659
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
660
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
651
661
|
const callback = cb || function(prev, cur) {
|
|
652
662
|
return versionLt(prev, cur);
|
|
653
663
|
};
|
|
@@ -658,20 +668,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
658
668
|
if (callback(prev, cur)) {
|
|
659
669
|
return cur;
|
|
660
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
|
+
}
|
|
661
675
|
return prev;
|
|
662
676
|
}, 0);
|
|
663
677
|
};
|
|
664
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
665
|
-
const
|
|
666
|
-
const versions = globalShares[scope][pkgName];
|
|
678
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
679
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
667
680
|
const callback = function(prev, cur) {
|
|
668
681
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
669
682
|
};
|
|
670
|
-
return findVersion(scope, pkgName, callback);
|
|
683
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
671
684
|
}
|
|
672
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
673
|
-
const
|
|
674
|
-
const versions = globalShares[scope][pkgName];
|
|
685
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
686
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
687
|
const callback = function(prev, cur) {
|
|
676
688
|
if (versions[cur].loaded) {
|
|
677
689
|
if (versions[prev].loaded) {
|
|
@@ -685,45 +697,62 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
685
697
|
}
|
|
686
698
|
return versionLt(prev, cur);
|
|
687
699
|
};
|
|
688
|
-
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;
|
|
689
707
|
}
|
|
690
708
|
// Details about shared resources
|
|
691
709
|
// TODO: Implement strictVersion for alignment with module federation.
|
|
692
|
-
function
|
|
693
|
-
|
|
710
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
711
|
+
if (!localShareScopeMap) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
694
714
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
695
715
|
const scopes = Array.isArray(scope) ? scope : [
|
|
696
716
|
scope
|
|
697
717
|
];
|
|
698
718
|
for (const sc of scopes){
|
|
699
|
-
if (shareConfig &&
|
|
719
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
700
720
|
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;
|
|
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
|
+
}
|
|
724
743
|
}
|
|
725
744
|
}
|
|
726
|
-
}
|
|
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();
|
|
727
756
|
}
|
|
728
757
|
}
|
|
729
758
|
}
|
|
@@ -731,4 +760,4 @@ function getGlobalShareScope() {
|
|
|
731
760
|
return Global.__FEDERATION__.__SHARE__;
|
|
732
761
|
}
|
|
733
762
|
|
|
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,
|
|
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,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?: {
|
|
@@ -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 {};
|
|
@@ -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";
|