@module-federation/sdk 0.1.18 → 0.1.20

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;
@@ -256,6 +256,12 @@ var parseEntry = function(str, devVerOrUrl) {
256
256
  // Check if the string starts with a type
257
257
  if (strSplit.length >= 2) {
258
258
  var _strSplit = _to_array(strSplit), name = _strSplit[0], versionOrEntryArr = _strSplit.slice(1);
259
+ if (str.startsWith(separator)) {
260
+ versionOrEntryArr = [
261
+ devVersionOrUrl || strSplit.slice(-1)[0]
262
+ ];
263
+ name = strSplit.slice(0, -1).join(separator);
264
+ }
259
265
  var versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
260
266
  if (isEntry(versionOrEntry)) {
261
267
  return {
@@ -374,7 +380,7 @@ var warn = function(msg) {
374
380
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
375
381
  };
376
382
 
377
- function _define_property$1(obj, key, value) {
383
+ function _define_property$2(obj, key, value) {
378
384
  if (key in obj) {
379
385
  Object.defineProperty(obj, key, {
380
386
  value: value,
@@ -387,7 +393,7 @@ function _define_property$1(obj, key, value) {
387
393
  }
388
394
  return obj;
389
395
  }
390
- function _object_spread$1(target) {
396
+ function _object_spread$2(target) {
391
397
  for(var i = 1; i < arguments.length; i++){
392
398
  var source = arguments[i] != null ? arguments[i] : {};
393
399
  var ownKeys = Object.keys(source);
@@ -397,7 +403,7 @@ function _object_spread$1(target) {
397
403
  }));
398
404
  }
399
405
  ownKeys.forEach(function(key) {
400
- _define_property$1(target, key, source[key]);
406
+ _define_property$2(target, key, source[key]);
401
407
  });
402
408
  }
403
409
  return target;
@@ -536,23 +542,23 @@ function generateSnapshotFromManifest(manifest) {
536
542
  };
537
543
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
538
544
  var prefetchInterface = manifest.metaData.prefetchInterface;
539
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
545
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
540
546
  prefetchInterface: prefetchInterface
541
547
  });
542
548
  }
543
549
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
544
550
  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), {
551
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
546
552
  prefetchEntry: simpleJoinRemoteEntry(path, name),
547
553
  prefetchEntryType: type
548
554
  });
549
555
  }
550
556
  if ('publicPath' in manifest.metaData) {
551
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
557
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
552
558
  publicPath: getPublicPath()
553
559
  });
554
560
  } else {
555
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
561
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
556
562
  getPublicPath: getPublicPath()
557
563
  });
558
564
  }
@@ -595,6 +601,19 @@ function _async_to_generator$1(fn) {
595
601
  });
596
602
  };
597
603
  }
604
+ function _define_property$1(obj, key, value) {
605
+ if (key in obj) {
606
+ Object.defineProperty(obj, key, {
607
+ value: value,
608
+ enumerable: true,
609
+ configurable: true,
610
+ writable: true
611
+ });
612
+ } else {
613
+ obj[key] = value;
614
+ }
615
+ return obj;
616
+ }
598
617
  function _instanceof(left, right) {
599
618
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
600
619
  return !!right[Symbol.hasInstance](left);
@@ -602,6 +621,25 @@ function _instanceof(left, right) {
602
621
  return left instanceof right;
603
622
  }
604
623
  }
624
+ function _object_spread$1(target) {
625
+ for(var i = 1; i < arguments.length; i++){
626
+ var source = arguments[i] != null ? arguments[i] : {};
627
+ var ownKeys = Object.keys(source);
628
+ if (typeof Object.getOwnPropertySymbols === "function") {
629
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
630
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
631
+ }));
632
+ }
633
+ ownKeys.forEach(function(key) {
634
+ _define_property$1(target, key, source[key]);
635
+ });
636
+ }
637
+ return target;
638
+ }
639
+ function _type_of$2(obj) {
640
+ "@swc/helpers - typeof";
641
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
642
+ }
605
643
  function _ts_generator$1(thisArg, body) {
606
644
  var f, y, t, g, _ = {
607
645
  label: 0,
@@ -746,7 +784,7 @@ function isStaticResourcesEqual(url1, url2) {
746
784
  // Check if the relative paths are identical
747
785
  return relativeUrl1 === relativeUrl2;
748
786
  }
749
- function createScript(url, cb, attrs, createScriptHook) {
787
+ function createScript(info) {
750
788
  // Retrieve the existing script element by its src attribute
751
789
  var script = null;
752
790
  var needAttach = true;
@@ -756,7 +794,7 @@ function createScript(url, cb, attrs, createScriptHook) {
756
794
  for(var i = 0; i < scripts.length; i++){
757
795
  var s = scripts[i];
758
796
  var scriptSrc = s.getAttribute('src');
759
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
797
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
760
798
  script = s;
761
799
  needAttach = false;
762
800
  break;
@@ -765,59 +803,65 @@ function createScript(url, cb, attrs, createScriptHook) {
765
803
  if (!script) {
766
804
  script = document.createElement('script');
767
805
  script.type = 'text/javascript';
768
- script.src = url;
769
- if (createScriptHook) {
770
- var createScriptRes = createScriptHook(url);
806
+ script.src = info.url;
807
+ if (info.createScriptHook) {
808
+ var createScriptRes = info.createScriptHook(info.url);
771
809
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
772
810
  script = createScriptRes;
773
- } else if (typeof createScriptRes === 'object') {
811
+ } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
774
812
  if (createScriptRes.script) script = createScriptRes.script;
775
813
  if (createScriptRes.timeout) timeout = createScriptRes.timeout;
776
814
  }
777
815
  }
778
- }
779
- if (attrs) {
780
- Object.keys(attrs).forEach(function(name) {
781
- if (script) {
782
- if (name === 'async' || name === 'defer') {
783
- script[name] = attrs[name];
784
- } else {
785
- script.setAttribute(name, attrs[name]);
816
+ var attrs = info.attrs;
817
+ if (attrs) {
818
+ Object.keys(attrs).forEach(function(name) {
819
+ if (script) {
820
+ if (name === 'async' || name === 'defer') {
821
+ script[name] = attrs[name];
822
+ // Attributes that do not exist are considered overridden
823
+ } else if (!script.getAttribute(name)) {
824
+ script.setAttribute(name, attrs[name]);
825
+ }
786
826
  }
787
- }
788
- });
827
+ });
828
+ }
789
829
  }
790
830
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
791
831
  event) {
832
+ var _info_cb;
792
833
  clearTimeout(timeoutId);
793
834
  // Prevent memory leaks in IE.
794
835
  if (script) {
795
836
  script.onerror = null;
796
837
  script.onload = null;
797
838
  safeWrapper(function() {
798
- (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
839
+ var _info_needDeleteScript = info.needDeleteScript, needDeleteScript = _info_needDeleteScript === void 0 ? true : _info_needDeleteScript;
840
+ if (needDeleteScript) {
841
+ (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
842
+ }
799
843
  });
800
844
  if (prev) {
845
+ var _info_cb1;
801
846
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
802
847
  var res = prev(event);
803
- cb();
848
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
804
849
  return res;
805
850
  }
806
851
  }
807
- cb();
852
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
808
853
  };
809
854
  script.onerror = onScriptComplete.bind(null, script.onerror);
810
855
  script.onload = onScriptComplete.bind(null, script.onload);
811
856
  timeoutId = setTimeout(function() {
812
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
857
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
813
858
  }, timeout);
814
859
  return {
815
860
  script: script,
816
861
  needAttach: needAttach
817
862
  };
818
863
  }
819
- function createLink(url, cb) {
820
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
864
+ function createLink(info) {
821
865
  // <link rel="preload" href="script.js" as="script">
822
866
  // Retrieve the existing script element by its src attribute
823
867
  var link = null;
@@ -827,7 +871,7 @@ function createLink(url, cb) {
827
871
  var l = links[i];
828
872
  var linkHref = l.getAttribute('href');
829
873
  var linkRef = l.getAttribute('ref');
830
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
874
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
831
875
  link = l;
832
876
  needAttach = false;
833
877
  break;
@@ -835,21 +879,21 @@ function createLink(url, cb) {
835
879
  }
836
880
  if (!link) {
837
881
  link = document.createElement('link');
838
- link.setAttribute('href', url);
839
- link.setAttribute('crossorigin', 'anonymous');
840
- if (createLinkHook) {
841
- var createLinkRes = createLinkHook(url);
882
+ link.setAttribute('href', info.url);
883
+ if (info.createLinkHook) {
884
+ var createLinkRes = info.createLinkHook(info.url);
842
885
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
843
886
  link = createLinkRes;
844
887
  }
845
888
  }
846
- }
847
- if (attrs) {
848
- Object.keys(attrs).forEach(function(name) {
849
- if (link) {
850
- link.setAttribute(name, attrs[name]);
851
- }
852
- });
889
+ var attrs = info.attrs;
890
+ if (attrs) {
891
+ Object.keys(attrs).forEach(function(name) {
892
+ if (link && !link.getAttribute(name)) {
893
+ link.setAttribute(name, attrs[name]);
894
+ }
895
+ });
896
+ }
853
897
  }
854
898
  var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
855
899
  event) {
@@ -858,16 +902,19 @@ function createLink(url, cb) {
858
902
  link.onerror = null;
859
903
  link.onload = null;
860
904
  safeWrapper(function() {
861
- (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
905
+ var _info_needDeleteLink = info.needDeleteLink, needDeleteLink = _info_needDeleteLink === void 0 ? true : _info_needDeleteLink;
906
+ if (needDeleteLink) {
907
+ (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
908
+ }
862
909
  });
863
910
  if (prev) {
864
911
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
865
912
  var res = prev(event);
866
- cb();
913
+ info.cb();
867
914
  return res;
868
915
  }
869
916
  }
870
- cb();
917
+ info.cb();
871
918
  };
872
919
  link.onerror = onLinkComplete.bind(null, link.onerror);
873
920
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -877,10 +924,19 @@ function createLink(url, cb) {
877
924
  };
878
925
  }
879
926
  function loadScript(url, info) {
880
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
927
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
881
928
  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);
929
+ var _createScript = createScript({
930
+ url: url,
931
+ cb: resolve,
932
+ attrs: _object_spread$1({
933
+ crossorigin: 'anonymous',
934
+ fetchpriority: 'high'
935
+ }, attrs),
936
+ createScriptHook: createScriptHook,
937
+ needDeleteScript: true
938
+ }), script = _createScript.script, needAttach = _createScript.needAttach;
939
+ needAttach && document.head.appendChild(script);
884
940
  });
885
941
  }
886
942
 
@@ -951,6 +1007,10 @@ function _non_iterable_rest() {
951
1007
  function _sliced_to_array(arr, i) {
952
1008
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
953
1009
  }
1010
+ function _type_of$1(obj) {
1011
+ "@swc/helpers - typeof";
1012
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1013
+ }
954
1014
  function _unsupported_iterable_to_array(o, minLen) {
955
1015
  if (!o) return;
956
1016
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -1069,7 +1129,7 @@ function importNodeModule(name) {
1069
1129
  function createScriptNode(url, cb, attrs, createScriptHook) {
1070
1130
  if (createScriptHook) {
1071
1131
  var hookResult = createScriptHook(url);
1072
- if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1132
+ if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of$1(hookResult)) === 'object' && 'url' in hookResult) {
1073
1133
  url = hookResult.url;
1074
1134
  }
1075
1135
  }
@@ -1241,7 +1301,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1241
1301
  if (options === true) {
1242
1302
  return defaultOptions;
1243
1303
  }
1244
- if (options && typeof options === 'object') {
1304
+ if (options && (typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object') {
1245
1305
  return _object_spread({}, defaultOptions, options);
1246
1306
  }
1247
1307
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
package/dist/index.esm.js CHANGED
@@ -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;
@@ -252,6 +252,12 @@ var parseEntry = function(str, devVerOrUrl) {
252
252
  // Check if the string starts with a type
253
253
  if (strSplit.length >= 2) {
254
254
  var _strSplit = _to_array(strSplit), name = _strSplit[0], versionOrEntryArr = _strSplit.slice(1);
255
+ if (str.startsWith(separator)) {
256
+ versionOrEntryArr = [
257
+ devVersionOrUrl || strSplit.slice(-1)[0]
258
+ ];
259
+ name = strSplit.slice(0, -1).join(separator);
260
+ }
255
261
  var versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
256
262
  if (isEntry(versionOrEntry)) {
257
263
  return {
@@ -370,7 +376,7 @@ var warn = function(msg) {
370
376
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
371
377
  };
372
378
 
373
- function _define_property$1(obj, key, value) {
379
+ function _define_property$2(obj, key, value) {
374
380
  if (key in obj) {
375
381
  Object.defineProperty(obj, key, {
376
382
  value: value,
@@ -383,7 +389,7 @@ function _define_property$1(obj, key, value) {
383
389
  }
384
390
  return obj;
385
391
  }
386
- function _object_spread$1(target) {
392
+ function _object_spread$2(target) {
387
393
  for(var i = 1; i < arguments.length; i++){
388
394
  var source = arguments[i] != null ? arguments[i] : {};
389
395
  var ownKeys = Object.keys(source);
@@ -393,7 +399,7 @@ function _object_spread$1(target) {
393
399
  }));
394
400
  }
395
401
  ownKeys.forEach(function(key) {
396
- _define_property$1(target, key, source[key]);
402
+ _define_property$2(target, key, source[key]);
397
403
  });
398
404
  }
399
405
  return target;
@@ -532,23 +538,23 @@ function generateSnapshotFromManifest(manifest) {
532
538
  };
533
539
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
534
540
  var prefetchInterface = manifest.metaData.prefetchInterface;
535
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
541
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
536
542
  prefetchInterface: prefetchInterface
537
543
  });
538
544
  }
539
545
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
540
546
  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), {
547
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
542
548
  prefetchEntry: simpleJoinRemoteEntry(path, name),
543
549
  prefetchEntryType: type
544
550
  });
545
551
  }
546
552
  if ('publicPath' in manifest.metaData) {
547
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
553
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
548
554
  publicPath: getPublicPath()
549
555
  });
550
556
  } else {
551
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
557
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
552
558
  getPublicPath: getPublicPath()
553
559
  });
554
560
  }
@@ -591,6 +597,19 @@ function _async_to_generator$1(fn) {
591
597
  });
592
598
  };
593
599
  }
600
+ function _define_property$1(obj, key, value) {
601
+ if (key in obj) {
602
+ Object.defineProperty(obj, key, {
603
+ value: value,
604
+ enumerable: true,
605
+ configurable: true,
606
+ writable: true
607
+ });
608
+ } else {
609
+ obj[key] = value;
610
+ }
611
+ return obj;
612
+ }
594
613
  function _instanceof(left, right) {
595
614
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
596
615
  return !!right[Symbol.hasInstance](left);
@@ -598,6 +617,25 @@ function _instanceof(left, right) {
598
617
  return left instanceof right;
599
618
  }
600
619
  }
620
+ function _object_spread$1(target) {
621
+ for(var i = 1; i < arguments.length; i++){
622
+ var source = arguments[i] != null ? arguments[i] : {};
623
+ var ownKeys = Object.keys(source);
624
+ if (typeof Object.getOwnPropertySymbols === "function") {
625
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
626
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
627
+ }));
628
+ }
629
+ ownKeys.forEach(function(key) {
630
+ _define_property$1(target, key, source[key]);
631
+ });
632
+ }
633
+ return target;
634
+ }
635
+ function _type_of$2(obj) {
636
+ "@swc/helpers - typeof";
637
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
638
+ }
601
639
  function _ts_generator$1(thisArg, body) {
602
640
  var f, y, t, g, _ = {
603
641
  label: 0,
@@ -742,7 +780,7 @@ function isStaticResourcesEqual(url1, url2) {
742
780
  // Check if the relative paths are identical
743
781
  return relativeUrl1 === relativeUrl2;
744
782
  }
745
- function createScript(url, cb, attrs, createScriptHook) {
783
+ function createScript(info) {
746
784
  // Retrieve the existing script element by its src attribute
747
785
  var script = null;
748
786
  var needAttach = true;
@@ -752,7 +790,7 @@ function createScript(url, cb, attrs, createScriptHook) {
752
790
  for(var i = 0; i < scripts.length; i++){
753
791
  var s = scripts[i];
754
792
  var scriptSrc = s.getAttribute('src');
755
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
793
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
756
794
  script = s;
757
795
  needAttach = false;
758
796
  break;
@@ -761,59 +799,65 @@ function createScript(url, cb, attrs, createScriptHook) {
761
799
  if (!script) {
762
800
  script = document.createElement('script');
763
801
  script.type = 'text/javascript';
764
- script.src = url;
765
- if (createScriptHook) {
766
- var createScriptRes = createScriptHook(url);
802
+ script.src = info.url;
803
+ if (info.createScriptHook) {
804
+ var createScriptRes = info.createScriptHook(info.url);
767
805
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
768
806
  script = createScriptRes;
769
- } else if (typeof createScriptRes === 'object') {
807
+ } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
770
808
  if (createScriptRes.script) script = createScriptRes.script;
771
809
  if (createScriptRes.timeout) timeout = createScriptRes.timeout;
772
810
  }
773
811
  }
774
- }
775
- if (attrs) {
776
- Object.keys(attrs).forEach(function(name) {
777
- if (script) {
778
- if (name === 'async' || name === 'defer') {
779
- script[name] = attrs[name];
780
- } else {
781
- script.setAttribute(name, attrs[name]);
812
+ var attrs = info.attrs;
813
+ if (attrs) {
814
+ Object.keys(attrs).forEach(function(name) {
815
+ if (script) {
816
+ if (name === 'async' || name === 'defer') {
817
+ script[name] = attrs[name];
818
+ // Attributes that do not exist are considered overridden
819
+ } else if (!script.getAttribute(name)) {
820
+ script.setAttribute(name, attrs[name]);
821
+ }
782
822
  }
783
- }
784
- });
823
+ });
824
+ }
785
825
  }
786
826
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
787
827
  event) {
828
+ var _info_cb;
788
829
  clearTimeout(timeoutId);
789
830
  // Prevent memory leaks in IE.
790
831
  if (script) {
791
832
  script.onerror = null;
792
833
  script.onload = null;
793
834
  safeWrapper(function() {
794
- (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
835
+ var _info_needDeleteScript = info.needDeleteScript, needDeleteScript = _info_needDeleteScript === void 0 ? true : _info_needDeleteScript;
836
+ if (needDeleteScript) {
837
+ (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
838
+ }
795
839
  });
796
840
  if (prev) {
841
+ var _info_cb1;
797
842
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
798
843
  var res = prev(event);
799
- cb();
844
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
800
845
  return res;
801
846
  }
802
847
  }
803
- cb();
848
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
804
849
  };
805
850
  script.onerror = onScriptComplete.bind(null, script.onerror);
806
851
  script.onload = onScriptComplete.bind(null, script.onload);
807
852
  timeoutId = setTimeout(function() {
808
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
853
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
809
854
  }, timeout);
810
855
  return {
811
856
  script: script,
812
857
  needAttach: needAttach
813
858
  };
814
859
  }
815
- function createLink(url, cb) {
816
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
860
+ function createLink(info) {
817
861
  // <link rel="preload" href="script.js" as="script">
818
862
  // Retrieve the existing script element by its src attribute
819
863
  var link = null;
@@ -823,7 +867,7 @@ function createLink(url, cb) {
823
867
  var l = links[i];
824
868
  var linkHref = l.getAttribute('href');
825
869
  var linkRef = l.getAttribute('ref');
826
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
870
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
827
871
  link = l;
828
872
  needAttach = false;
829
873
  break;
@@ -831,21 +875,21 @@ function createLink(url, cb) {
831
875
  }
832
876
  if (!link) {
833
877
  link = document.createElement('link');
834
- link.setAttribute('href', url);
835
- link.setAttribute('crossorigin', 'anonymous');
836
- if (createLinkHook) {
837
- var createLinkRes = createLinkHook(url);
878
+ link.setAttribute('href', info.url);
879
+ if (info.createLinkHook) {
880
+ var createLinkRes = info.createLinkHook(info.url);
838
881
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
839
882
  link = createLinkRes;
840
883
  }
841
884
  }
842
- }
843
- if (attrs) {
844
- Object.keys(attrs).forEach(function(name) {
845
- if (link) {
846
- link.setAttribute(name, attrs[name]);
847
- }
848
- });
885
+ var attrs = info.attrs;
886
+ if (attrs) {
887
+ Object.keys(attrs).forEach(function(name) {
888
+ if (link && !link.getAttribute(name)) {
889
+ link.setAttribute(name, attrs[name]);
890
+ }
891
+ });
892
+ }
849
893
  }
850
894
  var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
851
895
  event) {
@@ -854,16 +898,19 @@ function createLink(url, cb) {
854
898
  link.onerror = null;
855
899
  link.onload = null;
856
900
  safeWrapper(function() {
857
- (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
901
+ var _info_needDeleteLink = info.needDeleteLink, needDeleteLink = _info_needDeleteLink === void 0 ? true : _info_needDeleteLink;
902
+ if (needDeleteLink) {
903
+ (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
904
+ }
858
905
  });
859
906
  if (prev) {
860
907
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
861
908
  var res = prev(event);
862
- cb();
909
+ info.cb();
863
910
  return res;
864
911
  }
865
912
  }
866
- cb();
913
+ info.cb();
867
914
  };
868
915
  link.onerror = onLinkComplete.bind(null, link.onerror);
869
916
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -873,10 +920,19 @@ function createLink(url, cb) {
873
920
  };
874
921
  }
875
922
  function loadScript(url, info) {
876
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
923
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
877
924
  return new Promise(function(resolve, _reject) {
878
- var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
879
- needAttach && document.getElementsByTagName('head')[0].appendChild(script);
925
+ var _createScript = createScript({
926
+ url: url,
927
+ cb: resolve,
928
+ attrs: _object_spread$1({
929
+ crossorigin: 'anonymous',
930
+ fetchpriority: 'high'
931
+ }, attrs),
932
+ createScriptHook: createScriptHook,
933
+ needDeleteScript: true
934
+ }), script = _createScript.script, needAttach = _createScript.needAttach;
935
+ needAttach && document.head.appendChild(script);
880
936
  });
881
937
  }
882
938
 
@@ -947,6 +1003,10 @@ function _non_iterable_rest() {
947
1003
  function _sliced_to_array(arr, i) {
948
1004
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
949
1005
  }
1006
+ function _type_of$1(obj) {
1007
+ "@swc/helpers - typeof";
1008
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1009
+ }
950
1010
  function _unsupported_iterable_to_array(o, minLen) {
951
1011
  if (!o) return;
952
1012
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -1065,7 +1125,7 @@ function importNodeModule(name) {
1065
1125
  function createScriptNode(url, cb, attrs, createScriptHook) {
1066
1126
  if (createScriptHook) {
1067
1127
  var hookResult = createScriptHook(url);
1068
- if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1128
+ if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of$1(hookResult)) === 'object' && 'url' in hookResult) {
1069
1129
  url = hookResult.url;
1070
1130
  }
1071
1131
  }
@@ -1237,7 +1297,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1237
1297
  if (options === true) {
1238
1298
  return defaultOptions;
1239
1299
  }
1240
- if (options && typeof options === 'object') {
1300
+ if (options && (typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object') {
1241
1301
  return _object_spread({}, defaultOptions, options);
1242
1302
  }
1243
1303
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
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,23 @@ 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
+ needDeleteLink?: boolean;
22
+ createLinkHook?: (url: string) => HTMLLinkElement | void;
23
+ }): {
12
24
  link: HTMLLinkElement;
13
25
  needAttach: boolean;
14
26
  };
@@ -82,6 +82,7 @@ export interface PluginManifestOptions {
82
82
  export interface PluginDevOptions {
83
83
  disableLiveReload?: boolean;
84
84
  disableHotTypesReload?: boolean;
85
+ disableDynamicRemoteTypeHints?: boolean;
85
86
  }
86
87
  export interface DtsHostOptions {
87
88
  typesFolder?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [