@module-federation/utilities 3.1.69 → 3.1.71

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.
Files changed (3) hide show
  1. package/dist/index.cjs.js +339 -1052
  2. package/dist/index.esm.js +339 -1052
  3. package/package.json +2 -2
package/dist/index.cjs.js CHANGED
@@ -13,128 +13,66 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
13
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
14
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function _instanceof(left, right) {
17
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
18
- return !!right[Symbol.hasInstance](left);
19
- } else {
20
- return left instanceof right;
21
- }
22
- }
23
- function __awaiter(thisArg, _arguments, P, generator) {
24
- function adopt(value) {
25
- return _instanceof(value, P) ? value : new P(function(resolve) {
26
- resolve(value);
27
- });
28
- }
29
- return new (P || (P = Promise))(function(resolve, reject) {
30
- function fulfilled(value) {
31
- try {
32
- step(generator.next(value));
33
- } catch (e) {
34
- reject(e);
35
- }
36
- }
37
- function rejected(value) {
38
- try {
39
- step(generator["throw"](value));
40
- } catch (e) {
41
- reject(e);
42
- }
43
- }
44
- function step(result) {
45
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
46
- }
47
- step((generator = generator.apply(thisArg, _arguments || [])).next());
48
- });
49
- }
50
- typeof SuppressedError === "function" ? SuppressedError : function _SuppressedError(error, suppressed, message) {
51
- var e = new Error(message);
52
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
16
+ ***************************************************************************** */
17
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
18
+
19
+
20
+ function __awaiter(thisArg, _arguments, P, generator) {
21
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
27
+ });
28
+ }
29
+
30
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
+ var e = new Error(message);
32
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
53
33
  };
54
34
 
55
- function _array_like_to_array$3(arr, len) {
56
- if (len == null || len > arr.length) len = arr.length;
57
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
58
- return arr2;
59
- }
60
- function _array_with_holes$3(arr) {
61
- if (Array.isArray(arr)) return arr;
62
- }
63
- function _iterable_to_array_limit$3(arr, i) {
64
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
65
- if (_i == null) return;
66
- var _arr = [];
67
- var _n = true;
68
- var _d = false;
69
- var _s, _e;
70
- try {
71
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
72
- _arr.push(_s.value);
73
- if (i && _arr.length === i) break;
74
- }
75
- } catch (err) {
76
- _d = true;
77
- _e = err;
78
- } finally{
79
- try {
80
- if (!_n && _i["return"] != null) _i["return"]();
81
- } finally{
82
- if (_d) throw _e;
83
- }
84
- }
85
- return _arr;
86
- }
87
- function _non_iterable_rest$3() {
88
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
89
- }
90
- function _sliced_to_array$3(arr, i) {
91
- return _array_with_holes$3(arr) || _iterable_to_array_limit$3(arr, i) || _unsupported_iterable_to_array$3(arr, i) || _non_iterable_rest$3();
92
- }
93
- function _type_of$2(obj) {
94
- "@swc/helpers - typeof";
95
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
96
- }
97
- function _unsupported_iterable_to_array$3(o, minLen) {
98
- if (!o) return;
99
- if (typeof o === "string") return _array_like_to_array$3(o, minLen);
100
- var n = Object.prototype.toString.call(o).slice(8, -1);
101
- if (n === "Object" && o.constructor) n = o.constructor.name;
102
- if (n === "Map" || n === "Set") return Array.from(n);
103
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$3(o, minLen);
104
- }
105
- var pure = typeof process !== 'undefined' ? process.env['REMOTES'] || {} : {};
106
- var remoteVars = pure;
107
- var extractUrlAndGlobal = function(urlAndGlobal) {
108
- var index = urlAndGlobal.indexOf('@');
35
+ const pure = typeof process !== 'undefined' ? process.env['REMOTES'] || {} : {};
36
+ const remoteVars = pure;
37
+ const extractUrlAndGlobal = (urlAndGlobal) => {
38
+ const index = urlAndGlobal.indexOf('@');
109
39
  if (index <= 0 || index === urlAndGlobal.length - 1) {
110
- throw new Error('Invalid request "'.concat(urlAndGlobal, '"'));
40
+ throw new Error(`Invalid request "${urlAndGlobal}"`);
111
41
  }
112
- return [
113
- urlAndGlobal.substring(index + 1),
114
- urlAndGlobal.substring(0, index)
115
- ];
42
+ return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
116
43
  };
117
- var loadScript = function(keyOrRuntimeRemoteItem) {
118
- var runtimeRemotes = getRuntimeRemotes$1();
44
+ const loadScript = (keyOrRuntimeRemoteItem) => {
45
+ const runtimeRemotes = getRuntimeRemotes$1();
119
46
  // 1) Load remote container if needed
120
- var asyncContainer;
121
- var reference = typeof keyOrRuntimeRemoteItem === 'string' ? runtimeRemotes[keyOrRuntimeRemoteItem] : keyOrRuntimeRemoteItem;
47
+ let asyncContainer;
48
+ const reference = typeof keyOrRuntimeRemoteItem === 'string'
49
+ ? runtimeRemotes[keyOrRuntimeRemoteItem]
50
+ : keyOrRuntimeRemoteItem;
122
51
  if (reference.asyncContainer) {
123
- asyncContainer = typeof reference.asyncContainer.then === 'function' ? reference.asyncContainer : reference.asyncContainer();
124
- } else {
52
+ asyncContainer =
53
+ typeof reference.asyncContainer.then === 'function'
54
+ ? reference.asyncContainer
55
+ : // @ts-ignore
56
+ reference.asyncContainer();
57
+ }
58
+ else {
125
59
  // This casting is just to satisfy typescript,
126
60
  // In reality remoteGlobal will always be a string;
127
- var remoteGlobal = reference.global;
61
+ const remoteGlobal = reference.global;
128
62
  // Check if theres an override for container key if not use remote global
129
- var containerKey = reference.uniqueKey ? reference.uniqueKey : remoteGlobal;
130
- var __webpack_error__ = new Error();
63
+ const containerKey = reference.uniqueKey
64
+ ? reference.uniqueKey
65
+ : remoteGlobal;
66
+ const __webpack_error__ = new Error();
67
+ // @ts-ignore
68
+ const globalScope =
131
69
  // @ts-ignore
132
- var globalScope = // @ts-ignore
133
70
  typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
134
71
  if (typeof window === 'undefined') {
135
72
  //@ts-ignore
136
73
  globalScope['_config'][containerKey] = reference.url;
137
- } else {
74
+ }
75
+ else {
138
76
  // to match promise template system, can be removed once promise template is gone
139
77
  //@ts-ignore
140
78
  if (!globalScope['remoteLoading']) {
@@ -148,48 +86,55 @@ var loadScript = function(keyOrRuntimeRemoteItem) {
148
86
  }
149
87
  }
150
88
  // @ts-ignore
151
- asyncContainer = new Promise(function(resolve, reject) {
89
+ asyncContainer = new Promise(function (resolve, reject) {
152
90
  function resolveRemoteGlobal() {
153
91
  //@ts-ignore
154
- var asyncContainer = globalScope[remoteGlobal];
92
+ const asyncContainer = globalScope[remoteGlobal];
155
93
  return resolve(asyncContainer);
156
94
  }
157
95
  //@ts-ignore
158
96
  if (typeof globalScope[remoteGlobal] !== 'undefined') {
159
97
  return resolveRemoteGlobal();
160
98
  }
161
- __webpack_require__.l(reference.url, function(event) {
99
+ __webpack_require__.l(reference.url, function (event) {
162
100
  //@ts-ignore
163
101
  if (typeof globalScope[remoteGlobal] !== 'undefined') {
164
102
  return resolveRemoteGlobal();
165
103
  }
166
- var errorType = event && (event.type === 'load' ? 'missing' : event.type);
167
- var realSrc = event && event.target && event.target.src;
168
- __webpack_error__.message = 'Loading script failed.\n(' + errorType + ': ' + realSrc + ' or global var ' + remoteGlobal + ')';
104
+ const errorType = event && (event.type === 'load' ? 'missing' : event.type);
105
+ const realSrc = event && event.target && event.target.src;
106
+ __webpack_error__.message =
107
+ 'Loading script failed.\n(' +
108
+ errorType +
109
+ ': ' +
110
+ realSrc +
111
+ ' or global var ' +
112
+ remoteGlobal +
113
+ ')';
169
114
  __webpack_error__.name = 'ScriptExternalLoadError';
170
115
  __webpack_error__.type = errorType;
171
116
  __webpack_error__.request = realSrc;
172
117
  reject(__webpack_error__);
173
118
  }, containerKey);
174
- }).catch(function(err) {
119
+ }).catch(function (err) {
175
120
  console.error('container is offline, returning fake remote');
176
121
  console.error(err);
177
122
  return {
178
123
  fake: true,
179
124
  // @ts-ignore
180
- get: function(arg) {
125
+ get: (arg) => {
181
126
  console.warn('faking', arg, 'module on, its offline');
182
- return Promise.resolve(function() {
127
+ return Promise.resolve(() => {
183
128
  return {
184
129
  __esModule: true,
185
- default: function() {
130
+ default: () => {
186
131
  return null;
187
- }
132
+ },
188
133
  };
189
134
  });
190
135
  },
191
136
  //eslint-disable-next-line
192
- init: function() {}
137
+ init: () => { },
193
138
  };
194
139
  });
195
140
  if (typeof window !== 'undefined') {
@@ -199,202 +144,54 @@ var loadScript = function(keyOrRuntimeRemoteItem) {
199
144
  }
200
145
  return asyncContainer;
201
146
  };
202
- var getRuntimeRemotes$1 = function() {
203
- return Object.entries(remoteVars).reduce(function(acc, param) {
204
- var _param = _sliced_to_array$3(param, 2), key = _param[0], value = _param[1];
205
- if ((typeof value === "undefined" ? "undefined" : _type_of$2(value)) === 'object' && typeof value.then === 'function') {
206
- acc[key] = {
207
- asyncContainer: value
208
- };
209
- } else if (typeof value === 'function') {
210
- acc[key] = {
211
- asyncContainer: Promise.resolve(value())
212
- };
213
- } else if (typeof value === 'string') {
147
+ const getRuntimeRemotes$1 = () => {
148
+ return Object.entries(remoteVars).reduce((acc, [key, value]) => {
149
+ if (typeof value === 'object' && typeof value.then === 'function') {
150
+ acc[key] = { asyncContainer: value };
151
+ }
152
+ else if (typeof value === 'function') {
153
+ acc[key] = { asyncContainer: Promise.resolve(value()) };
154
+ }
155
+ else if (typeof value === 'string') {
214
156
  if (value.startsWith('internal ')) {
215
- var _value_replace_split = _sliced_to_array$3(value.replace('internal ', '').split('?'), 2); _value_replace_split[0]; var query = _value_replace_split[1];
157
+ const [request, query] = value.replace('internal ', '').split('?');
216
158
  if (query) {
217
- var remoteSyntax = new URLSearchParams(query).get('remote');
159
+ const remoteSyntax = new URLSearchParams(query).get('remote');
218
160
  if (remoteSyntax) {
219
- var _extractUrlAndGlobal = _sliced_to_array$3(extractUrlAndGlobal(remoteSyntax), 2), url = _extractUrlAndGlobal[0], global = _extractUrlAndGlobal[1];
220
- acc[key] = {
221
- global: global,
222
- url: url
223
- };
161
+ const [url, global] = extractUrlAndGlobal(remoteSyntax);
162
+ acc[key] = { global, url };
224
163
  }
225
164
  }
226
- } else {
227
- var _extractUrlAndGlobal1 = _sliced_to_array$3(extractUrlAndGlobal(value), 2), url1 = _extractUrlAndGlobal1[0], global1 = _extractUrlAndGlobal1[1];
228
- acc[key] = {
229
- global: global1,
230
- url: url1
231
- };
232
165
  }
233
- } else {
166
+ else {
167
+ const [url, global] = extractUrlAndGlobal(value);
168
+ acc[key] = { global, url };
169
+ }
170
+ }
171
+ else {
234
172
  console.warn('remotes process', process.env['REMOTES']);
235
- throw new Error('[mf] Invalid value received for runtime_remote "'.concat(key, '"'));
173
+ throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
236
174
  }
237
175
  return acc;
238
176
  }, {});
239
177
  };
240
178
 
241
- /* eslint-disable @typescript-eslint/ban-ts-comment */ function _array_like_to_array$2(arr, len) {
242
- if (len == null || len > arr.length) len = arr.length;
243
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
244
- return arr2;
245
- }
246
- function _array_with_holes$2(arr) {
247
- if (Array.isArray(arr)) return arr;
248
- }
249
- function _iterable_to_array_limit$2(arr, i) {
250
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
251
- if (_i == null) return;
252
- var _arr = [];
253
- var _n = true;
254
- var _d = false;
255
- var _s, _e;
256
- try {
257
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
258
- _arr.push(_s.value);
259
- if (i && _arr.length === i) break;
260
- }
261
- } catch (err) {
262
- _d = true;
263
- _e = err;
264
- } finally{
265
- try {
266
- if (!_n && _i["return"] != null) _i["return"]();
267
- } finally{
268
- if (_d) throw _e;
269
- }
270
- }
271
- return _arr;
272
- }
273
- function _non_iterable_rest$2() {
274
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
275
- }
276
- function _sliced_to_array$2(arr, i) {
277
- return _array_with_holes$2(arr) || _iterable_to_array_limit$2(arr, i) || _unsupported_iterable_to_array$2(arr, i) || _non_iterable_rest$2();
278
- }
279
- function _type_of$1(obj) {
280
- "@swc/helpers - typeof";
281
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
282
- }
283
- function _unsupported_iterable_to_array$2(o, minLen) {
284
- if (!o) return;
285
- if (typeof o === "string") return _array_like_to_array$2(o, minLen);
286
- var n = Object.prototype.toString.call(o).slice(8, -1);
287
- if (n === "Object" && o.constructor) n = o.constructor.name;
288
- if (n === "Map" || n === "Set") return Array.from(n);
289
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$2(o, minLen);
290
- }
291
- function _ts_generator$2(thisArg, body) {
292
- var f, y, t, g, _ = {
293
- label: 0,
294
- sent: function() {
295
- if (t[0] & 1) throw t[1];
296
- return t[1];
297
- },
298
- trys: [],
299
- ops: []
300
- };
301
- return g = {
302
- next: verb(0),
303
- "throw": verb(1),
304
- "return": verb(2)
305
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
306
- return this;
307
- }), g;
308
- function verb(n) {
309
- return function(v) {
310
- return step([
311
- n,
312
- v
313
- ]);
314
- };
315
- }
316
- function step(op) {
317
- if (f) throw new TypeError("Generator is already executing.");
318
- while(_)try {
319
- 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;
320
- if (y = 0, t) op = [
321
- op[0] & 2,
322
- t.value
323
- ];
324
- switch(op[0]){
325
- case 0:
326
- case 1:
327
- t = op;
328
- break;
329
- case 4:
330
- _.label++;
331
- return {
332
- value: op[1],
333
- done: false
334
- };
335
- case 5:
336
- _.label++;
337
- y = op[1];
338
- op = [
339
- 0
340
- ];
341
- continue;
342
- case 7:
343
- op = _.ops.pop();
344
- _.trys.pop();
345
- continue;
346
- default:
347
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
348
- _ = 0;
349
- continue;
350
- }
351
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
352
- _.label = op[1];
353
- break;
354
- }
355
- if (op[0] === 6 && _.label < t[1]) {
356
- _.label = t[1];
357
- t = op;
358
- break;
359
- }
360
- if (t && _.label < t[2]) {
361
- _.label = t[2];
362
- _.ops.push(op);
363
- break;
364
- }
365
- if (t[2]) _.ops.pop();
366
- _.trys.pop();
367
- continue;
368
- }
369
- op = body.call(thisArg, _);
370
- } catch (e) {
371
- op = [
372
- 6,
373
- e
374
- ];
375
- y = 0;
376
- } finally{
377
- f = t = 0;
378
- }
379
- if (op[0] & 5) throw op[1];
380
- return {
381
- value: op[0] ? op[1] : void 0,
382
- done: true
383
- };
384
- }
385
- }
386
- var createContainerSharingScope = function(asyncContainer) {
179
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
180
+ const createContainerSharingScope = (asyncContainer) => {
387
181
  // @ts-ignore
388
- return asyncContainer.then(function(container) {
182
+ return asyncContainer
183
+ .then(function (container) {
389
184
  if (!__webpack_share_scopes__['default']) {
390
185
  // not always a promise, so we wrap it in a resolve
391
- return Promise.resolve(__webpack_init_sharing__('default')).then(function() {
186
+ return Promise.resolve(__webpack_init_sharing__('default')).then(function () {
392
187
  return container;
393
188
  });
394
- } else {
189
+ }
190
+ else {
395
191
  return container;
396
192
  }
397
- }).then(function(container) {
193
+ })
194
+ .then(function (container) {
398
195
  try {
399
196
  // WARNING: here might be a potential BUG.
400
197
  // `container.init` does not return a Promise, and here we do not call `then` on it.
@@ -404,8 +201,9 @@ var createContainerSharingScope = function(asyncContainer) {
404
201
  // or maybe a bug in the webpack itself - instead of returning rejected promise it just throws an error.
405
202
  // But now everything works properly and we keep this code as is.
406
203
  container.init(__webpack_share_scopes__['default']);
407
- } catch (e) {
408
- // maybe container already initialized so nothing to throw
204
+ }
205
+ catch (e) {
206
+ // maybe container already initialized so nothing to throw
409
207
  }
410
208
  return container;
411
209
  });
@@ -417,34 +215,30 @@ var createContainerSharingScope = function(asyncContainer) {
417
215
  * { global, url } - values obtained from webpack remotes option `global@url`
418
216
  * or
419
217
  * { asyncContainer } - async container is a promise that resolves to the remote container
420
- */ var injectScript = function(keyOrRuntimeRemoteItem) {
421
- return __awaiter(void 0, void 0, void 0, function() {
422
- var asyncContainer;
423
- return _ts_generator$2(this, function(_state) {
424
- asyncContainer = loadScript(keyOrRuntimeRemoteItem);
425
- return [
426
- 2,
427
- createContainerSharingScope(asyncContainer)
428
- ];
429
- });
430
- });
431
- };
218
+ */
219
+ const injectScript = (keyOrRuntimeRemoteItem) => __awaiter(void 0, void 0, void 0, function* () {
220
+ const asyncContainer = loadScript(keyOrRuntimeRemoteItem);
221
+ return createContainerSharingScope(asyncContainer);
222
+ });
432
223
  /**
433
224
  * Creates runtime variables from the provided remotes.
434
225
  * If the value of a remote starts with 'promise ' or 'external ', it is transformed into a function that returns the promise call.
435
226
  * Otherwise, the value is stringified.
436
227
  * @param {Remotes} remotes - The remotes to create runtime variables from.
437
228
  * @returns {Record<string, string>} - The created runtime variables.
438
- */ var createRuntimeVariables = function(remotes) {
229
+ */
230
+ const createRuntimeVariables = (remotes) => {
439
231
  if (!remotes) {
440
232
  return {};
441
233
  }
442
- return Object.entries(remotes).reduce(function(acc, param) {
443
- var _param = _sliced_to_array$2(param, 2), key = _param[0], value = _param[1];
234
+ return Object.entries(remotes).reduce((acc, [key, value]) => {
444
235
  if (value.startsWith('promise ') || value.startsWith('external ')) {
445
- var promiseCall = value.split(' ')[1];
446
- acc[key] = "function() {\n return ".concat(promiseCall, "\n }");
447
- } else {
236
+ const promiseCall = value.split(' ')[1];
237
+ acc[key] = `function() {
238
+ return ${promiseCall}
239
+ }`;
240
+ }
241
+ else {
448
242
  acc[key] = JSON.stringify(value);
449
243
  }
450
244
  return acc;
@@ -453,274 +247,72 @@ var createContainerSharingScope = function(asyncContainer) {
453
247
  /**
454
248
  * Returns initialized webpack RemoteContainer.
455
249
  * If its' script does not loaded - then load & init it firstly.
456
- */ var getContainer = function(remoteContainer) {
457
- return __awaiter(void 0, void 0, void 0, function() {
458
- var containerScope, containerKey, container;
459
- return _ts_generator$2(this, function(_state) {
460
- switch(_state.label){
461
- case 0:
462
- if (!remoteContainer) {
463
- throw Error("Remote container options is empty");
464
- }
465
- containerScope = typeof window !== 'undefined' ? window : globalThis.__remote_scope__;
466
- if (!(typeof remoteContainer === 'string')) return [
467
- 3,
468
- 1
469
- ];
470
- containerKey = remoteContainer;
471
- return [
472
- 3,
473
- 3
474
- ];
475
- case 1:
476
- containerKey = remoteContainer.uniqueKey;
477
- if (!!containerScope[containerKey]) return [
478
- 3,
479
- 3
480
- ];
481
- return [
482
- 4,
483
- injectScript({
484
- global: remoteContainer.global,
485
- url: remoteContainer.url
486
- })
487
- ];
488
- case 2:
489
- container = _state.sent();
490
- if (!container) {
491
- throw Error("Remote container ".concat(remoteContainer.url, " is empty"));
492
- }
493
- _state.label = 3;
494
- case 3:
495
- return [
496
- 2,
497
- containerScope[containerKey]
498
- ];
250
+ */
251
+ const getContainer = (remoteContainer) => __awaiter(void 0, void 0, void 0, function* () {
252
+ if (!remoteContainer) {
253
+ throw Error(`Remote container options is empty`);
254
+ }
255
+ const containerScope = typeof window !== 'undefined'
256
+ ? window
257
+ : globalThis.__remote_scope__;
258
+ let containerKey;
259
+ if (typeof remoteContainer === 'string') {
260
+ containerKey = remoteContainer;
261
+ }
262
+ else {
263
+ containerKey = remoteContainer.uniqueKey;
264
+ if (!containerScope[containerKey]) {
265
+ const container = yield injectScript({
266
+ global: remoteContainer.global,
267
+ url: remoteContainer.url,
268
+ });
269
+ if (!container) {
270
+ throw Error(`Remote container ${remoteContainer.url} is empty`);
499
271
  }
500
- });
501
- });
502
- };
272
+ }
273
+ }
274
+ return containerScope[containerKey];
275
+ });
503
276
  /**
504
277
  * Return remote module from container.
505
278
  * If you provide `exportName` it automatically return exact property value from module.
506
279
  *
507
280
  * @example
508
281
  * remote.getModule('./pages/index', 'default')
509
- */ var getModule = function(_a) {
510
- return __awaiter(void 0, [
511
- _a
512
- ], void 0, function(param) {
513
- var remoteContainer, modulePath, exportName, container, modFactory, mod, error;
514
- return _ts_generator$2(this, function(_state) {
515
- switch(_state.label){
516
- case 0:
517
- remoteContainer = param.remoteContainer, modulePath = param.modulePath, exportName = param.exportName;
518
- return [
519
- 4,
520
- getContainer(remoteContainer)
521
- ];
522
- case 1:
523
- container = _state.sent();
524
- _state.label = 2;
525
- case 2:
526
- _state.trys.push([
527
- 2,
528
- 4,
529
- ,
530
- 5
531
- ]);
532
- return [
533
- 4,
534
- container === null || container === void 0 ? void 0 : container.get(modulePath)
535
- ];
536
- case 3:
537
- modFactory = _state.sent();
538
- if (!modFactory) {
539
- return [
540
- 2,
541
- undefined
542
- ];
543
- }
544
- mod = modFactory();
545
- if (exportName) {
546
- return [
547
- 2,
548
- mod && (typeof mod === "undefined" ? "undefined" : _type_of$1(mod)) === 'object' ? mod[exportName] : undefined
549
- ];
550
- } else {
551
- return [
552
- 2,
553
- mod
554
- ];
555
- }
556
- case 4:
557
- error = _state.sent();
558
- console.error(error);
559
- return [
560
- 2,
561
- undefined
562
- ];
563
- case 5:
564
- return [
565
- 2
566
- ];
567
- }
568
- });
569
- });
570
- };
571
-
572
- var isObjectEmpty = function(obj) {
573
- for(var x in obj){
574
- return false;
575
- }
576
- return true;
577
- };
578
-
579
- function _array_like_to_array$1(arr, len) {
580
- if (len == null || len > arr.length) len = arr.length;
581
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
582
- return arr2;
583
- }
584
- function _array_with_holes$1(arr) {
585
- if (Array.isArray(arr)) return arr;
586
- }
587
- function _iterable_to_array_limit$1(arr, i) {
588
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
589
- if (_i == null) return;
590
- var _arr = [];
591
- var _n = true;
592
- var _d = false;
593
- var _s, _e;
282
+ */
283
+ const getModule = (_a) => __awaiter(void 0, [_a], void 0, function* ({ remoteContainer, modulePath, exportName, }) {
284
+ const container = yield getContainer(remoteContainer);
594
285
  try {
595
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
596
- _arr.push(_s.value);
597
- if (i && _arr.length === i) break;
286
+ const modFactory = yield (container === null || container === void 0 ? void 0 : container.get(modulePath));
287
+ if (!modFactory) {
288
+ return undefined;
598
289
  }
599
- } catch (err) {
600
- _d = true;
601
- _e = err;
602
- } finally{
603
- try {
604
- if (!_n && _i["return"] != null) _i["return"]();
605
- } finally{
606
- if (_d) throw _e;
290
+ const mod = modFactory();
291
+ if (exportName) {
292
+ return mod && typeof mod === 'object' ? mod[exportName] : undefined;
293
+ }
294
+ else {
295
+ return mod;
607
296
  }
608
297
  }
609
- return _arr;
610
- }
611
- function _non_iterable_rest$1() {
612
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
613
- }
614
- function _sliced_to_array$1(arr, i) {
615
- return _array_with_holes$1(arr) || _iterable_to_array_limit$1(arr, i) || _unsupported_iterable_to_array$1(arr, i) || _non_iterable_rest$1();
616
- }
617
- function _unsupported_iterable_to_array$1(o, minLen) {
618
- if (!o) return;
619
- if (typeof o === "string") return _array_like_to_array$1(o, minLen);
620
- var n = Object.prototype.toString.call(o).slice(8, -1);
621
- if (n === "Object" && o.constructor) n = o.constructor.name;
622
- if (n === "Map" || n === "Set") return Array.from(n);
623
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array$1(o, minLen);
624
- }
625
- function _ts_generator$1(thisArg, body) {
626
- var f, y, t, g, _ = {
627
- label: 0,
628
- sent: function() {
629
- if (t[0] & 1) throw t[1];
630
- return t[1];
631
- },
632
- trys: [],
633
- ops: []
634
- };
635
- return g = {
636
- next: verb(0),
637
- "throw": verb(1),
638
- "return": verb(2)
639
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
640
- return this;
641
- }), g;
642
- function verb(n) {
643
- return function(v) {
644
- return step([
645
- n,
646
- v
647
- ]);
648
- };
298
+ catch (error) {
299
+ console.error(error);
300
+ return undefined;
649
301
  }
650
- function step(op) {
651
- if (f) throw new TypeError("Generator is already executing.");
652
- while(_)try {
653
- 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;
654
- if (y = 0, t) op = [
655
- op[0] & 2,
656
- t.value
657
- ];
658
- switch(op[0]){
659
- case 0:
660
- case 1:
661
- t = op;
662
- break;
663
- case 4:
664
- _.label++;
665
- return {
666
- value: op[1],
667
- done: false
668
- };
669
- case 5:
670
- _.label++;
671
- y = op[1];
672
- op = [
673
- 0
674
- ];
675
- continue;
676
- case 7:
677
- op = _.ops.pop();
678
- _.trys.pop();
679
- continue;
680
- default:
681
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
682
- _ = 0;
683
- continue;
684
- }
685
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
686
- _.label = op[1];
687
- break;
688
- }
689
- if (op[0] === 6 && _.label < t[1]) {
690
- _.label = t[1];
691
- t = op;
692
- break;
693
- }
694
- if (t && _.label < t[2]) {
695
- _.label = t[2];
696
- _.ops.push(op);
697
- break;
698
- }
699
- if (t[2]) _.ops.pop();
700
- _.trys.pop();
701
- continue;
702
- }
703
- op = body.call(thisArg, _);
704
- } catch (e) {
705
- op = [
706
- 6,
707
- e
708
- ];
709
- y = 0;
710
- } finally{
711
- f = t = 0;
712
- }
713
- if (op[0] & 5) throw op[1];
714
- return {
715
- value: op[0] ? op[1] : void 0,
716
- done: true
717
- };
302
+ });
303
+
304
+ const isObjectEmpty = (obj) => {
305
+ for (const x in obj) {
306
+ return false;
718
307
  }
719
- }
308
+ return true;
309
+ };
310
+
720
311
  /**
721
312
  * Constant for remote entry file
722
313
  * @constant {string}
723
- */ var REMOTE_ENTRY_FILE = 'remoteEntry.js';
314
+ */
315
+ const REMOTE_ENTRY_FILE = 'remoteEntry.js';
724
316
  /**
725
317
  * Function to load remote
726
318
  * @function
@@ -728,532 +320,227 @@ function _ts_generator$1(thisArg, body) {
728
320
  * @param {ImportRemoteOptions['scope']} scope - The scope of the remote module
729
321
  * @param {ImportRemoteOptions['bustRemoteEntryCache']} bustRemoteEntryCache - Flag to bust the remote entry cache
730
322
  * @returns {Promise<void>} A promise that resolves when the remote is loaded
731
- */ var loadRemote = function(url, scope, bustRemoteEntryCache) {
732
- return new Promise(function(resolve, reject) {
733
- var timestamp = bustRemoteEntryCache ? "?t=".concat(new Date().getTime()) : '';
734
- var webpackRequire = __webpack_require__;
735
- webpackRequire.l("".concat(url).concat(timestamp), function(event) {
736
- var _a;
737
- if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
738
- // Script loaded successfully:
739
- return resolve();
740
- }
741
- var realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
742
- var error = new Error();
743
- error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
744
- error.name = 'ScriptExternalLoadError';
745
- reject(error);
746
- }, scope);
747
- });
748
- };
749
- var loadEsmRemote = function(url, scope) {
750
- return __awaiter(void 0, void 0, void 0, function() {
751
- var module;
752
- return _ts_generator$1(this, function(_state) {
753
- switch(_state.label){
754
- case 0:
755
- return [
756
- 4,
757
- import(/* webpackIgnore: true */ url)
758
- ];
759
- case 1:
760
- module = _state.sent();
761
- if (!module) {
762
- throw new Error("Unable to load requested remote from ".concat(url, " with scope ").concat(scope));
763
- }
764
- window[scope] = Object.assign(Object.assign({}, module), {
765
- __initializing: false,
766
- __initialized: false
767
- });
768
- return [
769
- 2
770
- ];
771
- }
772
- });
773
- });
774
- };
323
+ */
324
+ const loadRemote = (url, scope, bustRemoteEntryCache) => new Promise((resolve, reject) => {
325
+ const timestamp = bustRemoteEntryCache ? `?t=${new Date().getTime()}` : '';
326
+ const webpackRequire = __webpack_require__;
327
+ webpackRequire.l(`${url}${timestamp}`, (event) => {
328
+ var _a;
329
+ if ((event === null || event === void 0 ? void 0 : event.type) === 'load') {
330
+ // Script loaded successfully:
331
+ return resolve();
332
+ }
333
+ const realSrc = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src;
334
+ const error = new Error();
335
+ error.message = 'Loading script failed.\n(missing: ' + realSrc + ')';
336
+ error.name = 'ScriptExternalLoadError';
337
+ reject(error);
338
+ }, scope);
339
+ });
340
+ const loadEsmRemote = (url, scope) => __awaiter(void 0, void 0, void 0, function* () {
341
+ const module = yield import(/* webpackIgnore: true */ url);
342
+ if (!module) {
343
+ throw new Error(`Unable to load requested remote from ${url} with scope ${scope}`);
344
+ }
345
+ window[scope] = Object.assign(Object.assign({}, module), { __initializing: false, __initialized: false });
346
+ });
775
347
  /**
776
348
  * Function to initialize sharing
777
349
  * @async
778
350
  * @function
779
- */ var initSharing = function() {
780
- return __awaiter(void 0, void 0, void 0, function() {
781
- var webpackShareScopes;
782
- return _ts_generator$1(this, function(_state) {
783
- switch(_state.label){
784
- case 0:
785
- webpackShareScopes = __webpack_share_scopes__;
786
- if (!!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) return [
787
- 3,
788
- 2
789
- ];
790
- return [
791
- 4,
792
- __webpack_init_sharing__('default')
793
- ];
794
- case 1:
795
- _state.sent();
796
- _state.label = 2;
797
- case 2:
798
- return [
799
- 2
800
- ];
801
- }
802
- });
803
- });
804
- };
351
+ */
352
+ const initSharing = () => __awaiter(void 0, void 0, void 0, function* () {
353
+ const webpackShareScopes = __webpack_share_scopes__;
354
+ if (!(webpackShareScopes === null || webpackShareScopes === void 0 ? void 0 : webpackShareScopes.default)) {
355
+ yield __webpack_init_sharing__('default');
356
+ }
357
+ });
805
358
  /**
806
359
  * Function to initialize container
807
360
  * @async
808
361
  * @function
809
362
  * @param {WebpackRemoteContainer} containerScope - The container scope
810
- */ var initContainer = function(containerScope) {
811
- return __awaiter(void 0, void 0, void 0, function() {
812
- var webpackShareScopes, error;
813
- return _ts_generator$1(this, function(_state) {
814
- switch(_state.label){
815
- case 0:
816
- _state.trys.push([
817
- 0,
818
- 3,
819
- ,
820
- 4
821
- ]);
822
- webpackShareScopes = __webpack_share_scopes__;
823
- if (!(!containerScope.__initialized && !containerScope.__initializing)) return [
824
- 3,
825
- 2
826
- ];
827
- containerScope.__initializing = true;
828
- return [
829
- 4,
830
- containerScope.init(webpackShareScopes.default)
831
- ];
832
- case 1:
833
- _state.sent();
834
- containerScope.__initialized = true;
835
- delete containerScope.__initializing;
836
- _state.label = 2;
837
- case 2:
838
- return [
839
- 3,
840
- 4
841
- ];
842
- case 3:
843
- error = _state.sent();
844
- console.error(error);
845
- return [
846
- 3,
847
- 4
848
- ];
849
- case 4:
850
- return [
851
- 2
852
- ];
853
- }
854
- });
855
- });
856
- };
363
+ */
364
+ const initContainer = (containerScope) => __awaiter(void 0, void 0, void 0, function* () {
365
+ try {
366
+ const webpackShareScopes = __webpack_share_scopes__;
367
+ if (!containerScope.__initialized && !containerScope.__initializing) {
368
+ containerScope.__initializing = true;
369
+ yield containerScope.init(webpackShareScopes.default);
370
+ containerScope.__initialized = true;
371
+ delete containerScope.__initializing;
372
+ }
373
+ }
374
+ catch (error) {
375
+ console.error(error);
376
+ }
377
+ });
857
378
  /**
858
379
  * Function to import remote
859
380
  * @async
860
381
  * @function
861
382
  * @param {ImportRemoteOptions} options - The options for importing the remote
862
383
  * @returns {Promise<T>} A promise that resolves with the imported module
863
- */ var importRemote = function(_a) {
864
- return __awaiter(void 0, [
865
- _a
866
- ], void 0, function(param) {
867
- var url, scope, module, _param_remoteEntryFileName, remoteEntryFileName, _param_bustRemoteEntryCache, bustRemoteEntryCache, _param_esm, esm, remoteScope, remoteUrl, remoteUrlWithEntryFile, asyncContainer, _ref, moduleFactory, moduleFactory1;
868
- return _ts_generator$1(this, function(_state) {
869
- switch(_state.label){
870
- case 0:
871
- url = param.url, scope = param.scope, module = param.module, _param_remoteEntryFileName = param.remoteEntryFileName, remoteEntryFileName = _param_remoteEntryFileName === void 0 ? REMOTE_ENTRY_FILE : _param_remoteEntryFileName, _param_bustRemoteEntryCache = param.bustRemoteEntryCache, bustRemoteEntryCache = _param_bustRemoteEntryCache === void 0 ? true : _param_bustRemoteEntryCache, _param_esm = param.esm, esm = _param_esm === void 0 ? false : _param_esm;
872
- remoteScope = scope;
873
- if (!!window[remoteScope]) return [
874
- 3,
875
- 6
876
- ];
877
- remoteUrl = '';
878
- if (!(typeof url === 'string')) return [
879
- 3,
880
- 1
881
- ];
882
- remoteUrl = url;
883
- return [
884
- 3,
885
- 3
886
- ];
887
- case 1:
888
- return [
889
- 4,
890
- url()
891
- ];
892
- case 2:
893
- remoteUrl = _state.sent();
894
- _state.label = 3;
895
- case 3:
896
- remoteUrlWithEntryFile = "".concat(remoteUrl, "/").concat(remoteEntryFileName);
897
- asyncContainer = !esm ? loadRemote(remoteUrlWithEntryFile, scope, bustRemoteEntryCache) : loadEsmRemote(remoteUrlWithEntryFile, scope);
898
- // Load the remote and initialize the share scope if it's empty
899
- return [
900
- 4,
901
- Promise.all([
902
- asyncContainer,
903
- initSharing()
904
- ])
905
- ];
906
- case 4:
907
- _state.sent();
908
- if (!window[remoteScope]) {
909
- throw new Error("Remote loaded successfully but ".concat(scope, " could not be found! Verify that the name is correct in the Webpack configuration!"));
910
- }
911
- return [
912
- 4,
913
- Promise.all([
914
- initContainer(window[remoteScope]),
915
- window[remoteScope].get(module === '.' || module.startsWith('./') ? module : "./".concat(module))
916
- ])
917
- ];
918
- case 5:
919
- _ref = _sliced_to_array$1.apply(void 0, [
920
- _state.sent(),
921
- 2
922
- ]), moduleFactory = _ref[1];
923
- return [
924
- 2,
925
- moduleFactory()
926
- ];
927
- case 6:
928
- return [
929
- 4,
930
- window[remoteScope].get(module === '.' || module.startsWith('./') ? module : "./".concat(module))
931
- ];
932
- case 7:
933
- moduleFactory1 = _state.sent();
934
- return [
935
- 2,
936
- moduleFactory1()
937
- ];
938
- case 8:
939
- return [
940
- 2
941
- ];
942
- }
943
- });
944
- });
945
- };
384
+ */
385
+ const importRemote = (_a) => __awaiter(void 0, [_a], void 0, function* ({ url, scope, module, remoteEntryFileName = REMOTE_ENTRY_FILE, bustRemoteEntryCache = true, esm = false, }) {
386
+ const remoteScope = scope;
387
+ if (!window[remoteScope]) {
388
+ let remoteUrl = '';
389
+ if (typeof url === 'string') {
390
+ remoteUrl = url;
391
+ }
392
+ else {
393
+ remoteUrl = yield url();
394
+ }
395
+ const remoteUrlWithEntryFile = `${remoteUrl}/${remoteEntryFileName}`;
396
+ const asyncContainer = !esm
397
+ ? loadRemote(remoteUrlWithEntryFile, scope, bustRemoteEntryCache)
398
+ : loadEsmRemote(remoteUrlWithEntryFile, scope);
399
+ // Load the remote and initialize the share scope if it's empty
400
+ yield Promise.all([asyncContainer, initSharing()]);
401
+ if (!window[remoteScope]) {
402
+ throw new Error(`Remote loaded successfully but ${scope} could not be found! Verify that the name is correct in the Webpack configuration!`);
403
+ }
404
+ // Initialize the container to get shared modules and get the module factory:
405
+ const [, moduleFactory] = yield Promise.all([
406
+ initContainer(window[remoteScope]),
407
+ window[remoteScope].get(module === '.' || module.startsWith('./') ? module : `./${module}`),
408
+ ]);
409
+ return moduleFactory();
410
+ }
411
+ else {
412
+ const moduleFactory = yield window[remoteScope].get(module === '.' || module.startsWith('./') ? module : `./${module}`);
413
+ return moduleFactory();
414
+ }
415
+ });
946
416
 
947
- function _class_call_check(instance, Constructor) {
948
- if (!(instance instanceof Constructor)) {
949
- throw new TypeError("Cannot call a class as a function");
417
+ class Logger {
418
+ static getLogger() {
419
+ return this.loggerInstance;
950
420
  }
951
- }
952
- function _defineProperties(target, props) {
953
- for(var i = 0; i < props.length; i++){
954
- var descriptor = props[i];
955
- descriptor.enumerable = descriptor.enumerable || false;
956
- descriptor.configurable = true;
957
- if ("value" in descriptor) descriptor.writable = true;
958
- Object.defineProperty(target, descriptor.key, descriptor);
421
+ static setLogger(logger) {
422
+ this.loggerInstance = logger || console;
423
+ return logger;
959
424
  }
960
425
  }
961
- function _create_class(Constructor, protoProps, staticProps) {
962
- if (staticProps) _defineProperties(Constructor, staticProps);
963
- return Constructor;
964
- }
965
- var Logger = /*#__PURE__*/ function() {
966
- function Logger() {
967
- _class_call_check(this, Logger);
968
- }
969
- _create_class(Logger, null, [
970
- {
971
- key: "getLogger",
972
- value: function getLogger() {
973
- return this.loggerInstance;
974
- }
975
- },
976
- {
977
- key: "setLogger",
978
- value: function setLogger(logger) {
979
- this.loggerInstance = logger || console;
980
- return logger;
981
- }
982
- }
983
- ]);
984
- return Logger;
985
- }();
986
426
  Logger.loggerInstance = console;
987
427
 
988
- function _array_like_to_array(arr, len) {
989
- if (len == null || len > arr.length) len = arr.length;
990
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
991
- return arr2;
992
- }
993
- function _array_with_holes(arr) {
994
- if (Array.isArray(arr)) return arr;
995
- }
996
- function _iterable_to_array_limit(arr, i) {
997
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
998
- if (_i == null) return;
999
- var _arr = [];
1000
- var _n = true;
1001
- var _d = false;
1002
- var _s, _e;
1003
- try {
1004
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
1005
- _arr.push(_s.value);
1006
- if (i && _arr.length === i) break;
1007
- }
1008
- } catch (err) {
1009
- _d = true;
1010
- _e = err;
1011
- } finally{
1012
- try {
1013
- if (!_n && _i["return"] != null) _i["return"]();
1014
- } finally{
1015
- if (_d) throw _e;
1016
- }
1017
- }
1018
- return _arr;
1019
- }
1020
- function _non_iterable_rest() {
1021
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1022
- }
1023
- function _sliced_to_array(arr, i) {
1024
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
1025
- }
1026
- function _type_of(obj) {
1027
- "@swc/helpers - typeof";
1028
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1029
- }
1030
- function _unsupported_iterable_to_array(o, minLen) {
1031
- if (!o) return;
1032
- if (typeof o === "string") return _array_like_to_array(o, minLen);
1033
- var n = Object.prototype.toString.call(o).slice(8, -1);
1034
- if (n === "Object" && o.constructor) n = o.constructor.name;
1035
- if (n === "Map" || n === "Set") return Array.from(n);
1036
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
1037
- }
1038
- var getRuntimeRemotes = function() {
428
+ const getRuntimeRemotes = () => {
1039
429
  try {
1040
- return Object.entries(remoteVars).reduce(function(acc, item) {
1041
- var _item = _sliced_to_array(item, 2), key = _item[0], value = _item[1];
430
+ return Object.entries(remoteVars).reduce(function (acc, item) {
431
+ const [key, value] = item;
1042
432
  // if its an object with a thenable (eagerly executing function)
1043
- if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === 'object' && typeof value.then === 'function') {
1044
- acc[key] = {
1045
- asyncContainer: value
1046
- };
1047
- } else if (typeof value === 'function') {
433
+ if (typeof value === 'object' && typeof value.then === 'function') {
434
+ acc[key] = { asyncContainer: value };
435
+ }
436
+ // if its a function that must be called (lazily executing function)
437
+ else if (typeof value === 'function') {
1048
438
  // @ts-ignore
1049
- acc[key] = {
1050
- asyncContainer: value
1051
- };
1052
- } else if (typeof value === 'string' && value.startsWith('internal ')) {
1053
- var _value_replace_split = _sliced_to_array(value.replace('internal ', '').split('?'), 2), request = _value_replace_split[0], query = _value_replace_split[1];
439
+ acc[key] = { asyncContainer: value };
440
+ }
441
+ // if its a delegate module, skip it
442
+ else if (typeof value === 'string' && value.startsWith('internal ')) {
443
+ const [request, query] = value.replace('internal ', '').split('?');
1054
444
  if (query) {
1055
- var remoteSyntax = new URLSearchParams(query).get('remote');
445
+ const remoteSyntax = new URLSearchParams(query).get('remote');
1056
446
  if (remoteSyntax) {
1057
- var _extractUrlAndGlobal = _sliced_to_array(extractUrlAndGlobal(remoteSyntax), 2), url = _extractUrlAndGlobal[0], global = _extractUrlAndGlobal[1];
1058
- acc[key] = {
1059
- global: global,
1060
- url: url
1061
- };
447
+ const [url, global] = extractUrlAndGlobal(remoteSyntax);
448
+ acc[key] = { global, url };
1062
449
  }
1063
450
  }
1064
- } else if (typeof value === 'string') {
1065
- var _extractUrlAndGlobal1 = _sliced_to_array(extractUrlAndGlobal(value), 2), url1 = _extractUrlAndGlobal1[0], global1 = _extractUrlAndGlobal1[1];
1066
- acc[key] = {
1067
- global: global1,
1068
- url: url1
1069
- };
1070
- } else {
451
+ }
452
+ // if its just a string (global@url)
453
+ else if (typeof value === 'string') {
454
+ const [url, global] = extractUrlAndGlobal(value);
455
+ acc[key] = { global, url };
456
+ }
457
+ // we dont know or currently support this type
458
+ else {
1071
459
  //@ts-ignore
1072
460
  console.warn('remotes process', process.env.REMOTES);
1073
- throw new Error('[mf] Invalid value received for runtime_remote "'.concat(key, '"'));
461
+ throw new Error(`[mf] Invalid value received for runtime_remote "${key}"`);
1074
462
  }
1075
463
  return acc;
1076
464
  }, {});
1077
- } catch (err) {
465
+ }
466
+ catch (err) {
1078
467
  console.warn('Unable to retrieve runtime remotes: ', err);
1079
468
  }
1080
469
  return {};
1081
470
  };
1082
471
 
1083
- function _ts_generator(thisArg, body) {
1084
- var f, y, t, g, _ = {
1085
- label: 0,
1086
- sent: function() {
1087
- if (t[0] & 1) throw t[1];
1088
- return t[1];
1089
- },
1090
- trys: [],
1091
- ops: []
1092
- };
1093
- return g = {
1094
- next: verb(0),
1095
- "throw": verb(1),
1096
- "return": verb(2)
1097
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1098
- return this;
1099
- }), g;
1100
- function verb(n) {
1101
- return function(v) {
1102
- return step([
1103
- n,
1104
- v
1105
- ]);
1106
- };
1107
- }
1108
- function step(op) {
1109
- if (f) throw new TypeError("Generator is already executing.");
1110
- while(_)try {
1111
- 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;
1112
- if (y = 0, t) op = [
1113
- op[0] & 2,
1114
- t.value
1115
- ];
1116
- switch(op[0]){
1117
- case 0:
1118
- case 1:
1119
- t = op;
1120
- break;
1121
- case 4:
1122
- _.label++;
1123
- return {
1124
- value: op[1],
1125
- done: false
1126
- };
1127
- case 5:
1128
- _.label++;
1129
- y = op[1];
1130
- op = [
1131
- 0
1132
- ];
1133
- continue;
1134
- case 7:
1135
- op = _.ops.pop();
1136
- _.trys.pop();
1137
- continue;
1138
- default:
1139
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1140
- _ = 0;
1141
- continue;
1142
- }
1143
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1144
- _.label = op[1];
1145
- break;
1146
- }
1147
- if (op[0] === 6 && _.label < t[1]) {
1148
- _.label = t[1];
1149
- t = op;
1150
- break;
1151
- }
1152
- if (t && _.label < t[2]) {
1153
- _.label = t[2];
1154
- _.ops.push(op);
1155
- break;
1156
- }
1157
- if (t[2]) _.ops.pop();
1158
- _.trys.pop();
1159
- continue;
472
+ const importDelegatedModule = (keyOrRuntimeRemoteItem) => __awaiter(void 0, void 0, void 0, function* () {
473
+ // @ts-ignore
474
+ return loadScript(keyOrRuntimeRemoteItem)
475
+ .then((asyncContainer) => {
476
+ return asyncContainer;
477
+ })
478
+ .then((asyncContainer) => {
479
+ // most of this is only needed because of legacy promise based implementation
480
+ // can remove proxies once we remove promise based implementations
481
+ if (typeof window === 'undefined') {
482
+ if (!Object.hasOwnProperty.call(keyOrRuntimeRemoteItem, 'globalThis')) {
483
+ return asyncContainer;
1160
484
  }
1161
- op = body.call(thisArg, _);
1162
- } catch (e) {
1163
- op = [
1164
- 6,
1165
- e
1166
- ];
1167
- y = 0;
1168
- } finally{
1169
- f = t = 0;
1170
- }
1171
- if (op[0] & 5) throw op[1];
1172
- return {
1173
- value: op[0] ? op[1] : void 0,
1174
- done: true
1175
- };
1176
- }
1177
- }
1178
- var importDelegatedModule = function(keyOrRuntimeRemoteItem) {
1179
- return __awaiter(void 0, void 0, void 0, function() {
1180
- return _ts_generator(this, function(_state) {
1181
- // @ts-ignore
1182
- return [
1183
- 2,
1184
- loadScript(keyOrRuntimeRemoteItem).then(function(asyncContainer) {
1185
- return asyncContainer;
1186
- }).then(function(asyncContainer) {
1187
- // most of this is only needed because of legacy promise based implementation
1188
- // can remove proxies once we remove promise based implementations
1189
- if (typeof window === 'undefined') {
1190
- if (!Object.hasOwnProperty.call(keyOrRuntimeRemoteItem, 'globalThis')) {
1191
- return asyncContainer;
1192
- }
1193
- // return asyncContainer;
1194
- //TODO: need to solve chunk flushing with delegated modules
1195
- return {
1196
- get: function get(arg) {
1197
- //@ts-ignore
1198
- return asyncContainer.get(arg).then(function(f) {
1199
- var _loop = function(prop) {
1200
- if (typeof m[prop] === 'function') {
1201
- Object.defineProperty(result, prop, {
1202
- get: function get() {
1203
- return function() {
1204
- var _m;
1205
- //@ts-ignore
1206
- if (globalThis.usedChunks) {
1207
- //@ts-ignore
1208
- globalThis.usedChunks.add(//@ts-ignore
1209
- "".concat(keyOrRuntimeRemoteItem.global, "->").concat(arg));
1210
- }
1211
- //eslint-disable-next-line prefer-rest-params
1212
- return (_m = m)[prop].apply(_m, arguments);
1213
- };
1214
- },
1215
- enumerable: true
1216
- });
1217
- } else {
1218
- Object.defineProperty(result, prop, {
1219
- get: function() {
1220
- //@ts-ignore
1221
- if (globalThis.usedChunks) {
1222
- //@ts-ignore
1223
- globalThis.usedChunks.add(//@ts-ignore
1224
- "".concat(keyOrRuntimeRemoteItem.global, "->").concat(arg));
1225
- }
1226
- return m[prop];
1227
- },
1228
- enumerable: true
1229
- });
485
+ // return asyncContainer;
486
+ //TODO: need to solve chunk flushing with delegated modules
487
+ return {
488
+ get: function (arg) {
489
+ //@ts-ignore
490
+ return asyncContainer.get(arg).then((f) => {
491
+ const m = f();
492
+ const result = {
493
+ __esModule: m.__esModule,
494
+ };
495
+ for (const prop in m) {
496
+ if (typeof m[prop] === 'function') {
497
+ Object.defineProperty(result, prop, {
498
+ get: function () {
499
+ return function () {
500
+ //@ts-ignore
501
+ if (globalThis.usedChunks) {
502
+ //@ts-ignore
503
+ globalThis.usedChunks.add(
504
+ //@ts-ignore
505
+ `${keyOrRuntimeRemoteItem.global}->${arg}`);
506
+ }
507
+ //eslint-disable-next-line prefer-rest-params
508
+ return m[prop](...arguments);
509
+ };
510
+ },
511
+ enumerable: true,
512
+ });
513
+ }
514
+ else {
515
+ Object.defineProperty(result, prop, {
516
+ get: () => {
517
+ //@ts-ignore
518
+ if (globalThis.usedChunks) {
519
+ //@ts-ignore
520
+ globalThis.usedChunks.add(
521
+ //@ts-ignore
522
+ `${keyOrRuntimeRemoteItem.global}->${arg}`);
1230
523
  }
1231
- };
1232
- var m = f();
1233
- var result = {
1234
- __esModule: m.__esModule
1235
- };
1236
- for(var prop in m)_loop(prop);
1237
- if (m.then) {
1238
- return Promise.resolve(function() {
1239
- return result;
1240
- });
1241
- }
1242
- return function() {
1243
- return result;
1244
- };
524
+ return m[prop];
525
+ },
526
+ enumerable: true,
1245
527
  });
1246
- },
1247
- init: asyncContainer.init
1248
- };
1249
- } else {
1250
- return asyncContainer;
1251
- }
1252
- })
1253
- ];
1254
- });
528
+ }
529
+ }
530
+ if (m.then) {
531
+ return Promise.resolve(() => result);
532
+ }
533
+ return () => result;
534
+ });
535
+ },
536
+ init: asyncContainer.init,
537
+ };
538
+ }
539
+ else {
540
+ return asyncContainer;
541
+ }
1255
542
  });
1256
- };
543
+ });
1257
544
 
1258
545
  exports.Logger = Logger;
1259
546
  exports.createRuntimeVariables = createRuntimeVariables;