@rsbuild/plugin-assets-retry 2.0.0 → 2.0.1

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 CHANGED
@@ -276,7 +276,7 @@ const pluginAssetsRetry = (userOptions = {})=>({
276
276
  const { inlineScript = true } = userOptions;
277
277
  const getScriptPath = (environment)=>{
278
278
  const distDir = environment.config.output.distPath.js;
279
- return node_path.posix.join(distDir, "assets-retry.2-0-0.js");
279
+ return node_path.posix.join(distDir, "assets-retry.2-0-1.js");
280
280
  };
281
281
  const getDefaultValueFromRsbuildConfig = (config)=>{
282
282
  const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
@@ -124,7 +124,7 @@
124
124
  cssFailedCount: 0
125
125
  };
126
126
  const callingCounter = args[10];
127
- const result = originalEnsureChunk.apply(null, args);
127
+ const result = originalEnsureChunk(...args);
128
128
  try {
129
129
  const originalScriptFilename = originalGetChunkScriptFilename(chunkId);
130
130
  const originalCssFilename = originalGetCssFilename(chunkId);
@@ -191,7 +191,7 @@
191
191
  const args = Array.prototype.slice.call(arguments);
192
192
  const retry = globalCurrRetrying[args[3]];
193
193
  if (retry) args[0] = retry.nextRetryUrl;
194
- return originalLoadScript.apply(null, args);
194
+ return originalLoadScript(...args);
195
195
  }
196
196
  function loadStyleSheet(href, chunkId) {
197
197
  const retry = globalCurrRetryingCss[chunkId];
@@ -1 +1 @@
1
- (()=>{let e="[@rsbuild/plugin-assets-retry] ";function t(e,t){let n=t.domain;for(let t=0;t<n.length;t++){let r=n[t];if(-1!==e.indexOf(r))return r}return window.origin}let n=/[?#].*$/;function r(e,t,r,_,l,o){var i;return e.replace(t,r).replace(n,"")+(i=_+1,!0===o.addQuery?""!==l?`${l}&retry=${i}`:"?retry="+i:"function"==typeof o.addQuery?o.addQuery({times:i,originalQuery:l}):"")}let _=__RETRY_OPTIONS__,l={},o={},i={},u={},a=__RUNTIME_GLOBALS_ENSURE_CHUNK__,c=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,s=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||(()=>null),f=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function y(n){let f=Array.prototype.slice.call(arguments);f[10]||(f[10]={count:0,cssFailedCount:0});let d=f[10],S=a.apply(null,f);try{let e=c(n),t=s(n);"u">typeof window&&(e&&(window.__RB_ASYNC_CHUNKS__[e]=!0),t&&(window.__RB_ASYNC_CHUNKS__[t]=!0))}catch(t){console.error(e,"get original script or CSS filename error",t)}return d&&"number"==typeof d.count&&"number"==typeof d.cssFailedCount?(d.count+=1,S.catch(a=>{var S,p;let R,E,L,U,N=d.count-1,m=d.cssFailedCount,A=!!(null==a||null==(S=a.message)?void 0:S.includes("CSS chunk"));A&&(d.cssFailedCount+=1);let C=A?m:N-m;try{let e=function(e,n,a){var f,y,d;let S,p=a?null==(f=o[e])?void 0:f[n]:null==(y=l[e])?void 0:y[n],R=n+1;if(0===n||void 0===p){if(!(S=function(e,n){let l,o=n?s(e):c(e);if(!o)throw Error("only support cssExtract");let i=__RUNTIME_GLOBALS_PUBLIC_PATH__,u="/"===i[0]&&"/"!==i[1]?window.origin+i+o:i+o,a=(l=u.split("?")[1])?"?"+l.split("#")[0]:"",f=function(e,n,r){for(let _=0;_<r.length;_++){let l=r[_],o=l.test,i=!0;if(o instanceof RegExp?i=o.test(e):"string"==typeof o?i=new RegExp(o).test(e):"function"==typeof o&&(i=o(e)),l.domain&&l.domain.length>0){let n=t(e,l);l.domain.includes(n)||(i=!1)}if(l.type&&l.type.length>0&&!l.type.includes(n)&&(i=!1),i)return l}return null}(u,n?"link":"script",_);if(!f)return null;let y=t(u,f);return{nextDomain:y,nextRetryUrl:r(u,y,y,0,a,f),originalScriptFilename:o,originalSrcUrl:u,originalQuery:a,rule:f}}(e,a)))return null;a?o[e]=[]:l[e]=[]}else{let e,_,l,{originalScriptFilename:o,originalSrcUrl:i,originalQuery:u,rule:a}=p,c=(d=p.nextDomain,e=a.domain,_=t(d,a),l=e.indexOf(_),-1===l?_:e[(l+1)%e.length]);S={nextDomain:c,nextRetryUrl:r(p.nextRetryUrl,p.nextDomain,c,n,u,a),originalScriptFilename:o,originalSrcUrl:i,originalQuery:u,rule:a}}return a?(o[e][R]=S,u[e]=S):(l[e][R]=S,i[e]=S),S}(n,C,A);if(!e)throw a;R=e.originalScriptFilename,E=e.nextRetryUrl,L=e.nextDomain,U=e.rule}catch(t){throw t!==a&&console.error(e,"failed to get nextRetryUrl",t),a}let T=e=>({times:e,domain:L,url:E,tagName:A?"link":"script",isAsyncChunk:!0}),g=T(C);if(C>=U.max)throw a.message=(null==(p=a.message)?void 0:p.includes("retries:"))?a.message:`Loading chunk ${n} from "${R}" failed after ${U.max} retries: "${a.message}"`,"function"==typeof U.onFail&&U.onFail(g),a;"function"==typeof U.onRetry&&U.onRetry(g);let I="function"==typeof U.delay?U.delay(g):U.delay;return(I>0?new Promise(e=>setTimeout(e,I)):Promise.resolve()).then(()=>y.apply(y,f)).then(e=>{let t=(null==d?void 0:d.count)===N+2;if("function"==typeof U.onSuccess&&t){let e=T(C+1);U.onSuccess(e)}return e})})):S}if("u">typeof window&&!window.__RB_ASYNC_CHUNKS__&&(window.__RB_ASYNC_CHUNKS__={}),"u">typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=y,__RUNTIME_GLOBALS_LOAD_SCRIPT__=function(){let e=Array.prototype.slice.call(arguments),t=i[e[3]];return t&&(e[0]=t.nextRetryUrl),f.apply(null,e)},__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=function(e,t){let n=u[t];return n&&n.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+e}}catch(t){console.error(e,"Register async chunk retry runtime failed",t)}})();
1
+ (()=>{let e="[@rsbuild/plugin-assets-retry] ";function t(e,t){let n=t.domain;for(let t=0;t<n.length;t++){let r=n[t];if(-1!==e.indexOf(r))return r}return window.origin}let n=/[?#].*$/;function r(e,t,r,_,l,o){var i;return e.replace(t,r).replace(n,"")+(i=_+1,!0===o.addQuery?""!==l?`${l}&retry=${i}`:"?retry="+i:"function"==typeof o.addQuery?o.addQuery({times:i,originalQuery:l}):"")}let _=__RETRY_OPTIONS__,l={},o={},i={},u={},c=__RUNTIME_GLOBALS_ENSURE_CHUNK__,s=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,a=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||(()=>null),f=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function y(n){let f=Array.prototype.slice.call(arguments);f[10]||(f[10]={count:0,cssFailedCount:0});let d=f[10],S=c(...f);try{let e=s(n),t=a(n);"u">typeof window&&(e&&(window.__RB_ASYNC_CHUNKS__[e]=!0),t&&(window.__RB_ASYNC_CHUNKS__[t]=!0))}catch(t){console.error(e,"get original script or CSS filename error",t)}return d&&"number"==typeof d.count&&"number"==typeof d.cssFailedCount?(d.count+=1,S.catch(c=>{var S,R;let E,p,L,U,N=d.count-1,m=d.cssFailedCount,A=!!(null==c||null==(S=c.message)?void 0:S.includes("CSS chunk"));A&&(d.cssFailedCount+=1);let C=A?m:N-m;try{let e=function(e,n,c){var f,y,d;let S,R=c?null==(f=o[e])?void 0:f[n]:null==(y=l[e])?void 0:y[n],E=n+1;if(0===n||void 0===R){if(!(S=function(e,n){let l,o=n?a(e):s(e);if(!o)throw Error("only support cssExtract");let i=__RUNTIME_GLOBALS_PUBLIC_PATH__,u="/"===i[0]&&"/"!==i[1]?window.origin+i+o:i+o,c=(l=u.split("?")[1])?"?"+l.split("#")[0]:"",f=function(e,n,r){for(let _=0;_<r.length;_++){let l=r[_],o=l.test,i=!0;if(o instanceof RegExp?i=o.test(e):"string"==typeof o?i=new RegExp(o).test(e):"function"==typeof o&&(i=o(e)),l.domain&&l.domain.length>0){let n=t(e,l);l.domain.includes(n)||(i=!1)}if(l.type&&l.type.length>0&&!l.type.includes(n)&&(i=!1),i)return l}return null}(u,n?"link":"script",_);if(!f)return null;let y=t(u,f);return{nextDomain:y,nextRetryUrl:r(u,y,y,0,c,f),originalScriptFilename:o,originalSrcUrl:u,originalQuery:c,rule:f}}(e,c)))return null;c?o[e]=[]:l[e]=[]}else{let e,_,l,{originalScriptFilename:o,originalSrcUrl:i,originalQuery:u,rule:c}=R,s=(d=R.nextDomain,e=c.domain,_=t(d,c),l=e.indexOf(_),-1===l?_:e[(l+1)%e.length]);S={nextDomain:s,nextRetryUrl:r(R.nextRetryUrl,R.nextDomain,s,n,u,c),originalScriptFilename:o,originalSrcUrl:i,originalQuery:u,rule:c}}return c?(o[e][E]=S,u[e]=S):(l[e][E]=S,i[e]=S),S}(n,C,A);if(!e)throw c;E=e.originalScriptFilename,p=e.nextRetryUrl,L=e.nextDomain,U=e.rule}catch(t){throw t!==c&&console.error(e,"failed to get nextRetryUrl",t),c}let T=e=>({times:e,domain:L,url:p,tagName:A?"link":"script",isAsyncChunk:!0}),g=T(C);if(C>=U.max)throw c.message=(null==(R=c.message)?void 0:R.includes("retries:"))?c.message:`Loading chunk ${n} from "${E}" failed after ${U.max} retries: "${c.message}"`,"function"==typeof U.onFail&&U.onFail(g),c;"function"==typeof U.onRetry&&U.onRetry(g);let I="function"==typeof U.delay?U.delay(g):U.delay;return(I>0?new Promise(e=>setTimeout(e,I)):Promise.resolve()).then(()=>y.apply(y,f)).then(e=>{let t=(null==d?void 0:d.count)===N+2;if("function"==typeof U.onSuccess&&t){let e=T(C+1);U.onSuccess(e)}return e})})):S}if("u">typeof window&&!window.__RB_ASYNC_CHUNKS__&&(window.__RB_ASYNC_CHUNKS__={}),"u">typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=y,__RUNTIME_GLOBALS_LOAD_SCRIPT__=function(){let e=Array.prototype.slice.call(arguments),t=i[e[3]];return t&&(e[0]=t.nextRetryUrl),f(...e)},__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=function(e,t){let n=u[t];return n&&n.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+e}}catch(t){console.error(e,"Register async chunk retry runtime failed",t)}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-assets-retry",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "An Rsbuild plugin to automatically resend requests when static assets fail to load.",
5
5
  "repository": "https://github.com/rstackjs/rsbuild-plugin-assets-retry",
6
6
  "license": "MIT",
@@ -15,35 +15,26 @@
15
15
  "files": [
16
16
  "dist"
17
17
  ],
18
- "scripts": {
19
- "build": "rslib",
20
- "dev": "rslib -w",
21
- "lint": "rslint && prettier -c .",
22
- "lint:write": "rslint --fix && prettier -w .",
23
- "prepare": "simple-git-hooks && pnpm run build",
24
- "test": "playwright test",
25
- "bump": "pnpx bumpp"
26
- },
27
18
  "simple-git-hooks": {
28
19
  "pre-commit": "pnpm run lint:write"
29
20
  },
30
21
  "devDependencies": {
31
22
  "@microsoft/api-extractor": "^7.58.7",
32
- "@playwright/test": "^1.59.1",
33
- "@rsbuild/core": "^1.7.5",
34
- "@rsbuild/plugin-react": "^1.4.6",
35
- "@rslib/core": "^0.21.3",
36
- "@rslint/core": "^0.4.2",
37
- "@swc/core": "^1.15.30",
38
- "@types/node": "^24.12.2",
39
- "@types/react": "^19.2.14",
23
+ "@playwright/test": "^1.60.0",
24
+ "@rsbuild/core": "^2.0.7",
25
+ "@rsbuild/plugin-react": "^2.0.0",
26
+ "@rslib/core": "^0.21.5",
27
+ "@rslint/core": "^0.5.3",
28
+ "@swc/core": "^1.15.40",
29
+ "@types/node": "^24.12.4",
30
+ "@types/react": "^19.2.15",
40
31
  "@types/react-dom": "^19.2.3",
41
32
  "@types/serialize-javascript": "^5.0.4",
42
- "playwright": "^1.59.1",
43
- "prettier": "^3.8.2",
44
- "react": "^19.2.5",
45
- "react-dom": "^19.2.5",
46
- "serialize-javascript": "^7.0.0",
33
+ "playwright": "^1.60.0",
34
+ "prettier": "^3.8.3",
35
+ "react": "^19.2.6",
36
+ "react-dom": "^19.2.6",
37
+ "serialize-javascript": "^7.0.5",
47
38
  "simple-git-hooks": "^2.13.1",
48
39
  "typescript": "6.0.3"
49
40
  },
@@ -55,9 +46,16 @@
55
46
  "optional": true
56
47
  }
57
48
  },
58
- "packageManager": "pnpm@10.33.2",
59
49
  "publishConfig": {
60
50
  "access": "public",
61
51
  "registry": "https://registry.npmjs.org/"
52
+ },
53
+ "scripts": {
54
+ "build": "rslib",
55
+ "dev": "rslib -w",
56
+ "lint": "rslint && prettier -c .",
57
+ "lint:write": "rslint --fix && prettier -w .",
58
+ "test": "playwright test",
59
+ "bump": "pnpx bumpp"
62
60
  }
63
- }
61
+ }