@module-federation/runtime-core 0.16.0 → 0.17.1
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.cjs +237 -227
- package/dist/index.esm.js +238 -228
- package/dist/src/core.d.ts +7 -6
- package/dist/src/global.d.ts +10 -10
- package/dist/src/helpers.d.ts +7 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/module/index.d.ts +3 -3
- package/dist/src/plugins/generate-preload-assets.d.ts +4 -4
- package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +6 -6
- package/dist/src/plugins/snapshot/index.d.ts +2 -2
- package/dist/src/remote/index.d.ts +14 -14
- package/dist/src/shared/index.d.ts +7 -7
- package/dist/src/type/config.d.ts +2 -2
- package/dist/src/type/plugin.d.ts +4 -3
- package/dist/src/utils/hooks/pluginSystem.d.ts +3 -2
- package/dist/src/utils/load.d.ts +2 -2
- package/dist/src/utils/plugin.d.ts +2 -3
- package/dist/src/utils/preload.d.ts +2 -2
- package/dist/src/utils/share.d.ts +1 -1
- package/package.json +10 -10
- /package/dist/{index.esm.d.ts → index.d.ts} +0 -0
- /package/dist/{types.esm.d.ts → types.d.ts} +0 -0
package/dist/index.cjs.cjs
CHANGED
|
@@ -15,14 +15,20 @@ function assert(condition, msg) {
|
|
|
15
15
|
}
|
|
16
16
|
function error(msg) {
|
|
17
17
|
if (msg instanceof Error) {
|
|
18
|
-
|
|
18
|
+
// Check if the message already starts with the log category to avoid duplication
|
|
19
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) {
|
|
20
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
21
|
+
}
|
|
19
22
|
throw msg;
|
|
20
23
|
}
|
|
21
24
|
throw new Error(`${LOG_CATEGORY}: ${msg}`);
|
|
22
25
|
}
|
|
23
26
|
function warn(msg) {
|
|
24
27
|
if (msg instanceof Error) {
|
|
25
|
-
|
|
28
|
+
// Check if the message already starts with the log category to avoid duplication
|
|
29
|
+
if (!msg.message.startsWith(LOG_CATEGORY)) {
|
|
30
|
+
msg.message = `${LOG_CATEGORY}: ${msg.message}`;
|
|
31
|
+
}
|
|
26
32
|
logger.warn(msg);
|
|
27
33
|
} else {
|
|
28
34
|
logger.warn(msg);
|
|
@@ -196,7 +202,7 @@ function getGlobalFederationConstructor() {
|
|
|
196
202
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
197
203
|
if (isDebug) {
|
|
198
204
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
199
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
205
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.17.1";
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
208
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -943,34 +949,6 @@ function getTargetSharedOptions(options) {
|
|
|
943
949
|
return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
|
|
944
950
|
}
|
|
945
951
|
|
|
946
|
-
const ShareUtils = {
|
|
947
|
-
getRegisteredShare,
|
|
948
|
-
getGlobalShareScope
|
|
949
|
-
};
|
|
950
|
-
const GlobalUtils = {
|
|
951
|
-
Global,
|
|
952
|
-
nativeGlobal,
|
|
953
|
-
resetFederationGlobalInfo,
|
|
954
|
-
setGlobalFederationInstance,
|
|
955
|
-
getGlobalFederationConstructor,
|
|
956
|
-
setGlobalFederationConstructor,
|
|
957
|
-
getInfoWithoutType,
|
|
958
|
-
getGlobalSnapshot,
|
|
959
|
-
getTargetSnapshotInfoByModuleInfo,
|
|
960
|
-
getGlobalSnapshotInfoByModuleInfo,
|
|
961
|
-
setGlobalSnapshotInfoByModuleInfo,
|
|
962
|
-
addGlobalSnapshot,
|
|
963
|
-
getRemoteEntryExports,
|
|
964
|
-
registerGlobalPlugins,
|
|
965
|
-
getGlobalHostPlugins,
|
|
966
|
-
getPreloaded,
|
|
967
|
-
setPreloaded
|
|
968
|
-
};
|
|
969
|
-
var helpers = {
|
|
970
|
-
global: GlobalUtils,
|
|
971
|
-
share: ShareUtils
|
|
972
|
-
};
|
|
973
|
-
|
|
974
952
|
function getBuilderId() {
|
|
975
953
|
//@ts-ignore
|
|
976
954
|
return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
|
|
@@ -1040,8 +1018,16 @@ function matchRemote(remotes, nameOrAlias) {
|
|
|
1040
1018
|
return;
|
|
1041
1019
|
}
|
|
1042
1020
|
|
|
1043
|
-
function registerPlugins(plugins,
|
|
1021
|
+
function registerPlugins(plugins, instance) {
|
|
1044
1022
|
const globalPlugins = getGlobalHostPlugins();
|
|
1023
|
+
const hookInstances = [
|
|
1024
|
+
instance.hooks,
|
|
1025
|
+
instance.remoteHandler.hooks,
|
|
1026
|
+
instance.sharedHandler.hooks,
|
|
1027
|
+
instance.snapshotHandler.hooks,
|
|
1028
|
+
instance.loaderHook,
|
|
1029
|
+
instance.bridgeHook
|
|
1030
|
+
];
|
|
1045
1031
|
// Incorporate global plugins
|
|
1046
1032
|
if (globalPlugins.length > 0) {
|
|
1047
1033
|
globalPlugins.forEach((plugin)=>{
|
|
@@ -1053,7 +1039,7 @@ function registerPlugins(plugins, hookInstances) {
|
|
|
1053
1039
|
if (plugins && plugins.length > 0) {
|
|
1054
1040
|
plugins.forEach((plugin)=>{
|
|
1055
1041
|
hookInstances.forEach((hookInstance)=>{
|
|
1056
|
-
hookInstance.applyPlugin(plugin);
|
|
1042
|
+
hookInstance.applyPlugin(plugin, instance);
|
|
1057
1043
|
});
|
|
1058
1044
|
});
|
|
1059
1045
|
}
|
|
@@ -1240,6 +1226,202 @@ function getRemoteInfo(remote) {
|
|
|
1240
1226
|
});
|
|
1241
1227
|
}
|
|
1242
1228
|
|
|
1229
|
+
function defaultPreloadArgs(preloadConfig) {
|
|
1230
|
+
return polyfills._extends({
|
|
1231
|
+
resourceCategory: 'sync',
|
|
1232
|
+
share: true,
|
|
1233
|
+
depsRemote: true,
|
|
1234
|
+
prefetchInterface: false
|
|
1235
|
+
}, preloadConfig);
|
|
1236
|
+
}
|
|
1237
|
+
function formatPreloadArgs(remotes, preloadArgs) {
|
|
1238
|
+
return preloadArgs.map((args)=>{
|
|
1239
|
+
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
1240
|
+
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
|
|
1241
|
+
remoteInfo,
|
|
1242
|
+
remotes
|
|
1243
|
+
})}`);
|
|
1244
|
+
return {
|
|
1245
|
+
remote: remoteInfo,
|
|
1246
|
+
preloadConfig: defaultPreloadArgs(args)
|
|
1247
|
+
};
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
function normalizePreloadExposes(exposes) {
|
|
1251
|
+
if (!exposes) {
|
|
1252
|
+
return [];
|
|
1253
|
+
}
|
|
1254
|
+
return exposes.map((expose)=>{
|
|
1255
|
+
if (expose === '.') {
|
|
1256
|
+
return expose;
|
|
1257
|
+
}
|
|
1258
|
+
if (expose.startsWith('./')) {
|
|
1259
|
+
return expose.replace('./', '');
|
|
1260
|
+
}
|
|
1261
|
+
return expose;
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1264
|
+
function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
|
|
1265
|
+
useLinkPreload = true) {
|
|
1266
|
+
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
1267
|
+
if (host.options.inBrowser) {
|
|
1268
|
+
entryAssets.forEach((asset)=>{
|
|
1269
|
+
const { moduleInfo } = asset;
|
|
1270
|
+
const module = host.moduleCache.get(remoteInfo.name);
|
|
1271
|
+
if (module) {
|
|
1272
|
+
getRemoteEntry({
|
|
1273
|
+
origin: host,
|
|
1274
|
+
remoteInfo: moduleInfo,
|
|
1275
|
+
remoteEntryExports: module.remoteEntryExports
|
|
1276
|
+
});
|
|
1277
|
+
} else {
|
|
1278
|
+
getRemoteEntry({
|
|
1279
|
+
origin: host,
|
|
1280
|
+
remoteInfo: moduleInfo,
|
|
1281
|
+
remoteEntryExports: undefined
|
|
1282
|
+
});
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
if (useLinkPreload) {
|
|
1286
|
+
const defaultAttrs = {
|
|
1287
|
+
rel: 'preload',
|
|
1288
|
+
as: 'style'
|
|
1289
|
+
};
|
|
1290
|
+
cssAssets.forEach((cssUrl)=>{
|
|
1291
|
+
const { link: cssEl, needAttach } = sdk.createLink({
|
|
1292
|
+
url: cssUrl,
|
|
1293
|
+
cb: ()=>{
|
|
1294
|
+
// noop
|
|
1295
|
+
},
|
|
1296
|
+
attrs: defaultAttrs,
|
|
1297
|
+
createLinkHook: (url, attrs)=>{
|
|
1298
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1299
|
+
url,
|
|
1300
|
+
attrs
|
|
1301
|
+
});
|
|
1302
|
+
if (res instanceof HTMLLinkElement) {
|
|
1303
|
+
return res;
|
|
1304
|
+
}
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
});
|
|
1308
|
+
needAttach && document.head.appendChild(cssEl);
|
|
1309
|
+
});
|
|
1310
|
+
} else {
|
|
1311
|
+
const defaultAttrs = {
|
|
1312
|
+
rel: 'stylesheet',
|
|
1313
|
+
type: 'text/css'
|
|
1314
|
+
};
|
|
1315
|
+
cssAssets.forEach((cssUrl)=>{
|
|
1316
|
+
const { link: cssEl, needAttach } = sdk.createLink({
|
|
1317
|
+
url: cssUrl,
|
|
1318
|
+
cb: ()=>{
|
|
1319
|
+
// noop
|
|
1320
|
+
},
|
|
1321
|
+
attrs: defaultAttrs,
|
|
1322
|
+
createLinkHook: (url, attrs)=>{
|
|
1323
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1324
|
+
url,
|
|
1325
|
+
attrs
|
|
1326
|
+
});
|
|
1327
|
+
if (res instanceof HTMLLinkElement) {
|
|
1328
|
+
return res;
|
|
1329
|
+
}
|
|
1330
|
+
return;
|
|
1331
|
+
},
|
|
1332
|
+
needDeleteLink: false
|
|
1333
|
+
});
|
|
1334
|
+
needAttach && document.head.appendChild(cssEl);
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
if (useLinkPreload) {
|
|
1338
|
+
const defaultAttrs = {
|
|
1339
|
+
rel: 'preload',
|
|
1340
|
+
as: 'script'
|
|
1341
|
+
};
|
|
1342
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1343
|
+
const { link: linkEl, needAttach } = sdk.createLink({
|
|
1344
|
+
url: jsUrl,
|
|
1345
|
+
cb: ()=>{
|
|
1346
|
+
// noop
|
|
1347
|
+
},
|
|
1348
|
+
attrs: defaultAttrs,
|
|
1349
|
+
createLinkHook: (url, attrs)=>{
|
|
1350
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1351
|
+
url,
|
|
1352
|
+
attrs
|
|
1353
|
+
});
|
|
1354
|
+
if (res instanceof HTMLLinkElement) {
|
|
1355
|
+
return res;
|
|
1356
|
+
}
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
needAttach && document.head.appendChild(linkEl);
|
|
1361
|
+
});
|
|
1362
|
+
} else {
|
|
1363
|
+
const defaultAttrs = {
|
|
1364
|
+
fetchpriority: 'high',
|
|
1365
|
+
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
1366
|
+
};
|
|
1367
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1368
|
+
const { script: scriptEl, needAttach } = sdk.createScript({
|
|
1369
|
+
url: jsUrl,
|
|
1370
|
+
cb: ()=>{
|
|
1371
|
+
// noop
|
|
1372
|
+
},
|
|
1373
|
+
attrs: defaultAttrs,
|
|
1374
|
+
createScriptHook: (url, attrs)=>{
|
|
1375
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
1376
|
+
url,
|
|
1377
|
+
attrs
|
|
1378
|
+
});
|
|
1379
|
+
if (res instanceof HTMLScriptElement) {
|
|
1380
|
+
return res;
|
|
1381
|
+
}
|
|
1382
|
+
return;
|
|
1383
|
+
},
|
|
1384
|
+
needDeleteScript: true
|
|
1385
|
+
});
|
|
1386
|
+
needAttach && document.head.appendChild(scriptEl);
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
const ShareUtils = {
|
|
1393
|
+
getRegisteredShare,
|
|
1394
|
+
getGlobalShareScope
|
|
1395
|
+
};
|
|
1396
|
+
const GlobalUtils = {
|
|
1397
|
+
Global,
|
|
1398
|
+
nativeGlobal,
|
|
1399
|
+
resetFederationGlobalInfo,
|
|
1400
|
+
setGlobalFederationInstance,
|
|
1401
|
+
getGlobalFederationConstructor,
|
|
1402
|
+
setGlobalFederationConstructor,
|
|
1403
|
+
getInfoWithoutType,
|
|
1404
|
+
getGlobalSnapshot,
|
|
1405
|
+
getTargetSnapshotInfoByModuleInfo,
|
|
1406
|
+
getGlobalSnapshotInfoByModuleInfo,
|
|
1407
|
+
setGlobalSnapshotInfoByModuleInfo,
|
|
1408
|
+
addGlobalSnapshot,
|
|
1409
|
+
getRemoteEntryExports,
|
|
1410
|
+
registerGlobalPlugins,
|
|
1411
|
+
getGlobalHostPlugins,
|
|
1412
|
+
getPreloaded,
|
|
1413
|
+
setPreloaded
|
|
1414
|
+
};
|
|
1415
|
+
var helpers = {
|
|
1416
|
+
global: GlobalUtils,
|
|
1417
|
+
share: ShareUtils,
|
|
1418
|
+
utils: {
|
|
1419
|
+
matchRemoteWithNameAndExpose,
|
|
1420
|
+
preloadAssets,
|
|
1421
|
+
getRemoteInfo
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1243
1425
|
let Module = class Module {
|
|
1244
1426
|
async getEntry() {
|
|
1245
1427
|
if (this.remoteEntryExports) {
|
|
@@ -1476,7 +1658,8 @@ class SyncWaterfallHook extends SyncHook {
|
|
|
1476
1658
|
return data;
|
|
1477
1659
|
}
|
|
1478
1660
|
constructor(type){
|
|
1479
|
-
super()
|
|
1661
|
+
super();
|
|
1662
|
+
this.onerror = error;
|
|
1480
1663
|
this.type = type;
|
|
1481
1664
|
}
|
|
1482
1665
|
}
|
|
@@ -1514,19 +1697,21 @@ class AsyncWaterfallHook extends SyncHook {
|
|
|
1514
1697
|
return Promise.resolve(data);
|
|
1515
1698
|
}
|
|
1516
1699
|
constructor(type){
|
|
1517
|
-
super()
|
|
1700
|
+
super();
|
|
1701
|
+
this.onerror = error;
|
|
1518
1702
|
this.type = type;
|
|
1519
1703
|
}
|
|
1520
1704
|
}
|
|
1521
1705
|
|
|
1522
1706
|
class PluginSystem {
|
|
1523
|
-
applyPlugin(plugin) {
|
|
1707
|
+
applyPlugin(plugin, instance) {
|
|
1524
1708
|
assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
1525
1709
|
// The plugin's name is mandatory and must be unique
|
|
1526
1710
|
const pluginName = plugin.name;
|
|
1527
1711
|
assert(pluginName, 'A name must be provided by the plugin.');
|
|
1528
1712
|
if (!this.registerPlugins[pluginName]) {
|
|
1529
1713
|
this.registerPlugins[pluginName] = plugin;
|
|
1714
|
+
plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
|
|
1530
1715
|
Object.keys(this.lifecycle).forEach((key)=>{
|
|
1531
1716
|
const pluginLife = plugin[key];
|
|
1532
1717
|
if (pluginLife) {
|
|
@@ -1545,17 +1730,6 @@ class PluginSystem {
|
|
|
1545
1730
|
}
|
|
1546
1731
|
});
|
|
1547
1732
|
}
|
|
1548
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1549
|
-
inherit({ lifecycle, registerPlugins }) {
|
|
1550
|
-
Object.keys(lifecycle).forEach((hookName)=>{
|
|
1551
|
-
assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
|
|
1552
|
-
this.lifecycle[hookName] = lifecycle[hookName];
|
|
1553
|
-
});
|
|
1554
|
-
Object.keys(registerPlugins).forEach((pluginName)=>{
|
|
1555
|
-
assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
|
|
1556
|
-
this.applyPlugin(registerPlugins[pluginName]);
|
|
1557
|
-
});
|
|
1558
|
-
}
|
|
1559
1733
|
constructor(lifecycle){
|
|
1560
1734
|
this.registerPlugins = {};
|
|
1561
1735
|
this.lifecycle = lifecycle;
|
|
@@ -1563,169 +1737,6 @@ class PluginSystem {
|
|
|
1563
1737
|
}
|
|
1564
1738
|
}
|
|
1565
1739
|
|
|
1566
|
-
function defaultPreloadArgs(preloadConfig) {
|
|
1567
|
-
return polyfills._extends({
|
|
1568
|
-
resourceCategory: 'sync',
|
|
1569
|
-
share: true,
|
|
1570
|
-
depsRemote: true,
|
|
1571
|
-
prefetchInterface: false
|
|
1572
|
-
}, preloadConfig);
|
|
1573
|
-
}
|
|
1574
|
-
function formatPreloadArgs(remotes, preloadArgs) {
|
|
1575
|
-
return preloadArgs.map((args)=>{
|
|
1576
|
-
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
1577
|
-
assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
|
|
1578
|
-
remoteInfo,
|
|
1579
|
-
remotes
|
|
1580
|
-
})}`);
|
|
1581
|
-
return {
|
|
1582
|
-
remote: remoteInfo,
|
|
1583
|
-
preloadConfig: defaultPreloadArgs(args)
|
|
1584
|
-
};
|
|
1585
|
-
});
|
|
1586
|
-
}
|
|
1587
|
-
function normalizePreloadExposes(exposes) {
|
|
1588
|
-
if (!exposes) {
|
|
1589
|
-
return [];
|
|
1590
|
-
}
|
|
1591
|
-
return exposes.map((expose)=>{
|
|
1592
|
-
if (expose === '.') {
|
|
1593
|
-
return expose;
|
|
1594
|
-
}
|
|
1595
|
-
if (expose.startsWith('./')) {
|
|
1596
|
-
return expose.replace('./', '');
|
|
1597
|
-
}
|
|
1598
|
-
return expose;
|
|
1599
|
-
});
|
|
1600
|
-
}
|
|
1601
|
-
function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
|
|
1602
|
-
useLinkPreload = true) {
|
|
1603
|
-
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
1604
|
-
if (host.options.inBrowser) {
|
|
1605
|
-
entryAssets.forEach((asset)=>{
|
|
1606
|
-
const { moduleInfo } = asset;
|
|
1607
|
-
const module = host.moduleCache.get(remoteInfo.name);
|
|
1608
|
-
if (module) {
|
|
1609
|
-
getRemoteEntry({
|
|
1610
|
-
origin: host,
|
|
1611
|
-
remoteInfo: moduleInfo,
|
|
1612
|
-
remoteEntryExports: module.remoteEntryExports
|
|
1613
|
-
});
|
|
1614
|
-
} else {
|
|
1615
|
-
getRemoteEntry({
|
|
1616
|
-
origin: host,
|
|
1617
|
-
remoteInfo: moduleInfo,
|
|
1618
|
-
remoteEntryExports: undefined
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
});
|
|
1622
|
-
if (useLinkPreload) {
|
|
1623
|
-
const defaultAttrs = {
|
|
1624
|
-
rel: 'preload',
|
|
1625
|
-
as: 'style'
|
|
1626
|
-
};
|
|
1627
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1628
|
-
const { link: cssEl, needAttach } = sdk.createLink({
|
|
1629
|
-
url: cssUrl,
|
|
1630
|
-
cb: ()=>{
|
|
1631
|
-
// noop
|
|
1632
|
-
},
|
|
1633
|
-
attrs: defaultAttrs,
|
|
1634
|
-
createLinkHook: (url, attrs)=>{
|
|
1635
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1636
|
-
url,
|
|
1637
|
-
attrs
|
|
1638
|
-
});
|
|
1639
|
-
if (res instanceof HTMLLinkElement) {
|
|
1640
|
-
return res;
|
|
1641
|
-
}
|
|
1642
|
-
return;
|
|
1643
|
-
}
|
|
1644
|
-
});
|
|
1645
|
-
needAttach && document.head.appendChild(cssEl);
|
|
1646
|
-
});
|
|
1647
|
-
} else {
|
|
1648
|
-
const defaultAttrs = {
|
|
1649
|
-
rel: 'stylesheet',
|
|
1650
|
-
type: 'text/css'
|
|
1651
|
-
};
|
|
1652
|
-
cssAssets.forEach((cssUrl)=>{
|
|
1653
|
-
const { link: cssEl, needAttach } = sdk.createLink({
|
|
1654
|
-
url: cssUrl,
|
|
1655
|
-
cb: ()=>{
|
|
1656
|
-
// noop
|
|
1657
|
-
},
|
|
1658
|
-
attrs: defaultAttrs,
|
|
1659
|
-
createLinkHook: (url, attrs)=>{
|
|
1660
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1661
|
-
url,
|
|
1662
|
-
attrs
|
|
1663
|
-
});
|
|
1664
|
-
if (res instanceof HTMLLinkElement) {
|
|
1665
|
-
return res;
|
|
1666
|
-
}
|
|
1667
|
-
return;
|
|
1668
|
-
},
|
|
1669
|
-
needDeleteLink: false
|
|
1670
|
-
});
|
|
1671
|
-
needAttach && document.head.appendChild(cssEl);
|
|
1672
|
-
});
|
|
1673
|
-
}
|
|
1674
|
-
if (useLinkPreload) {
|
|
1675
|
-
const defaultAttrs = {
|
|
1676
|
-
rel: 'preload',
|
|
1677
|
-
as: 'script'
|
|
1678
|
-
};
|
|
1679
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1680
|
-
const { link: linkEl, needAttach } = sdk.createLink({
|
|
1681
|
-
url: jsUrl,
|
|
1682
|
-
cb: ()=>{
|
|
1683
|
-
// noop
|
|
1684
|
-
},
|
|
1685
|
-
attrs: defaultAttrs,
|
|
1686
|
-
createLinkHook: (url, attrs)=>{
|
|
1687
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
1688
|
-
url,
|
|
1689
|
-
attrs
|
|
1690
|
-
});
|
|
1691
|
-
if (res instanceof HTMLLinkElement) {
|
|
1692
|
-
return res;
|
|
1693
|
-
}
|
|
1694
|
-
return;
|
|
1695
|
-
}
|
|
1696
|
-
});
|
|
1697
|
-
needAttach && document.head.appendChild(linkEl);
|
|
1698
|
-
});
|
|
1699
|
-
} else {
|
|
1700
|
-
const defaultAttrs = {
|
|
1701
|
-
fetchpriority: 'high',
|
|
1702
|
-
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
1703
|
-
};
|
|
1704
|
-
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
1705
|
-
const { script: scriptEl, needAttach } = sdk.createScript({
|
|
1706
|
-
url: jsUrl,
|
|
1707
|
-
cb: ()=>{
|
|
1708
|
-
// noop
|
|
1709
|
-
},
|
|
1710
|
-
attrs: defaultAttrs,
|
|
1711
|
-
createScriptHook: (url, attrs)=>{
|
|
1712
|
-
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
1713
|
-
url,
|
|
1714
|
-
attrs
|
|
1715
|
-
});
|
|
1716
|
-
if (res instanceof HTMLScriptElement) {
|
|
1717
|
-
return res;
|
|
1718
|
-
}
|
|
1719
|
-
return;
|
|
1720
|
-
},
|
|
1721
|
-
needDeleteScript: true
|
|
1722
|
-
});
|
|
1723
|
-
needAttach && document.head.appendChild(scriptEl);
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
1740
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
1730
1741
|
const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
1731
1742
|
if (!remoteEntryInfo.url) {
|
|
@@ -1931,7 +1942,7 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
1931
1942
|
}
|
|
1932
1943
|
}
|
|
1933
1944
|
}, true, memo, remoteSnapshot);
|
|
1934
|
-
if (remoteSnapshot.shared) {
|
|
1945
|
+
if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
|
|
1935
1946
|
const collectSharedAssets = (shareInfo, snapshotShared)=>{
|
|
1936
1947
|
const registeredShared = getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare);
|
|
1937
1948
|
// 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.
|
|
@@ -2287,6 +2298,7 @@ class SharedHandler {
|
|
|
2287
2298
|
if (gShared) {
|
|
2288
2299
|
gShared.lib = factory;
|
|
2289
2300
|
gShared.loaded = true;
|
|
2301
|
+
addUseIn(gShared);
|
|
2290
2302
|
}
|
|
2291
2303
|
return factory;
|
|
2292
2304
|
};
|
|
@@ -2329,10 +2341,10 @@ class SharedHandler {
|
|
|
2329
2341
|
}
|
|
2330
2342
|
}
|
|
2331
2343
|
/**
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2344
|
+
* This function initializes the sharing sequence (executed only once per share scope).
|
|
2345
|
+
* It accepts one argument, the name of the share scope.
|
|
2346
|
+
* If the share scope does not exist, it creates one.
|
|
2347
|
+
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
2336
2348
|
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
2337
2349
|
const { host } = this;
|
|
2338
2350
|
const from = extraOptions == null ? void 0 : extraOptions.from;
|
|
@@ -2918,7 +2930,7 @@ class RemoteHandler {
|
|
|
2918
2930
|
}
|
|
2919
2931
|
|
|
2920
2932
|
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean' ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true; // Default to true (use snapshot) when not explicitly defined
|
|
2921
|
-
class
|
|
2933
|
+
class ModuleFederation {
|
|
2922
2934
|
initOptions(userOptions) {
|
|
2923
2935
|
this.registerPlugins(userOptions.plugins);
|
|
2924
2936
|
const options = this.formatOptions(this.options, userOptions);
|
|
@@ -2995,14 +3007,7 @@ class FederationHost {
|
|
|
2995
3007
|
return optionsRes;
|
|
2996
3008
|
}
|
|
2997
3009
|
registerPlugins(plugins) {
|
|
2998
|
-
const pluginRes = registerPlugins(plugins,
|
|
2999
|
-
this.hooks,
|
|
3000
|
-
this.remoteHandler.hooks,
|
|
3001
|
-
this.sharedHandler.hooks,
|
|
3002
|
-
this.snapshotHandler.hooks,
|
|
3003
|
-
this.loaderHook,
|
|
3004
|
-
this.bridgeHook
|
|
3005
|
-
]);
|
|
3010
|
+
const pluginRes = registerPlugins(plugins, this);
|
|
3006
3011
|
// Merge plugin
|
|
3007
3012
|
this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
|
|
3008
3013
|
if (!plugin) return res;
|
|
@@ -3015,6 +3020,11 @@ class FederationHost {
|
|
|
3015
3020
|
registerRemotes(remotes, options) {
|
|
3016
3021
|
return this.remoteHandler.registerRemotes(remotes, options);
|
|
3017
3022
|
}
|
|
3023
|
+
registerShared(shared) {
|
|
3024
|
+
this.sharedHandler.registerShared(this.options, polyfills._extends({}, this.options, {
|
|
3025
|
+
shared
|
|
3026
|
+
}));
|
|
3027
|
+
}
|
|
3018
3028
|
constructor(userOptions){
|
|
3019
3029
|
this.hooks = new PluginSystem({
|
|
3020
3030
|
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
@@ -3024,7 +3034,7 @@ class FederationHost {
|
|
|
3024
3034
|
// maybe will change, temporarily for internal use only
|
|
3025
3035
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
3026
3036
|
});
|
|
3027
|
-
this.version = "0.
|
|
3037
|
+
this.version = "0.17.1";
|
|
3028
3038
|
this.moduleCache = new Map();
|
|
3029
3039
|
this.loaderHook = new PluginSystem({
|
|
3030
3040
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -3070,15 +3080,15 @@ class FederationHost {
|
|
|
3070
3080
|
}
|
|
3071
3081
|
|
|
3072
3082
|
var index = /*#__PURE__*/Object.freeze({
|
|
3073
|
-
|
|
3083
|
+
__proto__: null
|
|
3074
3084
|
});
|
|
3075
3085
|
|
|
3076
3086
|
exports.loadScript = sdk.loadScript;
|
|
3077
3087
|
exports.loadScriptNode = sdk.loadScriptNode;
|
|
3078
3088
|
exports.CurrentGlobal = CurrentGlobal;
|
|
3079
|
-
exports.FederationHost = FederationHost;
|
|
3080
3089
|
exports.Global = Global;
|
|
3081
3090
|
exports.Module = Module;
|
|
3091
|
+
exports.ModuleFederation = ModuleFederation;
|
|
3082
3092
|
exports.addGlobalSnapshot = addGlobalSnapshot;
|
|
3083
3093
|
exports.assert = assert;
|
|
3084
3094
|
exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
|