@module-federation/sdk 0.1.12 → 0.1.14

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,11 +450,14 @@ 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
+ function inferAutoPublicPath(url) {
459
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
460
+ }
458
461
  // Priority: overrides > remotes
459
462
  // eslint-disable-next-line max-lines-per-function
460
463
  function generateSnapshotFromManifest(manifest) {
@@ -463,7 +466,11 @@ function generateSnapshotFromManifest(manifest) {
463
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;
464
467
  var remoteSnapshot;
465
468
  var getPublicPath = function() {
466
- if ("publicPath" in manifest.metaData) {
469
+ if ('publicPath' in manifest.metaData) {
470
+ if (manifest.metaData.publicPath === 'auto' && version) {
471
+ // use same implementation as publicPath auto runtime module implements
472
+ return inferAutoPublicPath(version);
473
+ }
467
474
  return manifest.metaData.publicPath;
468
475
  } else {
469
476
  return manifest.metaData.getPublicPath;
@@ -481,7 +488,7 @@ function generateSnapshotFromManifest(manifest) {
481
488
  if (overridesKeys.includes(name)) {
482
489
  matchedVersion = overrides[name];
483
490
  } else {
484
- if ("version" in next) {
491
+ if ('version' in next) {
485
492
  matchedVersion = next.version;
486
493
  } else {
487
494
  matchedVersion = next.entry;
@@ -503,14 +510,14 @@ function generateSnapshotFromManifest(manifest) {
503
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;
504
511
  var exposes = manifest.exposes;
505
512
  var basicRemoteSnapshot = {
506
- version: version ? version : "",
513
+ version: version ? version : '',
507
514
  buildVersion: buildVersion,
508
515
  globalName: globalName,
509
516
  remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
510
517
  remoteEntryType: remoteEntryType,
511
518
  remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
512
- remoteTypesZip: remoteTypes.zip || "",
513
- remoteTypesAPI: remoteTypes.api || "",
519
+ remoteTypesZip: remoteTypes.zip || '',
520
+ remoteTypesAPI: remoteTypes.api || '',
514
521
  remotesInfo: remotesInfo,
515
522
  shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
516
523
  return {
@@ -540,7 +547,7 @@ function generateSnapshotFromManifest(manifest) {
540
547
  prefetchEntryType: type
541
548
  });
542
549
  }
543
- if ("publicPath" in manifest.metaData) {
550
+ if ('publicPath' in manifest.metaData) {
544
551
  remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
545
552
  publicPath: getPublicPath()
546
553
  });
@@ -552,7 +559,7 @@ function generateSnapshotFromManifest(manifest) {
552
559
  return remoteSnapshot;
553
560
  }
554
561
  function isManifestProvider(moduleInfo) {
555
- if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
562
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
556
563
  return true;
557
564
  } else {
558
565
  return false;
@@ -734,8 +741,8 @@ function _safeWrapper() {
734
741
  function isStaticResourcesEqual(url1, url2) {
735
742
  var REG_EXP = /^(https?:)?\/\//i;
736
743
  // Transform url1 and url2 into relative paths
737
- var relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
738
- var relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
744
+ var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
745
+ var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
739
746
  // Check if the relative paths are identical
740
747
  return relativeUrl1 === relativeUrl2;
741
748
  }
@@ -743,10 +750,12 @@ function createScript(url, cb, attrs, createScriptHook) {
743
750
  // Retrieve the existing script element by its src attribute
744
751
  var script = null;
745
752
  var needAttach = true;
746
- var scripts = document.getElementsByTagName("script");
753
+ var timeout = 20000;
754
+ var timeoutId;
755
+ var scripts = document.getElementsByTagName('script');
747
756
  for(var i = 0; i < scripts.length; i++){
748
757
  var s = scripts[i];
749
- var scriptSrc = s.getAttribute("src");
758
+ var scriptSrc = s.getAttribute('src');
750
759
  if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
751
760
  script = s;
752
761
  needAttach = false;
@@ -754,20 +763,23 @@ function createScript(url, cb, attrs, createScriptHook) {
754
763
  }
755
764
  }
756
765
  if (!script) {
757
- script = document.createElement("script");
758
- script.type = "text/javascript";
766
+ script = document.createElement('script');
767
+ script.type = 'text/javascript';
759
768
  script.src = url;
760
769
  if (createScriptHook) {
761
770
  var createScriptRes = createScriptHook(url);
762
771
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
763
772
  script = createScriptRes;
773
+ } else if (typeof createScriptRes === 'object') {
774
+ if (createScriptRes.script) script = createScriptRes.script;
775
+ if (createScriptRes.timeout) timeout = createScriptRes.timeout;
764
776
  }
765
777
  }
766
778
  }
767
779
  if (attrs) {
768
780
  Object.keys(attrs).forEach(function(name) {
769
781
  if (script) {
770
- if (name === "async" || name === "defer") {
782
+ if (name === 'async' || name === 'defer') {
771
783
  script[name] = attrs[name];
772
784
  } else {
773
785
  script.setAttribute(name, attrs[name]);
@@ -777,6 +789,7 @@ function createScript(url, cb, attrs, createScriptHook) {
777
789
  }
778
790
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
779
791
  event) {
792
+ clearTimeout(timeoutId);
780
793
  // Prevent memory leaks in IE.
781
794
  if (script) {
782
795
  script.onerror = null;
@@ -795,6 +808,9 @@ function createScript(url, cb, attrs, createScriptHook) {
795
808
  };
796
809
  script.onerror = onScriptComplete.bind(null, script.onerror);
797
810
  script.onload = onScriptComplete.bind(null, script.onload);
811
+ timeoutId = setTimeout(function() {
812
+ onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
813
+ }, timeout);
798
814
  return {
799
815
  script: script,
800
816
  needAttach: needAttach
@@ -806,20 +822,20 @@ function createLink(url, cb) {
806
822
  // Retrieve the existing script element by its src attribute
807
823
  var link = null;
808
824
  var needAttach = true;
809
- var links = document.getElementsByTagName("link");
825
+ var links = document.getElementsByTagName('link');
810
826
  for(var i = 0; i < links.length; i++){
811
827
  var l = links[i];
812
- var linkHref = l.getAttribute("href");
813
- var linkRef = l.getAttribute("ref");
814
- 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']) {
815
831
  link = l;
816
832
  needAttach = false;
817
833
  break;
818
834
  }
819
835
  }
820
836
  if (!link) {
821
- link = document.createElement("link");
822
- link.setAttribute("href", url);
837
+ link = document.createElement('link');
838
+ link.setAttribute('href', url);
823
839
  if (createLinkHook) {
824
840
  var createLinkRes = createLinkHook(url);
825
841
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
@@ -863,7 +879,7 @@ function loadScript(url, info) {
863
879
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
864
880
  return new Promise(function(resolve, _reject) {
865
881
  var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
866
- needAttach && document.getElementsByTagName("head")[0].appendChild(script);
882
+ needAttach && document.getElementsByTagName('head')[0].appendChild(script);
867
883
  });
868
884
  }
869
885
 
@@ -1039,9 +1055,9 @@ function _ts_generator(thisArg, body) {
1039
1055
  }
1040
1056
  function importNodeModule(name) {
1041
1057
  if (!name) {
1042
- throw new Error("import specifier is required");
1058
+ throw new Error('import specifier is required');
1043
1059
  }
1044
- var importModule = new Function("name", "return import(name)");
1060
+ var importModule = new Function('name', "return import(name)");
1045
1061
  return importModule(name).then(function(res) {
1046
1062
  return res.default;
1047
1063
  }).catch(function(error) {
@@ -1052,7 +1068,7 @@ function importNodeModule(name) {
1052
1068
  function createScriptNode(url, cb, attrs, createScriptHook) {
1053
1069
  if (createScriptHook) {
1054
1070
  var hookResult = createScriptHook(url);
1055
- if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
1071
+ if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1056
1072
  url = hookResult.url;
1057
1073
  }
1058
1074
  }
@@ -1060,7 +1076,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1060
1076
  try {
1061
1077
  urlObj = new URL(url);
1062
1078
  } catch (e) {
1063
- console.error("Error constructing URL:", e);
1079
+ console.error('Error constructing URL:', e);
1064
1080
  cb(new Error("Invalid URL: ".concat(e)));
1065
1081
  return;
1066
1082
  }
@@ -1070,13 +1086,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1070
1086
  return _ts_generator(this, function(_state) {
1071
1087
  switch(_state.label){
1072
1088
  case 0:
1073
- if (!(typeof fetch === "undefined")) return [
1089
+ if (!(typeof fetch === 'undefined')) return [
1074
1090
  3,
1075
1091
  2
1076
1092
  ];
1077
1093
  return [
1078
1094
  4,
1079
- importNodeModule("node-fetch")
1095
+ importNodeModule('node-fetch')
1080
1096
  ];
1081
1097
  case 1:
1082
1098
  fetchModule = _state.sent();
@@ -1101,7 +1117,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1101
1117
  return _ref.apply(this, arguments);
1102
1118
  };
1103
1119
  }();
1104
- console.log("fetching", urlObj.href);
1120
+ console.log('fetching', urlObj.href);
1105
1121
  getFetch().then(function(f) {
1106
1122
  f(urlObj.href).then(function(res) {
1107
1123
  return res.text();
@@ -1114,8 +1130,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1114
1130
  return [
1115
1131
  4,
1116
1132
  Promise.all([
1117
- importNodeModule("path"),
1118
- importNodeModule("vm")
1133
+ importNodeModule('path'),
1134
+ importNodeModule('vm')
1119
1135
  ])
1120
1136
  ];
1121
1137
  case 1:
@@ -1129,14 +1145,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1129
1145
  exports: {}
1130
1146
  }
1131
1147
  };
1132
- urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
1148
+ urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
1133
1149
  filename = path.basename(urlObj.pathname);
1134
1150
  try {
1135
1151
  script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
1136
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
1152
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
1137
1153
  exportedInterface = scriptContext.module.exports || scriptContext.exports;
1138
- if (attrs && exportedInterface && attrs["globalName"]) {
1139
- container = exportedInterface[attrs["globalName"]] || exportedInterface;
1154
+ if (attrs && exportedInterface && attrs['globalName']) {
1155
+ container = exportedInterface[attrs['globalName']] || exportedInterface;
1140
1156
  cb(undefined, container);
1141
1157
  return [
1142
1158
  2
@@ -1169,7 +1185,7 @@ function loadScriptNode(url, info) {
1169
1185
  reject(error);
1170
1186
  } else {
1171
1187
  var _info_attrs, _info_attrs1;
1172
- 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__");
1173
1189
  var entryExports = globalThis[remoteEntryKey] = scriptContext;
1174
1190
  resolve(entryExports);
1175
1191
  }
@@ -1214,7 +1230,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1214
1230
  if (options === false) {
1215
1231
  return false;
1216
1232
  }
1217
- if (typeof options === "undefined") {
1233
+ if (typeof options === 'undefined') {
1218
1234
  if (enableDefault) {
1219
1235
  return defaultOptions;
1220
1236
  } else {
@@ -1224,7 +1240,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1224
1240
  if (options === true) {
1225
1241
  return defaultOptions;
1226
1242
  }
1227
- if (options && typeof options === "object") {
1243
+ if (options && typeof options === 'object') {
1228
1244
  return _object_spread({}, defaultOptions, options);
1229
1245
  }
1230
1246
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
@@ -1259,6 +1275,7 @@ exports.generateShareFilename = generateShareFilename;
1259
1275
  exports.generateSnapshotFromManifest = generateSnapshotFromManifest;
1260
1276
  exports.getProcessEnv = getProcessEnv;
1261
1277
  exports.getResourceUrl = getResourceUrl;
1278
+ exports.inferAutoPublicPath = inferAutoPublicPath;
1262
1279
  exports.isBrowserEnv = isBrowserEnv;
1263
1280
  exports.isDebugMode = isDebugMode;
1264
1281
  exports.isManifestProvider = isManifestProvider;
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,11 +446,14 @@ 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
+ function inferAutoPublicPath(url) {
455
+ return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
456
+ }
454
457
  // Priority: overrides > remotes
455
458
  // eslint-disable-next-line max-lines-per-function
456
459
  function generateSnapshotFromManifest(manifest) {
@@ -459,7 +462,11 @@ function generateSnapshotFromManifest(manifest) {
459
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;
460
463
  var remoteSnapshot;
461
464
  var getPublicPath = function() {
462
- if ("publicPath" in manifest.metaData) {
465
+ if ('publicPath' in manifest.metaData) {
466
+ if (manifest.metaData.publicPath === 'auto' && version) {
467
+ // use same implementation as publicPath auto runtime module implements
468
+ return inferAutoPublicPath(version);
469
+ }
463
470
  return manifest.metaData.publicPath;
464
471
  } else {
465
472
  return manifest.metaData.getPublicPath;
@@ -477,7 +484,7 @@ function generateSnapshotFromManifest(manifest) {
477
484
  if (overridesKeys.includes(name)) {
478
485
  matchedVersion = overrides[name];
479
486
  } else {
480
- if ("version" in next) {
487
+ if ('version' in next) {
481
488
  matchedVersion = next.version;
482
489
  } else {
483
490
  matchedVersion = next.entry;
@@ -499,14 +506,14 @@ function generateSnapshotFromManifest(manifest) {
499
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;
500
507
  var exposes = manifest.exposes;
501
508
  var basicRemoteSnapshot = {
502
- version: version ? version : "",
509
+ version: version ? version : '',
503
510
  buildVersion: buildVersion,
504
511
  globalName: globalName,
505
512
  remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
506
513
  remoteEntryType: remoteEntryType,
507
514
  remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
508
- remoteTypesZip: remoteTypes.zip || "",
509
- remoteTypesAPI: remoteTypes.api || "",
515
+ remoteTypesZip: remoteTypes.zip || '',
516
+ remoteTypesAPI: remoteTypes.api || '',
510
517
  remotesInfo: remotesInfo,
511
518
  shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
512
519
  return {
@@ -536,7 +543,7 @@ function generateSnapshotFromManifest(manifest) {
536
543
  prefetchEntryType: type
537
544
  });
538
545
  }
539
- if ("publicPath" in manifest.metaData) {
546
+ if ('publicPath' in manifest.metaData) {
540
547
  remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
541
548
  publicPath: getPublicPath()
542
549
  });
@@ -548,7 +555,7 @@ function generateSnapshotFromManifest(manifest) {
548
555
  return remoteSnapshot;
549
556
  }
550
557
  function isManifestProvider(moduleInfo) {
551
- if ("remoteEntry" in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
558
+ if ('remoteEntry' in moduleInfo && moduleInfo.remoteEntry.includes(MANIFEST_EXT)) {
552
559
  return true;
553
560
  } else {
554
561
  return false;
@@ -730,8 +737,8 @@ function _safeWrapper() {
730
737
  function isStaticResourcesEqual(url1, url2) {
731
738
  var REG_EXP = /^(https?:)?\/\//i;
732
739
  // Transform url1 and url2 into relative paths
733
- var relativeUrl1 = url1.replace(REG_EXP, "").replace(/\/$/, "");
734
- var relativeUrl2 = url2.replace(REG_EXP, "").replace(/\/$/, "");
740
+ var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
741
+ var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
735
742
  // Check if the relative paths are identical
736
743
  return relativeUrl1 === relativeUrl2;
737
744
  }
@@ -739,10 +746,12 @@ function createScript(url, cb, attrs, createScriptHook) {
739
746
  // Retrieve the existing script element by its src attribute
740
747
  var script = null;
741
748
  var needAttach = true;
742
- var scripts = document.getElementsByTagName("script");
749
+ var timeout = 20000;
750
+ var timeoutId;
751
+ var scripts = document.getElementsByTagName('script');
743
752
  for(var i = 0; i < scripts.length; i++){
744
753
  var s = scripts[i];
745
- var scriptSrc = s.getAttribute("src");
754
+ var scriptSrc = s.getAttribute('src');
746
755
  if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
747
756
  script = s;
748
757
  needAttach = false;
@@ -750,20 +759,23 @@ function createScript(url, cb, attrs, createScriptHook) {
750
759
  }
751
760
  }
752
761
  if (!script) {
753
- script = document.createElement("script");
754
- script.type = "text/javascript";
762
+ script = document.createElement('script');
763
+ script.type = 'text/javascript';
755
764
  script.src = url;
756
765
  if (createScriptHook) {
757
766
  var createScriptRes = createScriptHook(url);
758
767
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
759
768
  script = createScriptRes;
769
+ } else if (typeof createScriptRes === 'object') {
770
+ if (createScriptRes.script) script = createScriptRes.script;
771
+ if (createScriptRes.timeout) timeout = createScriptRes.timeout;
760
772
  }
761
773
  }
762
774
  }
763
775
  if (attrs) {
764
776
  Object.keys(attrs).forEach(function(name) {
765
777
  if (script) {
766
- if (name === "async" || name === "defer") {
778
+ if (name === 'async' || name === 'defer') {
767
779
  script[name] = attrs[name];
768
780
  } else {
769
781
  script.setAttribute(name, attrs[name]);
@@ -773,6 +785,7 @@ function createScript(url, cb, attrs, createScriptHook) {
773
785
  }
774
786
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
775
787
  event) {
788
+ clearTimeout(timeoutId);
776
789
  // Prevent memory leaks in IE.
777
790
  if (script) {
778
791
  script.onerror = null;
@@ -791,6 +804,9 @@ function createScript(url, cb, attrs, createScriptHook) {
791
804
  };
792
805
  script.onerror = onScriptComplete.bind(null, script.onerror);
793
806
  script.onload = onScriptComplete.bind(null, script.onload);
807
+ timeoutId = setTimeout(function() {
808
+ onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
809
+ }, timeout);
794
810
  return {
795
811
  script: script,
796
812
  needAttach: needAttach
@@ -802,20 +818,20 @@ function createLink(url, cb) {
802
818
  // Retrieve the existing script element by its src attribute
803
819
  var link = null;
804
820
  var needAttach = true;
805
- var links = document.getElementsByTagName("link");
821
+ var links = document.getElementsByTagName('link');
806
822
  for(var i = 0; i < links.length; i++){
807
823
  var l = links[i];
808
- var linkHref = l.getAttribute("href");
809
- var linkRef = l.getAttribute("ref");
810
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs["ref"]) {
824
+ var linkHref = l.getAttribute('href');
825
+ var linkRef = l.getAttribute('ref');
826
+ if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
811
827
  link = l;
812
828
  needAttach = false;
813
829
  break;
814
830
  }
815
831
  }
816
832
  if (!link) {
817
- link = document.createElement("link");
818
- link.setAttribute("href", url);
833
+ link = document.createElement('link');
834
+ link.setAttribute('href', url);
819
835
  if (createLinkHook) {
820
836
  var createLinkRes = createLinkHook(url);
821
837
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
@@ -859,7 +875,7 @@ function loadScript(url, info) {
859
875
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
860
876
  return new Promise(function(resolve, _reject) {
861
877
  var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
862
- needAttach && document.getElementsByTagName("head")[0].appendChild(script);
878
+ needAttach && document.getElementsByTagName('head')[0].appendChild(script);
863
879
  });
864
880
  }
865
881
 
@@ -1035,9 +1051,9 @@ function _ts_generator(thisArg, body) {
1035
1051
  }
1036
1052
  function importNodeModule(name) {
1037
1053
  if (!name) {
1038
- throw new Error("import specifier is required");
1054
+ throw new Error('import specifier is required');
1039
1055
  }
1040
- var importModule = new Function("name", "return import(name)");
1056
+ var importModule = new Function('name', "return import(name)");
1041
1057
  return importModule(name).then(function(res) {
1042
1058
  return res.default;
1043
1059
  }).catch(function(error) {
@@ -1048,7 +1064,7 @@ function importNodeModule(name) {
1048
1064
  function createScriptNode(url, cb, attrs, createScriptHook) {
1049
1065
  if (createScriptHook) {
1050
1066
  var hookResult = createScriptHook(url);
1051
- if (hookResult && typeof hookResult === "object" && "url" in hookResult) {
1067
+ if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1052
1068
  url = hookResult.url;
1053
1069
  }
1054
1070
  }
@@ -1056,7 +1072,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1056
1072
  try {
1057
1073
  urlObj = new URL(url);
1058
1074
  } catch (e) {
1059
- console.error("Error constructing URL:", e);
1075
+ console.error('Error constructing URL:', e);
1060
1076
  cb(new Error("Invalid URL: ".concat(e)));
1061
1077
  return;
1062
1078
  }
@@ -1066,13 +1082,13 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1066
1082
  return _ts_generator(this, function(_state) {
1067
1083
  switch(_state.label){
1068
1084
  case 0:
1069
- if (!(typeof fetch === "undefined")) return [
1085
+ if (!(typeof fetch === 'undefined')) return [
1070
1086
  3,
1071
1087
  2
1072
1088
  ];
1073
1089
  return [
1074
1090
  4,
1075
- importNodeModule("node-fetch")
1091
+ importNodeModule('node-fetch')
1076
1092
  ];
1077
1093
  case 1:
1078
1094
  fetchModule = _state.sent();
@@ -1097,7 +1113,7 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1097
1113
  return _ref.apply(this, arguments);
1098
1114
  };
1099
1115
  }();
1100
- console.log("fetching", urlObj.href);
1116
+ console.log('fetching', urlObj.href);
1101
1117
  getFetch().then(function(f) {
1102
1118
  f(urlObj.href).then(function(res) {
1103
1119
  return res.text();
@@ -1110,8 +1126,8 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1110
1126
  return [
1111
1127
  4,
1112
1128
  Promise.all([
1113
- importNodeModule("path"),
1114
- importNodeModule("vm")
1129
+ importNodeModule('path'),
1130
+ importNodeModule('vm')
1115
1131
  ])
1116
1132
  ];
1117
1133
  case 1:
@@ -1125,14 +1141,14 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
1125
1141
  exports: {}
1126
1142
  }
1127
1143
  };
1128
- urlDirname = urlObj.pathname.split("/").slice(0, -1).join("/");
1144
+ urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
1129
1145
  filename = path.basename(urlObj.pathname);
1130
1146
  try {
1131
1147
  script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
1132
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval("require"), urlDirname, filename);
1148
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
1133
1149
  exportedInterface = scriptContext.module.exports || scriptContext.exports;
1134
- if (attrs && exportedInterface && attrs["globalName"]) {
1135
- container = exportedInterface[attrs["globalName"]] || exportedInterface;
1150
+ if (attrs && exportedInterface && attrs['globalName']) {
1151
+ container = exportedInterface[attrs['globalName']] || exportedInterface;
1136
1152
  cb(undefined, container);
1137
1153
  return [
1138
1154
  2
@@ -1165,7 +1181,7 @@ function loadScriptNode(url, info) {
1165
1181
  reject(error);
1166
1182
  } else {
1167
1183
  var _info_attrs, _info_attrs1;
1168
- 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__");
1184
+ 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__");
1169
1185
  var entryExports = globalThis[remoteEntryKey] = scriptContext;
1170
1186
  resolve(entryExports);
1171
1187
  }
@@ -1210,7 +1226,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1210
1226
  if (options === false) {
1211
1227
  return false;
1212
1228
  }
1213
- if (typeof options === "undefined") {
1229
+ if (typeof options === 'undefined') {
1214
1230
  if (enableDefault) {
1215
1231
  return defaultOptions;
1216
1232
  } else {
@@ -1220,11 +1236,11 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1220
1236
  if (options === true) {
1221
1237
  return defaultOptions;
1222
1238
  }
1223
- if (options && typeof options === "object") {
1239
+ if (options && typeof options === 'object') {
1224
1240
  return _object_spread({}, defaultOptions, options);
1225
1241
  }
1226
1242
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
1227
1243
  };
1228
1244
  }
1229
1245
 
1230
- export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, assert, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
1246
+ export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, MFModuleType, MODULE_DEVTOOL_IDENTIFIER, ManifestFileName, NameTransformMap, NameTransformSymbol, SEPARATOR, StatsFileName, assert, composeKeyWithSeparator, ContainerPlugin as containerPlugin, ContainerReferencePlugin as containerReferencePlugin, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, inferAutoPublicPath, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, ModuleFederationPlugin as moduleFederationPlugin, normalizeOptions, parseEntry, safeWrapper, SharePlugin as sharePlugin, simpleJoinRemoteEntry, warn };
@@ -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.14",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
package/dist/src/dom.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
2
2
  export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
3
- export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => HTMLScriptElement | void): {
3
+ export type CreateScriptHookReturn = HTMLScriptElement | {
4
+ script?: HTMLScriptElement;
5
+ timeout?: number;
6
+ } | void;
7
+ export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => CreateScriptHookReturn): {
4
8
  script: HTMLScriptElement;
5
9
  needAttach: boolean;
6
10
  };
@@ -10,5 +14,5 @@ export declare function createLink(url: string, cb: (value: void | PromiseLike<v
10
14
  };
11
15
  export declare function loadScript(url: string, info: {
12
16
  attrs?: Record<string, any>;
13
- createScriptHook?: (url: string) => HTMLScriptElement | void;
17
+ createScriptHook?: (url: string) => CreateScriptHookReturn;
14
18
  }): Promise<void>;
@@ -5,6 +5,7 @@ interface IOptions {
5
5
  version?: string;
6
6
  }
7
7
  export declare const simpleJoinRemoteEntry: (rPath: string, rName: string) => string;
8
+ export declare function inferAutoPublicPath(url: string): string;
8
9
  export declare function generateSnapshotFromManifest(manifest: Manifest, options?: IOptions): ProviderModuleInfo;
9
10
  export declare function isManifestProvider(moduleInfo: ModuleInfo | ManifestProvider): moduleInfo is ManifestProvider;
10
11
  export {};
@@ -1,7 +1,7 @@
1
1
  export * from './constant';
2
2
  export * from './types';
3
3
  export * from './utils';
4
- export { generateSnapshotFromManifest, isManifestProvider, simpleJoinRemoteEntry, } from './generateSnapshotFromManifest';
4
+ export { generateSnapshotFromManifest, isManifestProvider, simpleJoinRemoteEntry, inferAutoPublicPath, } from './generateSnapshotFromManifest';
5
5
  export * from './logger';
6
6
  export * from './env';
7
7
  export * from './dom';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [