@module-federation/sdk 0.0.0-next-20240605083609 → 0.0.0-next-20240605092134

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _define_property$3(obj, key, value) {
5
+ function _define_property$4(obj, key, value) {
6
6
  if (key in obj) {
7
7
  Object.defineProperty(obj, key, {
8
8
  value: value,
@@ -25,9 +25,9 @@ var NameTransformSymbol = {
25
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$4(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$4(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$4(_obj, NameTransformSymbol.SLASH, '__'), _obj);
29
29
  var _obj1;
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);
30
+ var EncodedNameTransformMap = (_obj1 = {}, _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
31
31
  var SEPARATOR = ':';
32
32
  var ManifestFileName = 'mf-manifest.json';
33
33
  var StatsFileName = 'mf-stats.json';
@@ -93,7 +93,7 @@ function _create_class(Constructor, protoProps, staticProps) {
93
93
  if (staticProps) _defineProperties(Constructor, staticProps);
94
94
  return Constructor;
95
95
  }
96
- function _define_property$2(obj, key, value) {
96
+ function _define_property$3(obj, key, value) {
97
97
  if (key in obj) {
98
98
  Object.defineProperty(obj, key, {
99
99
  value: value,
@@ -144,8 +144,8 @@ function safeGetLocalStorageItem() {
144
144
  var Logger = /*#__PURE__*/ function() {
145
145
  function Logger(identifier) {
146
146
  _class_call_check(this, Logger);
147
- _define_property$2(this, "enable", false);
148
- _define_property$2(this, "identifier", void 0);
147
+ _define_property$3(this, "enable", false);
148
+ _define_property$3(this, "identifier", void 0);
149
149
  this.identifier = identifier || DEBUG_LOG;
150
150
  if (isBrowserEnv() && safeGetLocalStorageItem()) {
151
151
  this.enable = true;
@@ -374,7 +374,7 @@ var warn = function(msg) {
374
374
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
375
375
  };
376
376
 
377
- function _define_property$1(obj, key, value) {
377
+ function _define_property$2(obj, key, value) {
378
378
  if (key in obj) {
379
379
  Object.defineProperty(obj, key, {
380
380
  value: value,
@@ -387,7 +387,7 @@ function _define_property$1(obj, key, value) {
387
387
  }
388
388
  return obj;
389
389
  }
390
- function _object_spread$1(target) {
390
+ function _object_spread$2(target) {
391
391
  for(var i = 1; i < arguments.length; i++){
392
392
  var source = arguments[i] != null ? arguments[i] : {};
393
393
  var ownKeys = Object.keys(source);
@@ -397,7 +397,7 @@ function _object_spread$1(target) {
397
397
  }));
398
398
  }
399
399
  ownKeys.forEach(function(key) {
400
- _define_property$1(target, key, source[key]);
400
+ _define_property$2(target, key, source[key]);
401
401
  });
402
402
  }
403
403
  return target;
@@ -507,7 +507,7 @@ 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, ssrRemoteEntry = _manifest_metaData2.ssrRemoteEntry;
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;
511
511
  var exposes = manifest.exposes;
512
512
  var basicRemoteSnapshot = {
513
513
  version: version ? version : '',
@@ -536,31 +536,26 @@ function generateSnapshotFromManifest(manifest) {
536
536
  };
537
537
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
538
538
  var prefetchInterface = manifest.metaData.prefetchInterface;
539
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
539
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
540
540
  prefetchInterface: prefetchInterface
541
541
  });
542
542
  }
543
543
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
544
544
  var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
545
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
545
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
546
546
  prefetchEntry: simpleJoinRemoteEntry(path, name),
547
547
  prefetchEntryType: type
548
548
  });
549
549
  }
550
550
  if ('publicPath' in manifest.metaData) {
551
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
551
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
552
552
  publicPath: getPublicPath()
553
553
  });
554
554
  } else {
555
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
555
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
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
- }
564
559
  return remoteSnapshot;
565
560
  }
566
561
  function isManifestProvider(moduleInfo) {
@@ -600,6 +595,19 @@ function _async_to_generator$1(fn) {
600
595
  });
601
596
  };
602
597
  }
598
+ function _define_property$1(obj, key, value) {
599
+ if (key in obj) {
600
+ Object.defineProperty(obj, key, {
601
+ value: value,
602
+ enumerable: true,
603
+ configurable: true,
604
+ writable: true
605
+ });
606
+ } else {
607
+ obj[key] = value;
608
+ }
609
+ return obj;
610
+ }
603
611
  function _instanceof(left, right) {
604
612
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
605
613
  return !!right[Symbol.hasInstance](left);
@@ -607,6 +615,21 @@ function _instanceof(left, right) {
607
615
  return left instanceof right;
608
616
  }
609
617
  }
618
+ function _object_spread$1(target) {
619
+ for(var i = 1; i < arguments.length; i++){
620
+ var source = arguments[i] != null ? arguments[i] : {};
621
+ var ownKeys = Object.keys(source);
622
+ if (typeof Object.getOwnPropertySymbols === "function") {
623
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
624
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
625
+ }));
626
+ }
627
+ ownKeys.forEach(function(key) {
628
+ _define_property$1(target, key, source[key]);
629
+ });
630
+ }
631
+ return target;
632
+ }
610
633
  function _ts_generator$1(thisArg, body) {
611
634
  var f, y, t, g, _ = {
612
635
  label: 0,
@@ -751,7 +774,7 @@ function isStaticResourcesEqual(url1, url2) {
751
774
  // Check if the relative paths are identical
752
775
  return relativeUrl1 === relativeUrl2;
753
776
  }
754
- function createScript(url, cb, attrs, createScriptHook) {
777
+ function createScript(info) {
755
778
  // Retrieve the existing script element by its src attribute
756
779
  var script = null;
757
780
  var needAttach = true;
@@ -761,7 +784,7 @@ function createScript(url, cb, attrs, createScriptHook) {
761
784
  for(var i = 0; i < scripts.length; i++){
762
785
  var s = scripts[i];
763
786
  var scriptSrc = s.getAttribute('src');
764
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
787
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
765
788
  script = s;
766
789
  needAttach = false;
767
790
  break;
@@ -770,9 +793,9 @@ function createScript(url, cb, attrs, createScriptHook) {
770
793
  if (!script) {
771
794
  script = document.createElement('script');
772
795
  script.type = 'text/javascript';
773
- script.src = url;
774
- if (createScriptHook) {
775
- var createScriptRes = createScriptHook(url);
796
+ script.src = info.url;
797
+ if (info.createScriptHook) {
798
+ var createScriptRes = info.createScriptHook(info.url);
776
799
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
777
800
  script = createScriptRes;
778
801
  } else if (typeof createScriptRes === 'object') {
@@ -781,6 +804,7 @@ function createScript(url, cb, attrs, createScriptHook) {
781
804
  }
782
805
  }
783
806
  }
807
+ var attrs = info.attrs;
784
808
  if (attrs) {
785
809
  Object.keys(attrs).forEach(function(name) {
786
810
  if (script) {
@@ -794,35 +818,38 @@ function createScript(url, cb, attrs, createScriptHook) {
794
818
  }
795
819
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
796
820
  event) {
821
+ var _info_cb;
797
822
  clearTimeout(timeoutId);
798
823
  // Prevent memory leaks in IE.
799
824
  if (script) {
800
825
  script.onerror = null;
801
826
  script.onload = null;
802
827
  safeWrapper(function() {
803
- (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
828
+ if (info.needDeleteScript) {
829
+ (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
830
+ }
804
831
  });
805
832
  if (prev) {
833
+ var _info_cb1;
806
834
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
807
835
  var res = prev(event);
808
- cb();
836
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
809
837
  return res;
810
838
  }
811
839
  }
812
- cb();
840
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
813
841
  };
814
842
  script.onerror = onScriptComplete.bind(null, script.onerror);
815
843
  script.onload = onScriptComplete.bind(null, script.onload);
816
844
  timeoutId = setTimeout(function() {
817
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
845
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
818
846
  }, timeout);
819
847
  return {
820
848
  script: script,
821
849
  needAttach: needAttach
822
850
  };
823
851
  }
824
- function createLink(url, cb) {
825
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
852
+ function createLink(info) {
826
853
  // <link rel="preload" href="script.js" as="script">
827
854
  // Retrieve the existing script element by its src attribute
828
855
  var link = null;
@@ -832,7 +859,7 @@ function createLink(url, cb) {
832
859
  var l = links[i];
833
860
  var linkHref = l.getAttribute('href');
834
861
  var linkRef = l.getAttribute('ref');
835
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
862
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
836
863
  link = l;
837
864
  needAttach = false;
838
865
  break;
@@ -840,14 +867,15 @@ function createLink(url, cb) {
840
867
  }
841
868
  if (!link) {
842
869
  link = document.createElement('link');
843
- link.setAttribute('href', url);
844
- if (createLinkHook) {
845
- var createLinkRes = createLinkHook(url);
870
+ link.setAttribute('href', info.url);
871
+ if (info.createLinkHook) {
872
+ var createLinkRes = info.createLinkHook(info.url);
846
873
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
847
874
  link = createLinkRes;
848
875
  }
849
876
  }
850
877
  }
878
+ var attrs = info.attrs;
851
879
  if (attrs) {
852
880
  Object.keys(attrs).forEach(function(name) {
853
881
  if (link) {
@@ -867,11 +895,11 @@ function createLink(url, cb) {
867
895
  if (prev) {
868
896
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
869
897
  var res = prev(event);
870
- cb();
898
+ info.cb();
871
899
  return res;
872
900
  }
873
901
  }
874
- cb();
902
+ info.cb();
875
903
  };
876
904
  link.onerror = onLinkComplete.bind(null, link.onerror);
877
905
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -881,10 +909,19 @@ function createLink(url, cb) {
881
909
  };
882
910
  }
883
911
  function loadScript(url, info) {
884
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
912
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
885
913
  return new Promise(function(resolve, _reject) {
886
- var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
887
- needAttach && document.getElementsByTagName('head')[0].appendChild(script);
914
+ var _createScript = createScript({
915
+ url: url,
916
+ cb: resolve,
917
+ attrs: _object_spread$1({
918
+ crossorigin: 'anonymous',
919
+ fetchpriority: 'high'
920
+ }, attrs),
921
+ createScriptHook: createScriptHook,
922
+ needDeleteScript: true
923
+ }), script = _createScript.script, needAttach = _createScript.needAttach;
924
+ needAttach && document.head.appendChild(script);
888
925
  });
889
926
  }
890
927
 
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- function _define_property$3(obj, key, value) {
1
+ function _define_property$4(obj, key, value) {
2
2
  if (key in obj) {
3
3
  Object.defineProperty(obj, key, {
4
4
  value: value,
@@ -21,9 +21,9 @@ var NameTransformSymbol = {
21
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$4(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$4(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$4(_obj, NameTransformSymbol.SLASH, '__'), _obj);
25
25
  var _obj1;
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);
26
+ var EncodedNameTransformMap = (_obj1 = {}, _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
27
27
  var SEPARATOR = ':';
28
28
  var ManifestFileName = 'mf-manifest.json';
29
29
  var StatsFileName = 'mf-stats.json';
@@ -89,7 +89,7 @@ function _create_class(Constructor, protoProps, staticProps) {
89
89
  if (staticProps) _defineProperties(Constructor, staticProps);
90
90
  return Constructor;
91
91
  }
92
- function _define_property$2(obj, key, value) {
92
+ function _define_property$3(obj, key, value) {
93
93
  if (key in obj) {
94
94
  Object.defineProperty(obj, key, {
95
95
  value: value,
@@ -140,8 +140,8 @@ function safeGetLocalStorageItem() {
140
140
  var Logger = /*#__PURE__*/ function() {
141
141
  function Logger(identifier) {
142
142
  _class_call_check(this, Logger);
143
- _define_property$2(this, "enable", false);
144
- _define_property$2(this, "identifier", void 0);
143
+ _define_property$3(this, "enable", false);
144
+ _define_property$3(this, "identifier", void 0);
145
145
  this.identifier = identifier || DEBUG_LOG;
146
146
  if (isBrowserEnv() && safeGetLocalStorageItem()) {
147
147
  this.enable = true;
@@ -370,7 +370,7 @@ var warn = function(msg) {
370
370
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
371
371
  };
372
372
 
373
- function _define_property$1(obj, key, value) {
373
+ function _define_property$2(obj, key, value) {
374
374
  if (key in obj) {
375
375
  Object.defineProperty(obj, key, {
376
376
  value: value,
@@ -383,7 +383,7 @@ function _define_property$1(obj, key, value) {
383
383
  }
384
384
  return obj;
385
385
  }
386
- function _object_spread$1(target) {
386
+ function _object_spread$2(target) {
387
387
  for(var i = 1; i < arguments.length; i++){
388
388
  var source = arguments[i] != null ? arguments[i] : {};
389
389
  var ownKeys = Object.keys(source);
@@ -393,7 +393,7 @@ function _object_spread$1(target) {
393
393
  }));
394
394
  }
395
395
  ownKeys.forEach(function(key) {
396
- _define_property$1(target, key, source[key]);
396
+ _define_property$2(target, key, source[key]);
397
397
  });
398
398
  }
399
399
  return target;
@@ -503,7 +503,7 @@ 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, ssrRemoteEntry = _manifest_metaData2.ssrRemoteEntry;
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;
507
507
  var exposes = manifest.exposes;
508
508
  var basicRemoteSnapshot = {
509
509
  version: version ? version : '',
@@ -532,31 +532,26 @@ function generateSnapshotFromManifest(manifest) {
532
532
  };
533
533
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
534
534
  var prefetchInterface = manifest.metaData.prefetchInterface;
535
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
535
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
536
536
  prefetchInterface: prefetchInterface
537
537
  });
538
538
  }
539
539
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
540
540
  var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
541
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
541
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
542
542
  prefetchEntry: simpleJoinRemoteEntry(path, name),
543
543
  prefetchEntryType: type
544
544
  });
545
545
  }
546
546
  if ('publicPath' in manifest.metaData) {
547
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
547
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
548
548
  publicPath: getPublicPath()
549
549
  });
550
550
  } else {
551
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
551
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
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
- }
560
555
  return remoteSnapshot;
561
556
  }
562
557
  function isManifestProvider(moduleInfo) {
@@ -596,6 +591,19 @@ function _async_to_generator$1(fn) {
596
591
  });
597
592
  };
598
593
  }
594
+ function _define_property$1(obj, key, value) {
595
+ if (key in obj) {
596
+ Object.defineProperty(obj, key, {
597
+ value: value,
598
+ enumerable: true,
599
+ configurable: true,
600
+ writable: true
601
+ });
602
+ } else {
603
+ obj[key] = value;
604
+ }
605
+ return obj;
606
+ }
599
607
  function _instanceof(left, right) {
600
608
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
601
609
  return !!right[Symbol.hasInstance](left);
@@ -603,6 +611,21 @@ function _instanceof(left, right) {
603
611
  return left instanceof right;
604
612
  }
605
613
  }
614
+ function _object_spread$1(target) {
615
+ for(var i = 1; i < arguments.length; i++){
616
+ var source = arguments[i] != null ? arguments[i] : {};
617
+ var ownKeys = Object.keys(source);
618
+ if (typeof Object.getOwnPropertySymbols === "function") {
619
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
620
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
621
+ }));
622
+ }
623
+ ownKeys.forEach(function(key) {
624
+ _define_property$1(target, key, source[key]);
625
+ });
626
+ }
627
+ return target;
628
+ }
606
629
  function _ts_generator$1(thisArg, body) {
607
630
  var f, y, t, g, _ = {
608
631
  label: 0,
@@ -747,7 +770,7 @@ function isStaticResourcesEqual(url1, url2) {
747
770
  // Check if the relative paths are identical
748
771
  return relativeUrl1 === relativeUrl2;
749
772
  }
750
- function createScript(url, cb, attrs, createScriptHook) {
773
+ function createScript(info) {
751
774
  // Retrieve the existing script element by its src attribute
752
775
  var script = null;
753
776
  var needAttach = true;
@@ -757,7 +780,7 @@ function createScript(url, cb, attrs, createScriptHook) {
757
780
  for(var i = 0; i < scripts.length; i++){
758
781
  var s = scripts[i];
759
782
  var scriptSrc = s.getAttribute('src');
760
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
783
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
761
784
  script = s;
762
785
  needAttach = false;
763
786
  break;
@@ -766,9 +789,9 @@ function createScript(url, cb, attrs, createScriptHook) {
766
789
  if (!script) {
767
790
  script = document.createElement('script');
768
791
  script.type = 'text/javascript';
769
- script.src = url;
770
- if (createScriptHook) {
771
- var createScriptRes = createScriptHook(url);
792
+ script.src = info.url;
793
+ if (info.createScriptHook) {
794
+ var createScriptRes = info.createScriptHook(info.url);
772
795
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
773
796
  script = createScriptRes;
774
797
  } else if (typeof createScriptRes === 'object') {
@@ -777,6 +800,7 @@ function createScript(url, cb, attrs, createScriptHook) {
777
800
  }
778
801
  }
779
802
  }
803
+ var attrs = info.attrs;
780
804
  if (attrs) {
781
805
  Object.keys(attrs).forEach(function(name) {
782
806
  if (script) {
@@ -790,35 +814,38 @@ function createScript(url, cb, attrs, createScriptHook) {
790
814
  }
791
815
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
792
816
  event) {
817
+ var _info_cb;
793
818
  clearTimeout(timeoutId);
794
819
  // Prevent memory leaks in IE.
795
820
  if (script) {
796
821
  script.onerror = null;
797
822
  script.onload = null;
798
823
  safeWrapper(function() {
799
- (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
824
+ if (info.needDeleteScript) {
825
+ (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
826
+ }
800
827
  });
801
828
  if (prev) {
829
+ var _info_cb1;
802
830
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
803
831
  var res = prev(event);
804
- cb();
832
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
805
833
  return res;
806
834
  }
807
835
  }
808
- cb();
836
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
809
837
  };
810
838
  script.onerror = onScriptComplete.bind(null, script.onerror);
811
839
  script.onload = onScriptComplete.bind(null, script.onload);
812
840
  timeoutId = setTimeout(function() {
813
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
841
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
814
842
  }, timeout);
815
843
  return {
816
844
  script: script,
817
845
  needAttach: needAttach
818
846
  };
819
847
  }
820
- function createLink(url, cb) {
821
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
848
+ function createLink(info) {
822
849
  // <link rel="preload" href="script.js" as="script">
823
850
  // Retrieve the existing script element by its src attribute
824
851
  var link = null;
@@ -828,7 +855,7 @@ function createLink(url, cb) {
828
855
  var l = links[i];
829
856
  var linkHref = l.getAttribute('href');
830
857
  var linkRef = l.getAttribute('ref');
831
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
858
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
832
859
  link = l;
833
860
  needAttach = false;
834
861
  break;
@@ -836,14 +863,15 @@ function createLink(url, cb) {
836
863
  }
837
864
  if (!link) {
838
865
  link = document.createElement('link');
839
- link.setAttribute('href', url);
840
- if (createLinkHook) {
841
- var createLinkRes = createLinkHook(url);
866
+ link.setAttribute('href', info.url);
867
+ if (info.createLinkHook) {
868
+ var createLinkRes = info.createLinkHook(info.url);
842
869
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
843
870
  link = createLinkRes;
844
871
  }
845
872
  }
846
873
  }
874
+ var attrs = info.attrs;
847
875
  if (attrs) {
848
876
  Object.keys(attrs).forEach(function(name) {
849
877
  if (link) {
@@ -863,11 +891,11 @@ function createLink(url, cb) {
863
891
  if (prev) {
864
892
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
865
893
  var res = prev(event);
866
- cb();
894
+ info.cb();
867
895
  return res;
868
896
  }
869
897
  }
870
- cb();
898
+ info.cb();
871
899
  };
872
900
  link.onerror = onLinkComplete.bind(null, link.onerror);
873
901
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -877,10 +905,19 @@ function createLink(url, cb) {
877
905
  };
878
906
  }
879
907
  function loadScript(url, info) {
880
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
908
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
881
909
  return new Promise(function(resolve, _reject) {
882
- var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
883
- needAttach && document.getElementsByTagName('head')[0].appendChild(script);
910
+ var _createScript = createScript({
911
+ url: url,
912
+ cb: resolve,
913
+ attrs: _object_spread$1({
914
+ crossorigin: 'anonymous',
915
+ fetchpriority: 'high'
916
+ }, attrs),
917
+ createScriptHook: createScriptHook,
918
+ needDeleteScript: true
919
+ }), script = _createScript.script, needAttach = _createScript.needAttach;
920
+ needAttach && document.head.appendChild(script);
884
921
  });
885
922
  }
886
923
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.15",
3
+ "version": "0.1.18",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
package/dist/src/dom.d.ts CHANGED
@@ -4,11 +4,22 @@ export type CreateScriptHookReturn = HTMLScriptElement | {
4
4
  script?: HTMLScriptElement;
5
5
  timeout?: number;
6
6
  } | void;
7
- export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => CreateScriptHookReturn): {
7
+ export declare function createScript(info: {
8
+ url: string;
9
+ cb?: (value: void | PromiseLike<void>) => void;
10
+ attrs?: Record<string, any>;
11
+ needDeleteScript?: boolean;
12
+ createScriptHook?: (url: string) => CreateScriptHookReturn;
13
+ }): {
8
14
  script: HTMLScriptElement;
9
15
  needAttach: boolean;
10
16
  };
11
- export declare function createLink(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, string>, createLinkHook?: (url: string) => HTMLLinkElement | void): {
17
+ export declare function createLink(info: {
18
+ url: string;
19
+ cb: (value: void | PromiseLike<void>) => void;
20
+ attrs: Record<string, string>;
21
+ createLinkHook?: (url: string) => HTMLLinkElement | void;
22
+ }): {
12
23
  link: HTMLLinkElement;
13
24
  needAttach: boolean;
14
25
  };
@@ -82,7 +82,6 @@ export interface PluginManifestOptions {
82
82
  export interface PluginDevOptions {
83
83
  disableLiveReload?: boolean;
84
84
  disableHotTypesReload?: boolean;
85
- injectWebClient?: boolean;
86
85
  }
87
86
  export interface DtsHostOptions {
88
87
  typesFolder?: string;
@@ -112,10 +111,6 @@ export interface PluginDtsOptions {
112
111
  extraOptions?: Record<string, any>;
113
112
  implementation?: string;
114
113
  }
115
- export type AsyncBoundaryOptions = {
116
- eager?: RegExp | ((module: any) => boolean);
117
- excludeChunk?: (chunk: any) => boolean;
118
- };
119
114
  export interface ModuleFederationPluginOptions {
120
115
  /**
121
116
  * Modules that should be exposed by this container. When provided, property name is used as public name, otherwise public name is automatically inferred from request.
@@ -164,7 +159,6 @@ export interface ModuleFederationPluginOptions {
164
159
  manifest?: boolean | PluginManifestOptions;
165
160
  dev?: boolean | PluginDevOptions;
166
161
  dts?: boolean | PluginDtsOptions;
167
- async?: boolean | AsyncBoundaryOptions;
168
162
  }
169
163
  /**
170
164
  * Modules that should be exposed by this container. Property names are used as public paths.
@@ -23,8 +23,6 @@ interface BasicModuleInfo {
23
23
  export interface BasicProviderModuleInfo extends BasicModuleInfo {
24
24
  remoteEntry: string;
25
25
  remoteEntryType: RemoteEntryType;
26
- ssrRemoteEntry?: string;
27
- ssrRemoteEntryType?: RemoteEntryType;
28
26
  remoteManifest?: string;
29
27
  globalName: string;
30
28
  modules: Array<{
@@ -44,7 +42,6 @@ interface BasicProviderModuleInfoWithGetPublicPath extends BasicProviderModuleIn
44
42
  }
45
43
  export interface ManifestProvider {
46
44
  remoteEntry: string;
47
- ssrRemoteEntry?: string;
48
45
  version?: string;
49
46
  }
50
47
  export interface PureEntryProvider extends ManifestProvider {
@@ -1,6 +1,6 @@
1
1
  import type { RemoteWithEntry, RemoteWithVersion } from './common';
2
- export type RemoteEntryType = 'esm' | 'global' | 'cjs:webpack';
3
- export interface ResourceInfo {
2
+ export type RemoteEntryType = 'var' | 'module' | 'assign' | 'assign-properties' | 'this' | 'window' | 'self' | 'global' | 'commonjs' | 'commonjs2' | 'commonjs-module' | 'commonjs-static' | 'amd' | 'amd-require' | 'umd' | 'umd2' | 'jsonp' | 'system' | string;
3
+ interface ResourceInfo {
4
4
  path: string;
5
5
  name: string;
6
6
  type: RemoteEntryType;
@@ -20,7 +20,6 @@ export interface BasicStatsMetaData {
20
20
  globalName: string;
21
21
  buildInfo: StatsBuildInfo;
22
22
  remoteEntry: ResourceInfo;
23
- ssrRemoteEntry?: ResourceInfo;
24
23
  prefetchInterface?: boolean;
25
24
  prefetchEntry?: ResourceInfo;
26
25
  types: MetaDataTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.0-next-20240605083609",
3
+ "version": "0.0.0-next-20240605092134",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [