@module-federation/sdk 0.0.11 → 0.0.13

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
@@ -757,6 +757,63 @@ function createScript(url, cb, attrs, createScriptHook) {
757
757
  needAttach: needAttach
758
758
  };
759
759
  }
760
+ function createLink(url, cb, attrs, createLinkHook) {
761
+ // <link rel="preload" href="script.js" as="script">
762
+ // Retrieve the existing script element by its src attribute
763
+ var link = null;
764
+ var needAttach = true;
765
+ var links = document.getElementsByTagName("link");
766
+ for(var i = 0; i < links.length; i++){
767
+ var l = links[i];
768
+ var linkHref = l.getAttribute("href");
769
+ if (linkHref && isStaticResourcesEqual(linkHref, url)) {
770
+ link = l;
771
+ needAttach = false;
772
+ break;
773
+ }
774
+ }
775
+ if (!link) {
776
+ link = document.createElement("link");
777
+ link.setAttribute("href", url);
778
+ if (createLinkHook) {
779
+ var createLinkRes = createLinkHook(url);
780
+ if (_instanceof(createLinkRes, HTMLLinkElement)) {
781
+ link = createLinkRes;
782
+ }
783
+ }
784
+ }
785
+ if (attrs) {
786
+ Object.keys(attrs).forEach(function(name) {
787
+ if (link) {
788
+ link.setAttribute(name, attrs[name]);
789
+ }
790
+ });
791
+ }
792
+ var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
793
+ event) {
794
+ // Prevent memory leaks in IE.
795
+ if (link) {
796
+ link.onerror = null;
797
+ link.onload = null;
798
+ safeWrapper(function() {
799
+ (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
800
+ });
801
+ if (prev) {
802
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
803
+ var res = prev(event);
804
+ cb();
805
+ return res;
806
+ }
807
+ }
808
+ cb();
809
+ };
810
+ link.onerror = onLinkComplete.bind(null, link.onerror);
811
+ link.onload = onLinkComplete.bind(null, link.onload);
812
+ return {
813
+ link: link,
814
+ needAttach: needAttach
815
+ };
816
+ }
760
817
  function loadScript(url, info) {
761
818
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
762
819
  return new Promise(function(resolve, _reject) {
@@ -1088,6 +1145,7 @@ exports.NameTransformSymbol = NameTransformSymbol;
1088
1145
  exports.SEPARATOR = SEPARATOR;
1089
1146
  exports.assert = assert;
1090
1147
  exports.composeKeyWithSeparator = composeKeyWithSeparator;
1148
+ exports.createLink = createLink;
1091
1149
  exports.createScript = createScript;
1092
1150
  exports.createScriptNode = createScriptNode;
1093
1151
  exports.decodeName = decodeName;
package/dist/index.esm.js CHANGED
@@ -753,6 +753,63 @@ function createScript(url, cb, attrs, createScriptHook) {
753
753
  needAttach: needAttach
754
754
  };
755
755
  }
756
+ function createLink(url, cb, attrs, createLinkHook) {
757
+ // <link rel="preload" href="script.js" as="script">
758
+ // Retrieve the existing script element by its src attribute
759
+ var link = null;
760
+ var needAttach = true;
761
+ var links = document.getElementsByTagName("link");
762
+ for(var i = 0; i < links.length; i++){
763
+ var l = links[i];
764
+ var linkHref = l.getAttribute("href");
765
+ if (linkHref && isStaticResourcesEqual(linkHref, url)) {
766
+ link = l;
767
+ needAttach = false;
768
+ break;
769
+ }
770
+ }
771
+ if (!link) {
772
+ link = document.createElement("link");
773
+ link.setAttribute("href", url);
774
+ if (createLinkHook) {
775
+ var createLinkRes = createLinkHook(url);
776
+ if (_instanceof(createLinkRes, HTMLLinkElement)) {
777
+ link = createLinkRes;
778
+ }
779
+ }
780
+ }
781
+ if (attrs) {
782
+ Object.keys(attrs).forEach(function(name) {
783
+ if (link) {
784
+ link.setAttribute(name, attrs[name]);
785
+ }
786
+ });
787
+ }
788
+ var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
789
+ event) {
790
+ // Prevent memory leaks in IE.
791
+ if (link) {
792
+ link.onerror = null;
793
+ link.onload = null;
794
+ safeWrapper(function() {
795
+ (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
796
+ });
797
+ if (prev) {
798
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
799
+ var res = prev(event);
800
+ cb();
801
+ return res;
802
+ }
803
+ }
804
+ cb();
805
+ };
806
+ link.onerror = onLinkComplete.bind(null, link.onerror);
807
+ link.onload = onLinkComplete.bind(null, link.onload);
808
+ return {
809
+ link: link,
810
+ needAttach: needAttach
811
+ };
812
+ }
756
813
  function loadScript(url, info) {
757
814
  var attrs = info.attrs, createScriptHook = info.createScriptHook;
758
815
  return new Promise(function(resolve, _reject) {
@@ -1073,4 +1130,4 @@ function loadScriptNode(url, info) {
1073
1130
  });
1074
1131
  }
1075
1132
 
1076
- export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, NameTransformMap, NameTransformSymbol, SEPARATOR, assert, composeKeyWithSeparator, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, parseEntry, safeWrapper, simpleJoinRemoteEntry, warn };
1133
+ export { BROWSER_LOG_KEY, BROWSER_LOG_VALUE, EncodedNameTransformMap, FederationModuleManifest, Logger, MANIFEST_EXT, NameTransformMap, NameTransformSymbol, SEPARATOR, assert, composeKeyWithSeparator, createLink, createScript, createScriptNode, decodeName, encodeName, error, generateExposeFilename, generateShareFilename, generateSnapshotFromManifest, getProcessEnv, getResourceUrl, isBrowserEnv, isDebugMode, isManifestProvider, isStaticResourcesEqual, loadScript, loadScriptNode, logger, parseEntry, safeWrapper, simpleJoinRemoteEntry, warn };
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
package/dist/src/dom.d.ts CHANGED
@@ -4,6 +4,10 @@ export declare function createScript(url: string, cb: (value: void | PromiseLike
4
4
  script: HTMLScriptElement;
5
5
  needAttach: boolean;
6
6
  };
7
+ export declare function createLink(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createLinkHook?: (url: string) => HTMLLinkElement | void): {
8
+ link: HTMLLinkElement;
9
+ needAttach: boolean;
10
+ };
7
11
  export declare function loadScript(url: string, info: {
8
12
  attrs?: Record<string, any>;
9
13
  createScriptHook?: (url: string) => HTMLScriptElement | void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [