@module-federation/vite 1.12.0 → 1.12.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/README.md CHANGED
@@ -124,6 +124,12 @@ export default defineConfig({
124
124
  // Timeout for parsing modules in seconds.
125
125
  // Defaults to 10 seconds.
126
126
  moduleParseTimeout: 10,
127
+ // Idle timeout for parsing modules in seconds. When set, the timeout
128
+ // resets on every parsed module and only fires when there has been no
129
+ // module activity for the configured duration. Prefer this over
130
+ // moduleParseTimeout for large codebases where total build time may
131
+ // exceed the fixed timeout value.
132
+ moduleParseIdleTimeout: 10,
127
133
  }),
128
134
  ],
129
135
  server: {
@@ -141,6 +147,7 @@ export default defineConfig({
141
147
  The host app configuration specifies its name, the filename of its exposed remote entry remoteEntry.js, and importantly, the configuration of the remote application to load.
142
148
  You can specify the place the host initialization file is injected with the **hostInitInjectLocation** option, which is described in the example code above.
143
149
  The **moduleParseTimeout** option allows you to configure the maximum time to wait for module parsing during the build process.
150
+ The **moduleParseIdleTimeout** option is an alternative that resets the timer on every parsed module. It only fires when there has been no module activity for the configured duration, making it suitable for large codebases where the total build time exceeds the fixed timeout.
144
151
 
145
152
  ## Load the Remote App
146
153
 
package/lib/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
@@ -7,16 +7,12 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
- key = keys[i];
13
- if (!__hasOwnProp.call(to, key) && key !== except) {
14
- __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- }
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
20
16
  }
21
17
  return to;
22
18
  };
@@ -24,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
20
  value: mod,
25
21
  enumerable: true
26
22
  }) : target, mod));
27
-
28
23
  //#endregion
29
24
  let defu = require("defu");
30
25
  defu = __toESM(defu);
@@ -35,13 +30,11 @@ pathe = __toESM(pathe);
35
30
  let magic_string = require("magic-string");
36
31
  magic_string = __toESM(magic_string);
37
32
  let _rollup_pluginutils = require("@rollup/pluginutils");
38
- let estree_walker = require("estree-walker");
39
33
  let _module_federation_sdk = require("@module-federation/sdk");
40
34
  let _module_federation_dts_plugin = require("@module-federation/dts-plugin");
41
35
  let _module_federation_dts_plugin_core = require("@module-federation/dts-plugin/core");
42
36
  let module$1 = require("module");
43
37
  let url = require("url");
44
-
45
38
  //#region src/utils/mapCodeToCodeWithSourcemap.ts
46
39
  async function mapCodeToCodeWithSourcemap(code) {
47
40
  const resolvedCode = await code;
@@ -52,14 +45,14 @@ async function mapCodeToCodeWithSourcemap(code) {
52
45
  map: s.generateMap({ hires: true })
53
46
  };
54
47
  }
55
-
56
48
  //#endregion
57
49
  //#region src/plugins/pluginAddEntry.ts
58
50
  function getFirstHtmlEntryFile(entryFiles) {
59
51
  return entryFiles.find((file) => file.endsWith(".html"));
60
52
  }
61
53
  const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
62
- let devEntryPath = entryPath.startsWith("virtual:mf") ? "@id/" + entryPath : entryPath;
54
+ const getEntryPath = () => typeof entryPath === "function" ? entryPath() : entryPath;
55
+ let devEntryPath = "";
63
56
  let entryFiles = [];
64
57
  let htmlFilePath;
65
58
  let _command;
@@ -79,6 +72,8 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
79
72
  },
80
73
  configResolved(config) {
81
74
  viteConfig = config;
75
+ const resolvedEntryPath = getEntryPath();
76
+ devEntryPath = resolvedEntryPath.startsWith("virtual:mf") ? "@id/" + resolvedEntryPath : resolvedEntryPath;
82
77
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, "/").replace(/.+?\:([/\\])[/\\]?/, "$1").replace(/^\//, "");
83
78
  },
84
79
  configureServer(server) {
@@ -120,7 +115,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
120
115
  const emitFileOptions = {
121
116
  name: entryName,
122
117
  type: "chunk",
123
- id: entryPath,
118
+ id: getEntryPath(),
124
119
  preserveSignature: "strict"
125
120
  };
126
121
  if (!hasHash) emitFileOptions.fileName = fileName;
@@ -166,12 +161,11 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
166
161
  },
167
162
  transform(code, id) {
168
163
  if (injectEntry() && entryFiles.some((file) => id.endsWith(file))) return mapCodeToCodeWithSourcemap(`
169
- import ${JSON.stringify(entryPath)};
164
+ import ${JSON.stringify(getEntryPath())};
170
165
  ` + code);
171
166
  }
172
167
  }];
173
168
  };
174
-
175
169
  //#endregion
176
170
  //#region src/plugins/pluginCheckAliasConflicts.ts
177
171
  /**
@@ -211,19 +205,23 @@ function checkAliasConflicts(options) {
211
205
  }
212
206
  };
213
207
  }
214
-
215
208
  //#endregion
216
209
  //#region src/plugins/pluginDevProxyModuleTopLevelAwait.ts
217
210
  /**
218
211
  * Solve the problem that dev mode dependency prebunding does not support top-level await syntax
219
212
  */
213
+ let walkPromise = null;
214
+ function loadWalk() {
215
+ walkPromise ||= import("estree-walker").then(({ walk }) => walk);
216
+ return walkPromise;
217
+ }
220
218
  function PluginDevProxyModuleTopLevelAwait() {
221
219
  const filterFunction = (0, _rollup_pluginutils.createFilter)();
222
220
  const processedFlag = "/* already-processed-by-dev-proxy-module-top-level-await */";
223
221
  return {
224
222
  name: "dev-proxy-module-top-level-await",
225
223
  apply: "serve",
226
- transform(code, id) {
224
+ async transform(code, id) {
227
225
  if (code.includes(processedFlag)) return null;
228
226
  if (!code.includes("/*mf top-level-await placeholder replacement mf*/")) return null;
229
227
  if (!filterFunction(id)) return null;
@@ -234,7 +232,7 @@ function PluginDevProxyModuleTopLevelAwait() {
234
232
  throw new Error(`${id}: ${e}`);
235
233
  }
236
234
  const magicString = new magic_string.default(code);
237
- (0, estree_walker.walk)(ast, { enter(node) {
235
+ (await loadWalk())(ast, { enter(node) {
238
236
  if (node.type === "ExportNamedDeclaration" && node.specifiers) {
239
237
  const exportSpecifiers = node.specifiers.map((specifier) => specifier.exported.name);
240
238
  const proxyStatements = exportSpecifiers.map((name) => `
@@ -276,7 +274,6 @@ function PluginDevProxyModuleTopLevelAwait() {
276
274
  }
277
275
  };
278
276
  }
279
-
280
277
  //#endregion
281
278
  //#region src/plugins/pluginDts.ts
282
279
  const DEFAULT_DEV_OPTIONS = {
@@ -504,7 +501,6 @@ function pluginDts(options) {
504
501
  }
505
502
  }];
506
503
  }
507
-
508
504
  //#endregion
509
505
  //#region src/utils/normalizeModuleFederationOptions.ts
510
506
  function normalizeExposesItem(key, item) {
@@ -671,11 +667,11 @@ function normalizeModuleFederationOptions(options) {
671
667
  hostInitInjectLocation: options.hostInitInjectLocation || "html",
672
668
  bundleAllCSS: options.bundleAllCSS || false,
673
669
  moduleParseTimeout: options.moduleParseTimeout || 10,
670
+ moduleParseIdleTimeout: options.moduleParseIdleTimeout,
674
671
  varFilename: options.varFilename,
675
672
  target: options.target
676
673
  };
677
674
  }
678
-
679
675
  //#endregion
680
676
  //#region src/utils/packageNameUtils.ts
681
677
  /**
@@ -704,7 +700,6 @@ function packageNameDecode(encoded) {
704
700
  if (typeof encoded !== "string") throw new Error("A string encoded file name is required");
705
701
  return encoded.replace(/_mf_0_/g, "@").replace(/_mf_1_/g, "/").replace(/_mf_2_/g, "-").replace(/_mf_3_/g, ".");
706
702
  }
707
-
708
703
  //#endregion
709
704
  //#region src/utils/localSharedImportMap_temp.ts
710
705
  /**
@@ -721,7 +716,6 @@ function createFile(filePath, content) {
721
716
  (0, fs.mkdirSync)(pathe.default.dirname(filePath), { recursive: true });
722
717
  (0, fs.writeFileSync)(filePath, content);
723
718
  }
724
-
725
719
  //#endregion
726
720
  //#region src/utils/serializeRuntimeOptions.ts
727
721
  /**
@@ -769,7 +763,6 @@ function serializeRuntimeOptions(options) {
769
763
  for (const key in options) if (Object.prototype.hasOwnProperty.call(options, key)) topLevelProps.push(`${JSON.stringify(key)}: ${valueToCode(options[key])}`);
770
764
  return `{${topLevelProps.join(", ")}}`;
771
765
  }
772
-
773
766
  //#endregion
774
767
  //#region src/utils/VirtualModule.ts
775
768
  /**
@@ -779,14 +772,12 @@ function serializeRuntimeOptions(options) {
779
772
  */
780
773
  function initVirtualModuleInfrastructure(root, virtualModuleDir = "__mf__virtual") {
781
774
  const virtualPackagePath = (0, pathe.join)((0, pathe.join)(root, "node_modules"), virtualModuleDir);
782
- if (!(0, fs.existsSync)(virtualPackagePath)) {
783
- (0, fs.mkdirSync)(virtualPackagePath, { recursive: true });
784
- (0, fs.writeFileSync)((0, pathe.join)(virtualPackagePath, "empty.js"), "");
785
- (0, fs.writeFileSync)((0, pathe.join)(virtualPackagePath, "package.json"), JSON.stringify({
786
- name: virtualModuleDir,
787
- main: "empty.js"
788
- }));
789
- }
775
+ (0, fs.mkdirSync)(virtualPackagePath, { recursive: true });
776
+ (0, fs.writeFileSync)((0, pathe.join)(virtualPackagePath, "empty.js"), "");
777
+ (0, fs.writeFileSync)((0, pathe.join)(virtualPackagePath, "package.json"), JSON.stringify({
778
+ name: virtualModuleDir,
779
+ main: "empty.js"
780
+ }));
790
781
  }
791
782
  let rootDir;
792
783
  function findNodeModulesDir(root = process.cwd()) {
@@ -835,14 +826,12 @@ var VirtualModule = class {
835
826
  const nodeModulesDir = getNodeModulesDir();
836
827
  const { virtualModuleDir } = getNormalizeModuleFederationOptions();
837
828
  const virtualPackagePath = (0, pathe.resolve)(nodeModulesDir, virtualModuleDir);
838
- if (!(0, fs.existsSync)(virtualPackagePath)) {
839
- (0, fs.mkdirSync)(virtualPackagePath);
840
- (0, fs.writeFileSync)((0, pathe.resolve)(virtualPackagePath, "empty.js"), "");
841
- (0, fs.writeFileSync)((0, pathe.resolve)(virtualPackagePath, "package.json"), JSON.stringify({
842
- name: virtualModuleDir,
843
- main: "empty.js"
844
- }));
845
- }
829
+ (0, fs.mkdirSync)(virtualPackagePath, { recursive: true });
830
+ (0, fs.writeFileSync)((0, pathe.resolve)(virtualPackagePath, "empty.js"), "");
831
+ (0, fs.writeFileSync)((0, pathe.resolve)(virtualPackagePath, "package.json"), JSON.stringify({
832
+ name: virtualModuleDir,
833
+ main: "empty.js"
834
+ }));
846
835
  }
847
836
  static findModule(tag, str = "") {
848
837
  if (!patternMap[tag]) patternMap[tag] = new RegExp(`(.*${packageNameEncode(tag)}(.+?)${packageNameEncode(tag)}.*)`);
@@ -873,7 +862,6 @@ var VirtualModule = class {
873
862
  (0, fs.writeFile)(this.getPath(), code, function() {});
874
863
  }
875
864
  };
876
-
877
865
  //#endregion
878
866
  //#region src/virtualModules/virtualExposes.ts
879
867
  function getVirtualExposesId(options) {
@@ -899,7 +887,6 @@ function generateExposes(options) {
899
887
  }
900
888
  `;
901
889
  }
902
-
903
890
  //#endregion
904
891
  //#region src/virtualModules/virtualRuntimeInitStatus.ts
905
892
  const virtualRuntimeInitStatus = new VirtualModule("runtimeInit");
@@ -924,7 +911,6 @@ if (!globalThis[globalKey]) {
924
911
  ${exportStatement}
925
912
  `);
926
913
  }
927
-
928
914
  //#endregion
929
915
  //#region src/virtualModules/virtualRemotes.ts
930
916
  const cacheRemoteMap = {};
@@ -956,7 +942,6 @@ function generateRemotes(id, command, isRolldown) {
956
942
  ${exportLine}
957
943
  `;
958
944
  }
959
-
960
945
  //#endregion
961
946
  //#region src/virtualModules/virtualShared_preBuild.ts
962
947
  /**
@@ -1020,7 +1005,6 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
1020
1005
  ${exportLine}
1021
1006
  `);
1022
1007
  }
1023
-
1024
1008
  //#endregion
1025
1009
  //#region src/virtualModules/virtualRemoteEntry.ts
1026
1010
  let usedShares = /* @__PURE__ */ new Set();
@@ -1180,12 +1164,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1180
1164
  }
1181
1165
  `;
1182
1166
  }
1183
- /**
1184
- * Inject entry file, automatically init when used as host,
1185
- * and will not inject remoteEntry
1186
- */
1187
- const HOST_AUTO_INIT_TAG = "__H_A_I__";
1188
- const hostAutoInitModule = new VirtualModule("hostAutoInit", HOST_AUTO_INIT_TAG);
1167
+ const hostAutoInitModule = new VirtualModule("hostAutoInit", "__H_A_I__");
1189
1168
  function writeHostAutoInit(remoteEntryId = REMOTE_ENTRY_ID) {
1190
1169
  hostAutoInitModule.writeSync(`
1191
1170
  const remoteEntryPromise = import("${remoteEntryId}")
@@ -1203,7 +1182,6 @@ function getHostAutoInitImportId() {
1203
1182
  function getHostAutoInitPath() {
1204
1183
  return hostAutoInitModule.getPath();
1205
1184
  }
1206
-
1207
1185
  //#endregion
1208
1186
  //#region src/virtualModules/index.ts
1209
1187
  function initVirtualModules(command, remoteEntryId) {
@@ -1211,13 +1189,11 @@ function initVirtualModules(command, remoteEntryId) {
1211
1189
  writeHostAutoInit(remoteEntryId);
1212
1190
  writeRuntimeInitStatus(command);
1213
1191
  }
1214
-
1215
1192
  //#endregion
1216
1193
  //#region src/utils/bundleHelpers.ts
1217
1194
  function findRemoteEntryFile(filename, bundle) {
1218
1195
  for (const [_, fileData] of Object.entries(bundle)) if (filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "") === fileData.name || fileData.name === "remoteEntry") return fileData.fileName;
1219
1196
  }
1220
-
1221
1197
  //#endregion
1222
1198
  //#region src/utils/cssModuleHelpers.ts
1223
1199
  const ASSET_TYPES = ["js", "css"];
@@ -1338,7 +1314,6 @@ const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
1338
1314
  for (const resolution of resolutions) if (resolution?.file) fileToShareKey.set(resolution.file, resolution.shareKey);
1339
1315
  return fileToShareKey;
1340
1316
  };
1341
-
1342
1317
  //#endregion
1343
1318
  //#region src/utils/publicPath.ts
1344
1319
  /**
@@ -1354,7 +1329,6 @@ function resolvePublicPath(options, viteBase, originalBase) {
1354
1329
  if (viteBase) return viteBase.replace(/\/?$/, "/");
1355
1330
  return "auto";
1356
1331
  }
1357
-
1358
1332
  //#endregion
1359
1333
  //#region src/plugins/pluginMFManifest.ts
1360
1334
  const Manifest = () => {
@@ -1569,7 +1543,6 @@ const Manifest = () => {
1569
1543
  };
1570
1544
  }
1571
1545
  };
1572
-
1573
1546
  //#endregion
1574
1547
  //#region src/plugins/pluginModuleParseEnd.ts
1575
1548
  let _resolve, _parseTimeout;
@@ -1586,12 +1559,19 @@ function setParseTimeout(timeout) {
1586
1559
  _resolve(1);
1587
1560
  }, timeout * 1e3);
1588
1561
  }
1562
+ function resetIdleTimeout(timeout) {
1563
+ clearTimeout(_parseTimeout);
1564
+ _parseTimeout = setTimeout(() => {
1565
+ console.warn(`moduleParseIdleTimeout: no module activity for ${timeout}s, forcing resolve. Some shared/remote dependencies may be missing. Consider increasing moduleParseIdleTimeout.`);
1566
+ _resolve(1);
1567
+ }, timeout * 1e3);
1568
+ }
1589
1569
  let parsePromise = promise;
1590
1570
  let exposesParseEnd = false;
1591
1571
  const parseStartSet = /* @__PURE__ */ new Set();
1592
1572
  const parseEndSet = /* @__PURE__ */ new Set();
1593
1573
  function pluginModuleParseEnd_default(excludeFn, options) {
1594
- setParseTimeout(options.moduleParseTimeout);
1574
+ const idleTimeout = options.moduleParseIdleTimeout;
1595
1575
  return [
1596
1576
  {
1597
1577
  name: "_",
@@ -1604,6 +1584,10 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1604
1584
  enforce: "pre",
1605
1585
  name: "parseStart",
1606
1586
  apply: "build",
1587
+ buildStart() {
1588
+ if (idleTimeout) resetIdleTimeout(idleTimeout);
1589
+ else setParseTimeout(options.moduleParseTimeout);
1590
+ },
1607
1591
  load(id) {
1608
1592
  if (excludeFn(id)) return;
1609
1593
  parseStartSet.add(id);
@@ -1616,6 +1600,7 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1616
1600
  moduleParsed(module) {
1617
1601
  const id = module.id;
1618
1602
  if (id === options.virtualExposesId) exposesParseEnd = true;
1603
+ if (idleTimeout) resetIdleTimeout(idleTimeout);
1619
1604
  if (excludeFn(id)) return;
1620
1605
  parseEndSet.add(id);
1621
1606
  if (exposesParseEnd && parseStartSet.size === parseEndSet.size) _resolve(1);
@@ -1623,7 +1608,6 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1623
1608
  }
1624
1609
  ];
1625
1610
  }
1626
-
1627
1611
  //#endregion
1628
1612
  //#region src/plugins/pluginProxyRemoteEntry.ts
1629
1613
  const filter = (0, _rollup_pluginutils.createFilter)();
@@ -1689,7 +1673,6 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
1689
1673
  }
1690
1674
  };
1691
1675
  }
1692
-
1693
1676
  //#endregion
1694
1677
  //#region src/plugins/pluginProxyRemotes.ts
1695
1678
  (0, _rollup_pluginutils.createFilter)();
@@ -1714,7 +1697,6 @@ function pluginProxyRemotes_default(options) {
1714
1697
  }
1715
1698
  };
1716
1699
  }
1717
-
1718
1700
  //#endregion
1719
1701
  //#region src/utils/PromiseStore.ts
1720
1702
  /**
@@ -1748,7 +1730,6 @@ var PromiseStore = class {
1748
1730
  return pendingPromise;
1749
1731
  }
1750
1732
  };
1751
-
1752
1733
  //#endregion
1753
1734
  //#region src/plugins/pluginProxySharedModule_preBuild.ts
1754
1735
  function proxySharedModule(options) {
@@ -1823,7 +1804,6 @@ function proxySharedModule(options) {
1823
1804
  }
1824
1805
  }];
1825
1806
  }
1826
-
1827
1807
  //#endregion
1828
1808
  //#region src/plugins/pluginVarRemoteEntry.ts
1829
1809
  const VarRemoteEntry = () => {
@@ -1904,7 +1884,6 @@ const VarRemoteEntry = () => {
1904
1884
  `;
1905
1885
  }
1906
1886
  };
1907
-
1908
1887
  //#endregion
1909
1888
  //#region src/utils/aliasToArrayPlugin.ts
1910
1889
  var aliasToArrayPlugin_default = {
@@ -1919,7 +1898,6 @@ var aliasToArrayPlugin_default = {
1919
1898
  }));
1920
1899
  }
1921
1900
  };
1922
-
1923
1901
  //#endregion
1924
1902
  //#region src/utils/normalizeOptimizeDeps.ts
1925
1903
  var normalizeOptimizeDeps_default = {
@@ -1935,7 +1913,6 @@ var normalizeOptimizeDeps_default = {
1935
1913
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
1936
1914
  }
1937
1915
  };
1938
-
1939
1916
  //#endregion
1940
1917
  //#region src/index.ts
1941
1918
  /**
@@ -2007,7 +1984,7 @@ function federation(mfUserOptions) {
2007
1984
  }),
2008
1985
  ...addEntry({
2009
1986
  entryName: "hostInit",
2010
- entryPath: getHostAutoInitPath(),
1987
+ entryPath: () => getHostAutoInitPath(),
2011
1988
  inject: hostInitInjectLocation
2012
1989
  }),
2013
1990
  ...addEntry({
@@ -2024,6 +2001,7 @@ function federation(mfUserOptions) {
2024
2001
  return id.includes(getHostAutoInitImportId()) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath());
2025
2002
  }, {
2026
2003
  moduleParseTimeout: options.moduleParseTimeout,
2004
+ moduleParseIdleTimeout: options.moduleParseIdleTimeout,
2027
2005
  virtualExposesId
2028
2006
  }),
2029
2007
  ...proxySharedModule({ shared }),
@@ -2040,7 +2018,7 @@ function federation(mfUserOptions) {
2040
2018
  const existingManualChunks = output.manualChunks;
2041
2019
  output.manualChunks = function(id) {
2042
2020
  if (id.includes(runtimeInitId)) return "runtimeInit";
2043
- if (id.includes(LOAD_SHARE_TAG)) {
2021
+ if (id.includes("__loadShare__")) {
2044
2022
  const match = id.match(/([^/\\]+__loadShare__[^/\\]+)/);
2045
2023
  return match ? match[1] : "loadShare";
2046
2024
  }
@@ -2053,7 +2031,7 @@ function federation(mfUserOptions) {
2053
2031
  },
2054
2032
  load(id) {
2055
2033
  if (id.startsWith("\0")) return;
2056
- if (id.includes(LOAD_SHARE_TAG) || id.includes(LOAD_REMOTE_TAG)) {
2034
+ if (id.includes("__loadShare__") || id.includes("__loadRemote__")) {
2057
2035
  let code = (0, fs.readFileSync)(id, "utf-8");
2058
2036
  code = code.replace(/import\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
2059
2037
  code = code.replace(/export\s+\*\s+from\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
@@ -2083,7 +2061,7 @@ function federation(mfUserOptions) {
2083
2061
  generateBundle(_, bundle) {
2084
2062
  for (const [fileName, chunk] of Object.entries(bundle)) {
2085
2063
  if (chunk.type !== "chunk") continue;
2086
- if (fileName.includes(LOAD_SHARE_TAG)) continue;
2064
+ if (fileName.includes("__loadShare__")) continue;
2087
2065
  let code = chunk.code;
2088
2066
  let m;
2089
2067
  const importedFromLoadShare = /* @__PURE__ */ new Set();
@@ -2113,7 +2091,7 @@ function federation(mfUserOptions) {
2113
2091
  const proxyChunks = /* @__PURE__ */ new Map();
2114
2092
  for (const [fileName, chunk] of Object.entries(bundle)) {
2115
2093
  if (chunk.type !== "chunk") continue;
2116
- if (fileName.includes(LOAD_SHARE_TAG) && fileName.includes("commonjs-proxy")) proxyChunks.set(fileName, {
2094
+ if (fileName.includes("__loadShare__") && fileName.includes("commonjs-proxy")) proxyChunks.set(fileName, {
2117
2095
  code: chunk.code,
2118
2096
  fileName
2119
2097
  });
@@ -2121,7 +2099,7 @@ function federation(mfUserOptions) {
2121
2099
  if (proxyChunks.size === 0) return;
2122
2100
  for (const [fileName, chunk] of Object.entries(bundle)) {
2123
2101
  if (chunk.type !== "chunk") continue;
2124
- if (fileName.includes(LOAD_SHARE_TAG)) continue;
2102
+ if (fileName.includes("__loadShare__")) continue;
2125
2103
  let code = chunk.code;
2126
2104
  let modified = false;
2127
2105
  for (const [proxyFileName, proxyInfo] of proxyChunks) {
@@ -2224,12 +2202,19 @@ function federation(mfUserOptions) {
2224
2202
  });
2225
2203
  config.build = (0, defu.default)(config.build || {}, { commonjsOptions: { strictRequires: "auto" } });
2226
2204
  const virtualDir = options.virtualModuleDir || "__mf__virtual";
2227
- config.optimizeDeps?.include?.push("@module-federation/runtime");
2228
- config.optimizeDeps?.include?.push(virtualDir);
2205
+ config.optimizeDeps ||= {};
2206
+ config.optimizeDeps.include ||= [];
2207
+ config.optimizeDeps.include.push("@module-federation/runtime");
2208
+ config.optimizeDeps.include.push(virtualDir);
2209
+ options.runtimePlugins.forEach((p) => {
2210
+ const pluginPath = typeof p === "string" ? p : p[0];
2211
+ if (pluginPath && !pluginPath.startsWith(".") && !pluginPath.startsWith("/") && !pluginPath.startsWith("\0") && !pluginPath.startsWith("virtual:")) config.optimizeDeps.include.push(pluginPath);
2212
+ });
2229
2213
  if (isRolldown) config.build = (0, defu.default)(config.build || {}, { target: "esnext" });
2230
2214
  else {
2231
- config.optimizeDeps?.needsInterop?.push(virtualDir);
2232
- config.optimizeDeps?.needsInterop?.push(getLocalSharedImportMapPath());
2215
+ config.optimizeDeps.needsInterop ||= [];
2216
+ config.optimizeDeps.needsInterop.push(virtualDir);
2217
+ config.optimizeDeps.needsInterop.push(getLocalSharedImportMapPath());
2233
2218
  }
2234
2219
  const resolvedTarget = options.target ?? (config.build?.ssr ? "node" : "web");
2235
2220
  if (!config.define) config.define = {};
@@ -2259,6 +2244,5 @@ function federation(mfUserOptions) {
2259
2244
  }] : []
2260
2245
  ];
2261
2246
  }
2262
-
2263
2247
  //#endregion
2264
- exports.federation = federation;
2248
+ exports.federation = federation;
package/lib/index.d.cts CHANGED
@@ -60,6 +60,13 @@ type ModuleFederationOptions = {
60
60
  * Defaults to 10 seconds.
61
61
  */
62
62
  moduleParseTimeout?: number;
63
+ /**
64
+ * Idle timeout for parsing modules in seconds. When set, the timeout resets
65
+ * on every parsed module and only fires when there has been no module activity
66
+ * for the configured duration. Prefer this over `moduleParseTimeout` for large
67
+ * codebases where the total build time may exceed the fixed timeout.
68
+ */
69
+ moduleParseIdleTimeout?: number;
63
70
  /**
64
71
  * Allows generate additional remoteEntry file for "var" host environment
65
72
  */
package/lib/index.d.mts CHANGED
@@ -60,6 +60,13 @@ type ModuleFederationOptions = {
60
60
  * Defaults to 10 seconds.
61
61
  */
62
62
  moduleParseTimeout?: number;
63
+ /**
64
+ * Idle timeout for parsing modules in seconds. When set, the timeout resets
65
+ * on every parsed module and only fires when there has been no module activity
66
+ * for the configured duration. Prefer this over `moduleParseTimeout` for large
67
+ * codebases where the total build time may exceed the fixed timeout.
68
+ */
69
+ moduleParseIdleTimeout?: number;
63
70
  /**
64
71
  * Allows generate additional remoteEntry file for "var" host environment
65
72
  */
package/lib/index.mjs CHANGED
@@ -6,16 +6,13 @@ import * as path$1 from "pathe";
6
6
  import path, { basename, dirname, join, parse, resolve } from "pathe";
7
7
  import MagicString from "magic-string";
8
8
  import { createFilter } from "@rollup/pluginutils";
9
- import { walk } from "estree-walker";
10
9
  import { normalizeOptions } from "@module-federation/sdk";
11
10
  import { consumeTypesAPI, generateTypesAPI, isTSProject, normalizeConsumeTypesOptions, normalizeDtsOptions, normalizeGenerateTypesOptions } from "@module-federation/dts-plugin";
12
11
  import { rpc } from "@module-federation/dts-plugin/core";
13
12
  import { createRequire as createRequire$1 } from "module";
14
13
  import { fileURLToPath } from "url";
15
-
16
14
  //#region \0rolldown/runtime.js
17
15
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
18
-
19
16
  //#endregion
20
17
  //#region src/utils/mapCodeToCodeWithSourcemap.ts
21
18
  async function mapCodeToCodeWithSourcemap(code) {
@@ -27,14 +24,14 @@ async function mapCodeToCodeWithSourcemap(code) {
27
24
  map: s.generateMap({ hires: true })
28
25
  };
29
26
  }
30
-
31
27
  //#endregion
32
28
  //#region src/plugins/pluginAddEntry.ts
33
29
  function getFirstHtmlEntryFile(entryFiles) {
34
30
  return entryFiles.find((file) => file.endsWith(".html"));
35
31
  }
36
32
  const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
37
- let devEntryPath = entryPath.startsWith("virtual:mf") ? "@id/" + entryPath : entryPath;
33
+ const getEntryPath = () => typeof entryPath === "function" ? entryPath() : entryPath;
34
+ let devEntryPath = "";
38
35
  let entryFiles = [];
39
36
  let htmlFilePath;
40
37
  let _command;
@@ -54,6 +51,8 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
54
51
  },
55
52
  configResolved(config) {
56
53
  viteConfig = config;
54
+ const resolvedEntryPath = getEntryPath();
55
+ devEntryPath = resolvedEntryPath.startsWith("virtual:mf") ? "@id/" + resolvedEntryPath : resolvedEntryPath;
57
56
  devEntryPath = config.base + devEntryPath.replace(/\\\\?/g, "/").replace(/.+?\:([/\\])[/\\]?/, "$1").replace(/^\//, "");
58
57
  },
59
58
  configureServer(server) {
@@ -95,7 +94,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
95
94
  const emitFileOptions = {
96
95
  name: entryName,
97
96
  type: "chunk",
98
- id: entryPath,
97
+ id: getEntryPath(),
99
98
  preserveSignature: "strict"
100
99
  };
101
100
  if (!hasHash) emitFileOptions.fileName = fileName;
@@ -141,12 +140,11 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry" }) => {
141
140
  },
142
141
  transform(code, id) {
143
142
  if (injectEntry() && entryFiles.some((file) => id.endsWith(file))) return mapCodeToCodeWithSourcemap(`
144
- import ${JSON.stringify(entryPath)};
143
+ import ${JSON.stringify(getEntryPath())};
145
144
  ` + code);
146
145
  }
147
146
  }];
148
147
  };
149
-
150
148
  //#endregion
151
149
  //#region src/plugins/pluginCheckAliasConflicts.ts
152
150
  /**
@@ -186,19 +184,23 @@ function checkAliasConflicts(options) {
186
184
  }
187
185
  };
188
186
  }
189
-
190
187
  //#endregion
191
188
  //#region src/plugins/pluginDevProxyModuleTopLevelAwait.ts
192
189
  /**
193
190
  * Solve the problem that dev mode dependency prebunding does not support top-level await syntax
194
191
  */
192
+ let walkPromise = null;
193
+ function loadWalk() {
194
+ walkPromise ||= import("estree-walker").then(({ walk }) => walk);
195
+ return walkPromise;
196
+ }
195
197
  function PluginDevProxyModuleTopLevelAwait() {
196
198
  const filterFunction = createFilter();
197
199
  const processedFlag = "/* already-processed-by-dev-proxy-module-top-level-await */";
198
200
  return {
199
201
  name: "dev-proxy-module-top-level-await",
200
202
  apply: "serve",
201
- transform(code, id) {
203
+ async transform(code, id) {
202
204
  if (code.includes(processedFlag)) return null;
203
205
  if (!code.includes("/*mf top-level-await placeholder replacement mf*/")) return null;
204
206
  if (!filterFunction(id)) return null;
@@ -209,7 +211,7 @@ function PluginDevProxyModuleTopLevelAwait() {
209
211
  throw new Error(`${id}: ${e}`);
210
212
  }
211
213
  const magicString = new MagicString(code);
212
- walk(ast, { enter(node) {
214
+ (await loadWalk())(ast, { enter(node) {
213
215
  if (node.type === "ExportNamedDeclaration" && node.specifiers) {
214
216
  const exportSpecifiers = node.specifiers.map((specifier) => specifier.exported.name);
215
217
  const proxyStatements = exportSpecifiers.map((name) => `
@@ -251,7 +253,6 @@ function PluginDevProxyModuleTopLevelAwait() {
251
253
  }
252
254
  };
253
255
  }
254
-
255
256
  //#endregion
256
257
  //#region src/plugins/pluginDts.ts
257
258
  const DEFAULT_DEV_OPTIONS = {
@@ -479,7 +480,6 @@ function pluginDts(options) {
479
480
  }
480
481
  }];
481
482
  }
482
-
483
483
  //#endregion
484
484
  //#region src/utils/normalizeModuleFederationOptions.ts
485
485
  function normalizeExposesItem(key, item) {
@@ -554,8 +554,7 @@ function normalizeShareItem(key, shareItem) {
554
554
  version = __require(path$1.join(removePathFromNpmPackage(key), "package.json")).version;
555
555
  } catch (e1) {
556
556
  try {
557
- const localPath = path$1.join(process.cwd(), "node_modules", removePathFromNpmPackage(key), "package.json");
558
- version = __require(localPath).version;
557
+ version = __require(path$1.join(process.cwd(), "node_modules", removePathFromNpmPackage(key), "package.json")).version;
559
558
  } catch (e2) {
560
559
  version = searchPackageVersion(key);
561
560
  if (!version) console.error(e1);
@@ -646,11 +645,11 @@ function normalizeModuleFederationOptions(options) {
646
645
  hostInitInjectLocation: options.hostInitInjectLocation || "html",
647
646
  bundleAllCSS: options.bundleAllCSS || false,
648
647
  moduleParseTimeout: options.moduleParseTimeout || 10,
648
+ moduleParseIdleTimeout: options.moduleParseIdleTimeout,
649
649
  varFilename: options.varFilename,
650
650
  target: options.target
651
651
  };
652
652
  }
653
-
654
653
  //#endregion
655
654
  //#region src/utils/packageNameUtils.ts
656
655
  /**
@@ -679,7 +678,6 @@ function packageNameDecode(encoded) {
679
678
  if (typeof encoded !== "string") throw new Error("A string encoded file name is required");
680
679
  return encoded.replace(/_mf_0_/g, "@").replace(/_mf_1_/g, "/").replace(/_mf_2_/g, "-").replace(/_mf_3_/g, ".");
681
680
  }
682
-
683
681
  //#endregion
684
682
  //#region src/utils/localSharedImportMap_temp.ts
685
683
  /**
@@ -696,7 +694,6 @@ function createFile(filePath, content) {
696
694
  mkdirSync(path.dirname(filePath), { recursive: true });
697
695
  writeFileSync(filePath, content);
698
696
  }
699
-
700
697
  //#endregion
701
698
  //#region src/utils/serializeRuntimeOptions.ts
702
699
  /**
@@ -744,7 +741,6 @@ function serializeRuntimeOptions(options) {
744
741
  for (const key in options) if (Object.prototype.hasOwnProperty.call(options, key)) topLevelProps.push(`${JSON.stringify(key)}: ${valueToCode(options[key])}`);
745
742
  return `{${topLevelProps.join(", ")}}`;
746
743
  }
747
-
748
744
  //#endregion
749
745
  //#region src/utils/VirtualModule.ts
750
746
  /**
@@ -754,14 +750,12 @@ function serializeRuntimeOptions(options) {
754
750
  */
755
751
  function initVirtualModuleInfrastructure(root, virtualModuleDir = "__mf__virtual") {
756
752
  const virtualPackagePath = join(join(root, "node_modules"), virtualModuleDir);
757
- if (!existsSync(virtualPackagePath)) {
758
- mkdirSync(virtualPackagePath, { recursive: true });
759
- writeFileSync(join(virtualPackagePath, "empty.js"), "");
760
- writeFileSync(join(virtualPackagePath, "package.json"), JSON.stringify({
761
- name: virtualModuleDir,
762
- main: "empty.js"
763
- }));
764
- }
753
+ mkdirSync(virtualPackagePath, { recursive: true });
754
+ writeFileSync(join(virtualPackagePath, "empty.js"), "");
755
+ writeFileSync(join(virtualPackagePath, "package.json"), JSON.stringify({
756
+ name: virtualModuleDir,
757
+ main: "empty.js"
758
+ }));
765
759
  }
766
760
  let rootDir;
767
761
  function findNodeModulesDir(root = process.cwd()) {
@@ -810,14 +804,12 @@ var VirtualModule = class {
810
804
  const nodeModulesDir = getNodeModulesDir();
811
805
  const { virtualModuleDir } = getNormalizeModuleFederationOptions();
812
806
  const virtualPackagePath = resolve(nodeModulesDir, virtualModuleDir);
813
- if (!existsSync(virtualPackagePath)) {
814
- mkdirSync(virtualPackagePath);
815
- writeFileSync(resolve(virtualPackagePath, "empty.js"), "");
816
- writeFileSync(resolve(virtualPackagePath, "package.json"), JSON.stringify({
817
- name: virtualModuleDir,
818
- main: "empty.js"
819
- }));
820
- }
807
+ mkdirSync(virtualPackagePath, { recursive: true });
808
+ writeFileSync(resolve(virtualPackagePath, "empty.js"), "");
809
+ writeFileSync(resolve(virtualPackagePath, "package.json"), JSON.stringify({
810
+ name: virtualModuleDir,
811
+ main: "empty.js"
812
+ }));
821
813
  }
822
814
  static findModule(tag, str = "") {
823
815
  if (!patternMap[tag]) patternMap[tag] = new RegExp(`(.*${packageNameEncode(tag)}(.+?)${packageNameEncode(tag)}.*)`);
@@ -848,7 +840,6 @@ var VirtualModule = class {
848
840
  writeFile(this.getPath(), code, function() {});
849
841
  }
850
842
  };
851
-
852
843
  //#endregion
853
844
  //#region src/virtualModules/virtualExposes.ts
854
845
  function getVirtualExposesId(options) {
@@ -874,7 +865,6 @@ function generateExposes(options) {
874
865
  }
875
866
  `;
876
867
  }
877
-
878
868
  //#endregion
879
869
  //#region src/virtualModules/virtualRuntimeInitStatus.ts
880
870
  const virtualRuntimeInitStatus = new VirtualModule("runtimeInit");
@@ -899,7 +889,6 @@ if (!globalThis[globalKey]) {
899
889
  ${exportStatement}
900
890
  `);
901
891
  }
902
-
903
892
  //#endregion
904
893
  //#region src/virtualModules/virtualRemotes.ts
905
894
  const cacheRemoteMap = {};
@@ -931,7 +920,6 @@ function generateRemotes(id, command, isRolldown) {
931
920
  ${exportLine}
932
921
  `;
933
922
  }
934
-
935
923
  //#endregion
936
924
  //#region src/virtualModules/virtualShared_preBuild.ts
937
925
  /**
@@ -995,7 +983,6 @@ function writeLoadShareModule(pkg, shareItem, command, isRolldown) {
995
983
  ${exportLine}
996
984
  `);
997
985
  }
998
-
999
986
  //#endregion
1000
987
  //#region src/virtualModules/virtualRemoteEntry.ts
1001
988
  let usedShares = /* @__PURE__ */ new Set();
@@ -1155,12 +1142,7 @@ function generateRemoteEntry(options, virtualExposesId = getVirtualExposesId(opt
1155
1142
  }
1156
1143
  `;
1157
1144
  }
1158
- /**
1159
- * Inject entry file, automatically init when used as host,
1160
- * and will not inject remoteEntry
1161
- */
1162
- const HOST_AUTO_INIT_TAG = "__H_A_I__";
1163
- const hostAutoInitModule = new VirtualModule("hostAutoInit", HOST_AUTO_INIT_TAG);
1145
+ const hostAutoInitModule = new VirtualModule("hostAutoInit", "__H_A_I__");
1164
1146
  function writeHostAutoInit(remoteEntryId = REMOTE_ENTRY_ID) {
1165
1147
  hostAutoInitModule.writeSync(`
1166
1148
  const remoteEntryPromise = import("${remoteEntryId}")
@@ -1178,7 +1160,6 @@ function getHostAutoInitImportId() {
1178
1160
  function getHostAutoInitPath() {
1179
1161
  return hostAutoInitModule.getPath();
1180
1162
  }
1181
-
1182
1163
  //#endregion
1183
1164
  //#region src/virtualModules/index.ts
1184
1165
  function initVirtualModules(command, remoteEntryId) {
@@ -1186,13 +1167,11 @@ function initVirtualModules(command, remoteEntryId) {
1186
1167
  writeHostAutoInit(remoteEntryId);
1187
1168
  writeRuntimeInitStatus(command);
1188
1169
  }
1189
-
1190
1170
  //#endregion
1191
1171
  //#region src/utils/bundleHelpers.ts
1192
1172
  function findRemoteEntryFile(filename, bundle) {
1193
1173
  for (const [_, fileData] of Object.entries(bundle)) if (filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "") === fileData.name || fileData.name === "remoteEntry") return fileData.fileName;
1194
1174
  }
1195
-
1196
1175
  //#endregion
1197
1176
  //#region src/utils/cssModuleHelpers.ts
1198
1177
  const ASSET_TYPES = ["js", "css"];
@@ -1313,7 +1292,6 @@ const buildFileToShareKeyMap = async (shareKeys, resolveFn) => {
1313
1292
  for (const resolution of resolutions) if (resolution?.file) fileToShareKey.set(resolution.file, resolution.shareKey);
1314
1293
  return fileToShareKey;
1315
1294
  };
1316
-
1317
1295
  //#endregion
1318
1296
  //#region src/utils/publicPath.ts
1319
1297
  /**
@@ -1329,7 +1307,6 @@ function resolvePublicPath(options, viteBase, originalBase) {
1329
1307
  if (viteBase) return viteBase.replace(/\/?$/, "/");
1330
1308
  return "auto";
1331
1309
  }
1332
-
1333
1310
  //#endregion
1334
1311
  //#region src/plugins/pluginMFManifest.ts
1335
1312
  const Manifest = () => {
@@ -1544,7 +1521,6 @@ const Manifest = () => {
1544
1521
  };
1545
1522
  }
1546
1523
  };
1547
-
1548
1524
  //#endregion
1549
1525
  //#region src/plugins/pluginModuleParseEnd.ts
1550
1526
  let _resolve, _parseTimeout;
@@ -1561,12 +1537,19 @@ function setParseTimeout(timeout) {
1561
1537
  _resolve(1);
1562
1538
  }, timeout * 1e3);
1563
1539
  }
1540
+ function resetIdleTimeout(timeout) {
1541
+ clearTimeout(_parseTimeout);
1542
+ _parseTimeout = setTimeout(() => {
1543
+ console.warn(`moduleParseIdleTimeout: no module activity for ${timeout}s, forcing resolve. Some shared/remote dependencies may be missing. Consider increasing moduleParseIdleTimeout.`);
1544
+ _resolve(1);
1545
+ }, timeout * 1e3);
1546
+ }
1564
1547
  let parsePromise = promise;
1565
1548
  let exposesParseEnd = false;
1566
1549
  const parseStartSet = /* @__PURE__ */ new Set();
1567
1550
  const parseEndSet = /* @__PURE__ */ new Set();
1568
1551
  function pluginModuleParseEnd_default(excludeFn, options) {
1569
- setParseTimeout(options.moduleParseTimeout);
1552
+ const idleTimeout = options.moduleParseIdleTimeout;
1570
1553
  return [
1571
1554
  {
1572
1555
  name: "_",
@@ -1579,6 +1562,10 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1579
1562
  enforce: "pre",
1580
1563
  name: "parseStart",
1581
1564
  apply: "build",
1565
+ buildStart() {
1566
+ if (idleTimeout) resetIdleTimeout(idleTimeout);
1567
+ else setParseTimeout(options.moduleParseTimeout);
1568
+ },
1582
1569
  load(id) {
1583
1570
  if (excludeFn(id)) return;
1584
1571
  parseStartSet.add(id);
@@ -1591,6 +1578,7 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1591
1578
  moduleParsed(module) {
1592
1579
  const id = module.id;
1593
1580
  if (id === options.virtualExposesId) exposesParseEnd = true;
1581
+ if (idleTimeout) resetIdleTimeout(idleTimeout);
1594
1582
  if (excludeFn(id)) return;
1595
1583
  parseEndSet.add(id);
1596
1584
  if (exposesParseEnd && parseStartSet.size === parseEndSet.size) _resolve(1);
@@ -1598,7 +1586,6 @@ function pluginModuleParseEnd_default(excludeFn, options) {
1598
1586
  }
1599
1587
  ];
1600
1588
  }
1601
-
1602
1589
  //#endregion
1603
1590
  //#region src/plugins/pluginProxyRemoteEntry.ts
1604
1591
  const filter = createFilter();
@@ -1664,7 +1651,6 @@ function pluginProxyRemoteEntry_default({ options, remoteEntryId, virtualExposes
1664
1651
  }
1665
1652
  };
1666
1653
  }
1667
-
1668
1654
  //#endregion
1669
1655
  //#region src/plugins/pluginProxyRemotes.ts
1670
1656
  createFilter();
@@ -1689,7 +1675,6 @@ function pluginProxyRemotes_default(options) {
1689
1675
  }
1690
1676
  };
1691
1677
  }
1692
-
1693
1678
  //#endregion
1694
1679
  //#region src/utils/PromiseStore.ts
1695
1680
  /**
@@ -1723,7 +1708,6 @@ var PromiseStore = class {
1723
1708
  return pendingPromise;
1724
1709
  }
1725
1710
  };
1726
-
1727
1711
  //#endregion
1728
1712
  //#region src/plugins/pluginProxySharedModule_preBuild.ts
1729
1713
  function proxySharedModule(options) {
@@ -1798,7 +1782,6 @@ function proxySharedModule(options) {
1798
1782
  }
1799
1783
  }];
1800
1784
  }
1801
-
1802
1785
  //#endregion
1803
1786
  //#region src/plugins/pluginVarRemoteEntry.ts
1804
1787
  const VarRemoteEntry = () => {
@@ -1879,7 +1862,6 @@ const VarRemoteEntry = () => {
1879
1862
  `;
1880
1863
  }
1881
1864
  };
1882
-
1883
1865
  //#endregion
1884
1866
  //#region src/utils/aliasToArrayPlugin.ts
1885
1867
  var aliasToArrayPlugin_default = {
@@ -1894,7 +1876,6 @@ var aliasToArrayPlugin_default = {
1894
1876
  }));
1895
1877
  }
1896
1878
  };
1897
-
1898
1879
  //#endregion
1899
1880
  //#region src/utils/normalizeOptimizeDeps.ts
1900
1881
  var normalizeOptimizeDeps_default = {
@@ -1910,7 +1891,6 @@ var normalizeOptimizeDeps_default = {
1910
1891
  if (!optimizeDeps.needsInterop) optimizeDeps.needsInterop = [];
1911
1892
  }
1912
1893
  };
1913
-
1914
1894
  //#endregion
1915
1895
  //#region src/index.ts
1916
1896
  /**
@@ -1982,7 +1962,7 @@ function federation(mfUserOptions) {
1982
1962
  }),
1983
1963
  ...addEntry({
1984
1964
  entryName: "hostInit",
1985
- entryPath: getHostAutoInitPath(),
1965
+ entryPath: () => getHostAutoInitPath(),
1986
1966
  inject: hostInitInjectLocation
1987
1967
  }),
1988
1968
  ...addEntry({
@@ -1999,6 +1979,7 @@ function federation(mfUserOptions) {
1999
1979
  return id.includes(getHostAutoInitImportId()) || id.includes(remoteEntryId) || id.includes(virtualExposesId) || id.includes(getLocalSharedImportMapPath());
2000
1980
  }, {
2001
1981
  moduleParseTimeout: options.moduleParseTimeout,
1982
+ moduleParseIdleTimeout: options.moduleParseIdleTimeout,
2002
1983
  virtualExposesId
2003
1984
  }),
2004
1985
  ...proxySharedModule({ shared }),
@@ -2015,7 +1996,7 @@ function federation(mfUserOptions) {
2015
1996
  const existingManualChunks = output.manualChunks;
2016
1997
  output.manualChunks = function(id) {
2017
1998
  if (id.includes(runtimeInitId)) return "runtimeInit";
2018
- if (id.includes(LOAD_SHARE_TAG)) {
1999
+ if (id.includes("__loadShare__")) {
2019
2000
  const match = id.match(/([^/\\]+__loadShare__[^/\\]+)/);
2020
2001
  return match ? match[1] : "loadShare";
2021
2002
  }
@@ -2028,7 +2009,7 @@ function federation(mfUserOptions) {
2028
2009
  },
2029
2010
  load(id) {
2030
2011
  if (id.startsWith("\0")) return;
2031
- if (id.includes(LOAD_SHARE_TAG) || id.includes(LOAD_REMOTE_TAG)) {
2012
+ if (id.includes("__loadShare__") || id.includes("__loadRemote__")) {
2032
2013
  let code = readFileSync(id, "utf-8");
2033
2014
  code = code.replace(/import\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
2034
2015
  code = code.replace(/export\s+\*\s+from\s+["'][^"']*__prebuild__[^"']*["']\s*;?/g, "");
@@ -2058,7 +2039,7 @@ function federation(mfUserOptions) {
2058
2039
  generateBundle(_, bundle) {
2059
2040
  for (const [fileName, chunk] of Object.entries(bundle)) {
2060
2041
  if (chunk.type !== "chunk") continue;
2061
- if (fileName.includes(LOAD_SHARE_TAG)) continue;
2042
+ if (fileName.includes("__loadShare__")) continue;
2062
2043
  let code = chunk.code;
2063
2044
  let m;
2064
2045
  const importedFromLoadShare = /* @__PURE__ */ new Set();
@@ -2088,7 +2069,7 @@ function federation(mfUserOptions) {
2088
2069
  const proxyChunks = /* @__PURE__ */ new Map();
2089
2070
  for (const [fileName, chunk] of Object.entries(bundle)) {
2090
2071
  if (chunk.type !== "chunk") continue;
2091
- if (fileName.includes(LOAD_SHARE_TAG) && fileName.includes("commonjs-proxy")) proxyChunks.set(fileName, {
2072
+ if (fileName.includes("__loadShare__") && fileName.includes("commonjs-proxy")) proxyChunks.set(fileName, {
2092
2073
  code: chunk.code,
2093
2074
  fileName
2094
2075
  });
@@ -2096,7 +2077,7 @@ function federation(mfUserOptions) {
2096
2077
  if (proxyChunks.size === 0) return;
2097
2078
  for (const [fileName, chunk] of Object.entries(bundle)) {
2098
2079
  if (chunk.type !== "chunk") continue;
2099
- if (fileName.includes(LOAD_SHARE_TAG)) continue;
2080
+ if (fileName.includes("__loadShare__")) continue;
2100
2081
  let code = chunk.code;
2101
2082
  let modified = false;
2102
2083
  for (const [proxyFileName, proxyInfo] of proxyChunks) {
@@ -2199,12 +2180,19 @@ function federation(mfUserOptions) {
2199
2180
  });
2200
2181
  config.build = defu(config.build || {}, { commonjsOptions: { strictRequires: "auto" } });
2201
2182
  const virtualDir = options.virtualModuleDir || "__mf__virtual";
2202
- config.optimizeDeps?.include?.push("@module-federation/runtime");
2203
- config.optimizeDeps?.include?.push(virtualDir);
2183
+ config.optimizeDeps ||= {};
2184
+ config.optimizeDeps.include ||= [];
2185
+ config.optimizeDeps.include.push("@module-federation/runtime");
2186
+ config.optimizeDeps.include.push(virtualDir);
2187
+ options.runtimePlugins.forEach((p) => {
2188
+ const pluginPath = typeof p === "string" ? p : p[0];
2189
+ if (pluginPath && !pluginPath.startsWith(".") && !pluginPath.startsWith("/") && !pluginPath.startsWith("\0") && !pluginPath.startsWith("virtual:")) config.optimizeDeps.include.push(pluginPath);
2190
+ });
2204
2191
  if (isRolldown) config.build = defu(config.build || {}, { target: "esnext" });
2205
2192
  else {
2206
- config.optimizeDeps?.needsInterop?.push(virtualDir);
2207
- config.optimizeDeps?.needsInterop?.push(getLocalSharedImportMapPath());
2193
+ config.optimizeDeps.needsInterop ||= [];
2194
+ config.optimizeDeps.needsInterop.push(virtualDir);
2195
+ config.optimizeDeps.needsInterop.push(getLocalSharedImportMapPath());
2208
2196
  }
2209
2197
  const resolvedTarget = options.target ?? (config.build?.ssr ? "node" : "web");
2210
2198
  if (!config.define) config.define = {};
@@ -2234,6 +2222,5 @@ function federation(mfUserOptions) {
2234
2222
  }] : []
2235
2223
  ];
2236
2224
  }
2237
-
2238
2225
  //#endregion
2239
- export { federation };
2226
+ export { federation };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -32,7 +32,7 @@
32
32
  "dev-nv": "pnpm clean && pnpm -filter 'examples-nuxt-vite-host' -filter 'examples-vite-vite-remote' run dev",
33
33
  "preview-vv": "pnpm clean && pnpm -filter 'examples-vite-vite*' --parallel run preview",
34
34
  "multi-example": "pnpm clean && pnpm --filter \"multi-example-*\" --parallel run start",
35
- "test": "vitest run src",
35
+ "test": "vitest run --dir src",
36
36
  "test:integration": "vitest run integration",
37
37
  "e2e": "playwright test",
38
38
  "changeset": "changeset",
@@ -58,6 +58,9 @@
58
58
  },
59
59
  "homepage": "https://github.com/module-federation/vite#readme",
60
60
  "packageManager": "pnpm@10.28.2",
61
+ "overrides": {
62
+ "koa": "3.1.2"
63
+ },
61
64
  "peerDependencies": {
62
65
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
63
66
  },
@@ -67,21 +70,21 @@
67
70
  "@module-federation/sdk": "^2.0.1",
68
71
  "@rollup/pluginutils": "^5.3.0",
69
72
  "defu": "^6.1.4",
70
- "estree-walker": "^2",
71
- "magic-string": "^0.30.11",
72
- "pathe": "^1.1.2"
73
+ "estree-walker": "^3.0.3",
74
+ "magic-string": "^0.30.21",
75
+ "pathe": "^2.0.3"
73
76
  },
74
77
  "devDependencies": {
75
- "@changesets/cli": "^2.27.9",
76
- "@playwright/test": "^1.47.2",
77
- "@types/node": "^22.7.4",
78
+ "@changesets/cli": "^2.30.0",
79
+ "@playwright/test": "^1.58.2",
80
+ "@types/node": "^25.3.3",
78
81
  "cjs-dep": "workspace:*",
79
- "husky": "^8.0.3",
80
- "mime-types": "^2.1.35",
81
- "oxfmt": "^0.35.0",
82
+ "husky": "^9.1.7",
83
+ "mime-types": "^3.0.2",
84
+ "oxfmt": "^0.36.0",
82
85
  "rollup": "^4.47.1",
83
- "tsdown": "^0.20.3",
84
- "vite": "^5.4.3",
85
- "vitest": "^2.1.1"
86
+ "tsdown": "^0.21.0",
87
+ "vite": "^7.3.1",
88
+ "vitest": "^4.0.18"
86
89
  }
87
- }
90
+ }