@luzmo/embed 6.13.2 → 6.13.3-es2021

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.
@@ -1659,6 +1659,8 @@ function createScript(info) {
1659
1659
  function createLink(info) {
1660
1660
  let link = null;
1661
1661
  let needAttach = true;
1662
+ let timeout = 2e4;
1663
+ let timeoutId;
1662
1664
  const links = document.getElementsByTagName("link");
1663
1665
  for (let i7 = 0; i7 < links.length; i7++) {
1664
1666
  const l3 = links[i7];
@@ -1674,19 +1676,42 @@ function createLink(info) {
1674
1676
  link = document.createElement("link");
1675
1677
  link.setAttribute("href", info.url);
1676
1678
  let createLinkRes = void 0;
1679
+ let shouldApplyAttrs = true;
1677
1680
  const attrs = info.attrs;
1678
1681
  if (info.createLinkHook) {
1679
1682
  createLinkRes = info.createLinkHook(info.url, attrs);
1680
- if (createLinkRes instanceof HTMLLinkElement) link = createLinkRes;
1683
+ if (createLinkRes instanceof HTMLLinkElement) {
1684
+ link = createLinkRes;
1685
+ shouldApplyAttrs = false;
1686
+ } else if (typeof createLinkRes === "object") {
1687
+ if ("link" in createLinkRes && createLinkRes.link) {
1688
+ link = createLinkRes.link;
1689
+ shouldApplyAttrs = false;
1690
+ }
1691
+ if ("timeout" in createLinkRes && createLinkRes.timeout) timeout = createLinkRes.timeout;
1692
+ }
1681
1693
  }
1682
- if (attrs && !createLinkRes) Object.keys(attrs).forEach((name) => {
1694
+ if (attrs && shouldApplyAttrs) Object.keys(attrs).forEach((name) => {
1683
1695
  if (link && !link.getAttribute(name)) link.setAttribute(name, attrs[name]);
1684
1696
  });
1685
1697
  }
1698
+ if (!needAttach) {
1699
+ Promise.resolve().then(() => {
1700
+ info?.cb && info?.cb();
1701
+ });
1702
+ return {
1703
+ link,
1704
+ needAttach
1705
+ };
1706
+ }
1686
1707
  const onLinkComplete = (prev, event) => {
1708
+ if (timeoutId) clearTimeout(timeoutId);
1687
1709
  const onLinkCompleteCallback = () => {
1688
- if (event?.type === "error") info?.onErrorCallback && info?.onErrorCallback(event);
1689
- else info?.cb && info?.cb();
1710
+ if (event?.type === "error") {
1711
+ const linkError = /* @__PURE__ */ new Error(event?.isTimeout ? `LinkNetworkError: Link "${info.url}" timed out.` : `LinkNetworkError: Failed to load link "${info.url}" - the URL is unreachable or the server returned an error.`);
1712
+ linkError.name = "LinkNetworkError";
1713
+ info?.onErrorCallback && info?.onErrorCallback(linkError);
1714
+ } else info?.cb && info?.cb();
1690
1715
  };
1691
1716
  if (link) {
1692
1717
  link.onerror = null;
@@ -1705,6 +1730,12 @@ function createLink(info) {
1705
1730
  };
1706
1731
  link.onerror = onLinkComplete.bind(null, link.onerror);
1707
1732
  link.onload = onLinkComplete.bind(null, link.onload);
1733
+ timeoutId = setTimeout(() => {
1734
+ onLinkComplete(null, {
1735
+ type: "error",
1736
+ isTimeout: true
1737
+ });
1738
+ }, timeout);
1708
1739
  return {
1709
1740
  link,
1710
1741
  needAttach
@@ -1986,8 +2017,8 @@ function setGlobalDefaultVal(target) {
1986
2017
  }
1987
2018
  setGlobalDefaultVal(CurrentGlobal);
1988
2019
  setGlobalDefaultVal(nativeGlobal);
1989
- function setGlobalFederationInstance(FederationInstance2) {
1990
- CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance2);
2020
+ function setGlobalFederationInstance(FederationInstance) {
2021
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
1991
2022
  }
1992
2023
  function getGlobalFederationConstructor() {
1993
2024
  return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
@@ -1995,7 +2026,7 @@ function getGlobalFederationConstructor() {
1995
2026
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
1996
2027
  if (isDebug) {
1997
2028
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
1998
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.4.0";
2029
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.5.0";
1999
2030
  }
2000
2031
  }
2001
2032
  function getInfoWithoutType(target, key) {
@@ -2579,6 +2610,10 @@ function directShare(shared, useTreesShaking) {
2579
2610
  }
2580
2611
 
2581
2612
  // node_modules/@module-federation/runtime-core/dist/utils/manifest.js
2613
+ function composeRemoteRequestId(remoteName, expose) {
2614
+ if (!expose || expose === ".") return remoteName;
2615
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
2616
+ }
2582
2617
  function matchRemoteWithNameAndExpose(remotes, id) {
2583
2618
  for (const remote of remotes) {
2584
2619
  const isNameMatched = id.startsWith(remote.name);
@@ -2637,6 +2672,9 @@ var RUNTIME_009 = "RUNTIME-009";
2637
2672
  var RUNTIME_010 = "RUNTIME-010";
2638
2673
  var RUNTIME_011 = "RUNTIME-011";
2639
2674
  var RUNTIME_012 = "RUNTIME-012";
2675
+ var RUNTIME_013 = "RUNTIME-013";
2676
+ var RUNTIME_014 = "RUNTIME-014";
2677
+ var RUNTIME_015 = "RUNTIME-015";
2640
2678
  var TYPE_001 = "TYPE-001";
2641
2679
  var BUILD_001 = "BUILD-001";
2642
2680
  var BUILD_002 = "BUILD-002";
@@ -2654,7 +2692,10 @@ var runtimeDescMap = {
2654
2692
  [RUNTIME_009]: "Please call createInstance first.",
2655
2693
  [RUNTIME_010]: 'The name option cannot be changed after initialization. If you want to create a new instance with a different name, please use "createInstance" api.',
2656
2694
  [RUNTIME_011]: "The remoteEntry URL is missing from the remote snapshot.",
2657
- [RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.'
2695
+ [RUNTIME_012]: 'The getter for the shared module is not a function. This may be caused by setting "shared.import: false" without the host providing the corresponding lib.',
2696
+ [RUNTIME_013]: "The manifest is not a valid Module Federation manifest.",
2697
+ [RUNTIME_014]: "The remote does not expose the requested module.",
2698
+ [RUNTIME_015]: "Remote container initialization failed."
2658
2699
  };
2659
2700
  var typeDescMap = { [TYPE_001]: "Failed to generate type declaration. Execute the below cmd to reproduce and fix the error." };
2660
2701
  var buildDescMap = {
@@ -2704,7 +2745,7 @@ function handleRemoteEntryLoaded(name, globalName, entry) {
2704
2745
  });
2705
2746
  return entryExports;
2706
2747
  }
2707
- async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl }) {
2748
+ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
2708
2749
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
2709
2750
  if (remoteEntryExports) return remoteEntryExports;
2710
2751
  const url = getEntryUrl ? getEntryUrl(entry) : entry;
@@ -2714,7 +2755,11 @@ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook
2714
2755
  const res = loaderHook.lifecycle.createScript.emit({
2715
2756
  url: url2,
2716
2757
  attrs,
2717
- remoteInfo
2758
+ remoteInfo,
2759
+ resourceContext: resourceContext ? {
2760
+ ...resourceContext,
2761
+ url: url2
2762
+ } : void 0
2718
2763
  });
2719
2764
  if (!res) return;
2720
2765
  if (res instanceof HTMLScriptElement) return res;
@@ -2730,7 +2775,7 @@ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook
2730
2775
  }, originalMsg);
2731
2776
  });
2732
2777
  }
2733
- async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl }) {
2778
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
2734
2779
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
2735
2780
  switch (type) {
2736
2781
  case "esm":
@@ -2751,11 +2796,12 @@ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEnt
2751
2796
  name,
2752
2797
  remoteInfo,
2753
2798
  loaderHook,
2754
- getEntryUrl
2799
+ getEntryUrl,
2800
+ resourceContext
2755
2801
  });
2756
2802
  }
2757
2803
  }
2758
- async function loadEntryNode({ remoteInfo, loaderHook }) {
2804
+ async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
2759
2805
  const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
2760
2806
  const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
2761
2807
  if (remoteEntryExports) return remoteEntryExports;
@@ -2769,7 +2815,11 @@ async function loadEntryNode({ remoteInfo, loaderHook }) {
2769
2815
  const res = loaderHook.lifecycle.createScript.emit({
2770
2816
  url,
2771
2817
  attrs,
2772
- remoteInfo
2818
+ remoteInfo,
2819
+ resourceContext: resourceContext ? {
2820
+ ...resourceContext,
2821
+ url
2822
+ } : void 0
2773
2823
  });
2774
2824
  if (!res) return;
2775
2825
  if ("url" in res) return res;
@@ -2785,13 +2835,14 @@ function getRemoteEntryUniqueKey(remoteInfo) {
2785
2835
  return composeKeyWithSeparator(name, entry);
2786
2836
  }
2787
2837
  async function getRemoteEntry(params) {
2788
- const { origin, remoteEntryExports, remoteInfo, getEntryUrl, _inErrorHandling = false } = params;
2838
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
2789
2839
  const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
2790
2840
  if (remoteEntryExports) return remoteEntryExports;
2791
2841
  if (!globalLoading[uniqueKey]) {
2792
2842
  const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
2793
2843
  const loaderHook = origin.loaderHook;
2794
2844
  globalLoading[uniqueKey] = loadEntryHook.emit({
2845
+ origin,
2795
2846
  loaderHook,
2796
2847
  remoteInfo,
2797
2848
  remoteEntryExports
@@ -2801,11 +2852,20 @@ async function getRemoteEntry(params) {
2801
2852
  remoteInfo,
2802
2853
  remoteEntryExports,
2803
2854
  loaderHook,
2804
- getEntryUrl
2855
+ getEntryUrl,
2856
+ resourceContext
2805
2857
  }) : loadEntryNode({
2806
2858
  remoteInfo,
2807
- loaderHook
2859
+ loaderHook,
2860
+ resourceContext
2861
+ });
2862
+ }).then(async (res) => {
2863
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
2864
+ origin,
2865
+ remoteInfo,
2866
+ remoteEntryExports: res
2808
2867
  });
2868
+ return res;
2809
2869
  }).catch(async (err) => {
2810
2870
  const uniqueKey2 = getRemoteEntryUniqueKey(remoteInfo);
2811
2871
  const isScriptExecutionError = err instanceof Error && err.message.includes("ScriptExecutionError");
@@ -2824,8 +2884,21 @@ async function getRemoteEntry(params) {
2824
2884
  globalLoading,
2825
2885
  uniqueKey: uniqueKey2
2826
2886
  });
2827
- if (RemoteEntryExports) return RemoteEntryExports;
2887
+ if (RemoteEntryExports) {
2888
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
2889
+ origin,
2890
+ remoteInfo,
2891
+ remoteEntryExports: RemoteEntryExports,
2892
+ recovered: true
2893
+ });
2894
+ return RemoteEntryExports;
2895
+ }
2828
2896
  }
2897
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
2898
+ origin,
2899
+ remoteInfo,
2900
+ error: err
2901
+ });
2829
2902
  throw err;
2830
2903
  });
2831
2904
  }
@@ -2935,22 +3008,113 @@ function normalizePreloadExposes(exposes) {
2935
3008
  return expose;
2936
3009
  });
2937
3010
  }
2938
- function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
3011
+ function isTimeoutError(error3) {
3012
+ if (!(error3 instanceof Error)) return false;
3013
+ return error3.message.includes("timed out") || error3.name.includes("Timeout");
3014
+ }
3015
+ function createAssetResult(context, url, status, error3) {
3016
+ return {
3017
+ url,
3018
+ status,
3019
+ resourceType: context.resourceType,
3020
+ initiator: context.initiator,
3021
+ id: context.id,
3022
+ error: error3
3023
+ };
3024
+ }
3025
+ async function waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, context) {
3026
+ const cachedRemote = host.moduleCache.get(entryRemoteInfo.name);
3027
+ const url = entryRemoteInfo.entry;
3028
+ if (cachedRemote?.remoteEntryExports) return createAssetResult(context, url, "cached");
3029
+ try {
3030
+ if (!await getRemoteEntry({
3031
+ origin: host,
3032
+ remoteInfo: entryRemoteInfo,
3033
+ remoteEntryExports: cachedRemote?.remoteEntryExports,
3034
+ resourceContext: {
3035
+ ...context,
3036
+ url
3037
+ }
3038
+ })) throw new Error(`Failed to load remoteEntry "${url}".`);
3039
+ return createAssetResult(context, url, "success");
3040
+ } catch (error3) {
3041
+ return createAssetResult(context, url, isTimeoutError(error3) ? "timeout" : "error", error3);
3042
+ }
3043
+ }
3044
+ function waitForLinkPreload({ host, remoteInfo, url, attrs, context, needDeleteLink }) {
3045
+ return new Promise((resolve) => {
3046
+ const { link, needAttach } = createLink({
3047
+ url,
3048
+ cb: () => {
3049
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
3050
+ },
3051
+ onErrorCallback: (error3) => {
3052
+ resolve(createAssetResult(context, url, isTimeoutError(error3) ? "timeout" : "error", error3));
3053
+ },
3054
+ attrs,
3055
+ createLinkHook: (hookUrl, hookAttrs) => {
3056
+ const res = host.loaderHook.lifecycle.createLink.emit({
3057
+ url: hookUrl,
3058
+ attrs: hookAttrs,
3059
+ remoteInfo,
3060
+ resourceContext: {
3061
+ ...context,
3062
+ url: hookUrl
3063
+ }
3064
+ });
3065
+ if (res instanceof HTMLLinkElement) return res;
3066
+ return res;
3067
+ },
3068
+ needDeleteLink
3069
+ });
3070
+ needAttach && document.head.appendChild(link);
3071
+ });
3072
+ }
3073
+ function waitForScriptPreload({ host, remoteInfo, url, attrs, context }) {
3074
+ return new Promise((resolve) => {
3075
+ const { script, needAttach } = createScript({
3076
+ url,
3077
+ cb: () => {
3078
+ resolve(createAssetResult(context, url, needAttach ? "success" : "cached"));
3079
+ },
3080
+ onErrorCallback: (error3) => {
3081
+ resolve(createAssetResult(context, url, isTimeoutError(error3) ? "timeout" : "error", error3));
3082
+ },
3083
+ attrs,
3084
+ createScriptHook: (hookUrl, hookAttrs) => {
3085
+ const res = host.loaderHook.lifecycle.createScript.emit({
3086
+ url: hookUrl,
3087
+ attrs: hookAttrs,
3088
+ remoteInfo,
3089
+ resourceContext: {
3090
+ ...context,
3091
+ url: hookUrl
3092
+ }
3093
+ });
3094
+ if (res instanceof HTMLScriptElement) return res;
3095
+ return res;
3096
+ },
3097
+ needDeleteScript: true
3098
+ });
3099
+ needAttach && document.head.appendChild(script);
3100
+ });
3101
+ }
3102
+ function createResourceContext(baseContext, resourceType) {
3103
+ return {
3104
+ ...baseContext,
3105
+ resourceType
3106
+ };
3107
+ }
3108
+ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true, baseContext = {
3109
+ initiator: "preloadRemote",
3110
+ id: remoteInfo.name
3111
+ }) {
2939
3112
  const { cssAssets, jsAssetsWithoutEntry, entryAssets } = assets;
3113
+ const results = [];
2940
3114
  if (host.options.inBrowser) {
2941
3115
  entryAssets.forEach((asset) => {
2942
- const { moduleInfo } = asset;
2943
- const module2 = host.moduleCache.get(remoteInfo.name);
2944
- if (module2) getRemoteEntry({
2945
- origin: host,
2946
- remoteInfo: moduleInfo,
2947
- remoteEntryExports: module2.remoteEntryExports
2948
- });
2949
- else getRemoteEntry({
2950
- origin: host,
2951
- remoteInfo: moduleInfo,
2952
- remoteEntryExports: void 0
2953
- });
3116
+ const { moduleInfo: entryRemoteInfo } = asset;
3117
+ results.push(waitForRemoteEntryPreload(host, remoteInfo, entryRemoteInfo, createResourceContext(baseContext, "remoteEntry")));
2954
3118
  });
2955
3119
  if (useLinkPreload) {
2956
3120
  const defaultAttrs = {
@@ -2958,21 +3122,13 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
2958
3122
  as: "style"
2959
3123
  };
2960
3124
  cssAssets.forEach((cssUrl) => {
2961
- const { link: cssEl, needAttach } = createLink({
3125
+ results.push(waitForLinkPreload({
3126
+ host,
3127
+ remoteInfo,
2962
3128
  url: cssUrl,
2963
- cb: () => {
2964
- },
2965
3129
  attrs: defaultAttrs,
2966
- createLinkHook: (url, attrs) => {
2967
- const res = host.loaderHook.lifecycle.createLink.emit({
2968
- url,
2969
- attrs,
2970
- remoteInfo
2971
- });
2972
- if (res instanceof HTMLLinkElement) return res;
2973
- }
2974
- });
2975
- needAttach && document.head.appendChild(cssEl);
3130
+ context: createResourceContext(baseContext, "css")
3131
+ }));
2976
3132
  });
2977
3133
  } else {
2978
3134
  const defaultAttrs = {
@@ -2980,22 +3136,14 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
2980
3136
  type: "text/css"
2981
3137
  };
2982
3138
  cssAssets.forEach((cssUrl) => {
2983
- const { link: cssEl, needAttach } = createLink({
3139
+ results.push(waitForLinkPreload({
3140
+ host,
3141
+ remoteInfo,
2984
3142
  url: cssUrl,
2985
- cb: () => {
2986
- },
2987
3143
  attrs: defaultAttrs,
2988
- createLinkHook: (url, attrs) => {
2989
- const res = host.loaderHook.lifecycle.createLink.emit({
2990
- url,
2991
- attrs,
2992
- remoteInfo
2993
- });
2994
- if (res instanceof HTMLLinkElement) return res;
2995
- },
2996
- needDeleteLink: false
2997
- });
2998
- needAttach && document.head.appendChild(cssEl);
3144
+ needDeleteLink: false,
3145
+ context: createResourceContext(baseContext, "css")
3146
+ }));
2999
3147
  });
3000
3148
  }
3001
3149
  if (useLinkPreload) {
@@ -3004,21 +3152,13 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
3004
3152
  as: "script"
3005
3153
  };
3006
3154
  jsAssetsWithoutEntry.forEach((jsUrl) => {
3007
- const { link: linkEl, needAttach } = createLink({
3155
+ results.push(waitForLinkPreload({
3156
+ host,
3157
+ remoteInfo,
3008
3158
  url: jsUrl,
3009
- cb: () => {
3010
- },
3011
3159
  attrs: defaultAttrs,
3012
- createLinkHook: (url, attrs) => {
3013
- const res = host.loaderHook.lifecycle.createLink.emit({
3014
- url,
3015
- attrs,
3016
- remoteInfo
3017
- });
3018
- if (res instanceof HTMLLinkElement) return res;
3019
- }
3020
- });
3021
- needAttach && document.head.appendChild(linkEl);
3160
+ context: createResourceContext(baseContext, "js")
3161
+ }));
3022
3162
  });
3023
3163
  } else {
3024
3164
  const defaultAttrs = {
@@ -3026,28 +3166,25 @@ function preloadAssets(remoteInfo, host, assets, useLinkPreload = true) {
3026
3166
  type: remoteInfo?.type === "module" ? "module" : "text/javascript"
3027
3167
  };
3028
3168
  jsAssetsWithoutEntry.forEach((jsUrl) => {
3029
- const { script: scriptEl, needAttach } = createScript({
3169
+ results.push(waitForScriptPreload({
3170
+ host,
3171
+ remoteInfo,
3030
3172
  url: jsUrl,
3031
- cb: () => {
3032
- },
3033
3173
  attrs: defaultAttrs,
3034
- createScriptHook: (url, attrs) => {
3035
- const res = host.loaderHook.lifecycle.createScript.emit({
3036
- url,
3037
- attrs,
3038
- remoteInfo
3039
- });
3040
- if (res instanceof HTMLScriptElement) return res;
3041
- },
3042
- needDeleteScript: true
3043
- });
3044
- needAttach && document.head.appendChild(scriptEl);
3174
+ context: createResourceContext(baseContext, "js")
3175
+ }));
3045
3176
  });
3046
3177
  }
3047
3178
  }
3179
+ return Promise.all(results);
3048
3180
  }
3049
3181
 
3050
3182
  // node_modules/@module-federation/runtime-core/dist/module/index.js
3183
+ function getAvailableExposeNames(remoteSnapshot) {
3184
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
3185
+ const exposes = remoteSnapshot.modules.map((module2) => module2.moduleName).filter(Boolean);
3186
+ return exposes.length ? exposes.join(",") : void 0;
3187
+ }
3051
3188
  function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
3052
3189
  const localShareScopeMap = hostShareScopeMap;
3053
3190
  const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
@@ -3077,27 +3214,69 @@ var Module$1 = class {
3077
3214
  this.remoteInfo = remoteInfo;
3078
3215
  this.host = host;
3079
3216
  }
3080
- async getEntry() {
3217
+ async getEntry(expose) {
3081
3218
  if (this.remoteEntryExports) return this.remoteEntryExports;
3082
3219
  const remoteEntryExports = await getRemoteEntry({
3083
3220
  origin: this.host,
3084
3221
  remoteInfo: this.remoteInfo,
3085
- remoteEntryExports: this.remoteEntryExports
3222
+ remoteEntryExports: this.remoteEntryExports,
3223
+ resourceContext: {
3224
+ initiator: "loadRemote",
3225
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
3226
+ resourceType: "remoteEntry"
3227
+ }
3086
3228
  });
3087
3229
  assert2(remoteEntryExports, `remoteEntryExports is undefined
3088
3230
  ${safeToString(this.remoteInfo)}`);
3089
3231
  this.remoteEntryExports = remoteEntryExports;
3090
3232
  return this.remoteEntryExports;
3091
3233
  }
3092
- async init(id, remoteSnapshot, rawInitScope) {
3093
- const remoteEntryExports = await this.getEntry();
3094
- if (this.inited) return remoteEntryExports;
3234
+ async init(id, remoteSnapshot, rawInitScope, expose) {
3235
+ const remoteEntryExports = await this.getEntry(expose);
3236
+ if (this.inited) {
3237
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
3238
+ id,
3239
+ remoteInfo: this.remoteInfo,
3240
+ remoteSnapshot,
3241
+ remoteEntryExports,
3242
+ cached: true,
3243
+ origin: this.host
3244
+ });
3245
+ return remoteEntryExports;
3246
+ }
3095
3247
  if (this.initPromise) {
3096
- await this.initPromise;
3248
+ try {
3249
+ await this.initPromise;
3250
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
3251
+ id,
3252
+ remoteInfo: this.remoteInfo,
3253
+ remoteSnapshot,
3254
+ remoteEntryExports,
3255
+ cached: true,
3256
+ origin: this.host
3257
+ });
3258
+ } catch (initError) {
3259
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
3260
+ id,
3261
+ remoteInfo: this.remoteInfo,
3262
+ remoteSnapshot,
3263
+ remoteEntryExports,
3264
+ error: initError,
3265
+ cached: true,
3266
+ origin: this.host
3267
+ });
3268
+ throw initError;
3269
+ }
3097
3270
  return remoteEntryExports;
3098
3271
  }
3099
3272
  this.initing = true;
3100
3273
  this.initPromise = (async () => {
3274
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
3275
+ id,
3276
+ remoteInfo: this.remoteInfo,
3277
+ remoteSnapshot,
3278
+ origin: this.host
3279
+ });
3101
3280
  const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
3102
3281
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
3103
3282
  shareScope,
@@ -3112,7 +3291,17 @@ var Module$1 = class {
3112
3291
  remoteEntryUrl: this.remoteInfo.entry,
3113
3292
  remoteEntryKey: this.remoteInfo.entryGlobalName
3114
3293
  }, void 0, optionsToMFContext(this.host.options));
3115
- await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
3294
+ try {
3295
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
3296
+ } catch (initError) {
3297
+ error2(RUNTIME_015, runtimeDescMap, {
3298
+ hostName: this.host.name,
3299
+ remoteName: this.remoteInfo.name,
3300
+ remoteEntryUrl: this.remoteInfo.entry,
3301
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
3302
+ shareScope: this.remoteInfo.shareScope
3303
+ }, `${initError}`, optionsToMFContext(this.host.options));
3304
+ }
3116
3305
  await this.host.hooks.lifecycle.initContainer.emit({
3117
3306
  ...initContainerOptions,
3118
3307
  id,
@@ -3123,6 +3312,23 @@ var Module$1 = class {
3123
3312
  })();
3124
3313
  try {
3125
3314
  await this.initPromise;
3315
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
3316
+ id,
3317
+ remoteInfo: this.remoteInfo,
3318
+ remoteSnapshot,
3319
+ remoteEntryExports,
3320
+ origin: this.host
3321
+ });
3322
+ } catch (initError) {
3323
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
3324
+ id,
3325
+ remoteInfo: this.remoteInfo,
3326
+ remoteSnapshot,
3327
+ remoteEntryExports,
3328
+ error: initError,
3329
+ origin: this.host
3330
+ });
3331
+ throw initError;
3126
3332
  } finally {
3127
3333
  this.initing = false;
3128
3334
  this.initPromise = void 0;
@@ -3131,20 +3337,83 @@ var Module$1 = class {
3131
3337
  }
3132
3338
  async get(id, expose, options, remoteSnapshot) {
3133
3339
  const { loadFactory = true } = options || { loadFactory: true };
3134
- const remoteEntryExports = await this.init(id, remoteSnapshot);
3340
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
3135
3341
  this.lib = remoteEntryExports;
3136
- let moduleFactory;
3137
- moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
3138
- remoteEntryExports,
3342
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
3343
+ id,
3139
3344
  expose,
3140
- moduleInfo: this.remoteInfo
3345
+ moduleInfo: this.remoteInfo,
3346
+ remoteEntryExports,
3347
+ origin: this.host
3141
3348
  });
3142
- if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
3143
- assert2(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
3349
+ let moduleFactory;
3350
+ try {
3351
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
3352
+ remoteEntryExports,
3353
+ expose,
3354
+ moduleInfo: this.remoteInfo
3355
+ });
3356
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
3357
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
3358
+ if (!moduleFactory) error2(RUNTIME_014, runtimeDescMap, {
3359
+ hostName: this.host.name,
3360
+ remoteName: this.remoteInfo.name,
3361
+ remoteEntryUrl: this.remoteInfo.entry,
3362
+ expose,
3363
+ requestId: id,
3364
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
3365
+ }, void 0, optionsToMFContext(this.host.options));
3366
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
3367
+ id,
3368
+ expose,
3369
+ moduleInfo: this.remoteInfo,
3370
+ remoteEntryExports,
3371
+ moduleFactory,
3372
+ origin: this.host
3373
+ });
3374
+ } catch (getExposeError) {
3375
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
3376
+ id,
3377
+ expose,
3378
+ moduleInfo: this.remoteInfo,
3379
+ remoteEntryExports,
3380
+ error: getExposeError,
3381
+ origin: this.host
3382
+ });
3383
+ throw getExposeError;
3384
+ }
3144
3385
  const symbolName = processModuleAlias(this.remoteInfo.name, expose);
3145
3386
  const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
3146
3387
  if (!loadFactory) return wrapModuleFactory;
3147
- return await wrapModuleFactory();
3388
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
3389
+ id,
3390
+ expose,
3391
+ moduleInfo: this.remoteInfo,
3392
+ loadFactory,
3393
+ origin: this.host
3394
+ });
3395
+ try {
3396
+ const exposeContent = await wrapModuleFactory();
3397
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
3398
+ id,
3399
+ expose,
3400
+ moduleInfo: this.remoteInfo,
3401
+ loadFactory,
3402
+ exposeModule: exposeContent,
3403
+ origin: this.host
3404
+ });
3405
+ return exposeContent;
3406
+ } catch (executeFactoryError) {
3407
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
3408
+ id,
3409
+ expose,
3410
+ moduleInfo: this.remoteInfo,
3411
+ loadFactory,
3412
+ error: executeFactoryError,
3413
+ origin: this.host
3414
+ });
3415
+ throw executeFactoryError;
3416
+ }
3148
3417
  }
3149
3418
  wraperFactory(moduleFactory, id) {
3150
3419
  function defineModuleId(res, id2) {
@@ -3153,13 +3422,12 @@ var Module$1 = class {
3153
3422
  enumerable: false
3154
3423
  });
3155
3424
  }
3156
- if (moduleFactory instanceof Promise) return async () => {
3157
- const res = await moduleFactory();
3158
- defineModuleId(res, id);
3159
- return res;
3160
- };
3161
- else return () => {
3425
+ return () => {
3162
3426
  const res = moduleFactory();
3427
+ if (res instanceof Promise) return res.then((asyncRes) => {
3428
+ defineModuleId(asyncRes, id);
3429
+ return asyncRes;
3430
+ });
3163
3431
  defineModuleId(res, id);
3164
3432
  return res;
3165
3433
  };
@@ -3186,7 +3454,8 @@ var SyncHook = class {
3186
3454
  emit(...data) {
3187
3455
  let result;
3188
3456
  if (this.listeners.size > 0) this.listeners.forEach((fn) => {
3189
- result = fn(...data);
3457
+ const nextResult = fn(...data);
3458
+ if (nextResult !== void 0) result = nextResult;
3190
3459
  });
3191
3460
  return result;
3192
3461
  }
@@ -3207,7 +3476,10 @@ var AsyncHook = class extends SyncHook {
3207
3476
  let i7 = 0;
3208
3477
  const call = (prev) => {
3209
3478
  if (prev === false) return false;
3210
- else if (i7 < ls.length) return Promise.resolve(ls[i7++].apply(null, data)).then(call);
3479
+ else if (i7 < ls.length) return Promise.resolve(ls[i7++].apply(null, data)).then((result2) => {
3480
+ if (result2 === void 0 || data.length === 1 && result2 === data[0]) return call(prev);
3481
+ return call(result2);
3482
+ });
3211
3483
  else return prev;
3212
3484
  };
3213
3485
  result = call();
@@ -3234,6 +3506,7 @@ var SyncWaterfallHook = class extends SyncHook {
3234
3506
  if (!isObject2(data)) error2(`The data for the "${this.type}" hook should be an object.`);
3235
3507
  for (const fn of this.listeners) try {
3236
3508
  const tempData = fn(data);
3509
+ if (tempData === void 0) continue;
3237
3510
  if (checkReturnData(data, tempData)) data = tempData;
3238
3511
  else {
3239
3512
  this.onerror(`A plugin returned an unacceptable value for the "${this.type}" type.`);
@@ -3265,14 +3538,16 @@ var AsyncWaterfallHook = class extends SyncHook {
3265
3538
  return data;
3266
3539
  };
3267
3540
  const call = (prevData) => {
3268
- if (checkReturnData(data, prevData)) {
3269
- data = prevData;
3270
- if (i7 < ls.length) try {
3271
- return Promise.resolve(ls[i7++](data)).then(call, processError);
3272
- } catch (e7) {
3273
- return processError(e7);
3274
- }
3275
- } else this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
3541
+ if (prevData !== void 0 && checkReturnData(data, prevData)) data = prevData;
3542
+ else if (prevData !== void 0) {
3543
+ this.onerror(`A plugin returned an incorrect value for the "${this.type}" type.`);
3544
+ return data;
3545
+ }
3546
+ if (i7 < ls.length) try {
3547
+ return Promise.resolve(ls[i7++](data)).then(call, processError);
3548
+ } catch (e7) {
3549
+ return processError(e7);
3550
+ }
3276
3551
  return data;
3277
3552
  };
3278
3553
  return Promise.resolve(call(data));
@@ -3331,7 +3606,7 @@ function snapshotPlugin() {
3331
3606
  if (!isRemoteInfoWithEntry(remote) || !isPureRemoteEntry(remote)) {
3332
3607
  const { remoteSnapshot, globalSnapshot } = await origin.snapshotHandler.loadRemoteSnapshotInfo({
3333
3608
  moduleInfo: remote,
3334
- id
3609
+ id: composeRemoteRequestId(remote.name, expose)
3335
3610
  });
3336
3611
  assignRemoteInfo(remoteInfo, remoteSnapshot);
3337
3612
  const preloadOptions = {
@@ -3352,7 +3627,10 @@ function snapshotPlugin() {
3352
3627
  remoteSnapshot,
3353
3628
  globalSnapshot
3354
3629
  });
3355
- if (assets) preloadAssets(remoteInfo, origin, assets, false);
3630
+ if (assets) preloadAssets(remoteInfo, origin, assets, false, {
3631
+ initiator: "loadRemote",
3632
+ id
3633
+ }).catch(() => void 0);
3356
3634
  return {
3357
3635
  ...args,
3358
3636
  remoteSnapshot
@@ -3572,11 +3850,12 @@ var SnapshotHandler = class {
3572
3850
  this.HostInstance = HostInstance;
3573
3851
  this.loaderHook = HostInstance.loaderHook;
3574
3852
  }
3575
- async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
3853
+ async loadRemoteSnapshotInfo({ moduleInfo, id, initiator = "loadRemote" }) {
3576
3854
  const { options } = this.HostInstance;
3577
3855
  await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
3578
3856
  options,
3579
- moduleInfo
3857
+ moduleInfo,
3858
+ origin: this.HostInstance
3580
3859
  });
3581
3860
  let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({
3582
3861
  name: this.HostInstance.options.name,
@@ -3608,7 +3887,10 @@ var SnapshotHandler = class {
3608
3887
  let gSnapshot;
3609
3888
  if (globalRemoteSnapshot) if (isManifestProvider(globalRemoteSnapshot)) {
3610
3889
  const remoteEntry = isBrowserEnvValue ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || "";
3611
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
3890
+ const moduleSnapshot = await this.loadManifestSnapshot(remoteEntry, moduleInfo, {}, {
3891
+ initiator,
3892
+ id: id || moduleInfo.name
3893
+ });
3612
3894
  const globalSnapshotRes2 = setGlobalSnapshotInfoByModuleInfo({
3613
3895
  ...moduleInfo,
3614
3896
  entry: remoteEntry
@@ -3626,15 +3908,12 @@ var SnapshotHandler = class {
3626
3908
  gSnapshot = globalSnapshotRes;
3627
3909
  }
3628
3910
  else if (isRemoteInfoWithEntry(moduleInfo)) {
3629
- const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
3630
- const globalSnapshotRes2 = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
3631
- const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
3632
- options: this.HostInstance.options,
3633
- moduleInfo,
3634
- remoteSnapshot: moduleSnapshot,
3635
- from: "global"
3911
+ const moduleSnapshot = await this.loadManifestSnapshot(moduleInfo.entry, moduleInfo, {}, {
3912
+ initiator,
3913
+ id: id || moduleInfo.name
3636
3914
  });
3637
- mSnapshot = remoteSnapshotRes;
3915
+ const globalSnapshotRes2 = setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
3916
+ mSnapshot = moduleSnapshot;
3638
3917
  gSnapshot = globalSnapshotRes2;
3639
3918
  } else error2(RUNTIME_007, runtimeDescMap, {
3640
3919
  remoteName: moduleInfo.name,
@@ -3657,12 +3936,17 @@ var SnapshotHandler = class {
3657
3936
  getGlobalRemoteInfo(moduleInfo) {
3658
3937
  return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
3659
3938
  }
3660
- async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
3939
+ async getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
3661
3940
  const getManifest = async () => {
3941
+ const remoteInfo = getRemoteInfo(moduleInfo);
3662
3942
  let manifestJson = this.manifestCache.get(manifestUrl);
3663
3943
  if (manifestJson) return manifestJson;
3664
3944
  try {
3665
- let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, getRemoteInfo(moduleInfo));
3945
+ let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, remoteInfo, resourceOptions ? {
3946
+ ...resourceOptions,
3947
+ url: manifestUrl,
3948
+ resourceType: "manifest"
3949
+ } : void 0);
3666
3950
  if (!res || !(res instanceof Response)) res = await fetch(manifestUrl, {});
3667
3951
  manifestJson = await res.json();
3668
3952
  } catch (err) {
@@ -3671,6 +3955,7 @@ var SnapshotHandler = class {
3671
3955
  error: err,
3672
3956
  from: "runtime",
3673
3957
  lifecycle: "afterResolve",
3958
+ remote: remoteInfo,
3674
3959
  origin: this.HostInstance
3675
3960
  });
3676
3961
  if (!manifestJson) {
@@ -3682,16 +3967,33 @@ var SnapshotHandler = class {
3682
3967
  }, `${err}`, optionsToMFContext(this.HostInstance.options));
3683
3968
  }
3684
3969
  }
3685
- assert2(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${[
3970
+ const missingRequiredFields = [
3686
3971
  !manifestJson.metaData && "metaData",
3687
3972
  !manifestJson.exposes && "exposes",
3688
3973
  !manifestJson.shared && "shared"
3689
- ].filter(Boolean).join(", ")}.`);
3974
+ ].filter(Boolean);
3975
+ if (missingRequiredFields.length > 0) await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
3976
+ id: manifestUrl,
3977
+ error: /* @__PURE__ */ new Error(`"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${missingRequiredFields.join(", ")}.`),
3978
+ from: "runtime",
3979
+ lifecycle: "afterResolve",
3980
+ remote: remoteInfo,
3981
+ origin: this.HostInstance
3982
+ });
3983
+ if (missingRequiredFields.length > 0) error2(RUNTIME_013, runtimeDescMap, {
3984
+ manifestUrl,
3985
+ moduleName: moduleInfo.name,
3986
+ hostName: this.HostInstance.options.name,
3987
+ missingFields: missingRequiredFields.join(",")
3988
+ }, void 0, optionsToMFContext(this.HostInstance.options));
3690
3989
  this.manifestCache.set(manifestUrl, manifestJson);
3691
3990
  return manifestJson;
3692
3991
  };
3992
+ return getManifest();
3993
+ }
3994
+ async loadManifestSnapshot(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
3693
3995
  const asyncLoadProcess = async () => {
3694
- const manifestJson = await getManifest();
3996
+ const manifestJson = await this.getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions);
3695
3997
  const remoteSnapshot = generateSnapshotFromManifest(manifestJson, { version: manifestUrl });
3696
3998
  const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
3697
3999
  options: this.HostInstance.options,
@@ -3716,6 +4018,8 @@ var SharedHandler = class {
3716
4018
  afterResolve: new AsyncWaterfallHook("afterResolve"),
3717
4019
  beforeLoadShare: new AsyncWaterfallHook("beforeLoadShare"),
3718
4020
  loadShare: new AsyncHook(),
4021
+ afterLoadShare: new SyncHook("afterLoadShare"),
4022
+ errorLoadShare: new SyncHook("errorLoadShare"),
3719
4023
  resolveShare: new SyncWaterfallHook("resolveShare"),
3720
4024
  initContainerShareScopeMap: new SyncWaterfallHook("initContainerShareScopeMap")
3721
4025
  });
@@ -3724,6 +4028,37 @@ var SharedHandler = class {
3724
4028
  this.initTokens = {};
3725
4029
  this._setGlobalShareScopeMap(host.options);
3726
4030
  }
4031
+ emitAfterLoadShare({ lifecycle, pkgName, shareInfo, selectedShared }) {
4032
+ try {
4033
+ this.hooks.lifecycle.afterLoadShare.emit({
4034
+ pkgName,
4035
+ shareInfo,
4036
+ selectedShared,
4037
+ shared: this.host.options.shared,
4038
+ shareScopeMap: this.shareScopeMap,
4039
+ lifecycle,
4040
+ origin: this.host
4041
+ });
4042
+ } catch (error3) {
4043
+ warn$1(error3);
4044
+ }
4045
+ }
4046
+ emitErrorLoadShare({ lifecycle, pkgName, shareInfo, error: error3, recovered }) {
4047
+ try {
4048
+ this.hooks.lifecycle.errorLoadShare.emit({
4049
+ pkgName,
4050
+ shareInfo,
4051
+ shared: this.host.options.shared,
4052
+ shareScopeMap: this.shareScopeMap,
4053
+ lifecycle,
4054
+ origin: this.host,
4055
+ error: error3,
4056
+ recovered
4057
+ });
4058
+ } catch (hookError) {
4059
+ warn$1(hookError);
4060
+ }
4061
+ }
3727
4062
  registerShared(globalOptions, userOptions) {
3728
4063
  const { newShareInfos, allShareInfos } = formatShareConfigs(globalOptions, userOptions);
3729
4064
  Object.keys(newShareInfos).forEach((sharedKey) => {
@@ -3757,77 +4092,123 @@ var SharedHandler = class {
3757
4092
  extraOptions,
3758
4093
  shareInfos: host.options.shared
3759
4094
  });
3760
- if (shareOptions?.scope) await Promise.all(shareOptions.scope.map(async (shareScope) => {
3761
- await Promise.all(this.initializeSharing(shareScope, { strategy: shareOptions.strategy }));
3762
- }));
3763
- const { shareInfo: shareOptionsRes } = await this.hooks.lifecycle.beforeLoadShare.emit({
3764
- pkgName,
3765
- shareInfo: shareOptions,
3766
- shared: host.options.shared,
3767
- origin: host
3768
- });
3769
- assert2(shareOptionsRes, `Cannot find shared "${pkgName}" in host "${host.options.name}". Ensure the shared config for "${pkgName}" is declared in the federation plugin options and the host has been initialized before loading shares.`);
3770
- const { shared: registeredShared, useTreesShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {};
3771
- if (registeredShared) {
3772
- const targetShared = directShare(registeredShared, useTreesShaking);
3773
- if (targetShared.lib) {
3774
- addUseIn(targetShared, host.options.name);
3775
- return targetShared.lib;
3776
- } else if (targetShared.loading && !targetShared.loaded) {
3777
- const factory = await targetShared.loading;
3778
- targetShared.loaded = true;
3779
- if (!targetShared.lib) targetShared.lib = factory;
3780
- addUseIn(targetShared, host.options.name);
3781
- return factory;
3782
- } else {
3783
- const asyncLoadProcess = async () => {
3784
- const factory = await targetShared.get();
4095
+ let shareOptionsRes = shareOptions;
4096
+ try {
4097
+ if (shareOptions?.scope) await Promise.all(shareOptions.scope.map(async (shareScope) => {
4098
+ await Promise.all(this.initializeSharing(shareScope, { strategy: shareOptions.strategy }));
4099
+ }));
4100
+ shareOptionsRes = (await this.hooks.lifecycle.beforeLoadShare.emit({
4101
+ pkgName,
4102
+ shareInfo: shareOptions,
4103
+ shared: host.options.shared,
4104
+ origin: host
4105
+ })).shareInfo;
4106
+ assert2(shareOptionsRes, `Cannot find shared "${pkgName}" in host "${host.options.name}". Ensure the shared config for "${pkgName}" is declared in the federation plugin options and the host has been initialized before loading shares.`);
4107
+ const resolvedShareOptions = shareOptionsRes;
4108
+ const { shared: registeredShared, useTreesShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {};
4109
+ if (registeredShared) {
4110
+ const targetShared = directShare(registeredShared, useTreesShaking);
4111
+ if (targetShared.lib) {
3785
4112
  addUseIn(targetShared, host.options.name);
4113
+ this.emitAfterLoadShare({
4114
+ lifecycle: "loadShare",
4115
+ pkgName,
4116
+ shareInfo: resolvedShareOptions,
4117
+ selectedShared: registeredShared
4118
+ });
4119
+ return targetShared.lib;
4120
+ } else if (targetShared.loading && !targetShared.loaded) {
4121
+ const factory = await targetShared.loading;
3786
4122
  targetShared.loaded = true;
3787
- targetShared.lib = factory;
4123
+ if (!targetShared.lib) targetShared.lib = factory;
4124
+ addUseIn(targetShared, host.options.name);
4125
+ this.emitAfterLoadShare({
4126
+ lifecycle: "loadShare",
4127
+ pkgName,
4128
+ shareInfo: resolvedShareOptions,
4129
+ selectedShared: registeredShared
4130
+ });
4131
+ return factory;
4132
+ } else {
4133
+ const asyncLoadProcess = async () => {
4134
+ const factory2 = await targetShared.get();
4135
+ addUseIn(targetShared, host.options.name);
4136
+ targetShared.loaded = true;
4137
+ targetShared.lib = factory2;
4138
+ return factory2;
4139
+ };
4140
+ const loading = asyncLoadProcess();
4141
+ this.setShared({
4142
+ pkgName,
4143
+ loaded: false,
4144
+ shared: registeredShared,
4145
+ from: host.options.name,
4146
+ lib: null,
4147
+ loading,
4148
+ treeShaking: useTreesShaking ? targetShared : void 0
4149
+ });
4150
+ const factory = await loading;
4151
+ this.emitAfterLoadShare({
4152
+ lifecycle: "loadShare",
4153
+ pkgName,
4154
+ shareInfo: resolvedShareOptions,
4155
+ selectedShared: registeredShared
4156
+ });
3788
4157
  return factory;
4158
+ }
4159
+ } else {
4160
+ if (extraOptions?.customShareInfo) {
4161
+ this.emitErrorLoadShare({
4162
+ lifecycle: "loadShare",
4163
+ pkgName,
4164
+ shareInfo: resolvedShareOptions,
4165
+ recovered: true
4166
+ });
4167
+ return false;
4168
+ }
4169
+ const _useTreeShaking = shouldUseTreeShaking(resolvedShareOptions.treeShaking);
4170
+ const targetShared = directShare(resolvedShareOptions, _useTreeShaking);
4171
+ const asyncLoadProcess = async () => {
4172
+ const factory2 = await targetShared.get();
4173
+ targetShared.lib = factory2;
4174
+ targetShared.loaded = true;
4175
+ addUseIn(targetShared, host.options.name);
4176
+ const { shared: gShared, useTreesShaking: gUseTreeShaking } = getRegisteredShare(this.shareScopeMap, pkgName, resolvedShareOptions, this.hooks.lifecycle.resolveShare) || {};
4177
+ if (gShared) {
4178
+ const targetGShared = directShare(gShared, gUseTreeShaking);
4179
+ targetGShared.lib = factory2;
4180
+ targetGShared.loaded = true;
4181
+ gShared.from = resolvedShareOptions.from;
4182
+ }
4183
+ return factory2;
3789
4184
  };
3790
4185
  const loading = asyncLoadProcess();
3791
4186
  this.setShared({
3792
4187
  pkgName,
3793
4188
  loaded: false,
3794
- shared: registeredShared,
4189
+ shared: resolvedShareOptions,
3795
4190
  from: host.options.name,
3796
4191
  lib: null,
3797
4192
  loading,
3798
- treeShaking: useTreesShaking ? targetShared : void 0
4193
+ treeShaking: _useTreeShaking ? targetShared : void 0
4194
+ });
4195
+ const factory = await loading;
4196
+ this.emitAfterLoadShare({
4197
+ lifecycle: "loadShare",
4198
+ pkgName,
4199
+ shareInfo: resolvedShareOptions,
4200
+ selectedShared: resolvedShareOptions
3799
4201
  });
3800
- return loading;
3801
- }
3802
- } else {
3803
- if (extraOptions?.customShareInfo) return false;
3804
- const _useTreeShaking = shouldUseTreeShaking(shareOptionsRes.treeShaking);
3805
- const targetShared = directShare(shareOptionsRes, _useTreeShaking);
3806
- const asyncLoadProcess = async () => {
3807
- const factory = await targetShared.get();
3808
- targetShared.lib = factory;
3809
- targetShared.loaded = true;
3810
- addUseIn(targetShared, host.options.name);
3811
- const { shared: gShared, useTreesShaking: gUseTreeShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptionsRes, this.hooks.lifecycle.resolveShare) || {};
3812
- if (gShared) {
3813
- const targetGShared = directShare(gShared, gUseTreeShaking);
3814
- targetGShared.lib = factory;
3815
- targetGShared.loaded = true;
3816
- gShared.from = shareOptionsRes.from;
3817
- }
3818
4202
  return factory;
3819
- };
3820
- const loading = asyncLoadProcess();
3821
- this.setShared({
4203
+ }
4204
+ } catch (shareError) {
4205
+ this.emitErrorLoadShare({
4206
+ lifecycle: "loadShare",
3822
4207
  pkgName,
3823
- loaded: false,
3824
- shared: shareOptionsRes,
3825
- from: host.options.name,
3826
- lib: null,
3827
- loading,
3828
- treeShaking: _useTreeShaking ? targetShared : void 0
4208
+ shareInfo: shareOptionsRes,
4209
+ error: shareError
3829
4210
  });
3830
- return loading;
4211
+ throw shareError;
3831
4212
  }
3832
4213
  }
3833
4214
  /**
@@ -3872,6 +4253,7 @@ var SharedHandler = class {
3872
4253
  error: error3,
3873
4254
  from: "runtime",
3874
4255
  lifecycle: "beforeLoadShare",
4256
+ remote: module2.remoteInfo,
3875
4257
  origin: host
3876
4258
  });
3877
4259
  if (!remoteEntryExports) return;
@@ -3899,58 +4281,92 @@ var SharedHandler = class {
3899
4281
  extraOptions,
3900
4282
  shareInfos: host.options.shared
3901
4283
  });
3902
- if (shareOptions?.scope) shareOptions.scope.forEach((shareScope) => {
3903
- this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
3904
- });
3905
- const { shared: registeredShared, useTreesShaking } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare) || {};
3906
- if (registeredShared) {
3907
- if (typeof registeredShared.lib === "function") {
3908
- addUseIn(registeredShared, host.options.name);
3909
- if (!registeredShared.loaded) {
3910
- registeredShared.loaded = true;
3911
- if (registeredShared.from === host.options.name) shareOptions.loaded = true;
3912
- }
3913
- return registeredShared.lib;
3914
- }
3915
- if (typeof registeredShared.get === "function") {
3916
- const module2 = registeredShared.get();
3917
- if (!(module2 instanceof Promise)) {
4284
+ try {
4285
+ if (shareOptions?.scope) shareOptions.scope.forEach((shareScope) => {
4286
+ this.initializeSharing(shareScope, { strategy: shareOptions.strategy });
4287
+ });
4288
+ const { shared: registeredShared } = getRegisteredShare(this.shareScopeMap, pkgName, shareOptions, this.hooks.lifecycle.resolveShare) || {};
4289
+ if (registeredShared) {
4290
+ if (typeof registeredShared.lib === "function") {
3918
4291
  addUseIn(registeredShared, host.options.name);
3919
- this.setShared({
4292
+ if (!registeredShared.loaded) {
4293
+ registeredShared.loaded = true;
4294
+ if (registeredShared.from === host.options.name) shareOptions.loaded = true;
4295
+ }
4296
+ this.emitAfterLoadShare({
4297
+ lifecycle: "loadShareSync",
3920
4298
  pkgName,
3921
- loaded: true,
3922
- from: host.options.name,
3923
- lib: module2,
3924
- shared: registeredShared
4299
+ shareInfo: shareOptions,
4300
+ selectedShared: registeredShared
3925
4301
  });
3926
- return module2;
4302
+ return registeredShared.lib;
4303
+ }
4304
+ if (typeof registeredShared.get === "function") {
4305
+ const module2 = registeredShared.get();
4306
+ if (!(module2 instanceof Promise)) {
4307
+ addUseIn(registeredShared, host.options.name);
4308
+ this.setShared({
4309
+ pkgName,
4310
+ loaded: true,
4311
+ from: host.options.name,
4312
+ lib: module2,
4313
+ shared: registeredShared
4314
+ });
4315
+ this.emitAfterLoadShare({
4316
+ lifecycle: "loadShareSync",
4317
+ pkgName,
4318
+ shareInfo: shareOptions,
4319
+ selectedShared: registeredShared
4320
+ });
4321
+ return module2;
4322
+ }
3927
4323
  }
3928
4324
  }
3929
- }
3930
- if (shareOptions.lib) {
3931
- if (!shareOptions.loaded) shareOptions.loaded = true;
3932
- return shareOptions.lib;
3933
- }
3934
- if (shareOptions.get) {
3935
- const module2 = shareOptions.get();
3936
- if (module2 instanceof Promise) error2(extraOptions?.from === "build" ? RUNTIME_005 : RUNTIME_006, runtimeDescMap, {
4325
+ if (shareOptions.lib) {
4326
+ if (!shareOptions.loaded) shareOptions.loaded = true;
4327
+ this.emitAfterLoadShare({
4328
+ lifecycle: "loadShareSync",
4329
+ pkgName,
4330
+ shareInfo: shareOptions,
4331
+ selectedShared: shareOptions
4332
+ });
4333
+ return shareOptions.lib;
4334
+ }
4335
+ if (shareOptions.get) {
4336
+ const module2 = shareOptions.get();
4337
+ if (module2 instanceof Promise) error2(extraOptions?.from === "build" ? RUNTIME_005 : RUNTIME_006, runtimeDescMap, {
4338
+ hostName: host.options.name,
4339
+ sharedPkgName: pkgName
4340
+ }, void 0, optionsToMFContext(host.options));
4341
+ shareOptions.lib = module2;
4342
+ this.setShared({
4343
+ pkgName,
4344
+ loaded: true,
4345
+ from: host.options.name,
4346
+ lib: shareOptions.lib,
4347
+ shared: shareOptions
4348
+ });
4349
+ this.emitAfterLoadShare({
4350
+ lifecycle: "loadShareSync",
4351
+ pkgName,
4352
+ shareInfo: shareOptions,
4353
+ selectedShared: shareOptions
4354
+ });
4355
+ return shareOptions.lib;
4356
+ }
4357
+ error2(RUNTIME_006, runtimeDescMap, {
3937
4358
  hostName: host.options.name,
3938
4359
  sharedPkgName: pkgName
3939
4360
  }, void 0, optionsToMFContext(host.options));
3940
- shareOptions.lib = module2;
3941
- this.setShared({
4361
+ } catch (shareError) {
4362
+ this.emitErrorLoadShare({
4363
+ lifecycle: "loadShareSync",
3942
4364
  pkgName,
3943
- loaded: true,
3944
- from: host.options.name,
3945
- lib: shareOptions.lib,
3946
- shared: shareOptions
4365
+ shareInfo: shareOptions,
4366
+ error: shareError
3947
4367
  });
3948
- return shareOptions.lib;
4368
+ throw shareError;
3949
4369
  }
3950
- error2(RUNTIME_006, runtimeDescMap, {
3951
- hostName: host.options.name,
3952
- sharedPkgName: pkgName
3953
- }, void 0, optionsToMFContext(host.options));
3954
4370
  }
3955
4371
  initShareScopeMap(scopeName, shareScope, extraOptions = {}) {
3956
4372
  const { host } = this;
@@ -4003,12 +4419,14 @@ var RemoteHandler = class {
4003
4419
  beforeRegisterRemote: new SyncWaterfallHook("beforeRegisterRemote"),
4004
4420
  registerRemote: new SyncWaterfallHook("registerRemote"),
4005
4421
  beforeRequest: new AsyncWaterfallHook("beforeRequest"),
4422
+ afterMatchRemote: new AsyncHook("afterMatchRemote"),
4006
4423
  onLoad: new AsyncHook("onLoad"),
4424
+ afterLoadRemote: new AsyncHook("afterLoadRemote"),
4007
4425
  handlePreloadModule: new SyncHook("handlePreloadModule"),
4008
4426
  errorLoadRemote: new AsyncHook("errorLoadRemote"),
4009
4427
  beforePreloadRemote: new AsyncHook("beforePreloadRemote"),
4010
4428
  generatePreloadAssets: new AsyncHook("generatePreloadAssets"),
4011
- afterPreloadRemote: new AsyncHook(),
4429
+ afterPreloadRemote: new AsyncHook("afterPreloadRemote"),
4012
4430
  loadEntry: new AsyncHook()
4013
4431
  });
4014
4432
  this.host = host;
@@ -4045,10 +4463,18 @@ var RemoteHandler = class {
4045
4463
  }
4046
4464
  async loadRemote(id, options) {
4047
4465
  const { host } = this;
4466
+ const startMatchInfo = matchRemoteWithNameAndExpose(host.options.remotes, id);
4467
+ let completeRequestId = id;
4468
+ let completeExpose = startMatchInfo?.expose;
4469
+ let completeRemote = startMatchInfo ? getRemoteInfo(startMatchInfo.remote) : void 0;
4470
+ let afterLoadRemoteArgs;
4048
4471
  try {
4049
4472
  const { loadFactory = true } = options || { loadFactory: true };
4050
4473
  const { module: module2, moduleOptions, remoteMatchInfo } = await this.getRemoteModuleAndOptions({ id });
4051
4474
  const { pkgNameOrAlias, remote, expose, id: idRes, remoteSnapshot } = remoteMatchInfo;
4475
+ completeRequestId = idRes;
4476
+ completeExpose = expose;
4477
+ completeRemote = getRemoteInfo(remote);
4052
4478
  const moduleOrFactory = await module2.get(idRes, expose, options, remoteSnapshot);
4053
4479
  const moduleWrapper = await this.hooks.lifecycle.onLoad.emit({
4054
4480
  id: idRes,
@@ -4062,44 +4488,155 @@ var RemoteHandler = class {
4062
4488
  origin: host
4063
4489
  });
4064
4490
  this.setIdToRemoteMap(id, remoteMatchInfo);
4491
+ afterLoadRemoteArgs = {
4492
+ id: completeRequestId,
4493
+ expose: completeExpose,
4494
+ remote: completeRemote,
4495
+ options,
4496
+ origin: host
4497
+ };
4065
4498
  if (typeof moduleWrapper === "function") return moduleWrapper;
4066
4499
  return moduleOrFactory;
4067
4500
  } catch (error3) {
4068
4501
  const { from = "runtime" } = options || { from: "runtime" };
4069
- const failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
4070
- id,
4502
+ let failOver;
4503
+ try {
4504
+ failOver = await this.hooks.lifecycle.errorLoadRemote.emit({
4505
+ id,
4506
+ error: error3,
4507
+ from,
4508
+ lifecycle: "onLoad",
4509
+ expose: completeExpose,
4510
+ remote: completeRemote,
4511
+ origin: host
4512
+ });
4513
+ } catch (hookError) {
4514
+ afterLoadRemoteArgs = {
4515
+ id: completeRequestId,
4516
+ expose: completeExpose,
4517
+ remote: completeRemote,
4518
+ options,
4519
+ error: hookError,
4520
+ origin: host
4521
+ };
4522
+ throw hookError;
4523
+ }
4524
+ if (!failOver) {
4525
+ afterLoadRemoteArgs = {
4526
+ id: completeRequestId,
4527
+ expose: completeExpose,
4528
+ remote: completeRemote,
4529
+ options,
4530
+ error: error3,
4531
+ origin: host
4532
+ };
4533
+ throw error3;
4534
+ }
4535
+ afterLoadRemoteArgs = {
4536
+ id: completeRequestId,
4537
+ expose: completeExpose,
4538
+ remote: completeRemote,
4539
+ options,
4071
4540
  error: error3,
4072
- from,
4073
- lifecycle: "onLoad",
4074
- origin: host
4075
- });
4076
- if (!failOver) throw error3;
4541
+ origin: host,
4542
+ recovered: true
4543
+ };
4077
4544
  return failOver;
4545
+ } finally {
4546
+ if (afterLoadRemoteArgs) await this.hooks.lifecycle.afterLoadRemote.emit(afterLoadRemoteArgs);
4078
4547
  }
4079
4548
  }
4080
4549
  async preloadRemote(preloadOptions) {
4081
4550
  const { host } = this;
4551
+ const preloadResults = [];
4082
4552
  await this.hooks.lifecycle.beforePreloadRemote.emit({
4083
4553
  preloadOps: preloadOptions,
4084
4554
  options: host.options,
4085
4555
  origin: host
4086
4556
  });
4087
4557
  const preloadOps = formatPreloadArgs(host.options.remotes, preloadOptions);
4088
- await Promise.all(preloadOps.map(async (ops) => {
4089
- const { remote } = ops;
4558
+ const createPreloadAssetOps = (ops) => {
4559
+ const { preloadConfig, remote } = ops;
4560
+ const exposes = preloadConfig.exposes || [];
4561
+ if (!exposes.length) return [{
4562
+ ops,
4563
+ id: `${remote.name}/*`
4564
+ }];
4565
+ return exposes.map((expose) => ({
4566
+ ops: {
4567
+ ...ops,
4568
+ preloadConfig: {
4569
+ ...preloadConfig,
4570
+ exposes: [expose]
4571
+ }
4572
+ },
4573
+ id: composeRemoteRequestId(remote.name, expose)
4574
+ }));
4575
+ };
4576
+ let preloadError;
4577
+ await Promise.all(preloadOps.flatMap(createPreloadAssetOps).map(async (assetOps) => {
4578
+ const { ops, id: preloadId } = assetOps;
4579
+ const { remote, preloadConfig } = ops;
4090
4580
  const remoteInfo = getRemoteInfo(remote);
4091
- const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({ moduleInfo: remote });
4092
- const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
4093
- origin: host,
4094
- preloadOptions: ops,
4095
- remote,
4096
- remoteInfo,
4097
- globalSnapshot,
4098
- remoteSnapshot
4099
- });
4100
- if (!assets) return;
4101
- preloadAssets(remoteInfo, host, assets);
4581
+ try {
4582
+ const { globalSnapshot, remoteSnapshot } = await host.snapshotHandler.loadRemoteSnapshotInfo({
4583
+ moduleInfo: remote,
4584
+ id: preloadId,
4585
+ initiator: "preloadRemote"
4586
+ });
4587
+ const assets = await this.hooks.lifecycle.generatePreloadAssets.emit({
4588
+ origin: host,
4589
+ preloadOptions: ops,
4590
+ remote,
4591
+ remoteInfo,
4592
+ globalSnapshot,
4593
+ remoteSnapshot
4594
+ });
4595
+ if (!assets) return;
4596
+ const results = await preloadAssets(remoteInfo, host, assets, true, {
4597
+ initiator: "preloadRemote",
4598
+ id: preloadId
4599
+ });
4600
+ preloadResults.push({
4601
+ remote,
4602
+ remoteInfo,
4603
+ preloadConfig,
4604
+ id: preloadId,
4605
+ results
4606
+ });
4607
+ } catch (error3) {
4608
+ preloadResults.push({
4609
+ remote,
4610
+ remoteInfo,
4611
+ preloadConfig,
4612
+ id: preloadId,
4613
+ results: [{
4614
+ url: remoteInfo.entry,
4615
+ status: "error",
4616
+ resourceType: /\.json(?:$|[?#])/i.test(remoteInfo.entry) ? "manifest" : "remoteEntry",
4617
+ initiator: "preloadRemote",
4618
+ id: preloadId,
4619
+ error: error3
4620
+ }]
4621
+ });
4622
+ }
4102
4623
  }));
4624
+ const failedResults = preloadResults.flatMap((preloadResult) => preloadResult.results.filter((result) => result.status === "error" || result.status === "timeout"));
4625
+ if (failedResults.length > 0) {
4626
+ preloadError = /* @__PURE__ */ new Error(`preloadRemote failed to load ${failedResults.length} resource(s).`);
4627
+ Object.assign(preloadError, {
4628
+ results: preloadResults,
4629
+ failedResults
4630
+ });
4631
+ }
4632
+ await this.hooks.lifecycle.afterPreloadRemote.emit({
4633
+ preloadOps: preloadOptions,
4634
+ options: host.options,
4635
+ origin: host,
4636
+ results: preloadResults,
4637
+ error: preloadError
4638
+ });
4639
+ if (preloadError) throw preloadError;
4103
4640
  }
4104
4641
  registerRemotes(remotes, options) {
4105
4642
  const { host } = this;
@@ -4130,12 +4667,29 @@ var RemoteHandler = class {
4130
4667
  }
4131
4668
  const { id: idRes } = loadRemoteArgs;
4132
4669
  const remoteSplitInfo = matchRemoteWithNameAndExpose(host.options.remotes, idRes);
4133
- if (!remoteSplitInfo) error2(RUNTIME_004, runtimeDescMap, {
4134
- hostName: host.options.name,
4135
- requestId: idRes
4136
- }, void 0, optionsToMFContext(host.options));
4670
+ if (!remoteSplitInfo) try {
4671
+ error2(RUNTIME_004, runtimeDescMap, {
4672
+ hostName: host.options.name,
4673
+ requestId: idRes
4674
+ }, void 0, optionsToMFContext(host.options));
4675
+ } catch (matchError) {
4676
+ await this.hooks.lifecycle.afterMatchRemote.emit({
4677
+ id: idRes,
4678
+ options: host.options,
4679
+ error: matchError,
4680
+ origin: host
4681
+ });
4682
+ throw matchError;
4683
+ }
4137
4684
  const { remote: rawRemote } = remoteSplitInfo;
4138
4685
  const remoteInfo = getRemoteInfo(rawRemote);
4686
+ await this.hooks.lifecycle.afterMatchRemote.emit({
4687
+ id: idRes,
4688
+ ...remoteSplitInfo,
4689
+ options: host.options,
4690
+ remoteInfo,
4691
+ origin: host
4692
+ });
4139
4693
  const matchInfo = await host.sharedHandler.hooks.lifecycle.afterResolve.emit({
4140
4694
  id: idRes,
4141
4695
  ...remoteSplitInfo,
@@ -4287,7 +4841,7 @@ var ModuleFederation = class {
4287
4841
  beforeInitContainer: new AsyncWaterfallHook("beforeInitContainer"),
4288
4842
  initContainer: new AsyncWaterfallHook("initContainer")
4289
4843
  });
4290
- this.version = "2.4.0";
4844
+ this.version = "2.5.0";
4291
4845
  this.moduleCache = /* @__PURE__ */ new Map();
4292
4846
  this.loaderHook = new PluginSystem({
4293
4847
  getModuleInfo: new SyncHook(),
@@ -4295,6 +4849,13 @@ var ModuleFederation = class {
4295
4849
  createLink: new SyncHook(),
4296
4850
  fetch: new AsyncHook(),
4297
4851
  loadEntryError: new AsyncHook(),
4852
+ afterLoadEntry: new AsyncHook("afterLoadEntry"),
4853
+ beforeInitRemote: new AsyncHook("beforeInitRemote"),
4854
+ afterInitRemote: new AsyncHook("afterInitRemote"),
4855
+ beforeGetExpose: new AsyncHook("beforeGetExpose"),
4856
+ afterGetExpose: new AsyncHook("afterGetExpose"),
4857
+ beforeExecuteFactory: new AsyncHook("beforeExecuteFactory"),
4858
+ afterExecuteFactory: new AsyncHook("afterExecuteFactory"),
4298
4859
  getModuleFactory: new AsyncHook()
4299
4860
  });
4300
4861
  this.bridgeHook = new PluginSystem({
@@ -4415,24 +4976,13 @@ function createInstance(options) {
4415
4976
  setGlobalFederationInstance(instance);
4416
4977
  return instance;
4417
4978
  }
4418
- var FederationInstance = null;
4419
- function getInstance() {
4420
- return FederationInstance;
4421
- }
4422
4979
  setGlobalFederationConstructor(ModuleFederation);
4423
4980
 
4424
4981
  // libs/embed-libs/shared-embed/src/lib/helpers/remote-federation.ts
4425
- var resolvedFederationRuntime = null;
4426
- function getFederationRuntime() {
4427
- if (resolvedFederationRuntime) {
4428
- return resolvedFederationRuntime;
4429
- }
4430
- resolvedFederationRuntime = getInstance() ?? createInstance({
4431
- name: "luzmo-embed-runtime",
4432
- remotes: []
4433
- });
4434
- return resolvedFederationRuntime;
4435
- }
4982
+ var federationRuntime = createInstance({
4983
+ name: "luzmo-embed-runtime",
4984
+ remotes: []
4985
+ });
4436
4986
  var remoteCache = /* @__PURE__ */ new Map();
4437
4987
  var remoteCounter = 0;
4438
4988
  var preconnectedOrigins = /* @__PURE__ */ new Set();
@@ -4497,9 +5047,8 @@ function loadLibrary(appServer, componentName = "DashboardApp") {
4497
5047
  if (remote.loadPromise) {
4498
5048
  return remote.loadPromise;
4499
5049
  }
4500
- const runtime = getFederationRuntime();
4501
5050
  if (!remote.registered) {
4502
- runtime.registerRemotes([
5051
+ federationRuntime.registerRemotes([
4503
5052
  {
4504
5053
  name: remote.remoteName,
4505
5054
  entry: remote.entry
@@ -4507,7 +5056,7 @@ function loadLibrary(appServer, componentName = "DashboardApp") {
4507
5056
  ]);
4508
5057
  remote.registered = true;
4509
5058
  }
4510
- remote.loadPromise = runtime.loadRemote(`${remote.remoteName}/${componentName}`).then((module2) => {
5059
+ remote.loadPromise = federationRuntime.loadRemote(`${remote.remoteName}/${componentName}`).then((module2) => {
4511
5060
  if (!module2) {
4512
5061
  throw new Error(`Failed to load "${componentName}" from "${remote.entry}".`);
4513
5062
  }
@@ -5193,7 +5742,7 @@ var o6 = e6(class extends i5 {
5193
5742
  });
5194
5743
 
5195
5744
  // libs/embed-libs/embed/package.json
5196
- var version = "6.13.2";
5745
+ var version = "6.13.3";
5197
5746
 
5198
5747
  // libs/embed-libs/embed/src/lib/luzmo-service.ts
5199
5748
  var LuzmoDashboardService = class {
@@ -6263,22 +6812,6 @@ var LuzmoBaseVizItem = class extends i4 {
6263
6812
  this.libVersion = version + "-wc-luzmo";
6264
6813
  this.postInitCallQueue = [];
6265
6814
  }
6266
- static {
6267
- // Static styles to set host display to block, else it is not shown at all for some reason.
6268
- this.styles = i`
6269
- :host {
6270
- display: block;
6271
- width: 100%;
6272
- height: 100%;
6273
- }
6274
-
6275
- luzmo-embed-viz-item {
6276
- width: 100%;
6277
- height: 1000%;
6278
- display: block;
6279
- }
6280
- `;
6281
- }
6282
6815
  createRenderRoot() {
6283
6816
  if (!this.style.display) {
6284
6817
  this.style.display = "block";
@@ -6389,6 +6922,20 @@ var LuzmoBaseVizItem = class extends i4 {
6389
6922
  return b2` `;
6390
6923
  }
6391
6924
  };
6925
+ // Static styles to set host display to block, else it is not shown at all for some reason.
6926
+ LuzmoBaseVizItem.styles = i`
6927
+ :host {
6928
+ display: block;
6929
+ width: 100%;
6930
+ height: 100%;
6931
+ }
6932
+
6933
+ luzmo-embed-viz-item {
6934
+ width: 100%;
6935
+ height: 1000%;
6936
+ display: block;
6937
+ }
6938
+ `;
6392
6939
  __decorateClass([
6393
6940
  n4()
6394
6941
  ], LuzmoBaseVizItem.prototype, "appServer", 2);
@@ -6479,16 +7026,6 @@ var LuzmoIQEmbedChatComponent = class extends i4 {
6479
7026
  this.remoteEntryServer = "http://localhost:4202/";
6480
7027
  this.aydHost = "https://ayd.luzmo.com/";
6481
7028
  }
6482
- static {
6483
- // Static styles to set host display to block, else it is not shown at all for some reason.
6484
- this.styles = i`
6485
- :host {
6486
- display: block;
6487
- width: 100%;
6488
- height: 100%;
6489
- }
6490
- `;
6491
- }
6492
7029
  createRenderRoot() {
6493
7030
  return this;
6494
7031
  }
@@ -6557,6 +7094,14 @@ var LuzmoIQEmbedChatComponent = class extends i4 {
6557
7094
  observer.observe(embedChat, { childList: true, subtree: true });
6558
7095
  }
6559
7096
  };
7097
+ // Static styles to set host display to block, else it is not shown at all for some reason.
7098
+ LuzmoIQEmbedChatComponent.styles = i`
7099
+ :host {
7100
+ display: block;
7101
+ width: 100%;
7102
+ height: 100%;
7103
+ }
7104
+ `;
6560
7105
  __decorateClass([
6561
7106
  n4()
6562
7107
  ], LuzmoIQEmbedChatComponent.prototype, "appServer", 2);
@@ -6619,16 +7164,6 @@ var LuzmoIQEmbedAnswerComponent = class extends i4 {
6619
7164
  this.libVersion = version + "-wc-luzmo";
6620
7165
  this.remoteEntryServer = "http://localhost:4202";
6621
7166
  }
6622
- static {
6623
- // Static styles to set host display to block, else it is not shown at all for some reason.
6624
- this.styles = i`
6625
- :host {
6626
- display: block;
6627
- width: 100%;
6628
- height: 100%;
6629
- }
6630
- `;
6631
- }
6632
7167
  createRenderRoot() {
6633
7168
  return this;
6634
7169
  }
@@ -6679,6 +7214,14 @@ var LuzmoIQEmbedAnswerComponent = class extends i4 {
6679
7214
  return b2` `;
6680
7215
  }
6681
7216
  };
7217
+ // Static styles to set host display to block, else it is not shown at all for some reason.
7218
+ LuzmoIQEmbedAnswerComponent.styles = i`
7219
+ :host {
7220
+ display: block;
7221
+ width: 100%;
7222
+ height: 100%;
7223
+ }
7224
+ `;
6682
7225
  __decorateClass([
6683
7226
  n4()
6684
7227
  ], LuzmoIQEmbedAnswerComponent.prototype, "appServer", 2);