@rsbuild/plugin-assets-retry 1.0.4 → 1.0.6
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 -306
- package/dist/index.js +114 -268
- package/dist/runtime/asyncChunkRetry.d.ts +5 -5
- package/dist/runtime/asyncChunkRetry.js +46 -20
- package/dist/runtime/asyncChunkRetry.min.js +1 -1
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
|
+
let __rslib_import_meta_url__ = 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
1
2
|
var __webpack_modules__ = {
|
|
2
|
-
"../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(
|
|
3
|
-
|
|
3
|
+
"../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
4
|
+
module.exports = __webpack_require__("crypto").randomBytes;
|
|
4
5
|
},
|
|
5
|
-
"../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(
|
|
6
|
+
"../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
6
7
|
"use strict";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/ var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js");
|
|
12
|
-
// Generate an internal UID to make the regexp pattern harder to guess.
|
|
13
|
-
var UID_LENGTH = 16;
|
|
14
|
-
var UID = generateUID();
|
|
15
|
-
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
|
|
16
|
-
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
|
17
|
-
var IS_PURE_FUNCTION = /function.*?\(/;
|
|
18
|
-
var IS_ARROW_FUNCTION = /.*?=>.*?/;
|
|
19
|
-
var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
|
|
20
|
-
var RESERVED_SYMBOLS = [
|
|
8
|
+
var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js"), UID = function() {
|
|
9
|
+
for(var bytes = randomBytes(16), result = '', i = 0; i < 16; ++i)result += bytes[i].toString(16);
|
|
10
|
+
return result;
|
|
11
|
+
}(), 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 = [
|
|
21
12
|
'*',
|
|
22
13
|
'async'
|
|
23
|
-
]
|
|
24
|
-
// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
|
|
25
|
-
// Unicode char counterparts which are safe to use in JavaScript strings.
|
|
26
|
-
var ESCAPED_CHARS = {
|
|
14
|
+
], ESCAPED_CHARS = {
|
|
27
15
|
'<': '\\u003C',
|
|
28
16
|
'>': '\\u003E',
|
|
29
17
|
'/': '\\u002F',
|
|
@@ -33,273 +21,138 @@ See the accompanying LICENSE file for terms.
|
|
|
33
21
|
function escapeUnsafeChars(unsafeChar) {
|
|
34
22
|
return ESCAPED_CHARS[unsafeChar];
|
|
35
23
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
var result = '';
|
|
39
|
-
for(var i = 0; i < UID_LENGTH; ++i)result += bytes[i].toString(16);
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
function deleteFunctions(obj) {
|
|
43
|
-
var functionKeys = [];
|
|
44
|
-
for(var key in obj)if ("function" == typeof obj[key]) functionKeys.push(key);
|
|
45
|
-
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
46
|
-
}
|
|
47
|
-
module1.exports = function serialize(obj, options) {
|
|
48
|
-
options || (options = {});
|
|
49
|
-
// Backwards-compatibility for `space` as the second argument.
|
|
50
|
-
if ('number' == typeof options || 'string' == typeof options) options = {
|
|
24
|
+
module.exports = function serialize(obj, options) {
|
|
25
|
+
options || (options = {}), ('number' == typeof options || 'string' == typeof options) && (options = {
|
|
51
26
|
space: options
|
|
52
|
-
};
|
|
53
|
-
var functions = [];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var bigInts = [];
|
|
62
|
-
var urls = [];
|
|
63
|
-
// Returns placeholders for functions and regexps (identified by index)
|
|
64
|
-
// which are later replaced by their string representation.
|
|
65
|
-
function replacer(key, value) {
|
|
66
|
-
// For nested function
|
|
67
|
-
if (options.ignoreFunction) deleteFunctions(value);
|
|
68
|
-
if (!value && void 0 !== value && value !== BigInt(0)) return value;
|
|
69
|
-
// If the value is an object w/ a toJSON method, toJSON is called before
|
|
70
|
-
// the replacer runs, so we use this[key] to get the non-toJSONed value.
|
|
71
|
-
var origValue = this[key];
|
|
72
|
-
var type = typeof origValue;
|
|
27
|
+
});
|
|
28
|
+
var str, functions = [], regexps = [], dates = [], maps = [], sets = [], arrays = [], undefs = [], infinities = [], bigInts = [], urls = [];
|
|
29
|
+
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) {
|
|
30
|
+
if (options.ignoreFunction && !function(obj) {
|
|
31
|
+
var functionKeys = [];
|
|
32
|
+
for(var key in obj)"function" == typeof obj[key] && functionKeys.push(key);
|
|
33
|
+
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
34
|
+
}(value), !value && void 0 !== value && value !== BigInt(0)) return value;
|
|
35
|
+
var origValue = this[key], type = typeof origValue;
|
|
73
36
|
if ('object' === type) {
|
|
74
37
|
if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
75
38
|
if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
76
39
|
if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
77
40
|
if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
78
|
-
if (origValue instanceof Array) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}).length !== origValue.length;
|
|
82
|
-
if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
83
|
-
}
|
|
41
|
+
if (origValue instanceof Array && origValue.filter(function() {
|
|
42
|
+
return !0;
|
|
43
|
+
}).length !== origValue.length) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
84
44
|
if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
85
45
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if ('bigint' === type) return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
|
|
90
|
-
return value;
|
|
91
|
-
}
|
|
92
|
-
function serializeFunc(fn) {
|
|
93
|
-
var serializedFn = fn.toString();
|
|
94
|
-
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw new TypeError('Serializing native function: ' + fn.name);
|
|
95
|
-
// pure functions, example: {key: function() {}}
|
|
96
|
-
if (IS_PURE_FUNCTION.test(serializedFn)) return serializedFn;
|
|
97
|
-
// arrow functions, example: arg1 => arg1+5
|
|
98
|
-
if (IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
99
|
-
var argsStartsAt = serializedFn.indexOf('(');
|
|
100
|
-
var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
101
|
-
return val.length > 0;
|
|
102
|
-
});
|
|
103
|
-
var nonReservedSymbols = def.filter(function(val) {
|
|
104
|
-
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
105
|
-
});
|
|
106
|
-
// enhanced literal objects, example: {key() {}}
|
|
107
|
-
if (nonReservedSymbols.length > 0) return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
|
|
108
|
-
// arrow functions
|
|
109
|
-
return serializedFn;
|
|
110
|
-
}
|
|
111
|
-
// Check if the parameter is function
|
|
112
|
-
if (options.ignoreFunction && "function" == typeof obj) obj = void 0;
|
|
113
|
-
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
114
|
-
// to the literal string: "undefined".
|
|
115
|
-
if (void 0 === obj) return String(obj);
|
|
116
|
-
var str;
|
|
117
|
-
// Creates a JSON string representation of the value.
|
|
118
|
-
// NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
|
|
119
|
-
str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
|
|
120
|
-
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
121
|
-
// to the literal string: "undefined".
|
|
122
|
-
if ('string' != typeof str) return String(str);
|
|
123
|
-
// Replace unsafe HTML and invalid JavaScript line terminator chars with
|
|
124
|
-
// their safe Unicode char counterpart. This _must_ happen before the
|
|
125
|
-
// regexps and functions are serialized and added back to the string.
|
|
126
|
-
if (true !== options.unsafe) str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
|
127
|
-
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;
|
|
128
|
-
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
|
|
129
|
-
// JSON string with their string representations. If the original value can
|
|
130
|
-
// not be found, then `undefined` is used.
|
|
131
|
-
return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
|
|
132
|
-
// The placeholder may not be preceded by a backslash. This is to prevent
|
|
133
|
-
// replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
|
|
134
|
-
// invalid JS.
|
|
135
|
-
if (backSlash) return match;
|
|
136
|
-
if ('D' === type) return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
|
|
137
|
-
if ('R' === type) return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
|
|
138
|
-
if ('M' === type) return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
|
|
139
|
-
if ('S' === type) return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
|
|
140
|
-
if ('A' === type) return "Array.prototype.slice.call(" + serialize(Object.assign({
|
|
46
|
+
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) + '__@';
|
|
47
|
+
}, 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) {
|
|
48
|
+
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({
|
|
141
49
|
length: arrays[valueIndex].length
|
|
142
|
-
}, arrays[valueIndex]), options) + ")"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
50
|
+
}, 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) {
|
|
51
|
+
var serializedFn = fn.toString();
|
|
52
|
+
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw TypeError('Serializing native function: ' + fn.name);
|
|
53
|
+
if (IS_PURE_FUNCTION.test(serializedFn) || IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
54
|
+
var argsStartsAt = serializedFn.indexOf('('), def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
55
|
+
return val.length > 0;
|
|
56
|
+
});
|
|
57
|
+
return def.filter(function(val) {
|
|
58
|
+
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
59
|
+
}).length > 0 ? (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt) : serializedFn;
|
|
60
|
+
}(functions[valueIndex]);
|
|
149
61
|
});
|
|
150
62
|
};
|
|
151
63
|
},
|
|
152
|
-
crypto: function(
|
|
64
|
+
crypto: function(module) {
|
|
153
65
|
"use strict";
|
|
154
|
-
|
|
66
|
+
module.exports = require("crypto");
|
|
155
67
|
}
|
|
156
|
-
};
|
|
157
|
-
/************************************************************************/ // The module cache
|
|
158
|
-
var __webpack_module_cache__ = {};
|
|
159
|
-
// The require function
|
|
68
|
+
}, __webpack_module_cache__ = {};
|
|
160
69
|
function __webpack_require__(moduleId) {
|
|
161
|
-
// Check if module is in cache
|
|
162
70
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
163
71
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
164
|
-
|
|
165
|
-
var module1 = __webpack_module_cache__[moduleId] = {
|
|
72
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
166
73
|
exports: {}
|
|
167
74
|
};
|
|
168
|
-
|
|
169
|
-
__webpack_modules__[moduleId](module1, module1.exports, __webpack_require__);
|
|
170
|
-
// Return the exports of the module
|
|
171
|
-
return module1.exports;
|
|
75
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
172
76
|
}
|
|
173
|
-
|
|
174
|
-
(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return module1['default'];
|
|
179
|
-
} : function() {
|
|
180
|
-
return module1;
|
|
181
|
-
};
|
|
182
|
-
__webpack_require__.d(getter, {
|
|
183
|
-
a: getter
|
|
184
|
-
});
|
|
185
|
-
return getter;
|
|
186
|
-
};
|
|
187
|
-
})();
|
|
188
|
-
// webpack/runtime/define_property_getters
|
|
189
|
-
(()=>{
|
|
190
|
-
__webpack_require__.d = function(exports1, definition) {
|
|
191
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
192
|
-
enumerable: true,
|
|
193
|
-
get: definition[key]
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
})();
|
|
197
|
-
// webpack/runtime/has_own_property
|
|
198
|
-
(()=>{
|
|
199
|
-
__webpack_require__.o = function(obj, prop) {
|
|
200
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
201
|
-
};
|
|
202
|
-
})();
|
|
203
|
-
// webpack/runtime/make_namespace_object
|
|
204
|
-
(()=>{
|
|
205
|
-
// define __esModule on exports
|
|
206
|
-
__webpack_require__.r = function(exports1) {
|
|
207
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
208
|
-
value: 'Module'
|
|
209
|
-
});
|
|
210
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
211
|
-
value: true
|
|
212
|
-
});
|
|
77
|
+
__webpack_require__.n = function(module) {
|
|
78
|
+
var getter = module && module.__esModule ? function() {
|
|
79
|
+
return module.default;
|
|
80
|
+
} : function() {
|
|
81
|
+
return module;
|
|
213
82
|
};
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
83
|
+
return __webpack_require__.d(getter, {
|
|
84
|
+
a: getter
|
|
85
|
+
}), getter;
|
|
86
|
+
}, __webpack_require__.d = function(exports1, definition) {
|
|
87
|
+
for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
|
|
88
|
+
enumerable: !0,
|
|
89
|
+
get: definition[key]
|
|
90
|
+
});
|
|
91
|
+
}, __webpack_require__.o = function(obj, prop) {
|
|
92
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
93
|
+
}, __webpack_require__.r = function(exports1) {
|
|
94
|
+
'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
95
|
+
value: 'Module'
|
|
96
|
+
}), Object.defineProperty(exports1, '__esModule', {
|
|
97
|
+
value: !0
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
var __webpack_exports__ = {};
|
|
217
101
|
(()=>{
|
|
218
102
|
"use strict";
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
223
|
-
PLUGIN_ASSETS_RETRY_NAME: ()=>/* binding */ PLUGIN_ASSETS_RETRY_NAME,
|
|
224
|
-
pluginAssetsRetry: ()=>/* binding */ pluginAssetsRetry
|
|
103
|
+
__webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
|
|
104
|
+
PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
|
|
105
|
+
pluginAssetsRetry: ()=>pluginAssetsRetry
|
|
225
106
|
});
|
|
226
|
-
|
|
227
|
-
var external_node_fs_default =
|
|
228
|
-
|
|
229
|
-
var external_node_path_default =
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// EXTERNAL MODULE: ../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js
|
|
233
|
-
var serialize_javascript = __webpack_require__("../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js");
|
|
234
|
-
var serialize_javascript_default = /*#__PURE__*/ __webpack_require__.n(serialize_javascript);
|
|
107
|
+
let external_node_fs_namespaceObject = require("node:fs");
|
|
108
|
+
var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
|
|
109
|
+
let external_node_path_namespaceObject = require("node:path");
|
|
110
|
+
var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
|
|
111
|
+
let external_node_url_namespaceObject = require("node:url"), core_namespaceObject = require("@rsbuild/core");
|
|
112
|
+
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);
|
|
235
113
|
function _define_property(obj, key, value) {
|
|
236
|
-
|
|
114
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
237
115
|
value: value,
|
|
238
|
-
enumerable:
|
|
239
|
-
configurable:
|
|
240
|
-
writable:
|
|
241
|
-
});
|
|
242
|
-
else obj[key] = value;
|
|
243
|
-
return obj;
|
|
244
|
-
}
|
|
245
|
-
const AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(/*#__PURE__*/ function() {
|
|
246
|
-
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
247
|
-
}()));
|
|
248
|
-
// https://github.com/web-infra-dev/rspack/pull/5370
|
|
249
|
-
function appendWebpackScript(module1, appendSource) {
|
|
250
|
-
try {
|
|
251
|
-
const originSource = module1.getGeneratedCode();
|
|
252
|
-
module1.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
|
|
253
|
-
} catch (err) {
|
|
254
|
-
console.error('Failed to modify Webpack RuntimeModule');
|
|
255
|
-
throw err;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
function appendRspackScript(module1, appendSource) {
|
|
259
|
-
try {
|
|
260
|
-
const source = module1.source.source.toString();
|
|
261
|
-
module1.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
|
|
262
|
-
} catch (err) {
|
|
263
|
-
console.error('Failed to modify Rspack RuntimeModule');
|
|
264
|
-
throw err;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function pick(obj, keys) {
|
|
268
|
-
return keys.reduce((ret, key)=>{
|
|
269
|
-
if (void 0 !== obj[key]) ret[key] = obj[key];
|
|
270
|
-
return ret;
|
|
271
|
-
}, {});
|
|
116
|
+
enumerable: !0,
|
|
117
|
+
configurable: !0,
|
|
118
|
+
writable: !0
|
|
119
|
+
}) : obj[key] = value, obj;
|
|
272
120
|
}
|
|
121
|
+
let AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
|
|
273
122
|
class AsyncChunkRetryPlugin {
|
|
274
123
|
getRawRuntimeRetryCode() {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
278
|
-
const rawText = external_node_fs_default().readFileSync(runtimeFilePath, 'utf-8');
|
|
279
|
-
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));
|
|
124
|
+
let { RuntimeGlobals } = core_namespaceObject.rspack, filename = 'asyncChunkRetry', runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
125
|
+
return external_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));
|
|
280
126
|
}
|
|
281
127
|
apply(compiler) {
|
|
282
128
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
283
|
-
compilation.hooks.runtimeModule.tap(this.name, (
|
|
129
|
+
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
284
130
|
var _module_constructor;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
131
|
+
let { isRspack } = this.options, constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
|
|
132
|
+
if (!('publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName)) return;
|
|
133
|
+
let runtimeCode = this.getRawRuntimeRetryCode();
|
|
134
|
+
isRspack ? !function(module, appendSource) {
|
|
135
|
+
try {
|
|
136
|
+
let source = module.source.source.toString();
|
|
137
|
+
module.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
|
|
138
|
+
} catch (err) {
|
|
139
|
+
throw console.error('Failed to modify Rspack RuntimeModule'), err;
|
|
140
|
+
}
|
|
141
|
+
}(module, runtimeCode) : !function(module, appendSource) {
|
|
142
|
+
try {
|
|
143
|
+
let originSource = module.getGeneratedCode();
|
|
144
|
+
module.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
|
|
145
|
+
} catch (err) {
|
|
146
|
+
throw console.error('Failed to modify Webpack RuntimeModule'), err;
|
|
147
|
+
}
|
|
148
|
+
}(module, runtimeCode);
|
|
294
149
|
});
|
|
295
150
|
});
|
|
296
151
|
}
|
|
297
152
|
constructor(options){
|
|
298
|
-
_define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN')
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.options = options;
|
|
302
|
-
this.runtimeOptions = pick(options, [
|
|
153
|
+
_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 = function(obj, keys) {
|
|
154
|
+
return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
|
|
155
|
+
}(options, [
|
|
303
156
|
'domain',
|
|
304
157
|
'max',
|
|
305
158
|
'onRetry',
|
|
@@ -310,78 +163,58 @@ function __webpack_require__(moduleId) {
|
|
|
310
163
|
]);
|
|
311
164
|
}
|
|
312
165
|
}
|
|
313
|
-
|
|
314
|
-
return 'undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
315
|
-
}()));
|
|
316
|
-
const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
166
|
+
let src_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__)), PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
|
|
317
167
|
async function getRetryCode(options) {
|
|
318
|
-
|
|
319
|
-
const { minify, inlineScript: _, ...restOptions } = options;
|
|
320
|
-
const runtimeFilePath = external_node_path_default().join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
|
|
321
|
-
const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
|
|
168
|
+
let filename = 'initialChunkRetry', { minify, inlineScript: _, ...restOptions } = options, runtimeFilePath = external_node_path_default().join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`), runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
|
|
322
169
|
return `(function(){${runtimeCode};init(${serialize_javascript_default()(restOptions)});})()`;
|
|
323
170
|
}
|
|
324
|
-
|
|
171
|
+
let pluginAssetsRetry = (userOptions = {})=>({
|
|
325
172
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
326
173
|
setup (api) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
const formatOptions = (config)=>{
|
|
333
|
-
const options = {
|
|
174
|
+
let { inlineScript = !0 } = userOptions, getScriptPath = (environment)=>{
|
|
175
|
+
let distDir = environment.config.output.distPath.js;
|
|
176
|
+
return external_node_path_default().posix.join(distDir, "assets-retry.1-0-6.js");
|
|
177
|
+
}, formatOptions = (config)=>{
|
|
178
|
+
let options = {
|
|
334
179
|
...userOptions
|
|
335
180
|
};
|
|
336
|
-
|
|
337
|
-
if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
|
|
338
|
-
if (void 0 === options.minify) {
|
|
181
|
+
if (void 0 === options.crossOrigin && (options.crossOrigin = config.html.crossorigin), void 0 === options.minify) {
|
|
339
182
|
var _config_output_minify;
|
|
340
|
-
|
|
183
|
+
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;
|
|
341
184
|
options.minify = minify && 'production' === config.mode;
|
|
342
185
|
}
|
|
343
186
|
return options;
|
|
344
187
|
};
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
headTags.unshift({
|
|
188
|
+
inlineScript ? api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
189
|
+
let code = await getRetryCode(formatOptions(environment.config));
|
|
190
|
+
return headTags.unshift({
|
|
348
191
|
tag: 'script',
|
|
349
192
|
attrs: {},
|
|
350
193
|
children: code
|
|
351
|
-
})
|
|
352
|
-
return {
|
|
194
|
+
}), {
|
|
353
195
|
headTags,
|
|
354
196
|
bodyTags
|
|
355
197
|
};
|
|
356
|
-
})
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}, async ({ sources, compilation, environment })=>{
|
|
375
|
-
const scriptPath = getScriptPath(environment);
|
|
376
|
-
const code = await getRetryCode(formatOptions(environment.config));
|
|
377
|
-
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
381
|
-
const { config, htmlPaths } = environment;
|
|
198
|
+
}) : (api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
|
|
199
|
+
let scriptPath = getScriptPath(environment), url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
|
|
200
|
+
return headTags.unshift({
|
|
201
|
+
tag: 'script',
|
|
202
|
+
attrs: {
|
|
203
|
+
src: url
|
|
204
|
+
}
|
|
205
|
+
}), {
|
|
206
|
+
headTags,
|
|
207
|
+
bodyTags
|
|
208
|
+
};
|
|
209
|
+
}), api.processAssets({
|
|
210
|
+
stage: 'additional'
|
|
211
|
+
}, async ({ sources, compilation, environment })=>{
|
|
212
|
+
let scriptPath = getScriptPath(environment), code = await getRetryCode(formatOptions(environment.config));
|
|
213
|
+
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
214
|
+
})), api.modifyBundlerChain(async (chain, { environment })=>{
|
|
215
|
+
let { config, htmlPaths } = environment;
|
|
382
216
|
if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
|
|
383
|
-
|
|
384
|
-
const isRspack = 'rspack' === api.context.bundlerType;
|
|
217
|
+
let options = formatOptions(config), isRspack = 'rspack' === api.context.bundlerType;
|
|
385
218
|
chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
|
|
386
219
|
{
|
|
387
220
|
...options,
|
|
@@ -394,6 +227,6 @@ function __webpack_require__(moduleId) {
|
|
|
394
227
|
})();
|
|
395
228
|
var __webpack_export_target__ = exports;
|
|
396
229
|
for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
|
|
397
|
-
|
|
398
|
-
value:
|
|
230
|
+
__webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
|
|
231
|
+
value: !0
|
|
399
232
|
});
|
package/dist/index.js
CHANGED
|
@@ -5,29 +5,16 @@ import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
|
|
|
5
5
|
import * as __WEBPACK_EXTERNAL_MODULE__rsbuild_core__ 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
|
-
module.exports = __webpack_require__("crypto")
|
|
8
|
+
module.exports = __webpack_require__("crypto").randomBytes;
|
|
9
9
|
},
|
|
10
10
|
"../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/ var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js");
|
|
16
|
-
// Generate an internal UID to make the regexp pattern harder to guess.
|
|
17
|
-
var UID_LENGTH = 16;
|
|
18
|
-
var UID = generateUID();
|
|
19
|
-
var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
|
|
20
|
-
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
|
21
|
-
var IS_PURE_FUNCTION = /function.*?\(/;
|
|
22
|
-
var IS_ARROW_FUNCTION = /.*?=>.*?/;
|
|
23
|
-
var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
|
|
24
|
-
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 = [
|
|
25
15
|
'*',
|
|
26
16
|
'async'
|
|
27
|
-
]
|
|
28
|
-
// Mapping of unsafe HTML and invalid JavaScript line terminator chars to their
|
|
29
|
-
// Unicode char counterparts which are safe to use in JavaScript strings.
|
|
30
|
-
var ESCAPED_CHARS = {
|
|
17
|
+
], ESCAPED_CHARS = {
|
|
31
18
|
'<': '\\u003C',
|
|
32
19
|
'>': '\\u003E',
|
|
33
20
|
'/': '\\u002F',
|
|
@@ -37,241 +24,118 @@ See the accompanying LICENSE file for terms.
|
|
|
37
24
|
function escapeUnsafeChars(unsafeChar) {
|
|
38
25
|
return ESCAPED_CHARS[unsafeChar];
|
|
39
26
|
}
|
|
40
|
-
function generateUID() {
|
|
41
|
-
var bytes = randomBytes(UID_LENGTH);
|
|
42
|
-
var result = '';
|
|
43
|
-
for(var i = 0; i < UID_LENGTH; ++i)result += bytes[i].toString(16);
|
|
44
|
-
return result;
|
|
45
|
-
}
|
|
46
|
-
function deleteFunctions(obj) {
|
|
47
|
-
var functionKeys = [];
|
|
48
|
-
for(var key in obj)if ("function" == typeof obj[key]) functionKeys.push(key);
|
|
49
|
-
for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
|
|
50
|
-
}
|
|
51
27
|
module.exports = function serialize(obj, options) {
|
|
52
|
-
options || (options = {})
|
|
53
|
-
// Backwards-compatibility for `space` as the second argument.
|
|
54
|
-
if ('number' == typeof options || 'string' == typeof options) options = {
|
|
28
|
+
options || (options = {}), ('number' == typeof options || 'string' == typeof options) && (options = {
|
|
55
29
|
space: options
|
|
56
|
-
};
|
|
57
|
-
var functions = [];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var bigInts = [];
|
|
66
|
-
var urls = [];
|
|
67
|
-
// Returns placeholders for functions and regexps (identified by index)
|
|
68
|
-
// which are later replaced by their string representation.
|
|
69
|
-
function replacer(key, value) {
|
|
70
|
-
// For nested function
|
|
71
|
-
if (options.ignoreFunction) deleteFunctions(value);
|
|
72
|
-
if (!value && void 0 !== value && value !== BigInt(0)) return value;
|
|
73
|
-
// If the value is an object w/ a toJSON method, toJSON is called before
|
|
74
|
-
// the replacer runs, so we use this[key] to get the non-toJSONed value.
|
|
75
|
-
var origValue = this[key];
|
|
76
|
-
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;
|
|
77
39
|
if ('object' === type) {
|
|
78
40
|
if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
|
|
79
41
|
if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
|
80
42
|
if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
|
81
43
|
if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
|
82
|
-
if (origValue instanceof Array) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}).length !== origValue.length;
|
|
86
|
-
if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
87
|
-
}
|
|
44
|
+
if (origValue instanceof Array && origValue.filter(function() {
|
|
45
|
+
return !0;
|
|
46
|
+
}).length !== origValue.length) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
|
|
88
47
|
if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
|
|
89
48
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if ('bigint' === type) return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
|
|
94
|
-
return value;
|
|
95
|
-
}
|
|
96
|
-
function serializeFunc(fn) {
|
|
97
|
-
var serializedFn = fn.toString();
|
|
98
|
-
if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw new TypeError('Serializing native function: ' + fn.name);
|
|
99
|
-
// pure functions, example: {key: function() {}}
|
|
100
|
-
if (IS_PURE_FUNCTION.test(serializedFn)) return serializedFn;
|
|
101
|
-
// arrow functions, example: arg1 => arg1+5
|
|
102
|
-
if (IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
|
|
103
|
-
var argsStartsAt = serializedFn.indexOf('(');
|
|
104
|
-
var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
|
|
105
|
-
return val.length > 0;
|
|
106
|
-
});
|
|
107
|
-
var nonReservedSymbols = def.filter(function(val) {
|
|
108
|
-
return -1 === RESERVED_SYMBOLS.indexOf(val);
|
|
109
|
-
});
|
|
110
|
-
// enhanced literal objects, example: {key() {}}
|
|
111
|
-
if (nonReservedSymbols.length > 0) return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
|
|
112
|
-
// arrow functions
|
|
113
|
-
return serializedFn;
|
|
114
|
-
}
|
|
115
|
-
// Check if the parameter is function
|
|
116
|
-
if (options.ignoreFunction && "function" == typeof obj) obj = void 0;
|
|
117
|
-
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
118
|
-
// to the literal string: "undefined".
|
|
119
|
-
if (void 0 === obj) return String(obj);
|
|
120
|
-
var str;
|
|
121
|
-
// Creates a JSON string representation of the value.
|
|
122
|
-
// NOTE: Node 0.12 goes into slow mode with extra JSON.stringify() args.
|
|
123
|
-
str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
|
|
124
|
-
// Protects against `JSON.stringify()` returning `undefined`, by serializing
|
|
125
|
-
// to the literal string: "undefined".
|
|
126
|
-
if ('string' != typeof str) return String(str);
|
|
127
|
-
// Replace unsafe HTML and invalid JavaScript line terminator chars with
|
|
128
|
-
// their safe Unicode char counterpart. This _must_ happen before the
|
|
129
|
-
// regexps and functions are serialized and added back to the string.
|
|
130
|
-
if (true !== options.unsafe) str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
|
131
|
-
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;
|
|
132
|
-
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
|
|
133
|
-
// JSON string with their string representations. If the original value can
|
|
134
|
-
// not be found, then `undefined` is used.
|
|
135
|
-
return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
|
|
136
|
-
// The placeholder may not be preceded by a backslash. This is to prevent
|
|
137
|
-
// replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
|
|
138
|
-
// invalid JS.
|
|
139
|
-
if (backSlash) return match;
|
|
140
|
-
if ('D' === type) return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
|
|
141
|
-
if ('R' === type) return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
|
|
142
|
-
if ('M' === type) return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
|
|
143
|
-
if ('S' === type) return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
|
|
144
|
-
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({
|
|
145
52
|
length: arrays[valueIndex].length
|
|
146
|
-
}, arrays[valueIndex]), options) + ")"
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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]);
|
|
153
64
|
});
|
|
154
65
|
};
|
|
155
66
|
},
|
|
156
67
|
crypto: function(module) {
|
|
157
68
|
module.exports = __WEBPACK_EXTERNAL_MODULE_crypto__;
|
|
158
69
|
}
|
|
159
|
-
};
|
|
160
|
-
/************************************************************************/ // The module cache
|
|
161
|
-
var __webpack_module_cache__ = {};
|
|
162
|
-
// The require function
|
|
70
|
+
}, __webpack_module_cache__ = {};
|
|
163
71
|
function __webpack_require__(moduleId) {
|
|
164
|
-
// Check if module is in cache
|
|
165
72
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
166
73
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
167
|
-
// Create a new module (and put it into the cache)
|
|
168
74
|
var module = __webpack_module_cache__[moduleId] = {
|
|
169
75
|
exports: {}
|
|
170
76
|
};
|
|
171
|
-
|
|
172
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
173
|
-
// Return the exports of the module
|
|
174
|
-
return module.exports;
|
|
77
|
+
return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
|
|
175
78
|
}
|
|
176
|
-
|
|
177
|
-
(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
return module['default'];
|
|
182
|
-
} : function() {
|
|
183
|
-
return module;
|
|
184
|
-
};
|
|
185
|
-
__webpack_require__.d(getter, {
|
|
186
|
-
a: getter
|
|
187
|
-
});
|
|
188
|
-
return getter;
|
|
189
|
-
};
|
|
190
|
-
})();
|
|
191
|
-
// webpack/runtime/define_property_getters
|
|
192
|
-
(()=>{
|
|
193
|
-
__webpack_require__.d = function(exports, definition) {
|
|
194
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
195
|
-
enumerable: true,
|
|
196
|
-
get: definition[key]
|
|
197
|
-
});
|
|
198
|
-
};
|
|
199
|
-
})();
|
|
200
|
-
// webpack/runtime/has_own_property
|
|
201
|
-
(()=>{
|
|
202
|
-
__webpack_require__.o = function(obj, prop) {
|
|
203
|
-
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;
|
|
204
84
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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);
|
|
209
97
|
function _define_property(obj, key, value) {
|
|
210
|
-
|
|
98
|
+
return key in obj ? Object.defineProperty(obj, key, {
|
|
211
99
|
value: value,
|
|
212
|
-
enumerable:
|
|
213
|
-
configurable:
|
|
214
|
-
writable:
|
|
215
|
-
});
|
|
216
|
-
else obj[key] = value;
|
|
217
|
-
return obj;
|
|
218
|
-
}
|
|
219
|
-
const AsyncChunkRetryPlugin_dirname = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url));
|
|
220
|
-
// https://github.com/web-infra-dev/rspack/pull/5370
|
|
221
|
-
function appendWebpackScript(module, appendSource) {
|
|
222
|
-
try {
|
|
223
|
-
const originSource = module.getGeneratedCode();
|
|
224
|
-
module.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
|
|
225
|
-
} catch (err) {
|
|
226
|
-
console.error('Failed to modify Webpack RuntimeModule');
|
|
227
|
-
throw err;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function appendRspackScript(module, appendSource) {
|
|
231
|
-
try {
|
|
232
|
-
const source = module.source.source.toString();
|
|
233
|
-
module.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
|
|
234
|
-
} catch (err) {
|
|
235
|
-
console.error('Failed to modify Rspack RuntimeModule');
|
|
236
|
-
throw err;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function pick(obj, keys) {
|
|
240
|
-
return keys.reduce((ret, key)=>{
|
|
241
|
-
if (void 0 !== obj[key]) ret[key] = obj[key];
|
|
242
|
-
return ret;
|
|
243
|
-
}, {});
|
|
100
|
+
enumerable: !0,
|
|
101
|
+
configurable: !0,
|
|
102
|
+
writable: !0
|
|
103
|
+
}) : obj[key] = value, obj;
|
|
244
104
|
}
|
|
105
|
+
let AsyncChunkRetryPlugin_dirname = __WEBPACK_EXTERNAL_MODULE_node_path__.default.dirname((0, __WEBPACK_EXTERNAL_MODULE_node_url__.fileURLToPath)(import.meta.url));
|
|
245
106
|
class AsyncChunkRetryPlugin {
|
|
246
107
|
getRawRuntimeRetryCode() {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
|
|
250
|
-
const rawText = __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(runtimeFilePath, 'utf-8');
|
|
251
|
-
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));
|
|
252
110
|
}
|
|
253
111
|
apply(compiler) {
|
|
254
112
|
compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
|
|
255
113
|
compilation.hooks.runtimeModule.tap(this.name, (module)=>{
|
|
256
114
|
var _module_constructor;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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);
|
|
266
133
|
});
|
|
267
134
|
});
|
|
268
135
|
}
|
|
269
136
|
constructor(options){
|
|
270
|
-
|
|
271
|
-
_define_property(this, "options", void 0)
|
|
272
|
-
_define_property(this, "runtimeOptions", void 0);
|
|
273
|
-
this.options = options;
|
|
274
|
-
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, [
|
|
275
139
|
'domain',
|
|
276
140
|
'max',
|
|
277
141
|
'onRetry',
|
|
@@ -279,79 +143,61 @@ class AsyncChunkRetryPlugin {
|
|
|
279
143
|
'onFail',
|
|
280
144
|
'addQuery',
|
|
281
145
|
'test'
|
|
282
|
-
]);
|
|
146
|
+
].reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {}));
|
|
283
147
|
}
|
|
284
148
|
}
|
|
285
|
-
|
|
286
|
-
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';
|
|
287
150
|
async function getRetryCode(options) {
|
|
288
|
-
|
|
289
|
-
const { minify, inlineScript: _, ...restOptions } = options;
|
|
290
|
-
const runtimeFilePath = __WEBPACK_EXTERNAL_MODULE_node_path__["default"].join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
|
|
291
|
-
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');
|
|
292
152
|
return `(function(){${runtimeCode};init(${serialize_javascript_default()(restOptions)});})()`;
|
|
293
153
|
}
|
|
294
|
-
|
|
154
|
+
let pluginAssetsRetry = (userOptions = {})=>({
|
|
295
155
|
name: PLUGIN_ASSETS_RETRY_NAME,
|
|
296
156
|
setup (api) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const formatOptions = (config)=>{
|
|
303
|
-
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-6.js");
|
|
160
|
+
}, formatOptions = (config)=>{
|
|
161
|
+
let options = {
|
|
304
162
|
...userOptions
|
|
305
163
|
};
|
|
306
|
-
|
|
307
|
-
if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
|
|
308
|
-
if (void 0 === options.minify) {
|
|
164
|
+
if (void 0 === options.crossOrigin && (options.crossOrigin = config.html.crossorigin), void 0 === options.minify) {
|
|
309
165
|
var _config_output_minify;
|
|
310
|
-
|
|
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;
|
|
311
167
|
options.minify = minify && 'production' === config.mode;
|
|
312
168
|
}
|
|
313
169
|
return options;
|
|
314
170
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
headTags.unshift({
|
|
171
|
+
inlineScript ? api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
|
|
172
|
+
let code = await getRetryCode(formatOptions(environment.config));
|
|
173
|
+
return headTags.unshift({
|
|
318
174
|
tag: 'script',
|
|
319
175
|
attrs: {},
|
|
320
176
|
children: code
|
|
321
|
-
})
|
|
322
|
-
return {
|
|
177
|
+
}), {
|
|
323
178
|
headTags,
|
|
324
179
|
bodyTags
|
|
325
180
|
};
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}, async ({ sources, compilation, environment })=>{
|
|
345
|
-
const scriptPath = getScriptPath(environment);
|
|
346
|
-
const code = await getRetryCode(formatOptions(environment.config));
|
|
347
|
-
compilation.emitAsset(scriptPath, new sources.RawSource(code));
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
api.modifyBundlerChain(async (chain, { environment })=>{
|
|
351
|
-
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;
|
|
352
199
|
if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
|
|
353
|
-
|
|
354
|
-
const isRspack = 'rspack' === api.context.bundlerType;
|
|
200
|
+
let options = formatOptions(config), isRspack = 'rspack' === api.context.bundlerType;
|
|
355
201
|
chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
|
|
356
202
|
{
|
|
357
203
|
...options,
|
|
@@ -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>;
|
|
@@ -123,24 +123,39 @@ var originalGetCssFilename = (_ref = (_RUNTIME_GLOBALS_GET = __RUNTIME_GLOBALS_G
|
|
|
123
123
|
return null;
|
|
124
124
|
};
|
|
125
125
|
var originalLoadScript = __RUNTIME_GLOBALS_LOAD_SCRIPT__;
|
|
126
|
+
var ERROR_PREFIX = '[@rsbuild/plugin-assets-retry] ';
|
|
126
127
|
|
|
127
128
|
// if users want to support es5, add Promise polyfill first https://github.com/webpack/webpack/issues/12877
|
|
128
|
-
function ensureChunk(chunkId
|
|
129
|
-
|
|
129
|
+
function ensureChunk(chunkId,
|
|
130
|
+
// args placeholder, to avoid that other webpack runtime would add arg for __webpack_require__.e
|
|
131
|
+
arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
|
|
132
|
+
var callingCounter = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : {
|
|
130
133
|
count: 0
|
|
131
134
|
};
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
for (var _len = arguments.length, args = new Array(_len > 9 ? _len - 9 : 0), _key = 9; _key < _len; _key++) {
|
|
136
|
+
args[_key - 9] = arguments[_key];
|
|
137
|
+
}
|
|
138
|
+
var result = originalEnsureChunk.apply(void 0, [chunkId, arg0, arg1, arg2, arg3, arg4, arg5, arg6, callingCounter].concat(args));
|
|
139
|
+
try {
|
|
140
|
+
var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
|
|
141
|
+
var originalCssFilename = originalGetCssFilename(chunkId);
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
+
// mark the async chunk name in the global variables and share it with initial chunk retry to avoid duplicate retrying
|
|
144
|
+
if (typeof window !== 'undefined') {
|
|
145
|
+
if (originalScriptFilename) {
|
|
146
|
+
window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
|
|
147
|
+
}
|
|
148
|
+
if (originalCssFilename) {
|
|
149
|
+
window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
|
|
150
|
+
}
|
|
143
151
|
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
console.error(ERROR_PREFIX, 'get original script or css filename error', e);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// if __webpack_require__.e is polluted by other runtime codes, fallback to originalEnsureChunk
|
|
157
|
+
if (typeof (callingCounter === null || callingCounter === void 0 ? void 0 : callingCounter.count) !== 'number') {
|
|
158
|
+
return result;
|
|
144
159
|
}
|
|
145
160
|
callingCounter.count += 1;
|
|
146
161
|
return result.catch(function (error) {
|
|
@@ -148,10 +163,18 @@ function ensureChunk(chunkId) {
|
|
|
148
163
|
// the first calling is not retry
|
|
149
164
|
// if the failed request is 4 in network panel, callingCounter.count === 4, the first one is the normal request, and existRetryTimes is 3, retried 3 times
|
|
150
165
|
var existRetryTimes = callingCounter.count - 1;
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
var originalSrcUrl;
|
|
167
|
+
var nextRetryUrl;
|
|
168
|
+
var nextDomain;
|
|
169
|
+
try {
|
|
170
|
+
var retryResult = nextRetry(chunkId, existRetryTimes);
|
|
171
|
+
originalSrcUrl = retryResult.originalSrcUrl;
|
|
172
|
+
nextRetryUrl = retryResult.nextRetryUrl;
|
|
173
|
+
nextDomain = retryResult.nextDomain;
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
155
178
|
|
|
156
179
|
// At present, we don't consider the switching domain and addQuery of async CSS chunk
|
|
157
180
|
// 1. Async js chunk will be requested first. It is rare for async CSS chunk to fail alone.
|
|
@@ -197,12 +220,12 @@ function ensureChunk(chunkId) {
|
|
|
197
220
|
if (typeof config.onRetry === 'function') {
|
|
198
221
|
config.onRetry(context);
|
|
199
222
|
}
|
|
200
|
-
var nextPromise = ensureChunk(chunkId, callingCounter);
|
|
223
|
+
var nextPromise = ensureChunk.apply(void 0, [chunkId, arg0, arg1, arg2, arg3, arg4, arg5, arg6, callingCounter].concat(args));
|
|
201
224
|
return nextPromise.then(function (result) {
|
|
202
225
|
// when after retrying the third time
|
|
203
226
|
// ensureChunk(chunkId, { count: 3 }), at that time, existRetryTimes === 2
|
|
204
227
|
// after all, callingCounter.count is 4
|
|
205
|
-
var isLastSuccessRetry = callingCounter.count === existRetryTimes + 2;
|
|
228
|
+
var isLastSuccessRetry = (callingCounter === null || callingCounter === void 0 ? void 0 : callingCounter.count) === existRetryTimes + 2;
|
|
206
229
|
if (typeof config.onSuccess === 'function' && isLastSuccessRetry) {
|
|
207
230
|
var _context = createContext(existRetryTimes + 1);
|
|
208
231
|
config.onSuccess(_context);
|
|
@@ -213,7 +236,10 @@ function ensureChunk(chunkId) {
|
|
|
213
236
|
}
|
|
214
237
|
function loadScript(originalUrl, done, key, chunkId) {
|
|
215
238
|
var retry = globalCurrRetrying[chunkId];
|
|
216
|
-
|
|
239
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 4 ? _len2 - 4 : 0), _key2 = 4; _key2 < _len2; _key2++) {
|
|
240
|
+
args[_key2 - 4] = arguments[_key2];
|
|
241
|
+
}
|
|
242
|
+
return originalLoadScript.apply(void 0, [retry ? retry.nextRetryUrl : originalUrl, done, key, chunkId].concat(args));
|
|
217
243
|
}
|
|
218
244
|
function registerAsyncChunkRetry() {
|
|
219
245
|
// init global variables shared between initial-chunk-retry and async-chunk-retry
|
|
@@ -225,7 +251,7 @@ function registerAsyncChunkRetry() {
|
|
|
225
251
|
__RUNTIME_GLOBALS_ENSURE_CHUNK__ = ensureChunk;
|
|
226
252
|
__RUNTIME_GLOBALS_LOAD_SCRIPT__ = loadScript;
|
|
227
253
|
} catch (e) {
|
|
228
|
-
console.error('
|
|
254
|
+
console.error(ERROR_PREFIX, 'Register async chunk retry runtime failed', e);
|
|
229
255
|
}
|
|
230
256
|
}
|
|
231
257
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _ref,_RUNTIME_GLOBALS_GET,config=__RETRY_OPTIONS__,maxRetries=config.max||3,retryCollector={};function findCurrentDomain(n){for(var r,e=null!==(r=config.domain)&&void 0!==r?r:[],i="",t=0;t<e.length;t++)if(-1!==n.indexOf(e[t])){i=e[t];break}return i||window.origin}function findNextDomain(n){var r,e=null!==(r=config.domain)&&void 0!==r?r:[],i=findCurrentDomain(n),t=e.indexOf(i);return e[(t+1)%e.length]||n}var postfixRE=/[?#].*$/;function cleanUrl(n){return n.replace(postfixRE,"")}function getQueryFromUrl(n){var r=n.split("?")[1];return r?"?".concat(r.split("#")[0]):""}function getUrlRetryQuery(n,r){return!0===config.addQuery?""!==r?"".concat(r,"&retry=").concat(n):"?retry=".concat(n):"function"==typeof config.addQuery?config.addQuery({times:n,originalQuery:r}):""}function removeDomainFromUrl(n){var r=n.indexOf("//");if(-1===r&&n.startsWith("/"))return n;var e=r+2,i=n.indexOf("/",e);return n.slice(i)}function getAbsolutePathFromUrl(n){return cleanUrl(removeDomainFromUrl(n))}function getNextRetryUrl(n,r,e){return r+getAbsolutePathFromUrl(e)+getUrlRetryQuery(n,getQueryFromUrl(e))}var globalCurrRetrying={};function getCurrentRetry(n,r){var e;return null===(e=retryCollector[n])||void 0===e?void 0:e[r]}function initRetry(n){var r,e,i=originalGetChunkScriptFilename(n),t=__RUNTIME_GLOBALS_PUBLIC_PATH__+i,o=null!==(r=null===(e=config.domain)||void 0===e?void 0:e[0])&&void 0!==r?r:window.origin;return{nextDomain:o,nextRetryUrl:getNextRetryUrl(1,o,t),originalScriptFilename:i,originalSrcUrl:t}}function nextRetry(n,r){var e,i=getCurrentRetry(n,r),t=r+1;if(0===r||void 0===i)e=initRetry(n),retryCollector[n]=[];else{var o=i.originalScriptFilename,
|
|
1
|
+
"use strict";var _ref,_RUNTIME_GLOBALS_GET,config=__RETRY_OPTIONS__,maxRetries=config.max||3,retryCollector={};function findCurrentDomain(n){for(var r,e=null!==(r=config.domain)&&void 0!==r?r:[],i="",t=0;t<e.length;t++)if(-1!==n.indexOf(e[t])){i=e[t];break}return i||window.origin}function findNextDomain(n){var r,e=null!==(r=config.domain)&&void 0!==r?r:[],i=findCurrentDomain(n),t=e.indexOf(i);return e[(t+1)%e.length]||n}var postfixRE=/[?#].*$/;function cleanUrl(n){return n.replace(postfixRE,"")}function getQueryFromUrl(n){var r=n.split("?")[1];return r?"?".concat(r.split("#")[0]):""}function getUrlRetryQuery(n,r){return!0===config.addQuery?""!==r?"".concat(r,"&retry=").concat(n):"?retry=".concat(n):"function"==typeof config.addQuery?config.addQuery({times:n,originalQuery:r}):""}function removeDomainFromUrl(n){var r=n.indexOf("//");if(-1===r&&n.startsWith("/"))return n;var e=r+2,i=n.indexOf("/",e);return n.slice(i)}function getAbsolutePathFromUrl(n){return cleanUrl(removeDomainFromUrl(n))}function getNextRetryUrl(n,r,e){return r+getAbsolutePathFromUrl(e)+getUrlRetryQuery(n,getQueryFromUrl(e))}var globalCurrRetrying={};function getCurrentRetry(n,r){var e;return null===(e=retryCollector[n])||void 0===e?void 0:e[r]}function initRetry(n){var r,e,i=originalGetChunkScriptFilename(n),t=__RUNTIME_GLOBALS_PUBLIC_PATH__+i,o=null!==(r=null===(e=config.domain)||void 0===e?void 0:e[0])&&void 0!==r?r:window.origin;return{nextDomain:o,nextRetryUrl:getNextRetryUrl(1,o,t),originalScriptFilename:i,originalSrcUrl:t}}function nextRetry(n,r){var e,i=getCurrentRetry(n,r),t=r+1;if(0===r||void 0===i)e=initRetry(n),retryCollector[n]=[];else{var o=i.originalScriptFilename,a=i.originalSrcUrl,l=findNextDomain(i.nextDomain);e={nextDomain:l,nextRetryUrl:getNextRetryUrl(t,l,a),originalScriptFilename:o,originalSrcUrl:a}}return retryCollector[n][t]=e,globalCurrRetrying[n]=e,e}var originalEnsureChunk=__RUNTIME_GLOBALS_ENSURE_CHUNK__,originalGetChunkScriptFilename=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,originalGetCssFilename=null!==(_ref=null!==(_RUNTIME_GLOBALS_GET=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__)&&void 0!==_RUNTIME_GLOBALS_GET?_RUNTIME_GLOBALS_GET:__RUNTIME_GLOBALS_GET_CSS_FILENAME__)&&void 0!==_ref?_ref:function(){return null},originalLoadScript=__RUNTIME_GLOBALS_LOAD_SCRIPT__,ERROR_PREFIX="[@rsbuild/plugin-assets-retry] ";function ensureChunk(n,r,e,i,t,o,a,l){for(var c=arguments.length>8&&void 0!==arguments[8]?arguments[8]:{count:0},_=arguments.length,u=new Array(_>9?_-9:0),f=9;f<_;f++)u[f-9]=arguments[f];var g=originalEnsureChunk.apply(void 0,[n,r,e,i,t,o,a,l,c].concat(u));try{var R=originalGetChunkScriptFilename(n),d=originalGetCssFilename(n);"undefined"!=typeof window&&(R&&(window.__RB_ASYNC_CHUNKS__[R]=!0),d&&(window.__RB_ASYNC_CHUNKS__[d]=!0))}catch(n){console.error(ERROR_PREFIX,"get original script or css filename error",n)}return"number"!=typeof(null==c?void 0:c.count)?g:(c.count+=1,g.catch((function(_){var f,g,R,d,s=c.count-1;try{var y=nextRetry(n,s);g=y.originalSrcUrl,R=y.nextRetryUrl,d=y.nextDomain}catch(n){throw console.error(ERROR_PREFIX,"failed to get nextRetryUrl",n),_}var m,S=Boolean(null==_||null===(f=_.message)||void 0===f?void 0:f.includes("CSS chunk")),E=function(n){return{times:n,domain:d,url:R,tagName:S?"link":"script",isAsyncChunk:!0}},U=E(s);if(s>=maxRetries)throw _.message=null!==(m=_.message)&&void 0!==m&&m.includes("retries:")?_.message:"Loading chunk ".concat(n," from ").concat(g," failed after ").concat(maxRetries,' retries: "').concat(_.message,'"'),"function"==typeof config.onFail&&config.onFail(U),_;var v=config.test;if(v){if("string"==typeof v){var C=new RegExp(v);v=function(n){return C.test(n)}}if("function"!=typeof v||!v(R))throw _}if(config.domain&&config.domain.length>0&&-1===config.domain.indexOf(d))throw _;return"function"==typeof config.onRetry&&config.onRetry(U),ensureChunk.apply(void 0,[n,r,e,i,t,o,a,l,c].concat(u)).then((function(n){var r=(null==c?void 0:c.count)===s+2;if("function"==typeof config.onSuccess&&r){var e=E(s+1);config.onSuccess(e)}return n}))})))}function loadScript(n,r,e,i){for(var t=globalCurrRetrying[i],o=arguments.length,a=new Array(o>4?o-4:0),l=4;l<o;l++)a[l-4]=arguments[l];return originalLoadScript.apply(void 0,[t?t.nextRetryUrl:n,r,e,i].concat(a))}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(ERROR_PREFIX,"Register async chunk retry runtime failed",n)}}registerAsyncChunkRetry();
|
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.6",
|
|
4
4
|
"description": "Assets retry plugin for Rsbuild",
|
|
5
5
|
"homepage": "https://rsbuild.dev",
|
|
6
6
|
"repository": {
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
"@babel/core": "^7.26.0",
|
|
27
27
|
"@babel/preset-env": "^7.26.0",
|
|
28
28
|
"@babel/preset-typescript": "^7.26.0",
|
|
29
|
+
"@rslib/core": "0.1.0",
|
|
29
30
|
"@types/serialize-javascript": "^5.0.4",
|
|
30
31
|
"serialize-javascript": "^6.0.2",
|
|
31
32
|
"terser": "5.36.0",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"@rsbuild/core": "1.
|
|
33
|
+
"typescript": "^5.7.2",
|
|
34
|
+
"@rsbuild/core": "1.1.5"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
37
|
"@rsbuild/core": "1.x"
|