@rsbuild/plugin-assets-retry 1.0.1 → 1.0.3
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-types → dist}/AsyncChunkRetryPlugin.d.ts +1 -1
- package/dist/index.cjs +387 -222
- package/{dist-types → dist}/index.d.ts +1 -1
- package/dist/index.js +357 -208
- package/{dist-types → dist}/runtime/asyncChunkRetry.d.ts +1 -1
- package/package.json +13 -16
- package/dist-types/package.json +0 -1
- /package/{dist-types → dist}/runtime/initialChunkRetry.d.ts +0 -0
- /package/{dist-types → dist}/types.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,223 +1,372 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
import { fileURLToPath as __webpack_fileURLToPath__ } from "url";
|
|
2
|
+
import { dirname as __webpack_dirname__ } from "path";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_crypto__ from "crypto";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
7
|
+
var __webpack_modules__ = {
|
|
8
|
+
"../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
9
|
+
module.exports = __webpack_require__("crypto")/* .randomBytes */ .randomBytes;
|
|
10
|
+
},
|
|
11
|
+
"../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
12
|
+
/*
|
|
13
|
+
Copyright (c) 2014, Yahoo! Inc. All rights reserved.
|
|
14
|
+
Copyrights licensed under the New BSD License.
|
|
15
|
+
See the accompanying LICENSE file for terms.
|
|
16
|
+
*/ var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js");
|
|
17
|
+
// Generate an internal UID to make the regexp pattern harder to guess.
|
|
18
|
+
var UID_LENGTH = 16;
|
|
19
|
+
var UID = generateUID();
|
|
20
|
+
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
|
|
21
|
+
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
|
22
|
+
var IS_PURE_FUNCTION = /function.*?\(/;
|
|
23
|
+
var IS_ARROW_FUNCTION = /.*?=>.*?/;
|
|
24
|
+
var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
|
|
25
|
+
var RESERVED_SYMBOLS = [
|
|
26
|
+
'*',
|
|
27
|
+
'async'
|
|
28
|
+
];
|
|
29
|
+
// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
|
|
30
|
+
// Unicode char counterparts which are safe to use in JavaScript strings.
|
|
31
|
+
var ESCAPED_CHARS = {
|
|
32
|
+
'<': '\\u003C',
|
|
33
|
+
'>': '\\u003E',
|
|
34
|
+
'/': '\\u002F',
|
|
35
|
+
'\u2028': '\\u2028',
|
|
36
|
+
'\u2029': '\\u2029'
|
|
37
|
+
};
|
|
38
|
+
function escapeUnsafeChars(unsafeChar) {
|
|
39
|
+
return ESCAPED_CHARS[unsafeChar];
|
|
40
|
+
}
|
|
41
|
+
function generateUID() {
|
|
42
|
+
var bytes = randomBytes(UID_LENGTH);
|
|
43
|
+
var result = '';
|
|
44
|
+
for(var i = 0; i < UID_LENGTH; ++i)result += bytes[i].toString(16);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function deleteFunctions(obj) {
|
|
48
|
+
var functionKeys = [];
|
|
49
|
+
for(var key in obj)if ("function" == typeof obj[key]) functionKeys.push(key);
|
|
50
|
+
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
51
|
+
}
|
|
52
|
+
module.exports = function serialize(obj, options) {
|
|
53
|
+
options || (options = {});
|
|
54
|
+
// Backwards-compatibility for `space` as the second argument.
|
|
55
|
+
if ('number' == typeof options || 'string' == typeof options) options = {
|
|
56
|
+
space: options
|
|
57
|
+
};
|
|
58
|
+
var functions = [];
|
|
59
|
+
var regexps = [];
|
|
60
|
+
var dates = [];
|
|
61
|
+
var maps = [];
|
|
62
|
+
var sets = [];
|
|
63
|
+
var arrays = [];
|
|
64
|
+
var undefs = [];
|
|
65
|
+
var infinities = [];
|
|
66
|
+
var bigInts = [];
|
|
67
|
+
var urls = [];
|
|
68
|
+
// Returns placeholders for functions and regexps (identified by index)
|
|
69
|
+
// which are later replaced by their string representation.
|
|
70
|
+
function replacer(key, value) {
|
|
71
|
+
// For nested function
|
|
72
|
+
if (options.ignoreFunction) deleteFunctions(value);
|
|
73
|
+
if (!value && void 0 !== value && value !== BigInt(0)) return value;
|
|
74
|
+
// If the value is an object w/ a toJSON method, toJSON is called before
|
|
75
|
+
// the replacer runs, so we use this[key] to get the non-toJSONed value.
|
|
76
|
+
var origValue = this[key];
|
|
77
|
+
var type = typeof origValue;
|
|
78
|
+
if ('object' === type) {
|
|
79
|
+
if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
80
|
+
if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
81
|
+
if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
82
|
+
if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
83
|
+
if (origValue instanceof Array) {
|
|
84
|
+
var isSparse = origValue.filter(function() {
|
|
85
|
+
return true;
|
|
86
|
+
}).length !== origValue.length;
|
|
87
|
+
if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
88
|
+
}
|
|
89
|
+
if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
90
|
+
}
|
|
91
|
+
if ('function' === type) return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
|
|
92
|
+
if ('undefined' === type) return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
|
|
93
|
+
if ('number' === type && !isNaN(origValue) && !isFinite(origValue)) return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
|
|
94
|
+
if ('bigint' === type) return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
function serializeFunc(fn) {
|
|
98
|
+
var serializedFn = fn.toString();
|
|
99
|
+
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw new TypeError('Serializing native function: ' + fn.name);
|
|
100
|
+
// pure functions, example: {key: function() {}}
|
|
101
|
+
if (IS_PURE_FUNCTION.test(serializedFn)) return serializedFn;
|
|
102
|
+
// arrow functions, example: arg1 => arg1+5
|
|
103
|
+
if (IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
104
|
+
var argsStartsAt = serializedFn.indexOf('(');
|
|
105
|
+
var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
106
|
+
return val.length > 0;
|
|
107
|
+
});
|
|
108
|
+
var nonReservedSymbols = def.filter(function(val) {
|
|
109
|
+
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
110
|
+
});
|
|
111
|
+
// enhanced literal objects, example: {key() {}}
|
|
112
|
+
if (nonReservedSymbols.length > 0) return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
|
|
113
|
+
// arrow functions
|
|
114
|
+
return serializedFn;
|
|
115
|
+
}
|
|
116
|
+
// Check if the parameter is function
|
|
117
|
+
if (options.ignoreFunction && "function" == typeof obj) obj = void 0;
|
|
118
|
+
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
119
|
+
// to the literal string: "undefined".
|
|
120
|
+
if (void 0 === obj) return String(obj);
|
|
121
|
+
var str;
|
|
122
|
+
// Creates a JSON string representation of the value.
|
|
123
|
+
// NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
|
|
124
|
+
str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
|
|
125
|
+
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
126
|
+
// to the literal string: "undefined".
|
|
127
|
+
if ('string' != typeof str) return String(str);
|
|
128
|
+
// Replace unsafe HTML and invalid JavaScript line terminator chars with
|
|
129
|
+
// their safe Unicode char counterpart. This _must_ happen before the
|
|
130
|
+
// regexps and functions are serialized and added back to the string.
|
|
131
|
+
if (true !== options.unsafe) str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
|
132
|
+
if (0 === functions.length && 0 === regexps.length && 0 === dates.length && 0 === maps.length && 0 === sets.length && 0 === arrays.length && 0 === undefs.length && 0 === infinities.length && 0 === bigInts.length && 0 === urls.length) return str;
|
|
133
|
+
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
|
|
134
|
+
// JSON string with their string representations. If the original value can
|
|
135
|
+
// not be found, then `undefined` is used.
|
|
136
|
+
return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
|
|
137
|
+
// The placeholder may not be preceded by a backslash. This is to prevent
|
|
138
|
+
// replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
|
|
139
|
+
// invalid JS.
|
|
140
|
+
if (backSlash) return match;
|
|
141
|
+
if ('D' === type) return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
|
|
142
|
+
if ('R' === type) return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
|
|
143
|
+
if ('M' === type) return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
|
|
144
|
+
if ('S' === type) return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
|
|
145
|
+
if ('A' === type) return "Array.prototype.slice.call(" + serialize(Object.assign({
|
|
146
|
+
length: arrays[valueIndex].length
|
|
147
|
+
}, arrays[valueIndex]), options) + ")";
|
|
148
|
+
if ('U' === type) return 'undefined';
|
|
149
|
+
if ('I' === type) return infinities[valueIndex];
|
|
150
|
+
if ('B' === type) return "BigInt(\"" + bigInts[valueIndex] + "\")";
|
|
151
|
+
if ('L' === type) return "new URL(" + serialize(urls[valueIndex].toString(), options) + ")";
|
|
152
|
+
var fn = functions[valueIndex];
|
|
153
|
+
return serializeFunc(fn);
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
crypto: function(module) {
|
|
158
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_crypto__;
|
|
159
|
+
}
|
|
17
160
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
161
|
+
/************************************************************************/ // The module cache
|
|
162
|
+
var __webpack_module_cache__ = {};
|
|
163
|
+
// The require function
|
|
164
|
+
function __webpack_require__(moduleId) {
|
|
165
|
+
// Check if module is in cache
|
|
166
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
167
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
168
|
+
// Create a new module (and put it into the cache)
|
|
169
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
170
|
+
exports: {}
|
|
171
|
+
};
|
|
172
|
+
// Execute the module function
|
|
173
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
174
|
+
// Return the exports of the module
|
|
175
|
+
return module.exports;
|
|
176
|
+
}
|
|
177
|
+
/************************************************************************/ // webpack/runtime/compat_get_default_export
|
|
178
|
+
(()=>{
|
|
179
|
+
// getDefaultExport function for compatibility with non-harmony modules
|
|
180
|
+
__webpack_require__.n = function(module) {
|
|
181
|
+
var getter = module && module.__esModule ? function() {
|
|
182
|
+
return module['default'];
|
|
183
|
+
} : function() {
|
|
184
|
+
return module;
|
|
185
|
+
};
|
|
186
|
+
__webpack_require__.d(getter, {
|
|
187
|
+
a: getter
|
|
188
|
+
});
|
|
189
|
+
return getter;
|
|
190
|
+
};
|
|
191
|
+
})();
|
|
192
|
+
// webpack/runtime/define_property_getters
|
|
193
|
+
(()=>{
|
|
194
|
+
__webpack_require__.d = function(exports, definition) {
|
|
195
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
get: definition[key]
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
})();
|
|
201
|
+
// webpack/runtime/has_own_property
|
|
202
|
+
(()=>{
|
|
203
|
+
__webpack_require__.o = function(obj, prop) {
|
|
204
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
205
|
+
};
|
|
206
|
+
})(); /************************************************************************/
|
|
207
|
+
// EXTERNAL MODULE: ../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js
|
|
208
|
+
var serialize_javascript = __webpack_require__("../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js");
|
|
209
|
+
var serialize_javascript_default = /*#__PURE__*/ __webpack_require__.n(serialize_javascript);
|
|
210
|
+
var AsyncChunkRetryPlugin_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
211
|
+
function _define_property(obj, key, value) {
|
|
212
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
213
|
+
value: value,
|
|
214
|
+
enumerable: true,
|
|
215
|
+
configurable: true,
|
|
216
|
+
writable: true
|
|
217
|
+
});
|
|
218
|
+
else obj[key] = value;
|
|
219
|
+
return obj;
|
|
220
|
+
}
|
|
221
|
+
// https://github.com/web-infra-dev/rspack/pull/5370
|
|
41
222
|
function appendWebpackScript(module, appendSource) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
223
|
+
try {
|
|
224
|
+
const originSource = module.getGeneratedCode();
|
|
225
|
+
module.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
|
|
226
|
+
} catch (err) {
|
|
227
|
+
console.error('Failed to modify Webpack RuntimeModule');
|
|
228
|
+
throw err;
|
|
229
|
+
}
|
|
50
230
|
}
|
|
51
231
|
function appendRspackScript(module, appendSource) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
232
|
+
try {
|
|
233
|
+
const source = module.source.source.toString();
|
|
234
|
+
module.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
|
|
235
|
+
} catch (err) {
|
|
236
|
+
console.error('Failed to modify Rspack RuntimeModule');
|
|
237
|
+
throw err;
|
|
238
|
+
}
|
|
60
239
|
}
|
|
61
240
|
function pick(obj, keys) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
return ret;
|
|
68
|
-
},
|
|
69
|
-
{}
|
|
70
|
-
);
|
|
241
|
+
return keys.reduce((ret, key)=>{
|
|
242
|
+
if (void 0 !== obj[key]) ret[key] = obj[key];
|
|
243
|
+
return ret;
|
|
244
|
+
}, {});
|
|
71
245
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
246
|
+
class AsyncChunkRetryPlugin {
|
|
247
|
+
getRawRuntimeRetryCode() {
|
|
248
|
+
const { RuntimeGlobals } = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack;
|
|
249
|
+
const filename = 'asyncChunkRetry';
|
|
250
|
+
const runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
251
|
+
const rawText = __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(runtimeFilePath, 'utf-8');
|
|
252
|
+
return rawText.replaceAll('__RUNTIME_GLOBALS_REQUIRE__', RuntimeGlobals.require).replaceAll('__RUNTIME_GLOBALS_ENSURE_CHUNK__', RuntimeGlobals.ensureChunk).replaceAll('__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__', RuntimeGlobals.getChunkScriptFilename).replaceAll('__RUNTIME_GLOBALS_GET_CSS_FILENAME__', RuntimeGlobals.getChunkCssFilename).replaceAll('__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__', '__webpack_require__.miniCssF').replaceAll('__RUNTIME_GLOBALS_PUBLIC_PATH__', RuntimeGlobals.publicPath).replaceAll('__RUNTIME_GLOBALS_LOAD_SCRIPT__', RuntimeGlobals.loadScript).replaceAll('__RETRY_OPTIONS__', serialize_javascript_default()(this.runtimeOptions));
|
|
253
|
+
}
|
|
254
|
+
apply(compiler) {
|
|
255
|
+
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
256
|
+
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
257
|
+
var _module_constructor;
|
|
258
|
+
const { isRspack } = this.options;
|
|
259
|
+
const constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
|
|
260
|
+
const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
|
|
261
|
+
if (!isPublicPathModule) return;
|
|
262
|
+
const runtimeCode = this.getRawRuntimeRetryCode();
|
|
263
|
+
// Rspack currently does not have module.addRuntimeModule on the js side,
|
|
264
|
+
// so we insert our runtime code after PublicPathRuntimeModule or AutoPublicPathRuntimeModule.
|
|
265
|
+
if (isRspack) appendRspackScript(module, runtimeCode);
|
|
266
|
+
else appendWebpackScript(module, runtimeCode);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
constructor(options){
|
|
271
|
+
_define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN');
|
|
272
|
+
_define_property(this, "options", void 0);
|
|
273
|
+
_define_property(this, "runtimeOptions", void 0);
|
|
82
274
|
this.options = options;
|
|
83
275
|
this.runtimeOptions = pick(options, [
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
276
|
+
'domain',
|
|
277
|
+
'max',
|
|
278
|
+
'onRetry',
|
|
279
|
+
'onSuccess',
|
|
280
|
+
'onFail',
|
|
281
|
+
'addQuery',
|
|
282
|
+
'test'
|
|
91
283
|
]);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const runtimeFilePath = path2.join(
|
|
97
|
-
__dirname,
|
|
98
|
-
"runtime",
|
|
99
|
-
this.options.minify ? `${filename}.min.js` : `${filename}.js`
|
|
100
|
-
);
|
|
101
|
-
const rawText = fs.readFileSync(runtimeFilePath, "utf-8");
|
|
102
|
-
return rawText.replaceAll("__RUNTIME_GLOBALS_REQUIRE__", RuntimeGlobals.require).replaceAll(
|
|
103
|
-
"__RUNTIME_GLOBALS_ENSURE_CHUNK__",
|
|
104
|
-
RuntimeGlobals.ensureChunk
|
|
105
|
-
).replaceAll(
|
|
106
|
-
"__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__",
|
|
107
|
-
RuntimeGlobals.getChunkScriptFilename
|
|
108
|
-
).replaceAll(
|
|
109
|
-
"__RUNTIME_GLOBALS_GET_CSS_FILENAME__",
|
|
110
|
-
RuntimeGlobals.getChunkCssFilename
|
|
111
|
-
).replaceAll(
|
|
112
|
-
"__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__",
|
|
113
|
-
"__webpack_require__.miniCssF"
|
|
114
|
-
).replaceAll("__RUNTIME_GLOBALS_PUBLIC_PATH__", RuntimeGlobals.publicPath).replaceAll("__RUNTIME_GLOBALS_LOAD_SCRIPT__", RuntimeGlobals.loadScript).replaceAll("__RETRY_OPTIONS__", serialize(this.runtimeOptions));
|
|
115
|
-
}
|
|
116
|
-
apply(compiler) {
|
|
117
|
-
compiler.hooks.thisCompilation.tap(this.name, (compilation) => {
|
|
118
|
-
compilation.hooks.runtimeModule.tap(this.name, (module) => {
|
|
119
|
-
const { isRspack } = this.options;
|
|
120
|
-
const constructorName = isRspack ? module.constructorName : module.constructor?.name;
|
|
121
|
-
const isPublicPathModule = module.name === "publicPath" || constructorName === "PublicPathRuntimeModule" || constructorName === "AutoPublicPathRuntimeModule";
|
|
122
|
-
if (!isPublicPathModule) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const runtimeCode = this.getRawRuntimeRetryCode();
|
|
126
|
-
if (isRspack) {
|
|
127
|
-
appendRspackScript(module, runtimeCode);
|
|
128
|
-
} else {
|
|
129
|
-
appendWebpackScript(module, runtimeCode);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// src/index.ts
|
|
139
|
-
init_esm();
|
|
140
|
-
import fs2 from "fs";
|
|
141
|
-
import path3 from "path";
|
|
142
|
-
import { ensureAssetPrefix } from "@rsbuild/core";
|
|
143
|
-
var PLUGIN_ASSETS_RETRY_NAME = "rsbuild:assets-retry";
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
var src_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
287
|
+
const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
144
288
|
async function getRetryCode(options) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
"runtime",
|
|
151
|
-
minify ? `${filename}.min.js` : `${filename}.js`
|
|
152
|
-
);
|
|
153
|
-
const runtimeCode = await fs2.promises.readFile(runtimeFilePath, "utf-8");
|
|
154
|
-
return `(function(){${runtimeCode};init(${serialize2(restOptions)});})()`;
|
|
289
|
+
const filename = 'initialChunkRetry';
|
|
290
|
+
const { minify, inlineScript: _, ...restOptions } = options;
|
|
291
|
+
const runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
|
|
292
|
+
const runtimeCode = await __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].promises.readFile(runtimeFilePath, 'utf-8');
|
|
293
|
+
return `(function(){${runtimeCode};init(${serialize_javascript_default()(restOptions)});})()`;
|
|
155
294
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
295
|
+
const pluginAssetsRetry = function() {
|
|
296
|
+
let userOptions = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
297
|
+
return {
|
|
298
|
+
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
299
|
+
setup (api) {
|
|
300
|
+
const { inlineScript = true } = userOptions;
|
|
301
|
+
const getScriptPath = (environment)=>{
|
|
302
|
+
const distDir = environment.config.output.distPath.js;
|
|
303
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__["default"].posix.join(distDir, "assets-retry.1-0-3.js");
|
|
304
|
+
};
|
|
305
|
+
const formatOptions = (config)=>{
|
|
306
|
+
const options = {
|
|
307
|
+
...userOptions
|
|
308
|
+
};
|
|
309
|
+
// options.crossOrigin should be same as html.crossorigin by default
|
|
310
|
+
if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
|
|
311
|
+
if (void 0 === options.minify) {
|
|
312
|
+
var _config_output_minify;
|
|
313
|
+
const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null === (_config_output_minify = config.output.minify) || void 0 === _config_output_minify ? void 0 : _config_output_minify.js;
|
|
314
|
+
options.minify = minify && 'production' === config.mode;
|
|
315
|
+
}
|
|
316
|
+
return options;
|
|
317
|
+
};
|
|
318
|
+
if (inlineScript) api.modifyHTMLTags(async (param, param1)=>{
|
|
319
|
+
let { headTags, bodyTags } = param, { environment } = param1;
|
|
320
|
+
const code = await getRetryCode(formatOptions(environment.config));
|
|
321
|
+
headTags.unshift({
|
|
322
|
+
tag: 'script',
|
|
323
|
+
attrs: {},
|
|
324
|
+
children: code
|
|
325
|
+
});
|
|
326
|
+
return {
|
|
327
|
+
headTags,
|
|
328
|
+
bodyTags
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
else {
|
|
332
|
+
api.modifyHTMLTags(async (param, param1)=>{
|
|
333
|
+
let { headTags, bodyTags } = param, { assetPrefix, environment } = param1;
|
|
334
|
+
const scriptPath = getScriptPath(environment);
|
|
335
|
+
const url = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
336
|
+
headTags.unshift({
|
|
337
|
+
tag: 'script',
|
|
338
|
+
attrs: {
|
|
339
|
+
src: url
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
headTags,
|
|
344
|
+
bodyTags
|
|
345
|
+
};
|
|
346
|
+
});
|
|
347
|
+
api.processAssets({
|
|
348
|
+
stage: 'additional'
|
|
349
|
+
}, async (param)=>{
|
|
350
|
+
let { sources, compilation, environment } = param;
|
|
351
|
+
const scriptPath = getScriptPath(environment);
|
|
352
|
+
const code = await getRetryCode(formatOptions(environment.config));
|
|
353
|
+
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
354
|
+
});
|
|
194
355
|
}
|
|
195
|
-
|
|
196
|
-
|
|
356
|
+
api.modifyBundlerChain(async (chain, param)=>{
|
|
357
|
+
let { environment } = param;
|
|
358
|
+
const { config, htmlPaths } = environment;
|
|
359
|
+
if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
|
|
360
|
+
const options = formatOptions(config);
|
|
361
|
+
const isRspack = 'rspack' === api.context.bundlerType;
|
|
362
|
+
chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
|
|
363
|
+
{
|
|
364
|
+
...options,
|
|
365
|
+
isRspack
|
|
366
|
+
}
|
|
367
|
+
]);
|
|
368
|
+
});
|
|
197
369
|
}
|
|
198
|
-
|
|
199
|
-
api.processAssets(
|
|
200
|
-
{ stage: "additional" },
|
|
201
|
-
async ({ sources, compilation, environment }) => {
|
|
202
|
-
const scriptPath = getScriptPath(environment);
|
|
203
|
-
const code = await getRetryCode(formatOptions(environment.config));
|
|
204
|
-
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
api.modifyBundlerChain(async (chain, { environment }) => {
|
|
209
|
-
const { config, htmlPaths } = environment;
|
|
210
|
-
if (!userOptions || Object.keys(htmlPaths).length === 0) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const { AsyncChunkRetryPlugin: AsyncChunkRetryPlugin2 } = await Promise.resolve().then(() => (init_AsyncChunkRetryPlugin(), AsyncChunkRetryPlugin_exports));
|
|
214
|
-
const options = formatOptions(config);
|
|
215
|
-
const isRspack = api.context.bundlerType === "rspack";
|
|
216
|
-
chain.plugin("async-chunk-retry").use(AsyncChunkRetryPlugin2, [{ ...options, isRspack }]);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
export {
|
|
221
|
-
PLUGIN_ASSETS_RETRY_NAME,
|
|
222
|
-
pluginAssetsRetry
|
|
370
|
+
};
|
|
223
371
|
};
|
|
372
|
+
export { PLUGIN_ASSETS_RETRY_NAME, pluginAssetsRetry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsbuild/plugin-assets-retry",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Assets retry plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -12,28 +12,25 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"types": "./dist
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"require": "./dist/index.cjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"main": "./dist/index.cjs",
|
|
21
|
-
"types": "./dist
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
"dist-types"
|
|
23
|
+
"dist"
|
|
25
24
|
],
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"serialize-javascript": "^6.0.2"
|
|
28
|
-
},
|
|
29
25
|
"devDependencies": {
|
|
30
|
-
"@babel/core": "^7.25.
|
|
31
|
-
"@babel/preset-env": "^7.25.
|
|
32
|
-
"@babel/preset-typescript": "^7.
|
|
26
|
+
"@babel/core": "^7.25.8",
|
|
27
|
+
"@babel/preset-env": "^7.25.8",
|
|
28
|
+
"@babel/preset-typescript": "^7.25.7",
|
|
33
29
|
"@types/serialize-javascript": "^5.0.4",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
30
|
+
"serialize-javascript": "^6.0.2",
|
|
31
|
+
"terser": "5.35.0",
|
|
32
|
+
"typescript": "^5.6.3",
|
|
33
|
+
"@rsbuild/core": "1.0.15"
|
|
37
34
|
},
|
|
38
35
|
"peerDependencies": {
|
|
39
36
|
"@rsbuild/core": "1.x || ^1.0.1-rc.0"
|
|
@@ -44,7 +41,7 @@
|
|
|
44
41
|
"registry": "https://registry.npmjs.org/"
|
|
45
42
|
},
|
|
46
43
|
"scripts": {
|
|
47
|
-
"build": "
|
|
48
|
-
"dev": "
|
|
44
|
+
"build": "rslib build && node scripts/postCompile.mjs",
|
|
45
|
+
"dev": "rslib build --watch"
|
|
49
46
|
}
|
|
50
47
|
}
|
package/dist-types/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"//":"This file is for making TypeScript work with moduleResolution node16+.","version":"1.0.0"}
|