@module-federation/runtime 0.1.18 → 0.1.20
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 +111 -42
- package/dist/index.esm.js +112 -43
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +1 -1
- package/dist/src/core.d.ts +3 -1
- package/dist/src/remote/index.d.ts +5 -1
- package/dist/src/shared/index.d.ts +6 -2
- package/dist/src/type/config.d.ts +1 -1
- package/dist/src/utils/preload.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -264,14 +264,14 @@ let Module = class Module {
|
|
|
264
264
|
version: this.remoteInfo.version || ''
|
|
265
265
|
};
|
|
266
266
|
// Help to find host instance
|
|
267
|
-
Object.defineProperty(remoteEntryInitOptions, '
|
|
268
|
-
value:
|
|
267
|
+
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
268
|
+
value: localShareScopeMap,
|
|
269
269
|
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
270
270
|
enumerable: false
|
|
271
271
|
});
|
|
272
272
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
273
273
|
shareScope,
|
|
274
|
-
// @ts-ignore
|
|
274
|
+
// @ts-ignore shareScopeMap will be set by Object.defineProperty
|
|
275
275
|
remoteEntryInitOptions,
|
|
276
276
|
initScope,
|
|
277
277
|
remoteInfo: this.remoteInfo,
|
|
@@ -296,7 +296,7 @@ let Module = class Module {
|
|
|
296
296
|
}
|
|
297
297
|
wraperFactory(moduleFactory, id) {
|
|
298
298
|
function defineModuleId(res, id) {
|
|
299
|
-
if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
299
|
+
if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
300
300
|
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
301
301
|
value: id,
|
|
302
302
|
enumerable: false
|
|
@@ -563,7 +563,8 @@ function normalizePreloadExposes(exposes) {
|
|
|
563
563
|
return expose;
|
|
564
564
|
});
|
|
565
565
|
}
|
|
566
|
-
function preloadAssets(remoteInfo, host, assets
|
|
566
|
+
function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
|
|
567
|
+
useLinkPreload = true) {
|
|
567
568
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
568
569
|
if (host.options.inBrowser) {
|
|
569
570
|
entryAssets.forEach((asset)=>{
|
|
@@ -615,40 +616,96 @@ function preloadAssets(remoteInfo, host, assets) {
|
|
|
615
616
|
});
|
|
616
617
|
}
|
|
617
618
|
});
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
619
|
+
if (useLinkPreload) {
|
|
620
|
+
cssAssets.forEach((cssUrl)=>{
|
|
621
|
+
const { link: cssEl, needAttach } = sdk.createLink({
|
|
622
|
+
url: cssUrl,
|
|
623
|
+
cb: ()=>{},
|
|
624
|
+
attrs: {
|
|
625
|
+
rel: 'preload',
|
|
626
|
+
as: 'style',
|
|
627
|
+
crossorigin: 'anonymous'
|
|
628
|
+
},
|
|
629
|
+
createLinkHook: (url)=>{
|
|
630
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
631
|
+
url
|
|
632
|
+
});
|
|
633
|
+
if (res instanceof HTMLLinkElement) {
|
|
634
|
+
return res;
|
|
635
|
+
}
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
626
638
|
});
|
|
627
|
-
|
|
628
|
-
return res;
|
|
629
|
-
}
|
|
630
|
-
return;
|
|
639
|
+
needAttach && document.head.appendChild(cssEl);
|
|
631
640
|
});
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
641
|
+
} else {
|
|
642
|
+
cssAssets.forEach((cssUrl)=>{
|
|
643
|
+
const { link: cssEl, needAttach } = sdk.createLink({
|
|
644
|
+
url: cssUrl,
|
|
645
|
+
cb: ()=>{},
|
|
646
|
+
attrs: {
|
|
647
|
+
rel: 'stylesheet',
|
|
648
|
+
type: 'text/css'
|
|
649
|
+
},
|
|
650
|
+
createLinkHook: (url)=>{
|
|
651
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
652
|
+
url
|
|
653
|
+
});
|
|
654
|
+
if (res instanceof HTMLLinkElement) {
|
|
655
|
+
return res;
|
|
656
|
+
}
|
|
657
|
+
return;
|
|
658
|
+
},
|
|
659
|
+
needDeleteLink: false
|
|
643
660
|
});
|
|
644
|
-
|
|
645
|
-
return res;
|
|
646
|
-
}
|
|
647
|
-
return;
|
|
661
|
+
needAttach && document.head.appendChild(cssEl);
|
|
648
662
|
});
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
663
|
+
}
|
|
664
|
+
if (useLinkPreload) {
|
|
665
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
666
|
+
const { link: linkEl, needAttach } = sdk.createLink({
|
|
667
|
+
url: jsUrl,
|
|
668
|
+
cb: ()=>{},
|
|
669
|
+
attrs: {
|
|
670
|
+
rel: 'preload',
|
|
671
|
+
as: 'script',
|
|
672
|
+
crossorigin: 'anonymous'
|
|
673
|
+
},
|
|
674
|
+
createLinkHook: (url)=>{
|
|
675
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
676
|
+
url
|
|
677
|
+
});
|
|
678
|
+
if (res instanceof HTMLLinkElement) {
|
|
679
|
+
return res;
|
|
680
|
+
}
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
needAttach && document.head.appendChild(linkEl);
|
|
685
|
+
});
|
|
686
|
+
} else {
|
|
687
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
688
|
+
const { script: scriptEl, needAttach } = sdk.createScript({
|
|
689
|
+
url: jsUrl,
|
|
690
|
+
cb: ()=>{},
|
|
691
|
+
attrs: {
|
|
692
|
+
crossorigin: 'anonymous',
|
|
693
|
+
fetchpriority: 'high'
|
|
694
|
+
},
|
|
695
|
+
createScriptHook: (url)=>{
|
|
696
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
697
|
+
url
|
|
698
|
+
});
|
|
699
|
+
if (res instanceof HTMLScriptElement) {
|
|
700
|
+
return res;
|
|
701
|
+
}
|
|
702
|
+
return;
|
|
703
|
+
},
|
|
704
|
+
needDeleteScript: true
|
|
705
|
+
});
|
|
706
|
+
needAttach && document.head.appendChild(scriptEl);
|
|
707
|
+
});
|
|
708
|
+
}
|
|
652
709
|
}
|
|
653
710
|
}
|
|
654
711
|
|
|
@@ -711,7 +768,7 @@ function snapshotPlugin() {
|
|
|
711
768
|
globalSnapshot
|
|
712
769
|
});
|
|
713
770
|
if (assets) {
|
|
714
|
-
preloadAssets(remoteInfo, origin, assets);
|
|
771
|
+
preloadAssets(remoteInfo, origin, assets, false);
|
|
715
772
|
}
|
|
716
773
|
return _extends$4({}, args, {
|
|
717
774
|
remoteSnapshot
|
|
@@ -1424,13 +1481,15 @@ class SharedHandler {
|
|
|
1424
1481
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1425
1482
|
`);
|
|
1426
1483
|
}
|
|
1427
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1484
|
+
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1428
1485
|
const { host } = this;
|
|
1429
1486
|
this.shareScopeMap[scopeName] = shareScope;
|
|
1430
1487
|
this.hooks.lifecycle.initContainerShareScopeMap.emit({
|
|
1431
1488
|
shareScope,
|
|
1432
1489
|
options: host.options,
|
|
1433
|
-
origin: host
|
|
1490
|
+
origin: host,
|
|
1491
|
+
scopeName,
|
|
1492
|
+
hostShareScopeMap: extraOptions.hostShareScopeMap
|
|
1434
1493
|
});
|
|
1435
1494
|
}
|
|
1436
1495
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
@@ -1481,7 +1540,7 @@ class SharedHandler {
|
|
|
1481
1540
|
loadShare: new AsyncHook(),
|
|
1482
1541
|
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1483
1542
|
// maybe will change, temporarily for internal use only
|
|
1484
|
-
initContainerShareScopeMap: new
|
|
1543
|
+
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
1485
1544
|
});
|
|
1486
1545
|
this.host = host;
|
|
1487
1546
|
this.shareScopeMap = {};
|
|
@@ -1660,6 +1719,7 @@ class RemoteHandler {
|
|
|
1660
1719
|
};
|
|
1661
1720
|
}
|
|
1662
1721
|
registerRemote(remote, targetRemotes, options) {
|
|
1722
|
+
const { host } = this;
|
|
1663
1723
|
const normalizeRemote = ()=>{
|
|
1664
1724
|
if (remote.alias) {
|
|
1665
1725
|
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
@@ -1687,6 +1747,10 @@ class RemoteHandler {
|
|
|
1687
1747
|
if (!registeredRemote) {
|
|
1688
1748
|
normalizeRemote();
|
|
1689
1749
|
targetRemotes.push(remote);
|
|
1750
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
1751
|
+
remote,
|
|
1752
|
+
origin: host
|
|
1753
|
+
});
|
|
1690
1754
|
} else {
|
|
1691
1755
|
const messages = [
|
|
1692
1756
|
`The remote "${remote.name}" is already registered.`,
|
|
@@ -1697,6 +1761,10 @@ class RemoteHandler {
|
|
|
1697
1761
|
this.removeRemote(registeredRemote);
|
|
1698
1762
|
normalizeRemote();
|
|
1699
1763
|
targetRemotes.push(remote);
|
|
1764
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
1765
|
+
remote,
|
|
1766
|
+
origin: host
|
|
1767
|
+
});
|
|
1700
1768
|
}
|
|
1701
1769
|
sdk.warn(messages.join(' '));
|
|
1702
1770
|
}
|
|
@@ -1781,6 +1849,7 @@ class RemoteHandler {
|
|
|
1781
1849
|
}
|
|
1782
1850
|
constructor(host){
|
|
1783
1851
|
this.hooks = new PluginSystem({
|
|
1852
|
+
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
1784
1853
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1785
1854
|
onLoad: new AsyncHook('onLoad'),
|
|
1786
1855
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
@@ -1850,8 +1919,8 @@ class FederationHost {
|
|
|
1850
1919
|
async preloadRemote(preloadOptions) {
|
|
1851
1920
|
return this.remoteHandler.preloadRemote(preloadOptions);
|
|
1852
1921
|
}
|
|
1853
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1854
|
-
this.sharedHandler.initShareScopeMap(scopeName, shareScope);
|
|
1922
|
+
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1923
|
+
this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
|
|
1855
1924
|
}
|
|
1856
1925
|
formatOptions(globalOptions, userOptions) {
|
|
1857
1926
|
const { shared } = share.formatShareConfigs(globalOptions, userOptions);
|
|
@@ -1913,7 +1982,7 @@ class FederationHost {
|
|
|
1913
1982
|
// maybe will change, temporarily for internal use only
|
|
1914
1983
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1915
1984
|
});
|
|
1916
|
-
this.version = "0.1.
|
|
1985
|
+
this.version = "0.1.20";
|
|
1917
1986
|
this.moduleCache = new Map();
|
|
1918
1987
|
this.loaderHook = new PluginSystem({
|
|
1919
1988
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { g as getGlobalHostPlugins, a as globalLoading, D as DEFAULT_REMOTE_TYPE, b as DEFAULT_SCOPE, c as getRemoteEntryExports, d as assert, s as safeToString, e as getFMId, i as isObject, f as error, w as warn, h as isPlainObject, j as isRemoteInfoWithEntry, k as isPureRemoteEntry, l as isBrowserEnv, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getRegisteredShare, q as arrayOptions, r as getGlobalSnapshotInfoByModuleInfo, t as addGlobalSnapshot, u as setGlobalSnapshotInfoByModuleInfo, v as getGlobalSnapshot, G as Global, x as formatShareConfigs, y as getTargetSharedOptions, z as getGlobalShareScope, A as addUniqueItem, B as getBuilderId, C as setGlobalFederationConstructor, E as getGlobalFederationInstance, F as getGlobalFederationConstructor, H as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { I as registerGlobalPlugins } from './share.esm.js';
|
|
3
|
-
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv as isBrowserEnv$1 } from '@module-federation/sdk';
|
|
3
|
+
import { loadScriptNode, loadScript, composeKeyWithSeparator, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1, isBrowserEnv as isBrowserEnv$1 } from '@module-federation/sdk';
|
|
4
4
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
5
5
|
|
|
6
6
|
// Function to match a remote with its name and expose
|
|
@@ -262,14 +262,14 @@ let Module = class Module {
|
|
|
262
262
|
version: this.remoteInfo.version || ''
|
|
263
263
|
};
|
|
264
264
|
// Help to find host instance
|
|
265
|
-
Object.defineProperty(remoteEntryInitOptions, '
|
|
266
|
-
value:
|
|
265
|
+
Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {
|
|
266
|
+
value: localShareScopeMap,
|
|
267
267
|
// remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed
|
|
268
268
|
enumerable: false
|
|
269
269
|
});
|
|
270
270
|
const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
|
|
271
271
|
shareScope,
|
|
272
|
-
// @ts-ignore
|
|
272
|
+
// @ts-ignore shareScopeMap will be set by Object.defineProperty
|
|
273
273
|
remoteEntryInitOptions,
|
|
274
274
|
initScope,
|
|
275
275
|
remoteInfo: this.remoteInfo,
|
|
@@ -294,7 +294,7 @@ let Module = class Module {
|
|
|
294
294
|
}
|
|
295
295
|
wraperFactory(moduleFactory, id) {
|
|
296
296
|
function defineModuleId(res, id) {
|
|
297
|
-
if (res && typeof res === 'object' && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
297
|
+
if (res && typeof res === 'object' && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))) {
|
|
298
298
|
Object.defineProperty(res, Symbol.for('mf_module_id'), {
|
|
299
299
|
value: id,
|
|
300
300
|
enumerable: false
|
|
@@ -561,7 +561,8 @@ function normalizePreloadExposes(exposes) {
|
|
|
561
561
|
return expose;
|
|
562
562
|
});
|
|
563
563
|
}
|
|
564
|
-
function preloadAssets(remoteInfo, host, assets
|
|
564
|
+
function preloadAssets(remoteInfo, host, assets, // It is used to distinguish preload from load remote parallel loading
|
|
565
|
+
useLinkPreload = true) {
|
|
565
566
|
const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
|
|
566
567
|
if (host.options.inBrowser) {
|
|
567
568
|
entryAssets.forEach((asset)=>{
|
|
@@ -613,40 +614,96 @@ function preloadAssets(remoteInfo, host, assets) {
|
|
|
613
614
|
});
|
|
614
615
|
}
|
|
615
616
|
});
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
617
|
+
if (useLinkPreload) {
|
|
618
|
+
cssAssets.forEach((cssUrl)=>{
|
|
619
|
+
const { link: cssEl, needAttach } = createLink({
|
|
620
|
+
url: cssUrl,
|
|
621
|
+
cb: ()=>{},
|
|
622
|
+
attrs: {
|
|
623
|
+
rel: 'preload',
|
|
624
|
+
as: 'style',
|
|
625
|
+
crossorigin: 'anonymous'
|
|
626
|
+
},
|
|
627
|
+
createLinkHook: (url)=>{
|
|
628
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
629
|
+
url
|
|
630
|
+
});
|
|
631
|
+
if (res instanceof HTMLLinkElement) {
|
|
632
|
+
return res;
|
|
633
|
+
}
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
624
636
|
});
|
|
625
|
-
|
|
626
|
-
return res;
|
|
627
|
-
}
|
|
628
|
-
return;
|
|
637
|
+
needAttach && document.head.appendChild(cssEl);
|
|
629
638
|
});
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
639
|
+
} else {
|
|
640
|
+
cssAssets.forEach((cssUrl)=>{
|
|
641
|
+
const { link: cssEl, needAttach } = createLink({
|
|
642
|
+
url: cssUrl,
|
|
643
|
+
cb: ()=>{},
|
|
644
|
+
attrs: {
|
|
645
|
+
rel: 'stylesheet',
|
|
646
|
+
type: 'text/css'
|
|
647
|
+
},
|
|
648
|
+
createLinkHook: (url)=>{
|
|
649
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
650
|
+
url
|
|
651
|
+
});
|
|
652
|
+
if (res instanceof HTMLLinkElement) {
|
|
653
|
+
return res;
|
|
654
|
+
}
|
|
655
|
+
return;
|
|
656
|
+
},
|
|
657
|
+
needDeleteLink: false
|
|
641
658
|
});
|
|
642
|
-
|
|
643
|
-
return res;
|
|
644
|
-
}
|
|
645
|
-
return;
|
|
659
|
+
needAttach && document.head.appendChild(cssEl);
|
|
646
660
|
});
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
661
|
+
}
|
|
662
|
+
if (useLinkPreload) {
|
|
663
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
664
|
+
const { link: linkEl, needAttach } = createLink({
|
|
665
|
+
url: jsUrl,
|
|
666
|
+
cb: ()=>{},
|
|
667
|
+
attrs: {
|
|
668
|
+
rel: 'preload',
|
|
669
|
+
as: 'script',
|
|
670
|
+
crossorigin: 'anonymous'
|
|
671
|
+
},
|
|
672
|
+
createLinkHook: (url)=>{
|
|
673
|
+
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
674
|
+
url
|
|
675
|
+
});
|
|
676
|
+
if (res instanceof HTMLLinkElement) {
|
|
677
|
+
return res;
|
|
678
|
+
}
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
needAttach && document.head.appendChild(linkEl);
|
|
683
|
+
});
|
|
684
|
+
} else {
|
|
685
|
+
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
686
|
+
const { script: scriptEl, needAttach } = createScript({
|
|
687
|
+
url: jsUrl,
|
|
688
|
+
cb: ()=>{},
|
|
689
|
+
attrs: {
|
|
690
|
+
crossorigin: 'anonymous',
|
|
691
|
+
fetchpriority: 'high'
|
|
692
|
+
},
|
|
693
|
+
createScriptHook: (url)=>{
|
|
694
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
695
|
+
url
|
|
696
|
+
});
|
|
697
|
+
if (res instanceof HTMLScriptElement) {
|
|
698
|
+
return res;
|
|
699
|
+
}
|
|
700
|
+
return;
|
|
701
|
+
},
|
|
702
|
+
needDeleteScript: true
|
|
703
|
+
});
|
|
704
|
+
needAttach && document.head.appendChild(scriptEl);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
650
707
|
}
|
|
651
708
|
}
|
|
652
709
|
|
|
@@ -709,7 +766,7 @@ function snapshotPlugin() {
|
|
|
709
766
|
globalSnapshot
|
|
710
767
|
});
|
|
711
768
|
if (assets) {
|
|
712
|
-
preloadAssets(remoteInfo, origin, assets);
|
|
769
|
+
preloadAssets(remoteInfo, origin, assets, false);
|
|
713
770
|
}
|
|
714
771
|
return _extends$4({}, args, {
|
|
715
772
|
remoteSnapshot
|
|
@@ -1422,13 +1479,15 @@ class SharedHandler {
|
|
|
1422
1479
|
2. The ${pkgName} share was not registered with the 'lib' attribute.\n
|
|
1423
1480
|
`);
|
|
1424
1481
|
}
|
|
1425
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1482
|
+
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1426
1483
|
const { host } = this;
|
|
1427
1484
|
this.shareScopeMap[scopeName] = shareScope;
|
|
1428
1485
|
this.hooks.lifecycle.initContainerShareScopeMap.emit({
|
|
1429
1486
|
shareScope,
|
|
1430
1487
|
options: host.options,
|
|
1431
|
-
origin: host
|
|
1488
|
+
origin: host,
|
|
1489
|
+
scopeName,
|
|
1490
|
+
hostShareScopeMap: extraOptions.hostShareScopeMap
|
|
1432
1491
|
});
|
|
1433
1492
|
}
|
|
1434
1493
|
setShared({ pkgName, shared, from, lib, loading, loaded, get }) {
|
|
@@ -1479,7 +1538,7 @@ class SharedHandler {
|
|
|
1479
1538
|
loadShare: new AsyncHook(),
|
|
1480
1539
|
resolveShare: new SyncWaterfallHook('resolveShare'),
|
|
1481
1540
|
// maybe will change, temporarily for internal use only
|
|
1482
|
-
initContainerShareScopeMap: new
|
|
1541
|
+
initContainerShareScopeMap: new SyncWaterfallHook('initContainerShareScopeMap')
|
|
1483
1542
|
});
|
|
1484
1543
|
this.host = host;
|
|
1485
1544
|
this.shareScopeMap = {};
|
|
@@ -1658,6 +1717,7 @@ class RemoteHandler {
|
|
|
1658
1717
|
};
|
|
1659
1718
|
}
|
|
1660
1719
|
registerRemote(remote, targetRemotes, options) {
|
|
1720
|
+
const { host } = this;
|
|
1661
1721
|
const normalizeRemote = ()=>{
|
|
1662
1722
|
if (remote.alias) {
|
|
1663
1723
|
// Validate if alias equals the prefix of remote.name and remote.alias, if so, throw an error
|
|
@@ -1685,6 +1745,10 @@ class RemoteHandler {
|
|
|
1685
1745
|
if (!registeredRemote) {
|
|
1686
1746
|
normalizeRemote();
|
|
1687
1747
|
targetRemotes.push(remote);
|
|
1748
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
1749
|
+
remote,
|
|
1750
|
+
origin: host
|
|
1751
|
+
});
|
|
1688
1752
|
} else {
|
|
1689
1753
|
const messages = [
|
|
1690
1754
|
`The remote "${remote.name}" is already registered.`,
|
|
@@ -1695,6 +1759,10 @@ class RemoteHandler {
|
|
|
1695
1759
|
this.removeRemote(registeredRemote);
|
|
1696
1760
|
normalizeRemote();
|
|
1697
1761
|
targetRemotes.push(remote);
|
|
1762
|
+
this.hooks.lifecycle.registerRemote.emit({
|
|
1763
|
+
remote,
|
|
1764
|
+
origin: host
|
|
1765
|
+
});
|
|
1698
1766
|
}
|
|
1699
1767
|
warn$1(messages.join(' '));
|
|
1700
1768
|
}
|
|
@@ -1779,6 +1847,7 @@ class RemoteHandler {
|
|
|
1779
1847
|
}
|
|
1780
1848
|
constructor(host){
|
|
1781
1849
|
this.hooks = new PluginSystem({
|
|
1850
|
+
registerRemote: new SyncWaterfallHook('registerRemote'),
|
|
1782
1851
|
beforeRequest: new AsyncWaterfallHook('beforeRequest'),
|
|
1783
1852
|
onLoad: new AsyncHook('onLoad'),
|
|
1784
1853
|
handlePreloadModule: new SyncHook('handlePreloadModule'),
|
|
@@ -1848,8 +1917,8 @@ class FederationHost {
|
|
|
1848
1917
|
async preloadRemote(preloadOptions) {
|
|
1849
1918
|
return this.remoteHandler.preloadRemote(preloadOptions);
|
|
1850
1919
|
}
|
|
1851
|
-
initShareScopeMap(scopeName, shareScope) {
|
|
1852
|
-
this.sharedHandler.initShareScopeMap(scopeName, shareScope);
|
|
1920
|
+
initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
|
|
1921
|
+
this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);
|
|
1853
1922
|
}
|
|
1854
1923
|
formatOptions(globalOptions, userOptions) {
|
|
1855
1924
|
const { shared } = formatShareConfigs(globalOptions, userOptions);
|
|
@@ -1911,7 +1980,7 @@ class FederationHost {
|
|
|
1911
1980
|
// maybe will change, temporarily for internal use only
|
|
1912
1981
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
1913
1982
|
});
|
|
1914
|
-
this.version = "0.1.
|
|
1983
|
+
this.version = "0.1.20";
|
|
1915
1984
|
this.moduleCache = new Map();
|
|
1916
1985
|
this.loaderHook = new PluginSystem({
|
|
1917
1986
|
// FIXME: may not be suitable , not open to the public yet
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -190,7 +190,7 @@ function getGlobalFederationConstructor() {
|
|
|
190
190
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
191
191
|
if (isDebug) {
|
|
192
192
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
193
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.
|
|
193
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.20";
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -188,7 +188,7 @@ function getGlobalFederationConstructor() {
|
|
|
188
188
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
189
189
|
if (isDebug) {
|
|
190
190
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
191
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.
|
|
191
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.1.20";
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/src/core.d.ts
CHANGED
|
@@ -74,7 +74,9 @@ export declare class FederationHost {
|
|
|
74
74
|
from: 'build' | 'runtime';
|
|
75
75
|
}): Promise<T | null>;
|
|
76
76
|
preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void>;
|
|
77
|
-
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]
|
|
77
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
|
|
78
|
+
hostShareScopeMap?: ShareScopeMap;
|
|
79
|
+
}): void;
|
|
78
80
|
private formatOptions;
|
|
79
81
|
registerPlugins(plugins: UserOptions['plugins']): void;
|
|
80
82
|
registerRemotes(remotes: Remote[], options?: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ModuleInfo, type GlobalModuleInfo } from '@module-federation/sdk';
|
|
2
2
|
import { Options, UserOptions, PreloadAssets, PreloadOptions, PreloadRemoteArgs, Remote, RemoteInfo } from '../type';
|
|
3
3
|
import { FederationHost } from '../core';
|
|
4
|
-
import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook } from '../utils/hooks';
|
|
4
|
+
import { PluginSystem, AsyncHook, AsyncWaterfallHook, SyncHook, SyncWaterfallHook } from '../utils/hooks';
|
|
5
5
|
import { Module, ModuleOptions } from '../module';
|
|
6
6
|
export interface LoadRemoteMatch {
|
|
7
7
|
id: string;
|
|
@@ -16,6 +16,10 @@ export interface LoadRemoteMatch {
|
|
|
16
16
|
export declare class RemoteHandler {
|
|
17
17
|
host: FederationHost;
|
|
18
18
|
hooks: PluginSystem<{
|
|
19
|
+
registerRemote: SyncWaterfallHook<{
|
|
20
|
+
remote: Remote;
|
|
21
|
+
origin: FederationHost;
|
|
22
|
+
}>;
|
|
19
23
|
beforeRequest: AsyncWaterfallHook<{
|
|
20
24
|
id: string;
|
|
21
25
|
options: Options;
|
|
@@ -23,10 +23,12 @@ export declare class SharedHandler {
|
|
|
23
23
|
GlobalFederation: Federation;
|
|
24
24
|
resolver: () => Shared | undefined;
|
|
25
25
|
}>;
|
|
26
|
-
initContainerShareScopeMap:
|
|
26
|
+
initContainerShareScopeMap: SyncWaterfallHook<{
|
|
27
27
|
shareScope: ShareScopeMap[string];
|
|
28
28
|
options: Options;
|
|
29
29
|
origin: FederationHost;
|
|
30
|
+
scopeName: string;
|
|
31
|
+
hostShareScopeMap?: ShareScopeMap | undefined;
|
|
30
32
|
}>;
|
|
31
33
|
}>;
|
|
32
34
|
constructor(host: FederationHost);
|
|
@@ -50,7 +52,9 @@ export declare class SharedHandler {
|
|
|
50
52
|
customShareInfo?: Partial<Shared>;
|
|
51
53
|
resolver?: (sharedOptions: ShareInfos[string]) => Shared;
|
|
52
54
|
}): () => T | never;
|
|
53
|
-
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string]
|
|
55
|
+
initShareScopeMap(scopeName: string, shareScope: ShareScopeMap[string], extraOptions?: {
|
|
56
|
+
hostShareScopeMap?: ShareScopeMap;
|
|
57
|
+
}): void;
|
|
54
58
|
private setShared;
|
|
55
59
|
private _setGlobalShareScopeMap;
|
|
56
60
|
}
|
|
@@ -3,4 +3,4 @@ import { FederationHost } from '../core';
|
|
|
3
3
|
export declare function defaultPreloadArgs(preloadConfig: PreloadRemoteArgs | depsPreloadArg): PreloadConfig;
|
|
4
4
|
export declare function formatPreloadArgs(remotes: Array<Remote>, preloadArgs: Array<PreloadRemoteArgs>): PreloadOptions;
|
|
5
5
|
export declare function normalizePreloadExposes(exposes?: string[]): string[];
|
|
6
|
-
export declare function preloadAssets(remoteInfo: RemoteInfo, host: FederationHost, assets: PreloadAssets): void;
|
|
6
|
+
export declare function preloadAssets(remoteInfo: RemoteInfo, host: FederationHost, assets: PreloadAssets, useLinkPreload?: boolean): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.1.
|
|
48
|
+
"@module-federation/sdk": "0.1.20"
|
|
49
49
|
}
|
|
50
50
|
}
|