@rsbuild/plugin-assets-retry 1.4.2 → 1.5.0
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 +17 -11
- package/dist/index.js +16 -10
- package/dist/runtime/asyncChunkRetry.js +1 -1
- package/package.json +18 -17
package/dist/index.cjs
CHANGED
|
@@ -169,9 +169,9 @@ var __webpack_exports__ = {};
|
|
|
169
169
|
"use strict";
|
|
170
170
|
__webpack_require__.r(__webpack_exports__);
|
|
171
171
|
__webpack_require__.d(__webpack_exports__, {
|
|
172
|
-
|
|
172
|
+
PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
|
|
173
173
|
ASSETS_RETRY_DATA_ATTRIBUTE: ()=>ASSETS_RETRY_DATA_ATTRIBUTE,
|
|
174
|
-
|
|
174
|
+
pluginAssetsRetry: ()=>pluginAssetsRetry
|
|
175
175
|
});
|
|
176
176
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
177
177
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
@@ -226,8 +226,7 @@ var __webpack_exports__ = {};
|
|
|
226
226
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
227
227
|
const isRspack = this.isRspack;
|
|
228
228
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
229
|
-
|
|
230
|
-
const constructorName = isRspack ? module.constructorName : null == (_module_constructor = module.constructor) ? void 0 : _module_constructor.name;
|
|
229
|
+
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
231
230
|
const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
|
|
232
231
|
if (isCssLoadingRuntimeModule) return void modifyRuntimeModule(module, (originSource)=>originSource.replace('var fullhref = __webpack_require__.p + href;', 'var fullhref = __webpack_require__.rbLoadStyleSheet ? __webpack_require__.rbLoadStyleSheet(href, chunkId) : (__webpack_require__.p + href);'), isRspack);
|
|
233
232
|
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
@@ -289,24 +288,28 @@ var __webpack_exports__ = {};
|
|
|
289
288
|
const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
|
|
290
289
|
return runtimeCode.replace('__RETRY_OPTIONS__', serialize_javascript_default()(runtimeOptions));
|
|
291
290
|
}
|
|
291
|
+
function logNoHtmlRegisterWaring() {
|
|
292
|
+
core_namespaceObject.logger.warn(`[${PLUGIN_ASSETS_RETRY_NAME}] no HTML files are generated in the current environment, so the "initialChunkRetry" script will not be injected. Please make sure to manually include the assets-retry script in your HTML files if needed.`);
|
|
293
|
+
}
|
|
292
294
|
const pluginAssetsRetry = (userOptions = {})=>({
|
|
293
295
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
294
296
|
setup (api) {
|
|
295
297
|
const { inlineScript = true } = userOptions;
|
|
296
298
|
const getScriptPath = (environment)=>{
|
|
297
299
|
const distDir = environment.config.output.distPath.js;
|
|
298
|
-
return external_node_path_default().posix.join(distDir, "assets-retry.1-
|
|
300
|
+
return external_node_path_default().posix.join(distDir, "assets-retry.1-5-0.js");
|
|
299
301
|
};
|
|
300
302
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
301
|
-
|
|
302
|
-
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null == (_config_output_minify = config.output.minify) ? void 0 : _config_output_minify.js;
|
|
303
|
+
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
|
|
303
304
|
return {
|
|
304
305
|
crossorigin: config.html.crossorigin,
|
|
305
306
|
minify: Boolean(minify) && 'production' === config.mode
|
|
306
307
|
};
|
|
307
308
|
};
|
|
308
309
|
if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
309
|
-
const {
|
|
310
|
+
const { htmlPaths, config } = environment;
|
|
311
|
+
if ('web' === config.output.target && 0 === Object.entries(htmlPaths).length) logNoHtmlRegisterWaring();
|
|
312
|
+
const { minify, crossorigin } = getDefaultValueFromRsbuildConfig(config);
|
|
310
313
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
311
314
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
312
315
|
headTags.unshift({
|
|
@@ -323,6 +326,7 @@ var __webpack_exports__ = {};
|
|
|
323
326
|
});
|
|
324
327
|
else {
|
|
325
328
|
api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
329
|
+
if ('web' === environment.config.output.target && 0 === Object.entries(environment.htmlPaths).length) logNoHtmlRegisterWaring();
|
|
326
330
|
const scriptPath = getScriptPath(environment);
|
|
327
331
|
const url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
328
332
|
headTags.unshift({
|
|
@@ -340,16 +344,18 @@ var __webpack_exports__ = {};
|
|
|
340
344
|
api.processAssets({
|
|
341
345
|
stage: 'additional'
|
|
342
346
|
}, async ({ sources, compilation, environment })=>{
|
|
347
|
+
const { config } = environment;
|
|
348
|
+
if ('web' !== config.output.target) return;
|
|
343
349
|
const scriptPath = getScriptPath(environment);
|
|
344
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(
|
|
350
|
+
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
345
351
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
346
352
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
347
353
|
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
348
354
|
});
|
|
349
355
|
}
|
|
350
356
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
351
|
-
const { config
|
|
352
|
-
if (
|
|
357
|
+
const { config } = environment;
|
|
358
|
+
if ('web' !== config.output.target) return;
|
|
353
359
|
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
354
360
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
355
361
|
const isRspack = 'rspack' === api.context.bundlerType;
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as __WEBPACK_EXTERNAL_MODULE_crypto__ from "crypto";
|
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import node_path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { ensureAssetPrefix, rspack } from "@rsbuild/core";
|
|
5
|
+
import { ensureAssetPrefix, logger, rspack } from "@rsbuild/core";
|
|
6
6
|
var __webpack_modules__ = {
|
|
7
7
|
"./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
8
8
|
module.exports = __webpack_require__("crypto").randomBytes;
|
|
@@ -201,8 +201,7 @@ class AsyncChunkRetryPlugin {
|
|
|
201
201
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
202
202
|
const isRspack = this.isRspack;
|
|
203
203
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
204
|
-
|
|
205
|
-
const constructorName = isRspack ? module.constructorName : null == (_module_constructor = module.constructor) ? void 0 : _module_constructor.name;
|
|
204
|
+
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
206
205
|
const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
|
|
207
206
|
if (isCssLoadingRuntimeModule) return void modifyRuntimeModule(module, (originSource)=>originSource.replace('var fullhref = __webpack_require__.p + href;', 'var fullhref = __webpack_require__.rbLoadStyleSheet ? __webpack_require__.rbLoadStyleSheet(href, chunkId) : (__webpack_require__.p + href);'), isRspack);
|
|
208
207
|
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
@@ -264,24 +263,28 @@ async function getRetryCode(runtimeOptions, minify) {
|
|
|
264
263
|
const runtimeCode = await node_fs.promises.readFile(runtimeFilePath, 'utf-8');
|
|
265
264
|
return runtimeCode.replace('__RETRY_OPTIONS__', serialize_javascript_default()(runtimeOptions));
|
|
266
265
|
}
|
|
266
|
+
function logNoHtmlRegisterWaring() {
|
|
267
|
+
logger.warn(`[${PLUGIN_ASSETS_RETRY_NAME}] no HTML files are generated in the current environment, so the "initialChunkRetry" script will not be injected. Please make sure to manually include the assets-retry script in your HTML files if needed.`);
|
|
268
|
+
}
|
|
267
269
|
const pluginAssetsRetry = (userOptions = {})=>({
|
|
268
270
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
269
271
|
setup (api) {
|
|
270
272
|
const { inlineScript = true } = userOptions;
|
|
271
273
|
const getScriptPath = (environment)=>{
|
|
272
274
|
const distDir = environment.config.output.distPath.js;
|
|
273
|
-
return node_path.posix.join(distDir, "assets-retry.1-
|
|
275
|
+
return node_path.posix.join(distDir, "assets-retry.1-5-0.js");
|
|
274
276
|
};
|
|
275
277
|
const getDefaultValueFromRsbuildConfig = (config)=>{
|
|
276
|
-
|
|
277
|
-
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null == (_config_output_minify = config.output.minify) ? void 0 : _config_output_minify.js;
|
|
278
|
+
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : config.output.minify?.js;
|
|
278
279
|
return {
|
|
279
280
|
crossorigin: config.html.crossorigin,
|
|
280
281
|
minify: Boolean(minify) && 'production' === config.mode
|
|
281
282
|
};
|
|
282
283
|
};
|
|
283
284
|
if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
284
|
-
const {
|
|
285
|
+
const { htmlPaths, config } = environment;
|
|
286
|
+
if ('web' === config.output.target && 0 === Object.entries(htmlPaths).length) logNoHtmlRegisterWaring();
|
|
287
|
+
const { minify, crossorigin } = getDefaultValueFromRsbuildConfig(config);
|
|
285
288
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
286
289
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
287
290
|
headTags.unshift({
|
|
@@ -298,6 +301,7 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
298
301
|
});
|
|
299
302
|
else {
|
|
300
303
|
api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
304
|
+
if ('web' === environment.config.output.target && 0 === Object.entries(environment.htmlPaths).length) logNoHtmlRegisterWaring();
|
|
301
305
|
const scriptPath = getScriptPath(environment);
|
|
302
306
|
const url = ensureAssetPrefix(scriptPath, assetPrefix);
|
|
303
307
|
headTags.unshift({
|
|
@@ -315,16 +319,18 @@ const pluginAssetsRetry = (userOptions = {})=>({
|
|
|
315
319
|
api.processAssets({
|
|
316
320
|
stage: 'additional'
|
|
317
321
|
}, async ({ sources, compilation, environment })=>{
|
|
322
|
+
const { config } = environment;
|
|
323
|
+
if ('web' !== config.output.target) return;
|
|
318
324
|
const scriptPath = getScriptPath(environment);
|
|
319
|
-
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(
|
|
325
|
+
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
320
326
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
321
327
|
const code = await getRetryCode(runtimeOptions, minify);
|
|
322
328
|
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
323
329
|
});
|
|
324
330
|
}
|
|
325
331
|
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
326
|
-
const { config
|
|
327
|
-
if (
|
|
332
|
+
const { config } = environment;
|
|
333
|
+
if ('web' !== config.output.target) return;
|
|
328
334
|
const { crossorigin, minify } = getDefaultValueFromRsbuildConfig(config);
|
|
329
335
|
const runtimeOptions = getRuntimeOptions(userOptions, crossorigin);
|
|
330
336
|
const isRspack = 'rspack' === api.context.bundlerType;
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
}
|
|
145
145
|
if (!callingCounter || 'number' != typeof callingCounter.count || 'number' != typeof callingCounter.cssFailedCount) return result;
|
|
146
146
|
callingCounter.count += 1;
|
|
147
|
-
return result
|
|
147
|
+
return result.catch(function(error) {
|
|
148
148
|
var _error_message;
|
|
149
149
|
var existRetryTimesAll = callingCounter.count - 1;
|
|
150
150
|
var cssExistRetryTimes = callingCounter.cssFailedCount;
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-assets-retry",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "An Rsbuild plugin to automatically resend requests when static assets fail to load.",
|
|
4
5
|
"repository": "https://github.com/rspack-contrib/rsbuild-plugin-assets-retry",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"type": "module",
|
|
@@ -17,34 +18,34 @@
|
|
|
17
18
|
"files": ["dist"],
|
|
18
19
|
"scripts": {
|
|
19
20
|
"build": "rslib build",
|
|
21
|
+
"bump": "npx bumpp",
|
|
20
22
|
"dev": "rslib build --watch",
|
|
21
23
|
"lint": "biome check .",
|
|
22
24
|
"lint:write": "biome check . --write",
|
|
23
25
|
"prepare": "simple-git-hooks && npm run build",
|
|
24
|
-
"test": "playwright test"
|
|
25
|
-
"bump": "npx bumpp"
|
|
26
|
+
"test": "playwright test"
|
|
26
27
|
},
|
|
27
28
|
"simple-git-hooks": {
|
|
28
29
|
"pre-commit": "npm run lint:write"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
|
-
"@microsoft/api-extractor": "^7.52.10",
|
|
32
32
|
"@biomejs/biome": "^1.9.4",
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@rsbuild/
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/react
|
|
33
|
+
"@microsoft/api-extractor": "^7.53.3",
|
|
34
|
+
"@playwright/test": "^1.56.1",
|
|
35
|
+
"@rsbuild/core": "^1.6.0",
|
|
36
|
+
"@rsbuild/plugin-react": "^1.4.1",
|
|
37
|
+
"@rslib/core": "^0.17.0",
|
|
38
|
+
"@swc/core": "^1.14.0",
|
|
39
|
+
"@types/node": "^22.18.13",
|
|
40
|
+
"@types/react": "^19.2.2",
|
|
41
|
+
"@types/react-dom": "^19.2.2",
|
|
41
42
|
"@types/serialize-javascript": "^5.0.4",
|
|
42
|
-
"playwright": "^1.
|
|
43
|
-
"react": "^19.
|
|
44
|
-
"react-dom": "^19.
|
|
43
|
+
"playwright": "^1.56.1",
|
|
44
|
+
"react": "^19.2.0",
|
|
45
|
+
"react-dom": "^19.2.0",
|
|
45
46
|
"serialize-javascript": "^6.0.2",
|
|
46
47
|
"simple-git-hooks": "^2.13.1",
|
|
47
|
-
"typescript": "^5.9.
|
|
48
|
+
"typescript": "^5.9.3"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"@rsbuild/core": "1.x"
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"optional": true
|
|
55
56
|
}
|
|
56
57
|
},
|
|
57
|
-
"packageManager": "pnpm@10.
|
|
58
|
+
"packageManager": "pnpm@10.20.0",
|
|
58
59
|
"publishConfig": {
|
|
59
60
|
"access": "public",
|
|
60
61
|
"registry": "https://registry.npmjs.org/"
|