@module-federation/vite 1.20.3 → 1.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as normalizePathForImport, r as rebaseImport } from "./buildPaths-BkaQHrd2.js";
2
- import { a as getMatchingNodeModuleSubpath, c as isNuxtClientBase, d as resolvePublicPath, i as getCommonSharedSubpaths, l as isViteOptimizableEntry, n as getBasePath$2, o as isAssetLikeImport, r as getCommonSharedSubpathFromNodeModulePath, s as isNodeModulePath, t as filterId, u as normalizeNodeModulePath } from "./pathNormalization-CLDIcf9-.js";
2
+ import { a as getCommonSharedSubpaths, c as isNodeModulePath, d as normalizeNodeModulePath, f as resolvePublicPath, i as getCommonSharedSubpathFromNodeModulePath, l as isNuxtClientBase, n as filterId, o as getMatchingNodeModuleSubpath, r as getBasePath$2, s as isAssetLikeImport, t as ensureTrailingSlash, u as isViteOptimizableEntry } from "./pathNormalization-DvgU8LIp.js";
3
3
  import { createRequire } from "node:module";
4
4
  import * as fs$2 from "fs";
5
5
  import fs, { existsSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "fs";
@@ -934,24 +934,7 @@ function normalizeSharedKey(key) {
934
934
  }
935
935
  function normalizeShared(shared) {
936
936
  explicitSharedKeys = /* @__PURE__ */ new Set();
937
- if (!shared) {
938
- const result = {};
939
- const packageJsonPath = path$1.join(getPackageDetectionCwd(), "package.json");
940
- try {
941
- const packageJson = JSON.parse(fs$2.readFileSync(packageJsonPath, "utf-8"));
942
- if (packageJson.name === "@module-federation/vite") return result;
943
- Object.keys(packageJson.dependencies || {}).filter((key) => shouldAutoShareDependency(key)).forEach((key) => {
944
- result[key] = normalizeShareItem(key, {
945
- name: key,
946
- import: void 0,
947
- singleton: true
948
- });
949
- });
950
- } catch {
951
- return result;
952
- }
953
- return result;
954
- }
937
+ if (!shared) return {};
955
938
  const result = {};
956
939
  const sourceEntries = [];
957
940
  if (Array.isArray(shared)) shared.forEach((key) => {
@@ -984,20 +967,6 @@ function normalizeShared(shared) {
984
967
  function isModuleFederationRuntimePackage(key) {
985
968
  return key === "@module-federation/runtime" || key === "@module-federation/runtime-core";
986
969
  }
987
- function shouldAutoShareDependency(key) {
988
- const pkg = getInstalledPackageJson(key)?.packageJson;
989
- if (!pkg) return false;
990
- if (!pkg.browser && !pkg.exports && typeof pkg.module !== "string") return false;
991
- if (key === "@module-federation/vite" || isModuleFederationRuntimePackage(key)) return false;
992
- const entry = [
993
- pkg.module,
994
- pkg.main,
995
- typeof pkg.exports === "string" ? pkg.exports : void 0
996
- ].find((value) => typeof value === "string")?.replace(/\\/g, "/");
997
- if (key === "nuxt" || key === "nuxt-nightly") return false;
998
- if (key.includes("nuxt") && entry?.endsWith("/dist/module.mjs")) return false;
999
- return true;
1000
- }
1001
970
  function normalizeLibrary(library) {
1002
971
  if (!library) return void 0;
1003
972
  return library;
@@ -1074,6 +1043,7 @@ function normalizeModuleFederationOptions(options) {
1074
1043
  moduleParseIdleTimeout: options.moduleParseIdleTimeout,
1075
1044
  varFilename: options.varFilename,
1076
1045
  target: options.target,
1046
+ ssrExternals: options.ssrExternals,
1077
1047
  disableRemote: options.disableRemote,
1078
1048
  disableShared: options.disableShared,
1079
1049
  disableSnapshot: options.disableSnapshot,
@@ -1752,6 +1722,24 @@ ${exportStatement}
1752
1722
  `);
1753
1723
  }
1754
1724
  //#endregion
1725
+ //#region src/plugins/pluginReactMixedModeGuard.ts
1726
+ function createReactMixedModeRuntimeGuard() {
1727
+ return `const __mfReactInternals = mod["__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE"];
1728
+ if (__mfReactInternals && "A" in __mfReactInternals) {
1729
+ let __mfReactDispatcher = __mfReactInternals.A;
1730
+ Object.defineProperty(__mfReactInternals, "A", {
1731
+ configurable: true,
1732
+ enumerable: true,
1733
+ get: () => __mfReactDispatcher,
1734
+ set: (next) => {
1735
+ if (next && typeof next.getOwner !== "function") next.getOwner = () => null;
1736
+ __mfReactDispatcher = next;
1737
+ },
1738
+ });
1739
+ __mfReactInternals.A = __mfReactDispatcher;
1740
+ }`;
1741
+ }
1742
+ //#endregion
1755
1743
  //#region src/utils/treeShaking.ts
1756
1744
  function shouldAnalyzeSharedExports(shareItem) {
1757
1745
  return !!(shareItem && (shareItem.shareConfig.treeShaking || shareItem.shareConfig.import === false));
@@ -3249,12 +3237,13 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exp
3249
3237
  const hasCompleteExportCoverage = detectedNamedExports !== void 0;
3250
3238
  const isWorkspaceSingleton = isWorkspacePackage && shareItem.shareConfig.singleton === true;
3251
3239
  const isDefaultShareScope = shareItem.scope === void 0 || shareItem.scope === "default" || Array.isArray(shareItem.scope) && shareItem.scope[0] === "default";
3252
- const usesDeferredSingletonFallback = hasCompleteExportCoverage && (isWorkspaceSingleton || command !== "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true || command === "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true && !isDefaultShareScope);
3240
+ const usesDeferredSingletonFallback = hasCompleteExportCoverage && (isWorkspacePackage || command !== "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true || command === "build" && isRemoteOnlyContainer(resolvedOptions) && (shareItem.shareConfig.singleton === true ? !isDefaultShareScope : isDefaultShareScope));
3253
3241
  const servesRemoteSingletonFallback = command !== "build" && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true;
3254
3242
  const isConsumedByPeerSingleton = isSharedSingletonConsumedByPeer(pkg, resolvedOptions);
3255
3243
  const usesEntryInjectedRemoteFallback = hasCompleteExportCoverage && command !== "build" && !isWorkspaceSingleton && isRemoteOnlyContainer(resolvedOptions) && shareItem.shareConfig.singleton === true && resolvedOptions.hostInitInjectLocation === "entry" && isConsumedByPeerSingleton;
3256
- const usesEagerWorkspaceFallback = hasCompleteExportCoverage && isWorkspaceSingleton && isConsumedByPeerSingleton;
3244
+ const usesEagerWorkspaceFallback = hasCompleteExportCoverage && isWorkspaceSingleton && (isConsumedByPeerSingleton || shareItem.shareConfig.eager === true);
3257
3245
  const usesDeferredTreeShakingFallback = hasCompleteExportCoverage && Boolean(treeShakingConsumer);
3246
+ const reactMixedModeGuard = pkg === "react" ? createReactMixedModeRuntimeGuard() : "";
3258
3247
  let exportLine;
3259
3248
  let initBlock = "";
3260
3249
  if (usesDeferredTreeShakingFallback) {
@@ -3280,13 +3269,17 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exp
3280
3269
  const namedExportVars = copiedNamedExports.map((_name, i) => `__mf_${i}`);
3281
3270
  exportLine = `${["let __mfDefaultExport;", ...namedExportVars.map((name) => `let ${name};`)].join("\n ")}
3282
3271
  const __mfApplySharedExports = (mod) => {
3283
- ${[...copiedNamedExports.map((name, i) => `${namedExportVars[i]} = mod[${escapeGeneratedStringLiteral(name)}];`), `__mfDefaultExport = (() => {
3272
+ ${[
3273
+ ...reactMixedModeGuard ? [reactMixedModeGuard] : [],
3274
+ ...copiedNamedExports.map((name, i) => `${namedExportVars[i]} = mod[${escapeGeneratedStringLiteral(name)}];`),
3275
+ `__mfDefaultExport = (() => {
3284
3276
  ${generateShareModuleUnwrapCode({
3285
- source: "mod",
3286
- preserveNamedExports: false,
3287
- stopWithReturn: "defaultExport ?? current"
3288
- })}
3289
- })();`].join("\n ")}
3277
+ source: "mod",
3278
+ preserveNamedExports: false,
3279
+ stopWithReturn: "defaultExport ?? current"
3280
+ })}
3281
+ })();`
3282
+ ].join("\n ")}
3290
3283
  };
3291
3284
  __mfSubscribeSharedCache(__mfModuleCache.share, ${cacheDescriptor}, __mfApplySharedExports);
3292
3285
  __mfApplySharedExports(exportModule);
@@ -3314,6 +3307,7 @@ function writeLoadShareModule(pkg, shareItem, command, _isRolldown, options, exp
3314
3307
  } else if (shareItem.shareConfig.singleton === true) {
3315
3308
  exportLine = `let __mfDefaultExport;
3316
3309
  const __mfApplySharedDefaultExport = (mod) => {
3310
+ ${reactMixedModeGuard}
3317
3311
  __mfDefaultExport = mod.default ?? mod;
3318
3312
  };
3319
3313
  __mfSubscribeSharedCache(__mfModuleCache.share, ${cacheDescriptor}, __mfApplySharedDefaultExport);
@@ -3856,7 +3850,6 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy) {
3856
3850
  : __mfReadSharedCache(__mfModuleCache.share, cacheDescriptor);
3857
3851
  if (cachedShare !== undefined) return false;
3858
3852
  if (share.treeShaking || share.shareConfig?.import === false) return true;
3859
- if (!share.shareConfig?.singleton) return false;
3860
3853
  if (typeof __mfSelectExternalSharedProvider !== 'function') return false;
3861
3854
  return Boolean(__mfSelectExternalSharedProvider(
3862
3855
  initialShared[pkg],
@@ -4595,6 +4588,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
4595
4588
  if (!providerEntry) return;
4596
4589
  const selectedLocalProvider = __mfMatchesSharedProvider(selectedRuntimeProvider, usedShare);
4597
4590
  const { version } = providerEntry;
4591
+ if (!usedShare.shareConfig?.singleton && version !== usedShare.version) return;
4598
4592
  const passedProvider = passedVersionMap?.[version];
4599
4593
  const resolvedExternalProvider = __mfResolveExternalSharedProvider(
4600
4594
  federationInstances,
@@ -4612,10 +4606,6 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
4612
4606
  provider: selectedRuntimeProvider,
4613
4607
  scopeRootProvider: undefined
4614
4608
  };
4615
- // Non-singleton proxies may have already snapshotted their local exports while
4616
- // seeding shared dependencies. Late cache replacement is safe only for the
4617
- // live-bound singleton proxies.
4618
- if (!usedShare.shareConfig?.singleton) return;
4619
4609
  if (usedShare.canLiveRebind === false) return;
4620
4610
  // Preserve a singleton already selected by another container. The bridge may
4621
4611
  // only replace the provisional local fallback seeded by this container.
@@ -5934,16 +5924,16 @@ const VUE_HMR_RUNTIME_GUARD_SCRIPT = `
5934
5924
  * the remote's bindings, so the render throws and Vue falls back to a full
5935
5925
  * reload required warning.
5936
5926
  *
5937
- * Fix: rewrite the remote's emitted `__hmrId` literal to be prefixed with the
5938
- * federation `name`, so the remote's instances live under a distinct key. The
5939
- * accept callback emitted by plugin-vue reads `_sfc_main.__hmrId` /
5940
- * `updated.__hmrId` at runtime, so rewriting the literal once is enough.
5927
+ * Fix: rewrite the remote's emitted HMR id literals to be prefixed with the
5928
+ * federation `name`, so the remote's instances live under a distinct key.
5929
+ * Main SFC modules assign `.__hmrId`; template submodules pass the same id
5930
+ * directly to `__VUE_HMR_RUNTIME__.rerender()`.
5941
5931
  */
5942
- const SFC_HMR_ID_LITERAL_RE = /(\.__hmrId\s*=\s*["'`])([^"'`]+)(["'`])/g;
5943
- function rewriteSfcHmrId(code, federationName) {
5932
+ const VUE_HMR_ID_LITERAL_RE = /((?:\.__hmrId\s*=|__VUE_HMR_RUNTIME__\.rerender\()\s*["'`])([^"'`]+)(["'`])/g;
5933
+ function rewriteVueHmrIds(code, federationName) {
5944
5934
  let matched = false;
5945
5935
  return {
5946
- code: code.replace(SFC_HMR_ID_LITERAL_RE, (_match, prefix, id, suffix) => {
5936
+ code: code.replace(VUE_HMR_ID_LITERAL_RE, (_match, prefix, id, suffix) => {
5947
5937
  matched = true;
5948
5938
  if (id.startsWith(`${federationName}-`)) return `${prefix}${id}${suffix}`;
5949
5939
  return `${prefix}${federationName}-${id}${suffix}`;
@@ -5955,7 +5945,7 @@ let pluginVueRegressionWarned = false;
5955
5945
  function warnPluginVueRegression() {
5956
5946
  if (pluginVueRegressionWarned) return;
5957
5947
  pluginVueRegressionWarned = true;
5958
- mfWarn("Detected a Vue SFC module that calls `__VUE_HMR_RUNTIME__.createRecord(` but no `.__hmrId = \"...\"` literal could be rewritten. @vitejs/plugin-vue may have changed its output format — without the rewrite, host and remote SFCs that share a path will collide on the shared HMR runtime. Please report this to @module-federation/vite.");
5948
+ mfWarn("Detected a Vue SFC module with HMR calls but no HMR id literal could be rewritten. @vitejs/plugin-vue may have changed its output format — without the rewrite, host and remote SFCs that share a path will collide on the shared HMR runtime. Please report this to @module-federation/vite.");
5959
5949
  }
5960
5950
  const vueAdapter = {
5961
5951
  name: "vue",
@@ -5968,8 +5958,8 @@ const vueAdapter = {
5968
5958
  }];
5969
5959
  } },
5970
5960
  remote: { transform(code, _id, ctx) {
5971
- if (!code.includes("__VUE_HMR_RUNTIME__.createRecord(")) return;
5972
- const { code: rewritten, matched } = rewriteSfcHmrId(code, ctx.options.name);
5961
+ if (!code.includes("__VUE_HMR_RUNTIME__.createRecord(") && !code.includes("__VUE_HMR_RUNTIME__.rerender(")) return;
5962
+ const { code: rewritten, matched } = rewriteVueHmrIds(code, ctx.options.name);
5973
5963
  if (!matched) {
5974
5964
  warnPluginVueRegression();
5975
5965
  return;
@@ -7878,6 +7868,11 @@ function resolveDevHashEntryFileName(fileName) {
7878
7868
  const baseName = path$1.basename(normalized);
7879
7869
  return path$1.extname(baseName) ? normalized : `${normalized}.js`;
7880
7870
  }
7871
+ function resolveAbsoluteDevRemoteEntryUrl(publicPath, fileName) {
7872
+ const base = new URL(publicPath);
7873
+ base.pathname = ensureTrailingSlash(base.pathname);
7874
+ return new URL(fileName, base).href;
7875
+ }
7881
7876
  function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposesId, getParsePromise = () => Promise.resolve() }) {
7882
7877
  let viteConfig, _command, root, originalConfigBase;
7883
7878
  let exposeRemoteDependencies = {};
@@ -8007,12 +8002,15 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
8007
8002
  if (_command === "serve") {
8008
8003
  const host = typeof viteConfig.server?.host === "string" && viteConfig.server.host !== "0.0.0.0" ? viteConfig.server.host : "localhost";
8009
8004
  const resolvedPublicPath = resolvePublicPath(options, viteConfig.base, originalConfigBase);
8010
- const publicPath = JSON.stringify((resolvedPublicPath === "auto" ? "/" : resolvedPublicPath) + resolveDevHashEntryFileName(options.filename));
8005
+ const devPublicPath = resolvedPublicPath === "auto" ? "/" : resolvedPublicPath;
8006
+ const remoteEntryFileName = resolveDevHashEntryFileName(options.filename);
8007
+ const isAbsolutePublicPath = /^https?:\/\//i.test(devPublicPath);
8008
+ const remoteEntryUrl = JSON.stringify(isAbsolutePublicPath ? resolveAbsoluteDevRemoteEntryUrl(devPublicPath, remoteEntryFileName) : `${ensureTrailingSlash(devPublicPath)}${remoteEntryFileName}`);
8011
8009
  const fallbackOrigin = `//${host}:${viteConfig.server?.port}`;
8012
8010
  const ssrRemoteEntry = "data:text/javascript," + encodeURIComponent("export async function init(){return {loadRemote:async()=>({}),loadShare:async()=>({})}}");
8013
8011
  return `
8014
8012
  const origin = typeof window !== 'undefined' && (${!options.ignoreOrigin}) ? window.origin : ${JSON.stringify(fallbackOrigin)};
8015
- const remoteEntryImport = typeof window !== 'undefined' ? origin + ${publicPath} : ${JSON.stringify(ssrRemoteEntry)};
8013
+ const remoteEntryImport = typeof window !== 'undefined' ? ${isAbsolutePublicPath ? remoteEntryUrl : `origin + ${remoteEntryUrl}`} : ${JSON.stringify(ssrRemoteEntry)};
8016
8014
  ${generateHostAutoInitCode("remoteEntryImport", "serve", options)}
8017
8015
  `;
8018
8016
  }
@@ -8155,41 +8153,6 @@ function pluginProxyRemotes_default(options) {
8155
8153
  };
8156
8154
  }
8157
8155
  //#endregion
8158
- //#region src/plugins/pluginReactMixedModeGuard.ts
8159
- const REACT_DEVELOPMENT_RUNTIME = /[\\/]react[\\/]cjs[\\/]react(?:-jsx-(?:dev-)?runtime)?\.development\.js$/;
8160
- const UNSAFE_GET_OWNER = "return null === dispatcher ? null : dispatcher.getOwner();";
8161
- const SAFE_GET_OWNER = "return typeof dispatcher?.getOwner === \"function\" ? dispatcher.getOwner() : null;";
8162
- const REACT_MIXED_MODE_ROLLDOWN_PLUGIN = "module-federation:react-mixed-mode-rolldown";
8163
- const REACT_MIXED_MODE_ESBUILD_PLUGIN = "module-federation:react-mixed-mode-esbuild";
8164
- function patchReactDevelopmentRuntime(code, id) {
8165
- if (!REACT_DEVELOPMENT_RUNTIME.test(id)) return;
8166
- const patched = code.replaceAll(UNSAFE_GET_OWNER, SAFE_GET_OWNER);
8167
- return patched === code ? void 0 : patched;
8168
- }
8169
- function createRolldownReactMixedModeGuard() {
8170
- return {
8171
- name: REACT_MIXED_MODE_ROLLDOWN_PLUGIN,
8172
- transform(code, id) {
8173
- return patchReactDevelopmentRuntime(code, id);
8174
- }
8175
- };
8176
- }
8177
- function createEsbuildReactMixedModeGuard() {
8178
- return {
8179
- name: REACT_MIXED_MODE_ESBUILD_PLUGIN,
8180
- setup(build) {
8181
- build.onLoad({ filter: REACT_DEVELOPMENT_RUNTIME }, (args) => {
8182
- const patched = patchReactDevelopmentRuntime(readFileSync$1(args.path, "utf8"), args.path);
8183
- if (patched === void 0) return;
8184
- return {
8185
- contents: patched,
8186
- loader: "js"
8187
- };
8188
- });
8189
- }
8190
- };
8191
- }
8192
- //#endregion
8193
8156
  //#region src/utils/PromiseStore.ts
8194
8157
  /**
8195
8158
  * example:
@@ -8968,8 +8931,8 @@ function readBoundedRunnerBody(req, res) {
8968
8931
  function pluginSSRRemoteEntry(options) {
8969
8932
  const remoteEntrySSRId = getRemoteEntrySSRId(options);
8970
8933
  const virtualExposesSSRId = getVirtualExposesSSRId(options);
8971
- let isRolldown = false;
8972
- let ssrOutputFilename = "";
8934
+ let cachedSsrRemoteEntrySource;
8935
+ const ssrOutputFilename = getSsrRemoteEntryFileName(options.filename);
8973
8936
  let ssrOutputFiles = /* @__PURE__ */ new Set();
8974
8937
  let ssrOutputDir = "";
8975
8938
  let clientOutputDir = "";
@@ -8986,6 +8949,16 @@ function pluginSSRRemoteEntry(options) {
8986
8949
  let viteConfig;
8987
8950
  let isNuxtProject = false;
8988
8951
  let reactIslandExposes = /* @__PURE__ */ new Set();
8952
+ const isSsrRemoteEntryBuild = (environment) => {
8953
+ const environmentName = environment?.name;
8954
+ const hasSsrEnvironment = Boolean(viteConfig?.environments?.ssr);
8955
+ const isLegacySsrBuild = Boolean(environment?.config?.build?.ssr ?? viteConfig?.build?.ssr);
8956
+ return Object.keys(options.exposes).length > 0 && !(hasSsrEnvironment && environmentName !== "ssr" || !hasSsrEnvironment && !isLegacySsrBuild);
8957
+ };
8958
+ const getSsrRemoteEntrySource = () => {
8959
+ if (cachedSsrRemoteEntrySource === void 0) cachedSsrRemoteEntrySource = generateRemoteEntrySSR(options);
8960
+ return cachedSsrRemoteEntrySource;
8961
+ };
8989
8962
  const findNuxtExposesChunk = (bundle) => {
8990
8963
  const exposeKeys = Object.keys(options.exposes);
8991
8964
  if (exposeKeys.length === 0) return;
@@ -9112,17 +9085,9 @@ function pluginSSRRemoteEntry(options) {
9112
9085
  },
9113
9086
  buildStart() {
9114
9087
  if (isServe) return;
9115
- isRolldown = getIsRolldown(this);
9116
- ssrOutputFilename = getSsrRemoteEntryFileName(options.filename);
9117
- const environmentName = this.environment?.name;
9118
- const hasSsrEnvironment = Boolean(viteConfig?.environments?.ssr);
9119
- const isLegacySsrBuild = Boolean(this.environment?.config?.build?.ssr);
9120
- if (hasSsrEnvironment) {
9121
- if (isNuxtProject) {
9122
- if (environmentName === "ssr") return;
9123
- } else if (environmentName !== "ssr") return;
9124
- } else if (isLegacySsrBuild) {} else if (environmentName && environmentName !== "client") return;
9125
- if (Object.keys(options.exposes).length === 0) return;
9088
+ const isRolldown = getIsRolldown(this);
9089
+ const environment = this.environment;
9090
+ if (!isSsrRemoteEntryBuild(environment)) return;
9126
9091
  if (isRolldown) this.emitFile({
9127
9092
  type: "chunk",
9128
9093
  id: remoteEntrySSRId,
@@ -9130,20 +9095,27 @@ function pluginSSRRemoteEntry(options) {
9130
9095
  fileName: ssrOutputFilename,
9131
9096
  preserveSignature: "strict"
9132
9097
  });
9133
- else this.emitFile({
9134
- type: "asset",
9135
- fileName: ssrOutputFilename,
9136
- source: generateRemoteEntrySSR(options)
9137
- });
9138
9098
  },
9139
- generateBundle(_options, bundle) {
9140
- const exposesChunk = findNuxtExposesChunk(bundle);
9141
- const ssrAsset = bundle[ssrOutputFilename];
9142
- if (exposesChunk && ssrAsset?.type === "asset" && typeof ssrAsset.source === "string") ssrAsset.source = ssrAsset.source.replace(/import\("virtual:mf-exposes-ssr:[^"]+"\)/g, `import("./${exposesChunk}")`);
9143
- if (this.environment?.name === "ssr") ssrOutputFiles = collectEntryOutputFiles(bundle, ssrOutputFilename);
9144
- if (!isRolldown) return;
9145
- const chunk = bundle[ssrOutputFilename];
9146
- if (!chunk || chunk.type !== "chunk") return;
9099
+ generateBundle: {
9100
+ order: "post",
9101
+ handler(_options, bundle) {
9102
+ const isRolldown = getIsRolldown(this);
9103
+ const environment = this.environment;
9104
+ const exposesChunk = findNuxtExposesChunk(bundle);
9105
+ if (!isRolldown && isSsrRemoteEntryBuild(environment)) {
9106
+ let source = getSsrRemoteEntrySource();
9107
+ if (exposesChunk) source = source.replace(/import\("virtual:mf-exposes-ssr:[^"]+"\)/g, `import("./${exposesChunk}")`);
9108
+ this.emitFile({
9109
+ type: "asset",
9110
+ fileName: ssrOutputFilename,
9111
+ source
9112
+ });
9113
+ }
9114
+ if (this.environment?.name === "ssr") ssrOutputFiles = collectEntryOutputFiles(bundle, ssrOutputFilename);
9115
+ if (!isRolldown) return;
9116
+ const chunk = bundle[ssrOutputFilename];
9117
+ if (!chunk || chunk.type !== "chunk") return;
9118
+ }
9147
9119
  },
9148
9120
  writeBundle(outputOptions) {
9149
9121
  const environmentName = this.environment?.name;
@@ -9661,7 +9633,6 @@ function includeLinkedSharedEntries(optimizeDeps, shared, projectRoot, exposes,
9661
9633
  function createEarlyVirtualModulesPlugin(options) {
9662
9634
  const { shared, remotes } = options;
9663
9635
  const isLitShare = (pkg) => pkg === "lit" || pkg.startsWith("lit/");
9664
- const shouldGuardReactMixedMode = Object.keys(remotes ?? {}).length > 0 && shared?.react?.shareConfig.singleton === true;
9665
9636
  return {
9666
9637
  name: "vite:module-federation-early-init",
9667
9638
  enforce: "pre",
@@ -9689,7 +9660,6 @@ function createEarlyVirtualModulesPlugin(options) {
9689
9660
  if (isRolldown) {
9690
9661
  optimizeDeps.rolldownOptions ??= {};
9691
9662
  optimizeDeps.rolldownOptions.plugins ??= [];
9692
- if (shouldGuardReactMixedMode) optimizeDeps.rolldownOptions.plugins.push(createRolldownReactMixedModeGuard());
9693
9663
  optimizeDeps.rolldownOptions.plugins.push({
9694
9664
  name: "module-federation:optimize-shared-resolver",
9695
9665
  load(id) {
@@ -9734,7 +9704,6 @@ function createEarlyVirtualModulesPlugin(options) {
9734
9704
  } else {
9735
9705
  optimizeDeps.esbuildOptions ??= {};
9736
9706
  optimizeDeps.esbuildOptions.plugins ??= [];
9737
- if (shouldGuardReactMixedMode) optimizeDeps.esbuildOptions.plugins.push(createEsbuildReactMixedModeGuard());
9738
9707
  optimizeDeps.esbuildOptions.plugins.push({
9739
9708
  name: "module-federation:optimize-shared-proxy",
9740
9709
  setup(build) {
@@ -9989,6 +9958,7 @@ function federation(mfUserOptions) {
9989
9958
  name: "vite:module-federation-virtual-modules",
9990
9959
  enforce: "pre",
9991
9960
  resolveId(id) {
9961
+ if (id === "@module-federation/vite/ssrEntryLoader") return resolveImportPath(id);
9992
9962
  let virtualModule = VirtualModule.findById(id);
9993
9963
  if (!virtualModule) {
9994
9964
  materializeCachedLoadShareModule({
@@ -10163,6 +10133,7 @@ function federation(mfUserOptions) {
10163
10133
  patchedManualChunks.add(mfChunkName);
10164
10134
  if (!useCodeSplitting) {
10165
10135
  const mfManualChunks = function(id) {
10136
+ if (PRELOAD_HELPER_TEST.test(id)) return PRELOAD_HELPER_CHUNK;
10166
10137
  return mfChunkName(id) ?? void 0;
10167
10138
  };
10168
10139
  patchedManualChunks.add(mfManualChunks);
@@ -116,4 +116,4 @@ function resolvePublicPath(options, viteBase, originalBase) {
116
116
  return "auto";
117
117
  }
118
118
  //#endregion
119
- export { getMatchingNodeModuleSubpath as a, isNuxtClientBase as c, resolvePublicPath as d, getCommonSharedSubpaths as i, isViteOptimizableEntry as l, getBasePath as n, isAssetLikeImport as o, getCommonSharedSubpathFromNodeModulePath as r, isNodeModulePath as s, filterId as t, normalizeNodeModulePath as u };
119
+ export { getCommonSharedSubpaths as a, isNodeModulePath as c, normalizeNodeModulePath as d, resolvePublicPath as f, getCommonSharedSubpathFromNodeModulePath as i, isNuxtClientBase as l, filterId as n, getMatchingNodeModuleSubpath as o, getBasePath as r, isAssetLikeImport as s, ensureTrailingSlash as t, isViteOptimizableEntry as u };
@@ -603,7 +603,7 @@ async function importTempModule(filePath, versionKey) {
603
603
  }
604
604
  let warnedVmUnavailable = false;
605
605
  async function tryVmStrategy(ssrEntry, options) {
606
- const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-BkEp3YIv.js");
606
+ const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-DTJITp2Z.js");
607
607
  if (!await isVmStrategyAvailable()) {
608
608
  if (!warnedVmUnavailable) {
609
609
  warnedVmUnavailable = true;
@@ -1,5 +1,5 @@
1
- import { i as getCommonSharedSubpaths } from "./pathNormalization-CLDIcf9-.js";
2
- import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-7v0Do_g5.js";
1
+ import { a as getCommonSharedSubpaths } from "./pathNormalization-DvgU8LIp.js";
2
+ import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-Ccr0zMrr.js";
3
3
  //#region src/utils/ssrVmStrategy.ts
4
4
  /**
5
5
  * vm.SourceTextModule strategy for loading remote SSR entries.
@@ -1,3 +1,4 @@
1
+ import runtimePackage from "@module-federation/runtime/package.json" with { type: "json" };
1
2
  import * as runtimeCore from "@module-federation/runtime/core";
2
3
  //#region src/utils/injectExternalRuntimeCorePlugin.ts
3
4
  /**
@@ -8,8 +9,7 @@ import * as runtimeCore from "@module-federation/runtime/core";
8
9
  * Mirrors `@module-federation/inject-external-runtime-core-plugin` without
9
10
  * adding that package (or `runtime-tools`) as a dependency of this plugin.
10
11
  */
11
- /** Keep in sync with the `@module-federation/runtime` dependency version. */
12
- const PLUGIN_VERSION = "2.8.0";
12
+ const PLUGIN_VERSION = runtimePackage.version;
13
13
  function getFederationGlobal() {
14
14
  const globalRef = runtimeCore.Global;
15
15
  if (!globalRef || typeof globalRef !== "object") return void 0;
@@ -1,2 +1,2 @@
1
- import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-7v0Do_g5.js";
1
+ import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-Ccr0zMrr.js";
2
2
  export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.20.3",
3
+ "version": "1.20.5",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -77,9 +77,9 @@
77
77
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
78
78
  },
79
79
  "dependencies": {
80
- "@module-federation/dts-plugin": "2.8.1",
81
- "@module-federation/runtime": "2.8.1",
82
- "@module-federation/sdk": "2.8.1"
80
+ "@module-federation/dts-plugin": "2.8.2",
81
+ "@module-federation/runtime": "2.8.2",
82
+ "@module-federation/sdk": "2.8.2"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@playwright/test": "1.62.0",