@rsbuild/plugin-assets-retry 1.0.3 → 1.0.5
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 +139 -307
- package/dist/index.js +116 -278
- package/dist/runtime/asyncChunkRetry.d.ts +5 -5
- package/dist/runtime/asyncChunkRetry.js +81 -44
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
|
-
import { fileURLToPath as __webpack_fileURLToPath__ } from "url";
|
|
2
|
-
import { dirname as __webpack_dirname__ } from "path";
|
|
3
1
|
import * as __WEBPACK_EXTERNAL_MODULE_crypto__ from "crypto";
|
|
4
2
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
|
|
5
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
|
|
6
5
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ from "@rsbuild/core";
|
|
7
6
|
var __webpack_modules__ = {
|
|
8
7
|
"../../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")
|
|
8
|
+
module.exports = __webpack_require__("crypto").randomBytes;
|
|
10
9
|
},
|
|
11
10
|
"../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 = [
|
|
11
|
+
var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js"), UID = function() {
|
|
12
|
+
for(var bytes = randomBytes(16), result = '', i = 0; i < 16; ++i)result += bytes[i].toString(16);
|
|
13
|
+
return result;
|
|
14
|
+
}(), PLACE_HOLDER_REGEXP = RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g'), IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g, IS_PURE_FUNCTION = /function.*?\(/, IS_ARROW_FUNCTION = /.*?=>.*?/, UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g, RESERVED_SYMBOLS = [
|
|
26
15
|
'*',
|
|
27
16
|
'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 = {
|
|
17
|
+
], ESCAPED_CHARS = {
|
|
32
18
|
'<': '\\u003C',
|
|
33
19
|
'>': '\\u003E',
|
|
34
20
|
'/': '\\u002F',
|
|
@@ -38,241 +24,118 @@ See the accompanying LICENSE file for terms.
|
|
|
38
24
|
function escapeUnsafeChars(unsafeChar) {
|
|
39
25
|
return ESCAPED_CHARS[unsafeChar];
|
|
40
26
|
}
|
|
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
27
|
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 = {
|
|
28
|
+
options || (options = {}), ('number' == typeof options || 'string' == typeof options) && (options = {
|
|
56
29
|
space: options
|
|
57
|
-
};
|
|
58
|
-
var functions = [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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;
|
|
30
|
+
});
|
|
31
|
+
var str, functions = [], regexps = [], dates = [], maps = [], sets = [], arrays = [], undefs = [], infinities = [], bigInts = [], urls = [];
|
|
32
|
+
return (options.ignoreFunction && "function" == typeof obj && (obj = void 0), void 0 === obj) ? String(obj) : 'string' != typeof (str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : function(key, value) {
|
|
33
|
+
if (options.ignoreFunction && !function(obj) {
|
|
34
|
+
var functionKeys = [];
|
|
35
|
+
for(var key in obj)"function" == typeof obj[key] && functionKeys.push(key);
|
|
36
|
+
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
37
|
+
}(value), !value && void 0 !== value && value !== BigInt(0)) return value;
|
|
38
|
+
var origValue = this[key], type = typeof origValue;
|
|
78
39
|
if ('object' === type) {
|
|
79
40
|
if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
80
41
|
if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
81
42
|
if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
82
43
|
if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
83
|
-
if (origValue instanceof Array) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}).length !== origValue.length;
|
|
87
|
-
if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
88
|
-
}
|
|
44
|
+
if (origValue instanceof Array && origValue.filter(function() {
|
|
45
|
+
return !0;
|
|
46
|
+
}).length !== origValue.length) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
89
47
|
if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
90
48
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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({
|
|
49
|
+
return 'function' === type ? '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@' : 'undefined' === type ? '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@' : 'number' !== type || isNaN(origValue) || isFinite(origValue) ? 'bigint' === type ? '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@' : value : '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
|
|
50
|
+
}, options.space)) ? String(str) : (!0 !== options.unsafe && (str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars)), 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) ? str : str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
|
|
51
|
+
return backSlash ? match : 'D' === type ? "new Date(\"" + dates[valueIndex].toISOString() + "\")" : 'R' === type ? "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")" : 'M' === type ? "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")" : 'S' === type ? "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")" : 'A' === type ? "Array.prototype.slice.call(" + serialize(Object.assign({
|
|
146
52
|
length: arrays[valueIndex].length
|
|
147
|
-
}, arrays[valueIndex]), options) + ")"
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
53
|
+
}, arrays[valueIndex]), options) + ")" : 'U' === type ? 'undefined' : 'I' === type ? infinities[valueIndex] : 'B' === type ? "BigInt(\"" + bigInts[valueIndex] + "\")" : 'L' === type ? "new URL(" + serialize(urls[valueIndex].toString(), options) + ")" : function(fn) {
|
|
54
|
+
var serializedFn = fn.toString();
|
|
55
|
+
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw TypeError('Serializing native function: ' + fn.name);
|
|
56
|
+
if (IS_PURE_FUNCTION.test(serializedFn) || IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
57
|
+
var argsStartsAt = serializedFn.indexOf('('), def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
58
|
+
return val.length > 0;
|
|
59
|
+
});
|
|
60
|
+
return def.filter(function(val) {
|
|
61
|
+
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
62
|
+
}).length > 0 ? (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt) : serializedFn;
|
|
63
|
+
}(functions[valueIndex]);
|
|
154
64
|
});
|
|
155
65
|
};
|
|
156
66
|
},
|
|
157
67
|
crypto: function(module) {
|
|
158
68
|
module.exports = __WEBPACK_EXTERNAL_MODULE_crypto__;
|
|
159
69
|
}
|
|
160
|
-
};
|
|
161
|
-
/************************************************************************/ // The module cache
|
|
162
|
-
var __webpack_module_cache__ = {};
|
|
163
|
-
// The require function
|
|
70
|
+
}, __webpack_module_cache__ = {};
|
|
164
71
|
function __webpack_require__(moduleId) {
|
|
165
|
-
// Check if module is in cache
|
|
166
72
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
167
73
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
168
|
-
// Create a new module (and put it into the cache)
|
|
169
74
|
var module = __webpack_module_cache__[moduleId] = {
|
|
170
75
|
exports: {}
|
|
171
76
|
};
|
|
172
|
-
|
|
173
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
174
|
-
// Return the exports of the module
|
|
175
|
-
return module.exports;
|
|
77
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
176
78
|
}
|
|
177
|
-
|
|
178
|
-
(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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);
|
|
79
|
+
__webpack_require__.n = function(module) {
|
|
80
|
+
var getter = module && module.__esModule ? function() {
|
|
81
|
+
return module.default;
|
|
82
|
+
} : function() {
|
|
83
|
+
return module;
|
|
205
84
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
var
|
|
85
|
+
return __webpack_require__.d(getter, {
|
|
86
|
+
a: getter
|
|
87
|
+
}), getter;
|
|
88
|
+
}, __webpack_require__.d = function(exports, definition) {
|
|
89
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key) && Object.defineProperty(exports, key, {
|
|
90
|
+
enumerable: !0,
|
|
91
|
+
get: definition[key]
|
|
92
|
+
});
|
|
93
|
+
}, __webpack_require__.o = function(obj, prop) {
|
|
94
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
95
|
+
};
|
|
96
|
+
var serialize_javascript = __webpack_require__("../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js"), serialize_javascript_default = __webpack_require__.n(serialize_javascript);
|
|
211
97
|
function _define_property(obj, key, value) {
|
|
212
|
-
|
|
98
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
213
99
|
value: value,
|
|
214
|
-
enumerable:
|
|
215
|
-
configurable:
|
|
216
|
-
writable:
|
|
217
|
-
});
|
|
218
|
-
else obj[key] = value;
|
|
219
|
-
return obj;
|
|
220
|
-
}
|
|
221
|
-
// https://github.com/web-infra-dev/rspack/pull/5370
|
|
222
|
-
function appendWebpackScript(module, appendSource) {
|
|
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
|
-
}
|
|
230
|
-
}
|
|
231
|
-
function appendRspackScript(module, appendSource) {
|
|
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
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function pick(obj, keys) {
|
|
241
|
-
return keys.reduce((ret, key)=>{
|
|
242
|
-
if (void 0 !== obj[key]) ret[key] = obj[key];
|
|
243
|
-
return ret;
|
|
244
|
-
}, {});
|
|
100
|
+
enumerable: !0,
|
|
101
|
+
configurable: !0,
|
|
102
|
+
writable: !0
|
|
103
|
+
}) : obj[key] = value, obj;
|
|
245
104
|
}
|
|
105
|
+
let AsyncChunkRetryPlugin_dirname = __WEBPACK_EXTERNAL_MODULE_node_path__.default.dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url));
|
|
246
106
|
class AsyncChunkRetryPlugin {
|
|
247
107
|
getRawRuntimeRetryCode() {
|
|
248
|
-
|
|
249
|
-
|
|
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));
|
|
108
|
+
let { RuntimeGlobals } = __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.rspack, filename = 'asyncChunkRetry', runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__.default.join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
109
|
+
return __WEBPACK_EXTERNAL_MODULE_node_fs__.default.readFileSync(runtimeFilePath, 'utf-8').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
110
|
}
|
|
254
111
|
apply(compiler) {
|
|
255
112
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
256
113
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
257
114
|
var _module_constructor;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
115
|
+
let { isRspack } = this.options, constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
|
|
116
|
+
if (!('publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName)) return;
|
|
117
|
+
let runtimeCode = this.getRawRuntimeRetryCode();
|
|
118
|
+
isRspack ? !function(module, appendSource) {
|
|
119
|
+
try {
|
|
120
|
+
let source = module.source.source.toString();
|
|
121
|
+
module.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
|
|
122
|
+
} catch (err) {
|
|
123
|
+
throw console.error('Failed to modify Rspack RuntimeModule'), err;
|
|
124
|
+
}
|
|
125
|
+
}(module, runtimeCode) : !function(module, appendSource) {
|
|
126
|
+
try {
|
|
127
|
+
let originSource = module.getGeneratedCode();
|
|
128
|
+
module.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
|
|
129
|
+
} catch (err) {
|
|
130
|
+
throw console.error('Failed to modify Webpack RuntimeModule'), err;
|
|
131
|
+
}
|
|
132
|
+
}(module, runtimeCode);
|
|
267
133
|
});
|
|
268
134
|
});
|
|
269
135
|
}
|
|
270
136
|
constructor(options){
|
|
271
|
-
|
|
272
|
-
_define_property(this, "options", void 0)
|
|
273
|
-
_define_property(this, "runtimeOptions", void 0);
|
|
274
|
-
this.options = options;
|
|
275
|
-
this.runtimeOptions = pick(options, [
|
|
137
|
+
var obj;
|
|
138
|
+
_define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN'), _define_property(this, "options", void 0), _define_property(this, "runtimeOptions", void 0), this.options = options, this.runtimeOptions = (obj = options, [
|
|
276
139
|
'domain',
|
|
277
140
|
'max',
|
|
278
141
|
'onRetry',
|
|
@@ -280,85 +143,61 @@ class AsyncChunkRetryPlugin {
|
|
|
280
143
|
'onFail',
|
|
281
144
|
'addQuery',
|
|
282
145
|
'test'
|
|
283
|
-
]);
|
|
146
|
+
].reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {}));
|
|
284
147
|
}
|
|
285
148
|
}
|
|
286
|
-
|
|
287
|
-
const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
149
|
+
let src_dirname = __WEBPACK_EXTERNAL_MODULE_node_path__.default.dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url)), PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
288
150
|
async function getRetryCode(options) {
|
|
289
|
-
|
|
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');
|
|
151
|
+
let filename = 'initialChunkRetry', { minify, inlineScript: _, ...restOptions } = options, runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__.default.join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`), runtimeCode = await __WEBPACK_EXTERNAL_MODULE_node_fs__.default.promises.readFile(runtimeFilePath, 'utf-8');
|
|
293
152
|
return `(function(){${runtimeCode};init(${serialize_javascript_default()(restOptions)});})()`;
|
|
294
153
|
}
|
|
295
|
-
|
|
296
|
-
let userOptions = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
297
|
-
return {
|
|
154
|
+
let pluginAssetsRetry = (userOptions = {})=>({
|
|
298
155
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
299
156
|
setup (api) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const formatOptions = (config)=>{
|
|
306
|
-
const options = {
|
|
157
|
+
let { inlineScript = !0 } = userOptions, getScriptPath = (environment)=>{
|
|
158
|
+
let distDir = environment.config.output.distPath.js;
|
|
159
|
+
return __WEBPACK_EXTERNAL_MODULE_node_path__.default.posix.join(distDir, "assets-retry.1-0-5.js");
|
|
160
|
+
}, formatOptions = (config)=>{
|
|
161
|
+
let options = {
|
|
307
162
|
...userOptions
|
|
308
163
|
};
|
|
309
|
-
|
|
310
|
-
if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
|
|
311
|
-
if (void 0 === options.minify) {
|
|
164
|
+
if (void 0 === options.crossOrigin && (options.crossOrigin = config.html.crossorigin), void 0 === options.minify) {
|
|
312
165
|
var _config_output_minify;
|
|
313
|
-
|
|
166
|
+
let 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
167
|
options.minify = minify && 'production' === config.mode;
|
|
315
168
|
}
|
|
316
169
|
return options;
|
|
317
170
|
};
|
|
318
|
-
|
|
319
|
-
let
|
|
320
|
-
|
|
321
|
-
headTags.unshift({
|
|
171
|
+
inlineScript ? api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
172
|
+
let code = await getRetryCode(formatOptions(environment.config));
|
|
173
|
+
return headTags.unshift({
|
|
322
174
|
tag: 'script',
|
|
323
175
|
attrs: {},
|
|
324
176
|
children: code
|
|
325
|
-
})
|
|
326
|
-
return {
|
|
177
|
+
}), {
|
|
327
178
|
headTags,
|
|
328
179
|
bodyTags
|
|
329
180
|
};
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
});
|
|
355
|
-
}
|
|
356
|
-
api.modifyBundlerChain(async (chain, param)=>{
|
|
357
|
-
let { environment } = param;
|
|
358
|
-
const { config, htmlPaths } = environment;
|
|
181
|
+
}) : (api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
182
|
+
let scriptPath = getScriptPath(environment), url = (0, __WEBPACK_EXTERNAL_MODULE__rsbuild_core__.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
183
|
+
return headTags.unshift({
|
|
184
|
+
tag: 'script',
|
|
185
|
+
attrs: {
|
|
186
|
+
src: url
|
|
187
|
+
}
|
|
188
|
+
}), {
|
|
189
|
+
headTags,
|
|
190
|
+
bodyTags
|
|
191
|
+
};
|
|
192
|
+
}), api.processAssets({
|
|
193
|
+
stage: 'additional'
|
|
194
|
+
}, async ({ sources, compilation, environment })=>{
|
|
195
|
+
let scriptPath = getScriptPath(environment), code = await getRetryCode(formatOptions(environment.config));
|
|
196
|
+
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
197
|
+
})), api.modifyBundlerChain(async (chain, { environment })=>{
|
|
198
|
+
let { config, htmlPaths } = environment;
|
|
359
199
|
if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
|
|
360
|
-
|
|
361
|
-
const isRspack = 'rspack' === api.context.bundlerType;
|
|
200
|
+
let options = formatOptions(config), isRspack = 'rspack' === api.context.bundlerType;
|
|
362
201
|
chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
|
|
363
202
|
{
|
|
364
203
|
...options,
|
|
@@ -367,6 +206,5 @@ const pluginAssetsRetry = function() {
|
|
|
367
206
|
]);
|
|
368
207
|
});
|
|
369
208
|
}
|
|
370
|
-
};
|
|
371
|
-
};
|
|
209
|
+
});
|
|
372
210
|
export { PLUGIN_ASSETS_RETRY_NAME, pluginAssetsRetry };
|
|
@@ -4,11 +4,11 @@ type ChunkFilename = string;
|
|
|
4
4
|
type ChunkSrcUrl = string;
|
|
5
5
|
declare global {
|
|
6
6
|
var __RUNTIME_GLOBALS_REQUIRE__: unknown;
|
|
7
|
-
var __RUNTIME_GLOBALS_ENSURE_CHUNK__: (chunkId: ChunkId) => Promise<unknown>;
|
|
8
|
-
var __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__: (chunkId: ChunkId) => string;
|
|
9
|
-
var __RUNTIME_GLOBALS_GET_CSS_FILENAME__: ((chunkId: ChunkId) => string) | undefined;
|
|
10
|
-
var __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__: ((chunkId: ChunkId) => string) | undefined;
|
|
11
|
-
var __RUNTIME_GLOBALS_LOAD_SCRIPT__: (url: ChunkSrcUrl, done: unknown, key: string, chunkId: ChunkId) => void;
|
|
7
|
+
var __RUNTIME_GLOBALS_ENSURE_CHUNK__: (chunkId: ChunkId, ...args: unknown[]) => Promise<unknown>;
|
|
8
|
+
var __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__: (chunkId: ChunkId, ...args: unknown[]) => string;
|
|
9
|
+
var __RUNTIME_GLOBALS_GET_CSS_FILENAME__: ((chunkId: ChunkId, ...args: unknown[]) => string) | undefined;
|
|
10
|
+
var __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__: ((chunkId: ChunkId, ...args: unknown[]) => string) | undefined;
|
|
11
|
+
var __RUNTIME_GLOBALS_LOAD_SCRIPT__: (url: ChunkSrcUrl, done: unknown, key: string, chunkId: ChunkId, ...args: unknown[]) => void;
|
|
12
12
|
var __RUNTIME_GLOBALS_PUBLIC_PATH__: string;
|
|
13
13
|
var __RETRY_OPTIONS__: RuntimeRetryOptions;
|
|
14
14
|
var __RB_ASYNC_CHUNKS__: Record<ChunkFilename, boolean>;
|