@rsbuild/plugin-assets-retry 0.6.2 → 0.6.4
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.js +1 -1
- package/dist/index.mjs +3 -3
- package/dist/runtime.js +15 -2
- package/dist/runtime.min.js +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -34,12 +34,12 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
34
34
|
return value;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
// ../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
37
|
+
// ../../node_modules/.pnpm/@modern-js+module-tools@2.49.0_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js
|
|
38
38
|
import { fileURLToPath } from "url";
|
|
39
39
|
import path from "path";
|
|
40
40
|
var getFilename, getDirname, __dirname;
|
|
41
41
|
var init_esm = __esm({
|
|
42
|
-
"../../node_modules/.pnpm/@modern-js+module-tools@2.
|
|
42
|
+
"../../node_modules/.pnpm/@modern-js+module-tools@2.49.0_eslint@8.57.0_typescript@5.4.5/node_modules/@modern-js/module-tools/shims/esm.js"() {
|
|
43
43
|
"use strict";
|
|
44
44
|
getFilename = () => fileURLToPath(import.meta.url);
|
|
45
45
|
getDirname = () => path.dirname(getFilename());
|
|
@@ -103,7 +103,7 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
103
103
|
if (!this.scriptPath) {
|
|
104
104
|
this.scriptPath = path2.posix.join(
|
|
105
105
|
this.distDir,
|
|
106
|
-
`assets-retry.${"0.6.
|
|
106
|
+
`assets-retry.${"0.6.4"}.js`
|
|
107
107
|
);
|
|
108
108
|
}
|
|
109
109
|
return this.scriptPath;
|
package/dist/runtime.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
// rsbuild/initial-chunk/retry
|
|
4
|
+
|
|
3
5
|
var TAG_TYPE = {
|
|
4
6
|
link: HTMLLinkElement,
|
|
5
7
|
script: HTMLScriptElement,
|
|
@@ -70,7 +72,9 @@ function createElement(origin, attributes) {
|
|
|
70
72
|
}
|
|
71
73
|
return {
|
|
72
74
|
element: script,
|
|
73
|
-
str:
|
|
75
|
+
str:
|
|
76
|
+
// biome-ignore lint/style/useTemplate: use "</" + "script>" instead of script tag to avoid syntax error when inlining in html
|
|
77
|
+
"<script src=\"".concat(attributes.url, "\" ").concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(isAsyncAttr, ">") + '</' + 'script>'
|
|
74
78
|
};
|
|
75
79
|
}
|
|
76
80
|
if (origin instanceof HTMLLinkElement) {
|
|
@@ -210,7 +214,16 @@ function resourceMonitor(error, success) {
|
|
|
210
214
|
|
|
211
215
|
// @ts-expect-error init is a global function, ignore ts(6133)
|
|
212
216
|
function init(options) {
|
|
213
|
-
var config =
|
|
217
|
+
var config = {};
|
|
218
|
+
for (var key in defaultConfig) {
|
|
219
|
+
// @ts-ignore
|
|
220
|
+
config[key] = defaultConfig[key];
|
|
221
|
+
}
|
|
222
|
+
for (var _key in options) {
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
config[_key] = options[_key];
|
|
225
|
+
}
|
|
226
|
+
|
|
214
227
|
// Normalize config
|
|
215
228
|
if (!Array.isArray(config.type) || config.type.length === 0) {
|
|
216
229
|
config.type = defaultConfig.type;
|
package/dist/runtime.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var TAG_TYPE={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement},TYPES=Object.keys(TAG_TYPE);function findCurrentDomain(e,t){for(var n="",r=0;r<t.length;r++)if(-1!==e.indexOf(t[r])){n=t[r];break}return n||e}function findNextDomain(e,t){var n=findCurrentDomain(e,t),r=t.indexOf(n);return t[(r+1)%t.length]||e}function getRequestUrl(e){return e instanceof HTMLScriptElement||e instanceof HTMLImageElement?e.src:e instanceof HTMLLinkElement?e.href:null}var defaultConfig={max:3,type:TYPES,domain:[],crossOrigin:!1};function validateTargetInfo(e,t){var n,r=t.target,i=null===(n=r.tagName)||void 0===n?void 0:n.toLocaleLowerCase(),a=e.type,o=getRequestUrl(r);return!!(i&&-1!==a.indexOf(i)&&TAG_TYPE[i]&&r instanceof TAG_TYPE[i]&&o)&&{target:r,tagName:i,url:o}}function createElement(e,t){var n=!0===t.crossOrigin?"anonymous":t.crossOrigin,r=n?'crossorigin="'.concat(n,'"'):"",i=t.times?'data-rsbuild-retry-times="'.concat(t.times,'"'):"",a=t.isAsync?"data-rsbuild-async":"";if(e instanceof HTMLScriptElement){var o=document.createElement("script");return o.src=t.url,n&&(o.crossOrigin=n),t.times&&(o.dataset.rsbuildRetryTimes=String(t.times)),t.isAsync&&(o.dataset.rsbuildAsync=""),{element:o,str:'<script src="'.concat(t.url,'" ').concat(r," ").concat(i," ").concat(a,"
|
|
1
|
+
"use strict";var TAG_TYPE={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement},TYPES=Object.keys(TAG_TYPE);function findCurrentDomain(e,t){for(var n="",r=0;r<t.length;r++)if(-1!==e.indexOf(t[r])){n=t[r];break}return n||e}function findNextDomain(e,t){var n=findCurrentDomain(e,t),r=t.indexOf(n);return t[(r+1)%t.length]||e}function getRequestUrl(e){return e instanceof HTMLScriptElement||e instanceof HTMLImageElement?e.src:e instanceof HTMLLinkElement?e.href:null}var defaultConfig={max:3,type:TYPES,domain:[],crossOrigin:!1};function validateTargetInfo(e,t){var n,r=t.target,i=null===(n=r.tagName)||void 0===n?void 0:n.toLocaleLowerCase(),a=e.type,o=getRequestUrl(r);return!!(i&&-1!==a.indexOf(i)&&TAG_TYPE[i]&&r instanceof TAG_TYPE[i]&&o)&&{target:r,tagName:i,url:o}}function createElement(e,t){var n=!0===t.crossOrigin?"anonymous":t.crossOrigin,r=n?'crossorigin="'.concat(n,'"'):"",i=t.times?'data-rsbuild-retry-times="'.concat(t.times,'"'):"",a=t.isAsync?"data-rsbuild-async":"";if(e instanceof HTMLScriptElement){var o=document.createElement("script");return o.src=t.url,n&&(o.crossOrigin=n),t.times&&(o.dataset.rsbuildRetryTimes=String(t.times)),t.isAsync&&(o.dataset.rsbuildAsync=""),{element:o,str:'<script src="'.concat(t.url,'" ').concat(r," ").concat(i," ").concat(a,">")+"<\/script>"}}if(e instanceof HTMLLinkElement){var s=document.createElement("link");return s.rel=e.rel||"stylesheet",e.as&&(s.as=e.as),s.href=t.url,n&&(s.crossOrigin=n),t.times&&(s.dataset.rsbuildRetryTimes=String(t.times)),{element:s,str:'<link rel="'.concat(s.rel,'" href="').concat(t.url,'" ').concat(r," ").concat(i," ").concat(s.as?'as="'.concat(s.as,'"'):"","></link>")}}}function reloadElementResource(e,t,n){e instanceof HTMLScriptElement&&(n.isAsync?document.body.appendChild(t.element):document.write(t.str)),e instanceof HTMLLinkElement&&document.getElementsByTagName("head")[0].appendChild(t.element),e instanceof HTMLImageElement&&(e.src=n.url,e.dataset.rsbuildRetryTimes=String(n.times))}function retry(e,t){var n=validateTargetInfo(e,t);if(!1!==n){var r=n.target,i=n.tagName,a=n.url,o=e.test;if(o){if("string"==typeof o){var s=new RegExp(o);o=function(e){return s.test(e)}}if("function"!=typeof o||!o(a))return}var c=findCurrentDomain(a,e.domain);if(!(e.domain&&e.domain.length>0&&-1===e.domain.indexOf(c))){var l=Number(r.dataset.rsbuildRetryTimes)||0;if(l!==e.max){var m=findNextDomain(c,e.domain),d=Boolean(r.dataset.rsbuildAsync)||r.async||r.defer,u={url:a.replace(c,m),times:l+1,crossOrigin:e.crossOrigin,isAsync:d},f=createElement(r,u);if(e.onRetry&&"function"==typeof e.onRetry){var g={times:l,domain:c,url:a,tagName:i};e.onRetry(g)}reloadElementResource(r,f,u)}else if("function"==typeof e.onFail){var y={times:l,domain:c,url:a,tagName:i};e.onFail(y)}}}}function load(e,t){var n=validateTargetInfo(e,t);if(!1!==n){var r=n.target,i=n.tagName,a=n.url,o=findCurrentDomain(a,e.domain),s=Number(r.dataset.rsbuildRetryTimes)||0;if(0!==s&&"function"==typeof e.onSuccess){var c={times:s,domain:o,url:a,tagName:i};e.onSuccess(c)}}}function resourceMonitor(e,t){"undefined"!=typeof window&&void 0!==window.document&&(document.addEventListener("error",(function(t){t&&t.target instanceof Element&&e(t)}),!0),document.addEventListener("load",(function(e){e&&e.target instanceof Element&&t(e)}),!0))}function init(e){var t={};for(var n in defaultConfig)t[n]=defaultConfig[n];for(var r in e)t[r]=e[r];Array.isArray(t.type)&&0!==t.type.length||(t.type=defaultConfig.type),Array.isArray(t.domain)&&0!==t.domain.length||(t.domain=defaultConfig.domain),Array.isArray(t.domain)&&(t.domain=t.domain.filter(Boolean));try{resourceMonitor((function(e){try{retry(t,e)}catch(e){console.error("retry error captured",e)}}),(function(e){try{load(t,e)}catch(e){console.error("load error captured",e)}}))}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": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Assets retry plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"serialize-javascript": "^6.0.2",
|
|
27
|
-
"@rsbuild/shared": "0.6.
|
|
27
|
+
"@rsbuild/shared": "0.6.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.24.4",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"@babel/preset-typescript": "^7.24.1",
|
|
33
33
|
"@types/serialize-javascript": "^5.0.4",
|
|
34
34
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
|
|
35
|
-
"terser": "5.
|
|
35
|
+
"terser": "5.30.3",
|
|
36
36
|
"typescript": "^5.4.2",
|
|
37
|
-
"@rsbuild/core": "0.6.
|
|
38
|
-
"@scripts/test-helper": "0.6.
|
|
37
|
+
"@rsbuild/core": "0.6.4",
|
|
38
|
+
"@scripts/test-helper": "0.6.4"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@rsbuild/core": "^0.6.
|
|
41
|
+
"@rsbuild/core": "^0.6.4"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public",
|