@rsbuild/plugin-assets-retry 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,29 +1,16 @@
1
1
  var __webpack_modules__ = {
2
- "../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
3
- module.exports = __webpack_require__("crypto")/* .randomBytes */ .randomBytes;
2
+ "../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js": function(module1, __unused_webpack_exports, __webpack_require__) {
3
+ module1.exports = __webpack_require__("crypto").randomBytes;
4
4
  },
5
- "../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module, __unused_webpack_exports, __webpack_require__) {
5
+ "../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js": function(module1, __unused_webpack_exports, __webpack_require__) {
6
6
  "use strict";
7
- /*
8
- Copyright (c) 2014, Yahoo! Inc. All rights reserved.
9
- Copyrights licensed under the New BSD License.
10
- See the accompanying LICENSE file for terms.
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 = [
7
+ var randomBytes = __webpack_require__("../../node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js"), UID = function() {
8
+ for(var bytes = randomBytes(16), result = '', i = 0; i < 16; ++i)result += bytes[i].toString(16);
9
+ return result;
10
+ }(), 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
11
  '*',
22
12
  '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 = {
13
+ ], ESCAPED_CHARS = {
27
14
  '<': '\\u003C',
28
15
  '>': '\\u003E',
29
16
  '/': '\\u002F',
@@ -33,269 +20,138 @@ See the accompanying LICENSE file for terms.
33
20
  function escapeUnsafeChars(unsafeChar) {
34
21
  return ESCAPED_CHARS[unsafeChar];
35
22
  }
36
- function generateUID() {
37
- var bytes = randomBytes(UID_LENGTH);
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
- module.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 = {
23
+ module1.exports = function serialize(obj, options) {
24
+ options || (options = {}), ('number' == typeof options || 'string' == typeof options) && (options = {
51
25
  space: options
52
- };
53
- var functions = [];
54
- var regexps = [];
55
- var dates = [];
56
- var maps = [];
57
- var sets = [];
58
- var arrays = [];
59
- var undefs = [];
60
- var infinities = [];
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;
26
+ });
27
+ var str, functions = [], regexps = [], dates = [], maps = [], sets = [], arrays = [], undefs = [], infinities = [], bigInts = [], urls = [];
28
+ 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) {
29
+ if (options.ignoreFunction && !function(obj) {
30
+ var functionKeys = [];
31
+ for(var key in obj)"function" == typeof obj[key] && functionKeys.push(key);
32
+ for(var i = 0; i < functionKeys.length; i++)delete obj[functionKeys[i]];
33
+ }(value), !value && void 0 !== value && value !== BigInt(0)) return value;
34
+ var origValue = this[key], type = typeof origValue;
73
35
  if ('object' === type) {
74
36
  if (origValue instanceof RegExp) return '@__R-' + UID + '-' + (regexps.push(origValue) - 1) + '__@';
75
37
  if (origValue instanceof Date) return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
76
38
  if (origValue instanceof Map) return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
77
39
  if (origValue instanceof Set) return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
78
- if (origValue instanceof Array) {
79
- var isSparse = origValue.filter(function() {
80
- return true;
81
- }).length !== origValue.length;
82
- if (isSparse) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
83
- }
40
+ if (origValue instanceof Array && origValue.filter(function() {
41
+ return !0;
42
+ }).length !== origValue.length) return '@__A-' + UID + '-' + (arrays.push(origValue) - 1) + '__@';
84
43
  if (origValue instanceof URL) return '@__L-' + UID + '-' + (urls.push(origValue) - 1) + '__@';
85
44
  }
86
- if ('function' === type) return '@__F-' + UID + '-' + (functions.push(origValue) - 1) + '__@';
87
- if ('undefined' === type) return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
88
- if ('number' === type && !isNaN(origValue) && !isFinite(origValue)) return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
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({
45
+ 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) + '__@';
46
+ }, 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) {
47
+ 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
48
  length: arrays[valueIndex].length
142
- }, arrays[valueIndex]), options) + ")";
143
- if ('U' === type) return 'undefined';
144
- if ('I' === type) return infinities[valueIndex];
145
- if ('B' === type) return "BigInt(\"" + bigInts[valueIndex] + "\")";
146
- if ('L' === type) return "new URL(" + serialize(urls[valueIndex].toString(), options) + ")";
147
- var fn = functions[valueIndex];
148
- return serializeFunc(fn);
49
+ }, 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) {
50
+ var serializedFn = fn.toString();
51
+ if (IS_NATIVE_CODE_REGEXP.test(serializedFn)) throw TypeError('Serializing native function: ' + fn.name);
52
+ if (IS_PURE_FUNCTION.test(serializedFn) || IS_ARROW_FUNCTION.test(serializedFn)) return serializedFn;
53
+ var argsStartsAt = serializedFn.indexOf('('), def = serializedFn.substr(0, argsStartsAt).trim().split(' ').filter(function(val) {
54
+ return val.length > 0;
55
+ });
56
+ return def.filter(function(val) {
57
+ return -1 === RESERVED_SYMBOLS.indexOf(val);
58
+ }).length > 0 ? (def.indexOf('async') > -1 ? 'async ' : '') + 'function' + (def.join('').indexOf('*') > -1 ? '*' : '') + serializedFn.substr(argsStartsAt) : serializedFn;
59
+ }(functions[valueIndex]);
149
60
  });
150
61
  };
151
62
  },
152
- crypto: function(module) {
63
+ crypto: function(module1) {
153
64
  "use strict";
154
- module.exports = require("crypto");
65
+ module1.exports = require("crypto");
155
66
  }
156
- };
157
- /************************************************************************/ // The module cache
158
- var __webpack_module_cache__ = {};
159
- // The require function
67
+ }, __webpack_module_cache__ = {};
160
68
  function __webpack_require__(moduleId) {
161
- // Check if module is in cache
162
69
  var cachedModule = __webpack_module_cache__[moduleId];
163
70
  if (void 0 !== cachedModule) return cachedModule.exports;
164
- // Create a new module (and put it into the cache)
165
- var module = __webpack_module_cache__[moduleId] = {
71
+ var module1 = __webpack_module_cache__[moduleId] = {
166
72
  exports: {}
167
73
  };
168
- // Execute the module function
169
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
170
- // Return the exports of the module
171
- return module.exports;
74
+ return __webpack_modules__[moduleId](module1, module1.exports, __webpack_require__), module1.exports;
172
75
  }
173
- /************************************************************************/ // webpack/runtime/compat_get_default_export
174
- (()=>{
175
- // getDefaultExport function for compatibility with non-harmony modules
176
- __webpack_require__.n = function(module) {
177
- var getter = module && module.__esModule ? function() {
178
- return module['default'];
179
- } : function() {
180
- return module;
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
- });
76
+ __webpack_require__.n = function(module1) {
77
+ var getter = module1 && module1.__esModule ? function() {
78
+ return module1.default;
79
+ } : function() {
80
+ return module1;
213
81
  };
214
- })();
215
- /************************************************************************/ var __webpack_exports__ = {};
216
- // This entry need to be wrapped in an IIFE because it need to be in strict mode.
82
+ return __webpack_require__.d(getter, {
83
+ a: getter
84
+ }), getter;
85
+ }, __webpack_require__.d = function(exports1, definition) {
86
+ for(var key in definition)__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key) && Object.defineProperty(exports1, key, {
87
+ enumerable: !0,
88
+ get: definition[key]
89
+ });
90
+ }, __webpack_require__.o = function(obj, prop) {
91
+ return Object.prototype.hasOwnProperty.call(obj, prop);
92
+ }, __webpack_require__.r = function(exports1) {
93
+ 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports1, Symbol.toStringTag, {
94
+ value: 'Module'
95
+ }), Object.defineProperty(exports1, '__esModule', {
96
+ value: !0
97
+ });
98
+ };
99
+ var __webpack_exports__ = {};
217
100
  (()=>{
218
101
  "use strict";
219
- // ESM COMPAT FLAG
220
- __webpack_require__.r(__webpack_exports__);
221
- // EXPORTS
222
- __webpack_require__.d(__webpack_exports__, {
223
- PLUGIN_ASSETS_RETRY_NAME: ()=>/* binding */ PLUGIN_ASSETS_RETRY_NAME,
224
- pluginAssetsRetry: ()=>/* binding */ pluginAssetsRetry
102
+ __webpack_require__.r(__webpack_exports__), __webpack_require__.d(__webpack_exports__, {
103
+ PLUGIN_ASSETS_RETRY_NAME: ()=>PLUGIN_ASSETS_RETRY_NAME,
104
+ pluginAssetsRetry: ()=>pluginAssetsRetry
225
105
  });
226
- const external_node_fs_namespaceObject = require("node:fs");
227
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
228
- const external_node_path_namespaceObject = require("node:path");
229
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
230
- const core_namespaceObject = require("@rsbuild/core");
231
- // EXTERNAL MODULE: ../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js
232
- var serialize_javascript = __webpack_require__("../../node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js");
233
- var serialize_javascript_default = /*#__PURE__*/ __webpack_require__.n(serialize_javascript);
106
+ let external_node_fs_namespaceObject = require("node:fs");
107
+ var external_node_fs_default = __webpack_require__.n(external_node_fs_namespaceObject);
108
+ let external_node_path_namespaceObject = require("node:path");
109
+ var external_node_path_default = __webpack_require__.n(external_node_path_namespaceObject);
110
+ let external_node_url_namespaceObject = require("node:url"), core_namespaceObject = require("@rsbuild/core");
111
+ 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);
234
112
  function _define_property(obj, key, value) {
235
- if (key in obj) Object.defineProperty(obj, key, {
113
+ return key in obj ? Object.defineProperty(obj, key, {
236
114
  value: value,
237
- enumerable: true,
238
- configurable: true,
239
- writable: true
240
- });
241
- else obj[key] = value;
242
- return obj;
243
- }
244
- // https://github.com/web-infra-dev/rspack/pull/5370
245
- function appendWebpackScript(module, appendSource) {
246
- try {
247
- const originSource = module.getGeneratedCode();
248
- module.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
249
- } catch (err) {
250
- console.error('Failed to modify Webpack RuntimeModule');
251
- throw err;
252
- }
253
- }
254
- function appendRspackScript(module, appendSource) {
255
- try {
256
- const source = module.source.source.toString();
257
- module.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
258
- } catch (err) {
259
- console.error('Failed to modify Rspack RuntimeModule');
260
- throw err;
261
- }
262
- }
263
- function pick(obj, keys) {
264
- return keys.reduce((ret, key)=>{
265
- if (void 0 !== obj[key]) ret[key] = obj[key];
266
- return ret;
267
- }, {});
115
+ enumerable: !0,
116
+ configurable: !0,
117
+ writable: !0
118
+ }) : obj[key] = value, obj;
268
119
  }
120
+ let AsyncChunkRetryPlugin_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)('undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href));
269
121
  class AsyncChunkRetryPlugin {
270
122
  getRawRuntimeRetryCode() {
271
- const { RuntimeGlobals } = core_namespaceObject.rspack;
272
- const filename = 'asyncChunkRetry';
273
- const runtimeFilePath = external_node_path_default().join(__dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
274
- const rawText = external_node_fs_default().readFileSync(runtimeFilePath, 'utf-8');
275
- 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));
123
+ let { RuntimeGlobals } = core_namespaceObject.rspack, filename = 'asyncChunkRetry', runtimeFilePath = external_node_path_default().join(AsyncChunkRetryPlugin_dirname, 'runtime', this.options.minify ? `${filename}.min.js` : `${filename}.js`);
124
+ 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));
276
125
  }
277
126
  apply(compiler) {
278
127
  compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
279
- compilation.hooks.runtimeModule.tap(this.name, (module)=>{
128
+ compilation.hooks.runtimeModule.tap(this.name, (module1)=>{
280
129
  var _module_constructor;
281
- const { isRspack } = this.options;
282
- const constructorName = isRspack ? module.constructorName : null === (_module_constructor = module.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
283
- const isPublicPathModule = 'publicPath' === module.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName;
284
- if (!isPublicPathModule) return;
285
- const runtimeCode = this.getRawRuntimeRetryCode();
286
- // Rspack currently does not have module.addRuntimeModule on the js side,
287
- // so we insert our runtime code after PublicPathRuntimeModule or AutoPublicPathRuntimeModule.
288
- if (isRspack) appendRspackScript(module, runtimeCode);
289
- else appendWebpackScript(module, runtimeCode);
130
+ let { isRspack } = this.options, constructorName = isRspack ? module1.constructorName : null === (_module_constructor = module1.constructor) || void 0 === _module_constructor ? void 0 : _module_constructor.name;
131
+ if (!('publicPath' === module1.name || 'PublicPathRuntimeModule' === constructorName || 'AutoPublicPathRuntimeModule' === constructorName)) return;
132
+ let runtimeCode = this.getRawRuntimeRetryCode();
133
+ isRspack ? !function(module1, appendSource) {
134
+ try {
135
+ let source = module1.source.source.toString();
136
+ module1.source.source = Buffer.from(`${source}\n${appendSource}`, 'utf-8');
137
+ } catch (err) {
138
+ throw console.error('Failed to modify Rspack RuntimeModule'), err;
139
+ }
140
+ }(module1, runtimeCode) : !function(module1, appendSource) {
141
+ try {
142
+ let originSource = module1.getGeneratedCode();
143
+ module1.getGeneratedCode = ()=>`${originSource}\n${appendSource}`;
144
+ } catch (err) {
145
+ throw console.error('Failed to modify Webpack RuntimeModule'), err;
146
+ }
147
+ }(module1, runtimeCode);
290
148
  });
291
149
  });
292
150
  }
293
151
  constructor(options){
294
- _define_property(this, "name", 'ASYNC_CHUNK_RETRY_PLUGIN');
295
- _define_property(this, "options", void 0);
296
- _define_property(this, "runtimeOptions", void 0);
297
- this.options = options;
298
- this.runtimeOptions = pick(options, [
152
+ _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) {
153
+ return keys.reduce((ret, key)=>(void 0 !== obj[key] && (ret[key] = obj[key]), ret), {});
154
+ }(options, [
299
155
  'domain',
300
156
  'max',
301
157
  'onRetry',
@@ -306,81 +162,58 @@ function __webpack_require__(moduleId) {
306
162
  ]);
307
163
  }
308
164
  }
309
- const PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
165
+ let src_dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)('undefined' == typeof document ? new (module.require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href)), PLUGIN_ASSETS_RETRY_NAME = 'rsbuild:assets-retry';
310
166
  async function getRetryCode(options) {
311
- const filename = 'initialChunkRetry';
312
- const { minify, inlineScript: _, ...restOptions } = options;
313
- const runtimeFilePath = external_node_path_default().join(__dirname, 'runtime', minify ? `${filename}.min.js` : `${filename}.js`);
314
- const runtimeCode = await external_node_fs_default().promises.readFile(runtimeFilePath, 'utf-8');
167
+ 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');
315
168
  return `(function(){${runtimeCode};init(${serialize_javascript_default()(restOptions)});})()`;
316
169
  }
317
- const pluginAssetsRetry = function() {
318
- let userOptions = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
319
- return {
170
+ let pluginAssetsRetry = (userOptions = {})=>({
320
171
  name: PLUGIN_ASSETS_RETRY_NAME,
321
172
  setup (api) {
322
- const { inlineScript = true } = userOptions;
323
- const getScriptPath = (environment)=>{
324
- const distDir = environment.config.output.distPath.js;
325
- return external_node_path_default().posix.join(distDir, "assets-retry.1-0-3.js");
326
- };
327
- const formatOptions = (config)=>{
328
- const options = {
173
+ let { inlineScript = !0 } = userOptions, getScriptPath = (environment)=>{
174
+ let distDir = environment.config.output.distPath.js;
175
+ return external_node_path_default().posix.join(distDir, "assets-retry.1-0-5.js");
176
+ }, formatOptions = (config)=>{
177
+ let options = {
329
178
  ...userOptions
330
179
  };
331
- // options.crossOrigin should be same as html.crossorigin by default
332
- if (void 0 === options.crossOrigin) options.crossOrigin = config.html.crossorigin;
333
- if (void 0 === options.minify) {
180
+ if (void 0 === options.crossOrigin && (options.crossOrigin = config.html.crossorigin), void 0 === options.minify) {
334
181
  var _config_output_minify;
335
- 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;
182
+ 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;
336
183
  options.minify = minify && 'production' === config.mode;
337
184
  }
338
185
  return options;
339
186
  };
340
- if (inlineScript) api.modifyHTMLTags(async (param, param1)=>{
341
- let { headTags, bodyTags } = param, { environment } = param1;
342
- const code = await getRetryCode(formatOptions(environment.config));
343
- headTags.unshift({
187
+ inlineScript ? api.modifyHTMLTags(async ({ headTags, bodyTags }, { environment })=>{
188
+ let code = await getRetryCode(formatOptions(environment.config));
189
+ return headTags.unshift({
344
190
  tag: 'script',
345
191
  attrs: {},
346
192
  children: code
347
- });
348
- return {
193
+ }), {
349
194
  headTags,
350
195
  bodyTags
351
196
  };
352
- });
353
- else {
354
- api.modifyHTMLTags(async (param, param1)=>{
355
- let { headTags, bodyTags } = param, { assetPrefix, environment } = param1;
356
- const scriptPath = getScriptPath(environment);
357
- const url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
358
- headTags.unshift({
359
- tag: 'script',
360
- attrs: {
361
- src: url
362
- }
363
- });
364
- return {
365
- headTags,
366
- bodyTags
367
- };
368
- });
369
- api.processAssets({
370
- stage: 'additional'
371
- }, async (param)=>{
372
- let { sources, compilation, environment } = param;
373
- const scriptPath = getScriptPath(environment);
374
- const code = await getRetryCode(formatOptions(environment.config));
375
- compilation.emitAsset(scriptPath, new sources.RawSource(code));
376
- });
377
- }
378
- api.modifyBundlerChain(async (chain, param)=>{
379
- let { environment } = param;
380
- const { config, htmlPaths } = environment;
197
+ }) : (api.modifyHTMLTags(async ({ headTags, bodyTags }, { assetPrefix, environment })=>{
198
+ let scriptPath = getScriptPath(environment), url = (0, core_namespaceObject.ensureAssetPrefix)(scriptPath, assetPrefix);
199
+ return headTags.unshift({
200
+ tag: 'script',
201
+ attrs: {
202
+ src: url
203
+ }
204
+ }), {
205
+ headTags,
206
+ bodyTags
207
+ };
208
+ }), api.processAssets({
209
+ stage: 'additional'
210
+ }, async ({ sources, compilation, environment })=>{
211
+ let scriptPath = getScriptPath(environment), code = await getRetryCode(formatOptions(environment.config));
212
+ compilation.emitAsset(scriptPath, new sources.RawSource(code));
213
+ })), api.modifyBundlerChain(async (chain, { environment })=>{
214
+ let { config, htmlPaths } = environment;
381
215
  if (!userOptions || 0 === Object.keys(htmlPaths).length) return;
382
- const options = formatOptions(config);
383
- const isRspack = 'rspack' === api.context.bundlerType;
216
+ let options = formatOptions(config), isRspack = 'rspack' === api.context.bundlerType;
384
217
  chain.plugin('async-chunk-retry').use(AsyncChunkRetryPlugin, [
385
218
  {
386
219
  ...options,
@@ -389,11 +222,10 @@ function __webpack_require__(moduleId) {
389
222
  ]);
390
223
  });
391
224
  }
392
- };
393
- };
225
+ });
394
226
  })();
395
227
  var __webpack_export_target__ = exports;
396
228
  for(var i in __webpack_exports__)__webpack_export_target__[i] = __webpack_exports__[i];
397
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
398
- value: true
229
+ __webpack_exports__.__esModule && Object.defineProperty(__webpack_export_target__, '__esModule', {
230
+ value: !0
399
231
  });