@module-federation/runtime 0.0.0-next-20240814104132 → 0.0.0-next-20240815094326
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 +25 -35
- package/dist/index.esm.js +25 -35
- package/dist/package.json +1 -9
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +1 -1
- package/dist/src/core.d.ts +0 -1
- package/package.json +2 -10
- package/dist/retry-plugin.cjs.d.ts +0 -2
- package/dist/retry-plugin.cjs.js +0 -68
- package/dist/retry-plugin.esm.js +0 -66
- package/dist/src/plugins/retry-plugin.d.ts +0 -9
package/dist/index.cjs.js
CHANGED
|
@@ -300,9 +300,6 @@ let Module = class Module {
|
|
|
300
300
|
remoteInfo: this.remoteInfo,
|
|
301
301
|
origin: this.host
|
|
302
302
|
});
|
|
303
|
-
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
|
|
304
|
-
console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
|
|
305
|
-
}
|
|
306
303
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
307
304
|
await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
|
|
308
305
|
remoteEntryExports
|
|
@@ -645,20 +642,18 @@ useLinkPreload = true) {
|
|
|
645
642
|
}
|
|
646
643
|
});
|
|
647
644
|
if (useLinkPreload) {
|
|
648
|
-
const defaultAttrs = {
|
|
649
|
-
rel: 'preload',
|
|
650
|
-
as: 'style',
|
|
651
|
-
crossorigin: 'anonymous'
|
|
652
|
-
};
|
|
653
645
|
cssAssets.forEach((cssUrl)=>{
|
|
654
646
|
const { link: cssEl, needAttach } = sdk.createLink({
|
|
655
647
|
url: cssUrl,
|
|
656
648
|
cb: ()=>{},
|
|
657
|
-
attrs:
|
|
658
|
-
|
|
649
|
+
attrs: {
|
|
650
|
+
rel: 'preload',
|
|
651
|
+
as: 'style',
|
|
652
|
+
crossorigin: 'anonymous'
|
|
653
|
+
},
|
|
654
|
+
createLinkHook: (url)=>{
|
|
659
655
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
660
|
-
url
|
|
661
|
-
attrs
|
|
656
|
+
url
|
|
662
657
|
});
|
|
663
658
|
if (res instanceof HTMLLinkElement) {
|
|
664
659
|
return res;
|
|
@@ -669,19 +664,17 @@ useLinkPreload = true) {
|
|
|
669
664
|
needAttach && document.head.appendChild(cssEl);
|
|
670
665
|
});
|
|
671
666
|
} else {
|
|
672
|
-
const defaultAttrs = {
|
|
673
|
-
rel: 'stylesheet',
|
|
674
|
-
type: 'text/css'
|
|
675
|
-
};
|
|
676
667
|
cssAssets.forEach((cssUrl)=>{
|
|
677
668
|
const { link: cssEl, needAttach } = sdk.createLink({
|
|
678
669
|
url: cssUrl,
|
|
679
670
|
cb: ()=>{},
|
|
680
|
-
attrs:
|
|
681
|
-
|
|
671
|
+
attrs: {
|
|
672
|
+
rel: 'stylesheet',
|
|
673
|
+
type: 'text/css'
|
|
674
|
+
},
|
|
675
|
+
createLinkHook: (url)=>{
|
|
682
676
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
683
|
-
url
|
|
684
|
-
attrs
|
|
677
|
+
url
|
|
685
678
|
});
|
|
686
679
|
if (res instanceof HTMLLinkElement) {
|
|
687
680
|
return res;
|
|
@@ -694,20 +687,18 @@ useLinkPreload = true) {
|
|
|
694
687
|
});
|
|
695
688
|
}
|
|
696
689
|
if (useLinkPreload) {
|
|
697
|
-
const defaultAttrs = {
|
|
698
|
-
rel: 'preload',
|
|
699
|
-
as: 'script',
|
|
700
|
-
crossorigin: 'anonymous'
|
|
701
|
-
};
|
|
702
690
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
703
691
|
const { link: linkEl, needAttach } = sdk.createLink({
|
|
704
692
|
url: jsUrl,
|
|
705
693
|
cb: ()=>{},
|
|
706
|
-
attrs:
|
|
707
|
-
|
|
694
|
+
attrs: {
|
|
695
|
+
rel: 'preload',
|
|
696
|
+
as: 'script',
|
|
697
|
+
crossorigin: 'anonymous'
|
|
698
|
+
},
|
|
699
|
+
createLinkHook: (url)=>{
|
|
708
700
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
709
|
-
url
|
|
710
|
-
attrs
|
|
701
|
+
url
|
|
711
702
|
});
|
|
712
703
|
if (res instanceof HTMLLinkElement) {
|
|
713
704
|
return res;
|
|
@@ -718,15 +709,14 @@ useLinkPreload = true) {
|
|
|
718
709
|
needAttach && document.head.appendChild(linkEl);
|
|
719
710
|
});
|
|
720
711
|
} else {
|
|
721
|
-
const defaultAttrs = {
|
|
722
|
-
fetchpriority: 'high',
|
|
723
|
-
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
724
|
-
};
|
|
725
712
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
726
713
|
const { script: scriptEl, needAttach } = sdk.createScript({
|
|
727
714
|
url: jsUrl,
|
|
728
715
|
cb: ()=>{},
|
|
729
|
-
attrs:
|
|
716
|
+
attrs: {
|
|
717
|
+
fetchpriority: 'high',
|
|
718
|
+
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
719
|
+
},
|
|
730
720
|
createScriptHook: (url, attrs)=>{
|
|
731
721
|
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
732
722
|
url,
|
|
@@ -2076,7 +2066,7 @@ class FederationHost {
|
|
|
2076
2066
|
// maybe will change, temporarily for internal use only
|
|
2077
2067
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2078
2068
|
});
|
|
2079
|
-
this.version = "0.
|
|
2069
|
+
this.version = "0.3.5";
|
|
2080
2070
|
this.moduleCache = new Map();
|
|
2081
2071
|
this.loaderHook = new PluginSystem({
|
|
2082
2072
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/index.esm.js
CHANGED
|
@@ -298,9 +298,6 @@ let Module = class Module {
|
|
|
298
298
|
remoteInfo: this.remoteInfo,
|
|
299
299
|
origin: this.host
|
|
300
300
|
});
|
|
301
|
-
if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === 'undefined') {
|
|
302
|
-
console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
|
|
303
|
-
}
|
|
304
301
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
305
302
|
await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
|
|
306
303
|
remoteEntryExports
|
|
@@ -643,20 +640,18 @@ useLinkPreload = true) {
|
|
|
643
640
|
}
|
|
644
641
|
});
|
|
645
642
|
if (useLinkPreload) {
|
|
646
|
-
const defaultAttrs = {
|
|
647
|
-
rel: 'preload',
|
|
648
|
-
as: 'style',
|
|
649
|
-
crossorigin: 'anonymous'
|
|
650
|
-
};
|
|
651
643
|
cssAssets.forEach((cssUrl)=>{
|
|
652
644
|
const { link: cssEl, needAttach } = createLink({
|
|
653
645
|
url: cssUrl,
|
|
654
646
|
cb: ()=>{},
|
|
655
|
-
attrs:
|
|
656
|
-
|
|
647
|
+
attrs: {
|
|
648
|
+
rel: 'preload',
|
|
649
|
+
as: 'style',
|
|
650
|
+
crossorigin: 'anonymous'
|
|
651
|
+
},
|
|
652
|
+
createLinkHook: (url)=>{
|
|
657
653
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
658
|
-
url
|
|
659
|
-
attrs
|
|
654
|
+
url
|
|
660
655
|
});
|
|
661
656
|
if (res instanceof HTMLLinkElement) {
|
|
662
657
|
return res;
|
|
@@ -667,19 +662,17 @@ useLinkPreload = true) {
|
|
|
667
662
|
needAttach && document.head.appendChild(cssEl);
|
|
668
663
|
});
|
|
669
664
|
} else {
|
|
670
|
-
const defaultAttrs = {
|
|
671
|
-
rel: 'stylesheet',
|
|
672
|
-
type: 'text/css'
|
|
673
|
-
};
|
|
674
665
|
cssAssets.forEach((cssUrl)=>{
|
|
675
666
|
const { link: cssEl, needAttach } = createLink({
|
|
676
667
|
url: cssUrl,
|
|
677
668
|
cb: ()=>{},
|
|
678
|
-
attrs:
|
|
679
|
-
|
|
669
|
+
attrs: {
|
|
670
|
+
rel: 'stylesheet',
|
|
671
|
+
type: 'text/css'
|
|
672
|
+
},
|
|
673
|
+
createLinkHook: (url)=>{
|
|
680
674
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
681
|
-
url
|
|
682
|
-
attrs
|
|
675
|
+
url
|
|
683
676
|
});
|
|
684
677
|
if (res instanceof HTMLLinkElement) {
|
|
685
678
|
return res;
|
|
@@ -692,20 +685,18 @@ useLinkPreload = true) {
|
|
|
692
685
|
});
|
|
693
686
|
}
|
|
694
687
|
if (useLinkPreload) {
|
|
695
|
-
const defaultAttrs = {
|
|
696
|
-
rel: 'preload',
|
|
697
|
-
as: 'script',
|
|
698
|
-
crossorigin: 'anonymous'
|
|
699
|
-
};
|
|
700
688
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
701
689
|
const { link: linkEl, needAttach } = createLink({
|
|
702
690
|
url: jsUrl,
|
|
703
691
|
cb: ()=>{},
|
|
704
|
-
attrs:
|
|
705
|
-
|
|
692
|
+
attrs: {
|
|
693
|
+
rel: 'preload',
|
|
694
|
+
as: 'script',
|
|
695
|
+
crossorigin: 'anonymous'
|
|
696
|
+
},
|
|
697
|
+
createLinkHook: (url)=>{
|
|
706
698
|
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
707
|
-
url
|
|
708
|
-
attrs
|
|
699
|
+
url
|
|
709
700
|
});
|
|
710
701
|
if (res instanceof HTMLLinkElement) {
|
|
711
702
|
return res;
|
|
@@ -716,15 +707,14 @@ useLinkPreload = true) {
|
|
|
716
707
|
needAttach && document.head.appendChild(linkEl);
|
|
717
708
|
});
|
|
718
709
|
} else {
|
|
719
|
-
const defaultAttrs = {
|
|
720
|
-
fetchpriority: 'high',
|
|
721
|
-
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
722
|
-
};
|
|
723
710
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
724
711
|
const { script: scriptEl, needAttach } = createScript({
|
|
725
712
|
url: jsUrl,
|
|
726
713
|
cb: ()=>{},
|
|
727
|
-
attrs:
|
|
714
|
+
attrs: {
|
|
715
|
+
fetchpriority: 'high',
|
|
716
|
+
type: (remoteInfo == null ? void 0 : remoteInfo.type) === 'module' ? 'module' : 'text/javascript'
|
|
717
|
+
},
|
|
728
718
|
createScriptHook: (url, attrs)=>{
|
|
729
719
|
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
730
720
|
url,
|
|
@@ -2074,7 +2064,7 @@ class FederationHost {
|
|
|
2074
2064
|
// maybe will change, temporarily for internal use only
|
|
2075
2065
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2076
2066
|
});
|
|
2077
|
-
this.version = "0.
|
|
2067
|
+
this.version = "0.3.5";
|
|
2078
2068
|
this.moduleCache = new Map();
|
|
2079
2069
|
this.loaderHook = new PluginSystem({
|
|
2080
2070
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -29,11 +29,6 @@
|
|
|
29
29
|
"import": "./dist/types.esm.js",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
|
-
"./retry-plugin": {
|
|
33
|
-
"types": "./dist/retry-plugin.cjs.d.ts",
|
|
34
|
-
"import": "./dist/retry-plugin.esm.js",
|
|
35
|
-
"require": "./dist/retry-plugin.cjs.js"
|
|
36
|
-
},
|
|
37
32
|
"./*": "./*"
|
|
38
33
|
},
|
|
39
34
|
"typesVersions": {
|
|
@@ -46,9 +41,6 @@
|
|
|
46
41
|
],
|
|
47
42
|
"types": [
|
|
48
43
|
"./dist/types.cjs.d.ts"
|
|
49
|
-
],
|
|
50
|
-
"retry-plugin": [
|
|
51
|
-
"./dist/retry-plugin.cjs.d.ts"
|
|
52
44
|
]
|
|
53
45
|
}
|
|
54
46
|
},
|
package/dist/share.cjs.js
CHANGED
|
@@ -212,7 +212,7 @@ function getGlobalFederationConstructor() {
|
|
|
212
212
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
213
213
|
if (isDebug) {
|
|
214
214
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
215
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
215
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.3.5";
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -210,7 +210,7 @@ function getGlobalFederationConstructor() {
|
|
|
210
210
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
211
211
|
if (isDebug) {
|
|
212
212
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
213
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
213
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.3.5";
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/src/core.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240815094326",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -29,11 +29,6 @@
|
|
|
29
29
|
"import": "./dist/types.esm.js",
|
|
30
30
|
"require": "./dist/types.cjs.js"
|
|
31
31
|
},
|
|
32
|
-
"./retry-plugin": {
|
|
33
|
-
"types": "./dist/retry-plugin.cjs.d.ts",
|
|
34
|
-
"import": "./dist/retry-plugin.esm.js",
|
|
35
|
-
"require": "./dist/retry-plugin.cjs.js"
|
|
36
|
-
},
|
|
37
32
|
"./*": "./*"
|
|
38
33
|
},
|
|
39
34
|
"typesVersions": {
|
|
@@ -46,13 +41,10 @@
|
|
|
46
41
|
],
|
|
47
42
|
"types": [
|
|
48
43
|
"./dist/types.cjs.d.ts"
|
|
49
|
-
],
|
|
50
|
-
"retry-plugin": [
|
|
51
|
-
"./dist/retry-plugin.cjs.d.ts"
|
|
52
44
|
]
|
|
53
45
|
}
|
|
54
46
|
},
|
|
55
47
|
"dependencies": {
|
|
56
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
48
|
+
"@module-federation/sdk": "0.0.0-next-20240815094326"
|
|
57
49
|
}
|
|
58
50
|
}
|
package/dist/retry-plugin.cjs.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _extends() {
|
|
4
|
-
_extends = Object.assign || function(target) {
|
|
5
|
-
for(var i = 1; i < arguments.length; i++){
|
|
6
|
-
var source = arguments[i];
|
|
7
|
-
for(var key in source){
|
|
8
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
9
|
-
target[key] = source[key];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return target;
|
|
14
|
-
};
|
|
15
|
-
return _extends.apply(this, arguments);
|
|
16
|
-
}
|
|
17
|
-
const defaultRetries = 3;
|
|
18
|
-
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
|
|
19
|
-
try {
|
|
20
|
-
const response = await fetch(url, options);
|
|
21
|
-
// To prevent the response object from being read multiple times and causing errors, clone it
|
|
22
|
-
const responseClone = response.clone();
|
|
23
|
-
// Network error
|
|
24
|
-
if (!response.ok) {
|
|
25
|
-
throw new Error(`Server error:${response.status}`);
|
|
26
|
-
}
|
|
27
|
-
// parse json error
|
|
28
|
-
await responseClone.json().catch((error)=>{
|
|
29
|
-
throw new Error(`Json parse error: ${error}, url is: ${url}`);
|
|
30
|
-
});
|
|
31
|
-
return response;
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (retryTimes <= 0) {
|
|
34
|
-
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
|
|
35
|
-
if (fallbackUrl && fallbackUrl !== url) {
|
|
36
|
-
return fetchWithRetry({
|
|
37
|
-
url: fallbackUrl,
|
|
38
|
-
options,
|
|
39
|
-
retryTimes: 1,
|
|
40
|
-
fallbackUrl
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
throw new Error('The request failed three times and has now been abandoned');
|
|
44
|
-
}
|
|
45
|
-
// If there are remaining times, delay 1 second and try again
|
|
46
|
-
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
47
|
-
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
|
|
48
|
-
return await fetchWithRetry({
|
|
49
|
-
url,
|
|
50
|
-
options,
|
|
51
|
-
retryTimes: retryTimes - 1,
|
|
52
|
-
fallbackUrl
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const RetryPlugin = (params)=>({
|
|
57
|
-
name: 'retry-plugin',
|
|
58
|
-
async fetch (url, options) {
|
|
59
|
-
return fetchWithRetry({
|
|
60
|
-
url,
|
|
61
|
-
options: _extends({}, options, params == null ? void 0 : params.options),
|
|
62
|
-
retryTimes: params == null ? void 0 : params.retryTimes,
|
|
63
|
-
fallbackUrl: params == null ? void 0 : params.fallbackUrl
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
module.exports = RetryPlugin;
|
package/dist/retry-plugin.esm.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
_extends = Object.assign || function(target) {
|
|
3
|
-
for(var i = 1; i < arguments.length; i++){
|
|
4
|
-
var source = arguments[i];
|
|
5
|
-
for(var key in source){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
7
|
-
target[key] = source[key];
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return target;
|
|
12
|
-
};
|
|
13
|
-
return _extends.apply(this, arguments);
|
|
14
|
-
}
|
|
15
|
-
const defaultRetries = 3;
|
|
16
|
-
async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries, fallbackUrl = '' }) {
|
|
17
|
-
try {
|
|
18
|
-
const response = await fetch(url, options);
|
|
19
|
-
// To prevent the response object from being read multiple times and causing errors, clone it
|
|
20
|
-
const responseClone = response.clone();
|
|
21
|
-
// Network error
|
|
22
|
-
if (!response.ok) {
|
|
23
|
-
throw new Error(`Server error:${response.status}`);
|
|
24
|
-
}
|
|
25
|
-
// parse json error
|
|
26
|
-
await responseClone.json().catch((error)=>{
|
|
27
|
-
throw new Error(`Json parse error: ${error}, url is: ${url}`);
|
|
28
|
-
});
|
|
29
|
-
return response;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (retryTimes <= 0) {
|
|
32
|
-
console.log(`>>>>>>>>> retry failed after ${defaultRetries} times for url: ${url}, now will try fallbackUrl url: ${fallbackUrl} <<<<<<<<<`);
|
|
33
|
-
if (fallbackUrl && fallbackUrl !== url) {
|
|
34
|
-
return fetchWithRetry({
|
|
35
|
-
url: fallbackUrl,
|
|
36
|
-
options,
|
|
37
|
-
retryTimes: 1,
|
|
38
|
-
fallbackUrl
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
throw new Error('The request failed three times and has now been abandoned');
|
|
42
|
-
}
|
|
43
|
-
// If there are remaining times, delay 1 second and try again
|
|
44
|
-
await new Promise((resolve)=>setTimeout(resolve, 1000));
|
|
45
|
-
console.log(`Trying again. Number of retries available:${retryTimes - 1}`);
|
|
46
|
-
return await fetchWithRetry({
|
|
47
|
-
url,
|
|
48
|
-
options,
|
|
49
|
-
retryTimes: retryTimes - 1,
|
|
50
|
-
fallbackUrl
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const RetryPlugin = (params)=>({
|
|
55
|
-
name: 'retry-plugin',
|
|
56
|
-
async fetch (url, options) {
|
|
57
|
-
return fetchWithRetry({
|
|
58
|
-
url,
|
|
59
|
-
options: _extends({}, options, params == null ? void 0 : params.options),
|
|
60
|
-
retryTimes: params == null ? void 0 : params.retryTimes,
|
|
61
|
-
fallbackUrl: params == null ? void 0 : params.fallbackUrl
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
export { RetryPlugin as default };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FederationRuntimePlugin } from '../type/plugin';
|
|
2
|
-
interface FetchWithRetryOptions {
|
|
3
|
-
url: string;
|
|
4
|
-
options?: RequestInit;
|
|
5
|
-
retryTimes?: number;
|
|
6
|
-
fallbackUrl?: string;
|
|
7
|
-
}
|
|
8
|
-
declare const RetryPlugin: (params?: Omit<FetchWithRetryOptions, 'url'>) => FederationRuntimePlugin;
|
|
9
|
-
export default RetryPlugin;
|