@module-federation/runtime 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +513 -124
- package/dist/helpers.cjs.js +1 -1
- package/dist/helpers.esm.js +2 -2
- package/dist/index.cjs.js +188 -77
- package/dist/index.esm.js +187 -79
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +85 -55
- package/dist/share.esm.js +85 -55
- package/dist/src/core.d.ts +26 -9
- package/dist/src/global.d.ts +2 -3
- package/dist/src/helpers.d.ts +2 -2
- package/dist/src/index.d.ts +3 -1
- package/dist/src/type/config.d.ts +7 -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,10 +1,11 @@
|
|
|
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() {
|
|
7
|
-
return Boolean(
|
|
8
|
+
return Boolean("");
|
|
8
9
|
}
|
|
9
10
|
function isBrowserEnv() {
|
|
10
11
|
return typeof window !== 'undefined';
|
|
@@ -109,7 +110,7 @@ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
|
109
110
|
}
|
|
110
111
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
111
112
|
function setGlobalDefaultVal(target) {
|
|
112
|
-
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5
|
|
113
|
+
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
|
|
113
114
|
if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
|
|
114
115
|
definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
|
|
115
116
|
}
|
|
@@ -120,7 +121,6 @@ function setGlobalDefaultVal(target) {
|
|
|
120
121
|
moduleInfo: {},
|
|
121
122
|
__SHARE__: {},
|
|
122
123
|
__MANIFEST_LOADING__: {},
|
|
123
|
-
__SHARE_SCOPE_LOADING__: {},
|
|
124
124
|
__PRELOADED_MAP__: new Map()
|
|
125
125
|
});
|
|
126
126
|
definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
|
|
@@ -135,10 +135,8 @@ function setGlobalDefaultVal(target) {
|
|
|
135
135
|
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
136
136
|
var ___MANIFEST_LOADING__;
|
|
137
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
138
|
var ___PRELOADED_MAP__;
|
|
141
|
-
(___PRELOADED_MAP__ = (
|
|
139
|
+
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
142
140
|
}
|
|
143
141
|
setGlobalDefaultVal(globalThis);
|
|
144
142
|
setGlobalDefaultVal(nativeGlobal);
|
|
@@ -148,7 +146,6 @@ function resetFederationGlobalInfo() {
|
|
|
148
146
|
globalThis.__FEDERATION__.moduleInfo = {};
|
|
149
147
|
globalThis.__FEDERATION__.__SHARE__ = {};
|
|
150
148
|
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
151
|
-
globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
152
149
|
}
|
|
153
150
|
function getGlobalFederationInstance(name, version) {
|
|
154
151
|
const buildId = getBuilderId();
|
|
@@ -174,7 +171,7 @@ function getGlobalFederationConstructor() {
|
|
|
174
171
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
175
172
|
if (isDebugMode()) {
|
|
176
173
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
177
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ =
|
|
174
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.8";
|
|
178
175
|
}
|
|
179
176
|
}
|
|
180
177
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -623,14 +620,16 @@ function formatShare(shareArgs, from) {
|
|
|
623
620
|
deps: [],
|
|
624
621
|
useIn: [],
|
|
625
622
|
from,
|
|
626
|
-
shareConfig: {
|
|
627
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
628
|
-
singleton: false,
|
|
629
|
-
eager: false
|
|
630
|
-
},
|
|
631
623
|
loading: null
|
|
632
624
|
}, shareArgs, {
|
|
625
|
+
shareConfig: _extends({
|
|
626
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
627
|
+
singleton: false,
|
|
628
|
+
eager: false,
|
|
629
|
+
strictVersion: false
|
|
630
|
+
}, shareArgs.shareConfig),
|
|
633
631
|
get,
|
|
632
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
634
633
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
635
634
|
'default'
|
|
636
635
|
],
|
|
@@ -647,15 +646,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
647
646
|
}, {});
|
|
648
647
|
}
|
|
649
648
|
function versionLt(a, b) {
|
|
650
|
-
|
|
649
|
+
const transformInvalidVersion = (version)=>{
|
|
650
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
651
|
+
if (isNumberVersion) {
|
|
652
|
+
const splitArr = version.split('.');
|
|
653
|
+
let validVersion = version;
|
|
654
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
655
|
+
validVersion += '.0';
|
|
656
|
+
}
|
|
657
|
+
return validVersion;
|
|
658
|
+
}
|
|
659
|
+
return version;
|
|
660
|
+
};
|
|
661
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
651
662
|
return true;
|
|
652
663
|
} else {
|
|
653
664
|
return false;
|
|
654
665
|
}
|
|
655
666
|
}
|
|
656
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
657
|
-
const
|
|
658
|
-
const versions = globalShares[scope][pkgName];
|
|
667
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
668
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
659
669
|
const callback = cb || function(prev, cur) {
|
|
660
670
|
return versionLt(prev, cur);
|
|
661
671
|
};
|
|
@@ -666,20 +676,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
666
676
|
if (callback(prev, cur)) {
|
|
667
677
|
return cur;
|
|
668
678
|
}
|
|
679
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
680
|
+
if (prev === '0') {
|
|
681
|
+
return cur;
|
|
682
|
+
}
|
|
669
683
|
return prev;
|
|
670
684
|
}, 0);
|
|
671
685
|
};
|
|
672
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
673
|
-
const
|
|
674
|
-
const versions = globalShares[scope][pkgName];
|
|
686
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
687
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
688
|
const callback = function(prev, cur) {
|
|
676
689
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
677
690
|
};
|
|
678
|
-
return findVersion(scope, pkgName, callback);
|
|
691
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
679
692
|
}
|
|
680
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
681
|
-
const
|
|
682
|
-
const versions = globalShares[scope][pkgName];
|
|
693
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
694
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
683
695
|
const callback = function(prev, cur) {
|
|
684
696
|
if (versions[cur].loaded) {
|
|
685
697
|
if (versions[prev].loaded) {
|
|
@@ -693,45 +705,63 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
693
705
|
}
|
|
694
706
|
return versionLt(prev, cur);
|
|
695
707
|
};
|
|
696
|
-
return findVersion(scope, pkgName, callback);
|
|
708
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
709
|
+
}
|
|
710
|
+
function getFindShareFunction(strategy) {
|
|
711
|
+
if (strategy === 'loaded-first') {
|
|
712
|
+
return findSingletonVersionOrderByLoaded;
|
|
713
|
+
}
|
|
714
|
+
return findSingletonVersionOrderByVersion;
|
|
697
715
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
716
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
717
|
+
if (!localShareScopeMap) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
702
720
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
703
721
|
const scopes = Array.isArray(scope) ? scope : [
|
|
704
722
|
scope
|
|
705
723
|
];
|
|
706
724
|
for (const sc of scopes){
|
|
707
|
-
if (shareConfig &&
|
|
725
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
708
726
|
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
|
-
|
|
727
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
728
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
729
|
+
//@ts-ignore
|
|
730
|
+
const defaultResolver = ()=>{
|
|
731
|
+
if (shareConfig.singleton) {
|
|
732
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
733
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
734
|
+
if (shareConfig.strictVersion) {
|
|
735
|
+
error(msg);
|
|
736
|
+
} else {
|
|
737
|
+
warn(msg);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
741
|
+
} else {
|
|
742
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
743
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
744
|
+
}
|
|
745
|
+
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
746
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
747
|
+
}
|
|
748
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
749
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
750
|
+
return versionValue;
|
|
751
|
+
}
|
|
732
752
|
}
|
|
733
753
|
}
|
|
734
|
-
}
|
|
754
|
+
};
|
|
755
|
+
const params = {
|
|
756
|
+
shareScopeMap: localShareScopeMap,
|
|
757
|
+
scope: sc,
|
|
758
|
+
pkgName,
|
|
759
|
+
version: maxOrSingletonVersion,
|
|
760
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
761
|
+
resolver: defaultResolver
|
|
762
|
+
};
|
|
763
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
764
|
+
return resolveShared.resolver();
|
|
735
765
|
}
|
|
736
766
|
}
|
|
737
767
|
}
|
|
@@ -752,12 +782,12 @@ exports.getFMId = getFMId;
|
|
|
752
782
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
753
783
|
exports.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
754
784
|
exports.getGlobalHostPlugins = getGlobalHostPlugins;
|
|
755
|
-
exports.getGlobalShare = getGlobalShare;
|
|
756
785
|
exports.getGlobalShareScope = getGlobalShareScope;
|
|
757
786
|
exports.getGlobalSnapshot = getGlobalSnapshot;
|
|
758
787
|
exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
|
|
759
788
|
exports.getInfoWithoutType = getInfoWithoutType;
|
|
760
789
|
exports.getPreloaded = getPreloaded;
|
|
790
|
+
exports.getRegisteredShare = getRegisteredShare;
|
|
761
791
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
762
792
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
763
793
|
exports.globalLoading = globalLoading;
|
package/dist/share.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function getBuilderId() {
|
|
2
|
+
//@ts-ignore
|
|
2
3
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
3
4
|
}
|
|
4
5
|
function isDebugMode() {
|
|
5
|
-
return Boolean(
|
|
6
|
+
return Boolean("");
|
|
6
7
|
}
|
|
7
8
|
function isBrowserEnv() {
|
|
8
9
|
return typeof window !== 'undefined';
|
|
@@ -107,7 +108,7 @@ if (!includeOwnProperty(globalThis, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {
|
|
|
107
108
|
}
|
|
108
109
|
const globalLoading = globalThis.__GLOBAL_LOADING_REMOTE_ENTRY__;
|
|
109
110
|
function setGlobalDefaultVal(target) {
|
|
110
|
-
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5
|
|
111
|
+
var _target___FEDERATION__, _target___FEDERATION__1, _target___FEDERATION__2, _target___FEDERATION__3, _target___FEDERATION__4, _target___FEDERATION__5;
|
|
111
112
|
if (includeOwnProperty(target, '__VMOK__') && !includeOwnProperty(target, '__FEDERATION__')) {
|
|
112
113
|
definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);
|
|
113
114
|
}
|
|
@@ -118,7 +119,6 @@ function setGlobalDefaultVal(target) {
|
|
|
118
119
|
moduleInfo: {},
|
|
119
120
|
__SHARE__: {},
|
|
120
121
|
__MANIFEST_LOADING__: {},
|
|
121
|
-
__SHARE_SCOPE_LOADING__: {},
|
|
122
122
|
__PRELOADED_MAP__: new Map()
|
|
123
123
|
});
|
|
124
124
|
definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);
|
|
@@ -133,10 +133,8 @@ function setGlobalDefaultVal(target) {
|
|
|
133
133
|
(___SHARE__ = (_target___FEDERATION__3 = target.__FEDERATION__).__SHARE__) != null ? ___SHARE__ : _target___FEDERATION__3.__SHARE__ = {};
|
|
134
134
|
var ___MANIFEST_LOADING__;
|
|
135
135
|
(___MANIFEST_LOADING__ = (_target___FEDERATION__4 = target.__FEDERATION__).__MANIFEST_LOADING__) != null ? ___MANIFEST_LOADING__ : _target___FEDERATION__4.__MANIFEST_LOADING__ = {};
|
|
136
|
-
var ___SHARE_SCOPE_LOADING__;
|
|
137
|
-
(___SHARE_SCOPE_LOADING__ = (_target___FEDERATION__5 = target.__FEDERATION__).__SHARE_SCOPE_LOADING__) != null ? ___SHARE_SCOPE_LOADING__ : _target___FEDERATION__5.__SHARE_SCOPE_LOADING__ = {};
|
|
138
136
|
var ___PRELOADED_MAP__;
|
|
139
|
-
(___PRELOADED_MAP__ = (
|
|
137
|
+
(___PRELOADED_MAP__ = (_target___FEDERATION__5 = target.__FEDERATION__).__PRELOADED_MAP__) != null ? ___PRELOADED_MAP__ : _target___FEDERATION__5.__PRELOADED_MAP__ = new Map();
|
|
140
138
|
}
|
|
141
139
|
setGlobalDefaultVal(globalThis);
|
|
142
140
|
setGlobalDefaultVal(nativeGlobal);
|
|
@@ -146,7 +144,6 @@ function resetFederationGlobalInfo() {
|
|
|
146
144
|
globalThis.__FEDERATION__.moduleInfo = {};
|
|
147
145
|
globalThis.__FEDERATION__.__SHARE__ = {};
|
|
148
146
|
globalThis.__FEDERATION__.__MANIFEST_LOADING__ = {};
|
|
149
|
-
globalThis.__FEDERATION__.__SHARE_SCOPE_LOADING__ = {};
|
|
150
147
|
}
|
|
151
148
|
function getGlobalFederationInstance(name, version) {
|
|
152
149
|
const buildId = getBuilderId();
|
|
@@ -172,7 +169,7 @@ function getGlobalFederationConstructor() {
|
|
|
172
169
|
function setGlobalFederationConstructor(FederationConstructor) {
|
|
173
170
|
if (isDebugMode()) {
|
|
174
171
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
175
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ =
|
|
172
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.8";
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
175
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -621,14 +618,16 @@ function formatShare(shareArgs, from) {
|
|
|
621
618
|
deps: [],
|
|
622
619
|
useIn: [],
|
|
623
620
|
from,
|
|
624
|
-
shareConfig: {
|
|
625
|
-
requiredVersion: `^${shareArgs.version}`,
|
|
626
|
-
singleton: false,
|
|
627
|
-
eager: false
|
|
628
|
-
},
|
|
629
621
|
loading: null
|
|
630
622
|
}, shareArgs, {
|
|
623
|
+
shareConfig: _extends({
|
|
624
|
+
requiredVersion: `^${shareArgs.version}`,
|
|
625
|
+
singleton: false,
|
|
626
|
+
eager: false,
|
|
627
|
+
strictVersion: false
|
|
628
|
+
}, shareArgs.shareConfig),
|
|
631
629
|
get,
|
|
630
|
+
loaded: 'lib' in shareArgs ? true : undefined,
|
|
632
631
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
633
632
|
'default'
|
|
634
633
|
],
|
|
@@ -645,15 +644,26 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
645
644
|
}, {});
|
|
646
645
|
}
|
|
647
646
|
function versionLt(a, b) {
|
|
648
|
-
|
|
647
|
+
const transformInvalidVersion = (version)=>{
|
|
648
|
+
const isNumberVersion = !Number.isNaN(Number(version));
|
|
649
|
+
if (isNumberVersion) {
|
|
650
|
+
const splitArr = version.split('.');
|
|
651
|
+
let validVersion = version;
|
|
652
|
+
for(let i = 0; i < 3 - splitArr.length; i++){
|
|
653
|
+
validVersion += '.0';
|
|
654
|
+
}
|
|
655
|
+
return validVersion;
|
|
656
|
+
}
|
|
657
|
+
return version;
|
|
658
|
+
};
|
|
659
|
+
if (satisfy(transformInvalidVersion(a), `<=${transformInvalidVersion(b)}`)) {
|
|
649
660
|
return true;
|
|
650
661
|
} else {
|
|
651
662
|
return false;
|
|
652
663
|
}
|
|
653
664
|
}
|
|
654
|
-
const findVersion = (scope, pkgName, cb)=>{
|
|
655
|
-
const
|
|
656
|
-
const versions = globalShares[scope][pkgName];
|
|
665
|
+
const findVersion = (shareScopeMap, scope, pkgName, cb)=>{
|
|
666
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
657
667
|
const callback = cb || function(prev, cur) {
|
|
658
668
|
return versionLt(prev, cur);
|
|
659
669
|
};
|
|
@@ -664,20 +674,22 @@ const findVersion = (scope, pkgName, cb)=>{
|
|
|
664
674
|
if (callback(prev, cur)) {
|
|
665
675
|
return cur;
|
|
666
676
|
}
|
|
677
|
+
// default version is '0' https://github.com/webpack/webpack/blob/main/lib/sharing/ProvideSharedModule.js#L136
|
|
678
|
+
if (prev === '0') {
|
|
679
|
+
return cur;
|
|
680
|
+
}
|
|
667
681
|
return prev;
|
|
668
682
|
}, 0);
|
|
669
683
|
};
|
|
670
|
-
function findSingletonVersionOrderByVersion(scope, pkgName) {
|
|
671
|
-
const
|
|
672
|
-
const versions = globalShares[scope][pkgName];
|
|
684
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
685
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
673
686
|
const callback = function(prev, cur) {
|
|
674
687
|
return !versions[prev].loaded && versionLt(prev, cur);
|
|
675
688
|
};
|
|
676
|
-
return findVersion(scope, pkgName, callback);
|
|
689
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
677
690
|
}
|
|
678
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
679
|
-
const
|
|
680
|
-
const versions = globalShares[scope][pkgName];
|
|
691
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
692
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
681
693
|
const callback = function(prev, cur) {
|
|
682
694
|
if (versions[cur].loaded) {
|
|
683
695
|
if (versions[prev].loaded) {
|
|
@@ -691,45 +703,63 @@ function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
|
691
703
|
}
|
|
692
704
|
return versionLt(prev, cur);
|
|
693
705
|
};
|
|
694
|
-
return findVersion(scope, pkgName, callback);
|
|
706
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
707
|
+
}
|
|
708
|
+
function getFindShareFunction(strategy) {
|
|
709
|
+
if (strategy === 'loaded-first') {
|
|
710
|
+
return findSingletonVersionOrderByLoaded;
|
|
711
|
+
}
|
|
712
|
+
return findSingletonVersionOrderByVersion;
|
|
695
713
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
714
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
715
|
+
if (!localShareScopeMap) {
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
700
718
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
701
719
|
const scopes = Array.isArray(scope) ? scope : [
|
|
702
720
|
scope
|
|
703
721
|
];
|
|
704
722
|
for (const sc of scopes){
|
|
705
|
-
if (shareConfig &&
|
|
723
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
706
724
|
const { requiredVersion } = shareConfig;
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
if (
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
725
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
726
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
727
|
+
//@ts-ignore
|
|
728
|
+
const defaultResolver = ()=>{
|
|
729
|
+
if (shareConfig.singleton) {
|
|
730
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
731
|
+
const msg = `Version ${maxOrSingletonVersion} from ${maxOrSingletonVersion && localShareScopeMap[sc][pkgName][maxOrSingletonVersion].from} of shared singleton module ${pkgName} does not satisfy the requirement of ${shareInfo.from} which needs ${requiredVersion})`;
|
|
732
|
+
if (shareConfig.strictVersion) {
|
|
733
|
+
error(msg);
|
|
734
|
+
} else {
|
|
735
|
+
warn(msg);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
739
|
+
} else {
|
|
740
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
741
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
742
|
+
}
|
|
743
|
+
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
744
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
745
|
+
}
|
|
746
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
747
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
748
|
+
return versionValue;
|
|
749
|
+
}
|
|
730
750
|
}
|
|
731
751
|
}
|
|
732
|
-
}
|
|
752
|
+
};
|
|
753
|
+
const params = {
|
|
754
|
+
shareScopeMap: localShareScopeMap,
|
|
755
|
+
scope: sc,
|
|
756
|
+
pkgName,
|
|
757
|
+
version: maxOrSingletonVersion,
|
|
758
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
759
|
+
resolver: defaultResolver
|
|
760
|
+
};
|
|
761
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
762
|
+
return resolveShared.resolver();
|
|
733
763
|
}
|
|
734
764
|
}
|
|
735
765
|
}
|
|
@@ -737,4 +767,4 @@ function getGlobalShareScope() {
|
|
|
737
767
|
return Global.__FEDERATION__.__SHARE__;
|
|
738
768
|
}
|
|
739
769
|
|
|
740
|
-
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k,
|
|
770
|
+
export { getGlobalFederationInstance as A, getGlobalFederationConstructor as B, setGlobalFederationInstance as C, DEFAULT_REMOTE_TYPE as D, registerGlobalPlugins as E, nativeGlobal as F, Global as G, resetFederationGlobalInfo as H, getTargetSnapshotInfoByModuleInfo as I, addGlobalSnapshot as J, DEFAULT_SCOPE as a, globalLoading as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, setGlobalSnapshotInfoByModuleInfo as q, getGlobalSnapshot as r, safeToString as s, getGlobalShareScope as t, formatShareConfigs as u, isBrowserEnv as v, warn as w, getBuilderId as x, addUniqueItem as y, setGlobalFederationConstructor as z };
|
package/dist/src/core.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
|
-
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo,
|
|
2
|
+
import { Options, PreloadAssets, PreloadOptions, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions } from './type';
|
|
3
3
|
import { Module, ModuleOptions } from './module';
|
|
4
4
|
import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
|
|
5
|
+
import { Federation } from './global';
|
|
5
6
|
import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
|
|
6
7
|
interface LoadRemoteMatch {
|
|
7
8
|
id: string;
|
|
@@ -33,14 +34,19 @@ export declare class FederationHost {
|
|
|
33
34
|
}>;
|
|
34
35
|
afterResolve: AsyncWaterfallHook<LoadRemoteMatch>;
|
|
35
36
|
beforeInitContainer: AsyncWaterfallHook<{
|
|
36
|
-
shareScope:
|
|
37
|
+
shareScope: ShareScopeMap[string];
|
|
37
38
|
initScope: InitScope;
|
|
38
39
|
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
39
40
|
remoteInfo: RemoteInfo;
|
|
40
41
|
origin: FederationHost;
|
|
41
42
|
}>;
|
|
43
|
+
initContainerShareScopeMap: AsyncWaterfallHook<{
|
|
44
|
+
shareScope: ShareScopeMap[string];
|
|
45
|
+
options: Options;
|
|
46
|
+
origin: FederationHost;
|
|
47
|
+
}>;
|
|
42
48
|
initContainer: AsyncWaterfallHook<{
|
|
43
|
-
shareScope:
|
|
49
|
+
shareScope: ShareScopeMap[string];
|
|
44
50
|
initScope: InitScope;
|
|
45
51
|
remoteEntryInitOptions: RemoteEntryInitOptions;
|
|
46
52
|
remoteInfo: RemoteInfo;
|
|
@@ -67,7 +73,9 @@ export declare class FederationHost {
|
|
|
67
73
|
errorLoadRemote: AsyncHook<[{
|
|
68
74
|
id: string;
|
|
69
75
|
error: unknown;
|
|
70
|
-
|
|
76
|
+
from: 'build' | 'runtime';
|
|
77
|
+
origin: FederationHost;
|
|
78
|
+
}], unknown>;
|
|
71
79
|
beforeLoadShare: AsyncWaterfallHook<{
|
|
72
80
|
pkgName: string;
|
|
73
81
|
shareInfo?: Shared | undefined;
|
|
@@ -75,6 +83,14 @@ export declare class FederationHost {
|
|
|
75
83
|
origin: FederationHost;
|
|
76
84
|
}>;
|
|
77
85
|
loadShare: AsyncHook<[FederationHost, string, ShareInfos], false | void | Promise<false | void>>;
|
|
86
|
+
resolveShare: SyncWaterfallHook<{
|
|
87
|
+
shareScopeMap: ShareScopeMap;
|
|
88
|
+
scope: string;
|
|
89
|
+
pkgName: string;
|
|
90
|
+
version: string;
|
|
91
|
+
GlobalFederation: Federation;
|
|
92
|
+
resolver: () => Shared | undefined;
|
|
93
|
+
}>;
|
|
78
94
|
beforePreloadRemote: AsyncHook<{
|
|
79
95
|
preloadOps: Array<PreloadRemoteArgs>;
|
|
80
96
|
options: Options;
|
|
@@ -98,6 +114,7 @@ export declare class FederationHost {
|
|
|
98
114
|
name: string;
|
|
99
115
|
moduleCache: Map<string, Module>;
|
|
100
116
|
snapshotHandler: SnapshotHandler;
|
|
117
|
+
shareScopeMap: ShareScopeMap;
|
|
101
118
|
loaderHook: PluginSystem<{
|
|
102
119
|
getModuleInfo: SyncHook<[{
|
|
103
120
|
target: Record<string, any>;
|
|
@@ -111,16 +128,15 @@ export declare class FederationHost {
|
|
|
111
128
|
}], void | HTMLScriptElement>;
|
|
112
129
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
113
130
|
}>;
|
|
114
|
-
loadingShare: {
|
|
115
|
-
[key: string]: Promise<any>;
|
|
116
|
-
};
|
|
117
131
|
constructor(userOptions: UserOptions);
|
|
132
|
+
private _setGlobalShareScopeMap;
|
|
118
133
|
initOptions(userOptions: UserOptions): Options;
|
|
119
134
|
loadShare<T>(pkgName: string, customShareInfo?: Partial<Shared>): Promise<false | (() => T | undefined)>;
|
|
120
|
-
loadShareSync<T>(pkgName: string): () => T | never;
|
|
135
|
+
loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
|
|
121
136
|
private _getRemoteModuleAndOptions;
|
|
122
137
|
loadRemote<T>(id: string, options?: {
|
|
123
138
|
loadFactory?: boolean;
|
|
139
|
+
from: 'build' | 'runtime';
|
|
124
140
|
}): Promise<T | null>;
|
|
125
141
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
126
142
|
/**
|
|
@@ -128,7 +144,8 @@ export declare class FederationHost {
|
|
|
128
144
|
* It accepts one argument, the name of the share scope.
|
|
129
145
|
* If the share scope does not exist, it creates one.
|
|
130
146
|
*/
|
|
131
|
-
initializeSharing(shareScopeName?: string):
|
|
147
|
+
initializeSharing(shareScopeName?: string, strategy?: Shared['strategy']): Array<Promise<void>>;
|
|
148
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]): void;
|
|
132
149
|
private formatOptions;
|
|
133
150
|
private registerPlugins;
|
|
134
151
|
private setShared;
|
package/dist/src/global.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FederationHost } from './core';
|
|
3
|
-
import { RemoteEntryExports,
|
|
3
|
+
import { RemoteEntryExports, GlobalShareScopeMap, Remote, Optional } from './type';
|
|
4
4
|
import { GlobalModuleInfo, ModuleInfo } from '@module-federation/sdk';
|
|
5
5
|
import { FederationRuntimePlugin } from './type/plugin';
|
|
6
6
|
export interface Federation {
|
|
@@ -9,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, Global } 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
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { FederationHost } from './core';
|
|
2
|
-
import { UserOptions } from './type';
|
|
2
|
+
import { UserOptions, FederationRuntimePlugin } from './type';
|
|
3
3
|
export { FederationHost } from './core';
|
|
4
4
|
export { registerGlobalPlugins } from './global';
|
|
5
|
+
export { loadScript } from '@module-federation/sdk';
|
|
5
6
|
export type { Federation } from './global';
|
|
7
|
+
export type { FederationRuntimePlugin };
|
|
6
8
|
export declare function init(options: UserOptions): FederationHost;
|
|
7
9
|
export declare function loadRemote(...args: Parameters<FederationHost['loadRemote']>): ReturnType<FederationHost['loadRemote']>;
|
|
8
10
|
export declare function loadShare(...args: Parameters<FederationHost['loadShare']>): ReturnType<FederationHost['loadShare']>;
|