@module-federation/runtime 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +29 -10
- package/dist/index.esm.js +29 -10
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +8 -5
- package/dist/share.esm.js +8 -5
- package/dist/src/core.d.ts +7 -3
- package/dist/src/remote/index.d.ts +3 -3
- package/dist/src/shared/index.d.ts +7 -2
- package/dist/src/type/config.d.ts +9 -2
- package/dist/src/utils/share.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1300,7 +1300,9 @@ class SharedHandler {
|
|
|
1300
1300
|
});
|
|
1301
1301
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1302
1302
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1303
|
-
await Promise.all(this.initializeSharing(shareScope,
|
|
1303
|
+
await Promise.all(this.initializeSharing(shareScope, {
|
|
1304
|
+
strategy: shareInfo.strategy
|
|
1305
|
+
}));
|
|
1304
1306
|
return;
|
|
1305
1307
|
}));
|
|
1306
1308
|
}
|
|
@@ -1388,8 +1390,22 @@ class SharedHandler {
|
|
|
1388
1390
|
* It accepts one argument, the name of the share scope.
|
|
1389
1391
|
* If the share scope does not exist, it creates one.
|
|
1390
1392
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1391
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE,
|
|
1393
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, extraOptions) {
|
|
1392
1394
|
const { host } = this;
|
|
1395
|
+
const from = extraOptions == null ? void 0 : extraOptions.from;
|
|
1396
|
+
const strategy = extraOptions == null ? void 0 : extraOptions.strategy;
|
|
1397
|
+
let initScope = extraOptions == null ? void 0 : extraOptions.initScope;
|
|
1398
|
+
const promises = [];
|
|
1399
|
+
if (from !== 'build') {
|
|
1400
|
+
const { initTokens } = this;
|
|
1401
|
+
if (!initScope) initScope = [];
|
|
1402
|
+
let initToken = initTokens[shareScopeName];
|
|
1403
|
+
if (!initToken) initToken = initTokens[shareScopeName] = {
|
|
1404
|
+
from: this.host.name
|
|
1405
|
+
};
|
|
1406
|
+
if (initScope.indexOf(initToken) >= 0) return promises;
|
|
1407
|
+
initScope.push(initToken);
|
|
1408
|
+
}
|
|
1393
1409
|
const shareScope = this.shareScopeMap;
|
|
1394
1410
|
const hostName = host.options.name;
|
|
1395
1411
|
// Creates a new share scope if necessary
|
|
@@ -1409,8 +1425,7 @@ class SharedHandler {
|
|
|
1409
1425
|
versions[version] = shared;
|
|
1410
1426
|
}
|
|
1411
1427
|
};
|
|
1412
|
-
const
|
|
1413
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1428
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
1414
1429
|
const initRemoteModule = async (key)=>{
|
|
1415
1430
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
1416
1431
|
id: key
|
|
@@ -1418,7 +1433,7 @@ class SharedHandler {
|
|
|
1418
1433
|
if (module.getEntry) {
|
|
1419
1434
|
const entry = await module.getEntry();
|
|
1420
1435
|
if (!module.inited) {
|
|
1421
|
-
initFn(entry);
|
|
1436
|
+
await initFn(entry);
|
|
1422
1437
|
module.inited = true;
|
|
1423
1438
|
}
|
|
1424
1439
|
}
|
|
@@ -1431,7 +1446,8 @@ class SharedHandler {
|
|
|
1431
1446
|
}
|
|
1432
1447
|
});
|
|
1433
1448
|
});
|
|
1434
|
-
|
|
1449
|
+
// TODO: strategy==='version-first' need to be removed in the future
|
|
1450
|
+
if (host.options.shareStrategy === 'version-first' || strategy === 'version-first') {
|
|
1435
1451
|
host.options.remotes.forEach((remote)=>{
|
|
1436
1452
|
if (remote.shareScope === shareScopeName) {
|
|
1437
1453
|
promises.push(initRemoteModule(remote.name));
|
|
@@ -1453,7 +1469,9 @@ class SharedHandler {
|
|
|
1453
1469
|
});
|
|
1454
1470
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1455
1471
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1456
|
-
this.initializeSharing(shareScope,
|
|
1472
|
+
this.initializeSharing(shareScope, {
|
|
1473
|
+
strategy: shareInfo.strategy
|
|
1474
|
+
});
|
|
1457
1475
|
});
|
|
1458
1476
|
}
|
|
1459
1477
|
const registeredShared = share.getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
@@ -1585,6 +1603,7 @@ class SharedHandler {
|
|
|
1585
1603
|
});
|
|
1586
1604
|
this.host = host;
|
|
1587
1605
|
this.shareScopeMap = {};
|
|
1606
|
+
this.initTokens = {};
|
|
1588
1607
|
this._setGlobalShareScopeMap(host.options);
|
|
1589
1608
|
}
|
|
1590
1609
|
}
|
|
@@ -1989,8 +2008,8 @@ class FederationHost {
|
|
|
1989
2008
|
loadShareSync(pkgName, extraOptions) {
|
|
1990
2009
|
return this.sharedHandler.loadShareSync(pkgName, extraOptions);
|
|
1991
2010
|
}
|
|
1992
|
-
initializeSharing(shareScopeName = share.DEFAULT_SCOPE,
|
|
1993
|
-
return this.sharedHandler.initializeSharing(shareScopeName,
|
|
2011
|
+
initializeSharing(shareScopeName = share.DEFAULT_SCOPE, extraOptions) {
|
|
2012
|
+
return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
|
|
1994
2013
|
}
|
|
1995
2014
|
initRawContainer(name, url, container) {
|
|
1996
2015
|
const remoteInfo = getRemoteInfo({
|
|
@@ -2077,7 +2096,7 @@ class FederationHost {
|
|
|
2077
2096
|
// maybe will change, temporarily for internal use only
|
|
2078
2097
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2079
2098
|
});
|
|
2080
|
-
this.version = "0.5.
|
|
2099
|
+
this.version = "0.5.2";
|
|
2081
2100
|
this.moduleCache = new Map();
|
|
2082
2101
|
this.loaderHook = new PluginSystem({
|
|
2083
2102
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/index.esm.js
CHANGED
|
@@ -1298,7 +1298,9 @@ class SharedHandler {
|
|
|
1298
1298
|
});
|
|
1299
1299
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1300
1300
|
await Promise.all(shareInfo.scope.map(async (shareScope)=>{
|
|
1301
|
-
await Promise.all(this.initializeSharing(shareScope,
|
|
1301
|
+
await Promise.all(this.initializeSharing(shareScope, {
|
|
1302
|
+
strategy: shareInfo.strategy
|
|
1303
|
+
}));
|
|
1302
1304
|
return;
|
|
1303
1305
|
}));
|
|
1304
1306
|
}
|
|
@@ -1386,8 +1388,22 @@ class SharedHandler {
|
|
|
1386
1388
|
* It accepts one argument, the name of the share scope.
|
|
1387
1389
|
* If the share scope does not exist, it creates one.
|
|
1388
1390
|
*/ // eslint-disable-next-line @typescript-eslint/member-ordering
|
|
1389
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE,
|
|
1391
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
1390
1392
|
const { host } = this;
|
|
1393
|
+
const from = extraOptions == null ? void 0 : extraOptions.from;
|
|
1394
|
+
const strategy = extraOptions == null ? void 0 : extraOptions.strategy;
|
|
1395
|
+
let initScope = extraOptions == null ? void 0 : extraOptions.initScope;
|
|
1396
|
+
const promises = [];
|
|
1397
|
+
if (from !== 'build') {
|
|
1398
|
+
const { initTokens } = this;
|
|
1399
|
+
if (!initScope) initScope = [];
|
|
1400
|
+
let initToken = initTokens[shareScopeName];
|
|
1401
|
+
if (!initToken) initToken = initTokens[shareScopeName] = {
|
|
1402
|
+
from: this.host.name
|
|
1403
|
+
};
|
|
1404
|
+
if (initScope.indexOf(initToken) >= 0) return promises;
|
|
1405
|
+
initScope.push(initToken);
|
|
1406
|
+
}
|
|
1391
1407
|
const shareScope = this.shareScopeMap;
|
|
1392
1408
|
const hostName = host.options.name;
|
|
1393
1409
|
// Creates a new share scope if necessary
|
|
@@ -1407,8 +1423,7 @@ class SharedHandler {
|
|
|
1407
1423
|
versions[version] = shared;
|
|
1408
1424
|
}
|
|
1409
1425
|
};
|
|
1410
|
-
const
|
|
1411
|
-
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName]);
|
|
1426
|
+
const initFn = (mod)=>mod && mod.init && mod.init(shareScope[shareScopeName], initScope);
|
|
1412
1427
|
const initRemoteModule = async (key)=>{
|
|
1413
1428
|
const { module } = await host.remoteHandler.getRemoteModuleAndOptions({
|
|
1414
1429
|
id: key
|
|
@@ -1416,7 +1431,7 @@ class SharedHandler {
|
|
|
1416
1431
|
if (module.getEntry) {
|
|
1417
1432
|
const entry = await module.getEntry();
|
|
1418
1433
|
if (!module.inited) {
|
|
1419
|
-
initFn(entry);
|
|
1434
|
+
await initFn(entry);
|
|
1420
1435
|
module.inited = true;
|
|
1421
1436
|
}
|
|
1422
1437
|
}
|
|
@@ -1429,7 +1444,8 @@ class SharedHandler {
|
|
|
1429
1444
|
}
|
|
1430
1445
|
});
|
|
1431
1446
|
});
|
|
1432
|
-
|
|
1447
|
+
// TODO: strategy==='version-first' need to be removed in the future
|
|
1448
|
+
if (host.options.shareStrategy === 'version-first' || strategy === 'version-first') {
|
|
1433
1449
|
host.options.remotes.forEach((remote)=>{
|
|
1434
1450
|
if (remote.shareScope === shareScopeName) {
|
|
1435
1451
|
promises.push(initRemoteModule(remote.name));
|
|
@@ -1451,7 +1467,9 @@ class SharedHandler {
|
|
|
1451
1467
|
});
|
|
1452
1468
|
if (shareInfo == null ? void 0 : shareInfo.scope) {
|
|
1453
1469
|
shareInfo.scope.forEach((shareScope)=>{
|
|
1454
|
-
this.initializeSharing(shareScope,
|
|
1470
|
+
this.initializeSharing(shareScope, {
|
|
1471
|
+
strategy: shareInfo.strategy
|
|
1472
|
+
});
|
|
1455
1473
|
});
|
|
1456
1474
|
}
|
|
1457
1475
|
const registeredShared = getRegisteredShare(this.shareScopeMap, pkgName, shareInfo, this.hooks.lifecycle.resolveShare);
|
|
@@ -1583,6 +1601,7 @@ class SharedHandler {
|
|
|
1583
1601
|
});
|
|
1584
1602
|
this.host = host;
|
|
1585
1603
|
this.shareScopeMap = {};
|
|
1604
|
+
this.initTokens = {};
|
|
1586
1605
|
this._setGlobalShareScopeMap(host.options);
|
|
1587
1606
|
}
|
|
1588
1607
|
}
|
|
@@ -1987,8 +2006,8 @@ class FederationHost {
|
|
|
1987
2006
|
loadShareSync(pkgName, extraOptions) {
|
|
1988
2007
|
return this.sharedHandler.loadShareSync(pkgName, extraOptions);
|
|
1989
2008
|
}
|
|
1990
|
-
initializeSharing(shareScopeName = DEFAULT_SCOPE,
|
|
1991
|
-
return this.sharedHandler.initializeSharing(shareScopeName,
|
|
2009
|
+
initializeSharing(shareScopeName = DEFAULT_SCOPE, extraOptions) {
|
|
2010
|
+
return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);
|
|
1992
2011
|
}
|
|
1993
2012
|
initRawContainer(name, url, container) {
|
|
1994
2013
|
const remoteInfo = getRemoteInfo({
|
|
@@ -2075,7 +2094,7 @@ class FederationHost {
|
|
|
2075
2094
|
// maybe will change, temporarily for internal use only
|
|
2076
2095
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2077
2096
|
});
|
|
2078
|
-
this.version = "0.5.
|
|
2097
|
+
this.version = "0.5.2";
|
|
2079
2098
|
this.moduleCache = new Map();
|
|
2080
2099
|
this.loaderHook = new PluginSystem({
|
|
2081
2100
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -212,7 +212,7 @@ function getGlobalFederationConstructor() {
|
|
|
212
212
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
213
213
|
if (isDebug) {
|
|
214
214
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
215
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.
|
|
215
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.2";
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -685,7 +685,7 @@ function _extends() {
|
|
|
685
685
|
};
|
|
686
686
|
return _extends.apply(this, arguments);
|
|
687
687
|
}
|
|
688
|
-
function formatShare(shareArgs, from, name) {
|
|
688
|
+
function formatShare(shareArgs, from, name, shareStrategy) {
|
|
689
689
|
let get;
|
|
690
690
|
if ('get' in shareArgs) {
|
|
691
691
|
// eslint-disable-next-line prefer-destructuring
|
|
@@ -697,7 +697,10 @@ function formatShare(shareArgs, from, name) {
|
|
|
697
697
|
throw new Error(`Can not get shared '${name}'!`);
|
|
698
698
|
});
|
|
699
699
|
}
|
|
700
|
-
|
|
700
|
+
if (shareArgs.strategy) {
|
|
701
|
+
warn(`"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"`);
|
|
702
|
+
}
|
|
703
|
+
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
|
|
701
704
|
return _extends({
|
|
702
705
|
deps: [],
|
|
703
706
|
useIn: [],
|
|
@@ -716,7 +719,7 @@ function formatShare(shareArgs, from, name) {
|
|
|
716
719
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
717
720
|
(_shareArgs_scope = shareArgs.scope) != null ? _shareArgs_scope : 'default'
|
|
718
721
|
],
|
|
719
|
-
strategy: shareArgs.strategy || 'version-first'
|
|
722
|
+
strategy: ((_shareArgs_strategy = shareArgs.strategy) != null ? _shareArgs_strategy : shareStrategy) || 'version-first'
|
|
720
723
|
});
|
|
721
724
|
}
|
|
722
725
|
function formatShareConfigs(globalOptions, userOptions) {
|
|
@@ -726,7 +729,7 @@ function formatShareConfigs(globalOptions, userOptions) {
|
|
|
726
729
|
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
727
730
|
res[pkgName] = res[pkgName] || [];
|
|
728
731
|
arrayShareArgs.forEach((shareConfig)=>{
|
|
729
|
-
res[pkgName].push(formatShare(shareConfig, from, pkgName));
|
|
732
|
+
res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
|
|
730
733
|
});
|
|
731
734
|
return res;
|
|
732
735
|
}, {});
|
package/dist/share.esm.js
CHANGED
|
@@ -210,7 +210,7 @@ function getGlobalFederationConstructor() {
|
|
|
210
210
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
211
211
|
if (isDebug) {
|
|
212
212
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
213
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.
|
|
213
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.5.2";
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -683,7 +683,7 @@ function _extends() {
|
|
|
683
683
|
};
|
|
684
684
|
return _extends.apply(this, arguments);
|
|
685
685
|
}
|
|
686
|
-
function formatShare(shareArgs, from, name) {
|
|
686
|
+
function formatShare(shareArgs, from, name, shareStrategy) {
|
|
687
687
|
let get;
|
|
688
688
|
if ('get' in shareArgs) {
|
|
689
689
|
// eslint-disable-next-line prefer-destructuring
|
|
@@ -695,7 +695,10 @@ function formatShare(shareArgs, from, name) {
|
|
|
695
695
|
throw new Error(`Can not get shared '${name}'!`);
|
|
696
696
|
});
|
|
697
697
|
}
|
|
698
|
-
|
|
698
|
+
if (shareArgs.strategy) {
|
|
699
|
+
warn(`"shared.strategy is deprecated, please set in initOptions.shareStrategy instead!"`);
|
|
700
|
+
}
|
|
701
|
+
var _shareArgs_version, _shareArgs_scope, _shareArgs_strategy;
|
|
699
702
|
return _extends({
|
|
700
703
|
deps: [],
|
|
701
704
|
useIn: [],
|
|
@@ -714,7 +717,7 @@ function formatShare(shareArgs, from, name) {
|
|
|
714
717
|
scope: Array.isArray(shareArgs.scope) ? shareArgs.scope : [
|
|
715
718
|
(_shareArgs_scope = shareArgs.scope) != null ? _shareArgs_scope : 'default'
|
|
716
719
|
],
|
|
717
|
-
strategy: shareArgs.strategy || 'version-first'
|
|
720
|
+
strategy: ((_shareArgs_strategy = shareArgs.strategy) != null ? _shareArgs_strategy : shareStrategy) || 'version-first'
|
|
718
721
|
});
|
|
719
722
|
}
|
|
720
723
|
function formatShareConfigs(globalOptions, userOptions) {
|
|
@@ -724,7 +727,7 @@ function formatShareConfigs(globalOptions, userOptions) {
|
|
|
724
727
|
const arrayShareArgs = arrayOptions(shareArgs[pkgName]);
|
|
725
728
|
res[pkgName] = res[pkgName] || [];
|
|
726
729
|
arrayShareArgs.forEach((shareConfig)=>{
|
|
727
|
-
res[pkgName].push(formatShare(shareConfig, from, pkgName));
|
|
730
|
+
res[pkgName].push(formatShare(shareConfig, from, pkgName, userOptions.shareStrategy));
|
|
728
731
|
});
|
|
729
732
|
return res;
|
|
730
733
|
}, {});
|
package/dist/src/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CreateScriptHookReturn } from '@module-federation/sdk';
|
|
2
|
-
import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions } from './type';
|
|
2
|
+
import { Options, PreloadRemoteArgs, RemoteEntryExports, Remote, Shared, ShareInfos, UserOptions, RemoteInfo, ShareScopeMap, InitScope, RemoteEntryInitOptions, CallFrom } from './type';
|
|
3
3
|
import { Module } from './module';
|
|
4
4
|
import { AsyncHook, AsyncWaterfallHook, PluginSystem, SyncHook, SyncWaterfallHook } from './utils/hooks';
|
|
5
5
|
import { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';
|
|
@@ -69,11 +69,15 @@ export declare class FederationHost {
|
|
|
69
69
|
customShareInfo?: Partial<Shared>;
|
|
70
70
|
resolver?: (sharedOptions: ShareInfos[string]) => Shared;
|
|
71
71
|
}): () => T | never;
|
|
72
|
-
initializeSharing(shareScopeName?: string,
|
|
72
|
+
initializeSharing(shareScopeName?: string, extraOptions?: {
|
|
73
|
+
initScope?: InitScope;
|
|
74
|
+
from?: CallFrom;
|
|
75
|
+
strategy?: Shared['strategy'];
|
|
76
|
+
}): Array<Promise<void>>;
|
|
73
77
|
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
|
|
74
78
|
loadRemote<T>(id: string, options?: {
|
|
75
79
|
loadFactory?: boolean;
|
|
76
|
-
from:
|
|
80
|
+
from: CallFrom;
|
|
77
81
|
}): Promise<T | null>;
|
|
78
82
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
79
83
|
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
|
-
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports } from '../type';
|
|
2
|
+
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo, RemoteEntryExports, CallFrom } from '../type';
|
|
3
3
|
import { FederationHost } from '../core';
|
|
4
4
|
import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
|
|
5
5
|
import { Module, ModuleOptions } from '../module';
|
|
@@ -56,7 +56,7 @@ export declare class RemoteHandler {
|
|
|
56
56
|
id: string;
|
|
57
57
|
error: unknown;
|
|
58
58
|
options?: any;
|
|
59
|
-
from:
|
|
59
|
+
from: CallFrom;
|
|
60
60
|
lifecycle: "onLoad" | "beforeRequest";
|
|
61
61
|
origin: FederationHost;
|
|
62
62
|
}], unknown>;
|
|
@@ -89,7 +89,7 @@ export declare class RemoteHandler {
|
|
|
89
89
|
setIdToRemoteMap(id: string, remoteMatchInfo: LoadRemoteMatch): void;
|
|
90
90
|
loadRemote<T>(id: string, options?: {
|
|
91
91
|
loadFactory?: boolean;
|
|
92
|
-
from:
|
|
92
|
+
from: CallFrom;
|
|
93
93
|
}): Promise<T | null>;
|
|
94
94
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
95
95
|
registerRemotes(remotes: Remote[], options?: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Federation } from '../global';
|
|
2
|
-
import { Options, ShareScopeMap, ShareInfos, Shared, UserOptions } from '../type';
|
|
2
|
+
import { Options, ShareScopeMap, ShareInfos, Shared, UserOptions, ShareStrategy, InitScope, InitTokens, CallFrom } from '../type';
|
|
3
3
|
import { FederationHost } from '../core';
|
|
4
4
|
import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncWaterfallHook } from '../utils/hooks';
|
|
5
5
|
import { LoadRemoteMatch } from '../remote';
|
|
@@ -31,6 +31,7 @@ export declare class SharedHandler {
|
|
|
31
31
|
hostShareScopeMap?: ShareScopeMap;
|
|
32
32
|
}>;
|
|
33
33
|
}>;
|
|
34
|
+
initTokens: InitTokens;
|
|
34
35
|
constructor(host: FederationHost);
|
|
35
36
|
registerShared(globalOptions: Options, userOptions: UserOptions): {
|
|
36
37
|
shareInfos: ShareInfos;
|
|
@@ -47,7 +48,11 @@ export declare class SharedHandler {
|
|
|
47
48
|
* It accepts one argument, the name of the share scope.
|
|
48
49
|
* If the share scope does not exist, it creates one.
|
|
49
50
|
*/
|
|
50
|
-
initializeSharing(shareScopeName?: string,
|
|
51
|
+
initializeSharing(shareScopeName?: string, extraOptions?: {
|
|
52
|
+
initScope?: InitScope;
|
|
53
|
+
from?: CallFrom;
|
|
54
|
+
strategy?: ShareStrategy;
|
|
55
|
+
}): Array<Promise<void>>;
|
|
51
56
|
loadShareSync<T>(pkgName: string, extraOptions?: {
|
|
52
57
|
customShareInfo?: Partial<Shared>;
|
|
53
58
|
resolver?: (sharedOptions: ShareInfos[string]) => Shared;
|
|
@@ -49,6 +49,7 @@ export type ShareArgs = (SharedBaseArgs & {
|
|
|
49
49
|
}) | (SharedBaseArgs & {
|
|
50
50
|
lib: () => Module;
|
|
51
51
|
}) | SharedBaseArgs;
|
|
52
|
+
export type ShareStrategy = 'version-first' | 'loaded-first';
|
|
52
53
|
export type Shared = {
|
|
53
54
|
version: string;
|
|
54
55
|
get: SharedGetter;
|
|
@@ -61,7 +62,10 @@ export type Shared = {
|
|
|
61
62
|
loaded?: boolean;
|
|
62
63
|
loading?: null | Promise<any>;
|
|
63
64
|
eager?: boolean;
|
|
64
|
-
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated set in initOptions.shareStrategy instead
|
|
67
|
+
*/
|
|
68
|
+
strategy: ShareStrategy;
|
|
65
69
|
};
|
|
66
70
|
export type ShareScopeMap = {
|
|
67
71
|
[scope: string]: {
|
|
@@ -84,6 +88,7 @@ export interface Options {
|
|
|
84
88
|
shared: ShareInfos;
|
|
85
89
|
plugins: Array<FederationRuntimePlugin>;
|
|
86
90
|
inBrowser: boolean;
|
|
91
|
+
shareStrategy?: ShareStrategy;
|
|
87
92
|
}
|
|
88
93
|
export type UserOptions = Omit<Optional<Options, 'plugins'>, 'shared' | 'inBrowser'> & {
|
|
89
94
|
shared?: {
|
|
@@ -97,7 +102,9 @@ export type RemoteEntryInitOptions = {
|
|
|
97
102
|
version: string;
|
|
98
103
|
shareScopeMap: ShareScopeMap;
|
|
99
104
|
};
|
|
100
|
-
export type
|
|
105
|
+
export type InitTokens = Record<string, Record<string, any>>;
|
|
106
|
+
export type InitScope = InitTokens[];
|
|
107
|
+
export type CallFrom = 'build' | 'runtime';
|
|
101
108
|
export type RemoteEntryExports = {
|
|
102
109
|
get: (id: string) => () => Promise<Module>;
|
|
103
110
|
init: (shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void | Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Federation } from '../global';
|
|
2
|
-
import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap, LoadShareExtraOptions, UserOptions, Options } from '../type';
|
|
2
|
+
import { GlobalShareScopeMap, Shared, ShareArgs, ShareInfos, ShareScopeMap, LoadShareExtraOptions, UserOptions, Options, ShareStrategy } from '../type';
|
|
3
3
|
import { SyncWaterfallHook } from './hooks';
|
|
4
|
-
export declare function formatShare(shareArgs: ShareArgs, from: string, name: string): Shared;
|
|
4
|
+
export declare function formatShare(shareArgs: ShareArgs, from: string, name: string, shareStrategy?: ShareStrategy): Shared;
|
|
5
5
|
export declare function formatShareConfigs(globalOptions: Options, userOptions: UserOptions): {
|
|
6
6
|
shared: {
|
|
7
7
|
[x: string]: Shared[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@module-federation/sdk": "0.5.
|
|
56
|
+
"@module-federation/sdk": "0.5.2"
|
|
57
57
|
}
|
|
58
58
|
}
|