@module-federation/vite 1.23.9 → 1.23.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +144 -67
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -3004,13 +3004,18 @@ function generateDeferredHostProvidedExports(namedExports, pkg, cacheDescriptor,
3004
3004
  const declarations = ["let __mf_default;", ...namedExportVars.map((name) => `let ${name};`)].join("\n ");
3005
3005
  const assignments = [...namedExports.map((name, i) => `${namedExportVars[i]} = exportModule[${escapeGeneratedStringLiteral(name)}];`), "__mf_default = exportModule.default ?? exportModule;"].join("\n ");
3006
3006
  const namedExportLine = namedExports.length > 0 ? `\n export { ${namedExports.map((name, i) => `${namedExportVars[i]} as ${name}`).join(", ")} };` : "";
3007
+ const subscribeToLateShare = treeShakingConsumer ? "" : `__mfSubscribeSharedCache(__mfModuleCache.share, ${cacheDescriptor}, (mod) => {
3008
+ exportModule = mod;
3009
+ __mfApplyHostProvidedExports(mod);
3010
+ });
3011
+ `;
3007
3012
  return `${declarations}
3008
3013
  const __mfApplyHostProvidedExports = (exportModule) => {
3009
3014
  ${assignments}
3010
3015
  };
3011
3016
  let exportModule = ${getSharedCacheReadExpression(cacheDescriptor, treeShakingConsumer)};
3012
3017
  if (exportModule === undefined) {
3013
- __mfTrackPendingShareLoad(initPromise.then(() => {
3018
+ ${subscribeToLateShare}__mfTrackPendingShareLoad(initPromise.then(() => {
3014
3019
  exportModule = ${getSharedCacheReadExpression(cacheDescriptor, treeShakingConsumer)};
3015
3020
  // A share init() left to its dynamic import is normally bridged before that import runs;
3016
3021
  // bridge it here when this wrapper is reached another way.
@@ -3174,7 +3179,7 @@ function writeLoadShareModule(pkg, shareItem, command, options, exportConditions
3174
3179
  const servesRemoteSingletonFallback = command !== "build" && isRemoteOnlyContainer(options) && isSingleton;
3175
3180
  const isConsumedByPeerSingleton = isSharedSingletonConsumedByPeer(pkg, options);
3176
3181
  const usesEntryInjectedRemoteFallback = hasCompleteExportCoverage && !isWorkspaceSingleton && isRemoteContainer(options) && isSingleton && options.hostInitInjectLocation === "entry" && (command === "build" || isConsumedByPeerSingleton);
3177
- const usesDeferredEntryInjectedSingletonFallback = usesEntryInjectedRemoteFallback && !isReactCoreShare(pkg) && (pkg === "react-dom/client" || shareItem.shareConfig.eager !== true && !isSharedSingletonConsumedByPeer(pkg, options, true));
3182
+ const usesDeferredEntryInjectedSingletonFallback = command === "build" && hasCompleteExportCoverage && isSingleton && pkg === "react-dom/client" && !isWorkspaceSingleton && options.hostInitInjectLocation === "entry" && hasRemotes(options) && !hasPackageDependency("vinext") || usesEntryInjectedRemoteFallback && !isReactCoreShare(pkg) && (pkg === "react-dom/client" || shareItem.shareConfig.eager !== true && !isSharedSingletonConsumedByPeer(pkg, options, true));
3178
3183
  const usesEagerWorkspaceFallback = hasCompleteExportCoverage && isWorkspaceSingleton && !servesRemoteSingletonFallback && (isConsumedByPeerSingleton || shareItem.shareConfig.eager === true);
3179
3184
  const usesDeferredTreeShakingFallback = hasCompleteExportCoverage && Boolean(treeShakingConsumer);
3180
3185
  const rebindsSharedExports = isSingleton || options.shareStrategy === "version-first";
@@ -4026,11 +4031,13 @@ function getMaterializedShares(options) {
4026
4031
  if (request.endsWith("/")) for (const concrete of expandSharedPrefixKey(request, usedForEager)) shares.add(concrete);
4027
4032
  else shares.add(pkg);
4028
4033
  }
4029
- const configured = /* @__PURE__ */ new Map();
4034
+ const sharedKeysByPackage = /* @__PURE__ */ new Map();
4030
4035
  const orderedUsed = getOrderedUsedShares(options);
4031
4036
  for (const pkg of orderedUsed) {
4032
4037
  const packageName = getPackageName(pkg);
4033
- if (!configured.has(packageName) || pkg === packageName) configured.set(packageName, pkg);
4038
+ const keys = sharedKeysByPackage.get(packageName);
4039
+ if (keys) keys.push(pkg);
4040
+ else sharedKeysByPackage.set(packageName, [pkg]);
4034
4041
  }
4035
4042
  const localImports = getLocalShareImports(orderedUsed, options);
4036
4043
  const pending = [...shares];
@@ -4049,13 +4056,11 @@ function getMaterializedShares(options) {
4049
4056
  ...packageJson?.optionalDependencies || {},
4050
4057
  ...packageJson?.peerDependenciesMeta || {}
4051
4058
  };
4052
- for (const dependency of Object.keys(dependencies)) {
4053
- const sharedDependency = configured.get(dependency);
4054
- const dependencyShare = sharedDependency ? getNormalizeShareItem(sharedDependency, options) : void 0;
4055
- if (sharedDependency && !shares.has(sharedDependency) && dependencyShare?.scope === share?.scope) {
4056
- shares.add(sharedDependency);
4057
- pending.push(sharedDependency);
4058
- }
4059
+ for (const dependency of Object.keys(dependencies)) for (const sharedDependency of sharedKeysByPackage.get(dependency) ?? []) {
4060
+ if (shares.has(sharedDependency)) continue;
4061
+ if (getNormalizeShareItem(sharedDependency, options)?.scope !== share?.scope) continue;
4062
+ shares.add(sharedDependency);
4063
+ pending.push(sharedDependency);
4059
4064
  }
4060
4065
  }
4061
4066
  const sorted = [...shares].sort((a, b) => {
@@ -4471,8 +4476,16 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy, options, command = "b
4471
4476
  };
4472
4477
  var __mfSeedLocalShared = async (seedKeys) => {
4473
4478
  const requested = new Set(seedKeys);
4479
+ // A dependent of a share left to the late bridge would evaluate against an empty
4480
+ // wrapper (#1541); leave it to its wrapper's own fallback load instead.
4481
+ const skipped = new Set();
4474
4482
  for (const batch of __mfSeedBatches) await Promise.all(batch.filter((pkg) => requested.has(pkg)).map(async (pkg) => {
4475
4483
  const share = usedShared[pkg];
4484
+ const seedIndex = __mfSeedIndex.get(pkg);
4485
+ if ((__mfSeedPrerequisites[seedIndex] || []).some((dependency) => skipped.has(dependency))) {
4486
+ skipped.add(seedIndex);
4487
+ return;
4488
+ }
4476
4489
  const cacheDescriptor = __mfGetSharedCacheDescriptor(pkg, share.shareConfig?.singleton, share.version, share.scope);
4477
4490
  if (
4478
4491
  share.shareConfig?.import === false ||
@@ -4543,7 +4556,10 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy, options, command = "b
4543
4556
  isWebpackProvider(externalProvider) &&
4544
4557
  (share.shareConfig?.singleton ||
4545
4558
  __mfFindSharedProviderEntry(initialShared[pkg], externalProvider)?.version === share.version)
4546
- ) return;
4559
+ ) {
4560
+ skipped.add(seedIndex);
4561
+ return;
4562
+ }
4547
4563
  }
4548
4564
  const providerKey = cacheDescriptor.canonical;
4549
4565
  const resolved = await __mfInitializeProviderOnce(providerKey, async () => {
@@ -4564,6 +4580,10 @@ function generateRuntimeSharedCacheSeedCode(shareStrategy, options, command = "b
4564
4580
  value: true,
4565
4581
  enumerable: false
4566
4582
  });
4583
+ // The init map is page-wide: another container may have run this provider
4584
+ // init and seeded the result under its own name. Keep that owner, or this
4585
+ // container would later treat a sibling's copy as its own provisional seed.
4586
+ if (__mfReadSharedCache(__mfModuleCache.share, cacheDescriptor) !== undefined) return;
4567
4587
  __mfWriteSharedCache(__mfModuleCache.share, cacheDescriptor, exportModule, mfName);
4568
4588
  }));
4569
4589
  };
@@ -4944,7 +4964,14 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
4944
4964
  return __mfExposesMap
4945
4965
  }
4946
4966
 
4967
+ // Hosts that call get() without awaiting init() must still see the shares that
4968
+ // init binds asynchronously: get() waits until no init() call is in flight.
4969
+ let __mfInitsInFlight = 0;
4970
+ let __mfInitsSettled = Promise.resolve();
4971
+ let __mfSettleInits = () => {};
4947
4972
  async function init(shared = {}, initScope = [], remoteEntryInitOptions = {}) {
4973
+ if (__mfInitsInFlight++ === 0) __mfInitsSettled = new Promise((resolve) => (__mfSettleInits = resolve));
4974
+ try {
4948
4975
  ${sharedCacheHelperCode}
4949
4976
  const getShareScope = (scopeName) => remoteEntryInitOptions.shareScopeMap?.[scopeName] ?? (${hasMultipleShareScopes} ? (shared?.[scopeName] || {}) : shared);
4950
4977
  const getShareScopeNames = (share) => {
@@ -5820,9 +5847,14 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
5820
5847
  };` : ""}
5821
5848
  initResolve(initRes)
5822
5849
  return initRes
5850
+ } finally {
5851
+ if (--__mfInitsInFlight === 0) __mfSettleInits();
5852
+ }
5823
5853
  }
5824
5854
 
5825
5855
  async function getExposes(moduleName) {
5856
+ // init() failures surface from init() itself; get() only waits for it to settle.
5857
+ if (__mfInitsInFlight) await __mfInitsSettled
5826
5858
  const exposesMap = await getExposesMap()
5827
5859
  if (!(moduleName in exposesMap)) throw new Error(\`[Module Federation] Module \${moduleName} does not exist in container.\`)
5828
5860
  if (__mfLateBridgeShared) await __mfLateBridgeShared()
@@ -5926,6 +5958,16 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build", options
5926
5958
  if (lateKeys.length) __mfHostInitShareBatches.push(lateKeys);
5927
5959
  }
5928
5960
  ${hostInitSharedProviderHelperCode}
5961
+ // Hosts on one page share the module cache. Negotiate one host at a time so
5962
+ // none adopts another's half-upgraded set of singletons.
5963
+ const __mfPinnedShareOwners = (__mfModuleCache.pinnedShareOwners ||= new Set());
5964
+ const __mfPreviousHostShareInit = __mfModuleCache.hostShareInit;
5965
+ let __mfReleaseHostShareInit;
5966
+ __mfModuleCache.hostShareInit = new Promise((resolve) => {
5967
+ __mfReleaseHostShareInit = resolve;
5968
+ });
5969
+ await __mfPreviousHostShareInit;
5970
+ try {
5929
5971
  for (const __mfHostInitShareBatch of __mfHostInitShareBatches) {
5930
5972
  await Promise.all(__mfHostInitShareBatch.map(async (pkg) => {
5931
5973
  const share = usedShared[pkg];
@@ -5936,6 +5978,20 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build", options
5936
5978
  // a generic full-module key here.
5937
5979
  if (share.treeShaking) return;
5938
5980
  const cacheDescriptor = __mfGetSharedCacheDescriptor(pkg, share.shareConfig?.singleton, share.version, share.scope);
5981
+ // Another host on the page may hold this singleton in the module cache. Its
5982
+ // app, e.g. its react-dom, is bound to that copy, so this host adopts it and
5983
+ // pins that host's seeds: re-negotiation may then no longer upgrade them.
5984
+ const __mfKeepsCachedSingleton = () => {
5985
+ if (!share.shareConfig?.singleton) return false;
5986
+ if (__mfReadSharedCache(__mfModuleCache.share, cacheDescriptor) === undefined) return false;
5987
+ const owner = __mfReadSharedCacheOwner(__mfModuleCache.share, cacheDescriptor);
5988
+ if (owner === undefined) return false;
5989
+ if (owner === ${cacheOwner}) return __mfPinnedShareOwners.has(owner);
5990
+ if ((runtime.options?.remotes || []).some((remote) => remote.name === owner)) return false;
5991
+ __mfPinnedShareOwners.add(owner);
5992
+ return true;
5993
+ };
5994
+ if (__mfKeepsCachedSingleton()) return;
5939
5995
  if (
5940
5996
  __mfReadSharedCache(__mfModuleCache.share, cacheDescriptor) !== undefined &&
5941
5997
  ${_command === "serve" ? `__mfReadSharedCacheOwner(__mfModuleCache.share, cacheDescriptor) !== undefined &&
@@ -5984,6 +6040,7 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build", options
5984
6040
  customShareInfo: { shareConfig: share.shareConfig }
5985
6041
  }).then(async (factory) => {
5986
6042
  if (factory === false) return;
6043
+ if (__mfKeepsCachedSingleton()) return;
5987
6044
  const mod = typeof factory === "function" ? factory() : factory;
5988
6045
  let resolved = __mfNormalizeRuntimeShare(await Promise.resolve(mod));
5989
6046
  ${preferLocalVinextReact ? `if (
@@ -6006,6 +6063,9 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build", options
6006
6063
  });
6007
6064
  }));
6008
6065
  }
6066
+ } finally {
6067
+ __mfReleaseHostShareInit();
6068
+ }
6009
6069
  ` : ""}
6010
6070
  // The seed called this container's get() directly, so the Runtime's
6011
6071
  // provider never learned it is in use and a remote could load its own
@@ -6549,7 +6609,7 @@ function escapeHtmlAttr(value) {
6549
6609
  function getExistingHrefSet(html) {
6550
6610
  return new Set(Array.from(html.matchAll(/\bhref\s*=\s*["']([^"']+)["']/gi), (match) => match[1]));
6551
6611
  }
6552
- function injectHostInitPreloads(html, bundle, resolvePath, externalHrefs = []) {
6612
+ function injectHostInitPreloads(html, bundle, resolvePath, externalHrefs = [], isExtraSeed = () => false) {
6553
6613
  const existingHrefs = getExistingHrefSet(html);
6554
6614
  const hrefs = [];
6555
6615
  for (const href of externalHrefs) {
@@ -6558,7 +6618,7 @@ function injectHostInitPreloads(html, bundle, resolvePath, externalHrefs = []) {
6558
6618
  hrefs.push(href);
6559
6619
  }
6560
6620
  const chunksByFileName = getChunksByFileName(bundle);
6561
- const seeds = Array.from(chunksByFileName.values()).filter(isHostInitPreloadSeed);
6621
+ const seeds = Array.from(chunksByFileName.values()).filter((chunk) => isHostInitPreloadSeed(chunk) || isExtraSeed(chunk));
6562
6622
  for (const fileName of collectPreloadChunkFiles(chunksByFileName, seeds)) {
6563
6623
  const href = resolvePath(fileName);
6564
6624
  if (existingHrefs.has(href)) continue;
@@ -6567,7 +6627,9 @@ function injectHostInitPreloads(html, bundle, resolvePath, externalHrefs = []) {
6567
6627
  }
6568
6628
  if (hrefs.length === 0) return html;
6569
6629
  const tags = hrefs.map((href) => `<link rel="modulepreload" crossorigin href="${escapeHtmlAttr(href)}">`).join("");
6570
- return html.includes("</head>") ? html.replace("</head>", `${tags}</head>`) : `${tags}${html}`;
6630
+ if (html.includes("</head>")) return html.replace("</head>", `${tags}</head>`);
6631
+ const script = html.search(/<script\b[^>]*\btype=["']module["']/i);
6632
+ return script === -1 ? `${tags}${html}` : html.slice(0, script) + tags + html.slice(script);
6571
6633
  }
6572
6634
  function appendRemoteEntryWarmup(bundle, entryFileName) {
6573
6635
  const chunksByFileName = getChunksByFileName(bundle);
@@ -6758,7 +6820,7 @@ const __mfCurrentScript = document.currentScript;
6758
6820
  const remoteSources = isLoadedFirstClientBuild ? Array.from(getPreloadRemotes(normalizedOptions)) : Object.keys(getUsedRemotesMap(normalizedOptions));
6759
6821
  return Array.from(new Set(remoteSources.flatMap((remote) => {
6760
6822
  const registration = getRemoteRegistration(remote, normalizedOptions.remotes, federationOptions);
6761
- return registration && (registration.type === "module" || registration.type === "esm") && /^(?:https?:)?\/\//.test(registration.entry) && !/\.json(?:[?#]|$)/i.test(registration.entry) ? [registration.entry] : [];
6823
+ return registration && (registration.type === "module" || registration.type === "esm") && /^(?:https?:)?\//.test(registration.entry) && !/\.json(?:[?#]|$)/i.test(registration.entry) ? [registration.entry] : [];
6762
6824
  })));
6763
6825
  }
6764
6826
  async function warmupDevEntryGraph(entryUrl) {
@@ -7138,7 +7200,8 @@ for (const __mfRemoteEntryPrefetchUrl of __mfRemoteEntryPrefetchUrls) {
7138
7200
  const remoteEntryFile = findRemoteEntryFile(fileName, bundle);
7139
7201
  if (remoteEntryFile) appendRemoteEntryWarmup(bundle, remoteEntryFile);
7140
7202
  }
7141
- if (!injectHtml()) return;
7203
+ const preloadsEntryHtml = inject === "entry" && waitsForInit && !viteConfig.build.ssr && viteConfig.build.modulePreload !== false;
7204
+ if (!injectHtml() && !preloadsEntryHtml) return;
7142
7205
  if (!emitFileId) return;
7143
7206
  const htmlFileNames = Object.keys(bundle).filter((fileName) => fileName.endsWith(".html"));
7144
7207
  if (htmlFileNames.length === 0) return;
@@ -7167,6 +7230,14 @@ for (const __mfRemoteEntryPrefetchUrl of __mfRemoteEntryPrefetchUrls) {
7167
7230
  };
7168
7231
  const basePrefix = viteConfig.base?.replace(/\/$/, "") ?? "";
7169
7232
  const stripBase = (p) => basePrefix && p.startsWith(basePrefix + "/") ? p.slice(basePrefix.length) : p;
7233
+ if (!injectHtml()) {
7234
+ for (const fileName of htmlFileNames) {
7235
+ const htmlAsset = bundle[fileName];
7236
+ if (htmlAsset.type === "chunk") continue;
7237
+ htmlAsset.source = injectHostInitPreloads(htmlAsset.source.toString(), bundle, (builtFileName) => resolvePath(builtFileName, fileName), getRemoteEntryPreloadUrls(), (chunk) => !!chunk.facadeModuleId && hasEntryBootstrapParam(chunk.facadeModuleId));
7238
+ }
7239
+ return;
7240
+ }
7170
7241
  let bootstrapIndex = 0;
7171
7242
  for (const fileName of htmlFileNames) {
7172
7243
  let htmlAsset = bundle[fileName];
@@ -8391,7 +8462,7 @@ function ${helperName}(names) {
8391
8462
  }
8392
8463
  //#endregion
8393
8464
  //#region package.json
8394
- var version$1 = "1.23.9";
8465
+ var version$1 = "1.23.10";
8395
8466
  //#endregion
8396
8467
  //#region src/virtualModules/virtualExposesSSR.ts
8397
8468
  /**
@@ -10388,8 +10459,9 @@ function proxySharedModule(options) {
10388
10459
  configureServer(server) {
10389
10460
  devServer = server;
10390
10461
  setLocalSharedImportMapInvalidator(() => {
10391
- const module = server.moduleGraph.getModuleById(getResolvedLocalSharedImportMapId(federationOptions));
10392
- if (module) server.moduleGraph.invalidateModule(module);
10462
+ const graph = server.environments?.client?.moduleGraph ?? server.moduleGraph;
10463
+ const module = graph.getModuleById(getResolvedLocalSharedImportMapId(federationOptions));
10464
+ if (module) graph.invalidateModule(module);
10393
10465
  }, federationOptions);
10394
10466
  },
10395
10467
  resolveId(source) {
@@ -10520,49 +10592,52 @@ function proxySharedModule(options) {
10520
10592
  {
10521
10593
  name: "proxyPreBuildShared:resolve-shared-loadShare",
10522
10594
  enforce: "pre",
10523
- async resolveId(source, importer, resolveOptions) {
10524
- if (isSharedEntryLookup(source, importer, resolveOptions) || resolveOptions.custom?.__mfTreeShakingGraph) return;
10525
- const sharedSource = await sharedSourceResolver.resolve(this, source, resolveOptions);
10526
- if (!sharedSource) return;
10527
- const key = findSharedKey(sharedSource, shared);
10528
- if (!key) return;
10529
- const shouldSkipTaggedImporterProxy = (sharedKey, tag) => {
10530
- if (!importer?.includes(tag)) return false;
10531
- const taggedModule = VirtualModule.findModule(tag, importer);
10532
- if (!taggedModule) return true;
10533
- return taggedModule.name === sharedKey || matchesSharedSource(sharedSource, taggedModule.name);
10534
- };
10535
- const importerPackage = getSharedPackageFromFile(importer, shared);
10536
- if (importerPackage === getPackageName(key) && keepsOwnPackageEdge(importer, shared)) return;
10537
- if (importerPackage && shared[key].shareConfig.import !== false) {
10538
- const importerIsUnsharedWorkspacePackage = !isNodeModulePath(importer) && !Object.keys(shared).some((sharedKey) => getPackageName(sharedKey) === importerPackage);
10539
- const request = getSharedRequest(key, shared[key]);
10540
- const runtimeDependencyRequest = request.endsWith("/") && matchesSharedSource(sharedSource, key, shared[key]) ? sharedSource : request;
10541
- if (importerIsUnsharedWorkspacePackage ? isSharedPackageRuntimeDependency(runtimeDependencyRequest, importerPackage, getRuntimeDependencyConditions(this, resolveOptions)) : isSharedPackageDependency(request, importerPackage)) return;
10542
- }
10543
- if (useDirectReactImport && key === "react") return;
10544
- if (isAssetLikeImport(source)) return;
10545
- if (isBuildConfigImporter(importer)) return;
10546
- if (useDirectReactImport && source === "react") return;
10547
- if (importer && importer.includes("localSharedImportMap")) return;
10548
- if (importer && (importer.includes("hostAutoInit") || importer.includes("__H_A_I__"))) return;
10549
- if (shouldSkipTaggedImporterProxy(key, "__loadShare__")) return;
10550
- if (shouldSkipTaggedImporterProxy(key, "__prebuild__")) return;
10551
- const shareSource = key === "vue" && sharedSource.startsWith("vue/dist/") ? key : sharedSource;
10552
- if (shouldKeepSharedImportLocal(shareSource, importer, key, shared, importerPackage, federationOptions)) {
10553
- const localSource = getPrebuildResolutionSource(shareSource, shared[key]);
10554
- return tryResolveFromProjectRoot(localSource) || localSource;
10555
- }
10556
- const loadSharePath = getLoadShareModulePath(shareSource, federationOptions);
10557
- if (!materializedLoadShareSources.has(shareSource)) {
10558
- materializedLoadShareSources.add(shareSource);
10559
- writeLoadShareModule(shareSource, shared[key], _command, federationOptions);
10560
- if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key], federationOptions);
10561
- addUsedShares(shareSource, federationOptions);
10562
- writeLocalSharedImportMap(federationOptions);
10563
- refreshHostAutoInit(federationOptions);
10595
+ resolveId: {
10596
+ order: "pre",
10597
+ async handler(source, importer, resolveOptions) {
10598
+ if (isSharedEntryLookup(source, importer, resolveOptions) || resolveOptions.custom?.__mfTreeShakingGraph) return;
10599
+ const sharedSource = await sharedSourceResolver.resolve(this, source, resolveOptions);
10600
+ if (!sharedSource) return;
10601
+ const key = findSharedKey(sharedSource, shared);
10602
+ if (!key) return;
10603
+ const shouldSkipTaggedImporterProxy = (sharedKey, tag) => {
10604
+ if (!importer?.includes(tag)) return false;
10605
+ const taggedModule = VirtualModule.findModule(tag, importer);
10606
+ if (!taggedModule) return true;
10607
+ return taggedModule.name === sharedKey || matchesSharedSource(sharedSource, taggedModule.name);
10608
+ };
10609
+ const importerPackage = getSharedPackageFromFile(importer, shared);
10610
+ if (importerPackage === getPackageName(key) && keepsOwnPackageEdge(importer, shared)) return;
10611
+ if (importerPackage && shared[key].shareConfig.import !== false) {
10612
+ const importerIsUnsharedWorkspacePackage = !isNodeModulePath(importer) && !Object.keys(shared).some((sharedKey) => getPackageName(sharedKey) === importerPackage);
10613
+ const request = getSharedRequest(key, shared[key]);
10614
+ const runtimeDependencyRequest = request.endsWith("/") && matchesSharedSource(sharedSource, key, shared[key]) ? sharedSource : request;
10615
+ if (importerIsUnsharedWorkspacePackage ? isSharedPackageRuntimeDependency(runtimeDependencyRequest, importerPackage, getRuntimeDependencyConditions(this, resolveOptions)) : isSharedPackageDependency(request, importerPackage)) return;
10616
+ }
10617
+ if (useDirectReactImport && key === "react") return;
10618
+ if (isAssetLikeImport(source)) return;
10619
+ if (isBuildConfigImporter(importer)) return;
10620
+ if (useDirectReactImport && source === "react") return;
10621
+ if (importer && importer.includes("localSharedImportMap")) return;
10622
+ if (importer && (importer.includes("hostAutoInit") || importer.includes("__H_A_I__"))) return;
10623
+ if (shouldSkipTaggedImporterProxy(key, "__loadShare__")) return;
10624
+ if (shouldSkipTaggedImporterProxy(key, "__prebuild__")) return;
10625
+ const shareSource = key === "vue" && sharedSource.startsWith("vue/dist/") ? key : sharedSource;
10626
+ if (shouldKeepSharedImportLocal(shareSource, importer, key, shared, importerPackage, federationOptions)) {
10627
+ const localSource = getPrebuildResolutionSource(shareSource, shared[key]);
10628
+ return tryResolveFromProjectRoot(localSource) || localSource;
10629
+ }
10630
+ const loadSharePath = getLoadShareModulePath(shareSource, federationOptions);
10631
+ if (!materializedLoadShareSources.has(shareSource)) {
10632
+ materializedLoadShareSources.add(shareSource);
10633
+ writeLoadShareModule(shareSource, shared[key], _command, federationOptions);
10634
+ if (shared[key].shareConfig.import !== false) writePreBuildLibPath(shareSource, shared[key], federationOptions);
10635
+ addUsedShares(shareSource, federationOptions);
10636
+ writeLocalSharedImportMap(federationOptions);
10637
+ refreshHostAutoInit(federationOptions);
10638
+ }
10639
+ return this.resolve(loadSharePath, importer, { skipSelf: true });
10564
10640
  }
10565
- return this.resolve(loadSharePath, importer, { skipSelf: true });
10566
10641
  }
10567
10642
  },
10568
10643
  {
@@ -12240,7 +12315,7 @@ function registerEntryImports(options, projectRoot, recordShared = true, entryFi
12240
12315
  function materializeSharedRequest(options, request) {
12241
12316
  addUsedShares(request, options);
12242
12317
  const packageName = getPackageName(request);
12243
- if (packageName !== request && findSharedKey(packageName, options.shared)) addUsedShares(packageName, options);
12318
+ if (packageName !== request && findSharedKey(packageName, options.shared) && isPackageExportAvailable(packageName)) addUsedShares(packageName, options);
12244
12319
  }
12245
12320
  function materializeAutomaticJsxRuntime(options, runtime) {
12246
12321
  if (!findSharedKey(runtime, options.shared)) return false;
@@ -12256,6 +12331,7 @@ function createEarlyVirtualModulesPlugin(options) {
12256
12331
  const { shared, remotes } = options;
12257
12332
  const isLitShare = (pkg) => pkg === "lit" || pkg.startsWith("lit/");
12258
12333
  let hasClientJsxSource = false;
12334
+ let scanBuildEntryImports;
12259
12335
  return {
12260
12336
  name: "vite:module-federation-early-init",
12261
12337
  enforce: "pre",
@@ -12284,10 +12360,8 @@ function createEarlyVirtualModulesPlugin(options) {
12284
12360
  config.optimizeDeps.exclude.push(...Object.keys(remotes || {}));
12285
12361
  }
12286
12362
  }
12287
- if (!config.build?.ssr && (hasShared(options) || hasRemotes(options))) {
12288
- const hasJsxSource = registerEntryImports(options, root, _command === "serve", resolvedConfiguredEntryFiles);
12289
- if (_command === "serve") hasClientJsxSource = hasJsxSource;
12290
- }
12363
+ if (!config.build?.ssr && (hasShared(options) || hasRemotes(options))) if (_command === "serve") hasClientJsxSource = registerEntryImports(options, root, true, resolvedConfiguredEntryFiles);
12364
+ else scanBuildEntryImports = () => registerEntryImports(options, root, false, resolvedConfiguredEntryFiles);
12291
12365
  if (hasShared(options)) {
12292
12366
  if (_command === "serve") {
12293
12367
  excludeSharedSubDependencies(shared);
@@ -12479,6 +12553,9 @@ export default __mfShared.default ?? __mfShared;`
12479
12553
  }
12480
12554
  }
12481
12555
  },
12556
+ buildStart() {
12557
+ scanBuildEntryImports?.();
12558
+ },
12482
12559
  configResolved(config) {
12483
12560
  if (hasClientJsxSource) {
12484
12561
  const automaticJsxRuntime = getAutomaticJsxRuntime(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.23.9",
3
+ "version": "1.23.10",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",