@rsbuild/plugin-assets-retry 1.2.2 → 1.2.3
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
|
@@ -297,7 +297,7 @@ var __webpack_exports__ = {};
|
|
|
297
297
|
const { inlineScript = true } = userOptions;
|
|
298
298
|
const getScriptPath = (environment)=>{
|
|
299
299
|
const distDir = environment.config.output.distPath.js;
|
|
300
|
-
return external_node_path_default().posix.join(distDir, "assets-retry.1-2-
|
|
300
|
+
return external_node_path_default().posix.join(distDir, "assets-retry.1-2-3.js");
|
|
301
301
|
};
|
|
302
302
|
const formatOptions = (config)=>{
|
|
303
303
|
const options = {
|
package/dist/index.js
CHANGED
|
@@ -273,7 +273,7 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
273
273
|
const { inlineScript = true } = userOptions;
|
|
274
274
|
const getScriptPath = (environment)=>{
|
|
275
275
|
const distDir = environment.config.output.distPath.js;
|
|
276
|
-
return node_path.posix.join(distDir, "assets-retry.1-2-
|
|
276
|
+
return node_path.posix.join(distDir, "assets-retry.1-2-3.js");
|
|
277
277
|
};
|
|
278
278
|
const formatOptions = (config)=>{
|
|
279
279
|
const options = {
|
|
@@ -30,16 +30,18 @@ function findNextDomain(url, domains) {
|
|
|
30
30
|
}
|
|
31
31
|
function getRequestUrl(element) {
|
|
32
32
|
if (_instanceof(element, HTMLScriptElement) || _instanceof(element, HTMLImageElement)) {
|
|
33
|
+
var _element_getAttribute;
|
|
33
34
|
// For <script src="" /> or <img src="" />
|
|
34
35
|
// element.getAttribute('src') === '' but element.src === baseURI
|
|
35
|
-
if (!element.getAttribute('src')) {
|
|
36
|
+
if (!((_element_getAttribute = element.getAttribute('src')) === null || _element_getAttribute === void 0 ? void 0 : _element_getAttribute.trim())) {
|
|
36
37
|
return null;
|
|
37
38
|
}
|
|
38
39
|
return element.src;
|
|
39
40
|
}
|
|
40
41
|
if (_instanceof(element, HTMLLinkElement)) {
|
|
42
|
+
var _element_getAttribute1;
|
|
41
43
|
// For <link href="" />
|
|
42
|
-
if (!element.getAttribute('href')) {
|
|
44
|
+
if (!((_element_getAttribute1 = element.getAttribute('href')) === null || _element_getAttribute1 === void 0 ? void 0 : _element_getAttribute1.trim())) {
|
|
43
45
|
return null;
|
|
44
46
|
}
|
|
45
47
|
return element.href;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}var t={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement};function n(e,t){for(var n="",r=0;r<t.length;r++)if(-1!==e.indexOf(t[r])){n=t[r];break}return n||window.origin}function r(n,r){var i,a=r.target,
|
|
1
|
+
function e(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}var t={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement};function n(e,t){for(var n="",r=0;r<t.length;r++)if(-1!==e.indexOf(t[r])){n=t[r];break}return n||window.origin}function r(n,r){var i,a,o,c=r.target,s=c.tagName.toLocaleLowerCase(),l=n.type,u=e(i=c,HTMLScriptElement)||e(i,HTMLImageElement)?(null==(a=i.getAttribute("src"))?void 0:a.trim())?i.src:null:e(i,HTMLLinkElement)?(null==(o=i.getAttribute("href"))?void 0:o.trim())?i.href:null:null;return!!s&&-1!==l.indexOf(s)&&!!t[s]&&!!e(c,t[s])&&!!u&&{target:c,tagName:s,url:u}}var i=/[?#].*$/;function a(t,n,r){e(t,HTMLScriptElement)&&(r.isAsync?document.body.appendChild(n.element):document.write(n.str)),e(t,HTMLLinkElement)&&document.getElementsByTagName("head")[0].appendChild(n.element),e(t,HTMLImageElement)&&(t.src=r.url,t.dataset.rbRetryTimes=String(r.times),t.dataset.rbOriginalQuery=String(r.originalQuery))}"undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={});try{var o,c,s=__RUNTIME_GLOBALS_OPTIONS__;o=function(t){try{!function(t,o){var c,s,l=r(t,o);if(!1!==l){var u=l.target,d=l.tagName,m=l.url;if(!("undefined"!=typeof window&&Object.keys(window.__RB_ASYNC_CHUNKS__||{}).some(function(e){return -1!==m.indexOf(e)}))){var y=t.test;if(y){if("string"==typeof y){var f=new RegExp(y);y=function(e){return f.test(e)}}if("function"!=typeof y||!y(m))return}var g=n(m,t.domain);if(!t.domain||!(t.domain.length>0)||-1!==t.domain.indexOf(g)){var p,v,b,_,L,S,E,T,h,w=Number(u.dataset.rbRetryTimes)||0;if(w===t.max){"function"==typeof t.onFail&&t.onFail({times:w,domain:g,url:m,tagName:d,isAsyncChunk:!1});return}var O=(E=n(g,S=t.domain),T=S.indexOf(E),S[(T+1)%S.length]||g),N=null!=(c=u.dataset.rbOriginalQuery)?c:(h=m.split("?")[1])?"?".concat(h.split("#")[0]):"",Q=!!u.dataset.rbAsync||u.async||u.defer,A={url:(p=m,v=g,b=O,_=w,p.replace(v,b).replace(i,"")+(L=_+1,!0===t.addQuery?""!==N?"".concat(N,"&retry=").concat(L):"?retry=".concat(L):"function"==typeof t.addQuery?t.addQuery({times:L,originalQuery:N}):"")),times:w+1,crossOrigin:t.crossOrigin,isAsync:Q,originalQuery:N},H=function(t,n){var r=!0===n.crossOrigin?"anonymous":n.crossOrigin,i=r?'crossorigin="'.concat(r,'"'):"",a=n.times?'data-rb-retry-times="'.concat(n.times,'"'):"",o=n.originalQuery?'data-rb-original-query="'.concat(n.originalQuery,'"'):"",c=n.isAsync?"data-rb-async":"";if(e(t,HTMLScriptElement)){var s=document.createElement("script");return s.src=n.url,r&&(s.crossOrigin=r),n.times&&(s.dataset.rbRetryTimes=String(n.times)),n.isAsync&&(s.dataset.rbAsync=""),void 0!==n.originalQuery&&(s.dataset.rbOriginalQuery=n.originalQuery),{element:s,str:'<script src="'.concat(n.url,'" ').concat(i," ").concat(a," ").concat(c," ").concat(o,">")+"<\/script>"}}if(e(t,HTMLLinkElement)){var l=document.createElement("link");return l.rel=t.rel||"stylesheet",t.as&&(l.as=t.as),l.href=n.url,r&&(l.crossOrigin=r),n.times&&(l.dataset.rbRetryTimes=String(n.times)),void 0!==n.originalQuery&&(l.dataset.rbOriginalQuery=n.originalQuery),{element:l,str:'<link rel="'.concat(l.rel,'" href="').concat(n.url,'" ').concat(i," ").concat(a," ").concat(l.as?'as="'.concat(l.as,'"'):""," ").concat(o,"></link>")}}}(u,A),k={times:w,domain:g,url:m,tagName:d,isAsyncChunk:!1};"function"==typeof t.onRetry&&t.onRetry(k);var C="function"==typeof t.delay?t.delay(k):null!=(s=t.delay)?s:0;C>0?setTimeout(function(){a(u,H,A)},C):a(u,H,A)}}}}(s,t)}catch(e){console.error("retry error captured",e)}},c=function(e){try{!function(e,t){var i=r(e,t);if(!1!==i){var a=i.target,o=i.tagName,c=i.url,s=n(c,e.domain),l=Number(a.dataset.rbRetryTimes)||0;0!==l&&"function"==typeof e.onSuccess&&e.onSuccess({times:l,domain:s,url:c,tagName:o,isAsyncChunk:!1})}}(s,e)}catch(e){console.error("load error captured",e)}},"undefined"!=typeof window&&void 0!==window.document&&(document.addEventListener("error",function(t){t&&e(t.target,Element)&&o(t)},!0),document.addEventListener("load",function(t){t&&e(t.target,Element)&&c(t)},!0))}catch(e){console.error("monitor error captured",e)}
|