@module-federation/runtime 0.0.0-next-20240205101340 → 0.0.0-next-20240205220829
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/README.md +7 -1
- package/dist/index.cjs.js +19 -27
- package/dist/index.esm.js +20 -30
- package/dist/package.json +1 -1
- package/dist/share.cjs.js +1 -1
- package/dist/share.esm.js +2 -2
- package/dist/src/core.d.ts +2 -3
- package/dist/src/index.d.ts +1 -0
- package/dist/src/type/config.d.ts +1 -1
- package/dist/src/utils/index.d.ts +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -276,6 +276,9 @@ const runtimePlugin: () => FederationRuntimePlugin =
|
|
|
276
276
|
console.log('beforeInit: ', args);
|
|
277
277
|
return args;
|
|
278
278
|
},
|
|
279
|
+
errorLoadRemote(args) {
|
|
280
|
+
return args
|
|
281
|
+
},
|
|
279
282
|
beforeRequest(args) {
|
|
280
283
|
console.log('beforeRequest: ', args);
|
|
281
284
|
return args;
|
|
@@ -288,6 +291,9 @@ const runtimePlugin: () => FederationRuntimePlugin =
|
|
|
288
291
|
console.log('onLoad: ', args);
|
|
289
292
|
return args;
|
|
290
293
|
},
|
|
294
|
+
resolveShare(args) {
|
|
295
|
+
return args
|
|
296
|
+
},
|
|
291
297
|
async loadShare(args) {
|
|
292
298
|
console.log('loadShare:', args);
|
|
293
299
|
},
|
|
@@ -514,7 +520,7 @@ loadRemote('app2/un-existed-module').then(mod=>{
|
|
|
514
520
|
|
|
515
521
|
`AsyncWaterfallHook`
|
|
516
522
|
|
|
517
|
-
|
|
523
|
+
between federated apps.
|
|
518
524
|
|
|
519
525
|
* type
|
|
520
526
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -263,7 +263,7 @@ let Module = class Module {
|
|
|
263
263
|
remoteInfo: this.remoteInfo,
|
|
264
264
|
origin: this.host
|
|
265
265
|
});
|
|
266
|
-
|
|
266
|
+
remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
267
267
|
await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
|
|
268
268
|
remoteEntryExports
|
|
269
269
|
}));
|
|
@@ -561,38 +561,27 @@ function preloadAssets(remoteInfo, host, assets) {
|
|
|
561
561
|
});
|
|
562
562
|
const fragment = document.createDocumentFragment();
|
|
563
563
|
cssAssets.forEach((cssUrl)=>{
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
url
|
|
570
|
-
});
|
|
571
|
-
if (res instanceof HTMLLinkElement) {
|
|
572
|
-
return res;
|
|
573
|
-
}
|
|
574
|
-
return;
|
|
575
|
-
});
|
|
576
|
-
needAttach && fragment.appendChild(cssEl);
|
|
564
|
+
const cssEl = document.createElement('link');
|
|
565
|
+
cssEl.setAttribute('rel', 'preload');
|
|
566
|
+
cssEl.setAttribute('href', cssUrl);
|
|
567
|
+
cssEl.setAttribute('as', 'style');
|
|
568
|
+
fragment.appendChild(cssEl);
|
|
577
569
|
});
|
|
570
|
+
document.head.appendChild(fragment);
|
|
578
571
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
579
|
-
const {
|
|
572
|
+
const { script: scriptEl } = sdk.createScript(jsUrl, ()=>{
|
|
580
573
|
// noop
|
|
581
|
-
}, {
|
|
582
|
-
|
|
583
|
-
as: 'script'
|
|
584
|
-
}, (url)=>{
|
|
585
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
574
|
+
}, {}, (url)=>{
|
|
575
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
586
576
|
url
|
|
587
577
|
});
|
|
588
|
-
if (res instanceof
|
|
578
|
+
if (res instanceof HTMLScriptElement) {
|
|
589
579
|
return res;
|
|
590
580
|
}
|
|
591
581
|
return;
|
|
592
582
|
});
|
|
593
|
-
|
|
583
|
+
document.head.appendChild(scriptEl);
|
|
594
584
|
});
|
|
595
|
-
document.head.appendChild(fragment);
|
|
596
585
|
}
|
|
597
586
|
}
|
|
598
587
|
|
|
@@ -784,7 +773,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
784
773
|
id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
|
|
785
774
|
name: remoteInfo.name,
|
|
786
775
|
remoteSnapshot: moduleInfoSnapshot,
|
|
787
|
-
preloadConfig
|
|
776
|
+
preloadConfig,
|
|
777
|
+
remote: remoteInfo,
|
|
778
|
+
origin
|
|
788
779
|
});
|
|
789
780
|
const preloaded = share.getPreloaded(exposeFullPath);
|
|
790
781
|
if (preloaded) {
|
|
@@ -1413,7 +1404,7 @@ class FederationHost {
|
|
|
1413
1404
|
const versions = scope[name];
|
|
1414
1405
|
const activeVersion = versions[version];
|
|
1415
1406
|
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1416
|
-
if (!activeVersion ||
|
|
1407
|
+
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1417
1408
|
versions[version] = shared;
|
|
1418
1409
|
}
|
|
1419
1410
|
};
|
|
@@ -1590,13 +1581,12 @@ class FederationHost {
|
|
|
1590
1581
|
// not used yet
|
|
1591
1582
|
afterPreloadRemote: new AsyncHook()
|
|
1592
1583
|
});
|
|
1593
|
-
this.version = "0.0.
|
|
1584
|
+
this.version = "0.0.10";
|
|
1594
1585
|
this.moduleCache = new Map();
|
|
1595
1586
|
this.loaderHook = new PluginSystem({
|
|
1596
1587
|
// FIXME: may not be suitable , not open to the public yet
|
|
1597
1588
|
getModuleInfo: new SyncHook(),
|
|
1598
1589
|
createScript: new SyncHook(),
|
|
1599
|
-
createLink: new SyncHook(),
|
|
1600
1590
|
// only work for manifest , so not open to the public yet
|
|
1601
1591
|
fetch: new AsyncHook('fetch')
|
|
1602
1592
|
});
|
|
@@ -1674,6 +1664,8 @@ Object.defineProperty(exports, 'loadScript', {
|
|
|
1674
1664
|
get: function () { return sdk.loadScript; }
|
|
1675
1665
|
});
|
|
1676
1666
|
exports.FederationHost = FederationHost;
|
|
1667
|
+
exports.getRemoteEntry = getRemoteEntry;
|
|
1668
|
+
exports.getRemoteInfo = getRemoteInfo;
|
|
1677
1669
|
exports.init = init;
|
|
1678
1670
|
exports.loadRemote = loadRemote;
|
|
1679
1671
|
exports.loadShare = loadShare;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { g as getGlobalHostPlugins,
|
|
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 getRegisteredShare, m as getInfoWithoutType, n as getPreloaded, o as setPreloaded, p as getGlobalSnapshotInfoByModuleInfo, q as addGlobalSnapshot, r as setGlobalSnapshotInfoByModuleInfo, t as getGlobalSnapshot, G as Global, u as getGlobalShareScope, v as formatShareConfigs, x as isBrowserEnv, y as getBuilderId, z as addUniqueItem, A as setGlobalFederationConstructor, B as getGlobalFederationInstance, C as getGlobalFederationConstructor, E as setGlobalFederationInstance } from './share.esm.js';
|
|
2
2
|
export { F as registerGlobalPlugins } from './share.esm.js';
|
|
3
|
-
import { composeKeyWithSeparator, loadScriptNode, loadScript,
|
|
3
|
+
import { composeKeyWithSeparator, loadScriptNode, loadScript, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest } from '@module-federation/sdk';
|
|
4
4
|
export { loadScript } from '@module-federation/sdk';
|
|
5
5
|
|
|
6
6
|
// Function to match a remote with its name and expose
|
|
@@ -261,7 +261,7 @@ let Module = class Module {
|
|
|
261
261
|
remoteInfo: this.remoteInfo,
|
|
262
262
|
origin: this.host
|
|
263
263
|
});
|
|
264
|
-
|
|
264
|
+
remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
|
|
265
265
|
await this.host.hooks.lifecycle.initContainer.emit(_extends$4({}, initContainerOptions, {
|
|
266
266
|
remoteEntryExports
|
|
267
267
|
}));
|
|
@@ -559,38 +559,27 @@ function preloadAssets(remoteInfo, host, assets) {
|
|
|
559
559
|
});
|
|
560
560
|
const fragment = document.createDocumentFragment();
|
|
561
561
|
cssAssets.forEach((cssUrl)=>{
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
url
|
|
568
|
-
});
|
|
569
|
-
if (res instanceof HTMLLinkElement) {
|
|
570
|
-
return res;
|
|
571
|
-
}
|
|
572
|
-
return;
|
|
573
|
-
});
|
|
574
|
-
needAttach && fragment.appendChild(cssEl);
|
|
562
|
+
const cssEl = document.createElement('link');
|
|
563
|
+
cssEl.setAttribute('rel', 'preload');
|
|
564
|
+
cssEl.setAttribute('href', cssUrl);
|
|
565
|
+
cssEl.setAttribute('as', 'style');
|
|
566
|
+
fragment.appendChild(cssEl);
|
|
575
567
|
});
|
|
568
|
+
document.head.appendChild(fragment);
|
|
576
569
|
jsAssetsWithoutEntry.forEach((jsUrl)=>{
|
|
577
|
-
const {
|
|
570
|
+
const { script: scriptEl } = createScript(jsUrl, ()=>{
|
|
578
571
|
// noop
|
|
579
|
-
}, {
|
|
580
|
-
|
|
581
|
-
as: 'script'
|
|
582
|
-
}, (url)=>{
|
|
583
|
-
const res = host.loaderHook.lifecycle.createLink.emit({
|
|
572
|
+
}, {}, (url)=>{
|
|
573
|
+
const res = host.loaderHook.lifecycle.createScript.emit({
|
|
584
574
|
url
|
|
585
575
|
});
|
|
586
|
-
if (res instanceof
|
|
576
|
+
if (res instanceof HTMLScriptElement) {
|
|
587
577
|
return res;
|
|
588
578
|
}
|
|
589
579
|
return;
|
|
590
580
|
});
|
|
591
|
-
|
|
581
|
+
document.head.appendChild(scriptEl);
|
|
592
582
|
});
|
|
593
|
-
document.head.appendChild(fragment);
|
|
594
583
|
}
|
|
595
584
|
}
|
|
596
585
|
|
|
@@ -782,7 +771,9 @@ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, r
|
|
|
782
771
|
id: assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,
|
|
783
772
|
name: remoteInfo.name,
|
|
784
773
|
remoteSnapshot: moduleInfoSnapshot,
|
|
785
|
-
preloadConfig
|
|
774
|
+
preloadConfig,
|
|
775
|
+
remote: remoteInfo,
|
|
776
|
+
origin
|
|
786
777
|
});
|
|
787
778
|
const preloaded = getPreloaded(exposeFullPath);
|
|
788
779
|
if (preloaded) {
|
|
@@ -1411,7 +1402,7 @@ class FederationHost {
|
|
|
1411
1402
|
const versions = scope[name];
|
|
1412
1403
|
const activeVersion = versions[version];
|
|
1413
1404
|
const activeVersionEager = Boolean(activeVersion && (activeVersion.eager || ((_activeVersion_shareConfig = activeVersion.shareConfig) == null ? void 0 : _activeVersion_shareConfig.eager)));
|
|
1414
|
-
if (!activeVersion ||
|
|
1405
|
+
if (!activeVersion || !activeVersion.loaded && (Boolean(!eager) !== !activeVersionEager ? eager : hostName > activeVersion.from)) {
|
|
1415
1406
|
versions[version] = shared;
|
|
1416
1407
|
}
|
|
1417
1408
|
};
|
|
@@ -1588,13 +1579,12 @@ class FederationHost {
|
|
|
1588
1579
|
// not used yet
|
|
1589
1580
|
afterPreloadRemote: new AsyncHook()
|
|
1590
1581
|
});
|
|
1591
|
-
this.version = "0.0.
|
|
1582
|
+
this.version = "0.0.10";
|
|
1592
1583
|
this.moduleCache = new Map();
|
|
1593
1584
|
this.loaderHook = new PluginSystem({
|
|
1594
1585
|
// FIXME: may not be suitable , not open to the public yet
|
|
1595
1586
|
getModuleInfo: new SyncHook(),
|
|
1596
1587
|
createScript: new SyncHook(),
|
|
1597
|
-
createLink: new SyncHook(),
|
|
1598
1588
|
// only work for manifest , so not open to the public yet
|
|
1599
1589
|
fetch: new AsyncHook('fetch')
|
|
1600
1590
|
});
|
|
@@ -1666,4 +1656,4 @@ function preloadRemote(...args) {
|
|
|
1666
1656
|
// Inject for debug
|
|
1667
1657
|
setGlobalFederationConstructor(FederationHost);
|
|
1668
1658
|
|
|
1669
|
-
export { FederationHost, init, loadRemote, loadShare, loadShareSync, preloadRemote };
|
|
1659
|
+
export { FederationHost, getRemoteEntry, getRemoteInfo, init, loadRemote, loadShare, loadShareSync, preloadRemote };
|
package/dist/package.json
CHANGED
package/dist/share.cjs.js
CHANGED
|
@@ -176,7 +176,7 @@ function getGlobalFederationConstructor() {
|
|
|
176
176
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
177
177
|
if (isDebug) {
|
|
178
178
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
179
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.
|
|
179
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.10";
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
package/dist/share.esm.js
CHANGED
|
@@ -174,7 +174,7 @@ function getGlobalFederationConstructor() {
|
|
|
174
174
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
175
175
|
if (isDebug) {
|
|
176
176
|
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
177
|
-
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.
|
|
177
|
+
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.10";
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -794,4 +794,4 @@ function getGlobalShareScope() {
|
|
|
794
794
|
return Global.__FEDERATION__.__SHARE__;
|
|
795
795
|
}
|
|
796
796
|
|
|
797
|
-
export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J,
|
|
797
|
+
export { setGlobalFederationConstructor as A, getGlobalFederationInstance as B, getGlobalFederationConstructor as C, DEFAULT_REMOTE_TYPE as D, setGlobalFederationInstance as E, registerGlobalPlugins as F, Global as G, nativeGlobal as H, resetFederationGlobalInfo as I, getTargetSnapshotInfoByModuleInfo as J, globalLoading as a, DEFAULT_SCOPE as b, getRemoteEntryExports as c, assert as d, getFMId as e, error as f, getGlobalHostPlugins as g, isPlainObject as h, isObject as i, isRemoteInfoWithEntry as j, isPureRemoteEntry as k, getRegisteredShare as l, getInfoWithoutType as m, getPreloaded as n, setPreloaded as o, getGlobalSnapshotInfoByModuleInfo as p, addGlobalSnapshot as q, setGlobalSnapshotInfoByModuleInfo as r, safeToString as s, getGlobalSnapshot as t, getGlobalShareScope as u, formatShareConfigs as v, warn as w, isBrowserEnv as x, getBuilderId as y, addUniqueItem as z };
|
package/dist/src/core.d.ts
CHANGED
|
@@ -67,8 +67,10 @@ export declare class FederationHost {
|
|
|
67
67
|
handlePreloadModule: SyncHook<{
|
|
68
68
|
id: string;
|
|
69
69
|
name: string;
|
|
70
|
+
remote: Remote;
|
|
70
71
|
remoteSnapshot: ModuleInfo;
|
|
71
72
|
preloadConfig: PreloadRemoteArgs;
|
|
73
|
+
origin: FederationHost;
|
|
72
74
|
}, void>;
|
|
73
75
|
errorLoadRemote: AsyncHook<[{
|
|
74
76
|
id: string;
|
|
@@ -126,9 +128,6 @@ export declare class FederationHost {
|
|
|
126
128
|
createScript: SyncHook<[{
|
|
127
129
|
url: string;
|
|
128
130
|
}], void | HTMLScriptElement>;
|
|
129
|
-
createLink: SyncHook<[{
|
|
130
|
-
url: string;
|
|
131
|
-
}], void | HTMLLinkElement>;
|
|
132
131
|
fetch: AsyncHook<[string, RequestInit], false | void | Promise<Response>>;
|
|
133
132
|
}>;
|
|
134
133
|
constructor(userOptions: UserOptions);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { FederationHost } from './core';
|
|
|
2
2
|
import { UserOptions, FederationRuntimePlugin } from './type';
|
|
3
3
|
export { FederationHost } from './core';
|
|
4
4
|
export { registerGlobalPlugins } from './global';
|
|
5
|
+
export { getRemoteEntry, getRemoteInfo } from './utils';
|
|
5
6
|
export { loadScript } from '@module-federation/sdk';
|
|
6
7
|
export type { Federation } from './global';
|
|
7
8
|
export type { FederationRuntimePlugin };
|
|
@@ -95,6 +95,6 @@ export type RemoteEntryInitOptions = {
|
|
|
95
95
|
export type InitScope = Array<Record<string, never>>;
|
|
96
96
|
export type RemoteEntryExports = {
|
|
97
97
|
get: (id: string) => () => Promise<Module>;
|
|
98
|
-
init: (shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void
|
|
98
|
+
init: (shareScope: ShareScopeMap[string], initScope?: InitScope, remoteEntryInitOPtions?: RemoteEntryInitOptions) => void;
|
|
99
99
|
};
|
|
100
100
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240205220829",
|
|
4
4
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
48
|
+
"@module-federation/sdk": "0.0.0-next-20240205220829"
|
|
49
49
|
}
|
|
50
50
|
}
|