@module-federation/vite 1.12.2 → 1.12.3

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
@@ -1206,6 +1206,20 @@ function initVirtualModules(command, remoteEntryId) {
1206
1206
  }
1207
1207
  //#endregion
1208
1208
  //#region src/utils/bundleHelpers.ts
1209
+ /**
1210
+ * Resolve the local alias for a non-inlineable proxy binding.
1211
+ * If Rollup's deconflict renamed the alias but didn't update references
1212
+ * in the code body, fall back to proxyLocal so they stay in sync.
1213
+ */
1214
+ function resolveProxyAlias(binding, proxyLocal, code, fullImport) {
1215
+ const codeWithoutImport = code.replace(fullImport, "");
1216
+ const escapedLocal = binding.local.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1217
+ const localUsedInCode = new RegExp(`\\b${escapedLocal}\\b`).test(codeWithoutImport);
1218
+ return {
1219
+ imported: binding.imported,
1220
+ local: localUsedInCode ? binding.local : proxyLocal
1221
+ };
1222
+ }
1209
1223
  function findRemoteEntryFile(filename, bundle) {
1210
1224
  for (const [_, fileData] of Object.entries(bundle)) if (filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "") === fileData.name || fileData.name === "remoteEntry") return fileData.fileName;
1211
1225
  }
@@ -2165,13 +2179,14 @@ function federation(mfUserOptions) {
2165
2179
  local: b.local,
2166
2180
  funcBody: renamedFunc
2167
2181
  });
2168
- } else nonInlineable.push(b);
2182
+ } else nonInlineable.push(resolveProxyAlias(b, proxyLocal, code, fullImport));
2169
2183
  }
2170
- if (inlineable.length === 0) continue;
2184
+ const hasRenamedAlias = nonInlineable.some((b) => bindings.find((ob) => ob.imported === b.imported)?.local !== b.local);
2185
+ if (inlineable.length === 0 && !hasRenamedAlias) continue;
2171
2186
  let replacement = "";
2172
2187
  if (nonInlineable.length > 0) replacement = `import{${nonInlineable.map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`).join(",")}}from"${importMatch[2]}";`;
2173
2188
  replacement += inlineable.map((f) => f.funcBody).join("");
2174
- code = code.replace(fullImport, replacement);
2189
+ code = code.replace(fullImport, () => replacement);
2175
2190
  modified = true;
2176
2191
  }
2177
2192
  if (modified) chunk.code = code;
package/lib/index.mjs CHANGED
@@ -1184,6 +1184,20 @@ function initVirtualModules(command, remoteEntryId) {
1184
1184
  }
1185
1185
  //#endregion
1186
1186
  //#region src/utils/bundleHelpers.ts
1187
+ /**
1188
+ * Resolve the local alias for a non-inlineable proxy binding.
1189
+ * If Rollup's deconflict renamed the alias but didn't update references
1190
+ * in the code body, fall back to proxyLocal so they stay in sync.
1191
+ */
1192
+ function resolveProxyAlias(binding, proxyLocal, code, fullImport) {
1193
+ const codeWithoutImport = code.replace(fullImport, "");
1194
+ const escapedLocal = binding.local.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1195
+ const localUsedInCode = new RegExp(`\\b${escapedLocal}\\b`).test(codeWithoutImport);
1196
+ return {
1197
+ imported: binding.imported,
1198
+ local: localUsedInCode ? binding.local : proxyLocal
1199
+ };
1200
+ }
1187
1201
  function findRemoteEntryFile(filename, bundle) {
1188
1202
  for (const [_, fileData] of Object.entries(bundle)) if (filename.replace(/[\[\]]/g, "_").replace(/\.[^/.]+$/, "") === fileData.name || fileData.name === "remoteEntry") return fileData.fileName;
1189
1203
  }
@@ -2143,13 +2157,14 @@ function federation(mfUserOptions) {
2143
2157
  local: b.local,
2144
2158
  funcBody: renamedFunc
2145
2159
  });
2146
- } else nonInlineable.push(b);
2160
+ } else nonInlineable.push(resolveProxyAlias(b, proxyLocal, code, fullImport));
2147
2161
  }
2148
- if (inlineable.length === 0) continue;
2162
+ const hasRenamedAlias = nonInlineable.some((b) => bindings.find((ob) => ob.imported === b.imported)?.local !== b.local);
2163
+ if (inlineable.length === 0 && !hasRenamedAlias) continue;
2149
2164
  let replacement = "";
2150
2165
  if (nonInlineable.length > 0) replacement = `import{${nonInlineable.map((b) => b.imported === b.local ? b.imported : `${b.imported} as ${b.local}`).join(",")}}from"${importMatch[2]}";`;
2151
2166
  replacement += inlineable.map((f) => f.funcBody).join("");
2152
- code = code.replace(fullImport, replacement);
2167
+ code = code.replace(fullImport, () => replacement);
2153
2168
  modified = true;
2154
2169
  }
2155
2170
  if (modified) chunk.code = code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.12.2",
3
+ "version": "1.12.3",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "import": "./lib/index.mjs",
16
16
  "require": "./lib/index.cjs"
17
- }
17
+ },
18
+ "./package.json": "./package.json"
18
19
  },
19
20
  "files": [
20
21
  "lib/**/*"
@@ -65,9 +66,9 @@
65
66
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
66
67
  },
67
68
  "dependencies": {
68
- "@module-federation/dts-plugin": "^2.0.1",
69
- "@module-federation/runtime": "^2.0.1",
70
- "@module-federation/sdk": "^2.0.1",
69
+ "@module-federation/dts-plugin": "2.0.1",
70
+ "@module-federation/runtime": "2.0.1",
71
+ "@module-federation/sdk": "2.0.1",
71
72
  "@rollup/pluginutils": "^5.3.0",
72
73
  "defu": "^6.1.4",
73
74
  "estree-walker": "^3.0.3",