@rsbuild/plugin-assets-retry 0.6.13 → 0.6.14
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.d.ts +17 -3
- package/dist/index.js +83 -73
- package/dist/index.mjs +74 -64
- package/dist/runtime/asyncChunkRetry.js +31 -16
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/dist/runtime/initialChunkRetry.js +41 -8
- package/dist/runtime/initialChunkRetry.min.js +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -22,26 +22,40 @@ type PluginAssetsRetryOptions = {
|
|
|
22
22
|
domain?: string[];
|
|
23
23
|
/**
|
|
24
24
|
* Set the `crossorigin` attribute for tags.
|
|
25
|
+
* @default config.html.crossorigin
|
|
25
26
|
*/
|
|
26
27
|
crossOrigin?: boolean | CrossOrigin;
|
|
27
28
|
/**
|
|
28
29
|
* The callback function when the asset is failed to be retried.
|
|
29
30
|
*/
|
|
30
|
-
onFail?: (
|
|
31
|
+
onFail?: (context: AssetsRetryHookContext) => void;
|
|
31
32
|
/**
|
|
32
33
|
* The callback function when the asset is being retried.
|
|
33
34
|
*/
|
|
34
|
-
onRetry?: (
|
|
35
|
+
onRetry?: (context: AssetsRetryHookContext) => void;
|
|
35
36
|
/**
|
|
36
37
|
* The callback function when the asset is successfully retried.
|
|
37
38
|
*/
|
|
38
|
-
onSuccess?: (
|
|
39
|
+
onSuccess?: (context: AssetsRetryHookContext) => void;
|
|
40
|
+
/**
|
|
41
|
+
* The function to add query parameters to the URL of the asset being retried.
|
|
42
|
+
* @param times e.g: 1 -> 2 -> 3
|
|
43
|
+
* @param originalQuery initial request url's query e.g: <script src="https://cdn.com/a.js?version=1"></script> -> "?version=1"
|
|
44
|
+
* @default false
|
|
45
|
+
* @description true -> hasQuery(originalQuery) ? `${getQuery(originalQuery)}&retry=${existRetryTimes}` : `?retry=${existRetryTimes}`
|
|
46
|
+
*/
|
|
47
|
+
addQuery?: boolean | ((context: {
|
|
48
|
+
times: number;
|
|
49
|
+
originalQuery: string;
|
|
50
|
+
}) => string);
|
|
39
51
|
/**
|
|
40
52
|
* Whether to inline the runtime JavaScript code of Assets Retry plugin into the HTML file.
|
|
53
|
+
* @default true
|
|
41
54
|
*/
|
|
42
55
|
inlineScript?: boolean;
|
|
43
56
|
/**
|
|
44
57
|
* Whether to minify the runtime JavaScript code of Assets Retry plugin.
|
|
58
|
+
* @default process.env.NODE_ENV === 'production'
|
|
45
59
|
*/
|
|
46
60
|
minify?: boolean;
|
|
47
61
|
};
|
package/dist/index.js
CHANGED
|
@@ -58,12 +58,12 @@ var AssetsRetryPlugin_exports = {};
|
|
|
58
58
|
__export(AssetsRetryPlugin_exports, {
|
|
59
59
|
AssetsRetryPlugin: () => AssetsRetryPlugin
|
|
60
60
|
});
|
|
61
|
-
var
|
|
61
|
+
var import_node_path, import_shared, _retryOptions, AssetsRetryPlugin;
|
|
62
62
|
var init_AssetsRetryPlugin = __esm({
|
|
63
63
|
"src/AssetsRetryPlugin.ts"() {
|
|
64
64
|
"use strict";
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
import_node_path = __toESM(require("path"));
|
|
66
|
+
import_shared = require("@rsbuild/shared");
|
|
67
67
|
AssetsRetryPlugin = class {
|
|
68
68
|
constructor(options) {
|
|
69
69
|
__publicField(this, "name");
|
|
@@ -91,21 +91,21 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
91
91
|
async getRetryCode() {
|
|
92
92
|
const { default: serialize2 } = await import("serialize-javascript");
|
|
93
93
|
const filename = "initialChunkRetry";
|
|
94
|
-
const runtimeFilePath =
|
|
94
|
+
const runtimeFilePath = import_node_path.default.join(
|
|
95
95
|
__dirname,
|
|
96
96
|
"runtime",
|
|
97
97
|
this.minify ? `${filename}.min.js` : `${filename}.js`
|
|
98
98
|
);
|
|
99
|
-
const runtimeCode = await
|
|
99
|
+
const runtimeCode = await import_shared.fse.readFile(runtimeFilePath, "utf-8");
|
|
100
100
|
return `(function(){${runtimeCode};init(${serialize2(
|
|
101
101
|
__privateGet(this, _retryOptions)
|
|
102
102
|
)});})()`;
|
|
103
103
|
}
|
|
104
104
|
async getScriptPath() {
|
|
105
105
|
if (!this.scriptPath) {
|
|
106
|
-
this.scriptPath =
|
|
106
|
+
this.scriptPath = import_node_path.default.posix.join(
|
|
107
107
|
this.distDir,
|
|
108
|
-
`assets-retry.${"0.6.
|
|
108
|
+
`assets-retry.${"0.6.14"}.js`
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
return this.scriptPath;
|
|
@@ -136,15 +136,15 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
136
136
|
this.HtmlPlugin.getHooks(compilation).alterAssetTagGroups.tapPromise(
|
|
137
137
|
this.name,
|
|
138
138
|
async (data) => {
|
|
139
|
-
const scriptTag = (0,
|
|
139
|
+
const scriptTag = (0, import_shared.generateScriptTag)();
|
|
140
140
|
if (this.inlineScript) {
|
|
141
141
|
data.headTags.unshift({
|
|
142
142
|
...scriptTag,
|
|
143
143
|
innerHTML: await this.getRetryCode()
|
|
144
144
|
});
|
|
145
145
|
} else {
|
|
146
|
-
const publicPath = (0,
|
|
147
|
-
const url = (0,
|
|
146
|
+
const publicPath = (0, import_shared.getPublicPathFromCompiler)(compiler);
|
|
147
|
+
const url = (0, import_shared.withPublicPath)(await this.getScriptPath(), publicPath);
|
|
148
148
|
data.headTags.unshift({
|
|
149
149
|
...scriptTag,
|
|
150
150
|
attributes: {
|
|
@@ -163,19 +163,11 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
// src/index.ts
|
|
167
|
-
var src_exports = {};
|
|
168
|
-
__export(src_exports, {
|
|
169
|
-
pluginAssetsRetry: () => pluginAssetsRetry
|
|
170
|
-
});
|
|
171
|
-
module.exports = __toCommonJS(src_exports);
|
|
172
|
-
var import_shared3 = require("@rsbuild/shared");
|
|
173
|
-
|
|
174
166
|
// src/AsyncChunkRetryPlugin.ts
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
var AsyncChunkRetryPlugin_exports = {};
|
|
168
|
+
__export(AsyncChunkRetryPlugin_exports, {
|
|
169
|
+
AsyncChunkRetryPlugin: () => AsyncChunkRetryPlugin
|
|
170
|
+
});
|
|
179
171
|
function appendWebpackScript(module2, appendSource) {
|
|
180
172
|
try {
|
|
181
173
|
const originSource = module2.getGeneratedCode();
|
|
@@ -196,59 +188,76 @@ ${appendSource}`, "utf-8");
|
|
|
196
188
|
throw err;
|
|
197
189
|
}
|
|
198
190
|
}
|
|
199
|
-
var
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
191
|
+
var import_node_path2, import_core, import_shared2, import_serialize_javascript, AsyncChunkRetryPlugin;
|
|
192
|
+
var init_AsyncChunkRetryPlugin = __esm({
|
|
193
|
+
"src/AsyncChunkRetryPlugin.ts"() {
|
|
194
|
+
"use strict";
|
|
195
|
+
import_node_path2 = __toESM(require("path"));
|
|
196
|
+
import_core = require("@rsbuild/core");
|
|
197
|
+
import_shared2 = require("@rsbuild/shared");
|
|
198
|
+
import_serialize_javascript = __toESM(require("serialize-javascript"));
|
|
199
|
+
AsyncChunkRetryPlugin = class {
|
|
200
|
+
constructor(options) {
|
|
201
|
+
__publicField(this, "name", "ASYNC_CHUNK_RETRY_PLUGIN");
|
|
202
|
+
__publicField(this, "options");
|
|
203
|
+
__publicField(this, "runtimeOptions");
|
|
204
|
+
this.options = options;
|
|
205
|
+
this.runtimeOptions = (0, import_shared2.pick)(options, [
|
|
206
|
+
"domain",
|
|
207
|
+
"max",
|
|
208
|
+
"onRetry",
|
|
209
|
+
"onSuccess",
|
|
210
|
+
"onFail",
|
|
211
|
+
"addQuery",
|
|
212
|
+
"test"
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
getRawRuntimeRetryCode() {
|
|
216
|
+
const { RuntimeGlobals } = import_core.rspack;
|
|
217
|
+
const filename = "asyncChunkRetry";
|
|
218
|
+
const runtimeFilePath = import_node_path2.default.join(
|
|
219
|
+
__dirname,
|
|
220
|
+
"runtime",
|
|
221
|
+
this.options.minify ? `${filename}.min.js` : `${filename}.js`
|
|
222
|
+
);
|
|
223
|
+
const rawText = import_shared2.fse.readFileSync(runtimeFilePath, "utf-8");
|
|
224
|
+
return rawText.replaceAll("__RUNTIME_GLOBALS_REQUIRE__", RuntimeGlobals.require).replaceAll(
|
|
225
|
+
"__RUNTIME_GLOBALS_ENSURE_CHUNK__",
|
|
226
|
+
RuntimeGlobals.ensureChunk
|
|
227
|
+
).replaceAll(
|
|
228
|
+
"__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__",
|
|
229
|
+
RuntimeGlobals.getChunkScriptFilename
|
|
230
|
+
).replaceAll("__RUNTIME_GLOBALS_PUBLIC_PATH__", RuntimeGlobals.publicPath).replaceAll("__RUNTIME_GLOBALS_LOAD_SCRIPT__", RuntimeGlobals.loadScript).replaceAll("__RETRY_OPTIONS__", (0, import_serialize_javascript.default)(this.runtimeOptions));
|
|
231
|
+
}
|
|
232
|
+
apply(compiler) {
|
|
233
|
+
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
234
|
+
compilation.hooks.runtimeModule.tap(this.name, (module2) => {
|
|
235
|
+
const { isRspack } = this.options;
|
|
236
|
+
const constructorName = isRspack ? module2.constructorName : module2.constructor?.name;
|
|
237
|
+
const isPublicPathModule = module2.name === "publicPath" || constructorName === "PublicPathRuntimeModule";
|
|
238
|
+
if (!isPublicPathModule) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const runtimeCode = this.getRawRuntimeRetryCode();
|
|
242
|
+
if (isRspack) {
|
|
243
|
+
appendRspackScript(module2, runtimeCode);
|
|
244
|
+
} else {
|
|
245
|
+
appendWebpackScript(module2, runtimeCode);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
};
|
|
248
251
|
}
|
|
249
|
-
};
|
|
252
|
+
});
|
|
250
253
|
|
|
251
254
|
// src/index.ts
|
|
255
|
+
var src_exports = {};
|
|
256
|
+
__export(src_exports, {
|
|
257
|
+
pluginAssetsRetry: () => pluginAssetsRetry
|
|
258
|
+
});
|
|
259
|
+
module.exports = __toCommonJS(src_exports);
|
|
260
|
+
var import_shared3 = require("@rsbuild/shared");
|
|
252
261
|
var pluginAssetsRetry = (options = {}) => ({
|
|
253
262
|
name: "rsbuild:assets-retry",
|
|
254
263
|
setup(api) {
|
|
@@ -259,6 +268,7 @@ var pluginAssetsRetry = (options = {}) => ({
|
|
|
259
268
|
return;
|
|
260
269
|
}
|
|
261
270
|
const { AssetsRetryPlugin: AssetsRetryPlugin2 } = await Promise.resolve().then(() => (init_AssetsRetryPlugin(), AssetsRetryPlugin_exports));
|
|
271
|
+
const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
|
|
262
272
|
const distDir = (0, import_shared3.getDistPath)(config, "js");
|
|
263
273
|
if (options.crossOrigin === void 0) {
|
|
264
274
|
options.crossOrigin = config.html.crossorigin;
|
|
@@ -275,7 +285,7 @@ var pluginAssetsRetry = (options = {}) => ({
|
|
|
275
285
|
}
|
|
276
286
|
]);
|
|
277
287
|
const isRspack = api.context.bundlerType === "rspack";
|
|
278
|
-
chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(
|
|
288
|
+
chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
|
|
279
289
|
}
|
|
280
290
|
);
|
|
281
291
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -52,9 +52,9 @@ var AssetsRetryPlugin_exports = {};
|
|
|
52
52
|
__export(AssetsRetryPlugin_exports, {
|
|
53
53
|
AssetsRetryPlugin: () => AssetsRetryPlugin
|
|
54
54
|
});
|
|
55
|
-
import
|
|
55
|
+
import path2 from "path";
|
|
56
56
|
import {
|
|
57
|
-
fse
|
|
57
|
+
fse,
|
|
58
58
|
generateScriptTag,
|
|
59
59
|
getPublicPathFromCompiler,
|
|
60
60
|
withPublicPath
|
|
@@ -91,21 +91,21 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
91
91
|
async getRetryCode() {
|
|
92
92
|
const { default: serialize2 } = await import("serialize-javascript");
|
|
93
93
|
const filename = "initialChunkRetry";
|
|
94
|
-
const runtimeFilePath =
|
|
94
|
+
const runtimeFilePath = path2.join(
|
|
95
95
|
__dirname,
|
|
96
96
|
"runtime",
|
|
97
97
|
this.minify ? `${filename}.min.js` : `${filename}.js`
|
|
98
98
|
);
|
|
99
|
-
const runtimeCode = await
|
|
99
|
+
const runtimeCode = await fse.readFile(runtimeFilePath, "utf-8");
|
|
100
100
|
return `(function(){${runtimeCode};init(${serialize2(
|
|
101
101
|
__privateGet(this, _retryOptions)
|
|
102
102
|
)});})()`;
|
|
103
103
|
}
|
|
104
104
|
async getScriptPath() {
|
|
105
105
|
if (!this.scriptPath) {
|
|
106
|
-
this.scriptPath =
|
|
106
|
+
this.scriptPath = path2.posix.join(
|
|
107
107
|
this.distDir,
|
|
108
|
-
`assets-retry.${"0.6.
|
|
108
|
+
`assets-retry.${"0.6.14"}.js`
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
return this.scriptPath;
|
|
@@ -163,15 +163,14 @@ var init_AssetsRetryPlugin = __esm({
|
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
-
// src/index.ts
|
|
167
|
-
init_esm();
|
|
168
|
-
import { getDistPath, isHtmlDisabled } from "@rsbuild/shared";
|
|
169
|
-
|
|
170
166
|
// src/AsyncChunkRetryPlugin.ts
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
var AsyncChunkRetryPlugin_exports = {};
|
|
168
|
+
__export(AsyncChunkRetryPlugin_exports, {
|
|
169
|
+
AsyncChunkRetryPlugin: () => AsyncChunkRetryPlugin
|
|
170
|
+
});
|
|
171
|
+
import path3 from "path";
|
|
173
172
|
import { rspack } from "@rsbuild/core";
|
|
174
|
-
import { fse, pick } from "@rsbuild/shared";
|
|
173
|
+
import { fse as fse2, pick } from "@rsbuild/shared";
|
|
175
174
|
import serialize from "serialize-javascript";
|
|
176
175
|
function appendWebpackScript(module, appendSource) {
|
|
177
176
|
try {
|
|
@@ -193,59 +192,69 @@ ${appendSource}`, "utf-8");
|
|
|
193
192
|
throw err;
|
|
194
193
|
}
|
|
195
194
|
}
|
|
196
|
-
var AsyncChunkRetryPlugin
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
195
|
+
var AsyncChunkRetryPlugin;
|
|
196
|
+
var init_AsyncChunkRetryPlugin = __esm({
|
|
197
|
+
"src/AsyncChunkRetryPlugin.ts"() {
|
|
198
|
+
"use strict";
|
|
199
|
+
init_esm();
|
|
200
|
+
AsyncChunkRetryPlugin = class {
|
|
201
|
+
constructor(options) {
|
|
202
|
+
__publicField(this, "name", "ASYNC_CHUNK_RETRY_PLUGIN");
|
|
203
|
+
__publicField(this, "options");
|
|
204
|
+
__publicField(this, "runtimeOptions");
|
|
205
|
+
this.options = options;
|
|
206
|
+
this.runtimeOptions = pick(options, [
|
|
207
|
+
"domain",
|
|
208
|
+
"max",
|
|
209
|
+
"onRetry",
|
|
210
|
+
"onSuccess",
|
|
211
|
+
"onFail",
|
|
212
|
+
"addQuery",
|
|
213
|
+
"test"
|
|
214
|
+
]);
|
|
215
|
+
}
|
|
216
|
+
getRawRuntimeRetryCode() {
|
|
217
|
+
const { RuntimeGlobals } = rspack;
|
|
218
|
+
const filename = "asyncChunkRetry";
|
|
219
|
+
const runtimeFilePath = path3.join(
|
|
220
|
+
__dirname,
|
|
221
|
+
"runtime",
|
|
222
|
+
this.options.minify ? `${filename}.min.js` : `${filename}.js`
|
|
223
|
+
);
|
|
224
|
+
const rawText = fse2.readFileSync(runtimeFilePath, "utf-8");
|
|
225
|
+
return rawText.replaceAll("__RUNTIME_GLOBALS_REQUIRE__", RuntimeGlobals.require).replaceAll(
|
|
226
|
+
"__RUNTIME_GLOBALS_ENSURE_CHUNK__",
|
|
227
|
+
RuntimeGlobals.ensureChunk
|
|
228
|
+
).replaceAll(
|
|
229
|
+
"__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__",
|
|
230
|
+
RuntimeGlobals.getChunkScriptFilename
|
|
231
|
+
).replaceAll("__RUNTIME_GLOBALS_PUBLIC_PATH__", RuntimeGlobals.publicPath).replaceAll("__RUNTIME_GLOBALS_LOAD_SCRIPT__", RuntimeGlobals.loadScript).replaceAll("__RETRY_OPTIONS__", serialize(this.runtimeOptions));
|
|
232
|
+
}
|
|
233
|
+
apply(compiler) {
|
|
234
|
+
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
235
|
+
compilation.hooks.runtimeModule.tap(this.name, (module) => {
|
|
236
|
+
const { isRspack } = this.options;
|
|
237
|
+
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
238
|
+
const isPublicPathModule = module.name === "publicPath" || constructorName === "PublicPathRuntimeModule";
|
|
239
|
+
if (!isPublicPathModule) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const runtimeCode = this.getRawRuntimeRetryCode();
|
|
243
|
+
if (isRspack) {
|
|
244
|
+
appendRspackScript(module, runtimeCode);
|
|
245
|
+
} else {
|
|
246
|
+
appendWebpackScript(module, runtimeCode);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
245
252
|
}
|
|
246
|
-
};
|
|
253
|
+
});
|
|
247
254
|
|
|
248
255
|
// src/index.ts
|
|
256
|
+
init_esm();
|
|
257
|
+
import { getDistPath, isHtmlDisabled } from "@rsbuild/shared";
|
|
249
258
|
var pluginAssetsRetry = (options = {}) => ({
|
|
250
259
|
name: "rsbuild:assets-retry",
|
|
251
260
|
setup(api) {
|
|
@@ -256,6 +265,7 @@ var pluginAssetsRetry = (options = {}) => ({
|
|
|
256
265
|
return;
|
|
257
266
|
}
|
|
258
267
|
const { AssetsRetryPlugin: AssetsRetryPlugin2 } = await Promise.resolve().then(() => (init_AssetsRetryPlugin(), AssetsRetryPlugin_exports));
|
|
268
|
+
const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
|
|
259
269
|
const distDir = getDistPath(config, "js");
|
|
260
270
|
if (options.crossOrigin === void 0) {
|
|
261
271
|
options.crossOrigin = config.html.crossorigin;
|
|
@@ -272,7 +282,7 @@ var pluginAssetsRetry = (options = {}) => ({
|
|
|
272
282
|
}
|
|
273
283
|
]);
|
|
274
284
|
const isRspack = api.context.bundlerType === "rspack";
|
|
275
|
-
chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(
|
|
285
|
+
chain.plugin(CHAIN_ID.PLUGIN.ASYNC_CHUNK_RETRY).use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
|
|
276
286
|
}
|
|
277
287
|
);
|
|
278
288
|
}
|
|
@@ -29,12 +29,29 @@ function findNextDomain(url) {
|
|
|
29
29
|
var index = domainList.indexOf(currentDomain);
|
|
30
30
|
return domainList[(index + 1) % domainList.length] || url;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
var postfixRE = /[?#].*$/;
|
|
33
|
+
function cleanUrl(url) {
|
|
34
|
+
return url.replace(postfixRE, '');
|
|
35
|
+
}
|
|
36
|
+
function getQueryFromUrl(url) {
|
|
37
|
+
var parts = url.split('?')[1];
|
|
38
|
+
return parts ? "?".concat(parts.split('#')[0]) : '';
|
|
39
|
+
}
|
|
40
|
+
function getUrlRetryQuery(existRetryTimes, originalQuery) {
|
|
41
|
+
if (config.addQuery === true) {
|
|
42
|
+
return originalQuery !== '' ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
|
|
43
|
+
}
|
|
44
|
+
if (typeof config.addQuery === 'function') {
|
|
45
|
+
return config.addQuery({
|
|
46
|
+
times: existRetryTimes,
|
|
47
|
+
originalQuery: originalQuery
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
function getNextRetryUrl(existRetryTimes, nextDomain, originalSrcUrl, originalScriptFilename) {
|
|
53
|
+
return cleanUrl(nextDomain + (nextDomain[nextDomain.length - 1] === '/' ? '' : '/') + originalScriptFilename) + getUrlRetryQuery(existRetryTimes, getQueryFromUrl(originalSrcUrl));
|
|
54
|
+
}
|
|
38
55
|
function getCurrentRetry(chunkId) {
|
|
39
56
|
return retryCollector[chunkId];
|
|
40
57
|
}
|
|
@@ -42,14 +59,12 @@ function initRetry(chunkId) {
|
|
|
42
59
|
var _config$domain$, _config$domain3;
|
|
43
60
|
var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
|
|
44
61
|
var originalSrcUrl = __RUNTIME_GLOBALS_PUBLIC_PATH__ + originalScriptFilename;
|
|
45
|
-
var nextDomain = (_config$domain$ = (_config$domain3 = config.domain) === null || _config$domain3 === void 0 ? void 0 : _config$domain3[0]) !== null && _config$domain$ !== void 0 ? _config$domain$ : __RUNTIME_GLOBALS_PUBLIC_PATH__;
|
|
46
62
|
var existRetryTimes = 1;
|
|
63
|
+
var nextDomain = (_config$domain$ = (_config$domain3 = config.domain) === null || _config$domain3 === void 0 ? void 0 : _config$domain3[0]) !== null && _config$domain$ !== void 0 ? _config$domain$ : __RUNTIME_GLOBALS_PUBLIC_PATH__;
|
|
47
64
|
return {
|
|
48
65
|
existRetryTimes: existRetryTimes,
|
|
49
66
|
nextDomain: nextDomain,
|
|
50
|
-
nextRetryUrl:
|
|
51
|
-
// + getUrlRetryQuery(existRetryTimes),
|
|
52
|
-
|
|
67
|
+
nextRetryUrl: getNextRetryUrl(existRetryTimes, nextDomain, originalSrcUrl, originalScriptFilename),
|
|
53
68
|
originalScriptFilename: originalScriptFilename,
|
|
54
69
|
originalSrcUrl: originalSrcUrl
|
|
55
70
|
};
|
|
@@ -60,16 +75,16 @@ function nextRetry(chunkId) {
|
|
|
60
75
|
if (!currRetry) {
|
|
61
76
|
nextRetry = initRetry(chunkId);
|
|
62
77
|
} else {
|
|
78
|
+
var originalScriptFilename = currRetry.originalScriptFilename,
|
|
79
|
+
originalSrcUrl = currRetry.originalSrcUrl;
|
|
63
80
|
var existRetryTimes = currRetry.existRetryTimes + 1;
|
|
64
81
|
var nextDomain = findNextDomain(currRetry.nextDomain);
|
|
65
82
|
nextRetry = {
|
|
66
83
|
existRetryTimes: existRetryTimes,
|
|
67
84
|
nextDomain: nextDomain,
|
|
68
|
-
nextRetryUrl:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
originalScriptFilename: currRetry.originalScriptFilename,
|
|
72
|
-
originalSrcUrl: currRetry.originalSrcUrl
|
|
85
|
+
nextRetryUrl: getNextRetryUrl(existRetryTimes, nextDomain, originalSrcUrl, originalScriptFilename),
|
|
86
|
+
originalScriptFilename: originalScriptFilename,
|
|
87
|
+
originalSrcUrl: originalSrcUrl
|
|
73
88
|
};
|
|
74
89
|
}
|
|
75
90
|
retryCollector[chunkId] = nextRetry;
|
|
@@ -155,7 +170,7 @@ function loadScript(originalUrl, done, key, chunkId) {
|
|
|
155
170
|
return originalLoadScript(retry ? retry.nextRetryUrl : originalUrl, done, key, chunkId);
|
|
156
171
|
}
|
|
157
172
|
function registerAsyncChunkRetry() {
|
|
158
|
-
// init global variables shared
|
|
173
|
+
// init global variables shared between initial-chunk-retry and async-chunk-retry
|
|
159
174
|
if (typeof window !== 'undefined' && !window.__RB_ASYNC_CHUNKS__) {
|
|
160
175
|
window.__RB_ASYNC_CHUNKS__ = {};
|
|
161
176
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var config=__RETRY_OPTIONS__,maxRetries=config.max||3,retryCollector={};function findCurrentDomain(n){for(var
|
|
1
|
+
"use strict";var config=__RETRY_OPTIONS__,maxRetries=config.max||3,retryCollector={};function findCurrentDomain(n){for(var e,r=null!==(e=config.domain)&&void 0!==e?e:[],t="",i=0;i<r.length;i++)if(-1!==n.indexOf(r[i])){t=r[i];break}return t||n}function findNextDomain(n){var e,r=null!==(e=config.domain)&&void 0!==e?e:[],t=findCurrentDomain(n),i=r.indexOf(t);return r[(i+1)%r.length]||n}var postfixRE=/[?#].*$/;function cleanUrl(n){return n.replace(postfixRE,"")}function getQueryFromUrl(n){var e=n.split("?")[1];return e?"?".concat(e.split("#")[0]):""}function getUrlRetryQuery(n,e){return!0===config.addQuery?""!==e?"".concat(e,"&retry=").concat(n):"?retry=".concat(n):"function"==typeof config.addQuery?config.addQuery({times:n,originalQuery:e}):""}function getNextRetryUrl(n,e,r,t){return cleanUrl(e+("/"===e[e.length-1]?"":"/")+t)+getUrlRetryQuery(n,getQueryFromUrl(r))}function getCurrentRetry(n){return retryCollector[n]}function initRetry(n){var e,r,t=originalGetChunkScriptFilename(n),i=__RUNTIME_GLOBALS_PUBLIC_PATH__+t,o=null!==(e=null===(r=config.domain)||void 0===r?void 0:r[0])&&void 0!==e?e:__RUNTIME_GLOBALS_PUBLIC_PATH__;return{existRetryTimes:1,nextDomain:o,nextRetryUrl:getNextRetryUrl(1,o,i,t),originalScriptFilename:t,originalSrcUrl:i}}function nextRetry(n){var e,r=getCurrentRetry(n);if(r){var t=r.originalScriptFilename,i=r.originalSrcUrl,o=r.existRetryTimes+1,c=findNextDomain(r.nextDomain);e={existRetryTimes:o,nextDomain:c,nextRetryUrl:getNextRetryUrl(o,c,i,t),originalScriptFilename:t,originalSrcUrl:i}}else e=initRetry(n);return retryCollector[n]=e,e}var originalEnsureChunk=__RUNTIME_GLOBALS_ENSURE_CHUNK__,originalGetChunkScriptFilename=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,originalLoadScript=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function ensureChunk(n){var e=originalEnsureChunk(n),r=originalGetChunkScriptFilename(n);return"undefined"==typeof window||window.__RB_ASYNC_CHUNKS__[r]||(window.__RB_ASYNC_CHUNKS__[r]=!0),e.catch((function(e){var r=nextRetry(n),t=r.existRetryTimes,i=r.originalSrcUrl,o=r.nextRetryUrl,c=r.nextDomain,a=function(n){return{times:n,domain:c,url:o,tagName:"script"}},_=a(t-1);if(t>maxRetries)throw e.message="Loading chunk ".concat(n," from ").concat(i," failed after ").concat(maxRetries,' retries: "').concat(e.message,'"'),"function"==typeof config.onFail&&config.onFail(_),e;var u=config.test;if(u){if("string"==typeof u){var f=new RegExp(u);u=function(n){return f.test(n)}}if("function"!=typeof u||!u(o))throw e}if(config.domain&&config.domain.length>0&&-1===config.domain.indexOf(c))throw e;return"function"==typeof config.onRetry&&config.onRetry(_),ensureChunk(n).then((function(e){if("function"==typeof config.onSuccess){var r,i=a(t);(null!==(r=getCurrentRetry(n))&&void 0!==r?r:{}).existRetryTimes===t&&config.onSuccess(i)}return e}))}))}function loadScript(n,e,r,t){var i=getCurrentRetry(t);return originalLoadScript(i?i.nextRetryUrl:n,e,r,t)}function registerAsyncChunkRetry(){if("undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={}),"undefined"!=typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=ensureChunk,__RUNTIME_GLOBALS_LOAD_SCRIPT__=loadScript}catch(n){console.error("[@rsbuild/plugin-assets-retry] Register async chunk retry runtime failed",n)}}registerAsyncChunkRetry();
|
|
@@ -53,10 +53,19 @@ function validateTargetInfo(config, e) {
|
|
|
53
53
|
url: url
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
var postfixRE = /[?#].*$/;
|
|
57
|
+
function cleanUrl(url) {
|
|
58
|
+
return url.replace(postfixRE, '');
|
|
59
|
+
}
|
|
60
|
+
function getQueryFromUrl(url) {
|
|
61
|
+
var parts = url.split('?')[1];
|
|
62
|
+
return parts ? "?".concat(parts.split('#')[0]) : '';
|
|
63
|
+
}
|
|
56
64
|
function createElement(origin, attributes) {
|
|
57
65
|
var crossOrigin = attributes.crossOrigin === true ? 'anonymous' : attributes.crossOrigin;
|
|
58
66
|
var crossOriginAttr = crossOrigin ? "crossorigin=\"".concat(crossOrigin, "\"") : '';
|
|
59
67
|
var retryTimesAttr = attributes.times ? "data-rsbuild-retry-times=\"".concat(attributes.times, "\"") : '';
|
|
68
|
+
var originalQueryAttr = attributes.originalQuery ? "data-rsbuild-original-query=\"".concat(attributes.originalQuery, "\"") : '';
|
|
60
69
|
var isAsyncAttr = attributes.isAsync ? 'data-rsbuild-async' : '';
|
|
61
70
|
if (origin instanceof HTMLScriptElement) {
|
|
62
71
|
var script = document.createElement('script');
|
|
@@ -70,11 +79,14 @@ function createElement(origin, attributes) {
|
|
|
70
79
|
if (attributes.isAsync) {
|
|
71
80
|
script.dataset.rsbuildAsync = '';
|
|
72
81
|
}
|
|
82
|
+
if (attributes.originalQuery !== undefined) {
|
|
83
|
+
script.dataset.rsbuildOriginalQuery = attributes.originalQuery;
|
|
84
|
+
}
|
|
73
85
|
return {
|
|
74
86
|
element: script,
|
|
75
87
|
str:
|
|
76
88
|
// 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>'
|
|
89
|
+
"<script src=\"".concat(attributes.url, "\" ").concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(isAsyncAttr, " ").concat(originalQueryAttr, ">") + '</' + 'script>'
|
|
78
90
|
};
|
|
79
91
|
}
|
|
80
92
|
if (origin instanceof HTMLLinkElement) {
|
|
@@ -90,15 +102,18 @@ function createElement(origin, attributes) {
|
|
|
90
102
|
if (attributes.times) {
|
|
91
103
|
link.dataset.rsbuildRetryTimes = String(attributes.times);
|
|
92
104
|
}
|
|
105
|
+
if (attributes.originalQuery !== undefined) {
|
|
106
|
+
link.dataset.rsbuildOriginalQuery = attributes.originalQuery;
|
|
107
|
+
}
|
|
93
108
|
return {
|
|
94
109
|
element: link,
|
|
95
|
-
str: "<link rel=\"".concat(link.rel, "\" href=\"").concat(attributes.url, "\" ").concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(link.as ? "as=\"".concat(link.as, "\"") : '', "></link>")
|
|
110
|
+
str: "<link rel=\"".concat(link.rel, "\" href=\"").concat(attributes.url, "\" ").concat(crossOriginAttr, " ").concat(retryTimesAttr, " ").concat(link.as ? "as=\"".concat(link.as, "\"") : '', " ").concat(originalQueryAttr, "></link>")
|
|
96
111
|
};
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
|
-
function reloadElementResource(origin, fresh,
|
|
114
|
+
function reloadElementResource(origin, fresh, attributes) {
|
|
100
115
|
if (origin instanceof HTMLScriptElement) {
|
|
101
|
-
if (
|
|
116
|
+
if (attributes.isAsync) {
|
|
102
117
|
document.body.appendChild(fresh.element);
|
|
103
118
|
} else {
|
|
104
119
|
document.write(fresh.str);
|
|
@@ -108,11 +123,13 @@ function reloadElementResource(origin, fresh, options) {
|
|
|
108
123
|
document.getElementsByTagName('head')[0].appendChild(fresh.element);
|
|
109
124
|
}
|
|
110
125
|
if (origin instanceof HTMLImageElement) {
|
|
111
|
-
origin.src =
|
|
112
|
-
origin.dataset.rsbuildRetryTimes = String(
|
|
126
|
+
origin.src = attributes.url;
|
|
127
|
+
origin.dataset.rsbuildRetryTimes = String(attributes.times);
|
|
128
|
+
origin.dataset.rsbuildOriginalQuery = String(attributes.originalQuery);
|
|
113
129
|
}
|
|
114
130
|
}
|
|
115
131
|
function retry(config, e) {
|
|
132
|
+
var _target$dataset$rsbui;
|
|
116
133
|
var targetInfo = validateTargetInfo(config, e);
|
|
117
134
|
if (targetInfo === false) {
|
|
118
135
|
return;
|
|
@@ -163,12 +180,28 @@ function retry(config, e) {
|
|
|
163
180
|
|
|
164
181
|
// Then, we will start to retry
|
|
165
182
|
var nextDomain = findNextDomain(domain, config.domain);
|
|
183
|
+
|
|
184
|
+
// if the initial request is "/static/js/async/src_Hello_tsx.js?q=1", retry url would be "/static/js/async/src_Hello_tsx.js?q=1&retry=1"
|
|
185
|
+
var originalQuery = (_target$dataset$rsbui = target.dataset.rsbuildOriginalQuery) !== null && _target$dataset$rsbui !== void 0 ? _target$dataset$rsbui : getQueryFromUrl(url);
|
|
186
|
+
function getUrlRetryQuery(existRetryTimes) {
|
|
187
|
+
if (config.addQuery === true) {
|
|
188
|
+
return originalQuery !== '' ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
|
|
189
|
+
}
|
|
190
|
+
if (typeof config.addQuery === 'function') {
|
|
191
|
+
return config.addQuery({
|
|
192
|
+
times: existRetryTimes,
|
|
193
|
+
originalQuery: originalQuery
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return '';
|
|
197
|
+
}
|
|
166
198
|
var isAsync = Boolean(target.dataset.rsbuildAsync) || target.async || target.defer;
|
|
167
199
|
var attributes = {
|
|
168
|
-
url: url.replace(domain, nextDomain),
|
|
200
|
+
url: cleanUrl(url.replace(domain, nextDomain)) + getUrlRetryQuery(existRetryTimes + 1),
|
|
169
201
|
times: existRetryTimes + 1,
|
|
170
202
|
crossOrigin: config.crossOrigin,
|
|
171
|
-
isAsync: isAsync
|
|
203
|
+
isAsync: isAsync,
|
|
204
|
+
originalQuery: originalQuery
|
|
172
205
|
};
|
|
173
206
|
var element = createElement(target, attributes);
|
|
174
207
|
if (config.onRetry && typeof config.onRetry === 'function') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var TAG_TYPE={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement},TYPES=Object.keys(TAG_TYPE);function findCurrentDomain(e,n){for(var t="",r=0;r<n.length;r++)if(-1!==e.indexOf(n[r])){t=n[r];break}return t||e}function findNextDomain(e,n){var t=findCurrentDomain(e,n),r=n.indexOf(t);return n[(r+1)%n.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,n){var t,r=n.target,i=null===(t=r.tagName)||void 0===t?void 0:t.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,n){var t=!0===n.crossOrigin?"anonymous":n.crossOrigin,r=t?'crossorigin="'.concat(t,'"'):"",i=n.times?'data-rsbuild-retry-times="'.concat(n.times,'"'):"",a=n.isAsync?"data-rsbuild-async":"";if(e instanceof HTMLScriptElement){var
|
|
1
|
+
"use strict";var TAG_TYPE={link:HTMLLinkElement,script:HTMLScriptElement,img:HTMLImageElement},TYPES=Object.keys(TAG_TYPE);function findCurrentDomain(e,n){for(var t="",r=0;r<n.length;r++)if(-1!==e.indexOf(n[r])){t=n[r];break}return t||e}function findNextDomain(e,n){var t=findCurrentDomain(e,n),r=n.indexOf(t);return n[(r+1)%n.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,n){var t,r=n.target,i=null===(t=r.tagName)||void 0===t?void 0:t.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}}var postfixRE=/[?#].*$/;function cleanUrl(e){return e.replace(postfixRE,"")}function getQueryFromUrl(e){var n=e.split("?")[1];return n?"?".concat(n.split("#")[0]):""}function createElement(e,n){var t=!0===n.crossOrigin?"anonymous":n.crossOrigin,r=t?'crossorigin="'.concat(t,'"'):"",i=n.times?'data-rsbuild-retry-times="'.concat(n.times,'"'):"",a=n.originalQuery?'data-rsbuild-original-query="'.concat(n.originalQuery,'"'):"",o=n.isAsync?"data-rsbuild-async":"";if(e instanceof HTMLScriptElement){var c=document.createElement("script");return c.src=n.url,t&&(c.crossOrigin=t),n.times&&(c.dataset.rsbuildRetryTimes=String(n.times)),n.isAsync&&(c.dataset.rsbuildAsync=""),void 0!==n.originalQuery&&(c.dataset.rsbuildOriginalQuery=n.originalQuery),{element:c,str:'<script src="'.concat(n.url,'" ').concat(r," ").concat(i," ").concat(o," ").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=n.url,t&&(s.crossOrigin=t),n.times&&(s.dataset.rsbuildRetryTimes=String(n.times)),void 0!==n.originalQuery&&(s.dataset.rsbuildOriginalQuery=n.originalQuery),{element:s,str:'<link rel="'.concat(s.rel,'" href="').concat(n.url,'" ').concat(r," ").concat(i," ").concat(s.as?'as="'.concat(s.as,'"'):""," ").concat(a,"></link>")}}}function reloadElementResource(e,n,t){e instanceof HTMLScriptElement&&(t.isAsync?document.body.appendChild(n.element):document.write(n.str)),e instanceof HTMLLinkElement&&document.getElementsByTagName("head")[0].appendChild(n.element),e instanceof HTMLImageElement&&(e.src=t.url,e.dataset.rsbuildRetryTimes=String(t.times),e.dataset.rsbuildOriginalQuery=String(t.originalQuery))}function retry(e,n){var t,r=validateTargetInfo(e,n);if(!1!==r){var i=r.target,a=r.tagName,o=r.url;if("undefined"==typeof window||!Object.keys(window.__RB_ASYNC_CHUNKS__||{}).some((function(e){return-1!==o.indexOf(e)}))){var c=e.test;if(c){if("string"==typeof c){var s=new RegExp(c);c=function(e){return s.test(e)}}if("function"!=typeof c||!c(o))return}var l=findCurrentDomain(o,e.domain);if(!(e.domain&&e.domain.length>0&&-1===e.domain.indexOf(l))){var u=Number(i.dataset.rsbuildRetryTimes)||0;if(u!==e.max){var d=findNextDomain(l,e.domain),f=null!==(t=i.dataset.rsbuildOriginalQuery)&&void 0!==t?t:getQueryFromUrl(o),m=Boolean(i.dataset.rsbuildAsync)||i.async||i.defer,y={url:cleanUrl(o.replace(l,d))+function(n){return!0===e.addQuery?""!==f?"".concat(f,"&retry=").concat(n):"?retry=".concat(n):"function"==typeof e.addQuery?e.addQuery({times:n,originalQuery:f}):""}(u+1),times:u+1,crossOrigin:e.crossOrigin,isAsync:m,originalQuery:f},g=createElement(i,y);if(e.onRetry&&"function"==typeof e.onRetry){var p={times:u,domain:l,url:o,tagName:a};e.onRetry(p)}reloadElementResource(i,g,y)}else if("function"==typeof e.onFail){var v={times:u,domain:l,url:o,tagName:a};e.onFail(v)}}}}}function load(e,n){var t=validateTargetInfo(e,n);if(!1!==t){var r=t.target,i=t.tagName,a=t.url,o=findCurrentDomain(a,e.domain),c=Number(r.dataset.rsbuildRetryTimes)||0;if(0!==c&&"function"==typeof e.onSuccess){var s={times:c,domain:o,url:a,tagName:i};e.onSuccess(s)}}}function resourceMonitor(e,n){"undefined"!=typeof window&&void 0!==window.document&&(document.addEventListener("error",(function(n){n&&n.target instanceof Element&&e(n)}),!0),document.addEventListener("load",(function(e){e&&e.target instanceof Element&&n(e)}),!0))}function init(e){var n={};for(var t in defaultConfig)n[t]=defaultConfig[t];for(var r in e)n[r]=e[r];Array.isArray(n.type)&&0!==n.type.length||(n.type=defaultConfig.type),Array.isArray(n.domain)&&0!==n.domain.length||(n.domain=defaultConfig.domain),Array.isArray(n.domain)&&(n.domain=n.domain.filter(Boolean)),"undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={});try{resourceMonitor((function(e){try{retry(n,e)}catch(e){console.error("retry error captured",e)}}),(function(e){try{load(n,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.14",
|
|
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.14"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.24.5",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"html-webpack-plugin": "npm:html-rspack-plugin@5.7.2",
|
|
35
35
|
"terser": "5.31.0",
|
|
36
36
|
"typescript": "^5.4.2",
|
|
37
|
-
"@rsbuild/core": "0.6.
|
|
38
|
-
"@scripts/test-helper": "0.6.
|
|
37
|
+
"@rsbuild/core": "0.6.14",
|
|
38
|
+
"@scripts/test-helper": "0.6.14"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@rsbuild/core": "^0.6.
|
|
41
|
+
"@rsbuild/core": "^0.6.14"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public",
|