@module-federation/runtime 0.0.0-next-20240829065118 → 0.0.0-next-20240830065016
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.cjs.js +12 -3
- package/dist/helpers.esm.js +13 -4
- package/dist/index.cjs.js +195 -293
- package/dist/index.esm.js +164 -262
- package/dist/package.json +1 -6
- package/dist/retry-plugin.cjs.js +15 -3
- package/dist/retry-plugin.esm.js +15 -3
- package/dist/share.cjs.js +278 -14
- package/dist/share.esm.js +269 -10
- package/dist/src/core.d.ts +3 -7
- package/dist/src/helpers.d.ts +4 -0
- package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +5 -0
- package/dist/src/remote/index.d.ts +4 -4
- package/dist/src/shared/index.d.ts +2 -7
- package/dist/src/type/config.d.ts +1 -3
- package/dist/src/utils/env.d.ts +2 -1
- package/dist/src/utils/plugin.d.ts +2 -1
- package/dist/src/utils/tool.d.ts +2 -1
- package/package.json +2 -7
- package/dist/embedded.cjs.d.ts +0 -1
- package/dist/embedded.cjs.js +0 -20
- package/dist/embedded.esm.js +0 -3
- package/dist/src/embedded.d.ts +0 -2
package/dist/index.cjs.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _extends = require('@swc/helpers/_/_extends');
|
|
6
|
-
var sdk = require('@module-federation/sdk');
|
|
7
5
|
var share = require('./share.cjs.js');
|
|
8
|
-
var
|
|
6
|
+
var sdk = require('@module-federation/sdk');
|
|
9
7
|
|
|
10
8
|
// Function to match a remote with its name and expose
|
|
11
9
|
// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button
|
|
@@ -71,26 +69,20 @@ function matchRemote(remotes, nameOrAlias) {
|
|
|
71
69
|
return;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
function _extends$7() {
|
|
73
|
+
_extends$7 = Object.assign || function(target) {
|
|
74
|
+
for(var i = 1; i < arguments.length; i++){
|
|
75
|
+
var source = arguments[i];
|
|
76
|
+
for(var key in source){
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
78
|
+
target[key] = source[key];
|
|
79
|
+
}
|
|
81
80
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
hookInstances.forEach((hookInstance)=>{
|
|
87
|
-
hookInstance.applyPlugin(plugin);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return plugins;
|
|
81
|
+
}
|
|
82
|
+
return target;
|
|
83
|
+
};
|
|
84
|
+
return _extends$7.apply(this, arguments);
|
|
92
85
|
}
|
|
93
|
-
|
|
94
86
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
95
87
|
return new Promise((resolve, reject)=>{
|
|
96
88
|
try {
|
|
@@ -253,7 +245,7 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
253
245
|
return share.globalLoading[uniqueKey];
|
|
254
246
|
}
|
|
255
247
|
function getRemoteInfo(remote) {
|
|
256
|
-
return _extends
|
|
248
|
+
return _extends$7({}, remote, {
|
|
257
249
|
entry: 'entry' in remote ? remote.entry : '',
|
|
258
250
|
type: remote.type || share.DEFAULT_REMOTE_TYPE,
|
|
259
251
|
entryGlobalName: remote.entryGlobalName || remote.name,
|
|
@@ -261,6 +253,20 @@ function getRemoteInfo(remote) {
|
|
|
261
253
|
});
|
|
262
254
|
}
|
|
263
255
|
|
|
256
|
+
function _extends$6() {
|
|
257
|
+
_extends$6 = Object.assign || function(target) {
|
|
258
|
+
for(var i = 1; i < arguments.length; i++){
|
|
259
|
+
var source = arguments[i];
|
|
260
|
+
for(var key in source){
|
|
261
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
262
|
+
target[key] = source[key];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return target;
|
|
267
|
+
};
|
|
268
|
+
return _extends$6.apply(this, arguments);
|
|
269
|
+
}
|
|
264
270
|
let Module = class Module {
|
|
265
271
|
async getEntry() {
|
|
266
272
|
if (this.remoteEntryExports) {
|
|
@@ -272,7 +278,7 @@ let Module = class Module {
|
|
|
272
278
|
remoteInfo: this.remoteInfo,
|
|
273
279
|
remoteEntryExports: this.remoteEntryExports
|
|
274
280
|
});
|
|
275
|
-
share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${
|
|
281
|
+
share.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${share.safeToString(this.remoteInfo)}`);
|
|
276
282
|
this.remoteEntryExports = remoteEntryExports;
|
|
277
283
|
return this.remoteEntryExports;
|
|
278
284
|
}
|
|
@@ -312,7 +318,7 @@ let Module = class Module {
|
|
|
312
318
|
console.error('The remote entry interface does not contain "init"', '\n', 'Ensure the name of this remote is not reserved or in use. Check if anything already exists on window[nameOfRemote]', '\n', 'Ensure that window[nameOfRemote] is returning a {get,init} object.');
|
|
313
319
|
}
|
|
314
320
|
await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
315
|
-
await this.host.hooks.lifecycle.initContainer.emit(_extends
|
|
321
|
+
await this.host.hooks.lifecycle.initContainer.emit(_extends$6({}, initContainerOptions, {
|
|
316
322
|
remoteEntryExports
|
|
317
323
|
}));
|
|
318
324
|
}
|
|
@@ -361,195 +367,22 @@ let Module = class Module {
|
|
|
361
367
|
}
|
|
362
368
|
};
|
|
363
369
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
372
|
-
const self = this;
|
|
373
|
-
this.on(function wrapper(...args) {
|
|
374
|
-
self.remove(wrapper);
|
|
375
|
-
// eslint-disable-next-line prefer-spread
|
|
376
|
-
return fn.apply(null, args);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
emit(...data) {
|
|
380
|
-
let result;
|
|
381
|
-
if (this.listeners.size > 0) {
|
|
382
|
-
// eslint-disable-next-line prefer-spread
|
|
383
|
-
this.listeners.forEach((fn)=>{
|
|
384
|
-
result = fn(...data);
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
return result;
|
|
388
|
-
}
|
|
389
|
-
remove(fn) {
|
|
390
|
-
this.listeners.delete(fn);
|
|
391
|
-
}
|
|
392
|
-
removeAll() {
|
|
393
|
-
this.listeners.clear();
|
|
394
|
-
}
|
|
395
|
-
constructor(type){
|
|
396
|
-
this.type = '';
|
|
397
|
-
this.listeners = new Set();
|
|
398
|
-
if (type) {
|
|
399
|
-
this.type = type;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
class AsyncHook extends SyncHook {
|
|
405
|
-
emit(...data) {
|
|
406
|
-
let result;
|
|
407
|
-
const ls = Array.from(this.listeners);
|
|
408
|
-
if (ls.length > 0) {
|
|
409
|
-
let i = 0;
|
|
410
|
-
const call = (prev)=>{
|
|
411
|
-
if (prev === false) {
|
|
412
|
-
return false; // Abort process
|
|
413
|
-
} else if (i < ls.length) {
|
|
414
|
-
return Promise.resolve(ls[i++].apply(null, data)).then(call);
|
|
415
|
-
} else {
|
|
416
|
-
return prev;
|
|
370
|
+
function _extends$5() {
|
|
371
|
+
_extends$5 = Object.assign || function(target) {
|
|
372
|
+
for(var i = 1; i < arguments.length; i++){
|
|
373
|
+
var source = arguments[i];
|
|
374
|
+
for(var key in source){
|
|
375
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
376
|
+
target[key] = source[key];
|
|
417
377
|
}
|
|
418
|
-
};
|
|
419
|
-
result = call();
|
|
420
|
-
}
|
|
421
|
-
return Promise.resolve(result);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
426
|
-
function checkReturnData(originalData, returnedData) {
|
|
427
|
-
if (!share.isObject(returnedData)) {
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
if (originalData !== returnedData) {
|
|
431
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
432
|
-
for(const key in originalData){
|
|
433
|
-
if (!(key in returnedData)) {
|
|
434
|
-
return false;
|
|
435
378
|
}
|
|
436
379
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
class SyncWaterfallHook extends SyncHook {
|
|
441
|
-
emit(data) {
|
|
442
|
-
if (!share.isObject(data)) {
|
|
443
|
-
share.error(`The data for the "${this.type}" hook should be an object.`);
|
|
444
|
-
}
|
|
445
|
-
for (const fn of this.listeners){
|
|
446
|
-
try {
|
|
447
|
-
const tempData = fn(data);
|
|
448
|
-
if (checkReturnData(data, tempData)) {
|
|
449
|
-
data = tempData;
|
|
450
|
-
} else {
|
|
451
|
-
this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
} catch (e) {
|
|
455
|
-
share.warn(e);
|
|
456
|
-
this.onerror(e);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
return data;
|
|
460
|
-
}
|
|
461
|
-
constructor(type){
|
|
462
|
-
super();
|
|
463
|
-
this.onerror = share.error;
|
|
464
|
-
this.type = type;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
class AsyncWaterfallHook extends SyncHook {
|
|
469
|
-
emit(data) {
|
|
470
|
-
if (!share.isObject(data)) {
|
|
471
|
-
share.error(`The response data for the "${this.type}" hook must be an object.`);
|
|
472
|
-
}
|
|
473
|
-
const ls = Array.from(this.listeners);
|
|
474
|
-
if (ls.length > 0) {
|
|
475
|
-
let i = 0;
|
|
476
|
-
const processError = (e)=>{
|
|
477
|
-
share.warn(e);
|
|
478
|
-
this.onerror(e);
|
|
479
|
-
return data;
|
|
480
|
-
};
|
|
481
|
-
const call = (prevData)=>{
|
|
482
|
-
if (checkReturnData(data, prevData)) {
|
|
483
|
-
data = prevData;
|
|
484
|
-
if (i < ls.length) {
|
|
485
|
-
try {
|
|
486
|
-
return Promise.resolve(ls[i++](data)).then(call, processError);
|
|
487
|
-
} catch (e) {
|
|
488
|
-
return processError(e);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
} else {
|
|
492
|
-
this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
|
|
493
|
-
}
|
|
494
|
-
return data;
|
|
495
|
-
};
|
|
496
|
-
return Promise.resolve(call(data));
|
|
497
|
-
}
|
|
498
|
-
return Promise.resolve(data);
|
|
499
|
-
}
|
|
500
|
-
constructor(type){
|
|
501
|
-
super();
|
|
502
|
-
this.onerror = share.error;
|
|
503
|
-
this.type = type;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
class PluginSystem {
|
|
508
|
-
applyPlugin(plugin) {
|
|
509
|
-
share.assert(share.isPlainObject(plugin), 'Plugin configuration is invalid.');
|
|
510
|
-
// The plugin's name is mandatory and must be unique
|
|
511
|
-
const pluginName = plugin.name;
|
|
512
|
-
share.assert(pluginName, 'A name must be provided by the plugin.');
|
|
513
|
-
if (!this.registerPlugins[pluginName]) {
|
|
514
|
-
this.registerPlugins[pluginName] = plugin;
|
|
515
|
-
Object.keys(this.lifecycle).forEach((key)=>{
|
|
516
|
-
const pluginLife = plugin[key];
|
|
517
|
-
if (pluginLife) {
|
|
518
|
-
this.lifecycle[key].on(pluginLife);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
removePlugin(pluginName) {
|
|
524
|
-
share.assert(pluginName, 'A name is required.');
|
|
525
|
-
const plugin = this.registerPlugins[pluginName];
|
|
526
|
-
share.assert(plugin, `The plugin "${pluginName}" is not registered.`);
|
|
527
|
-
Object.keys(plugin).forEach((key)=>{
|
|
528
|
-
if (key !== 'name') {
|
|
529
|
-
this.lifecycle[key].remove(plugin[key]);
|
|
530
|
-
}
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
534
|
-
inherit({ lifecycle, registerPlugins }) {
|
|
535
|
-
Object.keys(lifecycle).forEach((hookName)=>{
|
|
536
|
-
share.assert(!this.lifecycle[hookName], `The hook "${hookName}" has a conflict and cannot be inherited.`);
|
|
537
|
-
this.lifecycle[hookName] = lifecycle[hookName];
|
|
538
|
-
});
|
|
539
|
-
Object.keys(registerPlugins).forEach((pluginName)=>{
|
|
540
|
-
share.assert(!this.registerPlugins[pluginName], `The plugin "${pluginName}" has a conflict and cannot be inherited.`);
|
|
541
|
-
this.applyPlugin(registerPlugins[pluginName]);
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
constructor(lifecycle){
|
|
545
|
-
this.registerPlugins = {};
|
|
546
|
-
this.lifecycle = lifecycle;
|
|
547
|
-
this.lifecycleKeys = Object.keys(lifecycle);
|
|
548
|
-
}
|
|
380
|
+
return target;
|
|
381
|
+
};
|
|
382
|
+
return _extends$5.apply(this, arguments);
|
|
549
383
|
}
|
|
550
|
-
|
|
551
384
|
function defaultPreloadArgs(preloadConfig) {
|
|
552
|
-
return _extends
|
|
385
|
+
return _extends$5({
|
|
553
386
|
resourceCategory: 'sync',
|
|
554
387
|
share: true,
|
|
555
388
|
depsRemote: true,
|
|
@@ -559,7 +392,7 @@ function defaultPreloadArgs(preloadConfig) {
|
|
|
559
392
|
function formatPreloadArgs(remotes, preloadArgs) {
|
|
560
393
|
return preloadArgs.map((args)=>{
|
|
561
394
|
const remoteInfo = matchRemote(remotes, args.nameOrAlias);
|
|
562
|
-
share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo &&
|
|
395
|
+
share.assert(remoteInfo, `Unable to preload ${args.nameOrAlias} as it is not included in ${!remoteInfo && share.safeToString({
|
|
563
396
|
remoteInfo,
|
|
564
397
|
remotes
|
|
565
398
|
})}`);
|
|
@@ -705,13 +538,27 @@ useLinkPreload = true) {
|
|
|
705
538
|
}
|
|
706
539
|
}
|
|
707
540
|
|
|
541
|
+
function _extends$4() {
|
|
542
|
+
_extends$4 = Object.assign || function(target) {
|
|
543
|
+
for(var i = 1; i < arguments.length; i++){
|
|
544
|
+
var source = arguments[i];
|
|
545
|
+
for(var key in source){
|
|
546
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
547
|
+
target[key] = source[key];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return target;
|
|
552
|
+
};
|
|
553
|
+
return _extends$4.apply(this, arguments);
|
|
554
|
+
}
|
|
708
555
|
function assignRemoteInfo(remoteInfo, remoteSnapshot) {
|
|
709
556
|
const remoteEntryInfo = share.getRemoteEntryInfoFromSnapshot(remoteSnapshot);
|
|
710
557
|
if (!remoteEntryInfo.url) {
|
|
711
558
|
share.error(`The attribute remoteEntry of ${remoteInfo.name} must not be undefined.`);
|
|
712
559
|
}
|
|
713
560
|
let entryUrl = sdk.getResourceUrl(remoteSnapshot, remoteEntryInfo.url);
|
|
714
|
-
if (!
|
|
561
|
+
if (!share.isBrowserEnv() && !entryUrl.startsWith('http')) {
|
|
715
562
|
entryUrl = `https:${entryUrl}`;
|
|
716
563
|
}
|
|
717
564
|
remoteInfo.type = remoteEntryInfo.type;
|
|
@@ -752,7 +599,7 @@ function snapshotPlugin() {
|
|
|
752
599
|
if (assets) {
|
|
753
600
|
preloadAssets(remoteInfo, origin, assets, false);
|
|
754
601
|
}
|
|
755
|
-
return _extends
|
|
602
|
+
return _extends$4({}, args, {
|
|
756
603
|
remoteSnapshot
|
|
757
604
|
});
|
|
758
605
|
}
|
|
@@ -973,6 +820,20 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
973
820
|
};
|
|
974
821
|
};
|
|
975
822
|
|
|
823
|
+
function _extends$3() {
|
|
824
|
+
_extends$3 = Object.assign || function(target) {
|
|
825
|
+
for(var i = 1; i < arguments.length; i++){
|
|
826
|
+
var source = arguments[i];
|
|
827
|
+
for(var key in source){
|
|
828
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
829
|
+
target[key] = source[key];
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return target;
|
|
834
|
+
};
|
|
835
|
+
return _extends$3.apply(this, arguments);
|
|
836
|
+
}
|
|
976
837
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
977
838
|
const hostGlobalSnapshot = share.getGlobalSnapshotInfoByModuleInfo({
|
|
978
839
|
name: origin.options.name,
|
|
@@ -1040,7 +901,7 @@ class SnapshotHandler {
|
|
|
1040
901
|
// 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.
|
|
1041
902
|
if (hostSnapshot && 'remotesInfo' in hostSnapshot && !share.getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value) {
|
|
1042
903
|
if ('version' in moduleInfo || 'entry' in moduleInfo) {
|
|
1043
|
-
hostSnapshot.remotesInfo = _extends
|
|
904
|
+
hostSnapshot.remotesInfo = _extends$3({}, hostSnapshot == null ? void 0 : hostSnapshot.remotesInfo, {
|
|
1044
905
|
[moduleInfo.name]: {
|
|
1045
906
|
matchedVersion: 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry
|
|
1046
907
|
}
|
|
@@ -1055,21 +916,21 @@ class SnapshotHandler {
|
|
|
1055
916
|
remoteSnapshot,
|
|
1056
917
|
globalSnapshot
|
|
1057
918
|
});
|
|
919
|
+
let mSnapshot;
|
|
920
|
+
let gSnapshot;
|
|
1058
921
|
// global snapshot includes manifest or module info includes manifest
|
|
1059
922
|
if (globalRemoteSnapshot) {
|
|
1060
923
|
if (sdk.isManifestProvider(globalRemoteSnapshot)) {
|
|
1061
|
-
const remoteEntry =
|
|
924
|
+
const remoteEntry = share.isBrowserEnv() ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || '';
|
|
1062
925
|
const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
|
|
1063
926
|
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
1064
|
-
const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends
|
|
927
|
+
const globalSnapshotRes = share.setGlobalSnapshotInfoByModuleInfo(_extends$3({}, moduleInfo, {
|
|
1065
928
|
// The global remote may be overridden
|
|
1066
929
|
// Therefore, set the snapshot key to the global address of the actual request
|
|
1067
930
|
entry: remoteEntry
|
|
1068
931
|
}), moduleSnapshot);
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
globalSnapshot: globalSnapshotRes
|
|
1072
|
-
};
|
|
932
|
+
mSnapshot = moduleSnapshot;
|
|
933
|
+
gSnapshot = globalSnapshotRes;
|
|
1073
934
|
} else {
|
|
1074
935
|
const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
|
|
1075
936
|
options: this.HostInstance.options,
|
|
@@ -1077,10 +938,8 @@ class SnapshotHandler {
|
|
|
1077
938
|
remoteSnapshot: globalRemoteSnapshot,
|
|
1078
939
|
from: 'global'
|
|
1079
940
|
});
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
globalSnapshot: globalSnapshotRes
|
|
1083
|
-
};
|
|
941
|
+
mSnapshot = remoteSnapshotRes;
|
|
942
|
+
gSnapshot = globalSnapshotRes;
|
|
1084
943
|
}
|
|
1085
944
|
} else {
|
|
1086
945
|
if (share.isRemoteInfoWithEntry(moduleInfo)) {
|
|
@@ -1094,10 +953,8 @@ class SnapshotHandler {
|
|
|
1094
953
|
remoteSnapshot: moduleSnapshot,
|
|
1095
954
|
from: 'global'
|
|
1096
955
|
});
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
globalSnapshot: globalSnapshotRes
|
|
1100
|
-
};
|
|
956
|
+
mSnapshot = remoteSnapshotRes;
|
|
957
|
+
gSnapshot = globalSnapshotRes;
|
|
1101
958
|
} else {
|
|
1102
959
|
share.error(`
|
|
1103
960
|
Cannot get remoteSnapshot with the name: '${moduleInfo.name}', version: '${moduleInfo.version}' from __FEDERATION__.moduleInfo. The following reasons may be causing the problem:\n
|
|
@@ -1107,6 +964,15 @@ class SnapshotHandler {
|
|
|
1107
964
|
`);
|
|
1108
965
|
}
|
|
1109
966
|
}
|
|
967
|
+
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
968
|
+
options,
|
|
969
|
+
moduleInfo,
|
|
970
|
+
remoteSnapshot: mSnapshot
|
|
971
|
+
});
|
|
972
|
+
return {
|
|
973
|
+
remoteSnapshot: mSnapshot,
|
|
974
|
+
globalSnapshot: gSnapshot
|
|
975
|
+
};
|
|
1110
976
|
}
|
|
1111
977
|
getGlobalRemoteInfo(moduleInfo) {
|
|
1112
978
|
return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
|
|
@@ -1156,10 +1022,11 @@ class SnapshotHandler {
|
|
|
1156
1022
|
constructor(HostInstance){
|
|
1157
1023
|
this.loadingHostSnapshot = null;
|
|
1158
1024
|
this.manifestCache = new Map();
|
|
1159
|
-
this.hooks = new PluginSystem({
|
|
1160
|
-
beforeLoadRemoteSnapshot: new AsyncHook('beforeLoadRemoteSnapshot'),
|
|
1161
|
-
loadSnapshot: new AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
1162
|
-
loadRemoteSnapshot: new AsyncWaterfallHook('loadRemoteSnapshot')
|
|
1025
|
+
this.hooks = new share.PluginSystem({
|
|
1026
|
+
beforeLoadRemoteSnapshot: new share.AsyncHook('beforeLoadRemoteSnapshot'),
|
|
1027
|
+
loadSnapshot: new share.AsyncWaterfallHook('loadGlobalSnapshot'),
|
|
1028
|
+
loadRemoteSnapshot: new share.AsyncWaterfallHook('loadRemoteSnapshot'),
|
|
1029
|
+
afterLoadSnapshot: new share.AsyncWaterfallHook('afterLoadSnapshot')
|
|
1163
1030
|
});
|
|
1164
1031
|
this.manifestLoading = share.Global.__FEDERATION__.__MANIFEST_LOADING__;
|
|
1165
1032
|
this.HostInstance = HostInstance;
|
|
@@ -1167,6 +1034,32 @@ class SnapshotHandler {
|
|
|
1167
1034
|
}
|
|
1168
1035
|
}
|
|
1169
1036
|
|
|
1037
|
+
function _extends$2() {
|
|
1038
|
+
_extends$2 = Object.assign || function(target) {
|
|
1039
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1040
|
+
var source = arguments[i];
|
|
1041
|
+
for(var key in source){
|
|
1042
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1043
|
+
target[key] = source[key];
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return target;
|
|
1048
|
+
};
|
|
1049
|
+
return _extends$2.apply(this, arguments);
|
|
1050
|
+
}
|
|
1051
|
+
function _object_without_properties_loose(source, excluded) {
|
|
1052
|
+
if (source == null) return {};
|
|
1053
|
+
var target = {};
|
|
1054
|
+
var sourceKeys = Object.keys(source);
|
|
1055
|
+
var key, i;
|
|
1056
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
1057
|
+
key = sourceKeys[i];
|
|
1058
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
1059
|
+
target[key] = source[key];
|
|
1060
|
+
}
|
|
1061
|
+
return target;
|
|
1062
|
+
}
|
|
1170
1063
|
class SharedHandler {
|
|
1171
1064
|
// register shared in shareScopeMap
|
|
1172
1065
|
registerShared(globalOptions, userOptions) {
|
|
@@ -1206,9 +1099,7 @@ class SharedHandler {
|
|
|
1206
1099
|
});
|
|
1207
1100
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1208
1101
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1209
|
-
await Promise.all(this.initializeSharing(shareScope,
|
|
1210
|
-
strategy: shareInfo.strategy
|
|
1211
|
-
}));
|
|
1102
|
+
await Promise.all(this.initializeSharing(shareScope, shareInfo.strategy));
|
|
1212
1103
|
return;
|
|
1213
1104
|
}));
|
|
1214
1105
|
}
|
|
@@ -1296,22 +1187,8 @@ class SharedHandler {
|
|
|
1296
1187
|
* It accepts one argument, the name of the share scope.
|
|
1297
1188
|
* If the share scope does not exist, it creates one.
|
|
1298
1189
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1299
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE,
|
|
1190
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
|
|
1300
1191
|
const { host } = this;
|
|
1301
|
-
const from = extraOptions == null ? void 0 : extraOptions.from;
|
|
1302
|
-
const strategy = extraOptions == null ? void 0 : extraOptions.strategy;
|
|
1303
|
-
let initScope = extraOptions == null ? void 0 : extraOptions.initScope;
|
|
1304
|
-
const promises = [];
|
|
1305
|
-
if (from !== 'build') {
|
|
1306
|
-
const { initTokens } = this;
|
|
1307
|
-
if (!initScope) initScope = [];
|
|
1308
|
-
let initToken = initTokens[shareScopeName];
|
|
1309
|
-
if (!initToken) initToken = initTokens[shareScopeName] = {
|
|
1310
|
-
from: this.host.name
|
|
1311
|
-
};
|
|
1312
|
-
if (initScope.indexOf(initToken) >= 0) return promises;
|
|
1313
|
-
initScope.push(initToken);
|
|
1314
|
-
}
|
|
1315
1192
|
const shareScope = this.shareScopeMap;
|
|
1316
1193
|
const hostName = host.options.name;
|
|
1317
1194
|
// Creates a new share scope if necessary
|
|
@@ -1331,7 +1208,8 @@ class SharedHandler {
|
|
|
1331
1208
|
versions[version] = shared;
|
|
1332
1209
|
}
|
|
1333
1210
|
};
|
|
1334
|
-
const
|
|
1211
|
+
const promises = [];
|
|
1212
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1335
1213
|
const initRemoteModule = async (key)=>{
|
|
1336
1214
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
1337
1215
|
id: key
|
|
@@ -1339,7 +1217,7 @@ class SharedHandler {
|
|
|
1339
1217
|
if (module.getEntry) {
|
|
1340
1218
|
const entry = await module.getEntry();
|
|
1341
1219
|
if (!module.inited) {
|
|
1342
|
-
|
|
1220
|
+
initFn(entry);
|
|
1343
1221
|
module.inited = true;
|
|
1344
1222
|
}
|
|
1345
1223
|
}
|
|
@@ -1375,9 +1253,7 @@ class SharedHandler {
|
|
|
1375
1253
|
});
|
|
1376
1254
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1377
1255
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1378
|
-
this.initializeSharing(shareScope,
|
|
1379
|
-
strategy: shareInfo.strategy
|
|
1380
|
-
});
|
|
1256
|
+
this.initializeSharing(shareScope, shareInfo.strategy);
|
|
1381
1257
|
});
|
|
1382
1258
|
}
|
|
1383
1259
|
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
@@ -1458,7 +1334,7 @@ class SharedHandler {
|
|
|
1458
1334
|
});
|
|
1459
1335
|
}
|
|
1460
1336
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
1461
|
-
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose
|
|
1337
|
+
const { version, scope = 'default' } = shared, shareInfo = _object_without_properties_loose(shared, [
|
|
1462
1338
|
"version",
|
|
1463
1339
|
"scope"
|
|
1464
1340
|
]);
|
|
@@ -1475,7 +1351,7 @@ class SharedHandler {
|
|
|
1475
1351
|
if (this.shareScopeMap[sc][pkgName][version]) {
|
|
1476
1352
|
return;
|
|
1477
1353
|
}
|
|
1478
|
-
this.shareScopeMap[sc][pkgName][version] = _extends
|
|
1354
|
+
this.shareScopeMap[sc][pkgName][version] = _extends$2({
|
|
1479
1355
|
version,
|
|
1480
1356
|
scope: [
|
|
1481
1357
|
'default'
|
|
@@ -1498,22 +1374,35 @@ class SharedHandler {
|
|
|
1498
1374
|
}
|
|
1499
1375
|
}
|
|
1500
1376
|
constructor(host){
|
|
1501
|
-
this.hooks = new PluginSystem({
|
|
1502
|
-
afterResolve: new AsyncWaterfallHook('afterResolve'),
|
|
1503
|
-
beforeLoadShare: new AsyncWaterfallHook('beforeLoadShare'),
|
|
1377
|
+
this.hooks = new share.PluginSystem({
|
|
1378
|
+
afterResolve: new share.AsyncWaterfallHook('afterResolve'),
|
|
1379
|
+
beforeLoadShare: new share.AsyncWaterfallHook('beforeLoadShare'),
|
|
1504
1380
|
// not used yet
|
|
1505
|
-
loadShare: new AsyncHook(),
|
|
1506
|
-
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1381
|
+
loadShare: new share.AsyncHook(),
|
|
1382
|
+
resolveShare: new share.SyncWaterfallHook('resolveShare'),
|
|
1507
1383
|
// maybe will change, temporarily for internal use only
|
|
1508
|
-
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
1384
|
+
initContainerShareScopeMap: new share.SyncWaterfallHook('initContainerShareScopeMap')
|
|
1509
1385
|
});
|
|
1510
1386
|
this.host = host;
|
|
1511
1387
|
this.shareScopeMap = {};
|
|
1512
|
-
this.initTokens = {};
|
|
1513
1388
|
this._setGlobalShareScopeMap(host.options);
|
|
1514
1389
|
}
|
|
1515
1390
|
}
|
|
1516
1391
|
|
|
1392
|
+
function _extends$1() {
|
|
1393
|
+
_extends$1 = Object.assign || function(target) {
|
|
1394
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1395
|
+
var source = arguments[i];
|
|
1396
|
+
for(var key in source){
|
|
1397
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1398
|
+
target[key] = source[key];
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return target;
|
|
1403
|
+
};
|
|
1404
|
+
return _extends$1.apply(this, arguments);
|
|
1405
|
+
}
|
|
1517
1406
|
class RemoteHandler {
|
|
1518
1407
|
formatAndRegisterRemote(globalOptions, userOptions) {
|
|
1519
1408
|
const userRemotes = userOptions.remotes || [];
|
|
@@ -1670,7 +1559,7 @@ class RemoteHandler {
|
|
|
1670
1559
|
`);
|
|
1671
1560
|
const { remote: rawRemote } = remoteSplitInfo;
|
|
1672
1561
|
const remoteInfo = getRemoteInfo(rawRemote);
|
|
1673
|
-
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends
|
|
1562
|
+
const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit(_extends$1({
|
|
1674
1563
|
id: idRes
|
|
1675
1564
|
}, remoteSplitInfo, {
|
|
1676
1565
|
options: host.options,
|
|
@@ -1839,8 +1728,7 @@ class RemoteHandler {
|
|
|
1839
1728
|
const remoteKey = hostGlobalSnapshot && 'remotesInfo' in hostGlobalSnapshot && hostGlobalSnapshot.remotesInfo && share.getInfoWithoutType(hostGlobalSnapshot.remotesInfo, remote.name).key;
|
|
1840
1729
|
if (remoteKey) {
|
|
1841
1730
|
delete hostGlobalSnapshot.remotesInfo[remoteKey];
|
|
1842
|
-
if (
|
|
1843
|
-
Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1731
|
+
if (Boolean(share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey])) {
|
|
1844
1732
|
delete share.Global.__FEDERATION__.__MANIFEST_LOADING__[remoteKey];
|
|
1845
1733
|
}
|
|
1846
1734
|
}
|
|
@@ -1852,24 +1740,38 @@ class RemoteHandler {
|
|
|
1852
1740
|
}
|
|
1853
1741
|
}
|
|
1854
1742
|
constructor(host){
|
|
1855
|
-
this.hooks = new PluginSystem({
|
|
1856
|
-
beforeRegisterRemote: new SyncWaterfallHook('beforeRegisterRemote'),
|
|
1857
|
-
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
1858
|
-
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1859
|
-
onLoad: new AsyncHook('onLoad'),
|
|
1860
|
-
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
1861
|
-
errorLoadRemote: new AsyncHook('errorLoadRemote'),
|
|
1862
|
-
beforePreloadRemote: new AsyncHook('beforePreloadRemote'),
|
|
1863
|
-
generatePreloadAssets: new AsyncHook('generatePreloadAssets'),
|
|
1743
|
+
this.hooks = new share.PluginSystem({
|
|
1744
|
+
beforeRegisterRemote: new share.SyncWaterfallHook('beforeRegisterRemote'),
|
|
1745
|
+
registerRemote: new share.SyncWaterfallHook('registerRemote'),
|
|
1746
|
+
beforeRequest: new share.AsyncWaterfallHook('beforeRequest'),
|
|
1747
|
+
onLoad: new share.AsyncHook('onLoad'),
|
|
1748
|
+
handlePreloadModule: new share.SyncHook('handlePreloadModule'),
|
|
1749
|
+
errorLoadRemote: new share.AsyncHook('errorLoadRemote'),
|
|
1750
|
+
beforePreloadRemote: new share.AsyncHook('beforePreloadRemote'),
|
|
1751
|
+
generatePreloadAssets: new share.AsyncHook('generatePreloadAssets'),
|
|
1864
1752
|
// not used yet
|
|
1865
|
-
afterPreloadRemote: new AsyncHook(),
|
|
1866
|
-
loadEntry: new AsyncHook()
|
|
1753
|
+
afterPreloadRemote: new share.AsyncHook(),
|
|
1754
|
+
loadEntry: new share.AsyncHook()
|
|
1867
1755
|
});
|
|
1868
1756
|
this.host = host;
|
|
1869
1757
|
this.idToRemoteMap = {};
|
|
1870
1758
|
}
|
|
1871
1759
|
}
|
|
1872
1760
|
|
|
1761
|
+
function _extends() {
|
|
1762
|
+
_extends = Object.assign || function(target) {
|
|
1763
|
+
for(var i = 1; i < arguments.length; i++){
|
|
1764
|
+
var source = arguments[i];
|
|
1765
|
+
for(var key in source){
|
|
1766
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1767
|
+
target[key] = source[key];
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
return target;
|
|
1772
|
+
};
|
|
1773
|
+
return _extends.apply(this, arguments);
|
|
1774
|
+
}
|
|
1873
1775
|
class FederationHost {
|
|
1874
1776
|
initOptions(userOptions) {
|
|
1875
1777
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -1887,8 +1789,8 @@ class FederationHost {
|
|
|
1887
1789
|
loadShareSync(pkgName, extraOptions) {
|
|
1888
1790
|
return this.sharedHandler.loadShareSync(pkgName, extraOptions);
|
|
1889
1791
|
}
|
|
1890
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE,
|
|
1891
|
-
return this.sharedHandler.initializeSharing(shareScopeName,
|
|
1792
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, strategy) {
|
|
1793
|
+
return this.sharedHandler.initializeSharing(shareScopeName, strategy);
|
|
1892
1794
|
}
|
|
1893
1795
|
initRawContainer(name, url, container) {
|
|
1894
1796
|
const remoteInfo = getRemoteInfo({
|
|
@@ -1935,7 +1837,7 @@ class FederationHost {
|
|
|
1935
1837
|
}
|
|
1936
1838
|
});
|
|
1937
1839
|
}
|
|
1938
|
-
const optionsRes = _extends
|
|
1840
|
+
const optionsRes = _extends({}, globalOptions, userOptions, {
|
|
1939
1841
|
plugins,
|
|
1940
1842
|
remotes,
|
|
1941
1843
|
shared: handledShared
|
|
@@ -1947,7 +1849,7 @@ class FederationHost {
|
|
|
1947
1849
|
return optionsRes;
|
|
1948
1850
|
}
|
|
1949
1851
|
registerPlugins(plugins) {
|
|
1950
|
-
const pluginRes = registerPlugins
|
|
1852
|
+
const pluginRes = share.registerPlugins(plugins, [
|
|
1951
1853
|
this.hooks,
|
|
1952
1854
|
this.remoteHandler.hooks,
|
|
1953
1855
|
this.sharedHandler.hooks,
|
|
@@ -1967,23 +1869,23 @@ class FederationHost {
|
|
|
1967
1869
|
return this.remoteHandler.registerRemotes(remotes, options);
|
|
1968
1870
|
}
|
|
1969
1871
|
constructor(userOptions){
|
|
1970
|
-
this.hooks = new PluginSystem({
|
|
1971
|
-
beforeInit: new SyncWaterfallHook('beforeInit'),
|
|
1972
|
-
init: new SyncHook(),
|
|
1872
|
+
this.hooks = new share.PluginSystem({
|
|
1873
|
+
beforeInit: new share.SyncWaterfallHook('beforeInit'),
|
|
1874
|
+
init: new share.SyncHook(),
|
|
1973
1875
|
// maybe will change, temporarily for internal use only
|
|
1974
|
-
beforeInitContainer: new AsyncWaterfallHook('beforeInitContainer'),
|
|
1876
|
+
beforeInitContainer: new share.AsyncWaterfallHook('beforeInitContainer'),
|
|
1975
1877
|
// maybe will change, temporarily for internal use only
|
|
1976
|
-
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1878
|
+
initContainer: new share.AsyncWaterfallHook('initContainer')
|
|
1977
1879
|
});
|
|
1978
|
-
this.version = "0.
|
|
1880
|
+
this.version = "0.5.1";
|
|
1979
1881
|
this.moduleCache = new Map();
|
|
1980
|
-
this.loaderHook = new PluginSystem({
|
|
1882
|
+
this.loaderHook = new share.PluginSystem({
|
|
1981
1883
|
// FIXME: may not be suitable , not open to the public yet
|
|
1982
|
-
getModuleInfo: new SyncHook(),
|
|
1983
|
-
createScript: new SyncHook(),
|
|
1984
|
-
createLink: new SyncHook(),
|
|
1884
|
+
getModuleInfo: new share.SyncHook(),
|
|
1885
|
+
createScript: new share.SyncHook(),
|
|
1886
|
+
createLink: new share.SyncHook(),
|
|
1985
1887
|
// only work for manifest , so not open to the public yet
|
|
1986
|
-
fetch: new AsyncHook()
|
|
1888
|
+
fetch: new share.AsyncHook()
|
|
1987
1889
|
});
|
|
1988
1890
|
// TODO: Validate the details of the options
|
|
1989
1891
|
// Initialize options with default values
|
|
@@ -1996,7 +1898,7 @@ class FederationHost {
|
|
|
1996
1898
|
],
|
|
1997
1899
|
remotes: [],
|
|
1998
1900
|
shared: {},
|
|
1999
|
-
inBrowser:
|
|
1901
|
+
inBrowser: share.isBrowserEnv()
|
|
2000
1902
|
};
|
|
2001
1903
|
this.name = userOptions.name;
|
|
2002
1904
|
this.options = defaultOptions;
|
|
@@ -2070,6 +1972,7 @@ function getInstance() {
|
|
|
2070
1972
|
// Inject for debug
|
|
2071
1973
|
share.setGlobalFederationConstructor(FederationHost);
|
|
2072
1974
|
|
|
1975
|
+
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
2073
1976
|
Object.defineProperty(exports, 'loadScript', {
|
|
2074
1977
|
enumerable: true,
|
|
2075
1978
|
get: function () { return sdk.loadScript; }
|
|
@@ -2078,7 +1981,6 @@ Object.defineProperty(exports, 'loadScriptNode', {
|
|
|
2078
1981
|
enumerable: true,
|
|
2079
1982
|
get: function () { return sdk.loadScriptNode; }
|
|
2080
1983
|
});
|
|
2081
|
-
exports.registerGlobalPlugins = share.registerGlobalPlugins;
|
|
2082
1984
|
exports.FederationHost = FederationHost;
|
|
2083
1985
|
exports.getInstance = getInstance;
|
|
2084
1986
|
exports.getRemoteEntry = getRemoteEntry;
|