@module-federation/runtime-core 0.0.0-next-20250708134245 → 0.0.0-next-20250709032753

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.
@@ -296,8 +296,8 @@ const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
296
296
  const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
297
297
  const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
298
298
 
299
- const DEFAULT_SCOPE = 'default';
300
299
  const DEFAULT_REMOTE_TYPE = 'global';
300
+ const DEFAULT_SCOPE = 'default';
301
301
 
302
302
  // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
303
303
  // those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant
@@ -943,6 +943,34 @@ 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
+
946
974
  function getBuilderId() {
947
975
  //@ts-ignore
948
976
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
@@ -1012,16 +1040,8 @@ function matchRemote(remotes, nameOrAlias) {
1012
1040
  return;
1013
1041
  }
1014
1042
 
1015
- function registerPlugins(plugins, instance) {
1043
+ function registerPlugins(plugins, hookInstances) {
1016
1044
  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
- ];
1025
1045
  // Incorporate global plugins
1026
1046
  if (globalPlugins.length > 0) {
1027
1047
  globalPlugins.forEach((plugin)=>{
@@ -1033,7 +1053,7 @@ function registerPlugins(plugins, instance) {
1033
1053
  if (plugins && plugins.length > 0) {
1034
1054
  plugins.forEach((plugin)=>{
1035
1055
  hookInstances.forEach((hookInstance)=>{
1036
- hookInstance.applyPlugin(plugin, instance);
1056
+ hookInstance.applyPlugin(plugin);
1037
1057
  });
1038
1058
  });
1039
1059
  }
@@ -1220,202 +1240,6 @@ function getRemoteInfo(remote) {
1220
1240
  });
1221
1241
  }
1222
1242
 
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
-
1419
1243
  let Module = class Module {
1420
1244
  async getEntry() {
1421
1245
  if (this.remoteEntryExports) {
@@ -1696,14 +1520,13 @@ class AsyncWaterfallHook extends SyncHook {
1696
1520
  }
1697
1521
 
1698
1522
  class PluginSystem {
1699
- applyPlugin(plugin, instance) {
1523
+ applyPlugin(plugin) {
1700
1524
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1701
1525
  // The plugin's name is mandatory and must be unique
1702
1526
  const pluginName = plugin.name;
1703
1527
  assert(pluginName, 'A name must be provided by the plugin.');
1704
1528
  if (!this.registerPlugins[pluginName]) {
1705
1529
  this.registerPlugins[pluginName] = plugin;
1706
- plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1707
1530
  Object.keys(this.lifecycle).forEach((key)=>{
1708
1531
  const pluginLife = plugin[key];
1709
1532
  if (pluginLife) {
@@ -1722,6 +1545,17 @@ class PluginSystem {
1722
1545
  }
1723
1546
  });
1724
1547
  }
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
+ }
1725
1559
  constructor(lifecycle){
1726
1560
  this.registerPlugins = {};
1727
1561
  this.lifecycle = lifecycle;
@@ -1729,6 +1563,169 @@ class PluginSystem {
1729
1563
  }
1730
1564
  }
1731
1565
 
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
+
1732
1729
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1733
1730
  const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
1734
1731
  if (!remoteEntryInfo.url) {
@@ -2998,7 +2995,14 @@ class FederationHost {
2998
2995
  return optionsRes;
2999
2996
  }
3000
2997
  registerPlugins(plugins) {
3001
- const pluginRes = registerPlugins(plugins, this);
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
+ ]);
3002
3006
  // Merge plugin
3003
3007
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3004
3008
  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, createLink, createScript, safeToString, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
2
+ import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode, composeKeyWithSeparator, loadScriptNode, loadScript, safeToString, createLink, createScript, 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
 
@@ -295,8 +295,8 @@ const getGlobalHostPlugins = ()=>nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
295
295
  const getPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
296
296
  const setPreloaded = (id)=>CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
297
297
 
298
- const DEFAULT_SCOPE = 'default';
299
298
  const DEFAULT_REMOTE_TYPE = 'global';
299
+ const DEFAULT_SCOPE = 'default';
300
300
 
301
301
  // fork from https://github.com/originjs/vite-plugin-federation/blob/v1.1.12/packages/lib/src/utils/semver/index.ts
302
302
  // those constants are based on https://www.rubydoc.info/gems/semantic_range/3.0.0/SemanticRange#BUILDIDENTIFIER-constant
@@ -942,6 +942,34 @@ 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
+
945
973
  function getBuilderId() {
946
974
  //@ts-ignore
947
975
  return typeof FEDERATION_BUILD_IDENTIFIER !== 'undefined' ? FEDERATION_BUILD_IDENTIFIER : '';
@@ -1011,16 +1039,8 @@ function matchRemote(remotes, nameOrAlias) {
1011
1039
  return;
1012
1040
  }
1013
1041
 
1014
- function registerPlugins(plugins, instance) {
1042
+ function registerPlugins(plugins, hookInstances) {
1015
1043
  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
- ];
1024
1044
  // Incorporate global plugins
1025
1045
  if (globalPlugins.length > 0) {
1026
1046
  globalPlugins.forEach((plugin)=>{
@@ -1032,7 +1052,7 @@ function registerPlugins(plugins, instance) {
1032
1052
  if (plugins && plugins.length > 0) {
1033
1053
  plugins.forEach((plugin)=>{
1034
1054
  hookInstances.forEach((hookInstance)=>{
1035
- hookInstance.applyPlugin(plugin, instance);
1055
+ hookInstance.applyPlugin(plugin);
1036
1056
  });
1037
1057
  });
1038
1058
  }
@@ -1219,202 +1239,6 @@ function getRemoteInfo(remote) {
1219
1239
  });
1220
1240
  }
1221
1241
 
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
-
1418
1242
  let Module = class Module {
1419
1243
  async getEntry() {
1420
1244
  if (this.remoteEntryExports) {
@@ -1695,14 +1519,13 @@ class AsyncWaterfallHook extends SyncHook {
1695
1519
  }
1696
1520
 
1697
1521
  class PluginSystem {
1698
- applyPlugin(plugin, instance) {
1522
+ applyPlugin(plugin) {
1699
1523
  assert(isPlainObject(plugin), 'Plugin configuration is invalid.');
1700
1524
  // The plugin's name is mandatory and must be unique
1701
1525
  const pluginName = plugin.name;
1702
1526
  assert(pluginName, 'A name must be provided by the plugin.');
1703
1527
  if (!this.registerPlugins[pluginName]) {
1704
1528
  this.registerPlugins[pluginName] = plugin;
1705
- plugin.apply == null ? void 0 : plugin.apply.call(plugin, instance);
1706
1529
  Object.keys(this.lifecycle).forEach((key)=>{
1707
1530
  const pluginLife = plugin[key];
1708
1531
  if (pluginLife) {
@@ -1721,6 +1544,17 @@ class PluginSystem {
1721
1544
  }
1722
1545
  });
1723
1546
  }
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
+ }
1724
1558
  constructor(lifecycle){
1725
1559
  this.registerPlugins = {};
1726
1560
  this.lifecycle = lifecycle;
@@ -1728,6 +1562,169 @@ class PluginSystem {
1728
1562
  }
1729
1563
  }
1730
1564
 
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
+
1731
1728
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
1732
1729
  const remoteEntryInfo = getRemoteEntryInfoFromSnapshot(remoteSnapshot);
1733
1730
  if (!remoteEntryInfo.url) {
@@ -2997,7 +2994,14 @@ class FederationHost {
2997
2994
  return optionsRes;
2998
2995
  }
2999
2996
  registerPlugins(plugins) {
3000
- const pluginRes = registerPlugins(plugins, this);
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
+ ]);
3001
3005
  // Merge plugin
3002
3006
  this.options.plugins = this.options.plugins.reduce((res, plugin)=>{
3003
3007
  if (!plugin) return res;
@@ -1,2 +1,2 @@
1
- export declare const DEFAULT_SCOPE = "default";
2
1
  export declare const DEFAULT_REMOTE_TYPE = "global";
2
+ export declare const DEFAULT_SCOPE = "default";
@@ -1,7 +1,5 @@
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';
5
3
  interface IShareUtils {
6
4
  getRegisteredShare: typeof getRegisteredShare;
7
5
  getGlobalShareScope: typeof getGlobalShareScope;
@@ -28,11 +26,6 @@ interface IGlobalUtils {
28
26
  declare const _default: {
29
27
  global: IGlobalUtils;
30
28
  share: IShareUtils;
31
- utils: {
32
- matchRemoteWithNameAndExpose: typeof matchRemoteWithNameAndExpose;
33
- preloadAssets: typeof preloadAssets;
34
- getRemoteInfo: typeof getRemoteInfo;
35
- };
36
29
  };
37
30
  export default _default;
38
31
  export type { IGlobalUtils, IShareUtils };
@@ -30,6 +30,5 @@ 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;
34
33
  };
35
34
  export {};
@@ -1,16 +1,15 @@
1
- import type { FederationHost } from '../../core';
2
1
  export type Plugin<T extends Record<string, any>> = {
3
2
  [k in keyof T]?: Parameters<T[k]['on']>[0];
4
3
  } & {
5
4
  name: string;
6
5
  version?: string;
7
- apply?: (instance: FederationHost) => void;
8
6
  };
9
7
  export declare class PluginSystem<T extends Record<string, any>> {
10
8
  lifecycle: T;
11
9
  lifecycleKeys: Array<keyof T>;
12
10
  registerPlugins: Record<string, Plugin<T>>;
13
11
  constructor(lifecycle: T);
14
- applyPlugin(plugin: Plugin<T>, instance: FederationHost): void;
12
+ applyPlugin(plugin: Plugin<T>): void;
15
13
  removePlugin(pluginName: string): void;
14
+ inherit<T extends PluginSystem<any>>({ lifecycle, registerPlugins, }: T): void;
16
15
  }
@@ -1,3 +1,4 @@
1
1
  import { FederationHost } from '../core';
2
2
  import { UserOptions } from '../type';
3
- export declare function registerPlugins(plugins: UserOptions['plugins'], instance: FederationHost): import("../type").FederationRuntimePlugin[] | undefined;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/runtime-core",
3
- "version": "0.0.0-next-20250708134245",
3
+ "version": "0.0.0-next-20250709032753",
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-20250708134245",
56
- "@module-federation/error-codes": "0.0.0-next-20250708134245"
55
+ "@module-federation/sdk": "0.0.0-next-20250709032753",
56
+ "@module-federation/error-codes": "0.0.0-next-20250709032753"
57
57
  }
58
58
  }