@module-federation/sdk 0.2.2 → 0.2.4

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.js CHANGED
@@ -2,41 +2,34 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function _define_property$4(obj, key, value) {
6
- if (key in obj) {
7
- Object.defineProperty(obj, key, {
8
- value: value,
9
- enumerable: true,
10
- configurable: true,
11
- writable: true
12
- });
13
- } else {
14
- obj[key] = value;
15
- }
16
- return obj;
17
- }
18
- var FederationModuleManifest = 'federation-manifest.json';
19
- var MANIFEST_EXT = '.json';
20
- var BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
21
- var BROWSER_LOG_VALUE = '1';
22
- var NameTransformSymbol = {
5
+ const FederationModuleManifest = 'federation-manifest.json';
6
+ const MANIFEST_EXT = '.json';
7
+ const BROWSER_LOG_KEY = 'FEDERATION_DEBUG';
8
+ const BROWSER_LOG_VALUE = '1';
9
+ const NameTransformSymbol = {
23
10
  AT: '@',
24
11
  HYPHEN: '-',
25
12
  SLASH: '/'
26
13
  };
27
- var _obj;
28
- var NameTransformMap = (_obj = {}, _define_property$4(_obj, NameTransformSymbol.AT, 'scope_'), _define_property$4(_obj, NameTransformSymbol.HYPHEN, '_'), _define_property$4(_obj, NameTransformSymbol.SLASH, '__'), _obj);
29
- var _obj1;
30
- var EncodedNameTransformMap = (_obj1 = {}, _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.AT], NameTransformSymbol.AT), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.HYPHEN], NameTransformSymbol.HYPHEN), _define_property$4(_obj1, NameTransformMap[NameTransformSymbol.SLASH], NameTransformSymbol.SLASH), _obj1);
31
- var SEPARATOR = ':';
32
- var ManifestFileName = 'mf-manifest.json';
33
- var StatsFileName = 'mf-stats.json';
34
- var MFModuleType = {
14
+ const NameTransformMap = {
15
+ [NameTransformSymbol.AT]: 'scope_',
16
+ [NameTransformSymbol.HYPHEN]: '_',
17
+ [NameTransformSymbol.SLASH]: '__'
18
+ };
19
+ const EncodedNameTransformMap = {
20
+ [NameTransformMap[NameTransformSymbol.AT]]: NameTransformSymbol.AT,
21
+ [NameTransformMap[NameTransformSymbol.HYPHEN]]: NameTransformSymbol.HYPHEN,
22
+ [NameTransformMap[NameTransformSymbol.SLASH]]: NameTransformSymbol.SLASH
23
+ };
24
+ const SEPARATOR = ':';
25
+ const ManifestFileName = 'mf-manifest.json';
26
+ const StatsFileName = 'mf-stats.json';
27
+ const MFModuleType = {
35
28
  NPM: 'npm',
36
29
  APP: 'app'
37
30
  };
38
- var MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
39
- var ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
31
+ const MODULE_DEVTOOL_IDENTIFIER = '__MF_DEVTOOLS_MODULE_INFO__';
32
+ const ENCODE_NAME_PREFIX = 'ENCODE_NAME_PREFIX';
40
33
 
41
34
  var ContainerPlugin = /*#__PURE__*/Object.freeze({
42
35
  __proto__: null
@@ -63,67 +56,10 @@ function isDebugMode() {
63
56
  }
64
57
  return typeof FEDERATION_DEBUG !== 'undefined' && Boolean(FEDERATION_DEBUG);
65
58
  }
66
- var getProcessEnv = function getProcessEnv() {
59
+ const getProcessEnv = function() {
67
60
  return typeof process !== 'undefined' && process.env ? process.env : {};
68
61
  };
69
62
 
70
- function _array_like_to_array$2(arr, len) {
71
- if (len == null || len > arr.length) len = arr.length;
72
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
73
- return arr2;
74
- }
75
- function _array_without_holes(arr) {
76
- if (Array.isArray(arr)) return _array_like_to_array$2(arr);
77
- }
78
- function _class_call_check(instance, Constructor) {
79
- if (!(instance instanceof Constructor)) {
80
- throw new TypeError("Cannot call a class as a function");
81
- }
82
- }
83
- function _defineProperties(target, props) {
84
- for(var i = 0; i < props.length; i++){
85
- var descriptor = props[i];
86
- descriptor.enumerable = descriptor.enumerable || false;
87
- descriptor.configurable = true;
88
- if ("value" in descriptor) descriptor.writable = true;
89
- Object.defineProperty(target, descriptor.key, descriptor);
90
- }
91
- }
92
- function _create_class(Constructor, protoProps, staticProps) {
93
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
94
- if (staticProps) _defineProperties(Constructor, staticProps);
95
- return Constructor;
96
- }
97
- function _define_property$3(obj, key, value) {
98
- if (key in obj) {
99
- Object.defineProperty(obj, key, {
100
- value: value,
101
- enumerable: true,
102
- configurable: true,
103
- writable: true
104
- });
105
- } else {
106
- obj[key] = value;
107
- }
108
- return obj;
109
- }
110
- function _iterable_to_array$1(iter) {
111
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
112
- }
113
- function _non_iterable_spread() {
114
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
115
- }
116
- function _to_consumable_array(arr) {
117
- return _array_without_holes(arr) || _iterable_to_array$1(arr) || _unsupported_iterable_to_array$2(arr) || _non_iterable_spread();
118
- }
119
- function _unsupported_iterable_to_array$2(o, minLen) {
120
- if (!o) return;
121
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
122
- var n = Object.prototype.toString.call(o).slice(8, -1);
123
- if (n === "Object" && o.constructor) n = o.constructor.name;
124
- if (n === "Map" || n === "Set") return Array.from(n);
125
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
126
- }
127
63
  function safeToString(info) {
128
64
  try {
129
65
  return JSON.stringify(info, null, 2);
@@ -131,7 +67,7 @@ function safeToString(info) {
131
67
  return '';
132
68
  }
133
69
  }
134
- var DEBUG_LOG = '[ FEDERATION DEBUG ]';
70
+ const DEBUG_LOG = '[ FEDERATION DEBUG ]';
135
71
  function safeGetLocalStorageItem() {
136
72
  try {
137
73
  if (typeof window !== 'undefined' && window.localStorage) {
@@ -142,11 +78,30 @@ function safeGetLocalStorageItem() {
142
78
  }
143
79
  return false;
144
80
  }
145
- var Logger = /*#__PURE__*/ function() {
146
- function Logger(identifier) {
147
- _class_call_check(this, Logger);
148
- _define_property$3(this, "enable", false);
149
- _define_property$3(this, "identifier", void 0);
81
+ let Logger = class Logger {
82
+ info(msg, info) {
83
+ if (this.enable) {
84
+ const argsToString = safeToString(info) || '';
85
+ if (isBrowserEnv()) {
86
+ console.info(`%c ${this.identifier}: ${msg} ${argsToString}`, 'color:#3300CC');
87
+ } else {
88
+ console.info('\x1b[34m%s', `${this.identifier}: ${msg} ${argsToString ? `\n${argsToString}` : ''}`);
89
+ }
90
+ }
91
+ }
92
+ logOriginalInfo(...args) {
93
+ if (this.enable) {
94
+ if (isBrowserEnv()) {
95
+ console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
96
+ console.log(...args);
97
+ } else {
98
+ console.info(`%c ${this.identifier}: OriginalInfo`, 'color:#3300CC');
99
+ console.log(...args);
100
+ }
101
+ }
102
+ }
103
+ constructor(identifier){
104
+ this.enable = false;
150
105
  this.identifier = identifier || DEBUG_LOG;
151
106
  if (isBrowserEnv() && safeGetLocalStorageItem()) {
152
107
  this.enable = true;
@@ -154,182 +109,88 @@ var Logger = /*#__PURE__*/ function() {
154
109
  this.enable = true;
155
110
  }
156
111
  }
157
- _create_class(Logger, [
158
- {
159
- key: "info",
160
- value: function info(msg, info) {
161
- if (this.enable) {
162
- var argsToString = safeToString(info) || '';
163
- if (isBrowserEnv()) {
164
- console.info("%c ".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString), 'color:#3300CC');
165
- } else {
166
- console.info('\x1b[34m%s', "".concat(this.identifier, ": ").concat(msg, " ").concat(argsToString ? "\n".concat(argsToString) : ''));
167
- }
168
- }
169
- }
170
- },
171
- {
172
- key: "logOriginalInfo",
173
- value: function logOriginalInfo() {
174
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
175
- args[_key] = arguments[_key];
176
- }
177
- if (this.enable) {
178
- if (isBrowserEnv()) {
179
- var _console;
180
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
181
- (_console = console).log.apply(_console, _to_consumable_array(args));
182
- } else {
183
- var _console1;
184
- console.info("%c ".concat(this.identifier, ": OriginalInfo"), 'color:#3300CC');
185
- (_console1 = console).log.apply(_console1, _to_consumable_array(args));
186
- }
187
- }
188
- }
189
- }
190
- ]);
191
- return Logger;
192
- }();
112
+ };
193
113
 
194
- function _array_like_to_array$1(arr, len) {
195
- if (len == null || len > arr.length) len = arr.length;
196
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
197
- return arr2;
198
- }
199
- function _array_with_holes$1(arr) {
200
- if (Array.isArray(arr)) return arr;
201
- }
202
- function _iterable_to_array(iter) {
203
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
204
- }
205
- function _iterable_to_array_limit$1(arr, i) {
206
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
207
- if (_i == null) return;
208
- var _arr = [];
209
- var _n = true;
210
- var _d = false;
211
- var _s, _e;
212
- try {
213
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
214
- _arr.push(_s.value);
215
- if (i && _arr.length === i) break;
216
- }
217
- } catch (err) {
218
- _d = true;
219
- _e = err;
220
- } finally{
221
- try {
222
- if (!_n && _i["return"] != null) _i["return"]();
223
- } finally{
224
- if (_d) throw _e;
225
- }
226
- }
227
- return _arr;
228
- }
229
- function _non_iterable_rest$1() {
230
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
231
- }
232
- function _sliced_to_array$1(arr, i) {
233
- return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
234
- }
235
- function _to_array(arr) {
236
- return _array_with_holes$1(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array$1(arr) || _non_iterable_rest$1();
237
- }
238
- function _unsupported_iterable_to_array$1(o, minLen) {
239
- if (!o) return;
240
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
241
- var n = Object.prototype.toString.call(o).slice(8, -1);
242
- if (n === "Object" && o.constructor) n = o.constructor.name;
243
- if (n === "Map" || n === "Set") return Array.from(n);
244
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
245
- }
246
- var LOG_CATEGORY = '[ Federation Runtime ]';
114
+ const LOG_CATEGORY = '[ Federation Runtime ]';
247
115
  // entry: name:version version : 1.0.0 | ^1.2.3
248
116
  // entry: name:entry entry: https://localhost:9000/federation-manifest.json
249
- var parseEntry = function(str, devVerOrUrl) {
250
- var separator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : SEPARATOR;
251
- var strSplit = str.split(separator);
252
- var devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
253
- var defaultVersion = '*';
254
- var isEntry = function(s) {
255
- return s.startsWith('http') || s.includes(MANIFEST_EXT);
256
- };
117
+ const parseEntry = (str, devVerOrUrl, separator = SEPARATOR)=>{
118
+ const strSplit = str.split(separator);
119
+ const devVersionOrUrl = getProcessEnv()['NODE_ENV'] === 'development' && devVerOrUrl;
120
+ const defaultVersion = '*';
121
+ const isEntry = (s)=>s.startsWith('http') || s.includes(MANIFEST_EXT);
257
122
  // Check if the string starts with a type
258
123
  if (strSplit.length >= 2) {
259
- var _strSplit = _to_array(strSplit), name = _strSplit[0], versionOrEntryArr = _strSplit.slice(1);
124
+ let [name, ...versionOrEntryArr] = strSplit;
260
125
  if (str.startsWith(separator)) {
261
126
  versionOrEntryArr = [
262
127
  devVersionOrUrl || strSplit.slice(-1)[0]
263
128
  ];
264
129
  name = strSplit.slice(0, -1).join(separator);
265
130
  }
266
- var versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
131
+ let versionOrEntry = devVersionOrUrl || versionOrEntryArr.join(separator);
267
132
  if (isEntry(versionOrEntry)) {
268
133
  return {
269
- name: name,
134
+ name,
270
135
  entry: versionOrEntry
271
136
  };
272
137
  } else {
273
138
  // Apply version rule
274
139
  // devVersionOrUrl => inputVersion => defaultVersion
275
140
  return {
276
- name: name,
141
+ name,
277
142
  version: versionOrEntry || defaultVersion
278
143
  };
279
144
  }
280
145
  } else if (strSplit.length === 1) {
281
- var _strSplit1 = _sliced_to_array$1(strSplit, 1), name1 = _strSplit1[0];
146
+ const [name] = strSplit;
282
147
  if (devVersionOrUrl && isEntry(devVersionOrUrl)) {
283
148
  return {
284
- name: name1,
149
+ name,
285
150
  entry: devVersionOrUrl
286
151
  };
287
152
  }
288
153
  return {
289
- name: name1,
154
+ name,
290
155
  version: devVersionOrUrl || defaultVersion
291
156
  };
292
157
  } else {
293
- throw "Invalid entry value: ".concat(str);
158
+ throw `Invalid entry value: ${str}`;
294
159
  }
295
160
  };
296
- var logger = new Logger();
297
- var composeKeyWithSeparator = function composeKeyWithSeparator() {
298
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
299
- args[_key] = arguments[_key];
300
- }
161
+ const logger = new Logger();
162
+ const composeKeyWithSeparator = function(...args) {
301
163
  if (!args.length) {
302
164
  return '';
303
165
  }
304
- return args.reduce(function(sum, cur) {
166
+ return args.reduce((sum, cur)=>{
305
167
  if (!cur) {
306
168
  return sum;
307
169
  }
308
170
  if (!sum) {
309
171
  return cur;
310
172
  }
311
- return "".concat(sum).concat(SEPARATOR).concat(cur);
173
+ return `${sum}${SEPARATOR}${cur}`;
312
174
  }, '');
313
175
  };
314
- var encodeName = function encodeName(name) {
315
- var prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', withExt = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
176
+ const encodeName = function(name, prefix = '', withExt = false) {
316
177
  try {
317
- var ext = withExt ? '.js' : '';
318
- return "".concat(prefix).concat(name.replace(new RegExp("".concat(NameTransformSymbol.AT), 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp("".concat(NameTransformSymbol.HYPHEN), 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp("".concat(NameTransformSymbol.SLASH), 'g'), NameTransformMap[NameTransformSymbol.SLASH])).concat(ext);
178
+ const ext = withExt ? '.js' : '';
179
+ return `${prefix}${name.replace(new RegExp(`${NameTransformSymbol.AT}`, 'g'), NameTransformMap[NameTransformSymbol.AT]).replace(new RegExp(`${NameTransformSymbol.HYPHEN}`, 'g'), NameTransformMap[NameTransformSymbol.HYPHEN]).replace(new RegExp(`${NameTransformSymbol.SLASH}`, 'g'), NameTransformMap[NameTransformSymbol.SLASH])}${ext}`;
319
180
  } catch (err) {
320
181
  throw err;
321
182
  }
322
183
  };
323
- var decodeName = function decodeName(name, prefix, withExt) {
184
+ const decodeName = function(name, prefix, withExt) {
324
185
  try {
325
- var decodedName = name;
186
+ let decodedName = name;
326
187
  if (prefix) {
327
188
  if (!decodedName.startsWith(prefix)) {
328
189
  return decodedName;
329
190
  }
330
191
  decodedName = decodedName.replace(new RegExp(prefix, 'g'), '');
331
192
  }
332
- decodedName = decodedName.replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.AT]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.SLASH]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp("".concat(NameTransformMap[NameTransformSymbol.HYPHEN]), 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
193
+ decodedName = decodedName.replace(new RegExp(`${NameTransformMap[NameTransformSymbol.AT]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.AT]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.SLASH]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.SLASH]]).replace(new RegExp(`${NameTransformMap[NameTransformSymbol.HYPHEN]}`, 'g'), EncodedNameTransformMap[NameTransformMap[NameTransformSymbol.HYPHEN]]);
333
194
  if (withExt) {
334
195
  decodedName = decodedName.replace('.js', '');
335
196
  }
@@ -338,11 +199,11 @@ var decodeName = function decodeName(name, prefix, withExt) {
338
199
  throw err;
339
200
  }
340
201
  };
341
- var generateExposeFilename = function(exposeName, withExt) {
202
+ const generateExposeFilename = (exposeName, withExt)=>{
342
203
  if (!exposeName) {
343
204
  return '';
344
205
  }
345
- var expose = exposeName;
206
+ let expose = exposeName;
346
207
  if (expose === '.') {
347
208
  expose = 'default_export';
348
209
  }
@@ -351,98 +212,57 @@ var generateExposeFilename = function(exposeName, withExt) {
351
212
  }
352
213
  return encodeName(expose, '__federation_expose_', withExt);
353
214
  };
354
- var generateShareFilename = function(pkgName, withExt) {
215
+ const generateShareFilename = (pkgName, withExt)=>{
355
216
  if (!pkgName) {
356
217
  return '';
357
218
  }
358
219
  return encodeName(pkgName, '__federation_shared_', withExt);
359
220
  };
360
- var getResourceUrl = function(module, sourceUrl) {
221
+ const getResourceUrl = (module, sourceUrl)=>{
361
222
  if ('getPublicPath' in module) {
362
- var publicPath;
223
+ let publicPath;
363
224
  if (!module.getPublicPath.startsWith('function')) {
364
225
  publicPath = new Function(module.getPublicPath)();
365
226
  } else {
366
227
  publicPath = new Function('return ' + module.getPublicPath)()();
367
228
  }
368
- return "".concat(publicPath).concat(sourceUrl);
229
+ return `${publicPath}${sourceUrl}`;
369
230
  } else if ('publicPath' in module) {
370
- return "".concat(module.publicPath).concat(sourceUrl);
231
+ return `${module.publicPath}${sourceUrl}`;
371
232
  } else {
372
233
  console.warn('Cannot get resource URL. If in debug mode, please ignore.', module, sourceUrl);
373
234
  return '';
374
235
  }
375
236
  };
376
237
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
377
- var assert = function(condition, msg) {
238
+ const assert = (condition, msg)=>{
378
239
  if (!condition) {
379
240
  error(msg);
380
241
  }
381
242
  };
382
- var error = function(msg) {
383
- throw new Error("".concat(LOG_CATEGORY, ": ").concat(msg));
243
+ const error = (msg)=>{
244
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
384
245
  };
385
- var warn = function(msg) {
386
- console.warn("".concat(LOG_CATEGORY, ": ").concat(msg));
246
+ const warn = (msg)=>{
247
+ console.warn(`${LOG_CATEGORY}: ${msg}`);
387
248
  };
388
249
 
389
- function _define_property$2(obj, key, value) {
390
- if (key in obj) {
391
- Object.defineProperty(obj, key, {
392
- value: value,
393
- enumerable: true,
394
- configurable: true,
395
- writable: true
396
- });
397
- } else {
398
- obj[key] = value;
399
- }
400
- return obj;
401
- }
402
- function _object_spread$2(target) {
403
- for(var i = 1; i < arguments.length; i++){
404
- var source = arguments[i] != null ? arguments[i] : {};
405
- var ownKeys = Object.keys(source);
406
- if (typeof Object.getOwnPropertySymbols === "function") {
407
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
408
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
409
- }));
410
- }
411
- ownKeys.forEach(function(key) {
412
- _define_property$2(target, key, source[key]);
413
- });
414
- }
415
- return target;
416
- }
417
- function ownKeys(object, enumerableOnly) {
418
- var keys = Object.keys(object);
419
- if (Object.getOwnPropertySymbols) {
420
- var symbols = Object.getOwnPropertySymbols(object);
421
- if (enumerableOnly) {
422
- symbols = symbols.filter(function(sym) {
423
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
424
- });
250
+ function _extends() {
251
+ _extends = Object.assign || function assign(target) {
252
+ for(var i = 1; i < arguments.length; i++){
253
+ var source = arguments[i];
254
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
425
255
  }
426
- keys.push.apply(keys, symbols);
427
- }
428
- return keys;
429
- }
430
- function _object_spread_props(target, source) {
431
- source = source != null ? source : {};
432
- if (Object.getOwnPropertyDescriptors) {
433
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
434
- } else {
435
- ownKeys(Object(source)).forEach(function(key) {
436
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
437
- });
438
- }
439
- return target;
256
+ return target;
257
+ };
258
+ return _extends.apply(this, arguments);
440
259
  }
441
- var simpleJoinRemoteEntry = function(rPath, rName) {
260
+
261
+ const simpleJoinRemoteEntry = (rPath, rName)=>{
442
262
  if (!rPath) {
443
263
  return rName;
444
264
  }
445
- var transformPath = function(str) {
265
+ const transformPath = (str)=>{
446
266
  if (str === '.') {
447
267
  return '';
448
268
  }
@@ -450,7 +270,7 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
450
270
  return str.replace('./', '');
451
271
  }
452
272
  if (str.startsWith('/')) {
453
- var strWithoutSlash = str.slice(1);
273
+ const strWithoutSlash = str.slice(1);
454
274
  if (strWithoutSlash.endsWith('/')) {
455
275
  return strWithoutSlash.slice(0, -1);
456
276
  }
@@ -458,26 +278,25 @@ var simpleJoinRemoteEntry = function(rPath, rName) {
458
278
  }
459
279
  return str;
460
280
  };
461
- var transformedPath = transformPath(rPath);
281
+ const transformedPath = transformPath(rPath);
462
282
  if (!transformedPath) {
463
283
  return rName;
464
284
  }
465
285
  if (transformedPath.endsWith('/')) {
466
- return "".concat(transformedPath).concat(rName);
286
+ return `${transformedPath}${rName}`;
467
287
  }
468
- return "".concat(transformedPath, "/").concat(rName);
288
+ return `${transformedPath}/${rName}`;
469
289
  };
470
290
  function inferAutoPublicPath(url) {
471
291
  return url.replace(/#.*$/, '').replace(/\?.*$/, '').replace(/\/[^\/]+$/, '/');
472
292
  }
473
293
  // Priority: overrides > remotes
474
294
  // eslint-disable-next-line max-lines-per-function
475
- function generateSnapshotFromManifest(manifest) {
476
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
295
+ function generateSnapshotFromManifest(manifest, options = {}) {
477
296
  var _manifest_metaData, _manifest_metaData1;
478
- var _options_remotes = options.remotes, remotes = _options_remotes === void 0 ? {} : _options_remotes, _options_overrides = options.overrides, overrides = _options_overrides === void 0 ? {} : _options_overrides, version = options.version;
479
- var remoteSnapshot;
480
- var getPublicPath = function() {
297
+ const { remotes = {}, overrides = {}, version } = options;
298
+ let remoteSnapshot;
299
+ const getPublicPath = ()=>{
481
300
  if ('publicPath' in manifest.metaData) {
482
301
  if (manifest.metaData.publicPath === 'auto' && version) {
483
302
  // use same implementation as publicPath auto runtime module implements
@@ -488,14 +307,14 @@ function generateSnapshotFromManifest(manifest) {
488
307
  return manifest.metaData.getPublicPath;
489
308
  }
490
309
  };
491
- var overridesKeys = Object.keys(overrides);
492
- var remotesInfo = {};
310
+ const overridesKeys = Object.keys(overrides);
311
+ let remotesInfo = {};
493
312
  // If remotes are not provided, only the remotes in the manifest will be read
494
313
  if (!Object.keys(remotes).length) {
495
314
  var _manifest_remotes;
496
- remotesInfo = ((_manifest_remotes = manifest.remotes) === null || _manifest_remotes === void 0 ? void 0 : _manifest_remotes.reduce(function(res, next) {
497
- var matchedVersion;
498
- var name = next.federationContainerName;
315
+ remotesInfo = ((_manifest_remotes = manifest.remotes) == null ? void 0 : _manifest_remotes.reduce((res, next)=>{
316
+ let matchedVersion;
317
+ const name = next.federationContainerName;
499
318
  // overrides have higher priority
500
319
  if (overridesKeys.includes(name)) {
501
320
  matchedVersion = overrides[name];
@@ -507,64 +326,58 @@ function generateSnapshotFromManifest(manifest) {
507
326
  }
508
327
  }
509
328
  res[name] = {
510
- matchedVersion: matchedVersion
329
+ matchedVersion
511
330
  };
512
331
  return res;
513
332
  }, {})) || {};
514
333
  }
515
334
  // If remotes (deploy scenario) are specified, they need to be traversed again
516
- Object.keys(remotes).forEach(function(key) {
517
- return remotesInfo[key] = {
335
+ Object.keys(remotes).forEach((key)=>remotesInfo[key] = {
518
336
  // overrides will override dependencies
519
337
  matchedVersion: overridesKeys.includes(key) ? overrides[key] : remotes[key]
520
- };
521
- });
522
- var _manifest_metaData2 = manifest.metaData, _manifest_metaData_remoteEntry = _manifest_metaData2.remoteEntry, remoteEntryPath = _manifest_metaData_remoteEntry.path, remoteEntryName = _manifest_metaData_remoteEntry.name, remoteEntryType = _manifest_metaData_remoteEntry.type, remoteTypes = _manifest_metaData2.types, buildVersion = _manifest_metaData2.buildInfo.buildVersion, globalName = _manifest_metaData2.globalName;
523
- var exposes = manifest.exposes;
524
- var basicRemoteSnapshot = {
338
+ });
339
+ const { remoteEntry: { path: remoteEntryPath, name: remoteEntryName, type: remoteEntryType }, types: remoteTypes, buildInfo: { buildVersion }, globalName } = manifest.metaData;
340
+ const { exposes } = manifest;
341
+ let basicRemoteSnapshot = {
525
342
  version: version ? version : '',
526
- buildVersion: buildVersion,
527
- globalName: globalName,
343
+ buildVersion,
344
+ globalName,
528
345
  remoteEntry: simpleJoinRemoteEntry(remoteEntryPath, remoteEntryName),
529
- remoteEntryType: remoteEntryType,
346
+ remoteEntryType,
530
347
  remoteTypes: simpleJoinRemoteEntry(remoteTypes.path, remoteTypes.name),
531
348
  remoteTypesZip: remoteTypes.zip || '',
532
349
  remoteTypesAPI: remoteTypes.api || '',
533
- remotesInfo: remotesInfo,
534
- shared: manifest === null || manifest === void 0 ? void 0 : manifest.shared.map(function(item) {
535
- return {
350
+ remotesInfo,
351
+ shared: manifest == null ? void 0 : manifest.shared.map((item)=>({
536
352
  assets: item.assets,
537
353
  sharedName: item.name,
538
354
  version: item.version
539
- };
540
- }),
541
- modules: exposes === null || exposes === void 0 ? void 0 : exposes.map(function(expose) {
542
- return {
355
+ })),
356
+ modules: exposes == null ? void 0 : exposes.map((expose)=>({
543
357
  moduleName: expose.name,
544
358
  modulePath: expose.path,
545
359
  assets: expose.assets
546
- };
547
- })
360
+ }))
548
361
  };
549
- if ((_manifest_metaData = manifest.metaData) === null || _manifest_metaData === void 0 ? void 0 : _manifest_metaData.prefetchInterface) {
550
- var prefetchInterface = manifest.metaData.prefetchInterface;
551
- basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
552
- prefetchInterface: prefetchInterface
362
+ if ((_manifest_metaData = manifest.metaData) == null ? void 0 : _manifest_metaData.prefetchInterface) {
363
+ const prefetchInterface = manifest.metaData.prefetchInterface;
364
+ basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
365
+ prefetchInterface
553
366
  });
554
367
  }
555
- if ((_manifest_metaData1 = manifest.metaData) === null || _manifest_metaData1 === void 0 ? void 0 : _manifest_metaData1.prefetchEntry) {
556
- var _manifest_metaData_prefetchEntry = manifest.metaData.prefetchEntry, path = _manifest_metaData_prefetchEntry.path, name = _manifest_metaData_prefetchEntry.name, type = _manifest_metaData_prefetchEntry.type;
557
- basicRemoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
368
+ if ((_manifest_metaData1 = manifest.metaData) == null ? void 0 : _manifest_metaData1.prefetchEntry) {
369
+ const { path, name, type } = manifest.metaData.prefetchEntry;
370
+ basicRemoteSnapshot = _extends({}, basicRemoteSnapshot, {
558
371
  prefetchEntry: simpleJoinRemoteEntry(path, name),
559
372
  prefetchEntryType: type
560
373
  });
561
374
  }
562
375
  if ('publicPath' in manifest.metaData) {
563
- remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
376
+ remoteSnapshot = _extends({}, basicRemoteSnapshot, {
564
377
  publicPath: getPublicPath()
565
378
  });
566
379
  } else {
567
- remoteSnapshot = _object_spread_props(_object_spread$2({}, basicRemoteSnapshot), {
380
+ remoteSnapshot = _extends({}, basicRemoteSnapshot, {
568
381
  getPublicPath: getPublicPath()
569
382
  });
570
383
  }
@@ -578,228 +391,34 @@ function isManifestProvider(moduleInfo) {
578
391
  }
579
392
  }
580
393
 
581
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
394
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
395
+ async function safeWrapper(callback, disableWarn) {
582
396
  try {
583
- var info = gen[key](arg);
584
- var value = info.value;
585
- } catch (error) {
586
- reject(error);
397
+ const res = await callback();
398
+ return res;
399
+ } catch (e) {
400
+ !disableWarn && warn(e);
587
401
  return;
588
402
  }
589
- if (info.done) {
590
- resolve(value);
591
- } else {
592
- Promise.resolve(value).then(_next, _throw);
593
- }
594
- }
595
- function _async_to_generator$1(fn) {
596
- return function() {
597
- var self = this, args = arguments;
598
- return new Promise(function(resolve, reject) {
599
- var gen = fn.apply(self, args);
600
- function _next(value) {
601
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
602
- }
603
- function _throw(err) {
604
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
605
- }
606
- _next(undefined);
607
- });
608
- };
609
- }
610
- function _define_property$1(obj, key, value) {
611
- if (key in obj) {
612
- Object.defineProperty(obj, key, {
613
- value: value,
614
- enumerable: true,
615
- configurable: true,
616
- writable: true
617
- });
618
- } else {
619
- obj[key] = value;
620
- }
621
- return obj;
622
- }
623
- function _instanceof(left, right) {
624
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
625
- return !!right[Symbol.hasInstance](left);
626
- } else {
627
- return left instanceof right;
628
- }
629
- }
630
- function _object_spread$1(target) {
631
- for(var i = 1; i < arguments.length; i++){
632
- var source = arguments[i] != null ? arguments[i] : {};
633
- var ownKeys = Object.keys(source);
634
- if (typeof Object.getOwnPropertySymbols === "function") {
635
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
636
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
637
- }));
638
- }
639
- ownKeys.forEach(function(key) {
640
- _define_property$1(target, key, source[key]);
641
- });
642
- }
643
- return target;
644
- }
645
- function _type_of$2(obj) {
646
- "@swc/helpers - typeof";
647
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
648
- }
649
- function _ts_generator$1(thisArg, body) {
650
- var f, y, t, g, _ = {
651
- label: 0,
652
- sent: function() {
653
- if (t[0] & 1) throw t[1];
654
- return t[1];
655
- },
656
- trys: [],
657
- ops: []
658
- };
659
- return g = {
660
- next: verb(0),
661
- "throw": verb(1),
662
- "return": verb(2)
663
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
664
- return this;
665
- }), g;
666
- function verb(n) {
667
- return function(v) {
668
- return step([
669
- n,
670
- v
671
- ]);
672
- };
673
- }
674
- function step(op) {
675
- if (f) throw new TypeError("Generator is already executing.");
676
- while(_)try {
677
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
678
- if (y = 0, t) op = [
679
- op[0] & 2,
680
- t.value
681
- ];
682
- switch(op[0]){
683
- case 0:
684
- case 1:
685
- t = op;
686
- break;
687
- case 4:
688
- _.label++;
689
- return {
690
- value: op[1],
691
- done: false
692
- };
693
- case 5:
694
- _.label++;
695
- y = op[1];
696
- op = [
697
- 0
698
- ];
699
- continue;
700
- case 7:
701
- op = _.ops.pop();
702
- _.trys.pop();
703
- continue;
704
- default:
705
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
706
- _ = 0;
707
- continue;
708
- }
709
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
710
- _.label = op[1];
711
- break;
712
- }
713
- if (op[0] === 6 && _.label < t[1]) {
714
- _.label = t[1];
715
- t = op;
716
- break;
717
- }
718
- if (t && _.label < t[2]) {
719
- _.label = t[2];
720
- _.ops.push(op);
721
- break;
722
- }
723
- if (t[2]) _.ops.pop();
724
- _.trys.pop();
725
- continue;
726
- }
727
- op = body.call(thisArg, _);
728
- } catch (e) {
729
- op = [
730
- 6,
731
- e
732
- ];
733
- y = 0;
734
- } finally{
735
- f = t = 0;
736
- }
737
- if (op[0] & 5) throw op[1];
738
- return {
739
- value: op[0] ? op[1] : void 0,
740
- done: true
741
- };
742
- }
743
- }
744
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
745
- function safeWrapper(callback, disableWarn) {
746
- return _safeWrapper.apply(this, arguments);
747
- }
748
- function _safeWrapper() {
749
- _safeWrapper = _async_to_generator$1(function(callback, disableWarn) {
750
- var res, e;
751
- return _ts_generator$1(this, function(_state) {
752
- switch(_state.label){
753
- case 0:
754
- _state.trys.push([
755
- 0,
756
- 2,
757
- ,
758
- 3
759
- ]);
760
- return [
761
- 4,
762
- callback()
763
- ];
764
- case 1:
765
- res = _state.sent();
766
- return [
767
- 2,
768
- res
769
- ];
770
- case 2:
771
- e = _state.sent();
772
- !disableWarn && warn(e);
773
- return [
774
- 2
775
- ];
776
- case 3:
777
- return [
778
- 2
779
- ];
780
- }
781
- });
782
- });
783
- return _safeWrapper.apply(this, arguments);
784
403
  }
785
404
  function isStaticResourcesEqual(url1, url2) {
786
- var REG_EXP = /^(https?:)?\/\//i;
405
+ const REG_EXP = /^(https?:)?\/\//i;
787
406
  // Transform url1 and url2 into relative paths
788
- var relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
789
- var relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
407
+ const relativeUrl1 = url1.replace(REG_EXP, '').replace(/\/$/, '');
408
+ const relativeUrl2 = url2.replace(REG_EXP, '').replace(/\/$/, '');
790
409
  // Check if the relative paths are identical
791
410
  return relativeUrl1 === relativeUrl2;
792
411
  }
793
412
  function createScript(info) {
794
413
  // Retrieve the existing script element by its src attribute
795
- var script = null;
796
- var needAttach = true;
797
- var timeout = 20000;
798
- var timeoutId;
799
- var scripts = document.getElementsByTagName('script');
800
- for(var i = 0; i < scripts.length; i++){
801
- var s = scripts[i];
802
- var scriptSrc = s.getAttribute('src');
414
+ let script = null;
415
+ let needAttach = true;
416
+ let timeout = 20000;
417
+ let timeoutId;
418
+ const scripts = document.getElementsByTagName('script');
419
+ for(let i = 0; i < scripts.length; i++){
420
+ const s = scripts[i];
421
+ const scriptSrc = s.getAttribute('src');
803
422
  if (scriptSrc && isStaticResourcesEqual(scriptSrc, info.url)) {
804
423
  script = s;
805
424
  needAttach = false;
@@ -811,17 +430,17 @@ function createScript(info) {
811
430
  script.type = 'text/javascript';
812
431
  script.src = info.url;
813
432
  if (info.createScriptHook) {
814
- var createScriptRes = info.createScriptHook(info.url);
815
- if (_instanceof(createScriptRes, HTMLScriptElement)) {
433
+ const createScriptRes = info.createScriptHook(info.url, info.attrs);
434
+ if (createScriptRes instanceof HTMLScriptElement) {
816
435
  script = createScriptRes;
817
- } else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
436
+ } else if (typeof createScriptRes === 'object') {
818
437
  if (createScriptRes.script) script = createScriptRes.script;
819
438
  if (createScriptRes.timeout) timeout = createScriptRes.timeout;
820
439
  }
821
440
  }
822
- var attrs = info.attrs;
441
+ const attrs = info.attrs;
823
442
  if (attrs) {
824
- Object.keys(attrs).forEach(function(name) {
443
+ Object.keys(attrs).forEach((name)=>{
825
444
  if (script) {
826
445
  if (name === 'async' || name === 'defer') {
827
446
  script[name] = attrs[name];
@@ -833,50 +452,50 @@ function createScript(info) {
833
452
  });
834
453
  }
835
454
  }
836
- var onScriptComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
837
- event) {
455
+ const onScriptComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
456
+ event)=>{
838
457
  var _info_cb;
839
458
  clearTimeout(timeoutId);
840
459
  // Prevent memory leaks in IE.
841
460
  if (script) {
842
461
  script.onerror = null;
843
462
  script.onload = null;
844
- safeWrapper(function() {
845
- var _info_needDeleteScript = info.needDeleteScript, needDeleteScript = _info_needDeleteScript === void 0 ? true : _info_needDeleteScript;
463
+ safeWrapper(()=>{
464
+ const { needDeleteScript = true } = info;
846
465
  if (needDeleteScript) {
847
- (script === null || script === void 0 ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
466
+ (script == null ? void 0 : script.parentNode) && script.parentNode.removeChild(script);
848
467
  }
849
468
  });
850
469
  if (prev) {
851
470
  var _info_cb1;
852
471
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
853
- var res = prev(event);
854
- info === null || info === void 0 ? void 0 : (_info_cb1 = info.cb) === null || _info_cb1 === void 0 ? void 0 : _info_cb1.call(info);
472
+ const res = prev(event);
473
+ info == null ? void 0 : (_info_cb1 = info.cb) == null ? void 0 : _info_cb1.call(info);
855
474
  return res;
856
475
  }
857
476
  }
858
- info === null || info === void 0 ? void 0 : (_info_cb = info.cb) === null || _info_cb === void 0 ? void 0 : _info_cb.call(info);
477
+ info == null ? void 0 : (_info_cb = info.cb) == null ? void 0 : _info_cb.call(info);
859
478
  };
860
479
  script.onerror = onScriptComplete.bind(null, script.onerror);
861
480
  script.onload = onScriptComplete.bind(null, script.onload);
862
- timeoutId = setTimeout(function() {
863
- onScriptComplete(null, new Error('Remote script "'.concat(info.url, '" time-outed.')));
481
+ timeoutId = setTimeout(()=>{
482
+ onScriptComplete(null, new Error(`Remote script "${info.url}" time-outed.`));
864
483
  }, timeout);
865
484
  return {
866
- script: script,
867
- needAttach: needAttach
485
+ script,
486
+ needAttach
868
487
  };
869
488
  }
870
489
  function createLink(info) {
871
490
  // <link rel="preload" href="script.js" as="script">
872
491
  // Retrieve the existing script element by its src attribute
873
- var link = null;
874
- var needAttach = true;
875
- var links = document.getElementsByTagName('link');
876
- for(var i = 0; i < links.length; i++){
877
- var l = links[i];
878
- var linkHref = l.getAttribute('href');
879
- var linkRef = l.getAttribute('ref');
492
+ let link = null;
493
+ let needAttach = true;
494
+ const links = document.getElementsByTagName('link');
495
+ for(let i = 0; i < links.length; i++){
496
+ const l = links[i];
497
+ const linkHref = l.getAttribute('href');
498
+ const linkRef = l.getAttribute('ref');
880
499
  if (linkHref && isStaticResourcesEqual(linkHref, info.url) && linkRef === info.attrs['ref']) {
881
500
  link = l;
882
501
  needAttach = false;
@@ -887,35 +506,35 @@ function createLink(info) {
887
506
  link = document.createElement('link');
888
507
  link.setAttribute('href', info.url);
889
508
  if (info.createLinkHook) {
890
- var createLinkRes = info.createLinkHook(info.url);
891
- if (_instanceof(createLinkRes, HTMLLinkElement)) {
509
+ const createLinkRes = info.createLinkHook(info.url);
510
+ if (createLinkRes instanceof HTMLLinkElement) {
892
511
  link = createLinkRes;
893
512
  }
894
513
  }
895
- var attrs = info.attrs;
514
+ const attrs = info.attrs;
896
515
  if (attrs) {
897
- Object.keys(attrs).forEach(function(name) {
516
+ Object.keys(attrs).forEach((name)=>{
898
517
  if (link && !link.getAttribute(name)) {
899
518
  link.setAttribute(name, attrs[name]);
900
519
  }
901
520
  });
902
521
  }
903
522
  }
904
- var onLinkComplete = function(prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
905
- event) {
523
+ const onLinkComplete = (prev, // eslint-disable-next-line @typescript-eslint/no-explicit-any
524
+ event)=>{
906
525
  // Prevent memory leaks in IE.
907
526
  if (link) {
908
527
  link.onerror = null;
909
528
  link.onload = null;
910
- safeWrapper(function() {
911
- var _info_needDeleteLink = info.needDeleteLink, needDeleteLink = _info_needDeleteLink === void 0 ? true : _info_needDeleteLink;
529
+ safeWrapper(()=>{
530
+ const { needDeleteLink = true } = info;
912
531
  if (needDeleteLink) {
913
- (link === null || link === void 0 ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
532
+ (link == null ? void 0 : link.parentNode) && link.parentNode.removeChild(link);
914
533
  }
915
534
  });
916
535
  if (prev) {
917
536
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
918
- var res = prev(event);
537
+ const res = prev(event);
919
538
  info.cb();
920
539
  return res;
921
540
  }
@@ -925,373 +544,132 @@ function createLink(info) {
925
544
  link.onerror = onLinkComplete.bind(null, link.onerror);
926
545
  link.onload = onLinkComplete.bind(null, link.onload);
927
546
  return {
928
- link: link,
929
- needAttach: needAttach
547
+ link,
548
+ needAttach
930
549
  };
931
550
  }
932
551
  function loadScript(url, info) {
933
- var _info_attrs = info.attrs, attrs = _info_attrs === void 0 ? {} : _info_attrs, createScriptHook = info.createScriptHook;
934
- return new Promise(function(resolve, _reject) {
935
- var _createScript = createScript({
936
- url: url,
552
+ const { attrs = {}, createScriptHook } = info;
553
+ return new Promise((resolve, _reject)=>{
554
+ const { script, needAttach } = createScript({
555
+ url,
937
556
  cb: resolve,
938
- attrs: _object_spread$1({
557
+ attrs: _extends({
939
558
  crossorigin: 'anonymous',
940
559
  fetchpriority: 'high'
941
560
  }, attrs),
942
- createScriptHook: createScriptHook,
561
+ createScriptHook,
943
562
  needDeleteScript: true
944
- }), script = _createScript.script, needAttach = _createScript.needAttach;
563
+ });
945
564
  needAttach && document.head.appendChild(script);
946
565
  });
947
566
  }
948
567
 
949
- function _array_like_to_array(arr, len) {
950
- if (len == null || len > arr.length) len = arr.length;
951
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
952
- return arr2;
953
- }
954
- function _array_with_holes(arr) {
955
- if (Array.isArray(arr)) return arr;
956
- }
957
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
958
- try {
959
- var info = gen[key](arg);
960
- var value = info.value;
961
- } catch (error) {
962
- reject(error);
963
- return;
964
- }
965
- if (info.done) {
966
- resolve(value);
967
- } else {
968
- Promise.resolve(value).then(_next, _throw);
969
- }
970
- }
971
- function _async_to_generator(fn) {
972
- return function() {
973
- var self = this, args = arguments;
974
- return new Promise(function(resolve, reject) {
975
- var gen = fn.apply(self, args);
976
- function _next(value) {
977
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
978
- }
979
- function _throw(err) {
980
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
981
- }
982
- _next(undefined);
983
- });
984
- };
985
- }
986
- function _iterable_to_array_limit(arr, i) {
987
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
988
- if (_i == null) return;
989
- var _arr = [];
990
- var _n = true;
991
- var _d = false;
992
- var _s, _e;
993
- try {
994
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
995
- _arr.push(_s.value);
996
- if (i && _arr.length === i) break;
997
- }
998
- } catch (err) {
999
- _d = true;
1000
- _e = err;
1001
- } finally{
1002
- try {
1003
- if (!_n && _i["return"] != null) _i["return"]();
1004
- } finally{
1005
- if (_d) throw _e;
1006
- }
1007
- }
1008
- return _arr;
1009
- }
1010
- function _non_iterable_rest() {
1011
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1012
- }
1013
- function _sliced_to_array(arr, i) {
1014
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
1015
- }
1016
- function _type_of$1(obj) {
1017
- "@swc/helpers - typeof";
1018
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1019
- }
1020
- function _unsupported_iterable_to_array(o, minLen) {
1021
- if (!o) return;
1022
- if (typeof o === "string") return _array_like_to_array(o, minLen);
1023
- var n = Object.prototype.toString.call(o).slice(8, -1);
1024
- if (n === "Object" && o.constructor) n = o.constructor.name;
1025
- if (n === "Map" || n === "Set") return Array.from(n);
1026
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1027
- }
1028
- function _ts_generator(thisArg, body) {
1029
- var f, y, t, g, _ = {
1030
- label: 0,
1031
- sent: function() {
1032
- if (t[0] & 1) throw t[1];
1033
- return t[1];
1034
- },
1035
- trys: [],
1036
- ops: []
1037
- };
1038
- return g = {
1039
- next: verb(0),
1040
- "throw": verb(1),
1041
- "return": verb(2)
1042
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1043
- return this;
1044
- }), g;
1045
- function verb(n) {
1046
- return function(v) {
1047
- return step([
1048
- n,
1049
- v
1050
- ]);
1051
- };
1052
- }
1053
- function step(op) {
1054
- if (f) throw new TypeError("Generator is already executing.");
1055
- while(_)try {
1056
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1057
- if (y = 0, t) op = [
1058
- op[0] & 2,
1059
- t.value
1060
- ];
1061
- switch(op[0]){
1062
- case 0:
1063
- case 1:
1064
- t = op;
1065
- break;
1066
- case 4:
1067
- _.label++;
1068
- return {
1069
- value: op[1],
1070
- done: false
1071
- };
1072
- case 5:
1073
- _.label++;
1074
- y = op[1];
1075
- op = [
1076
- 0
1077
- ];
1078
- continue;
1079
- case 7:
1080
- op = _.ops.pop();
1081
- _.trys.pop();
1082
- continue;
1083
- default:
1084
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1085
- _ = 0;
1086
- continue;
1087
- }
1088
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1089
- _.label = op[1];
1090
- break;
1091
- }
1092
- if (op[0] === 6 && _.label < t[1]) {
1093
- _.label = t[1];
1094
- t = op;
1095
- break;
1096
- }
1097
- if (t && _.label < t[2]) {
1098
- _.label = t[2];
1099
- _.ops.push(op);
1100
- break;
1101
- }
1102
- if (t[2]) _.ops.pop();
1103
- _.trys.pop();
1104
- continue;
1105
- }
1106
- op = body.call(thisArg, _);
1107
- } catch (e) {
1108
- op = [
1109
- 6,
1110
- e
1111
- ];
1112
- y = 0;
1113
- } finally{
1114
- f = t = 0;
1115
- }
1116
- if (op[0] & 5) throw op[1];
1117
- return {
1118
- value: op[0] ? op[1] : void 0,
1119
- done: true
1120
- };
1121
- }
1122
- }
1123
568
  function importNodeModule(name) {
1124
569
  if (!name) {
1125
570
  throw new Error('import specifier is required');
1126
571
  }
1127
- var importModule = new Function('name', "return import(name)");
1128
- return importModule(name).then(function(res) {
1129
- return res.default;
1130
- }).catch(function(error) {
1131
- console.error("Error importing module ".concat(name, ":"), error);
572
+ const importModule = new Function('name', `return import(name)`);
573
+ return importModule(name).then((res)=>res.default).catch((error)=>{
574
+ console.error(`Error importing module ${name}:`, error);
1132
575
  throw error;
1133
576
  });
1134
577
  }
578
+ const loadNodeFetch = async ()=>{
579
+ const fetchModule = await importNodeModule('node-fetch');
580
+ return fetchModule.default || fetchModule;
581
+ };
582
+ const lazyLoaderHookFetch = async (input, init)=>{
583
+ // @ts-ignore
584
+ const loaderHooks = __webpack_require__.federation.instance.loaderHook;
585
+ const hook = (url, init)=>{
586
+ return loaderHooks.lifecycle.fetch.emit(url, init);
587
+ };
588
+ const res = await hook(input, init || {});
589
+ if (!res || !(res instanceof Response)) {
590
+ const fetchFunction = typeof fetch === 'undefined' ? await loadNodeFetch() : fetch;
591
+ return fetchFunction(input, init || {});
592
+ }
593
+ return res;
594
+ };
1135
595
  function createScriptNode(url, cb, attrs, createScriptHook) {
1136
596
  if (createScriptHook) {
1137
- var hookResult = createScriptHook(url);
1138
- if (hookResult && (typeof hookResult === "undefined" ? "undefined" : _type_of$1(hookResult)) === 'object' && 'url' in hookResult) {
597
+ const hookResult = createScriptHook(url);
598
+ if (hookResult && typeof hookResult === 'object' && 'url' in hookResult) {
1139
599
  url = hookResult.url;
1140
600
  }
1141
601
  }
1142
- var urlObj;
602
+ let urlObj;
1143
603
  try {
1144
604
  urlObj = new URL(url);
1145
605
  } catch (e) {
1146
606
  console.error('Error constructing URL:', e);
1147
- cb(new Error("Invalid URL: ".concat(e)));
607
+ cb(new Error(`Invalid URL: ${e}`));
1148
608
  return;
1149
609
  }
1150
- var getFetch = function() {
1151
- var _ref = _async_to_generator(function() {
1152
- var fetchModule;
1153
- return _ts_generator(this, function(_state) {
1154
- switch(_state.label){
1155
- case 0:
1156
- if (!(typeof fetch === 'undefined')) return [
1157
- 3,
1158
- 2
1159
- ];
1160
- return [
1161
- 4,
1162
- importNodeModule('node-fetch')
1163
- ];
1164
- case 1:
1165
- fetchModule = _state.sent();
1166
- //@ts-ignore
1167
- return [
1168
- 2,
1169
- (fetchModule === null || fetchModule === void 0 ? void 0 : fetchModule.default) || fetchModule
1170
- ];
1171
- case 2:
1172
- return [
1173
- 2,
1174
- fetch
1175
- ];
1176
- case 3:
1177
- return [
1178
- 2
1179
- ];
610
+ const getFetch = async ()=>{
611
+ //@ts-ignore
612
+ if (typeof __webpack_require__ !== 'undefined') {
613
+ try {
614
+ //@ts-ignore
615
+ const loaderHooks = __webpack_require__.federation.instance.loaderHook;
616
+ if (loaderHooks.lifecycle.fetch) {
617
+ return lazyLoaderHookFetch;
618
+ }
619
+ } catch (e) {
620
+ console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
621
+ }
622
+ }
623
+ return typeof fetch === 'undefined' ? loadNodeFetch() : fetch;
624
+ };
625
+ const handleScriptFetch = async (f, urlObj)=>{
626
+ try {
627
+ const res = await f(urlObj.href);
628
+ const data = await res.text();
629
+ const [path, vm] = await Promise.all([
630
+ importNodeModule('path'),
631
+ importNodeModule('vm')
632
+ ]);
633
+ const scriptContext = {
634
+ exports: {},
635
+ module: {
636
+ exports: {}
1180
637
  }
1181
- });
1182
- });
1183
- return function getFetch() {
1184
- return _ref.apply(this, arguments);
1185
- };
1186
- }();
1187
- console.log('fetching', urlObj.href);
1188
- getFetch().then(function(f) {
1189
- f(urlObj.href).then(function(res) {
1190
- return res.text();
1191
- }).then(function() {
1192
- var _ref = _async_to_generator(function(data) {
1193
- var _ref, path, vm, scriptContext, urlDirname, filename, script, exportedInterface, container;
1194
- return _ts_generator(this, function(_state) {
1195
- switch(_state.label){
1196
- case 0:
1197
- return [
1198
- 4,
1199
- Promise.all([
1200
- importNodeModule('path'),
1201
- importNodeModule('vm')
1202
- ])
1203
- ];
1204
- case 1:
1205
- _ref = _sliced_to_array.apply(void 0, [
1206
- _state.sent(),
1207
- 2
1208
- ]), path = _ref[0], vm = _ref[1];
1209
- scriptContext = {
1210
- exports: {},
1211
- module: {
1212
- exports: {}
1213
- }
1214
- };
1215
- urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
1216
- filename = path.basename(urlObj.pathname);
1217
- try {
1218
- script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
1219
- script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
1220
- exportedInterface = scriptContext.module.exports || scriptContext.exports;
1221
- if (attrs && exportedInterface && attrs['globalName']) {
1222
- container = exportedInterface[attrs['globalName']] || exportedInterface;
1223
- cb(undefined, container);
1224
- return [
1225
- 2
1226
- ];
1227
- }
1228
- cb(undefined, exportedInterface);
1229
- } catch (e) {
1230
- // console.error('Error running script:', e);
1231
- cb(new Error("Script execution error: ".concat(e)));
1232
- }
1233
- return [
1234
- 2
1235
- ];
1236
- }
1237
- });
1238
- });
1239
- return function(data) {
1240
- return _ref.apply(this, arguments);
1241
638
  };
1242
- }()).catch(function(err) {
1243
- // console.error('Error fetching script:', err);
1244
- cb(err);
1245
- });
639
+ const urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
640
+ const filename = path.basename(urlObj.pathname);
641
+ const script = new vm.Script(`(function(exports, module, require, __dirname, __filename) {${data}\n})`, filename);
642
+ script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
643
+ const exportedInterface = scriptContext.module.exports || scriptContext.exports;
644
+ if (attrs && exportedInterface && attrs['globalName']) {
645
+ const container = exportedInterface[attrs['globalName']] || exportedInterface;
646
+ cb(undefined, container);
647
+ return;
648
+ }
649
+ cb(undefined, exportedInterface);
650
+ } catch (e) {
651
+ cb(new Error(`Script execution error: ${e}`));
652
+ }
653
+ };
654
+ getFetch().then((f)=>handleScriptFetch(f, urlObj)).catch((err)=>{
655
+ cb(err);
1246
656
  });
1247
657
  }
1248
658
  function loadScriptNode(url, info) {
1249
- return new Promise(function(resolve, reject) {
1250
- createScriptNode(url, function(error, scriptContext) {
659
+ return new Promise((resolve, reject)=>{
660
+ createScriptNode(url, (error, scriptContext)=>{
1251
661
  if (error) {
1252
662
  reject(error);
1253
663
  } else {
1254
664
  var _info_attrs, _info_attrs1;
1255
- var remoteEntryKey = (info === null || info === void 0 ? void 0 : (_info_attrs = info.attrs) === null || _info_attrs === void 0 ? void 0 : _info_attrs['globalName']) || "__FEDERATION_".concat(info === null || info === void 0 ? void 0 : (_info_attrs1 = info.attrs) === null || _info_attrs1 === void 0 ? void 0 : _info_attrs1['name'], ":custom__");
1256
- var entryExports = globalThis[remoteEntryKey] = scriptContext;
665
+ const remoteEntryKey = (info == null ? void 0 : (_info_attrs = info.attrs) == null ? void 0 : _info_attrs['globalName']) || `__FEDERATION_${info == null ? void 0 : (_info_attrs1 = info.attrs) == null ? void 0 : _info_attrs1['name']}:custom__`;
666
+ const entryExports = globalThis[remoteEntryKey] = scriptContext;
1257
667
  resolve(entryExports);
1258
668
  }
1259
669
  }, info.attrs, info.createScriptHook);
1260
670
  });
1261
671
  }
1262
672
 
1263
- function _define_property(obj, key, value) {
1264
- if (key in obj) {
1265
- Object.defineProperty(obj, key, {
1266
- value: value,
1267
- enumerable: true,
1268
- configurable: true,
1269
- writable: true
1270
- });
1271
- } else {
1272
- obj[key] = value;
1273
- }
1274
- return obj;
1275
- }
1276
- function _object_spread(target) {
1277
- for(var i = 1; i < arguments.length; i++){
1278
- var source = arguments[i] != null ? arguments[i] : {};
1279
- var ownKeys = Object.keys(source);
1280
- if (typeof Object.getOwnPropertySymbols === "function") {
1281
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1282
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1283
- }));
1284
- }
1285
- ownKeys.forEach(function(key) {
1286
- _define_property(target, key, source[key]);
1287
- });
1288
- }
1289
- return target;
1290
- }
1291
- function _type_of(obj) {
1292
- "@swc/helpers - typeof";
1293
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1294
- }
1295
673
  function normalizeOptions(enableDefault, defaultOptions, key) {
1296
674
  return function(options) {
1297
675
  if (options === false) {
@@ -1307,10 +685,10 @@ function normalizeOptions(enableDefault, defaultOptions, key) {
1307
685
  if (options === true) {
1308
686
  return defaultOptions;
1309
687
  }
1310
- if (options && (typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object') {
1311
- return _object_spread({}, defaultOptions, options);
688
+ if (options && typeof options === 'object') {
689
+ return _extends({}, defaultOptions, options);
1312
690
  }
1313
- throw new Error("Unexpected type for `".concat(key, "`, expect boolean/undefined/object, got: ").concat(typeof options === "undefined" ? "undefined" : _type_of(options)));
691
+ throw new Error(`Unexpected type for \`${key}\`, expect boolean/undefined/object, got: ${typeof options}`);
1314
692
  };
1315
693
  }
1316
694