@module-federation/vite 1.15.0 → 1.15.1

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.cjs CHANGED
@@ -1292,7 +1292,7 @@ function getOrderedUsedShares() {
1292
1292
  const shares = new Set(getUsedShares());
1293
1293
  try {
1294
1294
  Object.keys(getNormalizeModuleFederationOptions().shared).forEach((pkg) => {
1295
- shares.add(pkg.endsWith("/") ? pkg.slice(0, -1) : pkg);
1295
+ if (!pkg.endsWith("/")) shares.add(pkg);
1296
1296
  });
1297
1297
  } catch {}
1298
1298
  return Array.from(shares).sort((a, b) => {
@@ -1306,12 +1306,8 @@ function getShareItemForPreload(pkg) {
1306
1306
  if (isExplicitSharedKey(pkg)) return shared[pkg];
1307
1307
  if (isExplicitSharedKey(wildcardKey)) return shared[wildcardKey];
1308
1308
  }
1309
- function generateDirectSharedCacheSeedCode(command = "build") {
1310
- return getOrderedUsedShares().map((pkg) => {
1311
- const shareItem = getShareItemForPreload(pkg);
1312
- if (!shareItem || shareItem.shareConfig.import === false) return null;
1313
- const importPath = command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem);
1314
- return `if (__mfModuleCache.share[${JSON.stringify(pkg)}] === undefined) {
1309
+ function generateSharedCacheSeedItem(pkg, importPath) {
1310
+ return `if (__mfModuleCache.share[${JSON.stringify(pkg)}] === undefined) {
1315
1311
  const mod = await import(${JSON.stringify(importPath)});
1316
1312
  const exportModule = ${JSON.stringify(shouldUseDirectReactImport())} && ${JSON.stringify(pkg)} === "react"
1317
1313
  ? (mod?.default ?? mod)
@@ -1322,6 +1318,33 @@ function generateDirectSharedCacheSeedCode(command = "build") {
1322
1318
  });
1323
1319
  __mfModuleCache.share[${JSON.stringify(pkg)}] = exportModule;
1324
1320
  }`;
1321
+ }
1322
+ function generateDirectSharedCacheSeedCode(command = "build") {
1323
+ return getOrderedUsedShares().map((pkg) => {
1324
+ const shareItem = getShareItemForPreload(pkg);
1325
+ if (!shareItem || shareItem.shareConfig.import === false) return null;
1326
+ return generateSharedCacheSeedItem(pkg, command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem));
1327
+ }).filter((item) => item !== null).join("\n");
1328
+ }
1329
+ function getBrowserImportPath(importPath) {
1330
+ if (/^(?:[a-zA-Z]:[\\/]|\/)/.test(importPath) && !importPath.startsWith("/@")) return `/@fs/${importPath}`;
1331
+ return importPath;
1332
+ }
1333
+ function getHostAutoInitSharedSeedItems() {
1334
+ return getOrderedUsedShares().map((pkg) => ({
1335
+ pkg,
1336
+ shareItem: getShareItemForPreload(pkg)
1337
+ })).filter(({ shareItem }) => shareItem?.shareConfig.import === false).sort((a, b) => {
1338
+ const priority = (pkg) => pkg === "vue" ? 0 : pkg === "pinia" ? 1 : 2;
1339
+ const aIsLocal = !!getLocalProviderImportPath(a.pkg);
1340
+ const bIsLocal = !!getLocalProviderImportPath(b.pkg);
1341
+ return priority(a.pkg) - priority(b.pkg) || Number(aIsLocal) - Number(bIsLocal) || a.pkg.localeCompare(b.pkg);
1342
+ });
1343
+ }
1344
+ function generateHostAutoInitSharedCacheSeedCode() {
1345
+ return getHostAutoInitSharedSeedItems().map(({ pkg, shareItem }) => {
1346
+ if (!shareItem) return null;
1347
+ return generateSharedCacheSeedItem(pkg, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)));
1325
1348
  }).filter((item) => item !== null).join("\n");
1326
1349
  }
1327
1350
  const REMOTE_ENTRY_ID = "virtual:mf-REMOTE_ENTRY_ID";
@@ -1428,6 +1451,7 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
1428
1451
  async function initHost() {
1429
1452
  if (!hostInitPromise) {
1430
1453
  hostInitPromise = (async () => {
1454
+ ${generateHostAutoInitSharedCacheSeedCode()}
1431
1455
  const remoteEntry = await import(${remoteEntryImport});
1432
1456
  const runtime = await remoteEntry.init();
1433
1457
  const usedShared = ${generateUsedSharedPreloadConfig()};
@@ -2631,6 +2655,12 @@ const COMMON_SHARED_SUBPATHS = {
2631
2655
  "react-dom/client",
2632
2656
  "react-dom/server",
2633
2657
  "react-dom/server.browser"
2658
+ ],
2659
+ "solid-js": [
2660
+ "solid-js/web",
2661
+ "solid-js/store",
2662
+ "solid-js/html",
2663
+ "solid-js/h"
2634
2664
  ]
2635
2665
  };
2636
2666
  function removeTrailingSlash(value) {
@@ -3302,7 +3332,6 @@ function proxySharedModule(options) {
3302
3332
  if (importer && (importer.includes("hostAutoInit") || importer.includes("__H_A_I__"))) return;
3303
3333
  if (importer && importer.includes("__loadShare__")) return;
3304
3334
  if (importer && importer.includes("__prebuild__")) return;
3305
- if (key.endsWith("/") && source !== key.slice(0, -1)) return;
3306
3335
  const shareSource = isNodeModulePath(source) ? getCommonSharedSubpathFromNodeModulePath(source, key) || key : source;
3307
3336
  const loadSharePath = getLoadShareModulePath(shareSource, useRolldown);
3308
3337
  writeLoadShareModule(shareSource, shared[key], _command, useRolldown);
@@ -4043,7 +4072,7 @@ export default __mfShared.default ?? __mfShared;`
4043
4072
  optimizeDeps.include ??= [];
4044
4073
  optimizeDeps.exclude ??= [];
4045
4074
  const shouldBypassOptimizeDep = isLitShare(key);
4046
- if (isRolldown || shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
4075
+ if (shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
4047
4076
  if (!isRolldown && !shouldBypassOptimizeDep) optimizeDeps.include.push(getLoadShareImportId(key, isRolldown));
4048
4077
  optimizeDeps.include.push(getPreBuildLibImportId(key));
4049
4078
  for (const subpath of getCommonSharedSubpaths(key)) {
package/lib/index.mjs CHANGED
@@ -1270,7 +1270,7 @@ function getOrderedUsedShares() {
1270
1270
  const shares = new Set(getUsedShares());
1271
1271
  try {
1272
1272
  Object.keys(getNormalizeModuleFederationOptions().shared).forEach((pkg) => {
1273
- shares.add(pkg.endsWith("/") ? pkg.slice(0, -1) : pkg);
1273
+ if (!pkg.endsWith("/")) shares.add(pkg);
1274
1274
  });
1275
1275
  } catch {}
1276
1276
  return Array.from(shares).sort((a, b) => {
@@ -1284,12 +1284,8 @@ function getShareItemForPreload(pkg) {
1284
1284
  if (isExplicitSharedKey(pkg)) return shared[pkg];
1285
1285
  if (isExplicitSharedKey(wildcardKey)) return shared[wildcardKey];
1286
1286
  }
1287
- function generateDirectSharedCacheSeedCode(command = "build") {
1288
- return getOrderedUsedShares().map((pkg) => {
1289
- const shareItem = getShareItemForPreload(pkg);
1290
- if (!shareItem || shareItem.shareConfig.import === false) return null;
1291
- const importPath = command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem);
1292
- return `if (__mfModuleCache.share[${JSON.stringify(pkg)}] === undefined) {
1287
+ function generateSharedCacheSeedItem(pkg, importPath) {
1288
+ return `if (__mfModuleCache.share[${JSON.stringify(pkg)}] === undefined) {
1293
1289
  const mod = await import(${JSON.stringify(importPath)});
1294
1290
  const exportModule = ${JSON.stringify(shouldUseDirectReactImport())} && ${JSON.stringify(pkg)} === "react"
1295
1291
  ? (mod?.default ?? mod)
@@ -1300,6 +1296,33 @@ function generateDirectSharedCacheSeedCode(command = "build") {
1300
1296
  });
1301
1297
  __mfModuleCache.share[${JSON.stringify(pkg)}] = exportModule;
1302
1298
  }`;
1299
+ }
1300
+ function generateDirectSharedCacheSeedCode(command = "build") {
1301
+ return getOrderedUsedShares().map((pkg) => {
1302
+ const shareItem = getShareItemForPreload(pkg);
1303
+ if (!shareItem || shareItem.shareConfig.import === false) return null;
1304
+ return generateSharedCacheSeedItem(pkg, command === "serve" ? getLocalSharedPackagePath(pkg, shareItem) : getDirectSharedCacheSeedImportPath(pkg, shareItem));
1305
+ }).filter((item) => item !== null).join("\n");
1306
+ }
1307
+ function getBrowserImportPath(importPath) {
1308
+ if (/^(?:[a-zA-Z]:[\\/]|\/)/.test(importPath) && !importPath.startsWith("/@")) return `/@fs/${importPath}`;
1309
+ return importPath;
1310
+ }
1311
+ function getHostAutoInitSharedSeedItems() {
1312
+ return getOrderedUsedShares().map((pkg) => ({
1313
+ pkg,
1314
+ shareItem: getShareItemForPreload(pkg)
1315
+ })).filter(({ shareItem }) => shareItem?.shareConfig.import === false).sort((a, b) => {
1316
+ const priority = (pkg) => pkg === "vue" ? 0 : pkg === "pinia" ? 1 : 2;
1317
+ const aIsLocal = !!getLocalProviderImportPath(a.pkg);
1318
+ const bIsLocal = !!getLocalProviderImportPath(b.pkg);
1319
+ return priority(a.pkg) - priority(b.pkg) || Number(aIsLocal) - Number(bIsLocal) || a.pkg.localeCompare(b.pkg);
1320
+ });
1321
+ }
1322
+ function generateHostAutoInitSharedCacheSeedCode() {
1323
+ return getHostAutoInitSharedSeedItems().map(({ pkg, shareItem }) => {
1324
+ if (!shareItem) return null;
1325
+ return generateSharedCacheSeedItem(pkg, getBrowserImportPath(getDirectSharedCacheSeedImportPath(pkg, shareItem)));
1303
1326
  }).filter((item) => item !== null).join("\n");
1304
1327
  }
1305
1328
  const REMOTE_ENTRY_ID = "virtual:mf-REMOTE_ENTRY_ID";
@@ -1406,6 +1429,7 @@ function generateHostAutoInitCode(remoteEntryImport, _command = "build") {
1406
1429
  async function initHost() {
1407
1430
  if (!hostInitPromise) {
1408
1431
  hostInitPromise = (async () => {
1432
+ ${generateHostAutoInitSharedCacheSeedCode()}
1409
1433
  const remoteEntry = await import(${remoteEntryImport});
1410
1434
  const runtime = await remoteEntry.init();
1411
1435
  const usedShared = ${generateUsedSharedPreloadConfig()};
@@ -2609,6 +2633,12 @@ const COMMON_SHARED_SUBPATHS = {
2609
2633
  "react-dom/client",
2610
2634
  "react-dom/server",
2611
2635
  "react-dom/server.browser"
2636
+ ],
2637
+ "solid-js": [
2638
+ "solid-js/web",
2639
+ "solid-js/store",
2640
+ "solid-js/html",
2641
+ "solid-js/h"
2612
2642
  ]
2613
2643
  };
2614
2644
  function removeTrailingSlash(value) {
@@ -3280,7 +3310,6 @@ function proxySharedModule(options) {
3280
3310
  if (importer && (importer.includes("hostAutoInit") || importer.includes("__H_A_I__"))) return;
3281
3311
  if (importer && importer.includes("__loadShare__")) return;
3282
3312
  if (importer && importer.includes("__prebuild__")) return;
3283
- if (key.endsWith("/") && source !== key.slice(0, -1)) return;
3284
3313
  const shareSource = isNodeModulePath(source) ? getCommonSharedSubpathFromNodeModulePath(source, key) || key : source;
3285
3314
  const loadSharePath = getLoadShareModulePath(shareSource, useRolldown);
3286
3315
  writeLoadShareModule(shareSource, shared[key], _command, useRolldown);
@@ -4021,7 +4050,7 @@ export default __mfShared.default ?? __mfShared;`
4021
4050
  optimizeDeps.include ??= [];
4022
4051
  optimizeDeps.exclude ??= [];
4023
4052
  const shouldBypassOptimizeDep = isLitShare(key);
4024
- if (isRolldown || shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
4053
+ if (shouldBypassOptimizeDep) optimizeDeps.exclude.push(key);
4025
4054
  if (!isRolldown && !shouldBypassOptimizeDep) optimizeDeps.include.push(getLoadShareImportId(key, isRolldown));
4026
4055
  optimizeDeps.include.push(getPreBuildLibImportId(key));
4027
4056
  for (const subpath of getCommonSharedSubpaths(key)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",