@module-federation/runtime 0.1.4 → 0.1.6
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 +5 -784
- package/dist/helpers.esm.js +1 -1
- package/dist/index.cjs.js +76 -36
- package/dist/index.esm.js +78 -38
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +45 -10
- package/dist/share.esm.js +44 -11
- package/dist/src/core.d.ts +8 -2
- package/dist/src/type/config.d.ts +8 -4
- package/dist/src/utils/plugin.d.ts +1 -1
- package/dist/src/utils/share.d.ts +12 -6
- package/dist/src/utils/tool.d.ts +1 -0
- package/package.json +2 -2
package/dist/helpers.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as getRegisteredShare, v as getGlobalShareScope, G as Global, J as nativeGlobal, K as resetFederationGlobalInfo, E as getGlobalFederationInstance, H as setGlobalFederationInstance, F as getGlobalFederationConstructor, C as setGlobalFederationConstructor, l as getInfoWithoutType, u as getGlobalSnapshot, L as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, I as registerGlobalPlugins, g as getGlobalHostPlugins, m as getPreloaded, n as setPreloaded } from './share.esm.js';
|
|
2
2
|
|
|
3
3
|
const ShareUtils = {
|
|
4
4
|
getRegisteredShare,
|
package/dist/index.cjs.js
CHANGED
|
@@ -86,6 +86,7 @@ function registerPlugins$1(plugins, hookInstances) {
|
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
+
return plugins;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
function _extends$5() {
|
|
@@ -813,23 +814,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
813
814
|
}
|
|
814
815
|
}, true, memo, remoteSnapshot);
|
|
815
816
|
if (remoteSnapshot.shared) {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
819
|
-
// When data is downgraded, the shared configuration may be different.
|
|
820
|
-
if (!shareInfo) {
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
817
|
+
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
818
|
+
const registeredShared = share.getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
824
819
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
825
820
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
826
|
-
|
|
821
|
+
snapshotShared.assets.js.sync.forEach((asset)=>{
|
|
827
822
|
loadedSharedJsAssets.add(asset);
|
|
828
823
|
});
|
|
829
|
-
|
|
824
|
+
snapshotShared.assets.css.sync.forEach((asset)=>{
|
|
830
825
|
loadedSharedCssAssets.add(asset);
|
|
831
826
|
});
|
|
832
827
|
}
|
|
828
|
+
};
|
|
829
|
+
remoteSnapshot.shared.forEach((shared)=>{
|
|
830
|
+
var _options_shared;
|
|
831
|
+
const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
832
|
+
if (!shareInfos) {
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
// if no version, preload all shared
|
|
836
|
+
const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
|
|
837
|
+
if (!sharedOptions) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const arrayShareInfo = share.arrayOptions(sharedOptions);
|
|
841
|
+
arrayShareInfo.forEach((s)=>{
|
|
842
|
+
collectSharedAssets(s, shared);
|
|
843
|
+
});
|
|
833
844
|
});
|
|
834
845
|
}
|
|
835
846
|
const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
|
|
@@ -1114,13 +1125,16 @@ class FederationHost {
|
|
|
1114
1125
|
this.options = options;
|
|
1115
1126
|
return options;
|
|
1116
1127
|
}
|
|
1117
|
-
async loadShare(pkgName,
|
|
1118
|
-
var _this_options_shared;
|
|
1128
|
+
async loadShare(pkgName, extraOptions) {
|
|
1119
1129
|
// This function performs the following steps:
|
|
1120
1130
|
// 1. Checks if the currently loaded share already exists, if not, it throws an error
|
|
1121
1131
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1122
1132
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1123
|
-
const shareInfo =
|
|
1133
|
+
const shareInfo = share.getTargetSharedOptions({
|
|
1134
|
+
pkgName,
|
|
1135
|
+
extraOptions,
|
|
1136
|
+
shareInfos: this.options.shared
|
|
1137
|
+
});
|
|
1124
1138
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1125
1139
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1126
1140
|
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
@@ -1179,7 +1193,7 @@ class FederationHost {
|
|
|
1179
1193
|
});
|
|
1180
1194
|
return loading;
|
|
1181
1195
|
} else {
|
|
1182
|
-
if (customShareInfo) {
|
|
1196
|
+
if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
|
|
1183
1197
|
return false;
|
|
1184
1198
|
}
|
|
1185
1199
|
const asyncLoadProcess = async ()=>{
|
|
@@ -1210,9 +1224,12 @@ class FederationHost {
|
|
|
1210
1224
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1211
1225
|
// 2. If lib exists in local shared, it will be used directly
|
|
1212
1226
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1213
|
-
loadShareSync(pkgName,
|
|
1214
|
-
|
|
1215
|
-
|
|
1227
|
+
loadShareSync(pkgName, extraOptions) {
|
|
1228
|
+
const shareInfo = share.getTargetSharedOptions({
|
|
1229
|
+
pkgName,
|
|
1230
|
+
extraOptions,
|
|
1231
|
+
shareInfos: this.options.shared
|
|
1232
|
+
});
|
|
1216
1233
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1217
1234
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1218
1235
|
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
@@ -1451,10 +1468,12 @@ class FederationHost {
|
|
|
1451
1468
|
}
|
|
1452
1469
|
};
|
|
1453
1470
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1454
|
-
const
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1471
|
+
const sharedArr = this.options.shared[shareName];
|
|
1472
|
+
sharedArr.forEach((shared)=>{
|
|
1473
|
+
if (shared.scope.includes(shareScopeName)) {
|
|
1474
|
+
register(shareName, shared);
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1458
1477
|
});
|
|
1459
1478
|
if (strategy === 'version-first') {
|
|
1460
1479
|
this.options.remotes.forEach((remote)=>{
|
|
@@ -1475,7 +1494,19 @@ class FederationHost {
|
|
|
1475
1494
|
}
|
|
1476
1495
|
formatOptions(globalOptions, userOptions) {
|
|
1477
1496
|
const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
1478
|
-
const shared = _extends({}, globalOptions.shared
|
|
1497
|
+
const shared = _extends({}, globalOptions.shared);
|
|
1498
|
+
Object.keys(formatShareOptions).forEach((shareKey)=>{
|
|
1499
|
+
if (!shared[shareKey]) {
|
|
1500
|
+
shared[shareKey] = formatShareOptions[shareKey];
|
|
1501
|
+
} else {
|
|
1502
|
+
formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
|
|
1503
|
+
const isSameVersion = shared[shareKey].find((sharedVal)=>sharedVal.version === newUserSharedOptions.version);
|
|
1504
|
+
if (!isSameVersion) {
|
|
1505
|
+
shared[shareKey].push(newUserSharedOptions);
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1479
1510
|
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
1480
1511
|
origin: this,
|
|
1481
1512
|
userOptions,
|
|
@@ -1492,18 +1523,20 @@ class FederationHost {
|
|
|
1492
1523
|
// register shared in shareScopeMap
|
|
1493
1524
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1494
1525
|
sharedKeys.forEach((sharedKey)=>{
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1526
|
+
const sharedVals = formatShareOptions[sharedKey];
|
|
1527
|
+
sharedVals.forEach((sharedVal)=>{
|
|
1528
|
+
const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1529
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1530
|
+
this.setShared({
|
|
1531
|
+
pkgName: sharedKey,
|
|
1532
|
+
lib: sharedVal.lib,
|
|
1533
|
+
get: sharedVal.get,
|
|
1534
|
+
loaded: true,
|
|
1535
|
+
shared: sharedVal,
|
|
1536
|
+
from: userOptions.name
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1507
1540
|
});
|
|
1508
1541
|
const plugins = [
|
|
1509
1542
|
...globalOptionsRes.plugins
|
|
@@ -1527,11 +1560,18 @@ class FederationHost {
|
|
|
1527
1560
|
return optionsRes;
|
|
1528
1561
|
}
|
|
1529
1562
|
registerPlugins(plugins) {
|
|
1530
|
-
registerPlugins$1(plugins, [
|
|
1563
|
+
const pluginRes = registerPlugins$1(plugins, [
|
|
1531
1564
|
this.hooks,
|
|
1532
1565
|
this.snapshotHandler.hooks,
|
|
1533
1566
|
this.loaderHook
|
|
1534
1567
|
]);
|
|
1568
|
+
// Merge plugin
|
|
1569
|
+
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
1570
|
+
if (res && !res.find((item)=>item.name === plugin.name)) {
|
|
1571
|
+
res.push(plugin);
|
|
1572
|
+
}
|
|
1573
|
+
return res;
|
|
1574
|
+
}, pluginRes || []);
|
|
1535
1575
|
}
|
|
1536
1576
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1537
1577
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
@@ -1658,7 +1698,7 @@ class FederationHost {
|
|
|
1658
1698
|
// not used yet
|
|
1659
1699
|
afterPreloadRemote: new AsyncHook()
|
|
1660
1700
|
});
|
|
1661
|
-
this.version = "0.1.
|
|
1701
|
+
this.version = "0.1.6";
|
|
1662
1702
|
this.moduleCache = new Map();
|
|
1663
1703
|
this.loaderHook = new PluginSystem({
|
|
1664
1704
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as
|
|
2
|
-
export {
|
|
1
|
+
import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as getInfoWithoutType, m as getPreloaded, n as setPreloaded, o as getRegisteredShare, p as arrayOptions, q as getGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, t as setGlobalSnapshotInfoByModuleInfo, u as getGlobalSnapshot, G as Global, v as getGlobalShareScope, x as getTargetSharedOptions, y as formatShareConfigs, z as getBuilderId, A as isBrowserEnv, B as addUniqueItem, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
|
|
2
|
+
export { I as registerGlobalPlugins } from './share.esm.js';
|
|
3
3
|
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
4
4
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
5
5
|
|
|
@@ -84,6 +84,7 @@ function registerPlugins$1(plugins, hookInstances) {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
+
return plugins;
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
function _extends$5() {
|
|
@@ -811,23 +812,33 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
811
812
|
}
|
|
812
813
|
}, true, memo, remoteSnapshot);
|
|
813
814
|
if (remoteSnapshot.shared) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
817
|
-
// When data is downgraded, the shared configuration may be different.
|
|
818
|
-
if (!shareInfo) {
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
const registeredShared = getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
815
|
+
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
816
|
+
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
|
|
822
817
|
// If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
|
|
823
818
|
if (registeredShared && typeof registeredShared.lib === 'function') {
|
|
824
|
-
|
|
819
|
+
snapshotShared.assets.js.sync.forEach((asset)=>{
|
|
825
820
|
loadedSharedJsAssets.add(asset);
|
|
826
821
|
});
|
|
827
|
-
|
|
822
|
+
snapshotShared.assets.css.sync.forEach((asset)=>{
|
|
828
823
|
loadedSharedCssAssets.add(asset);
|
|
829
824
|
});
|
|
830
825
|
}
|
|
826
|
+
};
|
|
827
|
+
remoteSnapshot.shared.forEach((shared)=>{
|
|
828
|
+
var _options_shared;
|
|
829
|
+
const shareInfos = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
|
|
830
|
+
if (!shareInfos) {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
// if no version, preload all shared
|
|
834
|
+
const sharedOptions = shared.version ? shareInfos.find((s)=>s.version === shared.version) : shareInfos;
|
|
835
|
+
if (!sharedOptions) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
const arrayShareInfo = arrayOptions(sharedOptions);
|
|
839
|
+
arrayShareInfo.forEach((s)=>{
|
|
840
|
+
collectSharedAssets(s, shared);
|
|
841
|
+
});
|
|
831
842
|
});
|
|
832
843
|
}
|
|
833
844
|
const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
|
|
@@ -1112,13 +1123,16 @@ class FederationHost {
|
|
|
1112
1123
|
this.options = options;
|
|
1113
1124
|
return options;
|
|
1114
1125
|
}
|
|
1115
|
-
async loadShare(pkgName,
|
|
1116
|
-
var _this_options_shared;
|
|
1126
|
+
async loadShare(pkgName, extraOptions) {
|
|
1117
1127
|
// This function performs the following steps:
|
|
1118
1128
|
// 1. Checks if the currently loaded share already exists, if not, it throws an error
|
|
1119
1129
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
1120
1130
|
// 3. If not found, it retrieves it from the current share and stores the obtained share globally.
|
|
1121
|
-
const shareInfo =
|
|
1131
|
+
const shareInfo = getTargetSharedOptions({
|
|
1132
|
+
pkgName,
|
|
1133
|
+
extraOptions,
|
|
1134
|
+
shareInfos: this.options.shared
|
|
1135
|
+
});
|
|
1122
1136
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1123
1137
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1124
1138
|
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
@@ -1177,7 +1191,7 @@ class FederationHost {
|
|
|
1177
1191
|
});
|
|
1178
1192
|
return loading;
|
|
1179
1193
|
} else {
|
|
1180
|
-
if (customShareInfo) {
|
|
1194
|
+
if (extraOptions == null ? void 0 : extraOptions.customShareInfo) {
|
|
1181
1195
|
return false;
|
|
1182
1196
|
}
|
|
1183
1197
|
const asyncLoadProcess = async ()=>{
|
|
@@ -1208,9 +1222,12 @@ class FederationHost {
|
|
|
1208
1222
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1209
1223
|
// 2. If lib exists in local shared, it will be used directly
|
|
1210
1224
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1211
|
-
loadShareSync(pkgName,
|
|
1212
|
-
|
|
1213
|
-
|
|
1225
|
+
loadShareSync(pkgName, extraOptions) {
|
|
1226
|
+
const shareInfo = getTargetSharedOptions({
|
|
1227
|
+
pkgName,
|
|
1228
|
+
extraOptions,
|
|
1229
|
+
shareInfos: this.options.shared
|
|
1230
|
+
});
|
|
1214
1231
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1215
1232
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1216
1233
|
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
@@ -1449,10 +1466,12 @@ class FederationHost {
|
|
|
1449
1466
|
}
|
|
1450
1467
|
};
|
|
1451
1468
|
Object.keys(this.options.shared).forEach((shareName)=>{
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1469
|
+
const sharedArr = this.options.shared[shareName];
|
|
1470
|
+
sharedArr.forEach((shared)=>{
|
|
1471
|
+
if (shared.scope.includes(shareScopeName)) {
|
|
1472
|
+
register(shareName, shared);
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1456
1475
|
});
|
|
1457
1476
|
if (strategy === 'version-first') {
|
|
1458
1477
|
this.options.remotes.forEach((remote)=>{
|
|
@@ -1473,7 +1492,19 @@ class FederationHost {
|
|
|
1473
1492
|
}
|
|
1474
1493
|
formatOptions(globalOptions, userOptions) {
|
|
1475
1494
|
const formatShareOptions = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
1476
|
-
const shared = _extends({}, globalOptions.shared
|
|
1495
|
+
const shared = _extends({}, globalOptions.shared);
|
|
1496
|
+
Object.keys(formatShareOptions).forEach((shareKey)=>{
|
|
1497
|
+
if (!shared[shareKey]) {
|
|
1498
|
+
shared[shareKey] = formatShareOptions[shareKey];
|
|
1499
|
+
} else {
|
|
1500
|
+
formatShareOptions[shareKey].forEach((newUserSharedOptions)=>{
|
|
1501
|
+
const isSameVersion = shared[shareKey].find((sharedVal)=>sharedVal.version === newUserSharedOptions.version);
|
|
1502
|
+
if (!isSameVersion) {
|
|
1503
|
+
shared[shareKey].push(newUserSharedOptions);
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1477
1508
|
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
1478
1509
|
origin: this,
|
|
1479
1510
|
userOptions,
|
|
@@ -1490,18 +1521,20 @@ class FederationHost {
|
|
|
1490
1521
|
// register shared in shareScopeMap
|
|
1491
1522
|
const sharedKeys = Object.keys(formatShareOptions);
|
|
1492
1523
|
sharedKeys.forEach((sharedKey)=>{
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1524
|
+
const sharedVals = formatShareOptions[sharedKey];
|
|
1525
|
+
sharedVals.forEach((sharedVal)=>{
|
|
1526
|
+
const registeredShared = getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
|
|
1527
|
+
if (!registeredShared && sharedVal && sharedVal.lib) {
|
|
1528
|
+
this.setShared({
|
|
1529
|
+
pkgName: sharedKey,
|
|
1530
|
+
lib: sharedVal.lib,
|
|
1531
|
+
get: sharedVal.get,
|
|
1532
|
+
loaded: true,
|
|
1533
|
+
shared: sharedVal,
|
|
1534
|
+
from: userOptions.name
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1505
1538
|
});
|
|
1506
1539
|
const plugins = [
|
|
1507
1540
|
...globalOptionsRes.plugins
|
|
@@ -1525,11 +1558,18 @@ class FederationHost {
|
|
|
1525
1558
|
return optionsRes;
|
|
1526
1559
|
}
|
|
1527
1560
|
registerPlugins(plugins) {
|
|
1528
|
-
registerPlugins$1(plugins, [
|
|
1561
|
+
const pluginRes = registerPlugins$1(plugins, [
|
|
1529
1562
|
this.hooks,
|
|
1530
1563
|
this.snapshotHandler.hooks,
|
|
1531
1564
|
this.loaderHook
|
|
1532
1565
|
]);
|
|
1566
|
+
// Merge plugin
|
|
1567
|
+
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
1568
|
+
if (res && !res.find((item)=>item.name === plugin.name)) {
|
|
1569
|
+
res.push(plugin);
|
|
1570
|
+
}
|
|
1571
|
+
return res;
|
|
1572
|
+
}, pluginRes || []);
|
|
1533
1573
|
}
|
|
1534
1574
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1535
1575
|
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
@@ -1656,7 +1696,7 @@ class FederationHost {
|
|
|
1656
1696
|
// not used yet
|
|
1657
1697
|
afterPreloadRemote: new AsyncHook()
|
|
1658
1698
|
});
|
|
1659
|
-
this.version = "0.1.
|
|
1699
|
+
this.version = "0.1.6";
|
|
1660
1700
|
this.moduleCache = new Map();
|
|
1661
1701
|
this.loaderHook = new PluginSystem({
|
|
1662
1702
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -71,6 +71,11 @@ const objectToString = Object.prototype.toString;
|
|
|
71
71
|
function isPlainObject(val) {
|
|
72
72
|
return objectToString.call(val) === '[object Object]';
|
|
73
73
|
}
|
|
74
|
+
function arrayOptions(options) {
|
|
75
|
+
return Array.isArray(options) ? options : [
|
|
76
|
+
options
|
|
77
|
+
];
|
|
78
|
+
}
|
|
74
79
|
|
|
75
80
|
function _extends$1() {
|
|
76
81
|
_extends$1 = Object.assign || function(target) {
|
|
@@ -185,7 +190,7 @@ function getGlobalFederationConstructor() {
|
|
|
185
190
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
186
191
|
if (isDebug) {
|
|
187
192
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
188
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.
|
|
193
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.6";
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
196
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -640,15 +645,19 @@ function _extends() {
|
|
|
640
645
|
};
|
|
641
646
|
return _extends.apply(this, arguments);
|
|
642
647
|
}
|
|
643
|
-
function formatShare(shareArgs, from) {
|
|
648
|
+
function formatShare(shareArgs, from, name) {
|
|
644
649
|
let get;
|
|
645
650
|
if ('get' in shareArgs) {
|
|
646
651
|
// eslint-disable-next-line prefer-destructuring
|
|
647
652
|
get = shareArgs.get;
|
|
648
|
-
} else {
|
|
649
|
-
// @ts-ignore ignore
|
|
653
|
+
} else if ('lib' in shareArgs) {
|
|
650
654
|
get = ()=>Promise.resolve(shareArgs.lib);
|
|
655
|
+
} else {
|
|
656
|
+
get = ()=>Promise.resolve(()=>{
|
|
657
|
+
throw new Error(`Can not get shared '${name}'!`);
|
|
658
|
+
});
|
|
651
659
|
}
|
|
660
|
+
var _shareArgs_version;
|
|
652
661
|
return _extends({
|
|
653
662
|
deps: [],
|
|
654
663
|
useIn: [],
|
|
@@ -663,6 +672,7 @@ function formatShare(shareArgs, from) {
|
|
|
663
672
|
}, shareArgs.shareConfig),
|
|
664
673
|
get,
|
|
665
674
|
loaded: 'lib' in shareArgs ? true : undefined,
|
|
675
|
+
version: (_shareArgs_version = shareArgs.version) != null ? _shareArgs_version : '0',
|
|
666
676
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
667
677
|
'default'
|
|
668
678
|
],
|
|
@@ -674,7 +684,11 @@ function formatShareConfigs(shareArgs, from) {
|
|
|
674
684
|
return {};
|
|
675
685
|
}
|
|
676
686
|
return Object.keys(shareArgs).reduce((res, pkgName)=>{
|
|
677
|
-
|
|
687
|
+
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
688
|
+
res[pkgName] = res[pkgName] || [];
|
|
689
|
+
arrayShareArgs.forEach((shareConfig)=>{
|
|
690
|
+
res[pkgName].push(formatShare(shareConfig, from, pkgName));
|
|
691
|
+
});
|
|
678
692
|
return res;
|
|
679
693
|
}, {});
|
|
680
694
|
}
|
|
@@ -697,12 +711,11 @@ function versionLt(a, b) {
|
|
|
697
711
|
return false;
|
|
698
712
|
}
|
|
699
713
|
}
|
|
700
|
-
const findVersion = (
|
|
701
|
-
const versions = shareScopeMap[scope][pkgName];
|
|
714
|
+
const findVersion = (shareVersionMap, cb)=>{
|
|
702
715
|
const callback = cb || function(prev, cur) {
|
|
703
716
|
return versionLt(prev, cur);
|
|
704
717
|
};
|
|
705
|
-
return Object.keys(
|
|
718
|
+
return Object.keys(shareVersionMap).reduce((prev, cur)=>{
|
|
706
719
|
if (!prev) {
|
|
707
720
|
return cur;
|
|
708
721
|
}
|
|
@@ -724,7 +737,7 @@ function findSingletonVersionOrderByVersion(shareScopeMap, scope, pkgName) {
|
|
|
724
737
|
const callback = function(prev, cur) {
|
|
725
738
|
return !isLoaded(versions[prev]) && versionLt(prev, cur);
|
|
726
739
|
};
|
|
727
|
-
return findVersion(shareScopeMap
|
|
740
|
+
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
728
741
|
}
|
|
729
742
|
function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
730
743
|
const versions = shareScopeMap[scope][pkgName];
|
|
@@ -741,7 +754,7 @@ function findSingletonVersionOrderByLoaded(shareScopeMap, scope, pkgName) {
|
|
|
741
754
|
}
|
|
742
755
|
return versionLt(prev, cur);
|
|
743
756
|
};
|
|
744
|
-
return findVersion(shareScopeMap
|
|
757
|
+
return findVersion(shareScopeMap[scope][pkgName], callback);
|
|
745
758
|
}
|
|
746
759
|
function getFindShareFunction(strategy) {
|
|
747
760
|
if (strategy === 'loaded-first') {
|
|
@@ -804,12 +817,33 @@ function getRegisteredShare(localShareScopeMap, pkgName, shareInfo, resolveShare
|
|
|
804
817
|
function getGlobalShareScope() {
|
|
805
818
|
return Global.__FEDERATION__.__SHARE__;
|
|
806
819
|
}
|
|
820
|
+
function getTargetSharedOptions(options) {
|
|
821
|
+
const { pkgName, extraOptions, shareInfos } = options;
|
|
822
|
+
const defaultResolver = (sharedOptions)=>{
|
|
823
|
+
if (!sharedOptions) {
|
|
824
|
+
return undefined;
|
|
825
|
+
}
|
|
826
|
+
const shareVersionMap = {};
|
|
827
|
+
sharedOptions.forEach((shared)=>{
|
|
828
|
+
shareVersionMap[shared.version] = shared;
|
|
829
|
+
});
|
|
830
|
+
const callback = function(prev, cur) {
|
|
831
|
+
return !isLoaded(shareVersionMap[prev]) && versionLt(prev, cur);
|
|
832
|
+
};
|
|
833
|
+
const maxVersion = findVersion(shareVersionMap, callback);
|
|
834
|
+
return shareVersionMap[maxVersion];
|
|
835
|
+
};
|
|
836
|
+
var _extraOptions_resolver;
|
|
837
|
+
const resolver = (_extraOptions_resolver = extraOptions == null ? void 0 : extraOptions.resolver) != null ? _extraOptions_resolver : defaultResolver;
|
|
838
|
+
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
839
|
+
}
|
|
807
840
|
|
|
808
841
|
exports.DEFAULT_REMOTE_TYPE = DEFAULT_REMOTE_TYPE;
|
|
809
842
|
exports.DEFAULT_SCOPE = DEFAULT_SCOPE;
|
|
810
843
|
exports.Global = Global;
|
|
811
844
|
exports.addGlobalSnapshot = addGlobalSnapshot;
|
|
812
845
|
exports.addUniqueItem = addUniqueItem;
|
|
846
|
+
exports.arrayOptions = arrayOptions;
|
|
813
847
|
exports.assert = assert;
|
|
814
848
|
exports.error = error;
|
|
815
849
|
exports.formatShareConfigs = formatShareConfigs;
|
|
@@ -825,6 +859,7 @@ exports.getInfoWithoutType = getInfoWithoutType;
|
|
|
825
859
|
exports.getPreloaded = getPreloaded;
|
|
826
860
|
exports.getRegisteredShare = getRegisteredShare;
|
|
827
861
|
exports.getRemoteEntryExports = getRemoteEntryExports;
|
|
862
|
+
exports.getTargetSharedOptions = getTargetSharedOptions;
|
|
828
863
|
exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
|
|
829
864
|
exports.globalLoading = globalLoading;
|
|
830
865
|
exports.isBrowserEnv = isBrowserEnv;
|