@module-federation/sdk 0.0.0-next-20240521125425 → 0.0.0-next-20240523080317

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
@@ -755,6 +755,8 @@ function createScript(url, cb, attrs, createScriptHook) {
755
755
  // Retrieve the existing script element by its src attribute
756
756
  var script = null;
757
757
  var needAttach = true;
758
+ var timeout = 20000;
759
+ var timeoutId;
758
760
  var scripts = document.getElementsByTagName('script');
759
761
  for(var i = 0; i < scripts.length; i++){
760
762
  var s = scripts[i];
@@ -773,6 +775,9 @@ function createScript(url, cb, attrs, createScriptHook) {
773
775
  var createScriptRes = createScriptHook(url);
774
776
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
775
777
  script = createScriptRes;
778
+ } else if (typeof createScriptRes === 'object') {
779
+ if (createScriptRes.script) script = createScriptRes.script;
780
+ if (createScriptRes.timeout) timeout = createScriptRes.timeout;
776
781
  }
777
782
  }
778
783
  }
@@ -789,6 +794,7 @@ function createScript(url, cb, attrs, createScriptHook) {
789
794
  }
790
795
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
791
796
  event) {
797
+ clearTimeout(timeoutId);
792
798
  // Prevent memory leaks in IE.
793
799
  if (script) {
794
800
  script.onerror = null;
@@ -807,6 +813,9 @@ function createScript(url, cb, attrs, createScriptHook) {
807
813
  };
808
814
  script.onerror = onScriptComplete.bind(null, script.onerror);
809
815
  script.onload = onScriptComplete.bind(null, script.onload);
816
+ timeoutId = setTimeout(function() {
817
+ onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
818
+ }, timeout);
810
819
  return {
811
820
  script: script,
812
821
  needAttach: needAttach
package/dist/index.esm.js CHANGED
@@ -751,6 +751,8 @@ function createScript(url, cb, attrs, createScriptHook) {
751
751
  // Retrieve the existing script element by its src attribute
752
752
  var script = null;
753
753
  var needAttach = true;
754
+ var timeout = 20000;
755
+ var timeoutId;
754
756
  var scripts = document.getElementsByTagName('script');
755
757
  for(var i = 0; i < scripts.length; i++){
756
758
  var s = scripts[i];
@@ -769,6 +771,9 @@ function createScript(url, cb, attrs, createScriptHook) {
769
771
  var createScriptRes = createScriptHook(url);
770
772
  if (_instanceof(createScriptRes, HTMLScriptElement)) {
771
773
  script = createScriptRes;
774
+ } else if (typeof createScriptRes === 'object') {
775
+ if (createScriptRes.script) script = createScriptRes.script;
776
+ if (createScriptRes.timeout) timeout = createScriptRes.timeout;
772
777
  }
773
778
  }
774
779
  }
@@ -785,6 +790,7 @@ function createScript(url, cb, attrs, createScriptHook) {
785
790
  }
786
791
  var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
787
792
  event) {
793
+ clearTimeout(timeoutId);
788
794
  // Prevent memory leaks in IE.
789
795
  if (script) {
790
796
  script.onerror = null;
@@ -803,6 +809,9 @@ function createScript(url, cb, attrs, createScriptHook) {
803
809
  };
804
810
  script.onerror = onScriptComplete.bind(null, script.onerror);
805
811
  script.onload = onScriptComplete.bind(null, script.onload);
812
+ timeoutId = setTimeout(function() {
813
+ onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
814
+ }, timeout);
806
815
  return {
807
816
  script: script,
808
817
  needAttach: needAttach
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/sdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [
package/dist/src/dom.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export declare function safeWrapper<T extends (...args: Array<any>) => any>(callback: T, disableWarn?: boolean): Promise<ReturnType<T> | undefined>;
2
2
  export declare function isStaticResourcesEqual(url1: string, url2: string): boolean;
3
- export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => HTMLScriptElement | void): {
3
+ export type CreateScriptHookReturn = HTMLScriptElement | {
4
+ script?: HTMLScriptElement;
5
+ timeout?: number;
6
+ } | void;
7
+ export declare function createScript(url: string, cb: (value: void | PromiseLike<void>) => void, attrs?: Record<string, any>, createScriptHook?: (url: string) => CreateScriptHookReturn): {
4
8
  script: HTMLScriptElement;
5
9
  needAttach: boolean;
6
10
  };
@@ -10,5 +14,5 @@ export declare function createLink(url: string, cb: (value: void | PromiseLike<v
10
14
  };
11
15
  export declare function loadScript(url: string, info: {
12
16
  attrs?: Record<string, any>;
13
- createScriptHook?: (url: string) => HTMLScriptElement | void;
17
+ createScriptHook?: (url: string) => CreateScriptHookReturn;
14
18
  }): Promise<void>;
@@ -82,6 +82,7 @@ export interface PluginManifestOptions {
82
82
  export interface PluginDevOptions {
83
83
  disableLiveReload?: boolean;
84
84
  disableHotTypesReload?: boolean;
85
+ injectWebClient?: 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.0.0-next-20240521125425",
3
+ "version": "0.0.0-next-20240523080317",
4
4
  "license": "MIT",
5
5
  "description": "A sdk for support module federation",
6
6
  "keywords": [