@module-federation/runtime-core 0.0.0-next-20250710071138 → 0.0.0-next-20250714073201

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.
@@ -943,34 +943,6 @@ function getTargetSharedOptions(options) {
943
943
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
944
944
  }
945
945
 
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
946
  function getBuilderId() {
975
947
  //@ts-ignore
976
948
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
@@ -1040,8 +1012,16 @@ function matchRemote(remotes, nameOrAlias) {
1040
1012
  return;
1041
1013
  }
1042
1014
 
1043
- function registerPlugins(plugins, hookInstances) {
1015
+ function registerPlugins(plugins, instance) {
1044
1016
  const globalPlugins = getGlobalHostPlugins();
1017
+ const hookInstances = [
1018
+ instance.hooks,
1019
+ instance.remoteHandler.hooks,
1020
+ instance.sharedHandler.hooks,
1021
+ instance.snapshotHandler.hooks,
1022
+ instance.loaderHook,
1023
+ instance.bridgeHook
1024
+ ];
1045
1025
  // Incorporate global plugins
1046
1026
  if (globalPlugins.length > 0) {
1047
1027
  globalPlugins.forEach((plugin)=>{
@@ -1053,7 +1033,7 @@ function registerPlugins(plugins, hookInstances) {
1053
1033
  if (plugins && plugins.length > 0) {
1054
1034
  plugins.forEach((plugin)=>{
1055
1035
  hookInstances.forEach((hookInstance)=>{
1056
- hookInstance.applyPlugin(plugin);
1036
+ hookInstance.applyPlugin(plugin, instance);
1057
1037
  });
1058
1038
  });
1059
1039
  }
@@ -1240,6 +1220,202 @@ function getRemoteInfo(remote) {
1240
1220
  });
1241
1221
  }
1242
1222
 
1223
+ function defaultPreloadArgs(preloadConfig) {
1224
+ return polyfills._extends({
1225
+ resourceCategory: 'sync',
1226
+ share: true,
1227
+ depsRemote: true,
1228
+ prefetchInterface: false
1229
+ }, preloadConfig);
1230
+ }
1231
+ function formatPreloadArgs(remotes, preloadArgs) {
1232
+ return preloadArgs.map((args)=>{
1233
+ const remoteInfo = matchRemote(remotes, args.nameOrAlias);
1234
+ assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
1235
+ remoteInfo,
1236
+ remotes
1237
+ })}`);
1238
+ return {
1239
+ remote: remoteInfo,
1240
+ preloadConfig: defaultPreloadArgs(args)
1241
+ };
1242
+ });
1243
+ }
1244
+ function normalizePreloadExposes(exposes) {
1245
+ if (!exposes) {
1246
+ return [];
1247
+ }
1248
+ return exposes.map((expose)=>{
1249
+ if (expose === '.') {
1250
+ return expose;
1251
+ }
1252
+ if (expose.startsWith('./')) {
1253
+ return expose.replace('./', '');
1254
+ }
1255
+ return expose;
1256
+ });
1257
+ }
1258
+ function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
1259
+ useLinkPreload = true) {
1260
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1261
+ if (host.options.inBrowser) {
1262
+ entryAssets.forEach((asset)=>{
1263
+ const { moduleInfo } = asset;
1264
+ const module = host.moduleCache.get(remoteInfo.name);
1265
+ if (module) {
1266
+ getRemoteEntry({
1267
+ origin: host,
1268
+ remoteInfo: moduleInfo,
1269
+ remoteEntryExports: module.remoteEntryExports
1270
+ });
1271
+ } else {
1272
+ getRemoteEntry({
1273
+ origin: host,
1274
+ remoteInfo: moduleInfo,
1275
+ remoteEntryExports: undefined
1276
+ });
1277
+ }
1278
+ });
1279
+ if (useLinkPreload) {
1280
+ const defaultAttrs = {
1281
+ rel: 'preload',
1282
+ as: 'style'
1283
+ };
1284
+ cssAssets.forEach((cssUrl)=>{
1285
+ const { link: cssEl, needAttach } = sdk.createLink({
1286
+ url: cssUrl,
1287
+ cb: ()=>{
1288
+ // noop
1289
+ },
1290
+ attrs: defaultAttrs,
1291
+ createLinkHook: (url, attrs)=>{
1292
+ const res = host.loaderHook.lifecycle.createLink.emit({
1293
+ url,
1294
+ attrs
1295
+ });
1296
+ if (res instanceof HTMLLinkElement) {
1297
+ return res;
1298
+ }
1299
+ return;
1300
+ }
1301
+ });
1302
+ needAttach && document.head.appendChild(cssEl);
1303
+ });
1304
+ } else {
1305
+ const defaultAttrs = {
1306
+ rel: 'stylesheet',
1307
+ type: 'text/css'
1308
+ };
1309
+ cssAssets.forEach((cssUrl)=>{
1310
+ const { link: cssEl, needAttach } = sdk.createLink({
1311
+ url: cssUrl,
1312
+ cb: ()=>{
1313
+ // noop
1314
+ },
1315
+ attrs: defaultAttrs,
1316
+ createLinkHook: (url, attrs)=>{
1317
+ const res = host.loaderHook.lifecycle.createLink.emit({
1318
+ url,
1319
+ attrs
1320
+ });
1321
+ if (res instanceof HTMLLinkElement) {
1322
+ return res;
1323
+ }
1324
+ return;
1325
+ },
1326
+ needDeleteLink: false
1327
+ });
1328
+ needAttach && document.head.appendChild(cssEl);
1329
+ });
1330
+ }
1331
+ if (useLinkPreload) {
1332
+ const defaultAttrs = {
1333
+ rel: 'preload',
1334
+ as: 'script'
1335
+ };
1336
+ jsAssetsWithoutEntry.forEach((jsUrl)=>{
1337
+ const { link: linkEl, needAttach } = sdk.createLink({
1338
+ url: jsUrl,
1339
+ cb: ()=>{
1340
+ // noop
1341
+ },
1342
+ attrs: defaultAttrs,
1343
+ createLinkHook: (url, attrs)=>{
1344
+ const res = host.loaderHook.lifecycle.createLink.emit({
1345
+ url,
1346
+ attrs
1347
+ });
1348
+ if (res instanceof HTMLLinkElement) {
1349
+ return res;
1350
+ }
1351
+ return;
1352
+ }
1353
+ });
1354
+ needAttach && document.head.appendChild(linkEl);
1355
+ });
1356
+ } else {
1357
+ const defaultAttrs = {
1358
+ fetchpriority: 'high',
1359
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
1360
+ };
1361
+ jsAssetsWithoutEntry.forEach((jsUrl)=>{
1362
+ const { script: scriptEl, needAttach } = sdk.createScript({
1363
+ url: jsUrl,
1364
+ cb: ()=>{
1365
+ // noop
1366
+ },
1367
+ attrs: defaultAttrs,
1368
+ createScriptHook: (url, attrs)=>{
1369
+ const res = host.loaderHook.lifecycle.createScript.emit({
1370
+ url,
1371
+ attrs
1372
+ });
1373
+ if (res instanceof HTMLScriptElement) {
1374
+ return res;
1375
+ }
1376
+ return;
1377
+ },
1378
+ needDeleteScript: true
1379
+ });
1380
+ needAttach && document.head.appendChild(scriptEl);
1381
+ });
1382
+ }
1383
+ }
1384
+ }
1385
+
1386
+ const ShareUtils = {
1387
+ getRegisteredShare,
1388
+ getGlobalShareScope
1389
+ };
1390
+ const GlobalUtils = {
1391
+ Global,
1392
+ nativeGlobal,
1393
+ resetFederationGlobalInfo,
1394
+ setGlobalFederationInstance,
1395
+ getGlobalFederationConstructor,
1396
+ setGlobalFederationConstructor,
1397
+ getInfoWithoutType,
1398
+ getGlobalSnapshot,
1399
+ getTargetSnapshotInfoByModuleInfo,
1400
+ getGlobalSnapshotInfoByModuleInfo,
1401
+ setGlobalSnapshotInfoByModuleInfo,
1402
+ addGlobalSnapshot,
1403
+ getRemoteEntryExports,
1404
+ registerGlobalPlugins,
1405
+ getGlobalHostPlugins,
1406
+ getPreloaded,
1407
+ setPreloaded
1408
+ };
1409
+ var helpers = {
1410
+ global: GlobalUtils,
1411
+ share: ShareUtils,
1412
+ utils: {
1413
+ matchRemoteWithNameAndExpose,
1414
+ preloadAssets,
1415
+ getRemoteInfo
1416
+ }
1417
+ };
1418
+
1243
1419
  let Module = class Module {
1244
1420
  async getEntry() {
1245
1421
  if (this.remoteEntryExports) {
@@ -1520,13 +1696,14 @@ class AsyncWaterfallHook extends SyncHook {
1520
1696
  }
1521
1697
 
1522
1698
  class PluginSystem {
1523
- applyPlugin(plugin) {
1699
+ applyPlugin(plugin, instance) {
1524
1700
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1525
1701
  // The plugin's name is mandatory and must be unique
1526
1702
  const pluginName = plugin.name;
1527
1703
  assert(pluginName, 'A name must be provided by the plugin.');
1528
1704
  if (!this.registerPlugins[pluginName]) {
1529
1705
  this.registerPlugins[pluginName] = plugin;
1706
+ plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1530
1707
  Object.keys(this.lifecycle).forEach((key)=>{
1531
1708
  const pluginLife = plugin[key];
1532
1709
  if (pluginLife) {
@@ -1545,17 +1722,6 @@ class PluginSystem {
1545
1722
  }
1546
1723
  });
1547
1724
  }
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
1725
  constructor(lifecycle){
1560
1726
  this.registerPlugins = {};
1561
1727
  this.lifecycle = lifecycle;
@@ -1563,169 +1729,6 @@ class PluginSystem {
1563
1729
  }
1564
1730
  }
1565
1731
 
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
1732
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1730
1733
  const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
1731
1734
  if (!remoteEntryInfo.url) {
@@ -2995,14 +2998,7 @@ class FederationHost {
2995
2998
  return optionsRes;
2996
2999
  }
2997
3000
  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
- ]);
3001
+ const pluginRes = registerPlugins(plugins, this);
3006
3002
  // Merge plugin
3007
3003
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3008
3004
  if (!plugin) return res;
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.js';
2
- import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode, composeKeyWithSeparator, loadScriptNode, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
2
+ import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode, composeKeyWithSeparator, loadScriptNode, loadScript, createLink, createScript, safeToString, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
3
3
  export { loadScript, loadScriptNode } from '@module-federation/sdk';
4
4
  import { getShortErrorMsg, RUNTIME_008, runtimeDescMap, RUNTIME_001, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
5
5
 
@@ -942,34 +942,6 @@ function getTargetSharedOptions(options) {
942
942
  return Object.assign({}, resolver(shareInfos[pkgName]), extraOptions == null ? void 0 : extraOptions.customShareInfo);
943
943
  }
944
944
 
945
- const ShareUtils = {
946
- getRegisteredShare,
947
- getGlobalShareScope
948
- };
949
- const GlobalUtils = {
950
- Global,
951
- nativeGlobal,
952
- resetFederationGlobalInfo,
953
- setGlobalFederationInstance,
954
- getGlobalFederationConstructor,
955
- setGlobalFederationConstructor,
956
- getInfoWithoutType,
957
- getGlobalSnapshot,
958
- getTargetSnapshotInfoByModuleInfo,
959
- getGlobalSnapshotInfoByModuleInfo,
960
- setGlobalSnapshotInfoByModuleInfo,
961
- addGlobalSnapshot,
962
- getRemoteEntryExports,
963
- registerGlobalPlugins,
964
- getGlobalHostPlugins,
965
- getPreloaded,
966
- setPreloaded
967
- };
968
- var helpers = {
969
- global: GlobalUtils,
970
- share: ShareUtils
971
- };
972
-
973
945
  function getBuilderId() {
974
946
  //@ts-ignore
975
947
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
@@ -1039,8 +1011,16 @@ function matchRemote(remotes, nameOrAlias) {
1039
1011
  return;
1040
1012
  }
1041
1013
 
1042
- function registerPlugins(plugins, hookInstances) {
1014
+ function registerPlugins(plugins, instance) {
1043
1015
  const globalPlugins = getGlobalHostPlugins();
1016
+ const hookInstances = [
1017
+ instance.hooks,
1018
+ instance.remoteHandler.hooks,
1019
+ instance.sharedHandler.hooks,
1020
+ instance.snapshotHandler.hooks,
1021
+ instance.loaderHook,
1022
+ instance.bridgeHook
1023
+ ];
1044
1024
  // Incorporate global plugins
1045
1025
  if (globalPlugins.length > 0) {
1046
1026
  globalPlugins.forEach((plugin)=>{
@@ -1052,7 +1032,7 @@ function registerPlugins(plugins, hookInstances) {
1052
1032
  if (plugins && plugins.length > 0) {
1053
1033
  plugins.forEach((plugin)=>{
1054
1034
  hookInstances.forEach((hookInstance)=>{
1055
- hookInstance.applyPlugin(plugin);
1035
+ hookInstance.applyPlugin(plugin, instance);
1056
1036
  });
1057
1037
  });
1058
1038
  }
@@ -1239,6 +1219,202 @@ function getRemoteInfo(remote) {
1239
1219
  });
1240
1220
  }
1241
1221
 
1222
+ function defaultPreloadArgs(preloadConfig) {
1223
+ return _extends({
1224
+ resourceCategory: 'sync',
1225
+ share: true,
1226
+ depsRemote: true,
1227
+ prefetchInterface: false
1228
+ }, preloadConfig);
1229
+ }
1230
+ function formatPreloadArgs(remotes, preloadArgs) {
1231
+ return preloadArgs.map((args)=>{
1232
+ const remoteInfo = matchRemote(remotes, args.nameOrAlias);
1233
+ assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && safeToString({
1234
+ remoteInfo,
1235
+ remotes
1236
+ })}`);
1237
+ return {
1238
+ remote: remoteInfo,
1239
+ preloadConfig: defaultPreloadArgs(args)
1240
+ };
1241
+ });
1242
+ }
1243
+ function normalizePreloadExposes(exposes) {
1244
+ if (!exposes) {
1245
+ return [];
1246
+ }
1247
+ return exposes.map((expose)=>{
1248
+ if (expose === '.') {
1249
+ return expose;
1250
+ }
1251
+ if (expose.startsWith('./')) {
1252
+ return expose.replace('./', '');
1253
+ }
1254
+ return expose;
1255
+ });
1256
+ }
1257
+ function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
1258
+ useLinkPreload = true) {
1259
+ const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1260
+ if (host.options.inBrowser) {
1261
+ entryAssets.forEach((asset)=>{
1262
+ const { moduleInfo } = asset;
1263
+ const module = host.moduleCache.get(remoteInfo.name);
1264
+ if (module) {
1265
+ getRemoteEntry({
1266
+ origin: host,
1267
+ remoteInfo: moduleInfo,
1268
+ remoteEntryExports: module.remoteEntryExports
1269
+ });
1270
+ } else {
1271
+ getRemoteEntry({
1272
+ origin: host,
1273
+ remoteInfo: moduleInfo,
1274
+ remoteEntryExports: undefined
1275
+ });
1276
+ }
1277
+ });
1278
+ if (useLinkPreload) {
1279
+ const defaultAttrs = {
1280
+ rel: 'preload',
1281
+ as: 'style'
1282
+ };
1283
+ cssAssets.forEach((cssUrl)=>{
1284
+ const { link: cssEl, needAttach } = createLink({
1285
+ url: cssUrl,
1286
+ cb: ()=>{
1287
+ // noop
1288
+ },
1289
+ attrs: defaultAttrs,
1290
+ createLinkHook: (url, attrs)=>{
1291
+ const res = host.loaderHook.lifecycle.createLink.emit({
1292
+ url,
1293
+ attrs
1294
+ });
1295
+ if (res instanceof HTMLLinkElement) {
1296
+ return res;
1297
+ }
1298
+ return;
1299
+ }
1300
+ });
1301
+ needAttach && document.head.appendChild(cssEl);
1302
+ });
1303
+ } else {
1304
+ const defaultAttrs = {
1305
+ rel: 'stylesheet',
1306
+ type: 'text/css'
1307
+ };
1308
+ cssAssets.forEach((cssUrl)=>{
1309
+ const { link: cssEl, needAttach } = createLink({
1310
+ url: cssUrl,
1311
+ cb: ()=>{
1312
+ // noop
1313
+ },
1314
+ attrs: defaultAttrs,
1315
+ createLinkHook: (url, attrs)=>{
1316
+ const res = host.loaderHook.lifecycle.createLink.emit({
1317
+ url,
1318
+ attrs
1319
+ });
1320
+ if (res instanceof HTMLLinkElement) {
1321
+ return res;
1322
+ }
1323
+ return;
1324
+ },
1325
+ needDeleteLink: false
1326
+ });
1327
+ needAttach && document.head.appendChild(cssEl);
1328
+ });
1329
+ }
1330
+ if (useLinkPreload) {
1331
+ const defaultAttrs = {
1332
+ rel: 'preload',
1333
+ as: 'script'
1334
+ };
1335
+ jsAssetsWithoutEntry.forEach((jsUrl)=>{
1336
+ const { link: linkEl, needAttach } = createLink({
1337
+ url: jsUrl,
1338
+ cb: ()=>{
1339
+ // noop
1340
+ },
1341
+ attrs: defaultAttrs,
1342
+ createLinkHook: (url, attrs)=>{
1343
+ const res = host.loaderHook.lifecycle.createLink.emit({
1344
+ url,
1345
+ attrs
1346
+ });
1347
+ if (res instanceof HTMLLinkElement) {
1348
+ return res;
1349
+ }
1350
+ return;
1351
+ }
1352
+ });
1353
+ needAttach && document.head.appendChild(linkEl);
1354
+ });
1355
+ } else {
1356
+ const defaultAttrs = {
1357
+ fetchpriority: 'high',
1358
+ type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
1359
+ };
1360
+ jsAssetsWithoutEntry.forEach((jsUrl)=>{
1361
+ const { script: scriptEl, needAttach } = createScript({
1362
+ url: jsUrl,
1363
+ cb: ()=>{
1364
+ // noop
1365
+ },
1366
+ attrs: defaultAttrs,
1367
+ createScriptHook: (url, attrs)=>{
1368
+ const res = host.loaderHook.lifecycle.createScript.emit({
1369
+ url,
1370
+ attrs
1371
+ });
1372
+ if (res instanceof HTMLScriptElement) {
1373
+ return res;
1374
+ }
1375
+ return;
1376
+ },
1377
+ needDeleteScript: true
1378
+ });
1379
+ needAttach && document.head.appendChild(scriptEl);
1380
+ });
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ const ShareUtils = {
1386
+ getRegisteredShare,
1387
+ getGlobalShareScope
1388
+ };
1389
+ const GlobalUtils = {
1390
+ Global,
1391
+ nativeGlobal,
1392
+ resetFederationGlobalInfo,
1393
+ setGlobalFederationInstance,
1394
+ getGlobalFederationConstructor,
1395
+ setGlobalFederationConstructor,
1396
+ getInfoWithoutType,
1397
+ getGlobalSnapshot,
1398
+ getTargetSnapshotInfoByModuleInfo,
1399
+ getGlobalSnapshotInfoByModuleInfo,
1400
+ setGlobalSnapshotInfoByModuleInfo,
1401
+ addGlobalSnapshot,
1402
+ getRemoteEntryExports,
1403
+ registerGlobalPlugins,
1404
+ getGlobalHostPlugins,
1405
+ getPreloaded,
1406
+ setPreloaded
1407
+ };
1408
+ var helpers = {
1409
+ global: GlobalUtils,
1410
+ share: ShareUtils,
1411
+ utils: {
1412
+ matchRemoteWithNameAndExpose,
1413
+ preloadAssets,
1414
+ getRemoteInfo
1415
+ }
1416
+ };
1417
+
1242
1418
  let Module = class Module {
1243
1419
  async getEntry() {
1244
1420
  if (this.remoteEntryExports) {
@@ -1519,13 +1695,14 @@ class AsyncWaterfallHook extends SyncHook {
1519
1695
  }
1520
1696
 
1521
1697
  class PluginSystem {
1522
- applyPlugin(plugin) {
1698
+ applyPlugin(plugin, instance) {
1523
1699
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1524
1700
  // The plugin's name is mandatory and must be unique
1525
1701
  const pluginName = plugin.name;
1526
1702
  assert(pluginName, 'A name must be provided by the plugin.');
1527
1703
  if (!this.registerPlugins[pluginName]) {
1528
1704
  this.registerPlugins[pluginName] = plugin;
1705
+ plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1529
1706
  Object.keys(this.lifecycle).forEach((key)=>{
1530
1707
  const pluginLife = plugin[key];
1531
1708
  if (pluginLife) {
@@ -1544,17 +1721,6 @@ class PluginSystem {
1544
1721
  }
1545
1722
  });
1546
1723
  }
1547
- // eslint-disable-next-line @typescript-eslint/no-shadow
1548
- inherit({ lifecycle, registerPlugins }) {
1549
- Object.keys(lifecycle).forEach((hookName)=>{
1550
- assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
1551
- this.lifecycle[hookName] = lifecycle[hookName];
1552
- });
1553
- Object.keys(registerPlugins).forEach((pluginName)=>{
1554
- assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
1555
- this.applyPlugin(registerPlugins[pluginName]);
1556
- });
1557
- }
1558
1724
  constructor(lifecycle){
1559
1725
  this.registerPlugins = {};
1560
1726
  this.lifecycle = lifecycle;
@@ -1562,169 +1728,6 @@ class PluginSystem {
1562
1728
  }
1563
1729
  }
1564
1730
 
1565
- function defaultPreloadArgs(preloadConfig) {
1566
- return _extends({
1567
- resourceCategory: 'sync',
1568
- share: true,
1569
- depsRemote: true,
1570
- prefetchInterface: false
1571
- }, preloadConfig);
1572
- }
1573
- function formatPreloadArgs(remotes, preloadArgs) {
1574
- return preloadArgs.map((args)=>{
1575
- const remoteInfo = matchRemote(remotes, args.nameOrAlias);
1576
- assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && safeToString({
1577
- remoteInfo,
1578
- remotes
1579
- })}`);
1580
- return {
1581
- remote: remoteInfo,
1582
- preloadConfig: defaultPreloadArgs(args)
1583
- };
1584
- });
1585
- }
1586
- function normalizePreloadExposes(exposes) {
1587
- if (!exposes) {
1588
- return [];
1589
- }
1590
- return exposes.map((expose)=>{
1591
- if (expose === '.') {
1592
- return expose;
1593
- }
1594
- if (expose.startsWith('./')) {
1595
- return expose.replace('./', '');
1596
- }
1597
- return expose;
1598
- });
1599
- }
1600
- function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
1601
- useLinkPreload = true) {
1602
- const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
1603
- if (host.options.inBrowser) {
1604
- entryAssets.forEach((asset)=>{
1605
- const { moduleInfo } = asset;
1606
- const module = host.moduleCache.get(remoteInfo.name);
1607
- if (module) {
1608
- getRemoteEntry({
1609
- origin: host,
1610
- remoteInfo: moduleInfo,
1611
- remoteEntryExports: module.remoteEntryExports
1612
- });
1613
- } else {
1614
- getRemoteEntry({
1615
- origin: host,
1616
- remoteInfo: moduleInfo,
1617
- remoteEntryExports: undefined
1618
- });
1619
- }
1620
- });
1621
- if (useLinkPreload) {
1622
- const defaultAttrs = {
1623
- rel: 'preload',
1624
- as: 'style'
1625
- };
1626
- cssAssets.forEach((cssUrl)=>{
1627
- const { link: cssEl, needAttach } = createLink({
1628
- url: cssUrl,
1629
- cb: ()=>{
1630
- // noop
1631
- },
1632
- attrs: defaultAttrs,
1633
- createLinkHook: (url, attrs)=>{
1634
- const res = host.loaderHook.lifecycle.createLink.emit({
1635
- url,
1636
- attrs
1637
- });
1638
- if (res instanceof HTMLLinkElement) {
1639
- return res;
1640
- }
1641
- return;
1642
- }
1643
- });
1644
- needAttach && document.head.appendChild(cssEl);
1645
- });
1646
- } else {
1647
- const defaultAttrs = {
1648
- rel: 'stylesheet',
1649
- type: 'text/css'
1650
- };
1651
- cssAssets.forEach((cssUrl)=>{
1652
- const { link: cssEl, needAttach } = createLink({
1653
- url: cssUrl,
1654
- cb: ()=>{
1655
- // noop
1656
- },
1657
- attrs: defaultAttrs,
1658
- createLinkHook: (url, attrs)=>{
1659
- const res = host.loaderHook.lifecycle.createLink.emit({
1660
- url,
1661
- attrs
1662
- });
1663
- if (res instanceof HTMLLinkElement) {
1664
- return res;
1665
- }
1666
- return;
1667
- },
1668
- needDeleteLink: false
1669
- });
1670
- needAttach && document.head.appendChild(cssEl);
1671
- });
1672
- }
1673
- if (useLinkPreload) {
1674
- const defaultAttrs = {
1675
- rel: 'preload',
1676
- as: 'script'
1677
- };
1678
- jsAssetsWithoutEntry.forEach((jsUrl)=>{
1679
- const { link: linkEl, needAttach } = createLink({
1680
- url: jsUrl,
1681
- cb: ()=>{
1682
- // noop
1683
- },
1684
- attrs: defaultAttrs,
1685
- createLinkHook: (url, attrs)=>{
1686
- const res = host.loaderHook.lifecycle.createLink.emit({
1687
- url,
1688
- attrs
1689
- });
1690
- if (res instanceof HTMLLinkElement) {
1691
- return res;
1692
- }
1693
- return;
1694
- }
1695
- });
1696
- needAttach && document.head.appendChild(linkEl);
1697
- });
1698
- } else {
1699
- const defaultAttrs = {
1700
- fetchpriority: 'high',
1701
- type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
1702
- };
1703
- jsAssetsWithoutEntry.forEach((jsUrl)=>{
1704
- const { script: scriptEl, needAttach } = createScript({
1705
- url: jsUrl,
1706
- cb: ()=>{
1707
- // noop
1708
- },
1709
- attrs: defaultAttrs,
1710
- createScriptHook: (url, attrs)=>{
1711
- const res = host.loaderHook.lifecycle.createScript.emit({
1712
- url,
1713
- attrs
1714
- });
1715
- if (res instanceof HTMLScriptElement) {
1716
- return res;
1717
- }
1718
- return;
1719
- },
1720
- needDeleteScript: true
1721
- });
1722
- needAttach && document.head.appendChild(scriptEl);
1723
- });
1724
- }
1725
- }
1726
- }
1727
-
1728
1731
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1729
1732
  const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
1730
1733
  if (!remoteEntryInfo.url) {
@@ -2994,14 +2997,7 @@ class FederationHost {
2994
2997
  return optionsRes;
2995
2998
  }
2996
2999
  registerPlugins(plugins) {
2997
- const pluginRes = registerPlugins(plugins, [
2998
- this.hooks,
2999
- this.remoteHandler.hooks,
3000
- this.sharedHandler.hooks,
3001
- this.snapshotHandler.hooks,
3002
- this.loaderHook,
3003
- this.bridgeHook
3004
- ]);
3000
+ const pluginRes = registerPlugins(plugins, this);
3005
3001
  // Merge plugin
3006
3002
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3007
3003
  if (!plugin) return res;
@@ -1,5 +1,7 @@
1
1
  import { resetFederationGlobalInfo, setGlobalFederationInstance, getGlobalFederationConstructor, setGlobalFederationConstructor, getInfoWithoutType, getGlobalSnapshot, getTargetSnapshotInfoByModuleInfo, getGlobalSnapshotInfoByModuleInfo, setGlobalSnapshotInfoByModuleInfo, addGlobalSnapshot, getRemoteEntryExports, registerGlobalPlugins, getGlobalHostPlugins, getPreloaded, setPreloaded, Global } from './global';
2
2
  import { getRegisteredShare, getGlobalShareScope } from './utils/share';
3
+ import { getRemoteInfo, matchRemoteWithNameAndExpose } from './utils';
4
+ import { preloadAssets } from './utils/preload';
3
5
  interface IShareUtils {
4
6
  getRegisteredShare: typeof getRegisteredShare;
5
7
  getGlobalShareScope: typeof getGlobalShareScope;
@@ -26,6 +28,11 @@ interface IGlobalUtils {
26
28
  declare const _default: {
27
29
  global: IGlobalUtils;
28
30
  share: IShareUtils;
31
+ utils: {
32
+ matchRemoteWithNameAndExpose: typeof matchRemoteWithNameAndExpose;
33
+ preloadAssets: typeof preloadAssets;
34
+ getRemoteInfo: typeof getRemoteInfo;
35
+ };
29
36
  };
30
37
  export default _default;
31
38
  export type { IGlobalUtils, IShareUtils };
@@ -30,5 +30,6 @@ type RemoteLifeCycleCyclePartial = Partial<{
30
30
  export type FederationRuntimePlugin = CoreLifeCyclePartial & SnapshotLifeCycleCyclePartial & SharedLifeCycleCyclePartial & RemoteLifeCycleCyclePartial & ModuleLifeCycleCyclePartial & ModuleBridgeLifeCycleCyclePartial & {
31
31
  name: string;
32
32
  version?: string;
33
+ apply?: (instance: FederationHost) => void;
33
34
  };
34
35
  export {};
@@ -1,15 +1,16 @@
1
+ import type { FederationHost } from '../../core';
1
2
  export type Plugin<T extends Record<string, any>> = {
2
3
  [k in keyof T]?: Parameters<T[k]['on']>[0];
3
4
  } & {
4
5
  name: string;
5
6
  version?: string;
7
+ apply?: (instance: FederationHost) => void;
6
8
  };
7
9
  export declare class PluginSystem<T extends Record<string, any>> {
8
10
  lifecycle: T;
9
11
  lifecycleKeys: Array<keyof T>;
10
12
  registerPlugins: Record<string, Plugin<T>>;
11
13
  constructor(lifecycle: T);
12
- applyPlugin(plugin: Plugin<T>): void;
14
+ applyPlugin(plugin: Plugin<T>, instance: FederationHost): void;
13
15
  removePlugin(pluginName: string): void;
14
- inherit<T extends PluginSystem<any>>({ lifecycle, registerPlugins, }: T): void;
15
16
  }
@@ -1,4 +1,3 @@
1
1
  import { FederationHost } from '../core';
2
2
  import { UserOptions } from '../type';
3
- import { Module } from '../module';
4
- export declare function registerPlugins(plugins: UserOptions['plugins'], hookInstances: Array<FederationHost['hooks'] | FederationHost['snapshotHandler']['hooks'] | FederationHost['sharedHandler']['hooks'] | FederationHost['remoteHandler']['hooks'] | Module['host']['loaderHook'] | Module['host']['bridgeHook']>): import("../type").FederationRuntimePlugin[] | undefined;
3
+ export declare function registerPlugins(plugins: UserOptions['plugins'], instance: FederationHost): import("../type").FederationRuntimePlugin[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.0.0-next-20250710071138",
3
+ "version": "0.0.0-next-20250714073201",
4
4
  "type": "module",
5
5
  "author": "zhouxiao <codingzx@gmail.com>",
6
6
  "main": "./dist/index.cjs.cjs",
@@ -52,7 +52,7 @@
52
52
  }
53
53
  },
54
54
  "dependencies": {
55
- "@module-federation/sdk": "0.0.0-next-20250710071138",
56
- "@module-federation/error-codes": "0.0.0-next-20250710071138"
55
+ "@module-federation/sdk": "0.0.0-next-20250714073201",
56
+ "@module-federation/error-codes": "0.0.0-next-20250714073201"
57
57
  }
58
58
  }