@module-federation/runtime 0.0.0-next-20240508024041 → 0.0.0-next-20240511023318
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/index.cjs.js +189 -165
- package/dist/index.esm.js +189 -165
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +1 -1
- package/dist/src/core.d.ts +1 -20
- package/dist/src/remote/index.d.ts +25 -6
- package/dist/src/shared/index.d.ts +8 -6
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -87,8 +87,8 @@ function registerPlugins$1(plugins, hookInstances) {
|
|
|
87
87
|
return plugins;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
function _extends$
|
|
91
|
-
_extends$
|
|
90
|
+
function _extends$7() {
|
|
91
|
+
_extends$7 = Object.assign || function(target) {
|
|
92
92
|
for(var i = 1; i < arguments.length; i++){
|
|
93
93
|
var source = arguments[i];
|
|
94
94
|
for(var key in source){
|
|
@@ -99,7 +99,7 @@ function _extends$6() {
|
|
|
99
99
|
}
|
|
100
100
|
return target;
|
|
101
101
|
};
|
|
102
|
-
return _extends$
|
|
102
|
+
return _extends$7.apply(this, arguments);
|
|
103
103
|
}
|
|
104
104
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
105
105
|
return new Promise((resolve, reject)=>{
|
|
@@ -187,7 +187,7 @@ async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook
|
|
|
187
187
|
return globalLoading[uniqueKey];
|
|
188
188
|
}
|
|
189
189
|
function getRemoteInfo(remote) {
|
|
190
|
-
return _extends$
|
|
190
|
+
return _extends$7({}, remote, {
|
|
191
191
|
entry: 'entry' in remote ? remote.entry : '',
|
|
192
192
|
type: remote.type || DEFAULT_REMOTE_TYPE,
|
|
193
193
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
@@ -195,8 +195,8 @@ function getRemoteInfo(remote) {
|
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
function _extends$
|
|
199
|
-
_extends$
|
|
198
|
+
function _extends$6() {
|
|
199
|
+
_extends$6 = Object.assign || function(target) {
|
|
200
200
|
for(var i = 1; i < arguments.length; i++){
|
|
201
201
|
var source = arguments[i];
|
|
202
202
|
for(var key in source){
|
|
@@ -207,7 +207,7 @@ function _extends$5() {
|
|
|
207
207
|
}
|
|
208
208
|
return target;
|
|
209
209
|
};
|
|
210
|
-
return _extends$
|
|
210
|
+
return _extends$6.apply(this, arguments);
|
|
211
211
|
}
|
|
212
212
|
let Module = class Module {
|
|
213
213
|
async getEntry() {
|
|
@@ -269,7 +269,7 @@ let Module = class Module {
|
|
|
269
269
|
origin: this.host
|
|
270
270
|
});
|
|
271
271
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
272
|
-
await this.host.hooks.lifecycle.initContainer.emit(_extends$
|
|
272
|
+
await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
|
|
273
273
|
remoteEntryExports
|
|
274
274
|
}));
|
|
275
275
|
}
|
|
@@ -479,8 +479,8 @@ class PluginSystem {
|
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
481
|
|
|
482
|
-
function _extends$
|
|
483
|
-
_extends$
|
|
482
|
+
function _extends$5() {
|
|
483
|
+
_extends$5 = Object.assign || function(target) {
|
|
484
484
|
for(var i = 1; i < arguments.length; i++){
|
|
485
485
|
var source = arguments[i];
|
|
486
486
|
for(var key in source){
|
|
@@ -491,10 +491,10 @@ function _extends$4() {
|
|
|
491
491
|
}
|
|
492
492
|
return target;
|
|
493
493
|
};
|
|
494
|
-
return _extends$
|
|
494
|
+
return _extends$5.apply(this, arguments);
|
|
495
495
|
}
|
|
496
496
|
function defaultPreloadArgs(preloadConfig) {
|
|
497
|
-
return _extends$
|
|
497
|
+
return _extends$5({
|
|
498
498
|
resourceCategory: 'sync',
|
|
499
499
|
share: true,
|
|
500
500
|
depsRemote: true,
|
|
@@ -601,8 +601,8 @@ function preloadAssets(remoteInfo, host, assets) {
|
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
603
|
|
|
604
|
-
function _extends$
|
|
605
|
-
_extends$
|
|
604
|
+
function _extends$4() {
|
|
605
|
+
_extends$4 = Object.assign || function(target) {
|
|
606
606
|
for(var i = 1; i < arguments.length; i++){
|
|
607
607
|
var source = arguments[i];
|
|
608
608
|
for(var key in source){
|
|
@@ -613,7 +613,7 @@ function _extends$3() {
|
|
|
613
613
|
}
|
|
614
614
|
return target;
|
|
615
615
|
};
|
|
616
|
-
return _extends$
|
|
616
|
+
return _extends$4.apply(this, arguments);
|
|
617
617
|
}
|
|
618
618
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
619
619
|
if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
|
|
@@ -659,7 +659,7 @@ function snapshotPlugin() {
|
|
|
659
659
|
if (assets) {
|
|
660
660
|
preloadAssets(remoteInfo, origin, assets);
|
|
661
661
|
}
|
|
662
|
-
return _extends$
|
|
662
|
+
return _extends$4({}, args, {
|
|
663
663
|
remoteSnapshot
|
|
664
664
|
});
|
|
665
665
|
}
|
|
@@ -880,8 +880,8 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
880
880
|
};
|
|
881
881
|
};
|
|
882
882
|
|
|
883
|
-
function _extends$
|
|
884
|
-
_extends$
|
|
883
|
+
function _extends$3() {
|
|
884
|
+
_extends$3 = Object.assign || function(target) {
|
|
885
885
|
for(var i = 1; i < arguments.length; i++){
|
|
886
886
|
var source = arguments[i];
|
|
887
887
|
for(var key in source){
|
|
@@ -892,7 +892,7 @@ function _extends$2() {
|
|
|
892
892
|
}
|
|
893
893
|
return target;
|
|
894
894
|
};
|
|
895
|
-
return _extends$
|
|
895
|
+
return _extends$3.apply(this, arguments);
|
|
896
896
|
}
|
|
897
897
|
class SnapshotHandler {
|
|
898
898
|
async loadSnapshot(moduleInfo) {
|
|
@@ -935,7 +935,7 @@ class SnapshotHandler {
|
|
|
935
935
|
// This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
|
|
936
936
|
if (hostSnapshot && 'remotesInfo' in hostSnapshot && !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
937
937
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
938
|
-
hostSnapshot.remotesInfo = _extends$
|
|
938
|
+
hostSnapshot.remotesInfo = _extends$3({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
|
|
939
939
|
[moduleInfo.name]: {
|
|
940
940
|
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
941
941
|
}
|
|
@@ -955,7 +955,7 @@ class SnapshotHandler {
|
|
|
955
955
|
if (isManifestProvider(globalRemoteSnapshot)) {
|
|
956
956
|
const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
|
|
957
957
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
958
|
-
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$
|
|
958
|
+
const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
|
|
959
959
|
// The global remote may be overridden
|
|
960
960
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
961
961
|
entry: globalRemoteSnapshot.remoteEntry
|
|
@@ -1083,8 +1083,8 @@ class SnapshotHandler {
|
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
1085
|
|
|
1086
|
-
function _extends$
|
|
1087
|
-
_extends$
|
|
1086
|
+
function _extends$2() {
|
|
1087
|
+
_extends$2 = Object.assign || function(target) {
|
|
1088
1088
|
for(var i = 1; i < arguments.length; i++){
|
|
1089
1089
|
var source = arguments[i];
|
|
1090
1090
|
for(var key in source){
|
|
@@ -1095,7 +1095,7 @@ function _extends$1() {
|
|
|
1095
1095
|
}
|
|
1096
1096
|
return target;
|
|
1097
1097
|
};
|
|
1098
|
-
return _extends$
|
|
1098
|
+
return _extends$2.apply(this, arguments);
|
|
1099
1099
|
}
|
|
1100
1100
|
function _object_without_properties_loose(source, excluded) {
|
|
1101
1101
|
if (source == null) return {};
|
|
@@ -1112,7 +1112,7 @@ function _object_without_properties_loose(source, excluded) {
|
|
|
1112
1112
|
class SharedHandler {
|
|
1113
1113
|
formatShareConfigs(globalOptions, userOptions) {
|
|
1114
1114
|
const shareInfos = formatShareConfigs(userOptions.shared || {}, userOptions.name);
|
|
1115
|
-
const shared = _extends$
|
|
1115
|
+
const shared = _extends$2({}, globalOptions.shared);
|
|
1116
1116
|
Object.keys(shareInfos).forEach((shareKey)=>{
|
|
1117
1117
|
if (!shared[shareKey]) {
|
|
1118
1118
|
shared[shareKey] = shareInfos[shareKey];
|
|
@@ -1150,7 +1150,8 @@ class SharedHandler {
|
|
|
1150
1150
|
});
|
|
1151
1151
|
});
|
|
1152
1152
|
}
|
|
1153
|
-
async loadShare(
|
|
1153
|
+
async loadShare(pkgName, extraOptions) {
|
|
1154
|
+
const { host } = this;
|
|
1154
1155
|
// This function performs the following steps:
|
|
1155
1156
|
// 1. Checks if the currently loaded share already exists, if not, it throws an error
|
|
1156
1157
|
// 2. Searches globally for a matching share, if found, it uses it directly
|
|
@@ -1158,30 +1159,30 @@ class SharedHandler {
|
|
|
1158
1159
|
const shareInfo = getTargetSharedOptions({
|
|
1159
1160
|
pkgName,
|
|
1160
1161
|
extraOptions,
|
|
1161
|
-
shareInfos:
|
|
1162
|
+
shareInfos: host.options.shared
|
|
1162
1163
|
});
|
|
1163
1164
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1164
1165
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1165
|
-
await Promise.all(this.initializeSharing(
|
|
1166
|
+
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
1166
1167
|
return;
|
|
1167
1168
|
}));
|
|
1168
1169
|
}
|
|
1169
1170
|
const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
|
|
1170
1171
|
pkgName,
|
|
1171
1172
|
shareInfo,
|
|
1172
|
-
shared:
|
|
1173
|
-
origin:
|
|
1173
|
+
shared: host.options.shared,
|
|
1174
|
+
origin: host
|
|
1174
1175
|
});
|
|
1175
1176
|
const { shareInfo: shareInfoRes } = loadShareRes;
|
|
1176
1177
|
// Assert that shareInfoRes exists, if not, throw an error
|
|
1177
|
-
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${
|
|
1178
|
+
assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${host.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
|
|
1178
1179
|
// Retrieve from cache
|
|
1179
1180
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
|
|
1180
1181
|
const addUseIn = (shared)=>{
|
|
1181
1182
|
if (!shared.useIn) {
|
|
1182
1183
|
shared.useIn = [];
|
|
1183
1184
|
}
|
|
1184
|
-
addUniqueItem(shared.useIn,
|
|
1185
|
+
addUniqueItem(shared.useIn, host.options.name);
|
|
1185
1186
|
};
|
|
1186
1187
|
if (registeredShared && registeredShared.lib) {
|
|
1187
1188
|
addUseIn(registeredShared);
|
|
@@ -1212,7 +1213,7 @@ class SharedHandler {
|
|
|
1212
1213
|
pkgName,
|
|
1213
1214
|
loaded: false,
|
|
1214
1215
|
shared: registeredShared,
|
|
1215
|
-
from:
|
|
1216
|
+
from: host.options.name,
|
|
1216
1217
|
lib: null,
|
|
1217
1218
|
loading
|
|
1218
1219
|
});
|
|
@@ -1238,7 +1239,7 @@ class SharedHandler {
|
|
|
1238
1239
|
pkgName,
|
|
1239
1240
|
loaded: false,
|
|
1240
1241
|
shared: shareInfoRes,
|
|
1241
|
-
from:
|
|
1242
|
+
from: host.options.name,
|
|
1242
1243
|
lib: null,
|
|
1243
1244
|
loading
|
|
1244
1245
|
});
|
|
@@ -1250,9 +1251,10 @@ class SharedHandler {
|
|
|
1250
1251
|
* It accepts one argument, the name of the share scope.
|
|
1251
1252
|
* If the share scope does not exist, it creates one.
|
|
1252
1253
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1253
|
-
initializeSharing(
|
|
1254
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE, strategy) {
|
|
1255
|
+
const { host } = this;
|
|
1254
1256
|
const shareScope = this.shareScopeMap;
|
|
1255
|
-
const hostName =
|
|
1257
|
+
const hostName = host.options.name;
|
|
1256
1258
|
// Creates a new share scope if necessary
|
|
1257
1259
|
if (!shareScope[shareScopeName]) {
|
|
1258
1260
|
shareScope[shareScopeName] = {};
|
|
@@ -1273,9 +1275,8 @@ class SharedHandler {
|
|
|
1273
1275
|
const promises = [];
|
|
1274
1276
|
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1275
1277
|
const initRemoteModule = async (key)=>{
|
|
1276
|
-
const { module } = await getRemoteModuleAndOptions({
|
|
1277
|
-
id: key
|
|
1278
|
-
origin
|
|
1278
|
+
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
1279
|
+
id: key
|
|
1279
1280
|
});
|
|
1280
1281
|
if (module.getEntry) {
|
|
1281
1282
|
const entry = await module.getEntry();
|
|
@@ -1285,8 +1286,8 @@ class SharedHandler {
|
|
|
1285
1286
|
}
|
|
1286
1287
|
}
|
|
1287
1288
|
};
|
|
1288
|
-
Object.keys(
|
|
1289
|
-
const sharedArr =
|
|
1289
|
+
Object.keys(host.options.shared).forEach((shareName)=>{
|
|
1290
|
+
const sharedArr = host.options.shared[shareName];
|
|
1290
1291
|
sharedArr.forEach((shared)=>{
|
|
1291
1292
|
if (shared.scope.includes(shareScopeName)) {
|
|
1292
1293
|
register(shareName, shared);
|
|
@@ -1294,7 +1295,7 @@ class SharedHandler {
|
|
|
1294
1295
|
});
|
|
1295
1296
|
});
|
|
1296
1297
|
if (strategy === 'version-first') {
|
|
1297
|
-
|
|
1298
|
+
host.options.remotes.forEach((remote)=>{
|
|
1298
1299
|
if (remote.shareScope === shareScopeName) {
|
|
1299
1300
|
promises.push(initRemoteModule(remote.name));
|
|
1300
1301
|
}
|
|
@@ -1306,15 +1307,16 @@ class SharedHandler {
|
|
|
1306
1307
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1307
1308
|
// 2. If lib exists in local shared, it will be used directly
|
|
1308
1309
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1309
|
-
loadShareSync(
|
|
1310
|
+
loadShareSync(pkgName, extraOptions) {
|
|
1311
|
+
const { host } = this;
|
|
1310
1312
|
const shareInfo = getTargetSharedOptions({
|
|
1311
1313
|
pkgName,
|
|
1312
1314
|
extraOptions,
|
|
1313
|
-
shareInfos:
|
|
1315
|
+
shareInfos: host.options.shared
|
|
1314
1316
|
});
|
|
1315
1317
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1316
1318
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1317
|
-
this.initializeSharing(
|
|
1319
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1318
1320
|
});
|
|
1319
1321
|
}
|
|
1320
1322
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
@@ -1322,14 +1324,14 @@ class SharedHandler {
|
|
|
1322
1324
|
if (!shared.useIn) {
|
|
1323
1325
|
shared.useIn = [];
|
|
1324
1326
|
}
|
|
1325
|
-
addUniqueItem(shared.useIn,
|
|
1327
|
+
addUniqueItem(shared.useIn, host.options.name);
|
|
1326
1328
|
};
|
|
1327
1329
|
if (registeredShared) {
|
|
1328
1330
|
if (typeof registeredShared.lib === 'function') {
|
|
1329
1331
|
addUseIn(registeredShared);
|
|
1330
1332
|
if (!registeredShared.loaded) {
|
|
1331
1333
|
registeredShared.loaded = true;
|
|
1332
|
-
if (registeredShared.from ===
|
|
1334
|
+
if (registeredShared.from === host.options.name) {
|
|
1333
1335
|
shareInfo.loaded = true;
|
|
1334
1336
|
}
|
|
1335
1337
|
}
|
|
@@ -1342,7 +1344,7 @@ class SharedHandler {
|
|
|
1342
1344
|
this.setShared({
|
|
1343
1345
|
pkgName,
|
|
1344
1346
|
loaded: true,
|
|
1345
|
-
from:
|
|
1347
|
+
from: host.options.name,
|
|
1346
1348
|
lib: module,
|
|
1347
1349
|
shared: registeredShared
|
|
1348
1350
|
});
|
|
@@ -1360,7 +1362,7 @@ class SharedHandler {
|
|
|
1360
1362
|
const module = shareInfo.get();
|
|
1361
1363
|
if (module instanceof Promise) {
|
|
1362
1364
|
throw new Error(`
|
|
1363
|
-
The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${
|
|
1365
|
+
The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${host.options.name}.
|
|
1364
1366
|
Possible reasons for failure: \n
|
|
1365
1367
|
1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
|
|
1366
1368
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
@@ -1370,25 +1372,26 @@ class SharedHandler {
|
|
|
1370
1372
|
this.setShared({
|
|
1371
1373
|
pkgName,
|
|
1372
1374
|
loaded: true,
|
|
1373
|
-
from:
|
|
1375
|
+
from: host.options.name,
|
|
1374
1376
|
lib: shareInfo.lib,
|
|
1375
1377
|
shared: shareInfo
|
|
1376
1378
|
});
|
|
1377
1379
|
return shareInfo.lib;
|
|
1378
1380
|
}
|
|
1379
1381
|
throw new Error(`
|
|
1380
|
-
The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${
|
|
1382
|
+
The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${host.options.name}.
|
|
1381
1383
|
Possible reasons for failure: \n
|
|
1382
1384
|
1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
|
|
1383
1385
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1384
1386
|
`);
|
|
1385
1387
|
}
|
|
1386
|
-
initShareScopeMap(
|
|
1388
|
+
initShareScopeMap(scopeName, shareScope) {
|
|
1389
|
+
const { host } = this;
|
|
1387
1390
|
this.shareScopeMap[scopeName] = shareScope;
|
|
1388
1391
|
this.hooks.lifecycle.initContainerShareScopeMap.emit({
|
|
1389
1392
|
shareScope,
|
|
1390
|
-
options:
|
|
1391
|
-
origin:
|
|
1393
|
+
options: host.options,
|
|
1394
|
+
origin: host
|
|
1392
1395
|
});
|
|
1393
1396
|
}
|
|
1394
1397
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
@@ -1409,7 +1412,7 @@ class SharedHandler {
|
|
|
1409
1412
|
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1410
1413
|
return;
|
|
1411
1414
|
}
|
|
1412
|
-
this.shareScopeMap[sc][pkgName][version] = _extends$
|
|
1415
|
+
this.shareScopeMap[sc][pkgName][version] = _extends$2({
|
|
1413
1416
|
version,
|
|
1414
1417
|
scope: [
|
|
1415
1418
|
'default'
|
|
@@ -1431,7 +1434,7 @@ class SharedHandler {
|
|
|
1431
1434
|
globalShareScopeMap[identifier] = this.shareScopeMap;
|
|
1432
1435
|
}
|
|
1433
1436
|
}
|
|
1434
|
-
constructor(
|
|
1437
|
+
constructor(host){
|
|
1435
1438
|
this.hooks = new PluginSystem({
|
|
1436
1439
|
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1437
1440
|
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
@@ -1441,16 +1444,31 @@ class SharedHandler {
|
|
|
1441
1444
|
// maybe will change, temporarily for internal use only
|
|
1442
1445
|
initContainerShareScopeMap: new AsyncWaterfallHook('initContainer')
|
|
1443
1446
|
});
|
|
1447
|
+
this.host = host;
|
|
1444
1448
|
this.shareScopeMap = {};
|
|
1445
|
-
this._setGlobalShareScopeMap(
|
|
1449
|
+
this._setGlobalShareScopeMap(host.options);
|
|
1446
1450
|
}
|
|
1447
1451
|
}
|
|
1448
1452
|
|
|
1453
|
+
function _extends$1() {
|
|
1454
|
+
_extends$1 = Object.assign || function(target) {
|
|
1455
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1456
|
+
var source = arguments[i];
|
|
1457
|
+
for(var key in source){
|
|
1458
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1459
|
+
target[key] = source[key];
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
return target;
|
|
1464
|
+
};
|
|
1465
|
+
return _extends$1.apply(this, arguments);
|
|
1466
|
+
}
|
|
1449
1467
|
class RemoteHandler {
|
|
1450
|
-
|
|
1468
|
+
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
1451
1469
|
const userRemotes = userOptions.remotes || [];
|
|
1452
1470
|
return userRemotes.reduce((res, remote)=>{
|
|
1453
|
-
this.registerRemote(
|
|
1471
|
+
this.registerRemote(remote, res, {
|
|
1454
1472
|
force: false
|
|
1455
1473
|
});
|
|
1456
1474
|
return res;
|
|
@@ -1458,7 +1476,8 @@ class RemoteHandler {
|
|
|
1458
1476
|
}
|
|
1459
1477
|
// eslint-disable-next-line max-lines-per-function
|
|
1460
1478
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1461
|
-
async loadRemote(
|
|
1479
|
+
async loadRemote(id, options) {
|
|
1480
|
+
const { host } = this;
|
|
1462
1481
|
try {
|
|
1463
1482
|
const { loadFactory = true } = options || {
|
|
1464
1483
|
loadFactory: true
|
|
@@ -1470,9 +1489,8 @@ class RemoteHandler {
|
|
|
1470
1489
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
1471
1490
|
// id: alias(app1) + expose(button) = app1/button
|
|
1472
1491
|
// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
|
|
1473
|
-
const { module, moduleOptions, remoteMatchInfo } = await getRemoteModuleAndOptions({
|
|
1474
|
-
id
|
|
1475
|
-
origin: origin
|
|
1492
|
+
const { module, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({
|
|
1493
|
+
id
|
|
1476
1494
|
});
|
|
1477
1495
|
const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
|
|
1478
1496
|
const moduleOrFactory = await module.get(expose, options);
|
|
@@ -1485,7 +1503,7 @@ class RemoteHandler {
|
|
|
1485
1503
|
remote,
|
|
1486
1504
|
options: moduleOptions,
|
|
1487
1505
|
moduleInstance: module,
|
|
1488
|
-
origin:
|
|
1506
|
+
origin: host
|
|
1489
1507
|
});
|
|
1490
1508
|
if (typeof moduleWrapper === 'function') {
|
|
1491
1509
|
return moduleWrapper;
|
|
@@ -1500,7 +1518,7 @@ class RemoteHandler {
|
|
|
1500
1518
|
error,
|
|
1501
1519
|
from,
|
|
1502
1520
|
lifecycle: 'onLoad',
|
|
1503
|
-
origin:
|
|
1521
|
+
origin: host
|
|
1504
1522
|
});
|
|
1505
1523
|
if (!failOver) {
|
|
1506
1524
|
throw error;
|
|
@@ -1509,19 +1527,20 @@ class RemoteHandler {
|
|
|
1509
1527
|
}
|
|
1510
1528
|
}
|
|
1511
1529
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1512
|
-
async preloadRemote(
|
|
1530
|
+
async preloadRemote(preloadOptions) {
|
|
1531
|
+
const { host } = this;
|
|
1513
1532
|
await this.hooks.lifecycle.beforePreloadRemote.emit({
|
|
1514
1533
|
preloadOptions,
|
|
1515
|
-
options:
|
|
1516
|
-
origin:
|
|
1534
|
+
options: host.options,
|
|
1535
|
+
origin: host
|
|
1517
1536
|
});
|
|
1518
|
-
const preloadOps = formatPreloadArgs(
|
|
1537
|
+
const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
|
|
1519
1538
|
await Promise.all(preloadOps.map(async (ops)=>{
|
|
1520
1539
|
const { remote } = ops;
|
|
1521
1540
|
const remoteInfo = getRemoteInfo(remote);
|
|
1522
|
-
const { globalSnapshot, remoteSnapshot } = await
|
|
1541
|
+
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo(remote);
|
|
1523
1542
|
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
1524
|
-
origin:
|
|
1543
|
+
origin: host,
|
|
1525
1544
|
preloadOptions: ops,
|
|
1526
1545
|
remote,
|
|
1527
1546
|
remoteInfo,
|
|
@@ -1531,36 +1550,77 @@ class RemoteHandler {
|
|
|
1531
1550
|
if (!assets) {
|
|
1532
1551
|
return;
|
|
1533
1552
|
}
|
|
1534
|
-
preloadAssets(remoteInfo,
|
|
1553
|
+
preloadAssets(remoteInfo, host, assets);
|
|
1535
1554
|
}));
|
|
1536
1555
|
}
|
|
1537
|
-
registerRemotes(
|
|
1556
|
+
registerRemotes(remotes, options) {
|
|
1557
|
+
const { host } = this;
|
|
1538
1558
|
remotes.forEach((remote)=>{
|
|
1539
|
-
this.registerRemote(
|
|
1559
|
+
this.registerRemote(remote, host.options.remotes, {
|
|
1540
1560
|
force: options == null ? void 0 : options.force
|
|
1541
1561
|
});
|
|
1542
1562
|
});
|
|
1543
1563
|
}
|
|
1544
|
-
|
|
1545
|
-
const {
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1564
|
+
async getRemoteModuleAndOptions(options) {
|
|
1565
|
+
const { host } = this;
|
|
1566
|
+
const { id } = options;
|
|
1567
|
+
let loadRemoteArgs;
|
|
1568
|
+
try {
|
|
1569
|
+
loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
|
|
1570
|
+
id,
|
|
1571
|
+
options: host.options,
|
|
1572
|
+
origin: host
|
|
1573
|
+
});
|
|
1574
|
+
} catch (error) {
|
|
1575
|
+
loadRemoteArgs = await this.hooks.lifecycle.errorLoadRemote.emit({
|
|
1576
|
+
id,
|
|
1577
|
+
options: host.options,
|
|
1578
|
+
origin: host,
|
|
1579
|
+
from: 'runtime',
|
|
1580
|
+
error,
|
|
1581
|
+
lifecycle: 'beforeRequest'
|
|
1582
|
+
});
|
|
1583
|
+
if (!loadRemoteArgs) {
|
|
1584
|
+
throw error;
|
|
1559
1585
|
}
|
|
1560
|
-
origin.moduleCache.delete(remote.name);
|
|
1561
1586
|
}
|
|
1587
|
+
const { id: idRes } = loadRemoteArgs;
|
|
1588
|
+
const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
|
|
1589
|
+
assert(remoteSplitInfo, `
|
|
1590
|
+
Unable to locate ${idRes} in ${host.options.name}. Potential reasons for failure include:\n
|
|
1591
|
+
1. ${idRes} was not included in the 'remotes' parameter of ${host.options.name || 'the host'}.\n
|
|
1592
|
+
2. ${idRes} could not be found in the 'remotes' of ${host.options.name} with either 'name' or 'alias' attributes.
|
|
1593
|
+
3. ${idRes} is not online, injected, or loaded.
|
|
1594
|
+
4. ${idRes} cannot be accessed on the expected.
|
|
1595
|
+
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1596
|
+
`);
|
|
1597
|
+
const { remote: rawRemote } = remoteSplitInfo;
|
|
1598
|
+
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1599
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
|
|
1600
|
+
id: idRes
|
|
1601
|
+
}, remoteSplitInfo, {
|
|
1602
|
+
options: host.options,
|
|
1603
|
+
origin: host,
|
|
1604
|
+
remoteInfo
|
|
1605
|
+
}));
|
|
1606
|
+
const { remote, expose } = matchInfo;
|
|
1607
|
+
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1608
|
+
let module = host.moduleCache.get(remote.name);
|
|
1609
|
+
const moduleOptions = {
|
|
1610
|
+
host: host,
|
|
1611
|
+
remoteInfo
|
|
1612
|
+
};
|
|
1613
|
+
if (!module) {
|
|
1614
|
+
module = new Module(moduleOptions);
|
|
1615
|
+
host.moduleCache.set(remote.name, module);
|
|
1616
|
+
}
|
|
1617
|
+
return {
|
|
1618
|
+
module,
|
|
1619
|
+
moduleOptions,
|
|
1620
|
+
remoteMatchInfo: matchInfo
|
|
1621
|
+
};
|
|
1562
1622
|
}
|
|
1563
|
-
registerRemote(
|
|
1623
|
+
registerRemote(remote, targetRemotes, options) {
|
|
1564
1624
|
const normalizeRemote = ()=>{
|
|
1565
1625
|
if (remote.alias) {
|
|
1566
1626
|
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
@@ -1595,14 +1655,34 @@ class RemoteHandler {
|
|
|
1595
1655
|
];
|
|
1596
1656
|
if (options == null ? void 0 : options.force) {
|
|
1597
1657
|
// remove registered remote
|
|
1598
|
-
this.removeRemote(
|
|
1658
|
+
this.removeRemote(registeredRemote);
|
|
1599
1659
|
normalizeRemote();
|
|
1600
1660
|
targetRemotes.push(remote);
|
|
1601
1661
|
}
|
|
1602
1662
|
warn$1(messages.join(' '));
|
|
1603
1663
|
}
|
|
1604
1664
|
}
|
|
1605
|
-
|
|
1665
|
+
removeRemote(remote) {
|
|
1666
|
+
const { host } = this;
|
|
1667
|
+
const { name } = remote;
|
|
1668
|
+
const remoteIndex = host.options.remotes.findIndex((item)=>item.name === name);
|
|
1669
|
+
if (remoteIndex !== -1) {
|
|
1670
|
+
host.options.remotes.splice(remoteIndex, 1);
|
|
1671
|
+
}
|
|
1672
|
+
const loadedModule = host.moduleCache.get(remote.name);
|
|
1673
|
+
if (loadedModule) {
|
|
1674
|
+
const key = loadedModule.remoteInfo.entryGlobalName;
|
|
1675
|
+
if (globalThis[key]) {
|
|
1676
|
+
delete globalThis[key];
|
|
1677
|
+
}
|
|
1678
|
+
const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
|
|
1679
|
+
if (globalLoading[remoteEntryUniqueKey]) {
|
|
1680
|
+
delete globalLoading[remoteEntryUniqueKey];
|
|
1681
|
+
}
|
|
1682
|
+
host.moduleCache.delete(remote.name);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
constructor(host){
|
|
1606
1686
|
this.hooks = new PluginSystem({
|
|
1607
1687
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1608
1688
|
onLoad: new AsyncHook('onLoad'),
|
|
@@ -1613,6 +1693,7 @@ class RemoteHandler {
|
|
|
1613
1693
|
// not used yet
|
|
1614
1694
|
afterPreloadRemote: new AsyncHook()
|
|
1615
1695
|
});
|
|
1696
|
+
this.host = host;
|
|
1616
1697
|
}
|
|
1617
1698
|
}
|
|
1618
1699
|
|
|
@@ -1630,64 +1711,6 @@ function _extends() {
|
|
|
1630
1711
|
};
|
|
1631
1712
|
return _extends.apply(this, arguments);
|
|
1632
1713
|
}
|
|
1633
|
-
async function getRemoteModuleAndOptions(options) {
|
|
1634
|
-
const { id, origin } = options;
|
|
1635
|
-
let loadRemoteArgs;
|
|
1636
|
-
try {
|
|
1637
|
-
loadRemoteArgs = await origin.remoteHandler.hooks.lifecycle.beforeRequest.emit({
|
|
1638
|
-
id,
|
|
1639
|
-
options: origin.options,
|
|
1640
|
-
origin: origin
|
|
1641
|
-
});
|
|
1642
|
-
} catch (error) {
|
|
1643
|
-
loadRemoteArgs = await origin.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
|
|
1644
|
-
id,
|
|
1645
|
-
options: origin.options,
|
|
1646
|
-
origin: origin,
|
|
1647
|
-
from: 'runtime',
|
|
1648
|
-
error,
|
|
1649
|
-
lifecycle: 'beforeRequest'
|
|
1650
|
-
});
|
|
1651
|
-
if (!loadRemoteArgs) {
|
|
1652
|
-
throw error;
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
const { id: idRes } = loadRemoteArgs;
|
|
1656
|
-
const remoteSplitInfo = matchRemoteWithNameAndExpose(origin.options.remotes, idRes);
|
|
1657
|
-
assert(remoteSplitInfo, `
|
|
1658
|
-
Unable to locate ${idRes} in ${origin.options.name}. Potential reasons for failure include:\n
|
|
1659
|
-
1. ${idRes} was not included in the 'remotes' parameter of ${origin.options.name || 'the host'}.\n
|
|
1660
|
-
2. ${idRes} could not be found in the 'remotes' of ${origin.options.name} with either 'name' or 'alias' attributes.
|
|
1661
|
-
3. ${idRes} is not online, injected, or loaded.
|
|
1662
|
-
4. ${idRes} cannot be accessed on the expected.
|
|
1663
|
-
5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
|
|
1664
|
-
`);
|
|
1665
|
-
const { remote: rawRemote } = remoteSplitInfo;
|
|
1666
|
-
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1667
|
-
const matchInfo = await origin.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends({
|
|
1668
|
-
id: idRes
|
|
1669
|
-
}, remoteSplitInfo, {
|
|
1670
|
-
options: origin.options,
|
|
1671
|
-
origin: origin,
|
|
1672
|
-
remoteInfo
|
|
1673
|
-
}));
|
|
1674
|
-
const { remote, expose } = matchInfo;
|
|
1675
|
-
assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
|
|
1676
|
-
let module = origin.moduleCache.get(remote.name);
|
|
1677
|
-
const moduleOptions = {
|
|
1678
|
-
host: origin,
|
|
1679
|
-
remoteInfo
|
|
1680
|
-
};
|
|
1681
|
-
if (!module) {
|
|
1682
|
-
module = new Module(moduleOptions);
|
|
1683
|
-
origin.moduleCache.set(remote.name, module);
|
|
1684
|
-
}
|
|
1685
|
-
return {
|
|
1686
|
-
module,
|
|
1687
|
-
moduleOptions,
|
|
1688
|
-
remoteMatchInfo: matchInfo
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
1714
|
class FederationHost {
|
|
1692
1715
|
initOptions(userOptions) {
|
|
1693
1716
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -1696,17 +1719,17 @@ class FederationHost {
|
|
|
1696
1719
|
return options;
|
|
1697
1720
|
}
|
|
1698
1721
|
async loadShare(pkgName, extraOptions) {
|
|
1699
|
-
return this.sharedHandler.loadShare(
|
|
1722
|
+
return this.sharedHandler.loadShare(pkgName, extraOptions);
|
|
1700
1723
|
}
|
|
1701
1724
|
// The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
|
|
1702
1725
|
// 1. If the loaded shared already exists globally, then it will be reused
|
|
1703
1726
|
// 2. If lib exists in local shared, it will be used directly
|
|
1704
1727
|
// 3. If the local get returns something other than Promise, then it will be used directly
|
|
1705
1728
|
loadShareSync(pkgName, extraOptions) {
|
|
1706
|
-
return this.sharedHandler.loadShareSync(
|
|
1729
|
+
return this.sharedHandler.loadShareSync(pkgName, extraOptions);
|
|
1707
1730
|
}
|
|
1708
1731
|
initializeSharing(shareScopeName = DEFAULT_SCOPE, strategy) {
|
|
1709
|
-
return this.sharedHandler.initializeSharing(
|
|
1732
|
+
return this.sharedHandler.initializeSharing(shareScopeName, strategy);
|
|
1710
1733
|
}
|
|
1711
1734
|
initRawContainer(name, url, container) {
|
|
1712
1735
|
const remoteInfo = getRemoteInfo({
|
|
@@ -1724,25 +1747,26 @@ class FederationHost {
|
|
|
1724
1747
|
// eslint-disable-next-line max-lines-per-function
|
|
1725
1748
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1726
1749
|
async loadRemote(id, options) {
|
|
1727
|
-
return this.remoteHandler.loadRemote(
|
|
1750
|
+
return this.remoteHandler.loadRemote(id, options);
|
|
1728
1751
|
}
|
|
1729
1752
|
// eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1730
1753
|
async preloadRemote(preloadOptions) {
|
|
1731
|
-
return this.remoteHandler.preloadRemote(
|
|
1754
|
+
return this.remoteHandler.preloadRemote(preloadOptions);
|
|
1732
1755
|
}
|
|
1733
1756
|
initShareScopeMap(scopeName, shareScope) {
|
|
1734
|
-
this.sharedHandler.initShareScopeMap(
|
|
1757
|
+
this.sharedHandler.initShareScopeMap(scopeName, shareScope);
|
|
1735
1758
|
}
|
|
1736
1759
|
formatOptions(globalOptions, userOptions) {
|
|
1737
|
-
const { shared
|
|
1760
|
+
const { shared } = this.sharedHandler.formatShareConfigs(globalOptions, userOptions);
|
|
1738
1761
|
const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
|
|
1739
1762
|
origin: this,
|
|
1740
1763
|
userOptions,
|
|
1741
1764
|
options: globalOptions,
|
|
1742
1765
|
shareInfo: shared
|
|
1743
1766
|
});
|
|
1744
|
-
const
|
|
1745
|
-
this.
|
|
1767
|
+
const { shared: handledShared, shareInfos: handledShareInfos } = this.sharedHandler.formatShareConfigs(globalOptions, userOptions);
|
|
1768
|
+
const remotes = this.remoteHandler.formatAndRegisterRemote(globalOptionsRes, userOptionsRes);
|
|
1769
|
+
this.sharedHandler.registerShared(handledShareInfos, userOptions);
|
|
1746
1770
|
const plugins = [
|
|
1747
1771
|
...globalOptionsRes.plugins
|
|
1748
1772
|
];
|
|
@@ -1756,7 +1780,7 @@ class FederationHost {
|
|
|
1756
1780
|
const optionsRes = _extends({}, globalOptions, userOptions, {
|
|
1757
1781
|
plugins,
|
|
1758
1782
|
remotes,
|
|
1759
|
-
shared
|
|
1783
|
+
shared: handledShared
|
|
1760
1784
|
});
|
|
1761
1785
|
this.hooks.lifecycle.init.emit({
|
|
1762
1786
|
origin: this,
|
|
@@ -1782,7 +1806,7 @@ class FederationHost {
|
|
|
1782
1806
|
}, pluginRes || []);
|
|
1783
1807
|
}
|
|
1784
1808
|
registerRemotes(remotes, options) {
|
|
1785
|
-
return this.remoteHandler.registerRemotes(
|
|
1809
|
+
return this.remoteHandler.registerRemotes(remotes, options);
|
|
1786
1810
|
}
|
|
1787
1811
|
constructor(userOptions){
|
|
1788
1812
|
this.hooks = new PluginSystem({
|
|
@@ -1793,7 +1817,7 @@ class FederationHost {
|
|
|
1793
1817
|
// maybe will change, temporarily for internal use only
|
|
1794
1818
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1795
1819
|
});
|
|
1796
|
-
this.version = "0.1.
|
|
1820
|
+
this.version = "0.1.12";
|
|
1797
1821
|
this.moduleCache = new Map();
|
|
1798
1822
|
this.loaderHook = new PluginSystem({
|
|
1799
1823
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -1819,8 +1843,8 @@ class FederationHost {
|
|
|
1819
1843
|
this.name = userOptions.name;
|
|
1820
1844
|
this.options = defaultOptions;
|
|
1821
1845
|
this.snapshotHandler = new SnapshotHandler(this);
|
|
1822
|
-
this.sharedHandler = new SharedHandler(this
|
|
1823
|
-
this.remoteHandler = new RemoteHandler();
|
|
1846
|
+
this.sharedHandler = new SharedHandler(this);
|
|
1847
|
+
this.remoteHandler = new RemoteHandler(this);
|
|
1824
1848
|
this.shareScopeMap = this.sharedHandler.shareScopeMap;
|
|
1825
1849
|
this.registerPlugins([
|
|
1826
1850
|
...defaultOptions.plugins,
|