Skip to content

Commit 21a5863

Browse files
authored
refactor(type): separate CompileTimeRetryOptions and RuntimeRetryOptions (#13)
chore: update
1 parent a458108 commit 21a5863

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

playground/rsbuild.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from '@rsbuild/core';
2-
import { pluginExample } from '../src';
2+
import { pluginAssetsRetry } from '../dist';
33

44
export default defineConfig({
5-
plugins: [pluginExample()],
5+
plugins: [pluginAssetsRetry()],
66
});

src/types.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { CrossOrigin } from '@rsbuild/core';
22

3-
export type PluginAssetsRetryOptions = {
3+
export type AssetsRetryHookContext = {
4+
url: string;
5+
times: number;
6+
domain: string;
7+
tagName: string;
8+
isAsyncChunk: boolean;
9+
};
10+
11+
export type RuntimeRetryOptions = {
412
/**
513
* The maximum number of retries for a single asset.
614
* @default 3
@@ -21,7 +29,7 @@ export type PluginAssetsRetryOptions = {
2129
domain?: string[];
2230
/**
2331
* Set the `crossorigin` attribute for tags.
24-
* @default config.html.crossorigin
32+
* @default rsbuildConfig.html.crossorigin
2533
*/
2634
crossOrigin?: boolean | CrossOrigin;
2735
/**
@@ -41,11 +49,25 @@ export type PluginAssetsRetryOptions = {
4149
* @param times e.g: 1 -> 2 -> 3
4250
* @param originalQuery initial request url's query e.g: <script src="https://cdn.com/a.js?version=1"></script> -> "?version=1"
4351
* @default false
44-
* @description true -> hasQuery(originalQuery) ? `${getQuery(originalQuery)}&retry=${existRetryTimes}` : `?retry=${existRetryTimes}`
52+
* @description
53+
*
54+
* if set to `true`, `?retry=${times}` will be added to the url.
55+
*
56+
* ```ts
57+
* ({ times, originalQuery }) => hasQuery(originalQuery) ? `${getQuery(originalQuery)}&retry=${times}` : `?retry=${times}`
58+
* ```
4559
*/
4660
addQuery?:
4761
| boolean
4862
| ((context: { times: number; originalQuery: string }) => string);
63+
/**
64+
* The delay time between retries. Unit: ms
65+
* @default 0
66+
*/
67+
delay?: number | ((context: AssetsRetryHookContext) => number);
68+
};
69+
70+
export type CompileTimeRetryOptions = {
4971
/**
5072
* Whether to inline the runtime JavaScript code of Assets Retry plugin into the HTML file.
5173
* @default true
@@ -56,22 +78,7 @@ export type PluginAssetsRetryOptions = {
5678
* @default rsbuildConfig.mode === 'production'
5779
*/
5880
minify?: boolean;
59-
/**
60-
* The delay time between retries. Unit: ms
61-
* @default 0
62-
*/
63-
delay?: number | ((context: AssetsRetryHookContext) => number);
6481
};
6582

66-
export type RuntimeRetryOptions = Omit<
67-
PluginAssetsRetryOptions,
68-
'inlineScript' | 'minify'
69-
>;
70-
71-
export type AssetsRetryHookContext = {
72-
url: string;
73-
times: number;
74-
domain: string;
75-
tagName: string;
76-
isAsyncChunk: boolean;
77-
};
83+
export type PluginAssetsRetryOptions = RuntimeRetryOptions &
84+
CompileTimeRetryOptions;

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"lib": ["DOM", "ESNext"],
77
"module": "Node16",
88
"strict": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
911
"declaration": true,
1012
"isolatedModules": true,
1113
"esModuleInterop": true,

0 commit comments

Comments
 (0)