@module-federation/sdk 0.0.0-next-20240617070818 → 0.0.0-next-20240617071542

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