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