@module-federation/runtime 0.6.0 → 0.6.2

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.
@@ -0,0 +1 @@
1
+ export * from "./src/embedded";
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance } = __webpack_require__.federation.runtime;
6
+
7
+ exports.FederationHost = FederationHost;
8
+ exports.getInstance = getInstance;
9
+ exports.getRemoteEntry = getRemoteEntry;
10
+ exports.getRemoteInfo = getRemoteInfo;
11
+ exports.init = init;
12
+ exports.loadRemote = loadRemote;
13
+ exports.loadScript = loadScript;
14
+ exports.loadScriptNode = loadScriptNode;
15
+ exports.loadShare = loadShare;
16
+ exports.loadShareSync = loadShareSync;
17
+ exports.preloadRemote = preloadRemote;
18
+ exports.registerGlobalPlugins = registerGlobalPlugins;
19
+ exports.registerPlugins = registerPlugins;
20
+ exports.registerRemotes = registerRemotes;
@@ -0,0 +1,3 @@
1
+ const { FederationHost, registerGlobalPlugins, getRemoteEntry, getRemoteInfo, loadScript, loadScriptNode, init, loadRemote, loadShare, loadShareSync, preloadRemote, registerRemotes, registerPlugins, getInstance } = __webpack_require__.federation.runtime;
2
+
3
+ export { FederationHost, getInstance, getRemoteEntry, getRemoteInfo, init, loadRemote, loadScript, loadScriptNode, loadShare, loadShareSync, preloadRemote, registerGlobalPlugins, registerPlugins, registerRemotes };
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var share = require('./share.cjs.js');
4
+ require('./polyfills.cjs.js');
5
+ require('@module-federation/sdk');
4
6
 
5
7
  const ShareUtils = {
6
8
  getRegisteredShare: share.getRegisteredShare,
@@ -1,4 +1,6 @@
1
- import { q as getRegisteredShare, A as getGlobalShareScope, G as Global, K as nativeGlobal, L as resetFederationGlobalInfo, F as getGlobalFederationInstance, I as setGlobalFederationInstance, H as getGlobalFederationConstructor, E as setGlobalFederationConstructor, n as getInfoWithoutType, x as getGlobalSnapshot, M as getTargetSnapshotInfoByModuleInfo, t as getGlobalSnapshotInfoByModuleInfo, v as setGlobalSnapshotInfoByModuleInfo, u as addGlobalSnapshot, c as getRemoteEntryExports, J as registerGlobalPlugins, g as getGlobalHostPlugins, o as getPreloaded, p as setPreloaded } from './share.esm.js';
1
+ import { o as getRegisteredShare, y as getGlobalShareScope, G as Global, I as nativeGlobal, J as resetFederationGlobalInfo, C as getGlobalFederationInstance, F as setGlobalFederationInstance, E as getGlobalFederationConstructor, B as setGlobalFederationConstructor, m as getInfoWithoutType, u as getGlobalSnapshot, K as getTargetSnapshotInfoByModuleInfo, q as getGlobalSnapshotInfoByModuleInfo, t as setGlobalSnapshotInfoByModuleInfo, r as addGlobalSnapshot, c as getRemoteEntryExports, H as registerGlobalPlugins, g as getGlobalHostPlugins, n as getPreloaded, s as setPreloaded } from './share.esm.js';
2
+ import './polyfills.esm.js';
3
+ import '@module-federation/sdk';
2
4
 
3
5
  const ShareUtils = {
4
6
  getRegisteredShare,
package/dist/index.cjs.js CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var share = require('./share.cjs.js');
5
+ var polyfills = require('./polyfills.cjs.js');
6
6
  var sdk = require('@module-federation/sdk');
7
+ var share = require('./share.cjs.js');
7
8
 
8
9
  // Function to match a remote with its name and expose
9
10
  // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
@@ -89,20 +90,6 @@ function registerPlugins$1(plugins, hookInstances) {
89
90
  return plugins;
90
91
  }
91
92
 
92
- function _extends$7() {
93
- _extends$7 = Object.assign || function(target) {
94
- for(var i = 1; i < arguments.length; i++){
95
- var source = arguments[i];
96
- for(var key in source){
97
- if (Object.prototype.hasOwnProperty.call(source, key)) {
98
- target[key] = source[key];
99
- }
100
- }
101
- }
102
- return target;
103
- };
104
- return _extends$7.apply(this, arguments);
105
- }
106
93
  async function loadEsmEntry({ entry, remoteEntryExports }) {
107
94
  return new Promise((resolve, reject)=>{
108
95
  try {
@@ -265,7 +252,7 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
265
252
  return share.globalLoading[uniqueKey];
266
253
  }
267
254
  function getRemoteInfo(remote) {
268
- return _extends$7({}, remote, {
255
+ return polyfills._extends({}, remote, {
269
256
  entry: 'entry' in remote ? remote.entry : '',
270
257
  type: remote.type || share.DEFAULT_REMOTE_TYPE,
271
258
  entryGlobalName: remote.entryGlobalName || remote.name,
@@ -273,20 +260,6 @@ function getRemoteInfo(remote) {
273
260
  });
274
261
  }
275
262
 
276
- function _extends$6() {
277
- _extends$6 = Object.assign || function(target) {
278
- for(var i = 1; i < arguments.length; i++){
279
- var source = arguments[i];
280
- for(var key in source){
281
- if (Object.prototype.hasOwnProperty.call(source, key)) {
282
- target[key] = source[key];
283
- }
284
- }
285
- }
286
- return target;
287
- };
288
- return _extends$6.apply(this, arguments);
289
- }
290
263
  let Module = class Module {
291
264
  async getEntry() {
292
265
  if (this.remoteEntryExports) {
@@ -298,7 +271,7 @@ let Module = class Module {
298
271
  remoteInfo: this.remoteInfo,
299
272
  remoteEntryExports: this.remoteEntryExports
300
273
  });
301
- share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${share.safeToString(this.remoteInfo)}`);
274
+ share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${sdk.safeToString(this.remoteInfo)}`);
302
275
  this.remoteEntryExports = remoteEntryExports;
303
276
  return this.remoteEntryExports;
304
277
  }
@@ -338,7 +311,7 @@ let Module = class Module {
338
311
  console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
339
312
  }
340
313
  await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
341
- await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
314
+ await this.host.hooks.lifecycle.initContainer.emit(polyfills._extends({}, initContainerOptions, {
342
315
  remoteEntryExports
343
316
  }));
344
317
  }
@@ -574,22 +547,8 @@ class PluginSystem {
574
547
  }
575
548
  }
576
549
 
577
- function _extends$5() {
578
- _extends$5 = Object.assign || function(target) {
579
- for(var i = 1; i < arguments.length; i++){
580
- var source = arguments[i];
581
- for(var key in source){
582
- if (Object.prototype.hasOwnProperty.call(source, key)) {
583
- target[key] = source[key];
584
- }
585
- }
586
- }
587
- return target;
588
- };
589
- return _extends$5.apply(this, arguments);
590
- }
591
550
  function defaultPreloadArgs(preloadConfig) {
592
- return _extends$5({
551
+ return polyfills._extends({
593
552
  resourceCategory: 'sync',
594
553
  share: true,
595
554
  depsRemote: true,
@@ -599,7 +558,7 @@ function defaultPreloadArgs(preloadConfig) {
599
558
  function formatPreloadArgs(remotes, preloadArgs) {
600
559
  return preloadArgs.map((args)=>{
601
560
  const remoteInfo = matchRemote(remotes, args.nameOrAlias);
602
- share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && share.safeToString({
561
+ share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && sdk.safeToString({
603
562
  remoteInfo,
604
563
  remotes
605
564
  })}`);
@@ -745,27 +704,13 @@ useLinkPreload = true) {
745
704
  }
746
705
  }
747
706
 
748
- function _extends$4() {
749
- _extends$4 = Object.assign || function(target) {
750
- for(var i = 1; i < arguments.length; i++){
751
- var source = arguments[i];
752
- for(var key in source){
753
- if (Object.prototype.hasOwnProperty.call(source, key)) {
754
- target[key] = source[key];
755
- }
756
- }
757
- }
758
- return target;
759
- };
760
- return _extends$4.apply(this, arguments);
761
- }
762
707
  function assignRemoteInfo(remoteInfo, remoteSnapshot) {
763
708
  const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
764
709
  if (!remoteEntryInfo.url) {
765
710
  share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
766
711
  }
767
712
  let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
768
- if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
713
+ if (!sdk.isBrowserEnv() && !entryUrl.startsWith('http')) {
769
714
  entryUrl = `https:${entryUrl}`;
770
715
  }
771
716
  remoteInfo.type = remoteEntryInfo.type;
@@ -806,7 +751,7 @@ function snapshotPlugin() {
806
751
  if (assets) {
807
752
  preloadAssets(remoteInfo, origin, assets, false);
808
753
  }
809
- return _extends$4({}, args, {
754
+ return polyfills._extends({}, args, {
810
755
  remoteSnapshot
811
756
  });
812
757
  }
@@ -1027,20 +972,6 @@ const generatePreloadAssetsPlugin = function() {
1027
972
  };
1028
973
  };
1029
974
 
1030
- function _extends$3() {
1031
- _extends$3 = Object.assign || function(target) {
1032
- for(var i = 1; i < arguments.length; i++){
1033
- var source = arguments[i];
1034
- for(var key in source){
1035
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1036
- target[key] = source[key];
1037
- }
1038
- }
1039
- }
1040
- return target;
1041
- };
1042
- return _extends$3.apply(this, arguments);
1043
- }
1044
975
  function getGlobalRemoteInfo(moduleInfo, origin) {
1045
976
  const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
1046
977
  name: origin.options.name,
@@ -1108,7 +1039,7 @@ class SnapshotHandler {
1108
1039
  // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
1109
1040
  if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
1110
1041
  if ('version' in moduleInfo || 'entry' in moduleInfo) {
1111
- hostSnapshot.remotesInfo = _extends$3({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
1042
+ hostSnapshot.remotesInfo = polyfills._extends({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
1112
1043
  [moduleInfo.name]: {
1113
1044
  matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
1114
1045
  }
@@ -1126,10 +1057,10 @@ class SnapshotHandler {
1126
1057
  // global snapshot includes manifest or module info includes manifest
1127
1058
  if (globalRemoteSnapshot) {
1128
1059
  if (sdk.isManifestProvider(globalRemoteSnapshot)) {
1129
- const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
1060
+ const remoteEntry = sdk.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
1130
1061
  const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
1131
1062
  // eslint-disable-next-line @typescript-eslint/no-shadow
1132
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
1063
+ const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(polyfills._extends({}, moduleInfo, {
1133
1064
  // The global remote may be overridden
1134
1065
  // Therefore, set the snapshot key to the global address of the actual request
1135
1066
  entry: remoteEntry
@@ -1235,32 +1166,6 @@ class SnapshotHandler {
1235
1166
  }
1236
1167
  }
1237
1168
 
1238
- function _extends$2() {
1239
- _extends$2 = Object.assign || function(target) {
1240
- for(var i = 1; i < arguments.length; i++){
1241
- var source = arguments[i];
1242
- for(var key in source){
1243
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1244
- target[key] = source[key];
1245
- }
1246
- }
1247
- }
1248
- return target;
1249
- };
1250
- return _extends$2.apply(this, arguments);
1251
- }
1252
- function _object_without_properties_loose(source, excluded) {
1253
- if (source == null) return {};
1254
- var target = {};
1255
- var sourceKeys = Object.keys(source);
1256
- var key, i;
1257
- for(i = 0; i < sourceKeys.length; i++){
1258
- key = sourceKeys[i];
1259
- if (excluded.indexOf(key) >= 0) continue;
1260
- target[key] = source[key];
1261
- }
1262
- return target;
1263
- }
1264
1169
  class SharedHandler {
1265
1170
  // register shared in shareScopeMap
1266
1171
  registerShared(globalOptions, userOptions) {
@@ -1552,7 +1457,7 @@ class SharedHandler {
1552
1457
  });
1553
1458
  }
1554
1459
  setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1555
- const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
1460
+ const { version, scope = 'default' } = shared, shareInfo = polyfills._object_without_properties_loose(shared, [
1556
1461
  "version",
1557
1462
  "scope"
1558
1463
  ]);
@@ -1566,21 +1471,25 @@ class SharedHandler {
1566
1471
  if (!this.shareScopeMap[sc][pkgName]) {
1567
1472
  this.shareScopeMap[sc][pkgName] = {};
1568
1473
  }
1569
- if (this.shareScopeMap[sc][pkgName][version]) {
1474
+ if (!this.shareScopeMap[sc][pkgName][version]) {
1475
+ this.shareScopeMap[sc][pkgName][version] = polyfills._extends({
1476
+ version,
1477
+ scope: [
1478
+ 'default'
1479
+ ]
1480
+ }, shareInfo, {
1481
+ lib,
1482
+ loaded,
1483
+ loading
1484
+ });
1485
+ if (get) {
1486
+ this.shareScopeMap[sc][pkgName][version].get = get;
1487
+ }
1570
1488
  return;
1571
1489
  }
1572
- this.shareScopeMap[sc][pkgName][version] = _extends$2({
1573
- version,
1574
- scope: [
1575
- 'default'
1576
- ]
1577
- }, shareInfo, {
1578
- lib,
1579
- loaded,
1580
- loading
1581
- });
1582
- if (get) {
1583
- this.shareScopeMap[sc][pkgName][version].get = get;
1490
+ const registeredShared = this.shareScopeMap[sc][pkgName][version];
1491
+ if (loading && !registeredShared.loading) {
1492
+ registeredShared.loading = loading;
1584
1493
  }
1585
1494
  });
1586
1495
  }
@@ -1608,20 +1517,6 @@ class SharedHandler {
1608
1517
  }
1609
1518
  }
1610
1519
 
1611
- function _extends$1() {
1612
- _extends$1 = Object.assign || function(target) {
1613
- for(var i = 1; i < arguments.length; i++){
1614
- var source = arguments[i];
1615
- for(var key in source){
1616
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1617
- target[key] = source[key];
1618
- }
1619
- }
1620
- }
1621
- return target;
1622
- };
1623
- return _extends$1.apply(this, arguments);
1624
- }
1625
1520
  class RemoteHandler {
1626
1521
  formatAndRegisterRemote(globalOptions, userOptions) {
1627
1522
  const userRemotes = userOptions.remotes || [];
@@ -1778,7 +1673,7 @@ class RemoteHandler {
1778
1673
  `);
1779
1674
  const { remote: rawRemote } = remoteSplitInfo;
1780
1675
  const remoteInfo = getRemoteInfo(rawRemote);
1781
- const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
1676
+ const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(polyfills._extends({
1782
1677
  id: idRes
1783
1678
  }, remoteSplitInfo, {
1784
1679
  options: host.options,
@@ -1947,7 +1842,8 @@ class RemoteHandler {
1947
1842
  const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
1948
1843
  if (remoteKey) {
1949
1844
  delete hostGlobalSnapshot.remotesInfo[remoteKey];
1950
- if (Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
1845
+ if (//eslint-disable-next-line no-extra-boolean-cast
1846
+ Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
1951
1847
  delete share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
1952
1848
  }
1953
1849
  }
@@ -1977,20 +1873,6 @@ class RemoteHandler {
1977
1873
  }
1978
1874
  }
1979
1875
 
1980
- function _extends() {
1981
- _extends = Object.assign || function(target) {
1982
- for(var i = 1; i < arguments.length; i++){
1983
- var source = arguments[i];
1984
- for(var key in source){
1985
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1986
- target[key] = source[key];
1987
- }
1988
- }
1989
- }
1990
- return target;
1991
- };
1992
- return _extends.apply(this, arguments);
1993
- }
1994
1876
  class FederationHost {
1995
1877
  initOptions(userOptions) {
1996
1878
  this.registerPlugins(userOptions.plugins);
@@ -2056,7 +1938,7 @@ class FederationHost {
2056
1938
  }
2057
1939
  });
2058
1940
  }
2059
- const optionsRes = _extends({}, globalOptions, userOptions, {
1941
+ const optionsRes = polyfills._extends({}, globalOptions, userOptions, {
2060
1942
  plugins,
2061
1943
  remotes,
2062
1944
  shared: handledShared
@@ -2096,7 +1978,7 @@ class FederationHost {
2096
1978
  // maybe will change, temporarily for internal use only
2097
1979
  initContainer: new AsyncWaterfallHook('initContainer')
2098
1980
  });
2099
- this.version = "0.6.0";
1981
+ this.version = "0.6.2";
2100
1982
  this.moduleCache = new Map();
2101
1983
  this.loaderHook = new PluginSystem({
2102
1984
  // FIXME: may not be suitable , not open to the public yet
@@ -2117,7 +1999,7 @@ class FederationHost {
2117
1999
  ],
2118
2000
  remotes: [],
2119
2001
  shared: {},
2120
- inBrowser: share.isBrowserEnv()
2002
+ inBrowser: sdk.isBrowserEnv()
2121
2003
  };
2122
2004
  this.name = userOptions.name;
2123
2005
  this.options = defaultOptions;
@@ -2191,7 +2073,6 @@ function getInstance() {
2191
2073
  // Inject for debug
2192
2074
  share.setGlobalFederationConstructor(FederationHost);
2193
2075
 
2194
- exports.registerGlobalPlugins = share.registerGlobalPlugins;
2195
2076
  Object.defineProperty(exports, 'loadScript', {
2196
2077
  enumerable: true,
2197
2078
  get: function () { return sdk.loadScript; }
@@ -2200,6 +2081,7 @@ Object.defineProperty(exports, 'loadScriptNode', {
2200
2081
  enumerable: true,
2201
2082
  get: function () { return sdk.loadScriptNode; }
2202
2083
  });
2084
+ exports.registerGlobalPlugins = share.registerGlobalPlugins;
2203
2085
  exports.FederationHost = FederationHost;
2204
2086
  exports.getInstance = getInstance;
2205
2087
  exports.getRemoteEntry = getRemoteEntry;