@rsbuild/plugin-assets-retry 1.4.0 → 1.4.2
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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/dist/runtime/initialChunkRetry.js +5 -16
- package/dist/runtime/initialChunkRetry.min.js +1 -1
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -90,8 +90,7 @@ const defaultAssetsRetryOptions = {
|
|
|
90
90
|
max: 3,
|
|
91
91
|
type: ['script', 'link', 'img'],
|
|
92
92
|
domain: [],
|
|
93
|
-
crossOrigin:
|
|
94
|
-
test: '',
|
|
93
|
+
crossOrigin: rsbuildConfig.html.crossorigin,
|
|
95
94
|
delay: 0,
|
|
96
95
|
addQuery: false,
|
|
97
96
|
inlineScript: true,
|
|
@@ -484,6 +483,7 @@ import { ASSETS_RETRY_DATA_ATTRIBUTE } from '@rsbuild/plugin-assets-retry';
|
|
|
484
483
|
```
|
|
485
484
|
|
|
486
485
|
The attribute values are:
|
|
486
|
+
|
|
487
487
|
- `"inline"` for inline scripts (when `inlineScript: true`)
|
|
488
488
|
- `"external"` for external scripts (when `inlineScript: false`)
|
|
489
489
|
|
package/README.zh-CN.md
CHANGED
|
@@ -88,8 +88,7 @@ const defaultAssetsRetryOptions = {
|
|
|
88
88
|
max: 3,
|
|
89
89
|
type: ['script', 'link', 'img'],
|
|
90
90
|
domain: [],
|
|
91
|
-
crossOrigin:
|
|
92
|
-
test: '',
|
|
91
|
+
crossOrigin: rsbuildConfig.html.crossorigin,
|
|
93
92
|
delay: 0,
|
|
94
93
|
addQuery: false,
|
|
95
94
|
inlineScript: true,
|
|
@@ -482,6 +481,7 @@ import { ASSETS_RETRY_DATA_ATTRIBUTE } from '@rsbuild/plugin-assets-retry';
|
|
|
482
481
|
```
|
|
483
482
|
|
|
484
483
|
属性值包括:
|
|
484
|
+
|
|
485
485
|
- `"inline"` 用于内联脚本(当 `inlineScript: true` 时)
|
|
486
486
|
- `"external"` 用于外部脚本(当 `inlineScript: false` 时)
|
|
487
487
|
|
package/dist/index.cjs
CHANGED
|
@@ -295,7 +295,7 @@ var __webpack_exports__ = {};
|
|
|
295
295
|
const { inlineScript = true } = userOptions;
|
|
296
296
|
const getScriptPath = (environment)=>{
|
|
297
297
|
const distDir = environment.config.output.distPath.js;
|
|
298
|
-
return external_node_path_default().posix.join(distDir, "assets-retry.1-4-
|
|
298
|
+
return external_node_path_default().posix.join(distDir, "assets-retry.1-4-2.js");
|
|
299
299
|
};
|
|
300
300
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
301
301
|
var _config_output_minify;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -270,7 +270,7 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
270
270
|
const { inlineScript = true } = userOptions;
|
|
271
271
|
const getScriptPath = (environment)=>{
|
|
272
272
|
const distDir = environment.config.output.distPath.js;
|
|
273
|
-
return node_path.posix.join(distDir, "assets-retry.1-4-
|
|
273
|
+
return node_path.posix.join(distDir, "assets-retry.1-4-2.js");
|
|
274
274
|
};
|
|
275
275
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
276
276
|
var _config_output_minify;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";var n="[@rsbuild/plugin-assets-retry] ";function
|
|
1
|
+
!function(){"use strict";var n="[@rsbuild/plugin-assets-retry] ";function e(n,e){for(var r=e.domain,t=0;t<r.length;t++){var i=r[t];if(-1!==n.indexOf(i))return i}return window.origin}var r=/[?#].*$/;function t(n,e,t,i,o,_){var a;return n.replace(e,t).replace(r,"")+(a=i+1,!0===_.addQuery?""!==o?"".concat(o,"&retry=").concat(a):"?retry=".concat(a):"function"==typeof _.addQuery?_.addQuery({times:a,originalQuery:o}):"")}var i=__RETRY_OPTIONS__,o={},_={},a={},l={},u=__RUNTIME_GLOBALS_ENSURE_CHUNK__,c=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,s=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||function(){return null},f=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function y(r){var f=Array.prototype.slice.call(arguments);f[10]||(f[10]={count:0,cssFailedCount:0});var d=f[10],S=u.apply(null,f);try{var p=c(r),R=s(r);"undefined"!=typeof window&&(p&&(window.__RB_ASYNC_CHUNKS__[p]=!0),R&&(window.__RB_ASYNC_CHUNKS__[R]=!0))}catch(e){console.error(n,"get original script or CSS filename error",e)}return d&&"number"==typeof d.count&&"number"==typeof d.cssFailedCount?(d.count+=1,S.catch(function(u){var S,p,R,m,E,U,g=d.count-1,v=d.cssFailedCount,L=!!(null==u||null==(S=u.message)?void 0:S.includes("CSS chunk"));L&&(d.cssFailedCount+=1);var N=L?v:g-v;try{var A=function(n,r,u){var f,y,d,S=u?null==(f=_[n])?void 0:f[r]:null==(y=o[n])?void 0:y[r],p=r+1;if(0===r||void 0===S){if(!(d=function(n,r){var o,_=r?s(n):c(n);if(!_)throw Error("only support cssExtract");var a=__RUNTIME_GLOBALS_PUBLIC_PATH__,l="/"===a[0]&&"/"!==a[1]?window.origin+a+_:a+_,u=(o=l.split("?")[1])?"?".concat(o.split("#")[0]):"",f=function(n,r,t){for(var i=0;i<t.length;i++){var o,_=t[i],a=_.test,l=!0;if((null!=(o=RegExp)&&"undefined"!=typeof Symbol&&o[Symbol.hasInstance]?!!o[Symbol.hasInstance](a):a instanceof o)?l=a.test(n):"string"==typeof a?l=new RegExp(a).test(n):"function"==typeof a&&(l=a(n)),_.domain&&_.domain.length>0){var u=e(n,_);_.domain.includes(u)||(l=!1)}if(_.type&&_.type.length>0&&!_.type.includes(r)&&(l=!1),l)return _}return null}(l,r?"link":"script",i);if(!f)return null;var y=e(l,f);return{nextDomain:y,nextRetryUrl:t(l,y,y,0,u,f),originalScriptFilename:_,originalSrcUrl:l,originalQuery:u,rule:f}}(n,u)))return null;u?_[n]=[]:o[n]=[]}else{var R,m,E,U,g=S.originalScriptFilename,v=S.originalSrcUrl,L=S.originalQuery,N=S.rule,A=(R=S.nextDomain,m=N.domain,E=e(R,N),-1===(U=m.indexOf(E))?E:m[(U+1)%m.length]);d={nextDomain:A,nextRetryUrl:t(S.nextRetryUrl,S.nextDomain,A,r,L,N),originalScriptFilename:g,originalSrcUrl:v,originalQuery:L,rule:N}}return u?(_[n][p]=d,l[n]=d):(o[n][p]=d,a[n]=d),d}(r,N,L);if(!A)throw u;p=A.originalScriptFilename,R=A.nextRetryUrl,m=A.nextDomain,E=A.rule}catch(e){throw e!==u&&console.error(n,"failed to get nextRetryUrl",e),u}var C=function(n){return{times:n,domain:m,url:R,tagName:L?"link":"script",isAsyncChunk:!0}},I=C(N);if(N>=E.max)throw u.message=(null==(U=u.message)?void 0:U.includes("retries:"))?u.message:"Loading chunk ".concat(r,' from "').concat(p,'" failed after ').concat(E.max,' retries: "').concat(u.message,'"'),"function"==typeof E.onFail&&E.onFail(I),u;"function"==typeof E.onRetry&&E.onRetry(I);var T="function"==typeof E.delay?E.delay(I):E.delay;return(T>0?new Promise(function(n){return setTimeout(n,T)}):Promise.resolve()).then(function(){return y.apply(y,f)}).then(function(n){var e=(null==d?void 0:d.count)===g+2;if("function"==typeof E.onSuccess&&e){var r=C(N+1);E.onSuccess(r)}return n})})):S}if("undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={}),"undefined"!=typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=y,__RUNTIME_GLOBALS_LOAD_SCRIPT__=function(){var n=Array.prototype.slice.call(arguments),e=a[n[3]];return e&&(n[0]=e.nextRetryUrl),f.apply(null,n)},__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=function(n,e){var r=l[e];return r&&r.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+n}}catch(e){console.error(n,"Register async chunk retry runtime failed",e)}}();
|
|
@@ -94,11 +94,6 @@
|
|
|
94
94
|
}
|
|
95
95
|
function createElement(origin, attributes) {
|
|
96
96
|
var crossOrigin = true === attributes.crossOrigin ? 'anonymous' : attributes.crossOrigin;
|
|
97
|
-
var crossOriginAttr = crossOrigin ? 'crossorigin="'.concat(crossOrigin, '"') : '';
|
|
98
|
-
var retryTimesAttr = attributes.times ? 'data-rb-retry-times="'.concat(attributes.times, '"') : '';
|
|
99
|
-
var originalQueryAttr = attributes.originalQuery ? 'data-rb-original-query="'.concat(attributes.originalQuery, '"') : '';
|
|
100
|
-
var ruleIndexAttr = attributes.ruleIndex >= 0 ? 'data-rb-rule-i="'.concat(attributes.ruleIndex, '"') : '';
|
|
101
|
-
var isAsyncAttr = attributes.isAsync ? 'data-rb-async' : '';
|
|
102
97
|
if (initialChunkRetry_instanceof(origin, HTMLScriptElement)) {
|
|
103
98
|
var script = document.createElement("script");
|
|
104
99
|
script.src = attributes.url;
|
|
@@ -107,10 +102,7 @@
|
|
|
107
102
|
if (attributes.isAsync) script.dataset.rbAsync = '';
|
|
108
103
|
if (void 0 !== attributes.originalQuery) script.dataset.rbOriginalQuery = attributes.originalQuery;
|
|
109
104
|
if (attributes.ruleIndex >= 0) script.dataset.rbRuleI = String(attributes.ruleIndex);
|
|
110
|
-
return
|
|
111
|
-
element: script,
|
|
112
|
-
str: '<script src="'.concat(attributes.url, '" ').concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(isAsyncAttr, " ").concat(ruleIndexAttr, " ").concat(originalQueryAttr, ">") + "<\/script>"
|
|
113
|
-
};
|
|
105
|
+
return script;
|
|
114
106
|
}
|
|
115
107
|
if (initialChunkRetry_instanceof(origin, HTMLLinkElement)) {
|
|
116
108
|
var link = document.createElement('link');
|
|
@@ -120,16 +112,13 @@
|
|
|
120
112
|
if (crossOrigin) link.crossOrigin = crossOrigin;
|
|
121
113
|
if (attributes.times) link.dataset.rbRetryTimes = String(attributes.times);
|
|
122
114
|
if (void 0 !== attributes.originalQuery) link.dataset.rbOriginalQuery = attributes.originalQuery;
|
|
123
|
-
return
|
|
124
|
-
element: link,
|
|
125
|
-
str: '<link rel="'.concat(link.rel, '" href="').concat(attributes.url, '" ').concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(link.as ? 'as="'.concat(link.as, '"') : '', " ").concat(ruleIndexAttr, " ").concat(originalQueryAttr, "></link>")
|
|
126
|
-
};
|
|
115
|
+
return link;
|
|
127
116
|
}
|
|
128
117
|
}
|
|
129
|
-
function reloadElementResource(origin,
|
|
130
|
-
if (initialChunkRetry_instanceof(origin, HTMLScriptElement)) if (attributes.isAsync) document.body.appendChild(
|
|
118
|
+
function reloadElementResource(origin, freshElement, attributes) {
|
|
119
|
+
if (initialChunkRetry_instanceof(origin, HTMLScriptElement)) if (attributes.isAsync) document.body.appendChild(freshElement);
|
|
131
120
|
else console.warn(ERROR_PREFIX, "load sync script failed, for security only async/defer script can be retried", origin);
|
|
132
|
-
if (initialChunkRetry_instanceof(origin, HTMLLinkElement)) document.getElementsByTagName('head')[0].appendChild(
|
|
121
|
+
if (initialChunkRetry_instanceof(origin, HTMLLinkElement)) document.getElementsByTagName('head')[0].appendChild(freshElement);
|
|
133
122
|
if (initialChunkRetry_instanceof(origin, HTMLImageElement)) {
|
|
134
123
|
origin.src = attributes.url;
|
|
135
124
|
origin.dataset.rbRetryTimes = String(attributes.times);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function e(e,
|
|
1
|
+
!function(){"use strict";function e(e,r){for(var n=r.domain,t=0;t<n.length;t++){var i=n[t];if(-1!==e.indexOf(i))return i}return window.origin}var r=/[?#].*$/;function n(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}var t={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement};function i(r,i){var a=i.target,o=a.tagName.toLocaleLowerCase(),s=n(a,HTMLScriptElement)||n(a,HTMLImageElement)?a.src:n(a,HTMLLinkElement)?a.href:null;if(!s)return!1;var u=Number(a.dataset.rbRuleI||"-1"),l=r[u]||function(r,n,t){for(var i=0;i<t.length;i++){var a,o=t[i],s=o.test,u=!0;if((null!=(a=RegExp)&&"undefined"!=typeof Symbol&&a[Symbol.hasInstance]?!!a[Symbol.hasInstance](s):s instanceof a)?u=s.test(r):"string"==typeof s?u=new RegExp(s).test(r):"function"==typeof s&&(u=s(r)),o.domain&&o.domain.length>0){var l=e(r,o);o.domain.includes(l)||(u=!1)}if(o.type&&o.type.length>0&&!o.type.includes(n)&&(u=!1),u)return o}return null}(s,o,r);if(!l)return!1;u=r.indexOf(l);var c=l.type;return!!o&&-1!==c.indexOf(o)&&!!t[o]&&!!n(a,t[o])&&{target:a,tagName:o,url:s,rule:l,ruleIndex:u}}function a(e,r,t){n(e,HTMLScriptElement)&&(t.isAsync?document.body.appendChild(r):console.warn("[@rsbuild/plugin-assets-retry] ","load sync script failed, for security only async/defer script can be retried",e)),n(e,HTMLLinkElement)&&document.getElementsByTagName("head")[0].appendChild(r),n(e,HTMLImageElement)&&(e.src=t.url,e.dataset.rbRetryTimes=t.times+"",e.dataset.rbOriginalQuery=t.originalQuery+"")}"undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={});try{var o=__RETRY_OPTIONS__;"undefined"!=typeof window&&void 0!==window.document&&(document.addEventListener("error",function(t){if(t&&n(t.target,Element))try{!function(t,o){var s,u=i(t,o);if(!1!==u){var l=u.target,c=u.tagName,d=u.url,m=u.rule,y=u.ruleIndex;if(!("undefined"!=typeof window&&Object.keys(window.__RB_ASYNC_CHUNKS__||{}).some(function(e){return -1!==d.indexOf(e)}))){var f,g,p,b,v,_=e(d,m),h=Number(l.dataset.rbRetryTimes)||0;if(h===m.max){"function"==typeof m.onFail&&m.onFail({times:h,domain:_,url:d,tagName:c,isAsyncChunk:!1});return}var E=(g=m.domain,p=e(_,m),-1===(b=g.indexOf(p))?p:g[(b+1)%g.length]),T=null!=(s=l.dataset.rbOriginalQuery)?s:(v=d.split("?")[1])?"?".concat(v.split("#")[0]):"",w=!!l.dataset.rbAsync||l.async||l.defer,L={url:d.replace(_,E).replace(r,"")+(f=h+1,!0===m.addQuery?""!==T?"".concat(T,"&retry=").concat(f):"?retry=".concat(f):"function"==typeof m.addQuery?m.addQuery({times:f,originalQuery:T}):""),times:h+1,originalQuery:T,ruleIndex:y,crossOrigin:m.crossOrigin,isAsync:w},S=function(e,r){var t=!0===r.crossOrigin?"anonymous":r.crossOrigin;if(n(e,HTMLScriptElement)){var i=document.createElement("script");return i.src=r.url,t&&(i.crossOrigin=t),r.times&&(i.dataset.rbRetryTimes=r.times+""),r.isAsync&&(i.dataset.rbAsync=""),void 0!==r.originalQuery&&(i.dataset.rbOriginalQuery=r.originalQuery),r.ruleIndex>=0&&(i.dataset.rbRuleI=r.ruleIndex+""),i}if(n(e,HTMLLinkElement)){var a=document.createElement("link");return a.rel=e.rel||"stylesheet",e.as&&(a.as=e.as),a.href=r.url,t&&(a.crossOrigin=t),r.times&&(a.dataset.rbRetryTimes=r.times+""),void 0!==r.originalQuery&&(a.dataset.rbOriginalQuery=r.originalQuery),a}}(l,L),N={times:h,domain:_,url:d,tagName:c,isAsyncChunk:!1};"function"==typeof m.onRetry&&m.onRetry(N);var O="function"==typeof m.delay?m.delay(N):m.delay;O>0?setTimeout(function(){a(l,S,L)},O):a(l,S,L)}}}(o,t)}catch(e){console.error("retry error captured",e)}},!0),document.addEventListener("load",function(r){if(r&&n(r.target,Element))try{!function(r,n){var t=i(r,n);if(!1!==t){var a=t.target,o=t.tagName,s=t.url,u=t.rule,l=e(s,u),c=Number(a.dataset.rbRetryTimes)||0;0!==c&&"function"==typeof u.onSuccess&&u.onSuccess({times:c,domain:l,url:s,tagName:o,isAsyncChunk:!1})}}(o,r)}catch(e){console.error("load error captured",e)}},!0))}catch(e){console.error("monitor error captured",e)}}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-assets-retry",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-assets-retry",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,23 +28,23 @@
|
|
|
28
28
|
"pre-commit": "npm run lint:write"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@microsoft/api-extractor": "^7.52.
|
|
31
|
+
"@microsoft/api-extractor": "^7.52.10",
|
|
32
32
|
"@biomejs/biome": "^1.9.4",
|
|
33
|
-
"@playwright/test": "^1.
|
|
34
|
-
"@rsbuild/core": "^1.
|
|
35
|
-
"@rsbuild/plugin-react": "^1.3.
|
|
36
|
-
"@rslib/core": "^0.
|
|
37
|
-
"@swc/core": "^1.
|
|
38
|
-
"@types/node": "^22.
|
|
39
|
-
"@types/react": "^19.1.
|
|
40
|
-
"@types/react-dom": "^19.1.
|
|
33
|
+
"@playwright/test": "^1.54.1",
|
|
34
|
+
"@rsbuild/core": "^1.5.0-beta.1",
|
|
35
|
+
"@rsbuild/plugin-react": "^1.3.4",
|
|
36
|
+
"@rslib/core": "^0.11.0",
|
|
37
|
+
"@swc/core": "^1.13.3",
|
|
38
|
+
"@types/node": "^22.17.0",
|
|
39
|
+
"@types/react": "^19.1.9",
|
|
40
|
+
"@types/react-dom": "^19.1.7",
|
|
41
41
|
"@types/serialize-javascript": "^5.0.4",
|
|
42
|
-
"playwright": "^1.
|
|
43
|
-
"react": "^19.1.
|
|
44
|
-
"react-dom": "^19.1.
|
|
42
|
+
"playwright": "^1.54.1",
|
|
43
|
+
"react": "^19.1.1",
|
|
44
|
+
"react-dom": "^19.1.1",
|
|
45
45
|
"serialize-javascript": "^6.0.2",
|
|
46
|
-
"simple-git-hooks": "^2.13.
|
|
47
|
-
"typescript": "^5.
|
|
46
|
+
"simple-git-hooks": "^2.13.1",
|
|
47
|
+
"typescript": "^5.9.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@rsbuild/core": "1.x"
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"optional": true
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
"packageManager": "pnpm@10.
|
|
57
|
+
"packageManager": "pnpm@10.14.0",
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|
|
60
60
|
"registry": "https://registry.npmjs.org/"
|