@module-federation/sdk 0.0.0-next-20240511031741 → 0.0.0-next-20240515062211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -15,27 +15,27 @@ function _define_property$3(obj, key, value) {
15
15
  }
16
16
  return obj;
17
17
  }
18
- var FederationModuleManifest = "federation-manifest.json";
19
- var MANIFEST_EXT = ".json";
20
- var BROWSER_LOG_KEY = "FEDERATION_DEBUG";
21
- var BROWSER_LOG_VALUE = "1";
18
+ var FederationModuleManifest = 'federation-manifest.json';
19
+ var MANIFEST_EXT = '.json';
20
+ var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
21
+ var BROWSER_LOG_VALUE = '1';
22
22
  var NameTransformSymbol = {
23
- AT: "@",
24
- HYPHEN: "-",
25
- SLASH: "/"
23
+ AT: '@',
24
+ HYPHEN: '-',
25
+ SLASH: '/'
26
26
  };
27
27
  var _obj;
28
- var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, "scope_"), _define_property$3(_obj, NameTransformSymbol.HYPHEN, "_"), _define_property$3(_obj, NameTransformSymbol.SLASH, "__"), _obj);
28
+ var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$3(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$3(_obj, NameTransformSymbol.SLASH, '__'), _obj);
29
29
  var _obj1;
30
30
  var EncodedNameTransformMap = (_obj1 = {}, _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
31
- var SEPARATOR = ":";
32
- var ManifestFileName = "mf-manifest.json";
33
- var StatsFileName = "mf-stats.json";
31
+ var SEPARATOR = ':';
32
+ var ManifestFileName = 'mf-manifest.json';
33
+ var StatsFileName = 'mf-stats.json';
34
34
  var MFModuleType = {
35
- NPM: "npm",
36
- APP: "app"
35
+ NPM: 'npm',
36
+ APP: 'app'
37
37
  };
38
- var MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
38
+ var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
39
39
 
40
40
  var ContainerPlugin = /*#__PURE__*/Object.freeze({
41
41
  __proto__: null
@@ -54,16 +54,16 @@ var SharePlugin = /*#__PURE__*/Object.freeze({
54
54
  });
55
55
 
56
56
  function isBrowserEnv() {
57
- return typeof window !== "undefined";
57
+ return typeof window !== 'undefined';
58
58
  }
59
59
  function isDebugMode() {
60
- if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
61
- return Boolean(process.env["FEDERATION_DEBUG"]);
60
+ if (typeof process !== 'undefined' && process.env && process.env['FEDERATION_DEBUG']) {
61
+ return Boolean(process.env['FEDERATION_DEBUG']);
62
62
  }
63
- return typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG);
63
+ return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
64
64
  }
65
65
  var getProcessEnv = function getProcessEnv() {
66
- return typeof process !== "undefined" && process.env ? process.env : {};
66
+ return typeof process !== 'undefined' && process.env ? process.env : {};
67
67
  };
68
68
 
69
69
  function _array_like_to_array$2(arr, len) {
@@ -127,17 +127,17 @@ function safeToString(info) {
127
127
  try {
128
128
  return JSON.stringify(info, null, 2);
129
129
  } catch (e) {
130
- return "";
130
+ return '';
131
131
  }
132
132
  }
133
- var DEBUG_LOG = "[ FEDERATION DEBUG ]";
133
+ var DEBUG_LOG = '[ FEDERATION DEBUG ]';
134
134
  function safeGetLocalStorageItem() {
135
135
  try {
136
- if (typeof window !== "undefined" && window.localStorage) {
136
+ if (typeof window !== 'undefined' && window.localStorage) {
137
137
  return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
138
138
  }
139
139
  } catch (error) {
140
- return typeof document !== "undefined";
140
+ return typeof document !== 'undefined';
141
141
  }
142
142
  return false;
143
143
  }
@@ -158,11 +158,11 @@ var Logger = /*#__PURE__*/ function() {
158
158
  key: "info",
159
159
  value: function info(msg, info) {
160
160
  if (this.enable) {
161
- var argsToString = safeToString(info) || "";
161
+ var argsToString = safeToString(info) || '';
162
162
  if (isBrowserEnv()) {
163
- console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), "color:#3300CC");
163
+ console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
164
164
  } else {
165
- console.info("\x1b[34m%s", "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ""));
165
+ console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
166
166
  }
167
167
  }
168
168
  }
@@ -176,11 +176,11 @@ var Logger = /*#__PURE__*/ function() {
176
176
  if (this.enable) {
177
177
  if (isBrowserEnv()) {
178
178
  var _console;
179
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
179
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
180
180
  (_console = console).log.apply(_console, _to_consumable_array(args));
181
181
  } else {
182
182
  var _console1;
183
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
183
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
184
184
  (_console1 = console).log.apply(_console1, _to_consumable_array(args));
185
185
  }
186
186
  }
@@ -242,16 +242,16 @@ function _unsupported_iterable_to_array$1(o, minLen) {
242
242
  if (n === "Map" || n === "Set") return Array.from(n);
243
243
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
244
244
  }
245
- var LOG_CATEGORY = "[ Federation Runtime ]";
245
+ var LOG_CATEGORY = '[ Federation Runtime ]';
246
246
  // entry: name:version version : 1.0.0 | ^1.2.3
247
247
  // entry: name:entry entry: https://localhost:9000/federation-manifest.json
248
248
  var parseEntry = function(str, devVerOrUrl) {
249
249
  var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : SEPARATOR;
250
250
  var strSplit = str.split(separator);
251
- var devVersionOrUrl = getProcessEnv()["NODE_ENV"] === "development" && devVerOrUrl;
252
- var defaultVersion = "*";
251
+ var devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
252
+ var defaultVersion = '*';
253
253
  var isEntry = function(s) {
254
- return s.startsWith("http") || s.includes(MANIFEST_EXT);
254
+ return s.startsWith('http') || s.includes(MANIFEST_EXT);
255
255
  };
256
256
  // Check if the string starts with a type
257
257
  if (strSplit.length >= 2) {
@@ -292,7 +292,7 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
292
292
  args[_key] = arguments[_key];
293
293
  }
294
294
  if (!args.length) {
295
- return "";
295
+ return '';
296
296
  }
297
297
  return args.reduce(function(sum, cur) {
298
298
  if (!cur) {
@@ -302,13 +302,13 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
302
302
  return cur;
303
303
  }
304
304
  return "".concat(sum).concat(SEPARATOR).concat(cur);
305
- }, "");
305
+ }, '');
306
306
  };
307
307
  var encodeName = function encodeName(name) {
308
- var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "", withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
308
+ var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
309
309
  try {
310
- var ext = withExt ? ".js" : "";
311
- return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), "g"), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
310
+ var ext = withExt ? '.js' : '';
311
+ return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), 'g'), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
312
312
  } catch (err) {
313
313
  throw err;
314
314
  }
@@ -320,11 +320,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
320
320
  if (!decodedName.startsWith(prefix)) {
321
321
  return decodedName;
322
322
  }
323
- decodedName = decodedName.replace(new RegExp(prefix, "g"), "");
323
+ decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
324
324
  }
325
- decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
325
+ decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
326
326
  if (withExt) {
327
- decodedName = decodedName.replace(".js", "");
327
+ decodedName = decodedName.replace('.js', '');
328
328
  }
329
329
  return decodedName;
330
330
  } catch (err) {
@@ -333,32 +333,32 @@ var decodeName = function decodeName(name, prefix, withExt) {
333
333
  };
334
334
  var generateExposeFilename = function(exposeName, withExt) {
335
335
  if (!exposeName) {
336
- return "";
336
+ return '';
337
337
  }
338
338
  var expose = exposeName;
339
- if (expose === ".") {
340
- expose = "default_export";
339
+ if (expose === '.') {
340
+ expose = 'default_export';
341
341
  }
342
- if (expose.startsWith("./")) {
343
- expose = expose.replace("./", "");
342
+ if (expose.startsWith('./')) {
343
+ expose = expose.replace('./', '');
344
344
  }
345
- return encodeName(expose, "__federation_expose_", withExt);
345
+ return encodeName(expose, '__federation_expose_', withExt);
346
346
  };
347
347
  var generateShareFilename = function(pkgName, withExt) {
348
348
  if (!pkgName) {
349
- return "";
349
+ return '';
350
350
  }
351
- return encodeName(pkgName, "__federation_shared_", withExt);
351
+ return encodeName(pkgName, '__federation_shared_', withExt);
352
352
  };
353
353
  var getResourceUrl = function(module, sourceUrl) {
354
- if ("getPublicPath" in module) {
354
+ if ('getPublicPath' in module) {
355
355
  var publicPath = new Function(module.getPublicPath)();
356
356
  return "".concat(publicPath).concat(sourceUrl);
357
- } else if ("publicPath" in module) {
357
+ } else if ('publicPath' in module) {
358
358
  return "".concat(module.publicPath).concat(sourceUrl);
359
359
  } else {
360
- console.warn("Can not get resource url, if in debug mode, please ignore", module, sourceUrl);
361
- return "";
360
+ console.warn('Can not get resource url, if in debug mode, please ignore', module, sourceUrl);
361
+ return '';
362
362
  }
363
363
  };
364
364
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -431,15 +431,15 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
431
431
  return rName;
432
432
  }
433
433
  var transformPath = function(str) {
434
- if (str === ".") {
435
- return "";
434
+ if (str === '.') {
435
+ return '';
436
436
  }
437
- if (str.startsWith("./")) {
438
- return str.replace("./", "");
437
+ if (str.startsWith('./')) {
438
+ return str.replace('./', '');
439
439
  }
440
- if (str.startsWith("/")) {
440
+ if (str.startsWith('/')) {
441
441
  var strWithoutSlash = str.slice(1);
442
- if (strWithoutSlash.endsWith("/")) {
442
+ if (strWithoutSlash.endsWith('/')) {
443
443
  return strWithoutSlash.slice(0, -1);
444
444
  }
445
445
  return strWithoutSlash;
@@ -450,13 +450,13 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
450
450
  if (!transformedPath) {
451
451
  return rName;
452
452
  }
453
- if (transformedPath.endsWith("/")) {
453
+ if (transformedPath.endsWith('/')) {
454
454
  return "".concat(transformedPath).concat(rName);
455
455
  }
456
456
  return "".concat(transformedPath, "/").concat(rName);
457
457
  };
458
458
  function inferAutoPublicPath(url) {
459
- return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
459
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
460
460
  }
461
461
  // Priority: overrides > remotes
462
462
  // eslint-disable-next-line max-lines-per-function
@@ -466,8 +466,8 @@ function generateSnapshotFromManifest(manifest) {
466
466
  var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
467
467
  var remoteSnapshot;
468
468
  var getPublicPath = function() {
469
- if ("publicPath" in manifest.metaData) {
470
- if (manifest.metaData.publicPath === "auto" && version) {
469
+ if ('publicPath' in manifest.metaData) {
470
+ if (manifest.metaData.publicPath === 'auto' && version) {
471
471
  // use same implementation as publicPath auto runtime module implements
472
472
  return inferAutoPublicPath(version);
473
473
  }
@@ -488,7 +488,7 @@ function generateSnapshotFromManifest(manifest) {
488
488
  if (overridesKeys.includes(name)) {
489
489
  matchedVersion = overrides[name];
490
490
  } else {
491
- if ("version" in next) {
491
+ if ('version' in next) {
492
492
  matchedVersion = next.version;
493
493
  } else {
494
494
  matchedVersion = next.entry;
@@ -507,17 +507,17 @@ function generateSnapshotFromManifest(manifest) {
507
507
  matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
508
508
  };
509
509
  });
510
- var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName;
510
+ var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName, ssrRemoteEntry = _manifest_metaData2.ssrRemoteEntry;
511
511
  var exposes = manifest.exposes;
512
512
  var basicRemoteSnapshot = {
513
- version: version ? version : "",
513
+ version: version ? version : '',
514
514
  buildVersion: buildVersion,
515
515
  globalName: globalName,
516
516
  remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
517
517
  remoteEntryType: remoteEntryType,
518
518
  remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
519
- remoteTypesZip: remoteTypes.zip || "",
520
- remoteTypesAPI: remoteTypes.api || "",
519
+ remoteTypesZip: remoteTypes.zip || '',
520
+ remoteTypesAPI: remoteTypes.api || '',
521
521
  remotesInfo: remotesInfo,
522
522
  shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
523
523
  return {
@@ -547,7 +547,7 @@ function generateSnapshotFromManifest(manifest) {
547
547
  prefetchEntryType: type
548
548
  });
549
549
  }
550
- if ("publicPath" in manifest.metaData) {
550
+ if ('publicPath' in manifest.metaData) {
551
551
  remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
552
552
  publicPath: getPublicPath()
553
553
  });
@@ -556,13 +556,26 @@ function generateSnapshotFromManifest(manifest) {
556
556
  getPublicPath: getPublicPath()
557
557
  });
558
558
  }
559
+ if (ssrRemoteEntry) {
560
+ var fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
561
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
562
+ remoteSnapshot.ssrRemoteEntryType = 'cjs:webpack';
563
+ }
559
564
  return remoteSnapshot;
560
565
  }
561
566
  function isManifestProvider(moduleInfo) {
562
- if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
563
- return true;
567
+ if (isBrowserEnv()) {
568
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
569
+ return true;
570
+ } else {
571
+ return false;
572
+ }
564
573
  } else {
565
- return false;
574
+ if ('ssrRemoteEntry' in moduleInfo && moduleInfo.ssrRemoteEntry && moduleInfo.ssrRemoteEntry.includes(MANIFEST_EXT)) {
575
+ return true;
576
+ } else {
577
+ return false;
578
+ }
566
579
  }
567
580
  }
568
581
 
@@ -741,8 +754,8 @@ function _safeWrapper() {
741
754
  function isStaticResourcesEqual(url1, url2) {
742
755
  var REG_EXP = /^(https?:)?\/\//i;
743
756
  // Transform url1 and url2 into relative paths
744
- var relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
745
- var relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
757
+ var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
758
+ var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
746
759
  // Check if the relative paths are identical
747
760
  return relativeUrl1 === relativeUrl2;
748
761
  }
@@ -750,10 +763,10 @@ function createScript(url, cb, attrs, createScriptHook) {
750
763
  // Retrieve the existing script element by its src attribute
751
764
  var script = null;
752
765
  var needAttach = true;
753
- var scripts = document.getElementsByTagName("script");
766
+ var scripts = document.getElementsByTagName('script');
754
767
  for(var i = 0; i < scripts.length; i++){
755
768
  var s = scripts[i];
756
- var scriptSrc = s.getAttribute("src");
769
+ var scriptSrc = s.getAttribute('src');
757
770
  if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
758
771
  script = s;
759
772
  needAttach = false;
@@ -761,8 +774,8 @@ function createScript(url, cb, attrs, createScriptHook) {
761
774
  }
762
775
  }
763
776
  if (!script) {
764
- script = document.createElement("script");
765
- script.type = "text/javascript";
777
+ script = document.createElement('script');
778
+ script.type = 'text/javascript';
766
779
  script.src = url;
767
780
  if (createScriptHook) {
768
781
  var createScriptRes = createScriptHook(url);
@@ -774,7 +787,7 @@ function createScript(url, cb, attrs, createScriptHook) {
774
787
  if (attrs) {
775
788
  Object.keys(attrs).forEach(function(name) {
776
789
  if (script) {
777
- if (name === "async" || name === "defer") {
790
+ if (name === 'async' || name === 'defer') {
778
791
  script[name] = attrs[name];
779
792
  } else {
780
793
  script.setAttribute(name, attrs[name]);
@@ -813,20 +826,20 @@ function createLink(url, cb) {
813
826
  // Retrieve the existing script element by its src attribute
814
827
  var link = null;
815
828
  var needAttach = true;
816
- var links = document.getElementsByTagName("link");
829
+ var links = document.getElementsByTagName('link');
817
830
  for(var i = 0; i < links.length; i++){
818
831
  var l = links[i];
819
- var linkHref = l.getAttribute("href");
820
- var linkRef = l.getAttribute("ref");
821
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs["ref"]) {
832
+ var linkHref = l.getAttribute('href');
833
+ var linkRef = l.getAttribute('ref');
834
+ if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
822
835
  link = l;
823
836
  needAttach = false;
824
837
  break;
825
838
  }
826
839
  }
827
840
  if (!link) {
828
- link = document.createElement("link");
829
- link.setAttribute("href", url);
841
+ link = document.createElement('link');
842
+ link.setAttribute('href', url);
830
843
  if (createLinkHook) {
831
844
  var createLinkRes = createLinkHook(url);
832
845
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
@@ -870,7 +883,7 @@ function loadScript(url, info) {
870
883
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
871
884
  return new Promise(function(resolve, _reject) {
872
885
  var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
873
- needAttach && document.getElementsByTagName("head")[0].appendChild(script);
886
+ needAttach && document.getElementsByTagName('head')[0].appendChild(script);
874
887
  });
875
888
  }
876
889
 
@@ -1046,9 +1059,9 @@ function _ts_generator(thisArg, body) {
1046
1059
  }
1047
1060
  function importNodeModule(name) {
1048
1061
  if (!name) {
1049
- throw new Error("import specifier is required");
1062
+ throw new Error('import specifier is required');
1050
1063
  }
1051
- var importModule = new Function("name", "return import(name)");
1064
+ var importModule = new Function('name', "return import(name)");
1052
1065
  return importModule(name).then(function(res) {
1053
1066
  return res.default;
1054
1067
  }).catch(function(error) {
@@ -1059,7 +1072,7 @@ function importNodeModule(name) {
1059
1072
  function createScriptNode(url, cb, attrs, createScriptHook) {
1060
1073
  if (createScriptHook) {
1061
1074
  var hookResult = createScriptHook(url);
1062
- if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
1075
+ if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1063
1076
  url = hookResult.url;
1064
1077
  }
1065
1078
  }
@@ -1067,7 +1080,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1067
1080
  try {
1068
1081
  urlObj = new URL(url);
1069
1082
  } catch (e) {
1070
- console.error("Error constructing URL:", e);
1083
+ console.error('Error constructing URL:', e);
1071
1084
  cb(new Error("Invalid URL: ".concat(e)));
1072
1085
  return;
1073
1086
  }
@@ -1077,13 +1090,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1077
1090
  return _ts_generator(this, function(_state) {
1078
1091
  switch(_state.label){
1079
1092
  case 0:
1080
- if (!(typeof fetch === "undefined")) return [
1093
+ if (!(typeof fetch === 'undefined')) return [
1081
1094
  3,
1082
1095
  2
1083
1096
  ];
1084
1097
  return [
1085
1098
  4,
1086
- importNodeModule("node-fetch")
1099
+ importNodeModule('node-fetch')
1087
1100
  ];
1088
1101
  case 1:
1089
1102
  fetchModule = _state.sent();
@@ -1108,7 +1121,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1108
1121
  return _ref.apply(this, arguments);
1109
1122
  };
1110
1123
  }();
1111
- console.log("fetching", urlObj.href);
1124
+ console.log('fetching', urlObj.href);
1112
1125
  getFetch().then(function(f) {
1113
1126
  f(urlObj.href).then(function(res) {
1114
1127
  return res.text();
@@ -1121,8 +1134,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1121
1134
  return [
1122
1135
  4,
1123
1136
  Promise.all([
1124
- importNodeModule("path"),
1125
- importNodeModule("vm")
1137
+ importNodeModule('path'),
1138
+ importNodeModule('vm')
1126
1139
  ])
1127
1140
  ];
1128
1141
  case 1:
@@ -1136,14 +1149,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1136
1149
  exports: {}
1137
1150
  }
1138
1151
  };
1139
- urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
1152
+ urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
1140
1153
  filename = path.basename(urlObj.pathname);
1141
1154
  try {
1142
1155
  script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
1143
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
1156
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
1144
1157
  exportedInterface = scriptContext.module.exports || scriptContext.exports;
1145
- if (attrs && exportedInterface && attrs["globalName"]) {
1146
- container = exportedInterface[attrs["globalName"]] || exportedInterface;
1158
+ if (attrs && exportedInterface && attrs['globalName']) {
1159
+ container = exportedInterface[attrs['globalName']] || exportedInterface;
1147
1160
  cb(undefined, container);
1148
1161
  return [
1149
1162
  2
@@ -1176,7 +1189,7 @@ function loadScriptNode(url, info) {
1176
1189
  reject(error);
1177
1190
  } else {
1178
1191
  var _info_attrs, _info_attrs1;
1179
- var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs["globalName"]) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1["name"], ":custom__");
1192
+ var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1['name'], ":custom__");
1180
1193
  var entryExports = globalThis[remoteEntryKey] = scriptContext;
1181
1194
  resolve(entryExports);
1182
1195
  }
@@ -1221,7 +1234,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1221
1234
  if (options === false) {
1222
1235
  return false;
1223
1236
  }
1224
- if (typeof options === "undefined") {
1237
+ if (typeof options === 'undefined') {
1225
1238
  if (enableDefault) {
1226
1239
  return defaultOptions;
1227
1240
  } else {
@@ -1231,7 +1244,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1231
1244
  if (options === true) {
1232
1245
  return defaultOptions;
1233
1246
  }
1234
- if (options && typeof options === "object") {
1247
+ if (options && typeof options === 'object') {
1235
1248
  return _object_spread({}, defaultOptions, options);
1236
1249
  }
1237
1250
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
package/dist/index.esm.js CHANGED
@@ -11,27 +11,27 @@ function _define_property$3(obj, key, value) {
11
11
  }
12
12
  return obj;
13
13
  }
14
- var FederationModuleManifest = "federation-manifest.json";
15
- var MANIFEST_EXT = ".json";
16
- var BROWSER_LOG_KEY = "FEDERATION_DEBUG";
17
- var BROWSER_LOG_VALUE = "1";
14
+ var FederationModuleManifest = 'federation-manifest.json';
15
+ var MANIFEST_EXT = '.json';
16
+ var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
17
+ var BROWSER_LOG_VALUE = '1';
18
18
  var NameTransformSymbol = {
19
- AT: "@",
20
- HYPHEN: "-",
21
- SLASH: "/"
19
+ AT: '@',
20
+ HYPHEN: '-',
21
+ SLASH: '/'
22
22
  };
23
23
  var _obj;
24
- var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, "scope_"), _define_property$3(_obj, NameTransformSymbol.HYPHEN, "_"), _define_property$3(_obj, NameTransformSymbol.SLASH, "__"), _obj);
24
+ var NameTransformMap = (_obj = {}, _define_property$3(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$3(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$3(_obj, NameTransformSymbol.SLASH, '__'), _obj);
25
25
  var _obj1;
26
26
  var EncodedNameTransformMap = (_obj1 = {}, _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$3(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
27
- var SEPARATOR = ":";
28
- var ManifestFileName = "mf-manifest.json";
29
- var StatsFileName = "mf-stats.json";
27
+ var SEPARATOR = ':';
28
+ var ManifestFileName = 'mf-manifest.json';
29
+ var StatsFileName = 'mf-stats.json';
30
30
  var MFModuleType = {
31
- NPM: "npm",
32
- APP: "app"
31
+ NPM: 'npm',
32
+ APP: 'app'
33
33
  };
34
- var MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
34
+ var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
35
35
 
36
36
  var ContainerPlugin = /*#__PURE__*/Object.freeze({
37
37
  __proto__: null
@@ -50,16 +50,16 @@ var SharePlugin = /*#__PURE__*/Object.freeze({
50
50
  });
51
51
 
52
52
  function isBrowserEnv() {
53
- return typeof window !== "undefined";
53
+ return typeof window !== 'undefined';
54
54
  }
55
55
  function isDebugMode() {
56
- if (typeof process !== "undefined" && process.env && process.env["FEDERATION_DEBUG"]) {
57
- return Boolean(process.env["FEDERATION_DEBUG"]);
56
+ if (typeof process !== 'undefined' && process.env && process.env['FEDERATION_DEBUG']) {
57
+ return Boolean(process.env['FEDERATION_DEBUG']);
58
58
  }
59
- return typeof FEDERATION_DEBUG !== "undefined" && Boolean(FEDERATION_DEBUG);
59
+ return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
60
60
  }
61
61
  var getProcessEnv = function getProcessEnv() {
62
- return typeof process !== "undefined" && process.env ? process.env : {};
62
+ return typeof process !== 'undefined' && process.env ? process.env : {};
63
63
  };
64
64
 
65
65
  function _array_like_to_array$2(arr, len) {
@@ -123,17 +123,17 @@ function safeToString(info) {
123
123
  try {
124
124
  return JSON.stringify(info, null, 2);
125
125
  } catch (e) {
126
- return "";
126
+ return '';
127
127
  }
128
128
  }
129
- var DEBUG_LOG = "[ FEDERATION DEBUG ]";
129
+ var DEBUG_LOG = '[ FEDERATION DEBUG ]';
130
130
  function safeGetLocalStorageItem() {
131
131
  try {
132
- if (typeof window !== "undefined" && window.localStorage) {
132
+ if (typeof window !== 'undefined' && window.localStorage) {
133
133
  return localStorage.getItem(BROWSER_LOG_KEY) === BROWSER_LOG_VALUE;
134
134
  }
135
135
  } catch (error) {
136
- return typeof document !== "undefined";
136
+ return typeof document !== 'undefined';
137
137
  }
138
138
  return false;
139
139
  }
@@ -154,11 +154,11 @@ var Logger = /*#__PURE__*/ function() {
154
154
  key: "info",
155
155
  value: function info(msg, info) {
156
156
  if (this.enable) {
157
- var argsToString = safeToString(info) || "";
157
+ var argsToString = safeToString(info) || '';
158
158
  if (isBrowserEnv()) {
159
- console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), "color:#3300CC");
159
+ console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
160
160
  } else {
161
- console.info("\x1b[34m%s", "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ""));
161
+ console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
162
162
  }
163
163
  }
164
164
  }
@@ -172,11 +172,11 @@ var Logger = /*#__PURE__*/ function() {
172
172
  if (this.enable) {
173
173
  if (isBrowserEnv()) {
174
174
  var _console;
175
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
175
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
176
176
  (_console = console).log.apply(_console, _to_consumable_array(args));
177
177
  } else {
178
178
  var _console1;
179
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), "color:#3300CC");
179
+ console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
180
180
  (_console1 = console).log.apply(_console1, _to_consumable_array(args));
181
181
  }
182
182
  }
@@ -238,16 +238,16 @@ function _unsupported_iterable_to_array$1(o, minLen) {
238
238
  if (n === "Map" || n === "Set") return Array.from(n);
239
239
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
240
240
  }
241
- var LOG_CATEGORY = "[ Federation Runtime ]";
241
+ var LOG_CATEGORY = '[ Federation Runtime ]';
242
242
  // entry: name:version version : 1.0.0 | ^1.2.3
243
243
  // entry: name:entry entry: https://localhost:9000/federation-manifest.json
244
244
  var parseEntry = function(str, devVerOrUrl) {
245
245
  var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : SEPARATOR;
246
246
  var strSplit = str.split(separator);
247
- var devVersionOrUrl = getProcessEnv()["NODE_ENV"] === "development" && devVerOrUrl;
248
- var defaultVersion = "*";
247
+ var devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
248
+ var defaultVersion = '*';
249
249
  var isEntry = function(s) {
250
- return s.startsWith("http") || s.includes(MANIFEST_EXT);
250
+ return s.startsWith('http') || s.includes(MANIFEST_EXT);
251
251
  };
252
252
  // Check if the string starts with a type
253
253
  if (strSplit.length >= 2) {
@@ -288,7 +288,7 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
288
288
  args[_key] = arguments[_key];
289
289
  }
290
290
  if (!args.length) {
291
- return "";
291
+ return '';
292
292
  }
293
293
  return args.reduce(function(sum, cur) {
294
294
  if (!cur) {
@@ -298,13 +298,13 @@ var composeKeyWithSeparator = function composeKeyWithSeparator() {
298
298
  return cur;
299
299
  }
300
300
  return "".concat(sum).concat(SEPARATOR).concat(cur);
301
- }, "");
301
+ }, '');
302
302
  };
303
303
  var encodeName = function encodeName(name) {
304
- var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "", withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
304
+ var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
305
305
  try {
306
- var ext = withExt ? ".js" : "";
307
- return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), "g"), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), "g"), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), "g"), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
306
+ var ext = withExt ? '.js' : '';
307
+ return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), 'g'), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
308
308
  } catch (err) {
309
309
  throw err;
310
310
  }
@@ -316,11 +316,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
316
316
  if (!decodedName.startsWith(prefix)) {
317
317
  return decodedName;
318
318
  }
319
- decodedName = decodedName.replace(new RegExp(prefix, "g"), "");
319
+ decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
320
320
  }
321
- decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), "g"), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
321
+ decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
322
322
  if (withExt) {
323
- decodedName = decodedName.replace(".js", "");
323
+ decodedName = decodedName.replace('.js', '');
324
324
  }
325
325
  return decodedName;
326
326
  } catch (err) {
@@ -329,32 +329,32 @@ var decodeName = function decodeName(name, prefix, withExt) {
329
329
  };
330
330
  var generateExposeFilename = function(exposeName, withExt) {
331
331
  if (!exposeName) {
332
- return "";
332
+ return '';
333
333
  }
334
334
  var expose = exposeName;
335
- if (expose === ".") {
336
- expose = "default_export";
335
+ if (expose === '.') {
336
+ expose = 'default_export';
337
337
  }
338
- if (expose.startsWith("./")) {
339
- expose = expose.replace("./", "");
338
+ if (expose.startsWith('./')) {
339
+ expose = expose.replace('./', '');
340
340
  }
341
- return encodeName(expose, "__federation_expose_", withExt);
341
+ return encodeName(expose, '__federation_expose_', withExt);
342
342
  };
343
343
  var generateShareFilename = function(pkgName, withExt) {
344
344
  if (!pkgName) {
345
- return "";
345
+ return '';
346
346
  }
347
- return encodeName(pkgName, "__federation_shared_", withExt);
347
+ return encodeName(pkgName, '__federation_shared_', withExt);
348
348
  };
349
349
  var getResourceUrl = function(module, sourceUrl) {
350
- if ("getPublicPath" in module) {
350
+ if ('getPublicPath' in module) {
351
351
  var publicPath = new Function(module.getPublicPath)();
352
352
  return "".concat(publicPath).concat(sourceUrl);
353
- } else if ("publicPath" in module) {
353
+ } else if ('publicPath' in module) {
354
354
  return "".concat(module.publicPath).concat(sourceUrl);
355
355
  } else {
356
- console.warn("Can not get resource url, if in debug mode, please ignore", module, sourceUrl);
357
- return "";
356
+ console.warn('Can not get resource url, if in debug mode, please ignore', module, sourceUrl);
357
+ return '';
358
358
  }
359
359
  };
360
360
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -427,15 +427,15 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
427
427
  return rName;
428
428
  }
429
429
  var transformPath = function(str) {
430
- if (str === ".") {
431
- return "";
430
+ if (str === '.') {
431
+ return '';
432
432
  }
433
- if (str.startsWith("./")) {
434
- return str.replace("./", "");
433
+ if (str.startsWith('./')) {
434
+ return str.replace('./', '');
435
435
  }
436
- if (str.startsWith("/")) {
436
+ if (str.startsWith('/')) {
437
437
  var strWithoutSlash = str.slice(1);
438
- if (strWithoutSlash.endsWith("/")) {
438
+ if (strWithoutSlash.endsWith('/')) {
439
439
  return strWithoutSlash.slice(0, -1);
440
440
  }
441
441
  return strWithoutSlash;
@@ -446,13 +446,13 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
446
446
  if (!transformedPath) {
447
447
  return rName;
448
448
  }
449
- if (transformedPath.endsWith("/")) {
449
+ if (transformedPath.endsWith('/')) {
450
450
  return "".concat(transformedPath).concat(rName);
451
451
  }
452
452
  return "".concat(transformedPath, "/").concat(rName);
453
453
  };
454
454
  function inferAutoPublicPath(url) {
455
- return url.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
455
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
456
456
  }
457
457
  // Priority: overrides > remotes
458
458
  // eslint-disable-next-line max-lines-per-function
@@ -462,8 +462,8 @@ function generateSnapshotFromManifest(manifest) {
462
462
  var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
463
463
  var remoteSnapshot;
464
464
  var getPublicPath = function() {
465
- if ("publicPath" in manifest.metaData) {
466
- if (manifest.metaData.publicPath === "auto" && version) {
465
+ if ('publicPath' in manifest.metaData) {
466
+ if (manifest.metaData.publicPath === 'auto' && version) {
467
467
  // use same implementation as publicPath auto runtime module implements
468
468
  return inferAutoPublicPath(version);
469
469
  }
@@ -484,7 +484,7 @@ function generateSnapshotFromManifest(manifest) {
484
484
  if (overridesKeys.includes(name)) {
485
485
  matchedVersion = overrides[name];
486
486
  } else {
487
- if ("version" in next) {
487
+ if ('version' in next) {
488
488
  matchedVersion = next.version;
489
489
  } else {
490
490
  matchedVersion = next.entry;
@@ -503,17 +503,17 @@ function generateSnapshotFromManifest(manifest) {
503
503
  matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
504
504
  };
505
505
  });
506
- var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName;
506
+ var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName, ssrRemoteEntry = _manifest_metaData2.ssrRemoteEntry;
507
507
  var exposes = manifest.exposes;
508
508
  var basicRemoteSnapshot = {
509
- version: version ? version : "",
509
+ version: version ? version : '',
510
510
  buildVersion: buildVersion,
511
511
  globalName: globalName,
512
512
  remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
513
513
  remoteEntryType: remoteEntryType,
514
514
  remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
515
- remoteTypesZip: remoteTypes.zip || "",
516
- remoteTypesAPI: remoteTypes.api || "",
515
+ remoteTypesZip: remoteTypes.zip || '',
516
+ remoteTypesAPI: remoteTypes.api || '',
517
517
  remotesInfo: remotesInfo,
518
518
  shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
519
519
  return {
@@ -543,7 +543,7 @@ function generateSnapshotFromManifest(manifest) {
543
543
  prefetchEntryType: type
544
544
  });
545
545
  }
546
- if ("publicPath" in manifest.metaData) {
546
+ if ('publicPath' in manifest.metaData) {
547
547
  remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
548
548
  publicPath: getPublicPath()
549
549
  });
@@ -552,13 +552,26 @@ function generateSnapshotFromManifest(manifest) {
552
552
  getPublicPath: getPublicPath()
553
553
  });
554
554
  }
555
+ if (ssrRemoteEntry) {
556
+ var fullSSRRemoteEntry = simpleJoinRemoteEntry(ssrRemoteEntry.path, ssrRemoteEntry.name);
557
+ remoteSnapshot.ssrRemoteEntry = fullSSRRemoteEntry;
558
+ remoteSnapshot.ssrRemoteEntryType = 'cjs:webpack';
559
+ }
555
560
  return remoteSnapshot;
556
561
  }
557
562
  function isManifestProvider(moduleInfo) {
558
- if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
559
- return true;
563
+ if (isBrowserEnv()) {
564
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
565
+ return true;
566
+ } else {
567
+ return false;
568
+ }
560
569
  } else {
561
- return false;
570
+ if ('ssrRemoteEntry' in moduleInfo && moduleInfo.ssrRemoteEntry && moduleInfo.ssrRemoteEntry.includes(MANIFEST_EXT)) {
571
+ return true;
572
+ } else {
573
+ return false;
574
+ }
562
575
  }
563
576
  }
564
577
 
@@ -737,8 +750,8 @@ function _safeWrapper() {
737
750
  function isStaticResourcesEqual(url1, url2) {
738
751
  var REG_EXP = /^(https?:)?\/\//i;
739
752
  // Transform url1 and url2 into relative paths
740
- var relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
741
- var relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
753
+ var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
754
+ var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
742
755
  // Check if the relative paths are identical
743
756
  return relativeUrl1 === relativeUrl2;
744
757
  }
@@ -746,10 +759,10 @@ function createScript(url, cb, attrs, createScriptHook) {
746
759
  // Retrieve the existing script element by its src attribute
747
760
  var script = null;
748
761
  var needAttach = true;
749
- var scripts = document.getElementsByTagName("script");
762
+ var scripts = document.getElementsByTagName('script');
750
763
  for(var i = 0; i < scripts.length; i++){
751
764
  var s = scripts[i];
752
- var scriptSrc = s.getAttribute("src");
765
+ var scriptSrc = s.getAttribute('src');
753
766
  if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
754
767
  script = s;
755
768
  needAttach = false;
@@ -757,8 +770,8 @@ function createScript(url, cb, attrs, createScriptHook) {
757
770
  }
758
771
  }
759
772
  if (!script) {
760
- script = document.createElement("script");
761
- script.type = "text/javascript";
773
+ script = document.createElement('script');
774
+ script.type = 'text/javascript';
762
775
  script.src = url;
763
776
  if (createScriptHook) {
764
777
  var createScriptRes = createScriptHook(url);
@@ -770,7 +783,7 @@ function createScript(url, cb, attrs, createScriptHook) {
770
783
  if (attrs) {
771
784
  Object.keys(attrs).forEach(function(name) {
772
785
  if (script) {
773
- if (name === "async" || name === "defer") {
786
+ if (name === 'async' || name === 'defer') {
774
787
  script[name] = attrs[name];
775
788
  } else {
776
789
  script.setAttribute(name, attrs[name]);
@@ -809,20 +822,20 @@ function createLink(url, cb) {
809
822
  // Retrieve the existing script element by its src attribute
810
823
  var link = null;
811
824
  var needAttach = true;
812
- var links = document.getElementsByTagName("link");
825
+ var links = document.getElementsByTagName('link');
813
826
  for(var i = 0; i < links.length; i++){
814
827
  var l = links[i];
815
- var linkHref = l.getAttribute("href");
816
- var linkRef = l.getAttribute("ref");
817
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs["ref"]) {
828
+ var linkHref = l.getAttribute('href');
829
+ var linkRef = l.getAttribute('ref');
830
+ if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
818
831
  link = l;
819
832
  needAttach = false;
820
833
  break;
821
834
  }
822
835
  }
823
836
  if (!link) {
824
- link = document.createElement("link");
825
- link.setAttribute("href", url);
837
+ link = document.createElement('link');
838
+ link.setAttribute('href', url);
826
839
  if (createLinkHook) {
827
840
  var createLinkRes = createLinkHook(url);
828
841
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
@@ -866,7 +879,7 @@ function loadScript(url, info) {
866
879
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
867
880
  return new Promise(function(resolve, _reject) {
868
881
  var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
869
- needAttach && document.getElementsByTagName("head")[0].appendChild(script);
882
+ needAttach && document.getElementsByTagName('head')[0].appendChild(script);
870
883
  });
871
884
  }
872
885
 
@@ -1042,9 +1055,9 @@ function _ts_generator(thisArg, body) {
1042
1055
  }
1043
1056
  function importNodeModule(name) {
1044
1057
  if (!name) {
1045
- throw new Error("import specifier is required");
1058
+ throw new Error('import specifier is required');
1046
1059
  }
1047
- var importModule = new Function("name", "return import(name)");
1060
+ var importModule = new Function('name', "return import(name)");
1048
1061
  return importModule(name).then(function(res) {
1049
1062
  return res.default;
1050
1063
  }).catch(function(error) {
@@ -1055,7 +1068,7 @@ function importNodeModule(name) {
1055
1068
  function createScriptNode(url, cb, attrs, createScriptHook) {
1056
1069
  if (createScriptHook) {
1057
1070
  var hookResult = createScriptHook(url);
1058
- if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
1071
+ if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1059
1072
  url = hookResult.url;
1060
1073
  }
1061
1074
  }
@@ -1063,7 +1076,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1063
1076
  try {
1064
1077
  urlObj = new URL(url);
1065
1078
  } catch (e) {
1066
- console.error("Error constructing URL:", e);
1079
+ console.error('Error constructing URL:', e);
1067
1080
  cb(new Error("Invalid URL: ".concat(e)));
1068
1081
  return;
1069
1082
  }
@@ -1073,13 +1086,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1073
1086
  return _ts_generator(this, function(_state) {
1074
1087
  switch(_state.label){
1075
1088
  case 0:
1076
- if (!(typeof fetch === "undefined")) return [
1089
+ if (!(typeof fetch === 'undefined')) return [
1077
1090
  3,
1078
1091
  2
1079
1092
  ];
1080
1093
  return [
1081
1094
  4,
1082
- importNodeModule("node-fetch")
1095
+ importNodeModule('node-fetch')
1083
1096
  ];
1084
1097
  case 1:
1085
1098
  fetchModule = _state.sent();
@@ -1104,7 +1117,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1104
1117
  return _ref.apply(this, arguments);
1105
1118
  };
1106
1119
  }();
1107
- console.log("fetching", urlObj.href);
1120
+ console.log('fetching', urlObj.href);
1108
1121
  getFetch().then(function(f) {
1109
1122
  f(urlObj.href).then(function(res) {
1110
1123
  return res.text();
@@ -1117,8 +1130,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1117
1130
  return [
1118
1131
  4,
1119
1132
  Promise.all([
1120
- importNodeModule("path"),
1121
- importNodeModule("vm")
1133
+ importNodeModule('path'),
1134
+ importNodeModule('vm')
1122
1135
  ])
1123
1136
  ];
1124
1137
  case 1:
@@ -1132,14 +1145,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1132
1145
  exports: {}
1133
1146
  }
1134
1147
  };
1135
- urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
1148
+ urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
1136
1149
  filename = path.basename(urlObj.pathname);
1137
1150
  try {
1138
1151
  script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
1139
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
1152
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
1140
1153
  exportedInterface = scriptContext.module.exports || scriptContext.exports;
1141
- if (attrs && exportedInterface && attrs["globalName"]) {
1142
- container = exportedInterface[attrs["globalName"]] || exportedInterface;
1154
+ if (attrs && exportedInterface && attrs['globalName']) {
1155
+ container = exportedInterface[attrs['globalName']] || exportedInterface;
1143
1156
  cb(undefined, container);
1144
1157
  return [
1145
1158
  2
@@ -1172,7 +1185,7 @@ function loadScriptNode(url, info) {
1172
1185
  reject(error);
1173
1186
  } else {
1174
1187
  var _info_attrs, _info_attrs1;
1175
- var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs["globalName"]) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1["name"], ":custom__");
1188
+ var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1['name'], ":custom__");
1176
1189
  var entryExports = globalThis[remoteEntryKey] = scriptContext;
1177
1190
  resolve(entryExports);
1178
1191
  }
@@ -1217,7 +1230,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1217
1230
  if (options === false) {
1218
1231
  return false;
1219
1232
  }
1220
- if (typeof options === "undefined") {
1233
+ if (typeof options === 'undefined') {
1221
1234
  if (enableDefault) {
1222
1235
  return defaultOptions;
1223
1236
  } else {
@@ -1227,7 +1240,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1227
1240
  if (options === true) {
1228
1241
  return defaultOptions;
1229
1242
  }
1230
- if (options && typeof options === "object") {
1243
+ if (options && typeof options === 'object') {
1231
1244
  return _object_spread({}, defaultOptions, options);
1232
1245
  }
1233
1246
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
@@ -10,27 +10,27 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
10
 
11
11
  function getWebpackPath(compiler) {
12
12
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
13
- framework: "other"
13
+ framework: 'other'
14
14
  };
15
15
  try {
16
16
  // @ts-ignore just throw err
17
17
  compiler.webpack();
18
- return "";
18
+ return '';
19
19
  } catch (err) {
20
20
  var _err_stack;
21
- var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split("\n")) || [];
21
+ var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split('\n')) || [];
22
22
  var webpackErrLocation = trace.find(function(item) {
23
- return item.includes("at webpack");
24
- }) || "";
25
- var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, "").slice(1, -1);
26
- var webpackPath = webpackLocationWithDetail.split(":").slice(0, -2).join(":");
27
- if ((options === null || options === void 0 ? void 0 : options.framework) === "nextjs") {
28
- if (webpackPath.endsWith("webpack.js")) {
29
- return webpackPath.replace("webpack.js", "index.js");
23
+ return item.includes('at webpack');
24
+ }) || '';
25
+ var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
26
+ var webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
27
+ if ((options === null || options === void 0 ? void 0 : options.framework) === 'nextjs') {
28
+ if (webpackPath.endsWith('webpack.js')) {
29
+ return webpackPath.replace('webpack.js', 'index.js');
30
30
  }
31
- return "";
31
+ return '';
32
32
  }
33
- return require.resolve("webpack", {
33
+ return require.resolve('webpack', {
34
34
  paths: [
35
35
  webpackPath
36
36
  ]
@@ -38,11 +38,11 @@ function getWebpackPath(compiler) {
38
38
  }
39
39
  }
40
40
  var normalizeWebpackPath = function(fullPath) {
41
- if (fullPath === "webpack") {
42
- return process.env["FEDERATION_WEBPACK_PATH"] || fullPath;
41
+ if (fullPath === 'webpack') {
42
+ return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
43
43
  }
44
- if (process.env["FEDERATION_WEBPACK_PATH"]) {
45
- return path__default["default"].resolve(process.env["FEDERATION_WEBPACK_PATH"], fullPath.replace("webpack", "../../"));
44
+ if (process.env['FEDERATION_WEBPACK_PATH']) {
45
+ return path__default["default"].resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
46
46
  }
47
47
  return fullPath;
48
48
  };
@@ -2,27 +2,27 @@ import path from 'path';
2
2
 
3
3
  function getWebpackPath(compiler) {
4
4
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
5
- framework: "other"
5
+ framework: 'other'
6
6
  };
7
7
  try {
8
8
  // @ts-ignore just throw err
9
9
  compiler.webpack();
10
- return "";
10
+ return '';
11
11
  } catch (err) {
12
12
  var _err_stack;
13
- var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split("\n")) || [];
13
+ var trace = ((_err_stack = err.stack) === null || _err_stack === void 0 ? void 0 : _err_stack.split('\n')) || [];
14
14
  var webpackErrLocation = trace.find(function(item) {
15
- return item.includes("at webpack");
16
- }) || "";
17
- var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, "").slice(1, -1);
18
- var webpackPath = webpackLocationWithDetail.split(":").slice(0, -2).join(":");
19
- if ((options === null || options === void 0 ? void 0 : options.framework) === "nextjs") {
20
- if (webpackPath.endsWith("webpack.js")) {
21
- return webpackPath.replace("webpack.js", "index.js");
15
+ return item.includes('at webpack');
16
+ }) || '';
17
+ var webpackLocationWithDetail = webpackErrLocation.replace(/[^\(\)]+/, '').slice(1, -1);
18
+ var webpackPath = webpackLocationWithDetail.split(':').slice(0, -2).join(':');
19
+ if ((options === null || options === void 0 ? void 0 : options.framework) === 'nextjs') {
20
+ if (webpackPath.endsWith('webpack.js')) {
21
+ return webpackPath.replace('webpack.js', 'index.js');
22
22
  }
23
- return "";
23
+ return '';
24
24
  }
25
- return require.resolve("webpack", {
25
+ return require.resolve('webpack', {
26
26
  paths: [
27
27
  webpackPath
28
28
  ]
@@ -30,11 +30,11 @@ function getWebpackPath(compiler) {
30
30
  }
31
31
  }
32
32
  var normalizeWebpackPath = function(fullPath) {
33
- if (fullPath === "webpack") {
34
- return process.env["FEDERATION_WEBPACK_PATH"] || fullPath;
33
+ if (fullPath === 'webpack') {
34
+ return process.env['FEDERATION_WEBPACK_PATH'] || fullPath;
35
35
  }
36
- if (process.env["FEDERATION_WEBPACK_PATH"]) {
37
- return path.resolve(process.env["FEDERATION_WEBPACK_PATH"], fullPath.replace("webpack", "../../"));
36
+ if (process.env['FEDERATION_WEBPACK_PATH']) {
37
+ return path.resolve(process.env['FEDERATION_WEBPACK_PATH'], fullPath.replace('webpack', '../../'));
38
38
  }
39
39
  return fullPath;
40
40
  };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
@@ -159,6 +159,7 @@ export interface ModuleFederationPluginOptions {
159
159
  manifest?: boolean | PluginManifestOptions;
160
160
  dev?: boolean | PluginDevOptions;
161
161
  dts?: boolean | PluginDtsOptions;
162
+ async?: boolean;
162
163
  }
163
164
  /**
164
165
  * Modules that should be exposed by this container. Property names are used as public paths.
@@ -23,6 +23,8 @@ interface BasicModuleInfo {
23
23
  export interface BasicProviderModuleInfo extends BasicModuleInfo {
24
24
  remoteEntry: string;
25
25
  remoteEntryType: RemoteEntryType;
26
+ ssrRemoteEntry?: string;
27
+ ssrRemoteEntryType?: RemoteEntryType;
26
28
  remoteManifest?: string;
27
29
  globalName: string;
28
30
  modules: Array<{
@@ -42,6 +44,7 @@ interface BasicProviderModuleInfoWithGetPublicPath extends BasicProviderModuleIn
42
44
  }
43
45
  export interface ManifestProvider {
44
46
  remoteEntry: string;
47
+ ssrRemoteEntry?: string;
45
48
  version?: string;
46
49
  }
47
50
  export interface PureEntryProvider extends ManifestProvider {
@@ -1,6 +1,6 @@
1
1
  import type { RemoteWithEntry, RemoteWithVersion } from './common';
2
- export type RemoteEntryType = 'esm' | 'global';
3
- interface ResourceInfo {
2
+ export type RemoteEntryType = 'esm' | 'global' | 'cjs:webpack';
3
+ export interface ResourceInfo {
4
4
  path: string;
5
5
  name: string;
6
6
  type: RemoteEntryType;
@@ -20,6 +20,7 @@ export interface BasicStatsMetaData {
20
20
  globalName: string;
21
21
  buildInfo: StatsBuildInfo;
22
22
  remoteEntry: ResourceInfo;
23
+ ssrRemoteEntry?: ResourceInfo;
23
24
  prefetchInterface?: boolean;
24
25
  prefetchEntry?: ResourceInfo;
25
26
  types: MetaDataTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.0-next-20240511031741",
3
+ "version": "0.0.0-next-20240515062211",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [