@module-federation/sdk 0.1.13 → 0.1.14
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 +9 -0
- package/dist/index.esm.js +9 -0
- package/dist/package.json +1 -1
- package/dist/src/dom.d.ts +6 -2
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -750,6 +750,8 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
750
750
|
// Retrieve the existing script element by its src attribute
|
|
751
751
|
var script = null;
|
|
752
752
|
var needAttach = true;
|
|
753
|
+
var timeout = 20000;
|
|
754
|
+
var timeoutId;
|
|
753
755
|
var scripts = document.getElementsByTagName('script');
|
|
754
756
|
for(var i = 0; i < scripts.length; i++){
|
|
755
757
|
var s = scripts[i];
|
|
@@ -768,6 +770,9 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
768
770
|
var createScriptRes = createScriptHook(url);
|
|
769
771
|
if (_instanceof(createScriptRes, HTMLScriptElement)) {
|
|
770
772
|
script = createScriptRes;
|
|
773
|
+
} else if (typeof createScriptRes === 'object') {
|
|
774
|
+
if (createScriptRes.script) script = createScriptRes.script;
|
|
775
|
+
if (createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
771
776
|
}
|
|
772
777
|
}
|
|
773
778
|
}
|
|
@@ -784,6 +789,7 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
784
789
|
}
|
|
785
790
|
var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
786
791
|
event) {
|
|
792
|
+
clearTimeout(timeoutId);
|
|
787
793
|
// Prevent memory leaks in IE.
|
|
788
794
|
if (script) {
|
|
789
795
|
script.onerror = null;
|
|
@@ -802,6 +808,9 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
802
808
|
};
|
|
803
809
|
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
804
810
|
script.onload = onScriptComplete.bind(null, script.onload);
|
|
811
|
+
timeoutId = setTimeout(function() {
|
|
812
|
+
onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
|
|
813
|
+
}, timeout);
|
|
805
814
|
return {
|
|
806
815
|
script: script,
|
|
807
816
|
needAttach: needAttach
|
package/dist/index.esm.js
CHANGED
|
@@ -746,6 +746,8 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
746
746
|
// Retrieve the existing script element by its src attribute
|
|
747
747
|
var script = null;
|
|
748
748
|
var needAttach = true;
|
|
749
|
+
var timeout = 20000;
|
|
750
|
+
var timeoutId;
|
|
749
751
|
var scripts = document.getElementsByTagName('script');
|
|
750
752
|
for(var i = 0; i < scripts.length; i++){
|
|
751
753
|
var s = scripts[i];
|
|
@@ -764,6 +766,9 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
764
766
|
var createScriptRes = createScriptHook(url);
|
|
765
767
|
if (_instanceof(createScriptRes, HTMLScriptElement)) {
|
|
766
768
|
script = createScriptRes;
|
|
769
|
+
} else if (typeof createScriptRes === 'object') {
|
|
770
|
+
if (createScriptRes.script) script = createScriptRes.script;
|
|
771
|
+
if (createScriptRes.timeout) timeout = createScriptRes.timeout;
|
|
767
772
|
}
|
|
768
773
|
}
|
|
769
774
|
}
|
|
@@ -780,6 +785,7 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
780
785
|
}
|
|
781
786
|
var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
782
787
|
event) {
|
|
788
|
+
clearTimeout(timeoutId);
|
|
783
789
|
// Prevent memory leaks in IE.
|
|
784
790
|
if (script) {
|
|
785
791
|
script.onerror = null;
|
|
@@ -798,6 +804,9 @@ function createScript(url, cb, attrs, createScriptHook) {
|
|
|
798
804
|
};
|
|
799
805
|
script.onerror = onScriptComplete.bind(null, script.onerror);
|
|
800
806
|
script.onload = onScriptComplete.bind(null, script.onload);
|
|
807
|
+
timeoutId = setTimeout(function() {
|
|
808
|
+
onScriptComplete(null, new Error('Remote script "'.concat(url, '" time-outed.')));
|
|
809
|
+
}, timeout);
|
|
801
810
|
return {
|
|
802
811
|
script: script,
|
|
803
812
|
needAttach: needAttach
|
package/dist/package.json
CHANGED
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
|
|
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) =>
|
|
17
|
+
createScriptHook?: (url: string) => CreateScriptHookReturn;
|
|
14
18
|
}): Promise<void>;
|