@rsbuild/plugin-assets-retry 1.4.1 → 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/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.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;
|
|
@@ -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,r){for(var n=r.domain,t=0;t<n.length;t++){var
|
|
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",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@microsoft/api-extractor": "^7.52.10",
|
|
32
32
|
"@biomejs/biome": "^1.9.4",
|
|
33
33
|
"@playwright/test": "^1.54.1",
|
|
34
|
-
"@rsbuild/core": "^1.
|
|
34
|
+
"@rsbuild/core": "^1.5.0-beta.1",
|
|
35
35
|
"@rsbuild/plugin-react": "^1.3.4",
|
|
36
36
|
"@rslib/core": "^0.11.0",
|
|
37
37
|
"@swc/core": "^1.13.3",
|