@module-federation/vite 1.16.10 → 1.16.11

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 +75 -11
  2. package/package.json +5 -5
package/lib/index.js CHANGED
@@ -2221,6 +2221,12 @@ function getFirstHtmlEntryFile(entryFiles) {
2221
2221
  function stripQueryAndHash(file) {
2222
2222
  return file.split(/[?#]/)[0];
2223
2223
  }
2224
+ function resolveDevHashEntryFileName(fileName) {
2225
+ if (!fileName.includes("[hash")) return fileName;
2226
+ const normalized = fileName.replace(/(?:[._-]?\[hash(?::\d+)?\])/g, "");
2227
+ const baseName = path$1.basename(normalized);
2228
+ return path$1.extname(baseName) ? normalized : `${normalized}.js`;
2229
+ }
2224
2230
  function getBuildInput(config) {
2225
2231
  return config.build?.rollupOptions?.input ?? config.build?.rolldownOptions?.input;
2226
2232
  }
@@ -2444,6 +2450,8 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2444
2450
  next();
2445
2451
  return;
2446
2452
  }
2453
+ const devFileName = resolveDevHashEntryFileName(fileName);
2454
+ if (devFileName !== fileName && req.url?.startsWith((viteConfig.base + devFileName).replace(/^\/?/, "/"))) req.url = req.url.replace(devFileName, fileName);
2447
2455
  if (req.url && req.url.startsWith((viteConfig.base + fileName).replace(/^\/?/, "/"))) req.url = devEntryPath;
2448
2456
  next();
2449
2457
  });
@@ -3349,7 +3357,13 @@ function rewriteSystemProxyConsumers(code, systemProxyInfo) {
3349
3357
  return nextCode;
3350
3358
  }
3351
3359
  function findRemoteEntryFile(filename, bundle) {
3352
- for (const [_, fileData] of Object.entries(bundle)) if (filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "") === fileData.name || fileData.name === "remoteEntry") return fileData.fileName;
3360
+ const strippedName = filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "");
3361
+ let fallback;
3362
+ for (const fileData of Object.values(bundle)) {
3363
+ if (fileData.fileName === filename) return fileData.fileName;
3364
+ if (fallback === void 0 && (strippedName === fileData.name || fileData.name === "remoteEntry")) fallback = fileData.fileName;
3365
+ }
3366
+ return fallback;
3353
3367
  }
3354
3368
  //#endregion
3355
3369
  //#region src/utils/cssModuleHelpers.ts
@@ -3699,13 +3713,13 @@ const Manifest = () => {
3699
3713
  },
3700
3714
  configureServer(server) {
3701
3715
  server.middlewares.use((req, res, next) => {
3702
- if (!mfManifestName) {
3716
+ const devRemoteEntryFile = resolveDevRemoteEntryFileName(filename);
3717
+ if (devRemoteEntryFile !== filename && Object.keys(mfOptions.exposes).length > 0 && req.url?.startsWith((viteConfig.base + devRemoteEntryFile).replace(/^\/?/, "/"))) {
3718
+ req.url = req.url.replace(devRemoteEntryFile, filename);
3703
3719
  next();
3704
3720
  return;
3705
3721
  }
3706
- const devRemoteEntryFile = resolveDevRemoteEntryFileName(filename);
3707
- if (devRemoteEntryFile !== filename && req.url?.startsWith((viteConfig.base + devRemoteEntryFile).replace(/^\/?/, "/"))) {
3708
- req.url = req.url.replace(devRemoteEntryFile, filename);
3722
+ if (!mfManifestName) {
3709
3723
  next();
3710
3724
  return;
3711
3725
  }
@@ -4482,7 +4496,6 @@ function proxySharedModule(options) {
4482
4496
  //#endregion
4483
4497
  //#region src/plugins/pluginRemoteNamedExports.ts
4484
4498
  const JS_EXTENSIONS_RE = /\.(?:[mc]?[jt]sx?|vue|svelte)(?:\?|$)/;
4485
- const REGEX_FALLBACK_EXTENSIONS_RE = /\.(?:[mc]?[jt]sx?)(?:\?|$)/;
4486
4499
  function isAstNode(value) {
4487
4500
  return !!value && typeof value === "object" && typeof value.type === "string";
4488
4501
  }
@@ -4679,10 +4692,12 @@ async function collectFromAST(ast, code, isRemoteImport) {
4679
4692
  }
4680
4693
  function collectFromRegex(code, isRemoteImport) {
4681
4694
  const result = [];
4695
+ const codePositions = createCodePositionMap(code);
4682
4696
  const importAttributes = String.raw`(?:\s+(?:with|assert)\s+\{[^;]*\})?`;
4683
4697
  const staticRe = new RegExp(String.raw`^\s*import\s+([\s\S]*?)\s+from\s+(['"])([^'"]+)\2${importAttributes}\s*;?`, "gm");
4684
4698
  for (const match of code.matchAll(staticRe)) {
4685
4699
  const [full, specifiersPartRaw, , source] = match;
4700
+ if (!codePositions[match.index]) continue;
4686
4701
  if (!isRemoteImport(source)) continue;
4687
4702
  const specifiersPart = specifiersPartRaw.trim();
4688
4703
  if (/^type\s/.test(specifiersPart)) continue;
@@ -4715,6 +4730,7 @@ function collectFromRegex(code, isRemoteImport) {
4715
4730
  const reexportRe = new RegExp(String.raw`^\s*export\s+\{([\s\S]*?)\}\s+from\s+(['"])([^'"]+)\2${importAttributes}\s*;?`, "gm");
4716
4731
  for (const match of code.matchAll(reexportRe)) {
4717
4732
  const [full, specifiersRaw, , source] = match;
4733
+ if (!codePositions[match.index]) continue;
4718
4734
  if (!isRemoteImport(source)) continue;
4719
4735
  const specifiers = parseNamedSpecifiers(specifiersRaw, "export");
4720
4736
  if (specifiers.length === 0) continue;
@@ -4729,6 +4745,7 @@ function collectFromRegex(code, isRemoteImport) {
4729
4745
  const exportAllRe = new RegExp(String.raw`^\s*export\s+\*\s+from\s+(['"])([^'"]+)\1${importAttributes}\s*;?`, "gm");
4730
4746
  for (const match of code.matchAll(exportAllRe)) {
4731
4747
  const [full, , source] = match;
4748
+ if (!codePositions[match.index]) continue;
4732
4749
  if (!isRemoteImport(source)) continue;
4733
4750
  result.push({
4734
4751
  kind: "export-all",
@@ -4739,6 +4756,7 @@ function collectFromRegex(code, isRemoteImport) {
4739
4756
  }
4740
4757
  for (const match of code.matchAll(/import\(\s*(?:\/\*[\s\S]*?\*\/\s*)?(['"])([^'"]+)\1\s*\)/g)) {
4741
4758
  const [full, , source] = match;
4759
+ if (!codePositions[match.index]) continue;
4742
4760
  if (!isRemoteImport(source)) continue;
4743
4761
  result.push({
4744
4762
  kind: "dynamic",
@@ -4749,6 +4767,50 @@ function collectFromRegex(code, isRemoteImport) {
4749
4767
  }
4750
4768
  return result.length > 0 ? result : void 0;
4751
4769
  }
4770
+ function createCodePositionMap(code) {
4771
+ const positions = Array(code.length).fill(true);
4772
+ function mask(start, end) {
4773
+ for (let i = start; i < end; i++) positions[i] = false;
4774
+ }
4775
+ for (let i = 0; i < code.length;) {
4776
+ const char = code[i];
4777
+ const next = code[i + 1];
4778
+ if (char === "/" && next === "/") {
4779
+ const start = i;
4780
+ i += 2;
4781
+ while (i < code.length && code[i] !== "\n" && code[i] !== "\r") i++;
4782
+ mask(start, i);
4783
+ continue;
4784
+ }
4785
+ if (char === "/" && next === "*") {
4786
+ const start = i;
4787
+ i += 2;
4788
+ while (i < code.length && !(code[i] === "*" && code[i + 1] === "/")) i++;
4789
+ i = Math.min(code.length, i + 2);
4790
+ mask(start, i);
4791
+ continue;
4792
+ }
4793
+ if (char === "\"" || char === "'" || char === "`") {
4794
+ const quote = char;
4795
+ const start = i++;
4796
+ while (i < code.length) {
4797
+ if (code[i] === "\\") {
4798
+ i += 2;
4799
+ continue;
4800
+ }
4801
+ if (code[i] === quote) {
4802
+ i++;
4803
+ break;
4804
+ }
4805
+ i++;
4806
+ }
4807
+ mask(start, i);
4808
+ continue;
4809
+ }
4810
+ i++;
4811
+ }
4812
+ return positions;
4813
+ }
4752
4814
  function pluginRemoteNamedExports(options) {
4753
4815
  const remoteNames = Object.keys(options.remotes);
4754
4816
  const isNodeModulesId = (id) => id.includes("/node_modules/") || id.includes("\\node_modules\\");
@@ -4775,7 +4837,6 @@ function pluginRemoteNamedExports(options) {
4775
4837
  if ((id.includes(".vue") || id.includes(".svelte")) && /^\s*</.test(code)) return;
4776
4838
  imports = collectFromRegex(code, matchesRemoteImport);
4777
4839
  }
4778
- if ((!imports || imports.length === 0) && REGEX_FALLBACK_EXTENSIONS_RE.test(id)) imports = collectFromRegex(code, matchesRemoteImport);
4779
4840
  if (!imports) return;
4780
4841
  return applyRewrites(code, imports, id);
4781
4842
  }
@@ -5180,18 +5241,21 @@ function normalizeVinextRscPreloadHints(code) {
5180
5241
  }
5181
5242
  function ignoreFederationGeneratedFiles(config, options) {
5182
5243
  config.server ??= {};
5183
- config.server.watch ??= {};
5244
+ const watch = config.server.watch;
5245
+ if (watch === false || watch === null) return;
5246
+ const watchOptions = watch === true || watch === void 0 ? {} : watch;
5247
+ config.server.watch = watchOptions;
5184
5248
  const federationIgnore = (file) => shouldIgnoreFile(file, options);
5185
- const ignored = config.server.watch.ignored;
5249
+ const ignored = watchOptions.ignored;
5186
5250
  if (!ignored) {
5187
- config.server.watch.ignored = federationIgnore;
5251
+ watchOptions.ignored = federationIgnore;
5188
5252
  return;
5189
5253
  }
5190
5254
  if (Array.isArray(ignored)) {
5191
5255
  ignored.push(federationIgnore);
5192
5256
  return;
5193
5257
  }
5194
- config.server.watch.ignored = [ignored, federationIgnore];
5258
+ watchOptions.ignored = [ignored, federationIgnore];
5195
5259
  }
5196
5260
  function isSharedResolverInternalImporter(importer) {
5197
5261
  return !!importer && (importer.includes("__loadShare__") || importer.includes("__prebuild__"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.16.10",
3
+ "version": "1.16.11",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -70,9 +70,9 @@
70
70
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
71
71
  },
72
72
  "dependencies": {
73
- "@module-federation/dts-plugin": "2.5.1",
74
- "@module-federation/runtime": "2.5.1",
75
- "@module-federation/sdk": "2.5.1"
73
+ "@module-federation/dts-plugin": "2.6.0",
74
+ "@module-federation/runtime": "2.6.0",
75
+ "@module-federation/sdk": "2.6.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@playwright/test": "1.58.2",
@@ -83,7 +83,7 @@
83
83
  "rollup": "4.47.1",
84
84
  "tsdown": "0.21.0",
85
85
  "typescript": "5.9.3",
86
- "vite": "8.0.10",
86
+ "vite": "8.1.0",
87
87
  "vitest": "4.0.18"
88
88
  }
89
89
  }