@rsbuild/plugin-assets-retry 1.1.1 → 1.2.1

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 CHANGED
@@ -1,17 +1,25 @@
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
+ const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
2
+ return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ }();
2
4
  var __webpack_modules__ = {
3
- "../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
5
+ "./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
4
6
  module.exports = __webpack_require__("crypto").randomBytes;
5
7
  },
6
- "../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
8
+ "./node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
7
9
  "use strict";
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 = [
10
+ var randomBytes = __webpack_require__("./node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js");
11
+ var UID_LENGTH = 16;
12
+ var UID = generateUID();
13
+ var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|A|U|I|B|L)-' + UID + '-(\\d+)__@"', 'g');
14
+ var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
15
+ var IS_PURE_FUNCTION = /function.*?\(/;
16
+ var IS_ARROW_FUNCTION = /.*?=>.*?/;
17
+ var UNSAFE_CHARS_REGEXP = /[<>\/\u2028\u2029]/g;
18
+ var RESERVED_SYMBOLS = [
12
19
  '*',
13
20
  'async'
14
- ], ESCAPED_CHARS = {
21
+ ];
22
+ var ESCAPED_CHARS = {
15
23
  '<': '\\u003C',
16
24
  '>': '\\u003E',
17
25
  '/': '\\u002F',
@@ -21,43 +29,93 @@ var __webpack_modules__ = {
21
29
  function escapeUnsafeChars(unsafeChar) {
22
30
  return ESCAPED_CHARS[unsafeChar];
23
31
  }
32
+ function generateUID() {
33
+ var bytes = randomBytes(UID_LENGTH);
34
+ var result = '';
35
+ for(var i = 0; i < UID_LENGTH; ++i)result += bytes[i].toString(16);
36
+ return result;
37
+ }
38
+ function deleteFunctions(obj) {
39
+ var functionKeys = [];
40
+ for(var key in obj)if ("function" == typeof obj[key]) functionKeys.push(key);
41
+ for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
42
+ }
24
43
  module.exports = function serialize(obj, options) {
25
- options || (options = {}), ('number' == typeof options || 'string' == typeof options) && (options = {
44
+ options || (options = {});
45
+ if ('number' == typeof options || 'string' == typeof options) options = {
26
46
  space: options
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;
47
+ };
48
+ var functions = [];
49
+ var regexps = [];
50
+ var dates = [];
51
+ var maps = [];
52
+ var sets = [];
53
+ var arrays = [];
54
+ var undefs = [];
55
+ var infinities = [];
56
+ var bigInts = [];
57
+ var urls = [];
58
+ function replacer(key, value) {
59
+ if (options.ignoreFunction) deleteFunctions(value);
60
+ if (!value && void 0 !== value && value !== BigInt(0)) return value;
61
+ var origValue = this[key];
62
+ var type = typeof origValue;
36
63
  if ('object' === type) {
37
64
  if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
38
65
  if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
39
66
  if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
40
67
  if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
41
- if (origValue instanceof Array && origValue.filter(function() {
42
- return !0;
43
- }).length !== origValue.length) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
68
+ if (origValue instanceof Array) {
69
+ var isSparse = origValue.filter(function() {
70
+ return true;
71
+ }).length !== origValue.length;
72
+ if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
73
+ }
44
74
  if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
45
75
  }
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({
76
+ if ('function' === type) return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
77
+ if ('undefined' === type) return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
78
+ if ('number' === type && !isNaN(origValue) && !isFinite(origValue)) return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
79
+ if ('bigint' === type) return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
80
+ return value;
81
+ }
82
+ function serializeFunc(fn) {
83
+ var serializedFn = fn.toString();
84
+ if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw new TypeError('Serializing native function: ' + fn.name);
85
+ if (IS_PURE_FUNCTION.test(serializedFn)) return serializedFn;
86
+ if (IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
87
+ var argsStartsAt = serializedFn.indexOf('(');
88
+ var def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
89
+ return val.length > 0;
90
+ });
91
+ var nonReservedSymbols = def.filter(function(val) {
92
+ return -1 === RESERVED_SYMBOLS.indexOf(val);
93
+ });
94
+ if (nonReservedSymbols.length > 0) return (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt);
95
+ return serializedFn;
96
+ }
97
+ if (options.ignoreFunction && "function" == typeof obj) obj = void 0;
98
+ if (void 0 === obj) return String(obj);
99
+ var str;
100
+ str = options.isJSON && !options.space ? JSON.stringify(obj) : JSON.stringify(obj, options.isJSON ? null : replacer, options.space);
101
+ if ('string' != typeof str) return String(str);
102
+ if (true !== options.unsafe) str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
103
+ 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;
104
+ return str.replace(PLACE_HOLDER_REGEXP, function(match, backSlash, type, valueIndex) {
105
+ if (backSlash) return match;
106
+ if ('D' === type) return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
107
+ if ('R' === type) return "new RegExp(" + serialize(regexps[valueIndex].source) + ", \"" + regexps[valueIndex].flags + "\")";
108
+ if ('M' === type) return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
109
+ if ('S' === type) return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
110
+ if ('A' === type) return "Array.prototype.slice.call(" + serialize(Object.assign({
49
111
  length: arrays[valueIndex].length
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]);
112
+ }, arrays[valueIndex]), options) + ")";
113
+ if ('U' === type) return 'undefined';
114
+ if ('I' === type) return infinities[valueIndex];
115
+ if ('B' === type) return "BigInt(\"" + bigInts[valueIndex] + "\")";
116
+ if ('L' === type) return "new URL(" + serialize(urls[valueIndex].toString(), options) + ")";
117
+ var fn = functions[valueIndex];
118
+ return serializeFunc(fn);
61
119
  });
62
120
  };
63
121
  },
@@ -65,179 +123,243 @@ var __webpack_modules__ = {
65
123
  "use strict";
66
124
  module.exports = require("crypto");
67
125
  }
68
- }, __webpack_module_cache__ = {};
126
+ };
127
+ var __webpack_module_cache__ = {};
69
128
  function __webpack_require__(moduleId) {
70
129
  var cachedModule = __webpack_module_cache__[moduleId];
71
130
  if (void 0 !== cachedModule) return cachedModule.exports;
72
131
  var module = __webpack_module_cache__[moduleId] = {
73
132
  exports: {}
74
133
  };
75
- return __webpack_modules__[moduleId](module, module.exports, __webpack_require__), module.exports;
134
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
135
+ return module.exports;
76
136
  }
77
- __webpack_require__.n = function(module) {
78
- var getter = module && module.__esModule ? function() {
79
- return module.default;
80
- } : function() {
81
- return module;
137
+ (()=>{
138
+ __webpack_require__.n = function(module) {
139
+ var getter = module && module.__esModule ? function() {
140
+ return module['default'];
141
+ } : function() {
142
+ return module;
143
+ };
144
+ __webpack_require__.d(getter, {
145
+ a: getter
146
+ });
147
+ return getter;
82
148
  };
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
- };
149
+ })();
150
+ (()=>{
151
+ __webpack_require__.d = function(exports1, definition) {
152
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
153
+ enumerable: true,
154
+ get: definition[key]
155
+ });
156
+ };
157
+ })();
158
+ (()=>{
159
+ __webpack_require__.o = function(obj, prop) {
160
+ return Object.prototype.hasOwnProperty.call(obj, prop);
161
+ };
162
+ })();
163
+ (()=>{
164
+ __webpack_require__.r = function(exports1) {
165
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
166
+ value: 'Module'
167
+ });
168
+ Object.defineProperty(exports1, '__esModule', {
169
+ value: true
170
+ });
171
+ };
172
+ })();
100
173
  var __webpack_exports__ = {};
101
174
  (()=>{
102
175
  "use strict";
103
- __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
176
+ __webpack_require__.r(__webpack_exports__);
177
+ __webpack_require__.d(__webpack_exports__, {
104
178
  PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
105
179
  pluginAssetsRetry: ()=>pluginAssetsRetry
106
180
  });
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);
181
+ const external_node_fs_namespaceObject = require("node:fs");
182
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
183
+ const external_node_path_namespaceObject = require("node:path");
184
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
185
+ const external_node_url_namespaceObject = require("node:url");
186
+ const core_namespaceObject = require("@rsbuild/core");
187
+ var serialize_javascript = __webpack_require__("./node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js");
188
+ var serialize_javascript_default = /*#__PURE__*/ __webpack_require__.n(serialize_javascript);
113
189
  function _define_property(obj, key, value) {
114
- return key in obj ? Object.defineProperty(obj, key, {
190
+ if (key in obj) Object.defineProperty(obj, key, {
115
191
  value: value,
116
- enumerable: !0,
117
- configurable: !0,
118
- writable: !0
119
- }) : obj[key] = value, obj;
192
+ enumerable: true,
193
+ configurable: true,
194
+ writable: true
195
+ });
196
+ else obj[key] = value;
197
+ return obj;
198
+ }
199
+ const AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
200
+ function modifyWebpackRuntimeModule(module, modifier) {
201
+ try {
202
+ const originSource = module.getGeneratedCode();
203
+ module.getGeneratedCode = ()=>modifier(originSource);
204
+ } catch (err) {
205
+ console.error('Failed to modify webpack RuntimeModule');
206
+ throw err;
207
+ }
208
+ }
209
+ function modifyRspackRuntimeModule(module, modifier) {
210
+ try {
211
+ const originSource = module.source.source.toString();
212
+ module.source.source = Buffer.from(modifier(originSource), 'utf-8');
213
+ } catch (err) {
214
+ console.error('Failed to modify Rspack RuntimeModule');
215
+ throw err;
216
+ }
120
217
  }
121
- let AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
122
218
  function modifyRuntimeModule(module, modifier, isRspack) {
123
- isRspack ? function(module, modifier) {
124
- try {
125
- let originSource = module.source.source.toString();
126
- module.source.source = Buffer.from(modifier(originSource), 'utf-8');
127
- } catch (err) {
128
- throw console.error('Failed to modify Rspack RuntimeModule'), err;
129
- }
130
- }(module, modifier) : function(module, modifier) {
131
- try {
132
- let originSource = module.getGeneratedCode();
133
- module.getGeneratedCode = ()=>modifier(originSource);
134
- } catch (err) {
135
- throw console.error('Failed to modify webpack RuntimeModule'), err;
136
- }
137
- }(module, modifier);
219
+ if (isRspack) modifyRspackRuntimeModule(module, modifier);
220
+ else modifyWebpackRuntimeModule(module, modifier);
221
+ }
222
+ function pick(obj, keys) {
223
+ return keys.reduce((ret, key)=>{
224
+ if (void 0 !== obj[key]) ret[key] = obj[key];
225
+ return ret;
226
+ }, {});
138
227
  }
139
228
  class AsyncChunkRetryPlugin {
140
229
  getRawRuntimeRetryCode() {
141
- let { RuntimeGlobals } = core_namespaceObject.rspack, filename = 'asyncChunkRetry', runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
142
- 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_RSBUILD_LOAD_STYLESHEET__', '__webpack_require__.rbLoadStyleSheet').replaceAll('__RUNTIME_GLOBALS_PUBLIC_PATH__', RuntimeGlobals.publicPath).replaceAll('__RUNTIME_GLOBALS_LOAD_SCRIPT__', RuntimeGlobals.loadScript).replaceAll('__RETRY_OPTIONS__', serialize_javascript_default()(this.runtimeOptions));
230
+ const { RuntimeGlobals } = core_namespaceObject.rspack;
231
+ const filename = 'asyncChunkRetry';
232
+ const runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
233
+ const rawText = external_node_fs_default().readFileSync(runtimeFilePath, 'utf-8');
234
+ 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_RSBUILD_LOAD_STYLESHEET__', '__webpack_require__.rbLoadStyleSheet').replaceAll('__RUNTIME_GLOBALS_PUBLIC_PATH__', RuntimeGlobals.publicPath).replaceAll('__RUNTIME_GLOBALS_LOAD_SCRIPT__', RuntimeGlobals.loadScript).replaceAll('__RETRY_OPTIONS__', serialize_javascript_default()(this.runtimeOptions));
143
235
  }
144
236
  apply(compiler) {
145
237
  compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
146
238
  compilation.hooks.runtimeModule.tap(this.name, (module)=>{
147
239
  var _module_constructor;
148
- let { isRspack } = this.options, constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
149
- if ('CssLoadingRuntimeModule' === constructorName) {
240
+ const { isRspack } = this.options;
241
+ const constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
242
+ const isCssLoadingRuntimeModule = 'CssLoadingRuntimeModule' === constructorName;
243
+ if (isCssLoadingRuntimeModule) {
150
244
  modifyRuntimeModule(module, (originSource)=>originSource.replace('var fullhref = __webpack_require__.p + href;', 'var fullhref = __webpack_require__.rbLoadStyleSheet ? __webpack_require__.rbLoadStyleSheet(href, chunkId) : (__webpack_require__.p + href);'), isRspack);
151
245
  return;
152
246
  }
153
- if ('publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName) {
154
- let runtimeCode = this.getRawRuntimeRetryCode();
247
+ const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
248
+ if (isPublicPathModule) {
249
+ const runtimeCode = this.getRawRuntimeRetryCode();
155
250
  modifyRuntimeModule(module, (originSource)=>`${originSource}\n${runtimeCode}`, isRspack);
156
251
  }
157
252
  });
158
253
  });
159
254
  }
160
255
  constructor(options){
161
- _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) {
162
- return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
163
- }(options, [
256
+ _define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN');
257
+ _define_property(this, "options", void 0);
258
+ _define_property(this, "runtimeOptions", void 0);
259
+ this.options = options;
260
+ this.runtimeOptions = pick(options, [
164
261
  'domain',
165
262
  'max',
166
263
  'onRetry',
167
264
  'onSuccess',
168
265
  'onFail',
169
266
  'addQuery',
170
- 'test'
267
+ 'test',
268
+ 'delay'
171
269
  ]);
172
270
  }
173
271
  }
174
- 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';
272
+ const src_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
273
+ const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
274
+ function getRuntimeOptions(userOptions) {
275
+ const defaultOptions = {
276
+ max: 3,
277
+ type: [
278
+ 'link',
279
+ "script",
280
+ 'img'
281
+ ],
282
+ domain: [],
283
+ crossOrigin: false,
284
+ delay: 0
285
+ };
286
+ const result = {
287
+ ...defaultOptions,
288
+ ...userOptions
289
+ };
290
+ if (!Array.isArray(result.type) || 0 === result.type.length) result.type = defaultOptions.type;
291
+ if (!Array.isArray(result.domain) || 0 === result.domain.length) result.domain = defaultOptions.domain;
292
+ if (Array.isArray(result.domain)) result.domain = result.domain.filter(Boolean);
293
+ return result;
294
+ }
175
295
  async function getRetryCode(options) {
176
- 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'), runtimeOptions = function(userOptions) {
177
- let defaultOptions = {
178
- max: 3,
179
- type: [
180
- 'link',
181
- "script",
182
- 'img'
183
- ],
184
- domain: [],
185
- crossOrigin: !1
186
- }, result = {
187
- ...defaultOptions,
188
- ...userOptions
189
- };
190
- return Array.isArray(result.type) && 0 !== result.type.length || (result.type = defaultOptions.type), Array.isArray(result.domain) && 0 !== result.domain.length || (result.domain = defaultOptions.domain), Array.isArray(result.domain) && (result.domain = result.domain.filter(Boolean)), result;
191
- }(restOptions);
296
+ const filename = 'initialChunkRetry';
297
+ const { minify, inlineScript: _, ...restOptions } = options;
298
+ const runtimeFilePath = external_node_path_default().join(src_dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
299
+ const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
300
+ const runtimeOptions = getRuntimeOptions(restOptions);
192
301
  return `(function(){${runtimeCode}})()`.replace('__RUNTIME_GLOBALS_OPTIONS__', serialize_javascript_default()(runtimeOptions));
193
302
  }
194
- let pluginAssetsRetry = (userOptions = {})=>({
303
+ const pluginAssetsRetry = (userOptions = {})=>({
195
304
  name: PLUGIN_ASSETS_RETRY_NAME,
196
305
  setup (api) {
197
- let { inlineScript = !0 } = userOptions, getScriptPath = (environment)=>{
198
- let distDir = environment.config.output.distPath.js;
199
- return external_node_path_default().posix.join(distDir, "assets-retry.1-1-1.js");
200
- }, formatOptions = (config)=>{
201
- let options = {
306
+ const { inlineScript = true } = userOptions;
307
+ const getScriptPath = (environment)=>{
308
+ const distDir = environment.config.output.distPath.js;
309
+ return external_node_path_default().posix.join(distDir, "assets-retry.1-2-1.js");
310
+ };
311
+ const formatOptions = (config)=>{
312
+ const options = {
202
313
  ...userOptions
203
314
  };
204
- if (void 0 === options.crossOrigin && (options.crossOrigin = config.html.crossorigin), void 0 === options.minify) {
315
+ if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
316
+ if (void 0 === options.minify) {
205
317
  var _config_output_minify;
206
- 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;
318
+ const minify = 'boolean' == typeof config.output.minify ? config.output.minify : null === (_config_output_minify = config.output.minify) || void 0 === _config_output_minify ? void 0 : _config_output_minify.js;
207
319
  options.minify = minify && 'production' === config.mode;
208
320
  }
209
321
  return options;
210
322
  };
211
- inlineScript ? api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
212
- let code = await getRetryCode(formatOptions(environment.config));
213
- return headTags.unshift({
323
+ if (inlineScript) api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
324
+ const code = await getRetryCode(formatOptions(environment.config));
325
+ headTags.unshift({
214
326
  tag: "script",
215
327
  attrs: {},
216
328
  children: code
217
- }), {
218
- headTags,
219
- bodyTags
220
- };
221
- }) : (api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
222
- let scriptPath = getScriptPath(environment), url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
223
- return headTags.unshift({
224
- tag: "script",
225
- attrs: {
226
- src: url
227
- }
228
- }), {
329
+ });
330
+ return {
229
331
  headTags,
230
332
  bodyTags
231
333
  };
232
- }), api.processAssets({
233
- stage: 'additional'
234
- }, async ({ sources, compilation, environment })=>{
235
- let scriptPath = getScriptPath(environment), code = await getRetryCode(formatOptions(environment.config));
236
- compilation.emitAsset(scriptPath, new sources.RawSource(code));
237
- })), api.modifyBundlerChain(async (chain, { environment })=>{
238
- let { config, htmlPaths } = environment;
334
+ });
335
+ else {
336
+ api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
337
+ const scriptPath = getScriptPath(environment);
338
+ const url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
339
+ headTags.unshift({
340
+ tag: "script",
341
+ attrs: {
342
+ src: url
343
+ }
344
+ });
345
+ return {
346
+ headTags,
347
+ bodyTags
348
+ };
349
+ });
350
+ api.processAssets({
351
+ stage: 'additional'
352
+ }, async ({ sources, compilation, environment })=>{
353
+ const scriptPath = getScriptPath(environment);
354
+ const code = await getRetryCode(formatOptions(environment.config));
355
+ compilation.emitAsset(scriptPath, new sources.RawSource(code));
356
+ });
357
+ }
358
+ api.modifyBundlerChain(async (chain, { environment })=>{
359
+ const { config, htmlPaths } = environment;
239
360
  if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
240
- let options = formatOptions(config), isRspack = 'rspack' === api.context.bundlerType;
361
+ const options = formatOptions(config);
362
+ const isRspack = 'rspack' === api.context.bundlerType;
241
363
  chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
242
364
  {
243
365
  ...options,
@@ -250,6 +372,6 @@ var __webpack_exports__ = {};
250
372
  })();
251
373
  var __webpack_export_target__ = exports;
252
374
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
253
- __webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
254
- value: !0
375
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
376
+ value: true
255
377
  });