@module-federation/bridge-react 2.7.0 → 2.8.0

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.
Files changed (90) hide show
  1. package/dist/base.cjs.js +4 -4
  2. package/dist/base.d.ts +8 -311
  3. package/dist/base.es.js +5 -5
  4. package/dist/{bridge-base-CIOXqUYV.mjs → bridge-base-BaKy6CY_.mjs} +25 -92
  5. package/dist/{bridge-base-HLp3d7aF.js → bridge-base-Ch33UJuN.js} +25 -91
  6. package/dist/{createHelpers-DNBacpxb.js → createHelpers-19BP0xtB.js} +2 -3
  7. package/dist/{createHelpers-BY5Uj9_Z.mjs → createHelpers-BSHeKyd-.mjs} +2 -3
  8. package/dist/data-fetch-server-middleware.cjs.js +1 -1
  9. package/dist/data-fetch-server-middleware.d.ts +1 -15
  10. package/dist/data-fetch-server-middleware.es.js +1 -1
  11. package/dist/data-fetch-utils.cjs.js +2 -2
  12. package/dist/data-fetch-utils.d.ts +1 -81
  13. package/dist/data-fetch-utils.es.js +4 -4
  14. package/dist/data-fetch.cjs.js +3 -3
  15. package/dist/data-fetch.d.ts +4 -140
  16. package/dist/data-fetch.es.js +3 -3
  17. package/dist/error-boundary.d.ts +17 -0
  18. package/dist/error-boundary.spec.d.ts +1 -0
  19. package/dist/index.cjs.js +4 -4
  20. package/dist/index.d.ts +12 -299
  21. package/dist/index.es.js +5 -5
  22. package/dist/lazy/AwaitDataFetch.d.ts +24 -0
  23. package/dist/lazy/constant.d.ts +26 -0
  24. package/dist/lazy/createLazyComponent.d.ts +28 -0
  25. package/dist/lazy/data-fetch/cache.d.ts +34 -0
  26. package/dist/lazy/data-fetch/cache.spec.d.ts +1 -0
  27. package/dist/lazy/data-fetch/call-data-fetch.d.ts +1 -0
  28. package/dist/lazy/data-fetch/data-fetch-server-middleware.d.ts +3 -0
  29. package/dist/lazy/data-fetch/index.d.ts +6 -0
  30. package/dist/lazy/data-fetch/inject-data-fetch.d.ts +4 -0
  31. package/dist/lazy/data-fetch/prefetch.d.ts +9 -0
  32. package/dist/lazy/data-fetch/runtime-plugin.d.ts +3 -0
  33. package/dist/lazy/index.d.ts +9 -0
  34. package/dist/lazy/logger.d.ts +2 -0
  35. package/dist/lazy/types.d.ts +60 -0
  36. package/dist/lazy/utils.d.ts +48 -0
  37. package/dist/lazy/wrapNoSSR.d.ts +9 -0
  38. package/dist/{lazy-load-component-plugin-aj97Vt-4.mjs → lazy-load-component-plugin-DEu-DfZt.mjs} +2 -2
  39. package/dist/{lazy-load-component-plugin-BjMVNoep.js → lazy-load-component-plugin-FKp6nQa-.js} +2 -2
  40. package/dist/lazy-load-component-plugin.cjs.js +2 -2
  41. package/dist/lazy-load-component-plugin.d.ts +2 -16
  42. package/dist/lazy-load-component-plugin.es.js +2 -2
  43. package/dist/lazy-utils.cjs.js +1 -1
  44. package/dist/lazy-utils.d.ts +1 -149
  45. package/dist/lazy-utils.es.js +2 -2
  46. package/dist/plugin.d.ts +2 -22
  47. package/dist/plugins/lazy-load-component-plugin.d.ts +12 -0
  48. package/dist/plugins/lazy-load-component-plugin.spec.d.ts +1 -0
  49. package/dist/{prefetch-BwRDb4SJ.mjs → prefetch-CTZuFBqh.mjs} +314 -1
  50. package/dist/{prefetch-DLhPTofn.js → prefetch-D66kL1aM.js} +314 -1
  51. package/dist/provider/context.d.ts +3 -0
  52. package/dist/provider/plugin.d.ts +7 -0
  53. package/dist/provider/versions/bridge-base.d.ts +5 -0
  54. package/dist/provider/versions/legacy.d.ts +26 -0
  55. package/dist/provider/versions/v18.d.ts +19 -0
  56. package/dist/provider/versions/v19.d.ts +21 -0
  57. package/dist/remote/RemoteAppWrapper.d.ts +7 -0
  58. package/dist/remote/base-component/component.d.ts +2 -0
  59. package/dist/remote/base-component/create.d.ts +9 -0
  60. package/dist/remote/base-component/index.d.ts +5 -0
  61. package/dist/remote/createHelpers.d.ts +17 -0
  62. package/dist/remote/router-component/component.d.ts +8 -0
  63. package/dist/remote/router-component/create.d.ts +9 -0
  64. package/dist/remote/router-component/index.d.ts +5 -0
  65. package/dist/router/default.d.ts +7 -0
  66. package/dist/router/v5.d.ts +4 -0
  67. package/dist/router/v6.d.ts +7 -0
  68. package/dist/router/v7.d.ts +6 -0
  69. package/dist/router-v5.d.ts +1 -17
  70. package/dist/router-v6.d.ts +1 -20
  71. package/dist/router-v7.d.ts +1 -19
  72. package/dist/router.d.ts +1 -20
  73. package/dist/shared/size-limited-cache.d.ts +29 -0
  74. package/dist/shared/size-limited-cache.spec.d.ts +1 -0
  75. package/dist/size-limited-cache.cjs.js +82 -0
  76. package/dist/size-limited-cache.d.ts +1 -0
  77. package/dist/size-limited-cache.es.js +82 -0
  78. package/dist/types.d.ts +137 -0
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils-5dGErM3C.js +588 -0
  81. package/dist/utils-BBP3hEeV.mjs +589 -0
  82. package/dist/v18.cjs.js +1 -1
  83. package/dist/v18.d.ts +3 -114
  84. package/dist/v18.es.js +1 -1
  85. package/dist/v19.cjs.js +1 -1
  86. package/dist/v19.d.ts +3 -115
  87. package/dist/v19.es.js +1 -1
  88. package/package.json +16 -11
  89. package/dist/utils-CFTy4LVE.js +0 -2029
  90. package/dist/utils-DGS4pYp8.mjs +0 -2030
@@ -1,4 +1,4 @@
1
- import { B as warn, y as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, o as getDataFetchItem, M as MF_DATA_FETCH_STATUS, q as MF_DATA_FETCH_TYPE, G as DOWNGRADE_KEY, H as callAllDowngrade, I as callDowngrade, J as getDowngradeTag, K as composeKeyWithSeparator, m as getDataFetchInfo, n as getDataFetchMapKey } from "./utils-DGS4pYp8.mjs";
1
+ import { B as warn, y as DATA_FETCH_FUNCTION, F as FS_HREF, l as logger, e as getDataFetchMap, i as initDataFetchMap, o as getDataFetchItem, M as MF_DATA_FETCH_STATUS, q as MF_DATA_FETCH_TYPE, G as DOWNGRADE_KEY, H as callAllDowngrade, I as callDowngrade, J as getDowngradeTag, K as composeKeyWithSeparator, N as safeToString, m as getDataFetchInfo, n as getDataFetchMapKey } from "./utils-BBP3hEeV.mjs";
2
2
  import { i as isBrowserEnvValue } from "./logger-DwWkXsWl.mjs";
3
3
  async function safeWrapper(callback, disableWarn) {
4
4
  try {
@@ -469,6 +469,9 @@ function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
469
469
  return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
470
470
  }
471
471
  const LOG_CATEGORY = "[ Federation Runtime ]";
472
+ function assert(condition, msgOrCode, descMap, args, context) {
473
+ if (!condition) error(msgOrCode);
474
+ }
472
475
  function error(msgOrCode, descMap, args, originalErrorMsg, context) {
473
476
  if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
474
477
  throw new Error(`${LOG_CATEGORY}: ${msg2}`);
@@ -480,6 +483,14 @@ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
480
483
  }
481
484
  throw new Error(`${LOG_CATEGORY}: ${msg}`);
482
485
  }
486
+ const processModuleAlias = (name, subPath) => {
487
+ let moduleName;
488
+ if (name.endsWith("/")) moduleName = name.slice(0, -1);
489
+ else moduleName = name;
490
+ if (subPath.startsWith(".")) subPath = subPath.slice(1);
491
+ moduleName = moduleName + subPath;
492
+ return moduleName;
493
+ };
483
494
  const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
484
495
  const nativeGlobal = (() => {
485
496
  try {
@@ -532,6 +543,10 @@ const getRemoteEntryExports = (name, globalName) => {
532
543
  };
533
544
  const DEFAULT_SCOPE = "default";
534
545
  const DEFAULT_REMOTE_TYPE = "global";
546
+ function composeRemoteRequestId(remoteName, expose) {
547
+ if (!expose || expose === ".") return remoteName;
548
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
549
+ }
535
550
  function matchRemoteWithNameAndExpose(remotes, id) {
536
551
  for (const remote of remotes) {
537
552
  const isNameMatched = id.startsWith(remote.name);
@@ -809,6 +824,42 @@ function getRemoteInfo(remote) {
809
824
  shareScope: remote.shareScope || DEFAULT_SCOPE
810
825
  };
811
826
  }
827
+ function remoteToEntry(r) {
828
+ return {
829
+ name: r.name,
830
+ alias: r.alias,
831
+ entry: "entry" in r ? r.entry : void 0,
832
+ version: "version" in r ? r.version : void 0,
833
+ type: r.type,
834
+ entryGlobalName: r.entryGlobalName,
835
+ shareScope: r.shareScope
836
+ };
837
+ }
838
+ function optionsToMFContext(options) {
839
+ var _a, _b, _c, _d, _e, _f;
840
+ const shared = {};
841
+ for (const [pkgName, versions] of Object.entries(options.shared)) {
842
+ const first = versions[0];
843
+ if (first) shared[pkgName] = {
844
+ version: first.version,
845
+ singleton: (_a = first.shareConfig) == null ? void 0 : _a.singleton,
846
+ requiredVersion: ((_b = first.shareConfig) == null ? void 0 : _b.requiredVersion) === false ? false : (_c = first.shareConfig) == null ? void 0 : _c.requiredVersion,
847
+ eager: first.eager,
848
+ strictVersion: (_d = first.shareConfig) == null ? void 0 : _d.strictVersion
849
+ };
850
+ }
851
+ return {
852
+ project: {
853
+ name: options.name,
854
+ mfRole: ((_e = options.remotes) == null ? void 0 : _e.length) > 0 ? "host" : "unknown"
855
+ },
856
+ mfConfig: {
857
+ name: options.name,
858
+ remotes: ((_f = options.remotes) == null ? void 0 : _f.map(remoteToEntry)) ?? [],
859
+ shared
860
+ }
861
+ };
862
+ }
812
863
  function isTimeoutError(error2) {
813
864
  if (!(error2 instanceof Error)) return false;
814
865
  return error2.message.includes("timed out") || error2.name.includes("Timeout");
@@ -986,8 +1037,270 @@ var helpers_default = {
986
1037
  getRemoteInfo
987
1038
  }
988
1039
  };
1040
+ function getAvailableExposeNames(remoteSnapshot) {
1041
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
1042
+ const exposes = remoteSnapshot.modules.map((module) => module.moduleName).filter(Boolean);
1043
+ return exposes.length ? exposes.join(",") : void 0;
1044
+ }
1045
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
1046
+ const localShareScopeMap = hostShareScopeMap;
1047
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
1048
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
1049
+ shareScopeKeys.forEach((shareScopeKey) => {
1050
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
1051
+ });
1052
+ const remoteEntryInitOptions = {
1053
+ version: remoteInfo.version || "",
1054
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
1055
+ };
1056
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
1057
+ value: localShareScopeMap,
1058
+ enumerable: false
1059
+ });
1060
+ return {
1061
+ remoteEntryInitOptions,
1062
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
1063
+ initScope: rawInitScope ?? []
1064
+ };
1065
+ }
1066
+ var Module$1 = class {
1067
+ constructor({ remoteInfo, host }) {
1068
+ this.inited = false;
1069
+ this.initing = false;
1070
+ this.lib = void 0;
1071
+ this.remoteInfo = remoteInfo;
1072
+ this.host = host;
1073
+ }
1074
+ async getEntry(expose) {
1075
+ if (this.remoteEntryExports) return this.remoteEntryExports;
1076
+ const remoteEntryExports = await getRemoteEntry({
1077
+ origin: this.host,
1078
+ remoteInfo: this.remoteInfo,
1079
+ remoteEntryExports: this.remoteEntryExports,
1080
+ resourceContext: {
1081
+ initiator: "loadRemote",
1082
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
1083
+ resourceType: "remoteEntry"
1084
+ }
1085
+ });
1086
+ assert(remoteEntryExports, `remoteEntryExports is undefined
1087
+ ${safeToString(this.remoteInfo)}`);
1088
+ this.remoteEntryExports = remoteEntryExports;
1089
+ return this.remoteEntryExports;
1090
+ }
1091
+ async init(id, remoteSnapshot, rawInitScope, expose) {
1092
+ const remoteEntryExports = await this.getEntry(expose);
1093
+ if (this.inited) {
1094
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1095
+ id,
1096
+ remoteInfo: this.remoteInfo,
1097
+ remoteSnapshot,
1098
+ remoteEntryExports,
1099
+ cached: true,
1100
+ origin: this.host
1101
+ });
1102
+ return remoteEntryExports;
1103
+ }
1104
+ if (this.initPromise) {
1105
+ try {
1106
+ await this.initPromise;
1107
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1108
+ id,
1109
+ remoteInfo: this.remoteInfo,
1110
+ remoteSnapshot,
1111
+ remoteEntryExports,
1112
+ cached: true,
1113
+ origin: this.host
1114
+ });
1115
+ } catch (initError) {
1116
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1117
+ id,
1118
+ remoteInfo: this.remoteInfo,
1119
+ remoteSnapshot,
1120
+ remoteEntryExports,
1121
+ error: initError,
1122
+ cached: true,
1123
+ origin: this.host
1124
+ });
1125
+ throw initError;
1126
+ }
1127
+ return remoteEntryExports;
1128
+ }
1129
+ this.initing = true;
1130
+ this.initPromise = (async () => {
1131
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
1132
+ id,
1133
+ remoteInfo: this.remoteInfo,
1134
+ remoteSnapshot,
1135
+ origin: this.host
1136
+ });
1137
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
1138
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1139
+ shareScope,
1140
+ remoteEntryInitOptions,
1141
+ initScope,
1142
+ remoteInfo: this.remoteInfo,
1143
+ origin: this.host
1144
+ });
1145
+ if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === "undefined") error(RUNTIME_002, runtimeDescMap, {
1146
+ hostName: this.host.name,
1147
+ remoteName: this.remoteInfo.name,
1148
+ remoteEntryUrl: this.remoteInfo.entry,
1149
+ remoteEntryKey: this.remoteInfo.entryGlobalName
1150
+ }, void 0, optionsToMFContext(this.host.options));
1151
+ try {
1152
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
1153
+ } catch (initError) {
1154
+ error(RUNTIME_015, runtimeDescMap, {
1155
+ hostName: this.host.name,
1156
+ remoteName: this.remoteInfo.name,
1157
+ remoteEntryUrl: this.remoteInfo.entry,
1158
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
1159
+ shareScope: this.remoteInfo.shareScope
1160
+ }, `${initError}`, optionsToMFContext(this.host.options));
1161
+ }
1162
+ await this.host.hooks.lifecycle.initContainer.emit({
1163
+ ...initContainerOptions,
1164
+ id,
1165
+ remoteSnapshot,
1166
+ remoteEntryExports
1167
+ });
1168
+ this.inited = true;
1169
+ })();
1170
+ try {
1171
+ await this.initPromise;
1172
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1173
+ id,
1174
+ remoteInfo: this.remoteInfo,
1175
+ remoteSnapshot,
1176
+ remoteEntryExports,
1177
+ origin: this.host
1178
+ });
1179
+ } catch (initError) {
1180
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1181
+ id,
1182
+ remoteInfo: this.remoteInfo,
1183
+ remoteSnapshot,
1184
+ remoteEntryExports,
1185
+ error: initError,
1186
+ origin: this.host
1187
+ });
1188
+ throw initError;
1189
+ } finally {
1190
+ this.initing = false;
1191
+ this.initPromise = void 0;
1192
+ }
1193
+ return remoteEntryExports;
1194
+ }
1195
+ async get(id, expose, options, remoteSnapshot) {
1196
+ const { loadFactory = true } = options || { loadFactory: true };
1197
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
1198
+ this.lib = remoteEntryExports;
1199
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
1200
+ id,
1201
+ expose,
1202
+ moduleInfo: this.remoteInfo,
1203
+ remoteEntryExports,
1204
+ origin: this.host
1205
+ });
1206
+ let moduleFactory;
1207
+ try {
1208
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1209
+ remoteEntryExports,
1210
+ expose,
1211
+ moduleInfo: this.remoteInfo
1212
+ });
1213
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
1214
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
1215
+ if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
1216
+ hostName: this.host.name,
1217
+ remoteName: this.remoteInfo.name,
1218
+ remoteEntryUrl: this.remoteInfo.entry,
1219
+ expose,
1220
+ requestId: id,
1221
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
1222
+ }, void 0, optionsToMFContext(this.host.options));
1223
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1224
+ id,
1225
+ expose,
1226
+ moduleInfo: this.remoteInfo,
1227
+ remoteEntryExports,
1228
+ moduleFactory,
1229
+ origin: this.host
1230
+ });
1231
+ } catch (getExposeError) {
1232
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1233
+ id,
1234
+ expose,
1235
+ moduleInfo: this.remoteInfo,
1236
+ remoteEntryExports,
1237
+ error: getExposeError,
1238
+ origin: this.host
1239
+ });
1240
+ throw getExposeError;
1241
+ }
1242
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
1243
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
1244
+ if (!loadFactory) return wrapModuleFactory;
1245
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
1246
+ id,
1247
+ expose,
1248
+ moduleInfo: this.remoteInfo,
1249
+ loadFactory,
1250
+ origin: this.host
1251
+ });
1252
+ try {
1253
+ const exposeContent = await wrapModuleFactory();
1254
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1255
+ id,
1256
+ expose,
1257
+ moduleInfo: this.remoteInfo,
1258
+ loadFactory,
1259
+ exposeModule: exposeContent,
1260
+ origin: this.host
1261
+ });
1262
+ return exposeContent;
1263
+ } catch (executeFactoryError) {
1264
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1265
+ id,
1266
+ expose,
1267
+ moduleInfo: this.remoteInfo,
1268
+ loadFactory,
1269
+ error: executeFactoryError,
1270
+ origin: this.host
1271
+ });
1272
+ throw executeFactoryError;
1273
+ }
1274
+ }
1275
+ wraperFactory(moduleFactory, id) {
1276
+ function defineModuleId(res, id2) {
1277
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
1278
+ value: id2,
1279
+ enumerable: false
1280
+ });
1281
+ }
1282
+ return () => {
1283
+ const res = moduleFactory();
1284
+ if (res instanceof Promise) return res.then((asyncRes) => {
1285
+ defineModuleId(asyncRes, id);
1286
+ return asyncRes;
1287
+ });
1288
+ defineModuleId(res, id);
1289
+ return res;
1290
+ };
1291
+ }
1292
+ };
1293
+ const REMOTE_DISABLED_MESSAGE = "Remote loading is disabled by experiments.optimization.disableRemote.";
1294
+ var UnavailableRemoteModule = class {
1295
+ constructor() {
1296
+ throw new Error(REMOTE_DISABLED_MESSAGE);
1297
+ }
1298
+ };
989
1299
  typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
1300
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
1301
+ typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
990
1302
  const helpers = helpers_default;
1303
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" && FEDERATION_OPTIMIZE_NO_REMOTE ? UnavailableRemoteModule : Module$1;
991
1304
  const utils = helpers.utils;
992
1305
  const runtimeHelpers = {
993
1306
  utils
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const lazyUtils = require("./utils-CFTy4LVE.js");
2
+ const lazyUtils = require("./utils-5dGErM3C.js");
3
3
  const logger = require("./logger-Dxblx6P-.js");
4
4
  async function safeWrapper(callback, disableWarn) {
5
5
  try {
@@ -470,6 +470,9 @@ function logAndReport(code, descMap, args, logger2, originalErrorMsg, context) {
470
470
  return logger2(getShortErrorMsg(code, descMap, args, originalErrorMsg));
471
471
  }
472
472
  const LOG_CATEGORY = "[ Federation Runtime ]";
473
+ function assert(condition, msgOrCode, descMap, args, context) {
474
+ if (!condition) error(msgOrCode);
475
+ }
473
476
  function error(msgOrCode, descMap, args, originalErrorMsg, context) {
474
477
  if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg2) => {
475
478
  throw new Error(`${LOG_CATEGORY}: ${msg2}`);
@@ -481,6 +484,14 @@ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
481
484
  }
482
485
  throw new Error(`${LOG_CATEGORY}: ${msg}`);
483
486
  }
487
+ const processModuleAlias = (name, subPath) => {
488
+ let moduleName;
489
+ if (name.endsWith("/")) moduleName = name.slice(0, -1);
490
+ else moduleName = name;
491
+ if (subPath.startsWith(".")) subPath = subPath.slice(1);
492
+ moduleName = moduleName + subPath;
493
+ return moduleName;
494
+ };
484
495
  const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
485
496
  const nativeGlobal = (() => {
486
497
  try {
@@ -533,6 +544,10 @@ const getRemoteEntryExports = (name, globalName) => {
533
544
  };
534
545
  const DEFAULT_SCOPE = "default";
535
546
  const DEFAULT_REMOTE_TYPE = "global";
547
+ function composeRemoteRequestId(remoteName, expose) {
548
+ if (!expose || expose === ".") return remoteName;
549
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
550
+ }
536
551
  function matchRemoteWithNameAndExpose(remotes, id) {
537
552
  for (const remote of remotes) {
538
553
  const isNameMatched = id.startsWith(remote.name);
@@ -810,6 +825,42 @@ function getRemoteInfo(remote) {
810
825
  shareScope: remote.shareScope || DEFAULT_SCOPE
811
826
  };
812
827
  }
828
+ function remoteToEntry(r) {
829
+ return {
830
+ name: r.name,
831
+ alias: r.alias,
832
+ entry: "entry" in r ? r.entry : void 0,
833
+ version: "version" in r ? r.version : void 0,
834
+ type: r.type,
835
+ entryGlobalName: r.entryGlobalName,
836
+ shareScope: r.shareScope
837
+ };
838
+ }
839
+ function optionsToMFContext(options) {
840
+ var _a, _b, _c, _d, _e, _f;
841
+ const shared = {};
842
+ for (const [pkgName, versions] of Object.entries(options.shared)) {
843
+ const first = versions[0];
844
+ if (first) shared[pkgName] = {
845
+ version: first.version,
846
+ singleton: (_a = first.shareConfig) == null ? void 0 : _a.singleton,
847
+ requiredVersion: ((_b = first.shareConfig) == null ? void 0 : _b.requiredVersion) === false ? false : (_c = first.shareConfig) == null ? void 0 : _c.requiredVersion,
848
+ eager: first.eager,
849
+ strictVersion: (_d = first.shareConfig) == null ? void 0 : _d.strictVersion
850
+ };
851
+ }
852
+ return {
853
+ project: {
854
+ name: options.name,
855
+ mfRole: ((_e = options.remotes) == null ? void 0 : _e.length) > 0 ? "host" : "unknown"
856
+ },
857
+ mfConfig: {
858
+ name: options.name,
859
+ remotes: ((_f = options.remotes) == null ? void 0 : _f.map(remoteToEntry)) ?? [],
860
+ shared
861
+ }
862
+ };
863
+ }
813
864
  function isTimeoutError(error2) {
814
865
  if (!(error2 instanceof Error)) return false;
815
866
  return error2.message.includes("timed out") || error2.name.includes("Timeout");
@@ -987,8 +1038,270 @@ var helpers_default = {
987
1038
  getRemoteInfo
988
1039
  }
989
1040
  };
1041
+ function getAvailableExposeNames(remoteSnapshot) {
1042
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
1043
+ const exposes = remoteSnapshot.modules.map((module2) => module2.moduleName).filter(Boolean);
1044
+ return exposes.length ? exposes.join(",") : void 0;
1045
+ }
1046
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
1047
+ const localShareScopeMap = hostShareScopeMap;
1048
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
1049
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
1050
+ shareScopeKeys.forEach((shareScopeKey) => {
1051
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
1052
+ });
1053
+ const remoteEntryInitOptions = {
1054
+ version: remoteInfo.version || "",
1055
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
1056
+ };
1057
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
1058
+ value: localShareScopeMap,
1059
+ enumerable: false
1060
+ });
1061
+ return {
1062
+ remoteEntryInitOptions,
1063
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
1064
+ initScope: rawInitScope ?? []
1065
+ };
1066
+ }
1067
+ var Module$1 = class {
1068
+ constructor({ remoteInfo, host }) {
1069
+ this.inited = false;
1070
+ this.initing = false;
1071
+ this.lib = void 0;
1072
+ this.remoteInfo = remoteInfo;
1073
+ this.host = host;
1074
+ }
1075
+ async getEntry(expose) {
1076
+ if (this.remoteEntryExports) return this.remoteEntryExports;
1077
+ const remoteEntryExports = await getRemoteEntry({
1078
+ origin: this.host,
1079
+ remoteInfo: this.remoteInfo,
1080
+ remoteEntryExports: this.remoteEntryExports,
1081
+ resourceContext: {
1082
+ initiator: "loadRemote",
1083
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
1084
+ resourceType: "remoteEntry"
1085
+ }
1086
+ });
1087
+ assert(remoteEntryExports, `remoteEntryExports is undefined
1088
+ ${lazyUtils.safeToString(this.remoteInfo)}`);
1089
+ this.remoteEntryExports = remoteEntryExports;
1090
+ return this.remoteEntryExports;
1091
+ }
1092
+ async init(id, remoteSnapshot, rawInitScope, expose) {
1093
+ const remoteEntryExports = await this.getEntry(expose);
1094
+ if (this.inited) {
1095
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1096
+ id,
1097
+ remoteInfo: this.remoteInfo,
1098
+ remoteSnapshot,
1099
+ remoteEntryExports,
1100
+ cached: true,
1101
+ origin: this.host
1102
+ });
1103
+ return remoteEntryExports;
1104
+ }
1105
+ if (this.initPromise) {
1106
+ try {
1107
+ await this.initPromise;
1108
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1109
+ id,
1110
+ remoteInfo: this.remoteInfo,
1111
+ remoteSnapshot,
1112
+ remoteEntryExports,
1113
+ cached: true,
1114
+ origin: this.host
1115
+ });
1116
+ } catch (initError) {
1117
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1118
+ id,
1119
+ remoteInfo: this.remoteInfo,
1120
+ remoteSnapshot,
1121
+ remoteEntryExports,
1122
+ error: initError,
1123
+ cached: true,
1124
+ origin: this.host
1125
+ });
1126
+ throw initError;
1127
+ }
1128
+ return remoteEntryExports;
1129
+ }
1130
+ this.initing = true;
1131
+ this.initPromise = (async () => {
1132
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
1133
+ id,
1134
+ remoteInfo: this.remoteInfo,
1135
+ remoteSnapshot,
1136
+ origin: this.host
1137
+ });
1138
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
1139
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
1140
+ shareScope,
1141
+ remoteEntryInitOptions,
1142
+ initScope,
1143
+ remoteInfo: this.remoteInfo,
1144
+ origin: this.host
1145
+ });
1146
+ if (typeof (remoteEntryExports == null ? void 0 : remoteEntryExports.init) === "undefined") error(RUNTIME_002, runtimeDescMap, {
1147
+ hostName: this.host.name,
1148
+ remoteName: this.remoteInfo.name,
1149
+ remoteEntryUrl: this.remoteInfo.entry,
1150
+ remoteEntryKey: this.remoteInfo.entryGlobalName
1151
+ }, void 0, optionsToMFContext(this.host.options));
1152
+ try {
1153
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
1154
+ } catch (initError) {
1155
+ error(RUNTIME_015, runtimeDescMap, {
1156
+ hostName: this.host.name,
1157
+ remoteName: this.remoteInfo.name,
1158
+ remoteEntryUrl: this.remoteInfo.entry,
1159
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
1160
+ shareScope: this.remoteInfo.shareScope
1161
+ }, `${initError}`, optionsToMFContext(this.host.options));
1162
+ }
1163
+ await this.host.hooks.lifecycle.initContainer.emit({
1164
+ ...initContainerOptions,
1165
+ id,
1166
+ remoteSnapshot,
1167
+ remoteEntryExports
1168
+ });
1169
+ this.inited = true;
1170
+ })();
1171
+ try {
1172
+ await this.initPromise;
1173
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1174
+ id,
1175
+ remoteInfo: this.remoteInfo,
1176
+ remoteSnapshot,
1177
+ remoteEntryExports,
1178
+ origin: this.host
1179
+ });
1180
+ } catch (initError) {
1181
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
1182
+ id,
1183
+ remoteInfo: this.remoteInfo,
1184
+ remoteSnapshot,
1185
+ remoteEntryExports,
1186
+ error: initError,
1187
+ origin: this.host
1188
+ });
1189
+ throw initError;
1190
+ } finally {
1191
+ this.initing = false;
1192
+ this.initPromise = void 0;
1193
+ }
1194
+ return remoteEntryExports;
1195
+ }
1196
+ async get(id, expose, options, remoteSnapshot) {
1197
+ const { loadFactory = true } = options || { loadFactory: true };
1198
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
1199
+ this.lib = remoteEntryExports;
1200
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
1201
+ id,
1202
+ expose,
1203
+ moduleInfo: this.remoteInfo,
1204
+ remoteEntryExports,
1205
+ origin: this.host
1206
+ });
1207
+ let moduleFactory;
1208
+ try {
1209
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
1210
+ remoteEntryExports,
1211
+ expose,
1212
+ moduleInfo: this.remoteInfo
1213
+ });
1214
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
1215
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
1216
+ if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
1217
+ hostName: this.host.name,
1218
+ remoteName: this.remoteInfo.name,
1219
+ remoteEntryUrl: this.remoteInfo.entry,
1220
+ expose,
1221
+ requestId: id,
1222
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
1223
+ }, void 0, optionsToMFContext(this.host.options));
1224
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1225
+ id,
1226
+ expose,
1227
+ moduleInfo: this.remoteInfo,
1228
+ remoteEntryExports,
1229
+ moduleFactory,
1230
+ origin: this.host
1231
+ });
1232
+ } catch (getExposeError) {
1233
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
1234
+ id,
1235
+ expose,
1236
+ moduleInfo: this.remoteInfo,
1237
+ remoteEntryExports,
1238
+ error: getExposeError,
1239
+ origin: this.host
1240
+ });
1241
+ throw getExposeError;
1242
+ }
1243
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
1244
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
1245
+ if (!loadFactory) return wrapModuleFactory;
1246
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
1247
+ id,
1248
+ expose,
1249
+ moduleInfo: this.remoteInfo,
1250
+ loadFactory,
1251
+ origin: this.host
1252
+ });
1253
+ try {
1254
+ const exposeContent = await wrapModuleFactory();
1255
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1256
+ id,
1257
+ expose,
1258
+ moduleInfo: this.remoteInfo,
1259
+ loadFactory,
1260
+ exposeModule: exposeContent,
1261
+ origin: this.host
1262
+ });
1263
+ return exposeContent;
1264
+ } catch (executeFactoryError) {
1265
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
1266
+ id,
1267
+ expose,
1268
+ moduleInfo: this.remoteInfo,
1269
+ loadFactory,
1270
+ error: executeFactoryError,
1271
+ origin: this.host
1272
+ });
1273
+ throw executeFactoryError;
1274
+ }
1275
+ }
1276
+ wraperFactory(moduleFactory, id) {
1277
+ function defineModuleId(res, id2) {
1278
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
1279
+ value: id2,
1280
+ enumerable: false
1281
+ });
1282
+ }
1283
+ return () => {
1284
+ const res = moduleFactory();
1285
+ if (res instanceof Promise) return res.then((asyncRes) => {
1286
+ defineModuleId(asyncRes, id);
1287
+ return asyncRes;
1288
+ });
1289
+ defineModuleId(res, id);
1290
+ return res;
1291
+ };
1292
+ }
1293
+ };
1294
+ const REMOTE_DISABLED_MESSAGE = "Remote loading is disabled by experiments.optimization.disableRemote.";
1295
+ var UnavailableRemoteModule = class {
1296
+ constructor() {
1297
+ throw new Error(REMOTE_DISABLED_MESSAGE);
1298
+ }
1299
+ };
990
1300
  typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === "boolean" ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN : true;
1301
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
1302
+ typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
991
1303
  const helpers = helpers_default;
1304
+ typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" && FEDERATION_OPTIMIZE_NO_REMOTE ? UnavailableRemoteModule : Module$1;
992
1305
  const utils = helpers.utils;
993
1306
  const runtimeHelpers = {
994
1307
  utils