@module-federation/runtime-core 0.0.0-next-20250515032632 → 0.0.0-next-20250522105937
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.cjs
CHANGED
|
@@ -48,7 +48,7 @@ function isRemoteInfoWithEntry(remote) {
|
|
|
48
48
|
return typeof remote.entry !== 'undefined';
|
|
49
49
|
}
|
|
50
50
|
function isPureRemoteEntry(remote) {
|
|
51
|
-
return !remote.entry.includes('.json')
|
|
51
|
+
return !remote.entry.includes('.json');
|
|
52
52
|
}
|
|
53
53
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
54
|
async function safeWrapper(callback, disableWarn) {
|
|
@@ -196,7 +196,7 @@ function getGlobalFederationConstructor() {
|
|
|
196
196
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = sdk.isDebugMode()) {
|
|
197
197
|
if (isDebug) {
|
|
198
198
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
199
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
199
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.14.0";
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -648,7 +648,6 @@ function satisfy(version, range) {
|
|
|
648
648
|
}
|
|
649
649
|
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
|
|
650
650
|
const versionAtom = {
|
|
651
|
-
operator: versionOperator,
|
|
652
651
|
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
|
|
653
652
|
major: versionMajor,
|
|
654
653
|
minor: versionMinor,
|
|
@@ -1008,12 +1007,13 @@ function registerPlugins(plugins, hookInstances) {
|
|
|
1008
1007
|
return plugins;
|
|
1009
1008
|
}
|
|
1010
1009
|
|
|
1010
|
+
const importCallback = '.then(callbacks[0]).catch(callbacks[1])';
|
|
1011
1011
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
1012
1012
|
return new Promise((resolve, reject)=>{
|
|
1013
1013
|
try {
|
|
1014
1014
|
if (!remoteEntryExports) {
|
|
1015
1015
|
if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
|
|
1016
|
-
new Function('callbacks', `import("${entry}")
|
|
1016
|
+
new Function('callbacks', `import("${entry}")${importCallback}`)([
|
|
1017
1017
|
resolve,
|
|
1018
1018
|
reject
|
|
1019
1019
|
]);
|
|
@@ -1037,7 +1037,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
1037
1037
|
//@ts-ignore
|
|
1038
1038
|
System.import(entry).then(resolve).catch(reject);
|
|
1039
1039
|
} else {
|
|
1040
|
-
new Function('callbacks', `System.import("${entry}")
|
|
1040
|
+
new Function('callbacks', `System.import("${entry}")${importCallback}`)([
|
|
1041
1041
|
resolve,
|
|
1042
1042
|
reject
|
|
1043
1043
|
]);
|
|
@@ -1050,6 +1050,15 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
});
|
|
1052
1052
|
}
|
|
1053
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
1054
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
1055
|
+
assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
|
|
1056
|
+
remoteName: name,
|
|
1057
|
+
remoteEntryUrl: entry,
|
|
1058
|
+
remoteEntryKey
|
|
1059
|
+
}));
|
|
1060
|
+
return entryExports;
|
|
1061
|
+
}
|
|
1053
1062
|
async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
1054
1063
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
1055
1064
|
if (remoteEntryExports) {
|
|
@@ -1072,13 +1081,7 @@ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
|
1072
1081
|
return;
|
|
1073
1082
|
}
|
|
1074
1083
|
}).then(()=>{
|
|
1075
|
-
|
|
1076
|
-
assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
|
|
1077
|
-
remoteName: name,
|
|
1078
|
-
remoteEntryUrl: entry,
|
|
1079
|
-
remoteEntryKey
|
|
1080
|
-
}));
|
|
1081
|
-
return entryExports;
|
|
1084
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1082
1085
|
}).catch((e)=>{
|
|
1083
1086
|
assert(undefined, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_008, errorCodes.runtimeDescMap, {
|
|
1084
1087
|
remoteName: name,
|
|
@@ -1136,13 +1139,7 @@ async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
|
1136
1139
|
}
|
|
1137
1140
|
}
|
|
1138
1141
|
}).then(()=>{
|
|
1139
|
-
|
|
1140
|
-
assert(entryExports, errorCodes.getShortErrorMsg(errorCodes.RUNTIME_001, errorCodes.runtimeDescMap, {
|
|
1141
|
-
remoteName: name,
|
|
1142
|
-
remoteEntryUrl: entry,
|
|
1143
|
-
remoteEntryKey
|
|
1144
|
-
}));
|
|
1145
|
-
return entryExports;
|
|
1142
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1146
1143
|
}).catch((e)=>{
|
|
1147
1144
|
throw e;
|
|
1148
1145
|
});
|
|
@@ -1167,7 +1164,9 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
1167
1164
|
if (res) {
|
|
1168
1165
|
return res;
|
|
1169
1166
|
}
|
|
1170
|
-
|
|
1167
|
+
// Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this
|
|
1168
|
+
const isWebEnvironment = typeof ENV_TARGET !== 'undefined' ? ENV_TARGET === 'web' : sdk.isBrowserEnv();
|
|
1169
|
+
return isWebEnvironment ? loadEntryDom({
|
|
1171
1170
|
remoteInfo,
|
|
1172
1171
|
remoteEntryExports,
|
|
1173
1172
|
loaderHook
|
|
@@ -1692,9 +1691,12 @@ function snapshotPlugin() {
|
|
|
1692
1691
|
return {
|
|
1693
1692
|
name: 'snapshot-plugin',
|
|
1694
1693
|
async afterResolve (args) {
|
|
1695
|
-
const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
|
|
1694
|
+
const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
|
|
1696
1695
|
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
1697
|
-
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(
|
|
1696
|
+
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
|
|
1697
|
+
moduleInfo: remote,
|
|
1698
|
+
id
|
|
1699
|
+
});
|
|
1698
1700
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
1699
1701
|
// preloading assets
|
|
1700
1702
|
const preloadOptions = {
|
|
@@ -1953,7 +1955,7 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
1953
1955
|
|
|
1954
1956
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1955
1957
|
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
1956
|
-
name: origin.
|
|
1958
|
+
name: origin.name,
|
|
1957
1959
|
version: origin.options.version
|
|
1958
1960
|
});
|
|
1959
1961
|
// get remote detail info from global
|
|
@@ -1978,23 +1980,8 @@ function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
|
1978
1980
|
};
|
|
1979
1981
|
}
|
|
1980
1982
|
class SnapshotHandler {
|
|
1981
|
-
async loadSnapshot(moduleInfo) {
|
|
1982
|
-
const { options } = this.HostInstance;
|
|
1983
|
-
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
1984
|
-
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
1985
|
-
options,
|
|
1986
|
-
moduleInfo,
|
|
1987
|
-
hostGlobalSnapshot,
|
|
1988
|
-
remoteSnapshot,
|
|
1989
|
-
globalSnapshot
|
|
1990
|
-
});
|
|
1991
|
-
return {
|
|
1992
|
-
remoteSnapshot: globalRemoteSnapshot,
|
|
1993
|
-
globalSnapshot: globalSnapshotRes
|
|
1994
|
-
};
|
|
1995
|
-
}
|
|
1996
1983
|
// eslint-disable-next-line max-lines-per-function
|
|
1997
|
-
async loadRemoteSnapshotInfo(moduleInfo) {
|
|
1984
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
|
|
1998
1985
|
const { options } = this.HostInstance;
|
|
1999
1986
|
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
2000
1987
|
options,
|
|
@@ -2081,6 +2068,8 @@ class SnapshotHandler {
|
|
|
2081
2068
|
}
|
|
2082
2069
|
}
|
|
2083
2070
|
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
2071
|
+
id,
|
|
2072
|
+
host: this.HostInstance,
|
|
2084
2073
|
options,
|
|
2085
2074
|
moduleInfo,
|
|
2086
2075
|
remoteSnapshot: mSnapshot
|
|
@@ -2618,7 +2607,9 @@ class RemoteHandler {
|
|
|
2618
2607
|
await Promise.all(preloadOps.map(async (ops)=>{
|
|
2619
2608
|
const { remote } = ops;
|
|
2620
2609
|
const remoteInfo = getRemoteInfo(remote);
|
|
2621
|
-
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo(
|
|
2610
|
+
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
2611
|
+
moduleInfo: remote
|
|
2612
|
+
});
|
|
2622
2613
|
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
2623
2614
|
origin: host,
|
|
2624
2615
|
preloadOptions: ops,
|
|
@@ -2872,6 +2863,7 @@ class RemoteHandler {
|
|
|
2872
2863
|
}
|
|
2873
2864
|
}
|
|
2874
2865
|
|
|
2866
|
+
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean' ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true; // Default to true (use snapshot) when not explicitly defined
|
|
2875
2867
|
class FederationHost {
|
|
2876
2868
|
initOptions(userOptions) {
|
|
2877
2869
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -2978,7 +2970,7 @@ class FederationHost {
|
|
|
2978
2970
|
// maybe will change, temporarily for internal use only
|
|
2979
2971
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2980
2972
|
});
|
|
2981
|
-
this.version = "0.
|
|
2973
|
+
this.version = "0.14.0";
|
|
2982
2974
|
this.moduleCache = new Map();
|
|
2983
2975
|
this.loaderHook = new PluginSystem({
|
|
2984
2976
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2995,15 +2987,16 @@ class FederationHost {
|
|
|
2995
2987
|
beforeBridgeDestroy: new SyncHook(),
|
|
2996
2988
|
afterBridgeDestroy: new SyncHook()
|
|
2997
2989
|
});
|
|
2990
|
+
const plugins = USE_SNAPSHOT ? [
|
|
2991
|
+
snapshotPlugin(),
|
|
2992
|
+
generatePreloadAssetsPlugin()
|
|
2993
|
+
] : [];
|
|
2998
2994
|
// TODO: Validate the details of the options
|
|
2999
2995
|
// Initialize options with default values
|
|
3000
2996
|
const defaultOptions = {
|
|
3001
2997
|
id: getBuilderId(),
|
|
3002
2998
|
name: userOptions.name,
|
|
3003
|
-
plugins
|
|
3004
|
-
snapshotPlugin(),
|
|
3005
|
-
generatePreloadAssetsPlugin()
|
|
3006
|
-
],
|
|
2999
|
+
plugins,
|
|
3007
3000
|
remotes: [],
|
|
3008
3001
|
shared: {},
|
|
3009
3002
|
inBrowser: sdk.isBrowserEnv()
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as _extends, a as _object_without_properties_loose } from './polyfills.esm.js';
|
|
2
|
-
import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode,
|
|
2
|
+
import { createLogger, isBrowserEnv, isReactNativeEnv, isDebugMode, composeKeyWithSeparator, loadScriptNode, loadScript, safeToString, createLink, createScript, getResourceUrl, isManifestProvider, generateSnapshotFromManifest, warn as warn$1 } from '@module-federation/sdk';
|
|
3
3
|
export { loadScript, loadScriptNode } from '@module-federation/sdk';
|
|
4
|
-
import { getShortErrorMsg,
|
|
4
|
+
import { getShortErrorMsg, RUNTIME_008, runtimeDescMap, RUNTIME_001, RUNTIME_002, RUNTIME_007, RUNTIME_003, RUNTIME_005, RUNTIME_006, RUNTIME_004 } from '@module-federation/error-codes';
|
|
5
5
|
|
|
6
6
|
const LOG_CATEGORY = '[ Federation Runtime ]';
|
|
7
7
|
// FIXME: pre-bundle ?
|
|
@@ -47,7 +47,7 @@ function isRemoteInfoWithEntry(remote) {
|
|
|
47
47
|
return typeof remote.entry !== 'undefined';
|
|
48
48
|
}
|
|
49
49
|
function isPureRemoteEntry(remote) {
|
|
50
|
-
return !remote.entry.includes('.json')
|
|
50
|
+
return !remote.entry.includes('.json');
|
|
51
51
|
}
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
53
|
async function safeWrapper(callback, disableWarn) {
|
|
@@ -195,7 +195,7 @@ function getGlobalFederationConstructor() {
|
|
|
195
195
|
function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
|
|
196
196
|
if (isDebug) {
|
|
197
197
|
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
|
|
198
|
-
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.
|
|
198
|
+
CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.14.0";
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -647,7 +647,6 @@ function satisfy(version, range) {
|
|
|
647
647
|
}
|
|
648
648
|
const [, versionOperator, , versionMajor, versionMinor, versionPatch, versionPreRelease] = extractedVersion;
|
|
649
649
|
const versionAtom = {
|
|
650
|
-
operator: versionOperator,
|
|
651
650
|
version: combineVersion(versionMajor, versionMinor, versionPatch, versionPreRelease),
|
|
652
651
|
major: versionMajor,
|
|
653
652
|
minor: versionMinor,
|
|
@@ -1007,12 +1006,13 @@ function registerPlugins(plugins, hookInstances) {
|
|
|
1007
1006
|
return plugins;
|
|
1008
1007
|
}
|
|
1009
1008
|
|
|
1009
|
+
const importCallback = '.then(callbacks[0]).catch(callbacks[1])';
|
|
1010
1010
|
async function loadEsmEntry({ entry, remoteEntryExports }) {
|
|
1011
1011
|
return new Promise((resolve, reject)=>{
|
|
1012
1012
|
try {
|
|
1013
1013
|
if (!remoteEntryExports) {
|
|
1014
1014
|
if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {
|
|
1015
|
-
new Function('callbacks', `import("${entry}")
|
|
1015
|
+
new Function('callbacks', `import("${entry}")${importCallback}`)([
|
|
1016
1016
|
resolve,
|
|
1017
1017
|
reject
|
|
1018
1018
|
]);
|
|
@@ -1036,7 +1036,7 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
1036
1036
|
//@ts-ignore
|
|
1037
1037
|
System.import(entry).then(resolve).catch(reject);
|
|
1038
1038
|
} else {
|
|
1039
|
-
new Function('callbacks', `System.import("${entry}")
|
|
1039
|
+
new Function('callbacks', `System.import("${entry}")${importCallback}`)([
|
|
1040
1040
|
resolve,
|
|
1041
1041
|
reject
|
|
1042
1042
|
]);
|
|
@@ -1049,6 +1049,15 @@ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
});
|
|
1051
1051
|
}
|
|
1052
|
+
function handleRemoteEntryLoaded(name, globalName, entry) {
|
|
1053
|
+
const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
|
|
1054
|
+
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
1055
|
+
remoteName: name,
|
|
1056
|
+
remoteEntryUrl: entry,
|
|
1057
|
+
remoteEntryKey
|
|
1058
|
+
}));
|
|
1059
|
+
return entryExports;
|
|
1060
|
+
}
|
|
1052
1061
|
async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
1053
1062
|
const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
|
|
1054
1063
|
if (remoteEntryExports) {
|
|
@@ -1071,13 +1080,7 @@ async function loadEntryScript({ name, globalName, entry, loaderHook }) {
|
|
|
1071
1080
|
return;
|
|
1072
1081
|
}
|
|
1073
1082
|
}).then(()=>{
|
|
1074
|
-
|
|
1075
|
-
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
1076
|
-
remoteName: name,
|
|
1077
|
-
remoteEntryUrl: entry,
|
|
1078
|
-
remoteEntryKey
|
|
1079
|
-
}));
|
|
1080
|
-
return entryExports;
|
|
1083
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1081
1084
|
}).catch((e)=>{
|
|
1082
1085
|
assert(undefined, getShortErrorMsg(RUNTIME_008, runtimeDescMap, {
|
|
1083
1086
|
remoteName: name,
|
|
@@ -1135,13 +1138,7 @@ async function loadEntryNode({ remoteInfo, loaderHook }) {
|
|
|
1135
1138
|
}
|
|
1136
1139
|
}
|
|
1137
1140
|
}).then(()=>{
|
|
1138
|
-
|
|
1139
|
-
assert(entryExports, getShortErrorMsg(RUNTIME_001, runtimeDescMap, {
|
|
1140
|
-
remoteName: name,
|
|
1141
|
-
remoteEntryUrl: entry,
|
|
1142
|
-
remoteEntryKey
|
|
1143
|
-
}));
|
|
1144
|
-
return entryExports;
|
|
1141
|
+
return handleRemoteEntryLoaded(name, globalName, entry);
|
|
1145
1142
|
}).catch((e)=>{
|
|
1146
1143
|
throw e;
|
|
1147
1144
|
});
|
|
@@ -1166,7 +1163,9 @@ async function getRemoteEntry({ origin, remoteEntryExports, remoteInfo }) {
|
|
|
1166
1163
|
if (res) {
|
|
1167
1164
|
return res;
|
|
1168
1165
|
}
|
|
1169
|
-
|
|
1166
|
+
// Use ENV_TARGET if defined, otherwise fallback to isBrowserEnv, must keep this
|
|
1167
|
+
const isWebEnvironment = typeof ENV_TARGET !== 'undefined' ? ENV_TARGET === 'web' : isBrowserEnv();
|
|
1168
|
+
return isWebEnvironment ? loadEntryDom({
|
|
1170
1169
|
remoteInfo,
|
|
1171
1170
|
remoteEntryExports,
|
|
1172
1171
|
loaderHook
|
|
@@ -1691,9 +1690,12 @@ function snapshotPlugin() {
|
|
|
1691
1690
|
return {
|
|
1692
1691
|
name: 'snapshot-plugin',
|
|
1693
1692
|
async afterResolve (args) {
|
|
1694
|
-
const { remote, pkgNameOrAlias, expose, origin, remoteInfo } = args;
|
|
1693
|
+
const { remote, pkgNameOrAlias, expose, origin, remoteInfo, id } = args;
|
|
1695
1694
|
if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
|
|
1696
|
-
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo(
|
|
1695
|
+
const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
|
|
1696
|
+
moduleInfo: remote,
|
|
1697
|
+
id
|
|
1698
|
+
});
|
|
1697
1699
|
assignRemoteInfo(remoteInfo, remoteSnapshot);
|
|
1698
1700
|
// preloading assets
|
|
1699
1701
|
const preloadOptions = {
|
|
@@ -1952,7 +1954,7 @@ const generatePreloadAssetsPlugin = function() {
|
|
|
1952
1954
|
|
|
1953
1955
|
function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
1954
1956
|
const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({
|
|
1955
|
-
name: origin.
|
|
1957
|
+
name: origin.name,
|
|
1956
1958
|
version: origin.options.version
|
|
1957
1959
|
});
|
|
1958
1960
|
// get remote detail info from global
|
|
@@ -1977,23 +1979,8 @@ function getGlobalRemoteInfo(moduleInfo, origin) {
|
|
|
1977
1979
|
};
|
|
1978
1980
|
}
|
|
1979
1981
|
class SnapshotHandler {
|
|
1980
|
-
async loadSnapshot(moduleInfo) {
|
|
1981
|
-
const { options } = this.HostInstance;
|
|
1982
|
-
const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } = this.getGlobalRemoteInfo(moduleInfo);
|
|
1983
|
-
const { remoteSnapshot: globalRemoteSnapshot, globalSnapshot: globalSnapshotRes } = await this.hooks.lifecycle.loadSnapshot.emit({
|
|
1984
|
-
options,
|
|
1985
|
-
moduleInfo,
|
|
1986
|
-
hostGlobalSnapshot,
|
|
1987
|
-
remoteSnapshot,
|
|
1988
|
-
globalSnapshot
|
|
1989
|
-
});
|
|
1990
|
-
return {
|
|
1991
|
-
remoteSnapshot: globalRemoteSnapshot,
|
|
1992
|
-
globalSnapshot: globalSnapshotRes
|
|
1993
|
-
};
|
|
1994
|
-
}
|
|
1995
1982
|
// eslint-disable-next-line max-lines-per-function
|
|
1996
|
-
async loadRemoteSnapshotInfo(moduleInfo) {
|
|
1983
|
+
async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
|
|
1997
1984
|
const { options } = this.HostInstance;
|
|
1998
1985
|
await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
|
|
1999
1986
|
options,
|
|
@@ -2080,6 +2067,8 @@ class SnapshotHandler {
|
|
|
2080
2067
|
}
|
|
2081
2068
|
}
|
|
2082
2069
|
await this.hooks.lifecycle.afterLoadSnapshot.emit({
|
|
2070
|
+
id,
|
|
2071
|
+
host: this.HostInstance,
|
|
2083
2072
|
options,
|
|
2084
2073
|
moduleInfo,
|
|
2085
2074
|
remoteSnapshot: mSnapshot
|
|
@@ -2617,7 +2606,9 @@ class RemoteHandler {
|
|
|
2617
2606
|
await Promise.all(preloadOps.map(async (ops)=>{
|
|
2618
2607
|
const { remote } = ops;
|
|
2619
2608
|
const remoteInfo = getRemoteInfo(remote);
|
|
2620
|
-
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo(
|
|
2609
|
+
const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
|
|
2610
|
+
moduleInfo: remote
|
|
2611
|
+
});
|
|
2621
2612
|
const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
|
|
2622
2613
|
origin: host,
|
|
2623
2614
|
preloadOptions: ops,
|
|
@@ -2871,6 +2862,7 @@ class RemoteHandler {
|
|
|
2871
2862
|
}
|
|
2872
2863
|
}
|
|
2873
2864
|
|
|
2865
|
+
const USE_SNAPSHOT = typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean' ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true; // Default to true (use snapshot) when not explicitly defined
|
|
2874
2866
|
class FederationHost {
|
|
2875
2867
|
initOptions(userOptions) {
|
|
2876
2868
|
this.registerPlugins(userOptions.plugins);
|
|
@@ -2977,7 +2969,7 @@ class FederationHost {
|
|
|
2977
2969
|
// maybe will change, temporarily for internal use only
|
|
2978
2970
|
initContainer: new AsyncWaterfallHook('initContainer')
|
|
2979
2971
|
});
|
|
2980
|
-
this.version = "0.
|
|
2972
|
+
this.version = "0.14.0";
|
|
2981
2973
|
this.moduleCache = new Map();
|
|
2982
2974
|
this.loaderHook = new PluginSystem({
|
|
2983
2975
|
// FIXME: may not be suitable , not open to the public yet
|
|
@@ -2994,15 +2986,16 @@ class FederationHost {
|
|
|
2994
2986
|
beforeBridgeDestroy: new SyncHook(),
|
|
2995
2987
|
afterBridgeDestroy: new SyncHook()
|
|
2996
2988
|
});
|
|
2989
|
+
const plugins = USE_SNAPSHOT ? [
|
|
2990
|
+
snapshotPlugin(),
|
|
2991
|
+
generatePreloadAssetsPlugin()
|
|
2992
|
+
] : [];
|
|
2997
2993
|
// TODO: Validate the details of the options
|
|
2998
2994
|
// Initialize options with default values
|
|
2999
2995
|
const defaultOptions = {
|
|
3000
2996
|
id: getBuilderId(),
|
|
3001
2997
|
name: userOptions.name,
|
|
3002
|
-
plugins
|
|
3003
|
-
snapshotPlugin(),
|
|
3004
|
-
generatePreloadAssetsPlugin()
|
|
3005
|
-
],
|
|
2998
|
+
plugins,
|
|
3006
2999
|
remotes: [],
|
|
3007
3000
|
shared: {},
|
|
3008
3001
|
inBrowser: isBrowserEnv()
|
|
@@ -33,6 +33,8 @@ export declare class SnapshotHandler {
|
|
|
33
33
|
from: "global" | "manifest";
|
|
34
34
|
}>;
|
|
35
35
|
afterLoadSnapshot: AsyncWaterfallHook<{
|
|
36
|
+
id?: string;
|
|
37
|
+
host: FederationHost;
|
|
36
38
|
options: Options;
|
|
37
39
|
moduleInfo: Remote;
|
|
38
40
|
remoteSnapshot: ModuleInfo;
|
|
@@ -41,11 +43,11 @@ export declare class SnapshotHandler {
|
|
|
41
43
|
loaderHook: FederationHost['loaderHook'];
|
|
42
44
|
manifestLoading: Record<string, Promise<ModuleInfo>>;
|
|
43
45
|
constructor(HostInstance: FederationHost);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
loadRemoteSnapshotInfo({ moduleInfo, id, expose, }: {
|
|
47
|
+
moduleInfo: Remote;
|
|
48
|
+
id?: string;
|
|
49
|
+
expose?: string;
|
|
50
|
+
}): Promise<{
|
|
49
51
|
remoteSnapshot: ModuleInfo;
|
|
50
52
|
globalSnapshot: GlobalModuleInfo;
|
|
51
53
|
}> | never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/runtime-core",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250522105937",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "zhouxiao <codingzx@gmail.com>",
|
|
6
6
|
"main": "./dist/index.cjs.cjs",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
56
|
-
"@module-federation/error-codes": "0.0.0-next-
|
|
55
|
+
"@module-federation/sdk": "0.0.0-next-20250522105937",
|
|
56
|
+
"@module-federation/error-codes": "0.0.0-next-20250522105937"
|
|
57
57
|
}
|
|
58
58
|
}
|