@module-federation/runtime 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +5 -784
  2. package/package.json +2 -2
  3. package/dist/LICENSE +0 -21
  4. package/dist/helpers.cjs.d.ts +0 -2
  5. package/dist/helpers.cjs.js +0 -34
  6. package/dist/helpers.esm.js +0 -32
  7. package/dist/index.cjs.d.ts +0 -1
  8. package/dist/index.cjs.js +0 -1767
  9. package/dist/index.esm.js +0 -1747
  10. package/dist/package.json +0 -50
  11. package/dist/share.cjs.js +0 -843
  12. package/dist/share.esm.js +0 -806
  13. package/dist/src/constant.d.ts +0 -2
  14. package/dist/src/core.d.ts +0 -164
  15. package/dist/src/global.d.ts +0 -43
  16. package/dist/src/helpers.d.ts +0 -33
  17. package/dist/src/index.d.ts +0 -15
  18. package/dist/src/module/index.d.ts +0 -19
  19. package/dist/src/plugins/generate-preload-assets.d.ts +0 -8
  20. package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +0 -44
  21. package/dist/src/plugins/snapshot/index.d.ts +0 -5
  22. package/dist/src/type/config.d.ts +0 -100
  23. package/dist/src/type/index.d.ts +0 -3
  24. package/dist/src/type/plugin.d.ts +0 -20
  25. package/dist/src/type/preload.d.ts +0 -26
  26. package/dist/src/types.d.ts +0 -1
  27. package/dist/src/utils/env.d.ts +0 -4
  28. package/dist/src/utils/hooks/asyncHook.d.ts +0 -6
  29. package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +0 -10
  30. package/dist/src/utils/hooks/index.d.ts +0 -6
  31. package/dist/src/utils/hooks/pluginSystem.d.ts +0 -15
  32. package/dist/src/utils/hooks/syncHook.d.ts +0 -12
  33. package/dist/src/utils/hooks/syncWaterfallHook.d.ts +0 -9
  34. package/dist/src/utils/index.d.ts +0 -6
  35. package/dist/src/utils/load.d.ts +0 -18
  36. package/dist/src/utils/logger.d.ts +0 -3
  37. package/dist/src/utils/manifest.d.ts +0 -7
  38. package/dist/src/utils/plugin.d.ts +0 -4
  39. package/dist/src/utils/preload.d.ts +0 -6
  40. package/dist/src/utils/semver/compare.d.ts +0 -9
  41. package/dist/src/utils/semver/constants.d.ts +0 -10
  42. package/dist/src/utils/semver/index.d.ts +0 -2
  43. package/dist/src/utils/semver/parser.d.ts +0 -9
  44. package/dist/src/utils/semver/utils.d.ts +0 -11
  45. package/dist/src/utils/share.d.ts +0 -16
  46. package/dist/src/utils/tool.d.ts +0 -12
  47. package/dist/types.cjs.d.ts +0 -1
  48. package/dist/types.cjs.js +0 -2
  49. package/dist/types.esm.js +0 -1
package/dist/index.cjs.js DELETED
@@ -1,1767 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var share = require('./share.cjs.js');
6
- var sdk = require('@module-federation/sdk');
7
-
8
- // Function to match a remote with its name and expose
9
- // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
10
- // id: alias(app1) + expose(button) = app1/button
11
- // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
12
- function matchRemoteWithNameAndExpose(remotes, id) {
13
- for (const remote of remotes){
14
- // match pkgName
15
- const isNameMatched = id.startsWith(remote.name);
16
- let expose = id.replace(remote.name, '');
17
- if (isNameMatched) {
18
- if (expose.startsWith('/')) {
19
- const pkgNameOrAlias = remote.name;
20
- expose = `.${expose}`;
21
- return {
22
- pkgNameOrAlias,
23
- expose,
24
- remote
25
- };
26
- } else if (expose === '') {
27
- return {
28
- pkgNameOrAlias: remote.name,
29
- expose: '.',
30
- remote
31
- };
32
- }
33
- }
34
- // match alias
35
- const isAliasMatched = remote.alias && id.startsWith(remote.alias);
36
- let exposeWithAlias = remote.alias && id.replace(remote.alias, '');
37
- if (remote.alias && isAliasMatched) {
38
- if (exposeWithAlias && exposeWithAlias.startsWith('/')) {
39
- const pkgNameOrAlias = remote.alias;
40
- exposeWithAlias = `.${exposeWithAlias}`;
41
- return {
42
- pkgNameOrAlias,
43
- expose: exposeWithAlias,
44
- remote
45
- };
46
- } else if (exposeWithAlias === '') {
47
- return {
48
- pkgNameOrAlias: remote.alias,
49
- expose: '.',
50
- remote
51
- };
52
- }
53
- }
54
- }
55
- return;
56
- }
57
- // Function to match a remote with its name or alias
58
- function matchRemote(remotes, nameOrAlias) {
59
- for (const remote of remotes){
60
- const isNameMatched = nameOrAlias === remote.name;
61
- if (isNameMatched) {
62
- return remote;
63
- }
64
- const isAliasMatched = remote.alias && nameOrAlias === remote.alias;
65
- if (isAliasMatched) {
66
- return remote;
67
- }
68
- }
69
- return;
70
- }
71
-
72
- function registerPlugins$1(plugins, hookInstances) {
73
- const globalPlugins = share.getGlobalHostPlugins();
74
- // Incorporate global plugins
75
- if (globalPlugins.length > 0) {
76
- globalPlugins.forEach((plugin)=>{
77
- if (plugins == null ? void 0 : plugins.find((item)=>item.name !== plugin.name)) {
78
- plugins.push(plugin);
79
- }
80
- });
81
- }
82
- if (plugins && plugins.length > 0) {
83
- plugins.forEach((plugin)=>{
84
- hookInstances.forEach((hookInstance)=>{
85
- hookInstance.applyPlugin(plugin);
86
- });
87
- });
88
- }
89
- }
90
-
91
- function _extends$5() {
92
- _extends$5 = Object.assign || function(target) {
93
- for(var i = 1; i < arguments.length; i++){
94
- var source = arguments[i];
95
- for(var key in source){
96
- if (Object.prototype.hasOwnProperty.call(source, key)) {
97
- target[key] = source[key];
98
- }
99
- }
100
- }
101
- return target;
102
- };
103
- return _extends$5.apply(this, arguments);
104
- }
105
- async function loadEsmEntry({ entry, remoteEntryExports }) {
106
- return new Promise((resolve, reject)=>{
107
- try {
108
- if (!remoteEntryExports) {
109
- // eslint-disable-next-line no-eval
110
- new Function('callbacks', `import("${entry}").then(callbacks[0]).catch(callbacks[1])`)([
111
- resolve,
112
- reject
113
- ]);
114
- } else {
115
- resolve(remoteEntryExports);
116
- }
117
- } catch (e) {
118
- reject(e);
119
- }
120
- });
121
- }
122
- async function loadEntryScript({ name, globalName, entry, createScriptHook }) {
123
- const { entryExports: remoteEntryExports } = share.getRemoteEntryExports(name, globalName);
124
- if (remoteEntryExports) {
125
- return remoteEntryExports;
126
- }
127
- if (typeof document === 'undefined') {
128
- return sdk.loadScriptNode(entry, {
129
- attrs: {
130
- name,
131
- globalName
132
- },
133
- createScriptHook
134
- }).then(()=>{
135
- const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
136
- share.assert(entryExports, `
137
- Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
138
- Possible reasons could be:\n
139
- 1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
140
- 2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
141
- `);
142
- return entryExports;
143
- }).catch((e)=>{
144
- return e;
145
- });
146
- }
147
- return sdk.loadScript(entry, {
148
- attrs: {},
149
- createScriptHook
150
- }).then(()=>{
151
- const { remoteEntryKey, entryExports } = share.getRemoteEntryExports(name, globalName);
152
- share.assert(entryExports, `
153
- Unable to use the ${name}'s '${entry}' URL with ${remoteEntryKey}'s globalName to get remoteEntry exports.
154
- Possible reasons could be:\n
155
- 1. '${entry}' is not the correct URL, or the remoteEntry resource or name is incorrect.\n
156
- 2. ${remoteEntryKey} cannot be used to get remoteEntry exports in the window object.
157
- `);
158
- return entryExports;
159
- }).catch((e)=>{
160
- return e;
161
- });
162
- }
163
- function getRemoteEntryUniqueKey(remoteInfo) {
164
- const { entry, name } = remoteInfo;
165
- return sdk.composeKeyWithSeparator(name, entry);
166
- }
167
- async function getRemoteEntry({ remoteEntryExports, remoteInfo, createScriptHook }) {
168
- const { entry, name, type, entryGlobalName } = remoteInfo;
169
- const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
170
- if (remoteEntryExports) {
171
- return remoteEntryExports;
172
- }
173
- if (!share.globalLoading[uniqueKey]) {
174
- if (type === 'esm') {
175
- share.globalLoading[uniqueKey] = loadEsmEntry({
176
- entry,
177
- remoteEntryExports
178
- });
179
- } else {
180
- share.globalLoading[uniqueKey] = loadEntryScript({
181
- name,
182
- globalName: entryGlobalName,
183
- entry,
184
- createScriptHook
185
- });
186
- }
187
- }
188
- return share.globalLoading[uniqueKey];
189
- }
190
- function getRemoteInfo(remote) {
191
- return _extends$5({}, remote, {
192
- entry: 'entry' in remote ? remote.entry : '',
193
- type: remote.type || share.DEFAULT_REMOTE_TYPE,
194
- entryGlobalName: remote.entryGlobalName || remote.name,
195
- shareScope: remote.shareScope || share.DEFAULT_SCOPE
196
- });
197
- }
198
-
199
- function _extends$4() {
200
- _extends$4 = Object.assign || function(target) {
201
- for(var i = 1; i < arguments.length; i++){
202
- var source = arguments[i];
203
- for(var key in source){
204
- if (Object.prototype.hasOwnProperty.call(source, key)) {
205
- target[key] = source[key];
206
- }
207
- }
208
- }
209
- return target;
210
- };
211
- return _extends$4.apply(this, arguments);
212
- }
213
- let Module = class Module {
214
- async getEntry() {
215
- if (this.remoteEntryExports) {
216
- return this.remoteEntryExports;
217
- }
218
- // Get remoteEntry.js
219
- const remoteEntryExports = await getRemoteEntry({
220
- remoteInfo: this.remoteInfo,
221
- remoteEntryExports: this.remoteEntryExports,
222
- createScriptHook: (url)=>{
223
- const res = this.host.loaderHook.lifecycle.createScript.emit({
224
- url
225
- });
226
- if (typeof document === 'undefined') {
227
- //todo: needs real fix
228
- return res;
229
- }
230
- if (res instanceof HTMLScriptElement) {
231
- return res;
232
- }
233
- return;
234
- }
235
- });
236
- share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${share.safeToString(this.remoteInfo)}`);
237
- this.remoteEntryExports = remoteEntryExports;
238
- return this.remoteEntryExports;
239
- }
240
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
241
- async get(expose, options) {
242
- const { loadFactory = true } = options || {
243
- loadFactory: true
244
- };
245
- // Get remoteEntry.js
246
- const remoteEntryExports = await this.getEntry();
247
- if (!this.inited) {
248
- const localShareScopeMap = this.host.shareScopeMap;
249
- const remoteShareScope = this.remoteInfo.shareScope || 'default';
250
- if (!localShareScopeMap[remoteShareScope]) {
251
- localShareScopeMap[remoteShareScope] = {};
252
- }
253
- const shareScope = localShareScopeMap[remoteShareScope];
254
- const initScope = [];
255
- const remoteEntryInitOptions = {
256
- version: this.remoteInfo.version || ''
257
- };
258
- // Help to find host instance
259
- Object.defineProperty(remoteEntryInitOptions, 'hostId', {
260
- value: this.host.options.id || this.host.name,
261
- // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
262
- enumerable: false
263
- });
264
- const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
265
- shareScope,
266
- // @ts-ignore hostId will be set by Object.defineProperty
267
- remoteEntryInitOptions,
268
- initScope,
269
- remoteInfo: this.remoteInfo,
270
- origin: this.host
271
- });
272
- await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
273
- await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
274
- remoteEntryExports
275
- }));
276
- }
277
- this.lib = remoteEntryExports;
278
- this.inited = true;
279
- // get exposeGetter
280
- const moduleFactory = await remoteEntryExports.get(expose);
281
- share.assert(moduleFactory, `${share.getFMId(this.remoteInfo)} remote don't export ${expose}.`);
282
- if (!loadFactory) {
283
- return moduleFactory;
284
- }
285
- const exposeContent = await moduleFactory();
286
- return exposeContent;
287
- }
288
- constructor({ remoteInfo, host }){
289
- this.inited = false;
290
- this.lib = undefined;
291
- this.remoteInfo = remoteInfo;
292
- this.host = host;
293
- }
294
- };
295
-
296
- class SyncHook {
297
- on(fn) {
298
- if (typeof fn === 'function') {
299
- this.listeners.add(fn);
300
- }
301
- }
302
- once(fn) {
303
- // eslint-disable-next-line @typescript-eslint/no-this-alias
304
- const self = this;
305
- this.on(function wrapper(...args) {
306
- self.remove(wrapper);
307
- // eslint-disable-next-line prefer-spread
308
- return fn.apply(null, args);
309
- });
310
- }
311
- emit(...data) {
312
- let result;
313
- if (this.listeners.size > 0) {
314
- // eslint-disable-next-line prefer-spread
315
- this.listeners.forEach((fn)=>{
316
- result = fn(...data);
317
- });
318
- }
319
- return result;
320
- }
321
- remove(fn) {
322
- this.listeners.delete(fn);
323
- }
324
- removeAll() {
325
- this.listeners.clear();
326
- }
327
- constructor(type){
328
- this.type = '';
329
- this.listeners = new Set();
330
- if (type) {
331
- this.type = type;
332
- }
333
- }
334
- }
335
-
336
- class AsyncHook extends SyncHook {
337
- emit(...data) {
338
- let result;
339
- const ls = Array.from(this.listeners);
340
- if (ls.length > 0) {
341
- let i = 0;
342
- const call = (prev)=>{
343
- if (prev === false) {
344
- return false; // Abort process
345
- } else if (i < ls.length) {
346
- return Promise.resolve(ls[i++].apply(null, data)).then(call);
347
- } else {
348
- return prev;
349
- }
350
- };
351
- result = call();
352
- }
353
- return Promise.resolve(result);
354
- }
355
- }
356
-
357
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
358
- function checkReturnData(originalData, returnedData) {
359
- if (!share.isObject(returnedData)) {
360
- return false;
361
- }
362
- if (originalData !== returnedData) {
363
- // eslint-disable-next-line no-restricted-syntax
364
- for(const key in originalData){
365
- if (!(key in returnedData)) {
366
- return false;
367
- }
368
- }
369
- }
370
- return true;
371
- }
372
- class SyncWaterfallHook extends SyncHook {
373
- emit(data) {
374
- if (!share.isObject(data)) {
375
- share.error(`The data for the "${this.type}" hook should be an object.`);
376
- }
377
- for (const fn of this.listeners){
378
- try {
379
- const tempData = fn(data);
380
- if (checkReturnData(data, tempData)) {
381
- data = tempData;
382
- } else {
383
- this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
384
- break;
385
- }
386
- } catch (e) {
387
- share.warn(e);
388
- this.onerror(e);
389
- }
390
- }
391
- return data;
392
- }
393
- constructor(type){
394
- super();
395
- this.onerror = share.error;
396
- this.type = type;
397
- }
398
- }
399
-
400
- class AsyncWaterfallHook extends SyncHook {
401
- emit(data) {
402
- if (!share.isObject(data)) {
403
- share.error(`The response data for the "${this.type}" hook must be an object.`);
404
- }
405
- const ls = Array.from(this.listeners);
406
- if (ls.length > 0) {
407
- let i = 0;
408
- const processError = (e)=>{
409
- share.warn(e);
410
- this.onerror(e);
411
- return data;
412
- };
413
- const call = (prevData)=>{
414
- if (checkReturnData(data, prevData)) {
415
- data = prevData;
416
- if (i < ls.length) {
417
- try {
418
- return Promise.resolve(ls[i++](data)).then(call, processError);
419
- } catch (e) {
420
- return processError(e);
421
- }
422
- }
423
- } else {
424
- this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
425
- }
426
- return data;
427
- };
428
- return Promise.resolve(call(data));
429
- }
430
- return Promise.resolve(data);
431
- }
432
- constructor(type){
433
- super();
434
- this.onerror = share.error;
435
- this.type = type;
436
- }
437
- }
438
-
439
- class PluginSystem {
440
- applyPlugin(plugin) {
441
- share.assert(share.isPlainObject(plugin), 'Plugin configuration is invalid.');
442
- // The plugin's name is mandatory and must be unique
443
- const pluginName = plugin.name;
444
- share.assert(pluginName, 'A name must be provided by the plugin.');
445
- if (!this.registerPlugins[pluginName]) {
446
- this.registerPlugins[pluginName] = plugin;
447
- Object.keys(this.lifecycle).forEach((key)=>{
448
- const pluginLife = plugin[key];
449
- if (pluginLife) {
450
- this.lifecycle[key].on(pluginLife);
451
- }
452
- });
453
- }
454
- }
455
- removePlugin(pluginName) {
456
- share.assert(pluginName, 'A name is required.');
457
- const plugin = this.registerPlugins[pluginName];
458
- share.assert(plugin, `The plugin "${pluginName}" is not registered.`);
459
- Object.keys(plugin).forEach((key)=>{
460
- if (key !== 'name') {
461
- this.lifecycle[key].remove(plugin[key]);
462
- }
463
- });
464
- }
465
- // eslint-disable-next-line @typescript-eslint/no-shadow
466
- inherit({ lifecycle, registerPlugins }) {
467
- Object.keys(lifecycle).forEach((hookName)=>{
468
- share.assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
469
- this.lifecycle[hookName] = lifecycle[hookName];
470
- });
471
- Object.keys(registerPlugins).forEach((pluginName)=>{
472
- share.assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
473
- this.applyPlugin(registerPlugins[pluginName]);
474
- });
475
- }
476
- constructor(lifecycle){
477
- this.registerPlugins = {};
478
- this.lifecycle = lifecycle;
479
- this.lifecycleKeys = Object.keys(lifecycle);
480
- }
481
- }
482
-
483
- function _extends$3() {
484
- _extends$3 = Object.assign || function(target) {
485
- for(var i = 1; i < arguments.length; i++){
486
- var source = arguments[i];
487
- for(var key in source){
488
- if (Object.prototype.hasOwnProperty.call(source, key)) {
489
- target[key] = source[key];
490
- }
491
- }
492
- }
493
- return target;
494
- };
495
- return _extends$3.apply(this, arguments);
496
- }
497
- function defaultPreloadArgs(preloadConfig) {
498
- return _extends$3({
499
- resourceCategory: 'sync',
500
- share: true,
501
- depsRemote: true,
502
- prefetchInterface: false
503
- }, preloadConfig);
504
- }
505
- function formatPreloadArgs(remotes, preloadArgs) {
506
- return preloadArgs.map((args)=>{
507
- const remoteInfo = matchRemote(remotes, args.nameOrAlias);
508
- share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && share.safeToString({
509
- remoteInfo,
510
- remotes
511
- })}`);
512
- return {
513
- remote: remoteInfo,
514
- preloadConfig: defaultPreloadArgs(args)
515
- };
516
- });
517
- }
518
- function normalizePreloadExposes(exposes) {
519
- if (!exposes) {
520
- return [];
521
- }
522
- return exposes.map((expose)=>{
523
- if (expose === '.') {
524
- return expose;
525
- }
526
- if (expose.startsWith('./')) {
527
- return expose.replace('./', '');
528
- }
529
- return expose;
530
- });
531
- }
532
- function preloadAssets(remoteInfo, host, assets) {
533
- const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
534
- if (host.options.inBrowser) {
535
- entryAssets.forEach((asset)=>{
536
- const { moduleInfo } = asset;
537
- const module = host.moduleCache.get(remoteInfo.name);
538
- if (module) {
539
- getRemoteEntry({
540
- remoteInfo: moduleInfo,
541
- remoteEntryExports: module.remoteEntryExports,
542
- createScriptHook: (url)=>{
543
- const res = host.loaderHook.lifecycle.createScript.emit({
544
- url
545
- });
546
- if (res instanceof HTMLScriptElement) {
547
- return res;
548
- }
549
- return;
550
- }
551
- });
552
- } else {
553
- getRemoteEntry({
554
- remoteInfo: moduleInfo,
555
- remoteEntryExports: undefined,
556
- createScriptHook: (url)=>{
557
- const res = host.loaderHook.lifecycle.createScript.emit({
558
- url
559
- });
560
- if (res instanceof HTMLScriptElement) {
561
- return res;
562
- }
563
- return;
564
- }
565
- });
566
- }
567
- });
568
- const fragment = document.createDocumentFragment();
569
- cssAssets.forEach((cssUrl)=>{
570
- const { link: cssEl, needAttach } = sdk.createLink(cssUrl, ()=>{}, {
571
- rel: 'preload',
572
- as: 'style'
573
- }, (url)=>{
574
- const res = host.loaderHook.lifecycle.createLink.emit({
575
- url
576
- });
577
- if (res instanceof HTMLLinkElement) {
578
- return res;
579
- }
580
- return;
581
- });
582
- needAttach && fragment.appendChild(cssEl);
583
- });
584
- jsAssetsWithoutEntry.forEach((jsUrl)=>{
585
- const { link: linkEl, needAttach } = sdk.createLink(jsUrl, ()=>{
586
- // noop
587
- }, {
588
- rel: 'preload',
589
- as: 'script'
590
- }, (url)=>{
591
- const res = host.loaderHook.lifecycle.createLink.emit({
592
- url
593
- });
594
- if (res instanceof HTMLLinkElement) {
595
- return res;
596
- }
597
- return;
598
- });
599
- needAttach && document.head.appendChild(linkEl);
600
- });
601
- document.head.appendChild(fragment);
602
- }
603
- }
604
-
605
- function _extends$2() {
606
- _extends$2 = Object.assign || function(target) {
607
- for(var i = 1; i < arguments.length; i++){
608
- var source = arguments[i];
609
- for(var key in source){
610
- if (Object.prototype.hasOwnProperty.call(source, key)) {
611
- target[key] = source[key];
612
- }
613
- }
614
- }
615
- return target;
616
- };
617
- return _extends$2.apply(this, arguments);
618
- }
619
- function assignRemoteInfo(remoteInfo, remoteSnapshot) {
620
- if (!('remoteEntry' in remoteSnapshot) || !remoteSnapshot.remoteEntry) {
621
- share.error(`The attribute remoteEntry of ${name} must not be undefined.`);
622
- }
623
- const { remoteEntry } = remoteSnapshot;
624
- const entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntry);
625
- remoteInfo.type = remoteSnapshot.remoteEntryType;
626
- remoteInfo.entryGlobalName = remoteSnapshot.globalName;
627
- remoteInfo.entry = entryUrl;
628
- remoteInfo.version = remoteSnapshot.version;
629
- remoteInfo.buildVersion = remoteSnapshot.buildVersion;
630
- }
631
- function snapshotPlugin() {
632
- return {
633
- name: 'snapshot-plugin',
634
- async afterResolve (args) {
635
- const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
636
- if (!share.isRemoteInfoWithEntry(remote) || !share.isPureRemoteEntry(remote)) {
637
- const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(remote);
638
- assignRemoteInfo(remoteInfo, remoteSnapshot);
639
- // preloading assets
640
- const preloadOptions = {
641
- remote,
642
- preloadConfig: {
643
- nameOrAlias: pkgNameOrAlias,
644
- exposes: [
645
- expose
646
- ],
647
- resourceCategory: 'sync',
648
- share: false,
649
- depsRemote: false
650
- }
651
- };
652
- const assets = await origin.hooks.lifecycle.generatePreloadAssets.emit({
653
- origin,
654
- preloadOptions,
655
- remoteInfo,
656
- remote,
657
- remoteSnapshot,
658
- globalSnapshot
659
- });
660
- if (assets) {
661
- preloadAssets(remoteInfo, origin, assets);
662
- }
663
- return _extends$2({}, args, {
664
- remoteSnapshot
665
- });
666
- }
667
- return args;
668
- }
669
- };
670
- }
671
-
672
- // name
673
- // name:version
674
- function splitId(id) {
675
- const splitInfo = id.split(':');
676
- if (splitInfo.length === 1) {
677
- return {
678
- name: splitInfo[0],
679
- version: undefined
680
- };
681
- } else if (splitInfo.length === 2) {
682
- return {
683
- name: splitInfo[0],
684
- version: splitInfo[1]
685
- };
686
- } else {
687
- return {
688
- name: splitInfo[1],
689
- version: splitInfo[2]
690
- };
691
- }
692
- }
693
- // Traverse all nodes in moduleInfo and traverse the entire snapshot
694
- function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
695
- const id = share.getFMId(remoteInfo);
696
- const { value: snapshotValue } = share.getInfoWithoutType(globalSnapshot, id);
697
- const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
698
- if (effectiveRemoteSnapshot && !sdk.isManifestProvider(effectiveRemoteSnapshot)) {
699
- traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
700
- if (effectiveRemoteSnapshot.remotesInfo) {
701
- const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
702
- for (const key of remoteKeys){
703
- if (memo[key]) {
704
- continue;
705
- }
706
- memo[key] = true;
707
- const subRemoteInfo = splitId(key);
708
- const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
709
- traverseModuleInfo(globalSnapshot, {
710
- name: subRemoteInfo.name,
711
- version: remoteValue.matchedVersion
712
- }, traverse, false, memo, undefined);
713
- }
714
- }
715
- }
716
- }
717
- // eslint-disable-next-line max-lines-per-function
718
- function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
719
- const cssAssets = [];
720
- const jsAssets = [];
721
- const entryAssets = [];
722
- const loadedSharedJsAssets = new Set();
723
- const loadedSharedCssAssets = new Set();
724
- const { options } = origin;
725
- const { preloadConfig: rootPreloadConfig } = preloadOptions;
726
- const { depsRemote } = rootPreloadConfig;
727
- const memo = {};
728
- traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot)=>{
729
- let preloadConfig;
730
- if (isRoot) {
731
- preloadConfig = rootPreloadConfig;
732
- } else {
733
- if (Array.isArray(depsRemote)) {
734
- // eslint-disable-next-line array-callback-return
735
- const findPreloadConfig = depsRemote.find((remoteConfig)=>{
736
- if (remoteConfig.nameOrAlias === remoteInfo.name || remoteConfig.nameOrAlias === remoteInfo.alias) {
737
- return true;
738
- }
739
- return false;
740
- });
741
- if (!findPreloadConfig) {
742
- return;
743
- }
744
- preloadConfig = defaultPreloadArgs(findPreloadConfig);
745
- } else if (depsRemote === true) {
746
- preloadConfig = rootPreloadConfig;
747
- } else {
748
- return;
749
- }
750
- }
751
- const remoteEntryUrl = sdk.getResourceUrl(moduleInfoSnapshot, 'remoteEntry' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntry : '');
752
- if (remoteEntryUrl) {
753
- entryAssets.push({
754
- name: remoteInfo.name,
755
- moduleInfo: {
756
- name: remoteInfo.name,
757
- entry: remoteEntryUrl,
758
- type: 'remoteEntryType' in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntryType : 'global',
759
- entryGlobalName: 'globalName' in moduleInfoSnapshot ? moduleInfoSnapshot.globalName : remoteInfo.name,
760
- shareScope: '',
761
- version: 'version' in moduleInfoSnapshot ? moduleInfoSnapshot.version : undefined
762
- },
763
- url: remoteEntryUrl
764
- });
765
- }
766
- let moduleAssetsInfo = 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
767
- const normalizedPreloadExposes = normalizePreloadExposes(preloadConfig.exposes);
768
- if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {
769
- var _moduleInfoSnapshot_modules;
770
- moduleAssetsInfo = moduleInfoSnapshot == null ? void 0 : (_moduleInfoSnapshot_modules = moduleInfoSnapshot.modules) == null ? void 0 : _moduleInfoSnapshot_modules.reduce((assets, moduleAssetInfo)=>{
771
- if ((normalizedPreloadExposes == null ? void 0 : normalizedPreloadExposes.indexOf(moduleAssetInfo.moduleName)) !== -1) {
772
- assets.push(moduleAssetInfo);
773
- }
774
- return assets;
775
- }, []);
776
- }
777
- function handleAssets(assets) {
778
- const assetsRes = assets.map((asset)=>sdk.getResourceUrl(moduleInfoSnapshot, asset));
779
- if (preloadConfig.filter) {
780
- return assetsRes.filter(preloadConfig.filter);
781
- }
782
- return assetsRes;
783
- }
784
- if (moduleAssetsInfo) {
785
- const assetsLength = moduleAssetsInfo.length;
786
- for(let index = 0; index < assetsLength; index++){
787
- const assetsInfo = moduleAssetsInfo[index];
788
- const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
789
- origin.hooks.lifecycle.handlePreloadModule.emit({
790
- id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
791
- name: remoteInfo.name,
792
- remoteSnapshot: moduleInfoSnapshot,
793
- preloadConfig,
794
- remote: remoteInfo,
795
- origin
796
- });
797
- const preloaded = share.getPreloaded(exposeFullPath);
798
- if (preloaded) {
799
- continue;
800
- }
801
- if (preloadConfig.resourceCategory === 'all') {
802
- cssAssets.push(...handleAssets(assetsInfo.assets.css.async));
803
- cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
804
- jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
805
- jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
806
- // eslint-disable-next-line no-constant-condition
807
- } else if (preloadConfig.resourceCategory = 'sync') {
808
- cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
809
- jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
810
- }
811
- share.setPreloaded(exposeFullPath);
812
- }
813
- }
814
- }, true, memo, remoteSnapshot);
815
- if (remoteSnapshot.shared) {
816
- remoteSnapshot.shared.forEach((shared)=>{
817
- var _options_shared;
818
- const shareInfo = (_options_shared = options.shared) == null ? void 0 : _options_shared[shared.sharedName];
819
- // When data is downgraded, the shared configuration may be different.
820
- if (!shareInfo) {
821
- return;
822
- }
823
- const registeredShared = share.getRegisteredShare(origin.shareScopeMap, shared.sharedName, shareInfo, origin.hooks.lifecycle.resolveShare);
824
- // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.
825
- if (registeredShared && typeof registeredShared.lib === 'function') {
826
- shared.assets.js.sync.forEach((asset)=>{
827
- loadedSharedJsAssets.add(asset);
828
- });
829
- shared.assets.css.sync.forEach((asset)=>{
830
- loadedSharedCssAssets.add(asset);
831
- });
832
- }
833
- });
834
- }
835
- const needPreloadJsAssets = jsAssets.filter((asset)=>!loadedSharedJsAssets.has(asset));
836
- const needPreloadCssAssets = cssAssets.filter((asset)=>!loadedSharedCssAssets.has(asset));
837
- return {
838
- cssAssets: needPreloadCssAssets,
839
- jsAssetsWithoutEntry: needPreloadJsAssets,
840
- entryAssets
841
- };
842
- }
843
- const generatePreloadAssetsPlugin = function() {
844
- return {
845
- name: 'generate-preload-assets-plugin',
846
- async generatePreloadAssets (args) {
847
- const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
848
- if (share.isRemoteInfoWithEntry(remote) && share.isPureRemoteEntry(remote)) {
849
- return {
850
- cssAssets: [],
851
- jsAssetsWithoutEntry: [],
852
- entryAssets: [
853
- {
854
- name: remote.name,
855
- url: remote.entry,
856
- moduleInfo: {
857
- name: remoteInfo.name,
858
- entry: remote.entry,
859
- type: 'global',
860
- entryGlobalName: '',
861
- shareScope: ''
862
- }
863
- }
864
- ]
865
- };
866
- }
867
- assignRemoteInfo(remoteInfo, remoteSnapshot);
868
- const assets = generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
869
- return assets;
870
- }
871
- };
872
- };
873
-
874
- function _extends$1() {
875
- _extends$1 = Object.assign || function(target) {
876
- for(var i = 1; i < arguments.length; i++){
877
- var source = arguments[i];
878
- for(var key in source){
879
- if (Object.prototype.hasOwnProperty.call(source, key)) {
880
- target[key] = source[key];
881
- }
882
- }
883
- }
884
- return target;
885
- };
886
- return _extends$1.apply(this, arguments);
887
- }
888
- class SnapshotHandler {
889
- async loadSnapshot(moduleInfo) {
890
- const { options } = this.HostInstance;
891
- const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
892
- const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
893
- options,
894
- moduleInfo,
895
- hostGlobalSnapshot,
896
- remoteSnapshot,
897
- globalSnapshot
898
- });
899
- return {
900
- remoteSnapshot: globalRemoteSnapshot,
901
- globalSnapshot: globalSnapshotRes
902
- };
903
- }
904
- // eslint-disable-next-line max-lines-per-function
905
- async loadRemoteSnapshotInfo(moduleInfo) {
906
- const { options } = this.HostInstance;
907
- await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
908
- options,
909
- moduleInfo
910
- });
911
- let hostSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
912
- name: this.HostInstance.options.name,
913
- version: this.HostInstance.options.version
914
- });
915
- if (!hostSnapshot) {
916
- hostSnapshot = {
917
- version: this.HostInstance.options.version || '',
918
- remoteEntry: '',
919
- remotesInfo: {}
920
- };
921
- share.addGlobalSnapshot({
922
- [this.HostInstance.options.name]: hostSnapshot
923
- });
924
- }
925
- // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.
926
- // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.
927
- if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
928
- if ('version' in moduleInfo || 'entry' in moduleInfo) {
929
- hostSnapshot.remotesInfo = _extends$1({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
930
- [moduleInfo.name]: {
931
- matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
932
- }
933
- });
934
- }
935
- }
936
- const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
937
- const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
938
- options,
939
- moduleInfo,
940
- hostGlobalSnapshot,
941
- remoteSnapshot,
942
- globalSnapshot
943
- });
944
- // global snapshot includes manifest or module info includes manifest
945
- if (globalRemoteSnapshot) {
946
- if (sdk.isManifestProvider(globalRemoteSnapshot)) {
947
- const moduleSnapshot = await this.getManifestJson(globalRemoteSnapshot.remoteEntry, moduleInfo, {});
948
- // eslint-disable-next-line @typescript-eslint/no-shadow
949
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$1({}, moduleInfo, {
950
- // The global remote may be overridden
951
- // Therefore, set the snapshot key to the global address of the actual request
952
- entry: globalRemoteSnapshot.remoteEntry
953
- }), moduleSnapshot);
954
- return {
955
- remoteSnapshot: moduleSnapshot,
956
- globalSnapshot: globalSnapshotRes
957
- };
958
- } else {
959
- const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
960
- options: this.HostInstance.options,
961
- moduleInfo,
962
- remoteSnapshot: globalRemoteSnapshot,
963
- from: 'global'
964
- });
965
- return {
966
- remoteSnapshot: remoteSnapshotRes,
967
- globalSnapshot: globalSnapshotRes
968
- };
969
- }
970
- } else {
971
- if (share.isRemoteInfoWithEntry(moduleInfo)) {
972
- // get from manifest.json and merge remote info from remote server
973
- const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
974
- // eslint-disable-next-line @typescript-eslint/no-shadow
975
- const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
976
- const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
977
- options: this.HostInstance.options,
978
- moduleInfo,
979
- remoteSnapshot: moduleSnapshot,
980
- from: 'global'
981
- });
982
- return {
983
- remoteSnapshot: remoteSnapshotRes,
984
- globalSnapshot: globalSnapshotRes
985
- };
986
- } else {
987
- share.error(`
988
- Cannot get remoteSnapshot with the name: '${moduleInfo.name}', version: '${moduleInfo.version}' from __FEDERATION__.moduleInfo. The following reasons may be causing the problem:\n
989
- 1. The Deploy platform did not deliver the correct data. You can use __FEDERATION__.moduleInfo to check the remoteInfo.\n
990
- 2. The remote '${moduleInfo.name}' version '${moduleInfo.version}' is not released.\n
991
- The transformed module info: ${JSON.stringify(globalSnapshotRes)}
992
- `);
993
- }
994
- }
995
- }
996
- getGlobalRemoteInfo(moduleInfo) {
997
- const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
998
- name: this.HostInstance.options.name,
999
- version: this.HostInstance.options.version
1000
- });
1001
- // get remote detail info from global
1002
- const globalRemoteInfo = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;
1003
- if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {
1004
- return {
1005
- hostGlobalSnapshot,
1006
- globalSnapshot: share.getGlobalSnapshot(),
1007
- remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1008
- name: moduleInfo.name,
1009
- version: globalRemoteInfo.matchedVersion
1010
- })
1011
- };
1012
- }
1013
- return {
1014
- hostGlobalSnapshot: undefined,
1015
- globalSnapshot: share.getGlobalSnapshot(),
1016
- remoteSnapshot: share.getGlobalSnapshotInfoByModuleInfo({
1017
- name: moduleInfo.name,
1018
- version: 'version' in moduleInfo ? moduleInfo.version : undefined
1019
- })
1020
- };
1021
- }
1022
- async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
1023
- const getManifest = async ()=>{
1024
- let manifestJson = this.manifestCache.get(manifestUrl);
1025
- if (manifestJson) {
1026
- return manifestJson;
1027
- }
1028
- try {
1029
- let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {});
1030
- if (!res || !(res instanceof Response)) {
1031
- res = await fetch(manifestUrl, {});
1032
- }
1033
- manifestJson = await res.json();
1034
- share.assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `${manifestUrl} is not a federation manifest`);
1035
- this.manifestCache.set(manifestUrl, manifestJson);
1036
- return manifestJson;
1037
- } catch (err) {
1038
- share.error(`Failed to get manifestJson for ${moduleInfo.name}. The manifest URL is ${manifestUrl}. Please ensure that the manifestUrl is accessible.
1039
- \n Error message:
1040
- \n ${err}`);
1041
- }
1042
- };
1043
- const asyncLoadProcess = async ()=>{
1044
- const manifestJson = await getManifest();
1045
- const remoteSnapshot = sdk.generateSnapshotFromManifest(manifestJson, {
1046
- version: manifestUrl
1047
- });
1048
- const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
1049
- options: this.HostInstance.options,
1050
- moduleInfo,
1051
- manifestJson,
1052
- remoteSnapshot,
1053
- manifestUrl,
1054
- from: 'manifest'
1055
- });
1056
- return remoteSnapshotRes;
1057
- };
1058
- if (!this.manifestLoading[manifestUrl]) {
1059
- this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res)=>res);
1060
- }
1061
- return this.manifestLoading[manifestUrl];
1062
- }
1063
- constructor(HostInstance){
1064
- this.loadingHostSnapshot = null;
1065
- this.manifestCache = new Map();
1066
- this.hooks = new PluginSystem({
1067
- beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
1068
- loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
1069
- loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot')
1070
- });
1071
- this.manifestLoading = share.Global.__FEDERATION__.__MANIFEST_LOADING__;
1072
- this.HostInstance = HostInstance;
1073
- this.loaderHook = HostInstance.loaderHook;
1074
- }
1075
- }
1076
-
1077
- function _extends() {
1078
- _extends = Object.assign || function(target) {
1079
- for(var i = 1; i < arguments.length; i++){
1080
- var source = arguments[i];
1081
- for(var key in source){
1082
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1083
- target[key] = source[key];
1084
- }
1085
- }
1086
- }
1087
- return target;
1088
- };
1089
- return _extends.apply(this, arguments);
1090
- }
1091
- function _object_without_properties_loose(source, excluded) {
1092
- if (source == null) return {};
1093
- var target = {};
1094
- var sourceKeys = Object.keys(source);
1095
- var key, i;
1096
- for(i = 0; i < sourceKeys.length; i++){
1097
- key = sourceKeys[i];
1098
- if (excluded.indexOf(key) >= 0) continue;
1099
- target[key] = source[key];
1100
- }
1101
- return target;
1102
- }
1103
- class FederationHost {
1104
- _setGlobalShareScopeMap() {
1105
- const globalShareScopeMap = share.getGlobalShareScope();
1106
- const identifier = this.options.id || this.options.name;
1107
- if (identifier && !globalShareScopeMap[identifier]) {
1108
- globalShareScopeMap[identifier] = this.shareScopeMap;
1109
- }
1110
- }
1111
- initOptions(userOptions) {
1112
- this.registerPlugins(userOptions.plugins);
1113
- const options = this.formatOptions(this.options, userOptions);
1114
- this.options = options;
1115
- return options;
1116
- }
1117
- async loadShare(pkgName, customShareInfo) {
1118
- var _this_options_shared;
1119
- // This function performs the following steps:
1120
- // 1. Checks if the currently loaded share already exists, if not, it throws an error
1121
- // 2. Searches globally for a matching share, if found, it uses it directly
1122
- // 3. If not found, it retrieves it from the current share and stores the obtained share globally.
1123
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1124
- if (shareInfo == null ? void 0 : shareInfo.scope) {
1125
- await Promise.all(shareInfo.scope.map(async (shareScope)=>{
1126
- await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
1127
- return;
1128
- }));
1129
- }
1130
- const loadShareRes = await this.hooks.lifecycle.beforeLoadShare.emit({
1131
- pkgName,
1132
- shareInfo,
1133
- shared: this.options.shared,
1134
- origin: this
1135
- });
1136
- const { shareInfo: shareInfoRes } = loadShareRes;
1137
- // Assert that shareInfoRes exists, if not, throw an error
1138
- share.assert(shareInfoRes, `Cannot find ${pkgName} Share in the ${this.options.name}. Please ensure that the ${pkgName} Share parameters have been injected`);
1139
- // Retrieve from cache
1140
- const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1141
- const addUseIn = (shared)=>{
1142
- if (!shared.useIn) {
1143
- shared.useIn = [];
1144
- }
1145
- share.addUniqueItem(shared.useIn, this.options.name);
1146
- };
1147
- if (registeredShared && registeredShared.lib) {
1148
- addUseIn(registeredShared);
1149
- return registeredShared.lib;
1150
- } else if (registeredShared && registeredShared.loading && !registeredShared.loaded) {
1151
- const factory = await registeredShared.loading;
1152
- registeredShared.loaded = true;
1153
- if (!registeredShared.lib) {
1154
- registeredShared.lib = factory;
1155
- }
1156
- addUseIn(registeredShared);
1157
- return factory;
1158
- } else if (registeredShared) {
1159
- const asyncLoadProcess = async ()=>{
1160
- const factory = await registeredShared.get();
1161
- shareInfoRes.lib = factory;
1162
- shareInfoRes.loaded = true;
1163
- addUseIn(shareInfoRes);
1164
- const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1165
- if (gShared) {
1166
- gShared.lib = factory;
1167
- gShared.loaded = true;
1168
- }
1169
- return factory;
1170
- };
1171
- const loading = asyncLoadProcess();
1172
- this.setShared({
1173
- pkgName,
1174
- loaded: false,
1175
- shared: registeredShared,
1176
- from: this.options.name,
1177
- lib: null,
1178
- loading
1179
- });
1180
- return loading;
1181
- } else {
1182
- if (customShareInfo) {
1183
- return false;
1184
- }
1185
- const asyncLoadProcess = async ()=>{
1186
- const factory = await shareInfoRes.get();
1187
- shareInfoRes.lib = factory;
1188
- shareInfoRes.loaded = true;
1189
- addUseIn(shareInfoRes);
1190
- const gShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfoRes, this.hooks.lifecycle.resolveShare);
1191
- if (gShared) {
1192
- gShared.lib = factory;
1193
- gShared.loaded = true;
1194
- }
1195
- return factory;
1196
- };
1197
- const loading = asyncLoadProcess();
1198
- this.setShared({
1199
- pkgName,
1200
- loaded: false,
1201
- shared: shareInfoRes,
1202
- from: this.options.name,
1203
- lib: null,
1204
- loading
1205
- });
1206
- return loading;
1207
- }
1208
- }
1209
- // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.
1210
- // 1. If the loaded shared already exists globally, then it will be reused
1211
- // 2. If lib exists in local shared, it will be used directly
1212
- // 3. If the local get returns something other than Promise, then it will be used directly
1213
- loadShareSync(pkgName, customShareInfo) {
1214
- var _this_options_shared;
1215
- const shareInfo = Object.assign({}, (_this_options_shared = this.options.shared) == null ? void 0 : _this_options_shared[pkgName], customShareInfo);
1216
- if (shareInfo == null ? void 0 : shareInfo.scope) {
1217
- shareInfo.scope.forEach((shareScope)=>{
1218
- this.initializeSharing(shareScope, shareInfo.strategy);
1219
- });
1220
- }
1221
- const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
1222
- const addUseIn = (shared)=>{
1223
- if (!shared.useIn) {
1224
- shared.useIn = [];
1225
- }
1226
- share.addUniqueItem(shared.useIn, this.options.name);
1227
- };
1228
- if (registeredShared) {
1229
- if (typeof registeredShared.lib === 'function') {
1230
- addUseIn(registeredShared);
1231
- if (!registeredShared.loaded) {
1232
- registeredShared.loaded = true;
1233
- if (registeredShared.from === this.options.name) {
1234
- shareInfo.loaded = true;
1235
- }
1236
- }
1237
- return registeredShared.lib;
1238
- }
1239
- if (typeof registeredShared.get === 'function') {
1240
- const module = registeredShared.get();
1241
- if (!(module instanceof Promise)) {
1242
- addUseIn(registeredShared);
1243
- this.setShared({
1244
- pkgName,
1245
- loaded: true,
1246
- from: this.options.name,
1247
- lib: module,
1248
- shared: registeredShared
1249
- });
1250
- return module;
1251
- }
1252
- }
1253
- }
1254
- if (shareInfo.lib) {
1255
- if (!shareInfo.loaded) {
1256
- shareInfo.loaded = true;
1257
- }
1258
- return shareInfo.lib;
1259
- }
1260
- if (shareInfo.get) {
1261
- const module = shareInfo.get();
1262
- if (module instanceof Promise) {
1263
- throw new Error(`
1264
- The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${this.options.name}.
1265
- Possible reasons for failure: \n
1266
- 1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
1267
- 2. The ${pkgName} share was not registered with the 'lib' attribute.\n
1268
- `);
1269
- }
1270
- shareInfo.lib = module;
1271
- this.setShared({
1272
- pkgName,
1273
- loaded: true,
1274
- from: this.options.name,
1275
- lib: shareInfo.lib,
1276
- shared: shareInfo
1277
- });
1278
- return shareInfo.lib;
1279
- }
1280
- throw new Error(`
1281
- The loadShareSync function was unable to load ${pkgName}. The ${pkgName} could not be found in ${this.options.name}.
1282
- Possible reasons for failure: \n
1283
- 1. The ${pkgName} share was registered with the 'get' attribute, but loadShare was not used beforehand.\n
1284
- 2. The ${pkgName} share was not registered with the 'lib' attribute.\n
1285
- `);
1286
- }
1287
- initRawContainer(name, url, container) {
1288
- const remoteInfo = getRemoteInfo({
1289
- name,
1290
- entry: url
1291
- });
1292
- const module = new Module({
1293
- host: this,
1294
- remoteInfo
1295
- });
1296
- module.remoteEntryExports = container;
1297
- this.moduleCache.set(name, module);
1298
- return module;
1299
- }
1300
- async _getRemoteModuleAndOptions(id) {
1301
- const loadRemoteArgs = await this.hooks.lifecycle.beforeRequest.emit({
1302
- id,
1303
- options: this.options,
1304
- origin: this
1305
- });
1306
- const { id: idRes } = loadRemoteArgs;
1307
- const remoteSplitInfo = matchRemoteWithNameAndExpose(this.options.remotes, idRes);
1308
- share.assert(remoteSplitInfo, `
1309
- Unable to locate ${idRes} in ${this.options.name}. Potential reasons for failure include:\n
1310
- 1. ${idRes} was not included in the 'remotes' parameter of ${this.options.name || 'the host'}.\n
1311
- 2. ${idRes} could not be found in the 'remotes' of ${this.options.name} with either 'name' or 'alias' attributes.
1312
- 3. ${idRes} is not online, injected, or loaded.
1313
- 4. ${idRes} cannot be accessed on the expected.
1314
- 5. The 'beforeRequest' hook was provided but did not return the correct 'remoteInfo' when attempting to load ${idRes}.
1315
- `);
1316
- const { remote: rawRemote } = remoteSplitInfo;
1317
- const remoteInfo = getRemoteInfo(rawRemote);
1318
- const matchInfo = await this.hooks.lifecycle.afterResolve.emit(_extends({
1319
- id: idRes
1320
- }, remoteSplitInfo, {
1321
- options: this.options,
1322
- origin: this,
1323
- remoteInfo
1324
- }));
1325
- const { remote, expose } = matchInfo;
1326
- share.assert(remote && expose, `The 'beforeRequest' hook was executed, but it failed to return the correct 'remote' and 'expose' values while loading ${idRes}.`);
1327
- let module = this.moduleCache.get(remote.name);
1328
- const moduleOptions = {
1329
- host: this,
1330
- remoteInfo
1331
- };
1332
- if (!module) {
1333
- module = new Module(moduleOptions);
1334
- this.moduleCache.set(remote.name, module);
1335
- }
1336
- return {
1337
- module,
1338
- moduleOptions,
1339
- remoteMatchInfo: matchInfo
1340
- };
1341
- }
1342
- // eslint-disable-next-line max-lines-per-function
1343
- // eslint-disable-next-line @typescript-eslint/member-ordering
1344
- async loadRemote(id, options) {
1345
- try {
1346
- const { loadFactory = true } = options || {
1347
- loadFactory: true
1348
- };
1349
- // 1. Validate the parameters of the retrieved module. There are two module request methods: pkgName + expose and alias + expose.
1350
- // 2. Request the snapshot information of the current host and globally store the obtained snapshot information. The retrieved module information is partially offline and partially online. The online module information will retrieve the modules used online.
1351
- // 3. Retrieve the detailed information of the current module from global (remoteEntry address, expose resource address)
1352
- // 4. After retrieving remoteEntry, call the init of the module, and then retrieve the exported content of the module through get
1353
- // id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
1354
- // id: alias(app1) + expose(button) = app1/button
1355
- // id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort
1356
- const { module, moduleOptions, remoteMatchInfo } = await this._getRemoteModuleAndOptions(id);
1357
- const { pkgNameOrAlias, remote, expose, id: idRes } = remoteMatchInfo;
1358
- const moduleOrFactory = await module.get(expose, options);
1359
- const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
1360
- id: idRes,
1361
- pkgNameOrAlias,
1362
- expose,
1363
- exposeModule: loadFactory ? moduleOrFactory : undefined,
1364
- exposeModuleFactory: loadFactory ? undefined : moduleOrFactory,
1365
- remote,
1366
- options: moduleOptions,
1367
- moduleInstance: module,
1368
- origin: this
1369
- });
1370
- if (typeof moduleWrapper === 'function') {
1371
- return moduleWrapper;
1372
- }
1373
- return moduleOrFactory;
1374
- } catch (error) {
1375
- const { from = 'runtime' } = options || {
1376
- from: 'runtime'
1377
- };
1378
- const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
1379
- id,
1380
- error,
1381
- from,
1382
- origin: this
1383
- });
1384
- if (!failOver) {
1385
- throw error;
1386
- }
1387
- return failOver;
1388
- }
1389
- }
1390
- // eslint-disable-next-line @typescript-eslint/member-ordering
1391
- async preloadRemote(preloadOptions) {
1392
- await this.hooks.lifecycle.beforePreloadRemote.emit({
1393
- preloadOptions,
1394
- options: this.options,
1395
- origin: this
1396
- });
1397
- const preloadOps = formatPreloadArgs(this.options.remotes, preloadOptions);
1398
- await Promise.all(preloadOps.map(async (ops)=>{
1399
- const { remote } = ops;
1400
- const remoteInfo = getRemoteInfo(remote);
1401
- const { globalSnapshot, remoteSnapshot } = await this.snapshotHandler.loadRemoteSnapshotInfo(remote);
1402
- const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
1403
- origin: this,
1404
- preloadOptions: ops,
1405
- remote,
1406
- remoteInfo,
1407
- globalSnapshot,
1408
- remoteSnapshot
1409
- });
1410
- if (!assets) {
1411
- return;
1412
- }
1413
- preloadAssets(remoteInfo, this, assets);
1414
- }));
1415
- }
1416
- /**
1417
- * This function initializes the sharing sequence (executed only once per share scope).
1418
- * It accepts one argument, the name of the share scope.
1419
- * If the share scope does not exist, it creates one.
1420
- */ // eslint-disable-next-line @typescript-eslint/member-ordering
1421
- initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
1422
- const shareScope = this.shareScopeMap;
1423
- const hostName = this.options.name;
1424
- // Creates a new share scope if necessary
1425
- if (!shareScope[shareScopeName]) {
1426
- shareScope[shareScopeName] = {};
1427
- }
1428
- // Executes all initialization snippets from all accessible modules
1429
- const scope = shareScope[shareScopeName];
1430
- const register = (name, shared)=>{
1431
- var _activeVersion_shareConfig;
1432
- const { version, eager } = shared;
1433
- scope[name] = scope[name] || {};
1434
- const versions = scope[name];
1435
- const activeVersion = versions[version];
1436
- const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
1437
- if (!activeVersion || activeVersion.strategy !== 'loaded-first' && !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
1438
- versions[version] = shared;
1439
- }
1440
- };
1441
- const promises = [];
1442
- const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
1443
- const initRemoteModule = async (key)=>{
1444
- const { module } = await this._getRemoteModuleAndOptions(key);
1445
- if (module.getEntry) {
1446
- const entry = await module.getEntry();
1447
- if (!module.inited) {
1448
- initFn(entry);
1449
- module.inited = true;
1450
- }
1451
- }
1452
- };
1453
- Object.keys(this.options.shared).forEach((shareName)=>{
1454
- const shared = this.options.shared[shareName];
1455
- if (shared.scope.includes(shareScopeName)) {
1456
- register(shareName, shared);
1457
- }
1458
- });
1459
- if (strategy === 'version-first') {
1460
- this.options.remotes.forEach((remote)=>{
1461
- if (remote.shareScope === shareScopeName) {
1462
- promises.push(initRemoteModule(remote.name));
1463
- }
1464
- });
1465
- }
1466
- return promises;
1467
- }
1468
- initShareScopeMap(scopeName, shareScope) {
1469
- this.shareScopeMap[scopeName] = shareScope;
1470
- this.hooks.lifecycle.initContainerShareScopeMap.emit({
1471
- shareScope,
1472
- options: this.options,
1473
- origin: this
1474
- });
1475
- }
1476
- formatOptions(globalOptions, userOptions) {
1477
- const formatShareOptions = share.formatShareConfigs(userOptions.shared || {}, userOptions.name);
1478
- const shared = _extends({}, globalOptions.shared, formatShareOptions);
1479
- const { userOptions: userOptionsRes, options: globalOptionsRes } = this.hooks.lifecycle.beforeInit.emit({
1480
- origin: this,
1481
- userOptions,
1482
- options: globalOptions,
1483
- shareInfo: shared
1484
- });
1485
- const userRemotes = userOptionsRes.remotes || [];
1486
- const remotes = userRemotes.reduce((res, remote)=>{
1487
- this.registerRemote(remote, res, {
1488
- force: false
1489
- });
1490
- return res;
1491
- }, globalOptionsRes.remotes);
1492
- // register shared in shareScopeMap
1493
- const sharedKeys = Object.keys(formatShareOptions);
1494
- sharedKeys.forEach((sharedKey)=>{
1495
- const sharedVal = formatShareOptions[sharedKey];
1496
- const registeredShared = share.getRegisteredShare(this.shareScopeMap, sharedKey, sharedVal, this.hooks.lifecycle.resolveShare);
1497
- if (!registeredShared && sharedVal && sharedVal.lib) {
1498
- this.setShared({
1499
- pkgName: sharedKey,
1500
- lib: sharedVal.lib,
1501
- get: sharedVal.get,
1502
- loaded: true,
1503
- shared: sharedVal,
1504
- from: userOptions.name
1505
- });
1506
- }
1507
- });
1508
- const plugins = [
1509
- ...globalOptionsRes.plugins
1510
- ];
1511
- if (userOptionsRes.plugins) {
1512
- userOptionsRes.plugins.forEach((plugin)=>{
1513
- if (!plugins.includes(plugin)) {
1514
- plugins.push(plugin);
1515
- }
1516
- });
1517
- }
1518
- const optionsRes = _extends({}, globalOptions, userOptions, {
1519
- plugins,
1520
- remotes,
1521
- shared
1522
- });
1523
- this.hooks.lifecycle.init.emit({
1524
- origin: this,
1525
- options: optionsRes
1526
- });
1527
- return optionsRes;
1528
- }
1529
- registerPlugins(plugins) {
1530
- registerPlugins$1(plugins, [
1531
- this.hooks,
1532
- this.snapshotHandler.hooks,
1533
- this.loaderHook
1534
- ]);
1535
- }
1536
- setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
1537
- const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
1538
- "version",
1539
- "scope"
1540
- ]);
1541
- const scopes = Array.isArray(scope) ? scope : [
1542
- scope
1543
- ];
1544
- scopes.forEach((sc)=>{
1545
- if (!this.shareScopeMap[sc]) {
1546
- this.shareScopeMap[sc] = {};
1547
- }
1548
- if (!this.shareScopeMap[sc][pkgName]) {
1549
- this.shareScopeMap[sc][pkgName] = {};
1550
- }
1551
- if (this.shareScopeMap[sc][pkgName][version]) {
1552
- return;
1553
- }
1554
- this.shareScopeMap[sc][pkgName][version] = _extends({
1555
- version,
1556
- scope: [
1557
- 'default'
1558
- ]
1559
- }, shareInfo, {
1560
- lib,
1561
- loaded,
1562
- loading
1563
- });
1564
- if (get) {
1565
- this.shareScopeMap[sc][pkgName][version].get = get;
1566
- }
1567
- });
1568
- }
1569
- removeRemote(remote) {
1570
- const { name } = remote;
1571
- const remoteIndex = this.options.remotes.findIndex((item)=>item.name === name);
1572
- if (remoteIndex !== -1) {
1573
- this.options.remotes.splice(remoteIndex, 1);
1574
- }
1575
- const loadedModule = this.moduleCache.get(remote.name);
1576
- if (loadedModule) {
1577
- const key = loadedModule.remoteInfo.entryGlobalName;
1578
- if (globalThis[key]) {
1579
- delete globalThis[key];
1580
- }
1581
- const remoteEntryUniqueKey = getRemoteEntryUniqueKey(loadedModule.remoteInfo);
1582
- if (share.globalLoading[remoteEntryUniqueKey]) {
1583
- delete share.globalLoading[remoteEntryUniqueKey];
1584
- }
1585
- this.moduleCache.delete(remote.name);
1586
- }
1587
- }
1588
- registerRemote(remote, targetRemotes, options) {
1589
- const normalizeRemote = ()=>{
1590
- if (remote.alias) {
1591
- // Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
1592
- // As multi-level path references cannot guarantee unique names, alias being a prefix of remote.name is not supported
1593
- const findEqual = targetRemotes.find((item)=>{
1594
- var _item_alias;
1595
- return remote.alias && (item.name.startsWith(remote.alias) || ((_item_alias = item.alias) == null ? void 0 : _item_alias.startsWith(remote.alias)));
1596
- });
1597
- share.assert(!findEqual, `The alias ${remote.alias} of remote ${remote.name} is not allowed to be the prefix of ${findEqual && findEqual.name} name or alias`);
1598
- }
1599
- // Set the remote entry to a complete path
1600
- if ('entry' in remote) {
1601
- if (share.isBrowserEnv() && !remote.entry.startsWith('http')) {
1602
- remote.entry = new URL(remote.entry, window.location.origin).href;
1603
- }
1604
- }
1605
- if (!remote.shareScope) {
1606
- remote.shareScope = share.DEFAULT_SCOPE;
1607
- }
1608
- if (!remote.type) {
1609
- remote.type = share.DEFAULT_REMOTE_TYPE;
1610
- }
1611
- };
1612
- const registeredRemote = targetRemotes.find((item)=>item.name === remote.name);
1613
- if (!registeredRemote) {
1614
- normalizeRemote();
1615
- targetRemotes.push(remote);
1616
- } else {
1617
- const messages = [
1618
- `The remote "${remote.name}" is already registered.`,
1619
- (options == null ? void 0 : options.force) ? 'Hope you have known that OVERRIDE it may have some unexpected errors' : 'If you want to merge the remote, you can set "force: true".'
1620
- ];
1621
- if (options == null ? void 0 : options.force) {
1622
- // remove registered remote
1623
- this.removeRemote(registeredRemote);
1624
- normalizeRemote();
1625
- targetRemotes.push(remote);
1626
- }
1627
- share.warn(messages.join(' '));
1628
- }
1629
- }
1630
- registerRemotes(remotes, options) {
1631
- remotes.forEach((remote)=>{
1632
- this.registerRemote(remote, this.options.remotes, {
1633
- force: options == null ? void 0 : options.force
1634
- });
1635
- });
1636
- }
1637
- constructor(userOptions){
1638
- this.hooks = new PluginSystem({
1639
- beforeInit: new SyncWaterfallHook('beforeInit'),
1640
- init: new SyncHook(),
1641
- beforeRequest: new AsyncWaterfallHook('beforeRequest'),
1642
- afterResolve: new AsyncWaterfallHook('afterResolve'),
1643
- // maybe will change, temporarily for internal use only
1644
- beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
1645
- // maybe will change, temporarily for internal use only
1646
- initContainerShareScopeMap: new AsyncWaterfallHook('initContainer'),
1647
- // maybe will change, temporarily for internal use only
1648
- initContainer: new AsyncWaterfallHook('initContainer'),
1649
- onLoad: new AsyncHook('onLoad'),
1650
- handlePreloadModule: new SyncHook('handlePreloadModule'),
1651
- errorLoadRemote: new AsyncHook('errorLoadRemote'),
1652
- beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
1653
- // not used yet
1654
- loadShare: new AsyncHook(),
1655
- resolveShare: new SyncWaterfallHook('resolveShare'),
1656
- beforePreloadRemote: new AsyncHook(),
1657
- generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
1658
- // not used yet
1659
- afterPreloadRemote: new AsyncHook()
1660
- });
1661
- this.version = "0.1.4";
1662
- this.moduleCache = new Map();
1663
- this.loaderHook = new PluginSystem({
1664
- // FIXME: may not be suitable , not open to the public yet
1665
- getModuleInfo: new SyncHook(),
1666
- createScript: new SyncHook(),
1667
- createLink: new SyncHook(),
1668
- // only work for manifest , so not open to the public yet
1669
- fetch: new AsyncHook('fetch')
1670
- });
1671
- // TODO: Validate the details of the options
1672
- // Initialize options with default values
1673
- const defaultOptions = {
1674
- id: share.getBuilderId(),
1675
- name: userOptions.name,
1676
- plugins: [
1677
- snapshotPlugin(),
1678
- generatePreloadAssetsPlugin()
1679
- ],
1680
- remotes: [],
1681
- shared: {},
1682
- inBrowser: share.isBrowserEnv()
1683
- };
1684
- this.name = userOptions.name;
1685
- this.options = defaultOptions;
1686
- this.shareScopeMap = {};
1687
- this._setGlobalShareScopeMap();
1688
- this.snapshotHandler = new SnapshotHandler(this);
1689
- this.registerPlugins([
1690
- ...defaultOptions.plugins,
1691
- ...userOptions.plugins || []
1692
- ]);
1693
- this.options = this.formatOptions(defaultOptions, userOptions);
1694
- }
1695
- }
1696
-
1697
- let FederationInstance = null;
1698
- function init(options) {
1699
- // Retrieve the same instance with the same name
1700
- const instance = share.getGlobalFederationInstance(options.name, options.version);
1701
- if (!instance) {
1702
- // Retrieve debug constructor
1703
- const FederationConstructor = share.getGlobalFederationConstructor() || FederationHost;
1704
- FederationInstance = new FederationConstructor(options);
1705
- share.setGlobalFederationInstance(FederationInstance);
1706
- return FederationInstance;
1707
- } else {
1708
- // Merge options
1709
- instance.initOptions(options);
1710
- if (!FederationInstance) {
1711
- FederationInstance = instance;
1712
- }
1713
- return instance;
1714
- }
1715
- }
1716
- function loadRemote(...args) {
1717
- share.assert(FederationInstance, 'Please call init first');
1718
- // eslint-disable-next-line prefer-spread
1719
- return FederationInstance.loadRemote.apply(FederationInstance, args);
1720
- }
1721
- function loadShare(...args) {
1722
- share.assert(FederationInstance, 'Please call init first');
1723
- // eslint-disable-next-line prefer-spread
1724
- return FederationInstance.loadShare.apply(FederationInstance, args);
1725
- }
1726
- function loadShareSync(...args) {
1727
- share.assert(FederationInstance, 'Please call init first');
1728
- // eslint-disable-next-line prefer-spread
1729
- return FederationInstance.loadShareSync.apply(FederationInstance, args);
1730
- }
1731
- function preloadRemote(...args) {
1732
- share.assert(FederationInstance, 'Please call init first');
1733
- // eslint-disable-next-line prefer-spread
1734
- return FederationInstance.preloadRemote.apply(FederationInstance, args);
1735
- }
1736
- function registerRemotes(...args) {
1737
- share.assert(FederationInstance, 'Please call init first');
1738
- // eslint-disable-next-line prefer-spread
1739
- return FederationInstance.registerRemotes.apply(FederationInstance, args);
1740
- }
1741
- function registerPlugins(...args) {
1742
- share.assert(FederationInstance, 'Please call init first');
1743
- // eslint-disable-next-line prefer-spread
1744
- return FederationInstance.registerPlugins.apply(FederationInstance, args);
1745
- }
1746
- // Inject for debug
1747
- share.setGlobalFederationConstructor(FederationHost);
1748
-
1749
- exports.registerGlobalPlugins = share.registerGlobalPlugins;
1750
- Object.defineProperty(exports, 'loadScript', {
1751
- enumerable: true,
1752
- get: function () { return sdk.loadScript; }
1753
- });
1754
- Object.defineProperty(exports, 'loadScriptNode', {
1755
- enumerable: true,
1756
- get: function () { return sdk.loadScriptNode; }
1757
- });
1758
- exports.FederationHost = FederationHost;
1759
- exports.getRemoteEntry = getRemoteEntry;
1760
- exports.getRemoteInfo = getRemoteInfo;
1761
- exports.init = init;
1762
- exports.loadRemote = loadRemote;
1763
- exports.loadShare = loadShare;
1764
- exports.loadShareSync = loadShareSync;
1765
- exports.preloadRemote = preloadRemote;
1766
- exports.registerPlugins = registerPlugins;
1767
- exports.registerRemotes = registerRemotes;