@module-federation/runtime 0.0.7 → 0.0.9
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 +189 -78
- package/dist/index.esm.js +188 -80
- package/dist/package.json +3 -3
- package/dist/share.cjs.js +92 -59
- package/dist/share.esm.js +92 -59
- 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.9";
|
|
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,72 +676,95 @@ 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
|
-
|
|
673
|
-
|
|
674
|
-
|
|
686
|
+
const isLoaded = (shared)=>{
|
|
687
|
+
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
688
|
+
};
|
|
689
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
690
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
675
691
|
const callback = function(prev, cur) {
|
|
676
|
-
return !versions[prev]
|
|
692
|
+
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
677
693
|
};
|
|
678
|
-
return findVersion(scope, pkgName, callback);
|
|
694
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
679
695
|
}
|
|
680
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
681
|
-
const
|
|
682
|
-
const versions = globalShares[scope][pkgName];
|
|
696
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
697
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
683
698
|
const callback = function(prev, cur) {
|
|
684
|
-
if (versions[cur]
|
|
685
|
-
if (versions[prev]
|
|
699
|
+
if (isLoaded(versions[cur])) {
|
|
700
|
+
if (isLoaded(versions[prev])) {
|
|
686
701
|
return Boolean(versionLt(prev, cur));
|
|
687
702
|
} else {
|
|
688
703
|
return true;
|
|
689
704
|
}
|
|
690
705
|
}
|
|
691
|
-
if (versions[prev]
|
|
706
|
+
if (isLoaded(versions[prev])) {
|
|
692
707
|
return false;
|
|
693
708
|
}
|
|
694
709
|
return versionLt(prev, cur);
|
|
695
710
|
};
|
|
696
|
-
return findVersion(scope, pkgName, callback);
|
|
711
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
712
|
+
}
|
|
713
|
+
function getFindShareFunction(strategy) {
|
|
714
|
+
if (strategy === 'loaded-first') {
|
|
715
|
+
return findSingletonVersionOrderByLoaded;
|
|
716
|
+
}
|
|
717
|
+
return findSingletonVersionOrderByVersion;
|
|
697
718
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
719
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
720
|
+
if (!localShareScopeMap) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
702
723
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
703
724
|
const scopes = Array.isArray(scope) ? scope : [
|
|
704
725
|
scope
|
|
705
726
|
];
|
|
706
727
|
for (const sc of scopes){
|
|
707
|
-
if (shareConfig &&
|
|
728
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
708
729
|
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
|
-
|
|
730
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
731
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
732
|
+
//@ts-ignore
|
|
733
|
+
const defaultResolver = ()=>{
|
|
734
|
+
if (shareConfig.singleton) {
|
|
735
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
736
|
+
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})`;
|
|
737
|
+
if (shareConfig.strictVersion) {
|
|
738
|
+
error(msg);
|
|
739
|
+
} else {
|
|
740
|
+
warn(msg);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
744
|
+
} else {
|
|
745
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
746
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
747
|
+
}
|
|
748
|
+
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
749
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
750
|
+
}
|
|
751
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
752
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
753
|
+
return versionValue;
|
|
754
|
+
}
|
|
732
755
|
}
|
|
733
756
|
}
|
|
734
|
-
}
|
|
757
|
+
};
|
|
758
|
+
const params = {
|
|
759
|
+
shareScopeMap: localShareScopeMap,
|
|
760
|
+
scope: sc,
|
|
761
|
+
pkgName,
|
|
762
|
+
version: maxOrSingletonVersion,
|
|
763
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
764
|
+
resolver: defaultResolver
|
|
765
|
+
};
|
|
766
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
767
|
+
return resolveShared.resolver();
|
|
735
768
|
}
|
|
736
769
|
}
|
|
737
770
|
}
|
|
@@ -752,12 +785,12 @@ exports.getFMId = getFMId;
|
|
|
752
785
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|
|
753
786
|
exports.getGlobalFederationInstance = getGlobalFederationInstance;
|
|
754
787
|
exports.getGlobalHostPlugins = getGlobalHostPlugins;
|
|
755
|
-
exports.getGlobalShare = getGlobalShare;
|
|
756
788
|
exports.getGlobalShareScope = getGlobalShareScope;
|
|
757
789
|
exports.getGlobalSnapshot = getGlobalSnapshot;
|
|
758
790
|
exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
|
|
759
791
|
exports.getInfoWithoutType = getInfoWithoutType;
|
|
760
792
|
exports.getPreloaded = getPreloaded;
|
|
793
|
+
exports.getRegisteredShare = getRegisteredShare;
|
|
761
794
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
762
795
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
763
796
|
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.9";
|
|
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,72 +674,95 @@ 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
|
-
|
|
671
|
-
|
|
672
|
-
|
|
684
|
+
const isLoaded = (shared)=>{
|
|
685
|
+
return Boolean(shared.loaded) || typeof shared.lib === 'function';
|
|
686
|
+
};
|
|
687
|
+
function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
688
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
673
689
|
const callback = function(prev, cur) {
|
|
674
|
-
return !versions[prev]
|
|
690
|
+
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
675
691
|
};
|
|
676
|
-
return findVersion(scope, pkgName, callback);
|
|
692
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
677
693
|
}
|
|
678
|
-
function findSingletonVersionOrderByLoaded(scope, pkgName) {
|
|
679
|
-
const
|
|
680
|
-
const versions = globalShares[scope][pkgName];
|
|
694
|
+
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
695
|
+
const versions = shareScopeMap[scope][pkgName];
|
|
681
696
|
const callback = function(prev, cur) {
|
|
682
|
-
if (versions[cur]
|
|
683
|
-
if (versions[prev]
|
|
697
|
+
if (isLoaded(versions[cur])) {
|
|
698
|
+
if (isLoaded(versions[prev])) {
|
|
684
699
|
return Boolean(versionLt(prev, cur));
|
|
685
700
|
} else {
|
|
686
701
|
return true;
|
|
687
702
|
}
|
|
688
703
|
}
|
|
689
|
-
if (versions[prev]
|
|
704
|
+
if (isLoaded(versions[prev])) {
|
|
690
705
|
return false;
|
|
691
706
|
}
|
|
692
707
|
return versionLt(prev, cur);
|
|
693
708
|
};
|
|
694
|
-
return findVersion(scope, pkgName, callback);
|
|
709
|
+
return findVersion(shareScopeMap, scope, pkgName, callback);
|
|
710
|
+
}
|
|
711
|
+
function getFindShareFunction(strategy) {
|
|
712
|
+
if (strategy === 'loaded-first') {
|
|
713
|
+
return findSingletonVersionOrderByLoaded;
|
|
714
|
+
}
|
|
715
|
+
return findSingletonVersionOrderByVersion;
|
|
695
716
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
717
|
+
function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare) {
|
|
718
|
+
if (!localShareScopeMap) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
700
721
|
const { shareConfig, scope = DEFAULT_SCOPE, strategy } = shareInfo;
|
|
701
722
|
const scopes = Array.isArray(scope) ? scope : [
|
|
702
723
|
scope
|
|
703
724
|
];
|
|
704
725
|
for (const sc of scopes){
|
|
705
|
-
if (shareConfig &&
|
|
726
|
+
if (shareConfig && localShareScopeMap[sc] && localShareScopeMap[sc][pkgName]) {
|
|
706
727
|
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
|
-
|
|
728
|
+
const findShareFunction = getFindShareFunction(strategy);
|
|
729
|
+
const maxOrSingletonVersion = findShareFunction(localShareScopeMap, sc, pkgName);
|
|
730
|
+
//@ts-ignore
|
|
731
|
+
const defaultResolver = ()=>{
|
|
732
|
+
if (shareConfig.singleton) {
|
|
733
|
+
if (typeof requiredVersion === 'string' && !satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
734
|
+
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})`;
|
|
735
|
+
if (shareConfig.strictVersion) {
|
|
736
|
+
error(msg);
|
|
737
|
+
} else {
|
|
738
|
+
warn(msg);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
742
|
+
} else {
|
|
743
|
+
if (requiredVersion === false || requiredVersion === '*') {
|
|
744
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
745
|
+
}
|
|
746
|
+
if (satisfy(maxOrSingletonVersion, requiredVersion)) {
|
|
747
|
+
return localShareScopeMap[sc][pkgName][maxOrSingletonVersion];
|
|
748
|
+
}
|
|
749
|
+
for (const [versionKey, versionValue] of Object.entries(localShareScopeMap[sc][pkgName])){
|
|
750
|
+
if (satisfy(versionKey, requiredVersion)) {
|
|
751
|
+
return versionValue;
|
|
752
|
+
}
|
|
730
753
|
}
|
|
731
754
|
}
|
|
732
|
-
}
|
|
755
|
+
};
|
|
756
|
+
const params = {
|
|
757
|
+
shareScopeMap: localShareScopeMap,
|
|
758
|
+
scope: sc,
|
|
759
|
+
pkgName,
|
|
760
|
+
version: maxOrSingletonVersion,
|
|
761
|
+
GlobalFederation: Global.__FEDERATION__,
|
|
762
|
+
resolver: defaultResolver
|
|
763
|
+
};
|
|
764
|
+
const resolveShared = resolveShare.emit(params) || params;
|
|
765
|
+
return resolveShared.resolver();
|
|
733
766
|
}
|
|
734
767
|
}
|
|
735
768
|
}
|
|
@@ -737,4 +770,4 @@ function getGlobalShareScope() {
|
|
|
737
770
|
return Global.__FEDERATION__.__SHARE__;
|
|
738
771
|
}
|
|
739
772
|
|
|
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,
|
|
773
|
+
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']>;
|