@module-federation/sdk 0.0.0-next-20240617071032 → 0.0.0-next-20240617084909

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';
@@ -36,13 +36,6 @@ var MFModuleType = {
36
36
  APP: 'app'
37
37
  };
38
38
  var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
39
- var MFPrefetchCommon = {
40
- identifier: 'MFDataPrefetch',
41
- globalKey: '__PREFETCH__',
42
- library: 'mf-data-prefetch',
43
- exportsKey: '__PREFETCH_EXPORTS__',
44
- fileName: 'prefetch.js'
45
- };
46
39
 
47
40
  var ContainerPlugin = /*#__PURE__*/Object.freeze({
48
41
  __proto__: null
@@ -100,7 +93,7 @@ function _create_class(Constructor, protoProps, staticProps) {
100
93
  if (staticProps) _defineProperties(Constructor, staticProps);
101
94
  return Constructor;
102
95
  }
103
- function _define_property$2(obj, key, value) {
96
+ function _define_property$3(obj, key, value) {
104
97
  if (key in obj) {
105
98
  Object.defineProperty(obj, key, {
106
99
  value: value,
@@ -151,8 +144,8 @@ function safeGetLocalStorageItem() {
151
144
  var Logger = /*#__PURE__*/ function() {
152
145
  function Logger(identifier) {
153
146
  _class_call_check(this, Logger);
154
- _define_property$2(this, "enable", false);
155
- _define_property$2(this, "identifier", void 0);
147
+ _define_property$3(this, "enable", false);
148
+ _define_property$3(this, "identifier", void 0);
156
149
  this.identifier = identifier || DEBUG_LOG;
157
150
  if (isBrowserEnv() && safeGetLocalStorageItem()) {
158
151
  this.enable = true;
@@ -263,6 +256,12 @@ var parseEntry = function(str, devVerOrUrl) {
263
256
  // Check if the string starts with a type
264
257
  if (strSplit.length >= 2) {
265
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
+ }
266
265
  var versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
267
266
  if (isEntry(versionOrEntry)) {
268
267
  return {
@@ -381,7 +380,7 @@ var warn = function(msg) {
381
380
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
382
381
  };
383
382
 
384
- function _define_property$1(obj, key, value) {
383
+ function _define_property$2(obj, key, value) {
385
384
  if (key in obj) {
386
385
  Object.defineProperty(obj, key, {
387
386
  value: value,
@@ -394,7 +393,7 @@ function _define_property$1(obj, key, value) {
394
393
  }
395
394
  return obj;
396
395
  }
397
- function _object_spread$1(target) {
396
+ function _object_spread$2(target) {
398
397
  for(var i = 1; i < arguments.length; i++){
399
398
  var source = arguments[i] != null ? arguments[i] : {};
400
399
  var ownKeys = Object.keys(source);
@@ -404,7 +403,7 @@ function _object_spread$1(target) {
404
403
  }));
405
404
  }
406
405
  ownKeys.forEach(function(key) {
407
- _define_property$1(target, key, source[key]);
406
+ _define_property$2(target, key, source[key]);
408
407
  });
409
408
  }
410
409
  return target;
@@ -543,23 +542,23 @@ function generateSnapshotFromManifest(manifest) {
543
542
  };
544
543
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
545
544
  var prefetchInterface = manifest.metaData.prefetchInterface;
546
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
545
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
547
546
  prefetchInterface: prefetchInterface
548
547
  });
549
548
  }
550
549
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
551
550
  var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
552
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
551
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
553
552
  prefetchEntry: simpleJoinRemoteEntry(path, name),
554
553
  prefetchEntryType: type
555
554
  });
556
555
  }
557
556
  if ('publicPath' in manifest.metaData) {
558
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
557
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
559
558
  publicPath: getPublicPath()
560
559
  });
561
560
  } else {
562
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
561
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
563
562
  getPublicPath: getPublicPath()
564
563
  });
565
564
  }
@@ -602,6 +601,19 @@ function _async_to_generator$1(fn) {
602
601
  });
603
602
  };
604
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
+ }
605
617
  function _instanceof(left, right) {
606
618
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
607
619
  return !!right[Symbol.hasInstance](left);
@@ -609,6 +621,25 @@ function _instanceof(left, right) {
609
621
  return left instanceof right;
610
622
  }
611
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
+ }
612
643
  function _ts_generator$1(thisArg, body) {
613
644
  var f, y, t, g, _ = {
614
645
  label: 0,
@@ -753,7 +784,7 @@ function isStaticResourcesEqual(url1, url2) {
753
784
  // Check if the relative paths are identical
754
785
  return relativeUrl1 === relativeUrl2;
755
786
  }
756
- function createScript(url, cb, attrs, createScriptHook) {
787
+ function createScript(info) {
757
788
  // Retrieve the existing script element by its src attribute
758
789
  var script = null;
759
790
  var needAttach = true;
@@ -763,7 +794,7 @@ function createScript(url, cb, attrs, createScriptHook) {
763
794
  for(var i = 0; i < scripts.length; i++){
764
795
  var s = scripts[i];
765
796
  var scriptSrc = s.getAttribute('src');
766
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
797
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
767
798
  script = s;
768
799
  needAttach = false;
769
800
  break;
@@ -772,59 +803,65 @@ function createScript(url, cb, attrs, createScriptHook) {
772
803
  if (!script) {
773
804
  script = document.createElement('script');
774
805
  script.type = 'text/javascript';
775
- script.src = url;
776
- if (createScriptHook) {
777
- var createScriptRes = createScriptHook(url);
806
+ script.src = info.url;
807
+ if (info.createScriptHook) {
808
+ var createScriptRes = info.createScriptHook(info.url);
778
809
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
779
810
  script = createScriptRes;
780
- } else if (typeof createScriptRes === 'object') {
811
+ } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
781
812
  if (createScriptRes.script) script = createScriptRes.script;
782
813
  if (createScriptRes.timeout) timeout = createScriptRes.timeout;
783
814
  }
784
815
  }
785
- }
786
- if (attrs) {
787
- Object.keys(attrs).forEach(function(name) {
788
- if (script) {
789
- if (name === 'async' || name === 'defer') {
790
- script[name] = attrs[name];
791
- } else {
792
- 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
+ }
793
826
  }
794
- }
795
- });
827
+ });
828
+ }
796
829
  }
797
830
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
798
831
  event) {
832
+ var _info_cb;
799
833
  clearTimeout(timeoutId);
800
834
  // Prevent memory leaks in IE.
801
835
  if (script) {
802
836
  script.onerror = null;
803
837
  script.onload = null;
804
838
  safeWrapper(function() {
805
- (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
+ }
806
843
  });
807
844
  if (prev) {
845
+ var _info_cb1;
808
846
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
809
847
  var res = prev(event);
810
- cb();
848
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
811
849
  return res;
812
850
  }
813
851
  }
814
- cb();
852
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
815
853
  };
816
854
  script.onerror = onScriptComplete.bind(null, script.onerror);
817
855
  script.onload = onScriptComplete.bind(null, script.onload);
818
856
  timeoutId = setTimeout(function() {
819
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
857
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
820
858
  }, timeout);
821
859
  return {
822
860
  script: script,
823
861
  needAttach: needAttach
824
862
  };
825
863
  }
826
- function createLink(url, cb) {
827
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
864
+ function createLink(info) {
828
865
  // <link rel="preload" href="script.js" as="script">
829
866
  // Retrieve the existing script element by its src attribute
830
867
  var link = null;
@@ -834,7 +871,7 @@ function createLink(url, cb) {
834
871
  var l = links[i];
835
872
  var linkHref = l.getAttribute('href');
836
873
  var linkRef = l.getAttribute('ref');
837
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
874
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
838
875
  link = l;
839
876
  needAttach = false;
840
877
  break;
@@ -842,21 +879,21 @@ function createLink(url, cb) {
842
879
  }
843
880
  if (!link) {
844
881
  link = document.createElement('link');
845
- link.setAttribute('href', url);
846
- link.setAttribute('crossorigin', 'anonymous');
847
- if (createLinkHook) {
848
- var createLinkRes = createLinkHook(url);
882
+ link.setAttribute('href', info.url);
883
+ if (info.createLinkHook) {
884
+ var createLinkRes = info.createLinkHook(info.url);
849
885
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
850
886
  link = createLinkRes;
851
887
  }
852
888
  }
853
- }
854
- if (attrs) {
855
- Object.keys(attrs).forEach(function(name) {
856
- if (link) {
857
- link.setAttribute(name, attrs[name]);
858
- }
859
- });
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
+ }
860
897
  }
861
898
  var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
862
899
  event) {
@@ -865,16 +902,19 @@ function createLink(url, cb) {
865
902
  link.onerror = null;
866
903
  link.onload = null;
867
904
  safeWrapper(function() {
868
- (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
+ }
869
909
  });
870
910
  if (prev) {
871
911
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
872
912
  var res = prev(event);
873
- cb();
913
+ info.cb();
874
914
  return res;
875
915
  }
876
916
  }
877
- cb();
917
+ info.cb();
878
918
  };
879
919
  link.onerror = onLinkComplete.bind(null, link.onerror);
880
920
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -884,10 +924,19 @@ function createLink(url, cb) {
884
924
  };
885
925
  }
886
926
  function loadScript(url, info) {
887
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
927
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
888
928
  return new Promise(function(resolve, _reject) {
889
- var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
890
- 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);
891
940
  });
892
941
  }
893
942
 
@@ -958,6 +1007,10 @@ function _non_iterable_rest() {
958
1007
  function _sliced_to_array(arr, i) {
959
1008
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
960
1009
  }
1010
+ function _type_of$1(obj) {
1011
+ "@swc/helpers - typeof";
1012
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1013
+ }
961
1014
  function _unsupported_iterable_to_array(o, minLen) {
962
1015
  if (!o) return;
963
1016
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -1076,7 +1129,7 @@ function importNodeModule(name) {
1076
1129
  function createScriptNode(url, cb, attrs, createScriptHook) {
1077
1130
  if (createScriptHook) {
1078
1131
  var hookResult = createScriptHook(url);
1079
- if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1132
+ if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of$1(hookResult)) === 'object' && 'url' in hookResult) {
1080
1133
  url = hookResult.url;
1081
1134
  }
1082
1135
  }
@@ -1248,7 +1301,7 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1248
1301
  if (options === true) {
1249
1302
  return defaultOptions;
1250
1303
  }
1251
- if (options && typeof options === 'object') {
1304
+ if (options && (typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object') {
1252
1305
  return _object_spread({}, defaultOptions, options);
1253
1306
  }
1254
1307
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
@@ -1262,7 +1315,6 @@ exports.FederationModuleManifest = FederationModuleManifest;
1262
1315
  exports.Logger = Logger;
1263
1316
  exports.MANIFEST_EXT = MANIFEST_EXT;
1264
1317
  exports.MFModuleType = MFModuleType;
1265
- exports.MFPrefetchCommon = MFPrefetchCommon;
1266
1318
  exports.MODULE_DEVTOOL_IDENTIFIER = MODULE_DEVTOOL_IDENTIFIER;
1267
1319
  exports.ManifestFileName = ManifestFileName;
1268
1320
  exports.NameTransformMap = NameTransformMap;
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';
@@ -32,13 +32,6 @@ var MFModuleType = {
32
32
  APP: 'app'
33
33
  };
34
34
  var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
35
- var MFPrefetchCommon = {
36
- identifier: 'MFDataPrefetch',
37
- globalKey: '__PREFETCH__',
38
- library: 'mf-data-prefetch',
39
- exportsKey: '__PREFETCH_EXPORTS__',
40
- fileName: 'prefetch.js'
41
- };
42
35
 
43
36
  var ContainerPlugin = /*#__PURE__*/Object.freeze({
44
37
  __proto__: null
@@ -96,7 +89,7 @@ function _create_class(Constructor, protoProps, staticProps) {
96
89
  if (staticProps) _defineProperties(Constructor, staticProps);
97
90
  return Constructor;
98
91
  }
99
- function _define_property$2(obj, key, value) {
92
+ function _define_property$3(obj, key, value) {
100
93
  if (key in obj) {
101
94
  Object.defineProperty(obj, key, {
102
95
  value: value,
@@ -147,8 +140,8 @@ function safeGetLocalStorageItem() {
147
140
  var Logger = /*#__PURE__*/ function() {
148
141
  function Logger(identifier) {
149
142
  _class_call_check(this, Logger);
150
- _define_property$2(this, "enable", false);
151
- _define_property$2(this, "identifier", void 0);
143
+ _define_property$3(this, "enable", false);
144
+ _define_property$3(this, "identifier", void 0);
152
145
  this.identifier = identifier || DEBUG_LOG;
153
146
  if (isBrowserEnv() && safeGetLocalStorageItem()) {
154
147
  this.enable = true;
@@ -259,6 +252,12 @@ var parseEntry = function(str, devVerOrUrl) {
259
252
  // Check if the string starts with a type
260
253
  if (strSplit.length >= 2) {
261
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
+ }
262
261
  var versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
263
262
  if (isEntry(versionOrEntry)) {
264
263
  return {
@@ -377,7 +376,7 @@ var warn = function(msg) {
377
376
  console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
378
377
  };
379
378
 
380
- function _define_property$1(obj, key, value) {
379
+ function _define_property$2(obj, key, value) {
381
380
  if (key in obj) {
382
381
  Object.defineProperty(obj, key, {
383
382
  value: value,
@@ -390,7 +389,7 @@ function _define_property$1(obj, key, value) {
390
389
  }
391
390
  return obj;
392
391
  }
393
- function _object_spread$1(target) {
392
+ function _object_spread$2(target) {
394
393
  for(var i = 1; i < arguments.length; i++){
395
394
  var source = arguments[i] != null ? arguments[i] : {};
396
395
  var ownKeys = Object.keys(source);
@@ -400,7 +399,7 @@ function _object_spread$1(target) {
400
399
  }));
401
400
  }
402
401
  ownKeys.forEach(function(key) {
403
- _define_property$1(target, key, source[key]);
402
+ _define_property$2(target, key, source[key]);
404
403
  });
405
404
  }
406
405
  return target;
@@ -539,23 +538,23 @@ function generateSnapshotFromManifest(manifest) {
539
538
  };
540
539
  if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
541
540
  var prefetchInterface = manifest.metaData.prefetchInterface;
542
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
541
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
543
542
  prefetchInterface: prefetchInterface
544
543
  });
545
544
  }
546
545
  if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
547
546
  var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
548
- basicRemoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
547
+ basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
549
548
  prefetchEntry: simpleJoinRemoteEntry(path, name),
550
549
  prefetchEntryType: type
551
550
  });
552
551
  }
553
552
  if ('publicPath' in manifest.metaData) {
554
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
553
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
555
554
  publicPath: getPublicPath()
556
555
  });
557
556
  } else {
558
- remoteSnapshot = _object_spread_props(_object_spread$1({}, basicRemoteSnapshot), {
557
+ remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
559
558
  getPublicPath: getPublicPath()
560
559
  });
561
560
  }
@@ -598,6 +597,19 @@ function _async_to_generator$1(fn) {
598
597
  });
599
598
  };
600
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
+ }
601
613
  function _instanceof(left, right) {
602
614
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
603
615
  return !!right[Symbol.hasInstance](left);
@@ -605,6 +617,25 @@ function _instanceof(left, right) {
605
617
  return left instanceof right;
606
618
  }
607
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
+ }
608
639
  function _ts_generator$1(thisArg, body) {
609
640
  var f, y, t, g, _ = {
610
641
  label: 0,
@@ -749,7 +780,7 @@ function isStaticResourcesEqual(url1, url2) {
749
780
  // Check if the relative paths are identical
750
781
  return relativeUrl1 === relativeUrl2;
751
782
  }
752
- function createScript(url, cb, attrs, createScriptHook) {
783
+ function createScript(info) {
753
784
  // Retrieve the existing script element by its src attribute
754
785
  var script = null;
755
786
  var needAttach = true;
@@ -759,7 +790,7 @@ function createScript(url, cb, attrs, createScriptHook) {
759
790
  for(var i = 0; i < scripts.length; i++){
760
791
  var s = scripts[i];
761
792
  var scriptSrc = s.getAttribute('src');
762
- if (scriptSrc && isStaticResourcesEqual(scriptSrc, url)) {
793
+ if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
763
794
  script = s;
764
795
  needAttach = false;
765
796
  break;
@@ -768,59 +799,65 @@ function createScript(url, cb, attrs, createScriptHook) {
768
799
  if (!script) {
769
800
  script = document.createElement('script');
770
801
  script.type = 'text/javascript';
771
- script.src = url;
772
- if (createScriptHook) {
773
- var createScriptRes = createScriptHook(url);
802
+ script.src = info.url;
803
+ if (info.createScriptHook) {
804
+ var createScriptRes = info.createScriptHook(info.url);
774
805
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
775
806
  script = createScriptRes;
776
- } else if (typeof createScriptRes === 'object') {
807
+ } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
777
808
  if (createScriptRes.script) script = createScriptRes.script;
778
809
  if (createScriptRes.timeout) timeout = createScriptRes.timeout;
779
810
  }
780
811
  }
781
- }
782
- if (attrs) {
783
- Object.keys(attrs).forEach(function(name) {
784
- if (script) {
785
- if (name === 'async' || name === 'defer') {
786
- script[name] = attrs[name];
787
- } else {
788
- 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
+ }
789
822
  }
790
- }
791
- });
823
+ });
824
+ }
792
825
  }
793
826
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
794
827
  event) {
828
+ var _info_cb;
795
829
  clearTimeout(timeoutId);
796
830
  // Prevent memory leaks in IE.
797
831
  if (script) {
798
832
  script.onerror = null;
799
833
  script.onload = null;
800
834
  safeWrapper(function() {
801
- (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
+ }
802
839
  });
803
840
  if (prev) {
841
+ var _info_cb1;
804
842
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
805
843
  var res = prev(event);
806
- cb();
844
+ info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
807
845
  return res;
808
846
  }
809
847
  }
810
- cb();
848
+ info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
811
849
  };
812
850
  script.onerror = onScriptComplete.bind(null, script.onerror);
813
851
  script.onload = onScriptComplete.bind(null, script.onload);
814
852
  timeoutId = setTimeout(function() {
815
- onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
853
+ onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
816
854
  }, timeout);
817
855
  return {
818
856
  script: script,
819
857
  needAttach: needAttach
820
858
  };
821
859
  }
822
- function createLink(url, cb) {
823
- var attrs = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, createLinkHook = arguments.length > 3 ? arguments[3] : void 0;
860
+ function createLink(info) {
824
861
  // <link rel="preload" href="script.js" as="script">
825
862
  // Retrieve the existing script element by its src attribute
826
863
  var link = null;
@@ -830,7 +867,7 @@ function createLink(url, cb) {
830
867
  var l = links[i];
831
868
  var linkHref = l.getAttribute('href');
832
869
  var linkRef = l.getAttribute('ref');
833
- if (linkHref && isStaticResourcesEqual(linkHref, url) && linkRef === attrs['ref']) {
870
+ if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
834
871
  link = l;
835
872
  needAttach = false;
836
873
  break;
@@ -838,21 +875,21 @@ function createLink(url, cb) {
838
875
  }
839
876
  if (!link) {
840
877
  link = document.createElement('link');
841
- link.setAttribute('href', url);
842
- link.setAttribute('crossorigin', 'anonymous');
843
- if (createLinkHook) {
844
- var createLinkRes = createLinkHook(url);
878
+ link.setAttribute('href', info.url);
879
+ if (info.createLinkHook) {
880
+ var createLinkRes = info.createLinkHook(info.url);
845
881
  if (_instanceof(createLinkRes, HTMLLinkElement)) {
846
882
  link = createLinkRes;
847
883
  }
848
884
  }
849
- }
850
- if (attrs) {
851
- Object.keys(attrs).forEach(function(name) {
852
- if (link) {
853
- link.setAttribute(name, attrs[name]);
854
- }
855
- });
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
+ }
856
893
  }
857
894
  var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
858
895
  event) {
@@ -861,16 +898,19 @@ function createLink(url, cb) {
861
898
  link.onerror = null;
862
899
  link.onload = null;
863
900
  safeWrapper(function() {
864
- (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
+ }
865
905
  });
866
906
  if (prev) {
867
907
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
868
908
  var res = prev(event);
869
- cb();
909
+ info.cb();
870
910
  return res;
871
911
  }
872
912
  }
873
- cb();
913
+ info.cb();
874
914
  };
875
915
  link.onerror = onLinkComplete.bind(null, link.onerror);
876
916
  link.onload = onLinkComplete.bind(null, link.onload);
@@ -880,10 +920,19 @@ function createLink(url, cb) {
880
920
  };
881
921
  }
882
922
  function loadScript(url, info) {
883
- var attrs = info.attrs, createScriptHook = info.createScriptHook;
923
+ var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
884
924
  return new Promise(function(resolve, _reject) {
885
- var _createScript = createScript(url, resolve, attrs, createScriptHook), script = _createScript.script, needAttach = _createScript.needAttach;
886
- 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);
887
936
  });
888
937
  }
889
938
 
@@ -954,6 +1003,10 @@ function _non_iterable_rest() {
954
1003
  function _sliced_to_array(arr, i) {
955
1004
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
956
1005
  }
1006
+ function _type_of$1(obj) {
1007
+ "@swc/helpers - typeof";
1008
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1009
+ }
957
1010
  function _unsupported_iterable_to_array(o, minLen) {
958
1011
  if (!o) return;
959
1012
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -1072,7 +1125,7 @@ function importNodeModule(name) {
1072
1125
  function createScriptNode(url, cb, attrs, createScriptHook) {
1073
1126
  if (createScriptHook) {
1074
1127
  var hookResult = createScriptHook(url);
1075
- if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1128
+ if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of$1(hookResult)) === 'object' && 'url' in hookResult) {
1076
1129
  url = hookResult.url;
1077
1130
  }
1078
1131
  }
@@ -1244,11 +1297,11 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1244
1297
  if (options === true) {
1245
1298
  return defaultOptions;
1246
1299
  }
1247
- if (options && typeof options === 'object') {
1300
+ if (options && (typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object') {
1248
1301
  return _object_spread({}, defaultOptions, options);
1249
1302
  }
1250
1303
  throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
1251
1304
  };
1252
1305
  }
1253
1306
 
1254
- export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, MFModuleType, MFPrefetchCommon, 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 };
1307
+ 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 };
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.19",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
@@ -21,10 +21,3 @@ export declare const MFModuleType: {
21
21
  APP: string;
22
22
  };
23
23
  export declare const MODULE_DEVTOOL_IDENTIFIER = "__MF_DEVTOOLS_MODULE_INFO__";
24
- export declare const MFPrefetchCommon: {
25
- identifier: string;
26
- globalKey: string;
27
- library: string;
28
- exportsKey: string;
29
- fileName: string;
30
- };
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;
@@ -1,5 +1,5 @@
1
1
  import type { RemoteWithEntry, RemoteWithVersion } from './common';
2
- export type RemoteEntryType = 'esm' | 'global';
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
3
  interface ResourceInfo {
4
4
  path: string;
5
5
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.0-next-20240617071032",
3
+ "version": "0.0.0-next-20240617084909",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [