@module-federation/vite 1.16.3 → 1.16.4

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
@@ -861,12 +861,25 @@ function getNamedExportsViaRegex(source, filePath, visited) {
861
861
  const names = /* @__PURE__ */ new Set();
862
862
  visited = visited || /* @__PURE__ */ new Set();
863
863
  if (filePath) visited.add(filePath);
864
- const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
864
+ const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+|enum\\s+|namespace\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
865
865
  let match;
866
866
  while ((match = declRegex.exec(source)) !== null) {
867
867
  const name = match[1];
868
868
  if (isValidEsmExportName(name)) names.add(name);
869
869
  }
870
+ const destructureRegex = /export\s+(?:const|let|var)\s+(\{[^}]*\}|\[[^\]]*\])\s*=/g;
871
+ const bindingNameRegex = new RegExp(`^(${JS_IDENTIFIER_PATTERN})`, "u");
872
+ while ((match = destructureRegex.exec(source)) !== null) {
873
+ const inner = match[1].slice(1, -1);
874
+ for (const part of inner.split(",")) {
875
+ let token = part.split("=")[0].trim();
876
+ if (token.startsWith("...")) token = token.slice(3).trim();
877
+ if (!token) continue;
878
+ if (token.includes(":")) token = token.slice(token.indexOf(":") + 1).trim();
879
+ const bindingMatch = token.match(bindingNameRegex);
880
+ if (bindingMatch && isValidEsmExportName(bindingMatch[1])) names.add(bindingMatch[1]);
881
+ }
882
+ }
870
883
  const listRegex = /export\s*\{([^}]+)\}/g;
871
884
  const typeOnlySpecifierRegex = new RegExp(`^type\\s+${JS_IDENTIFIER_PATTERN}(?:\\s+as\\s+${JS_IDENTIFIER_PATTERN})?$`, "u");
872
885
  const exportSpecifierRegex = new RegExp(`(?:\\S+\\s+as\\s+)?(${JS_IDENTIFIER_PATTERN})$`, "u");
@@ -1821,7 +1834,8 @@ function patchHashEntryFileNames(config, entryName, fileName) {
1821
1834
  }
1822
1835
  const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClientInjected, skipTransformFor = [] }) => {
1823
1836
  const DEV_HTML_PROXY_PREFIX = "virtual:mf-html-entry-proxy?";
1824
- const ENTRY_BOOTSTRAP_QUERY = "?mf-entry-bootstrap";
1837
+ const ENTRY_BOOTSTRAP_PARAM = "mf-entry-bootstrap";
1838
+ const ENTRY_BOOTSTRAP_QUERY = `?${ENTRY_BOOTSTRAP_PARAM}`;
1825
1839
  const waitsForInit = entryName === "hostInit";
1826
1840
  const getEntryPath = () => typeof entryPath === "function" ? entryPath() : entryPath;
1827
1841
  let devEntryPath = "";
@@ -1839,6 +1853,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
1839
1853
  function isSvelteKitServerModule(id) {
1840
1854
  return require_packageUtils.hasPackageDependency("@sveltejs/kit") && (id.includes(".svelte-kit/generated/") || id.includes("/@sveltejs/kit/src/runtime/server/"));
1841
1855
  }
1856
+ function hasEntryBootstrapParam(id) {
1857
+ return id.includes(ENTRY_BOOTSTRAP_PARAM) || decodeURIComponent(id).includes(ENTRY_BOOTSTRAP_PARAM);
1858
+ }
1842
1859
  function rewriteSvelteKitInlineStart(html, initPath) {
1843
1860
  return html.replace(/<script>([\s\S]*?)<\/script>/gi, (scriptTag, body) => {
1844
1861
  if (!body.includes("kit.start(app, element);") || !body.includes("Promise.all([")) return scriptTag;
@@ -2148,7 +2165,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2148
2165
  transform(code, id) {
2149
2166
  if (skipSvelteKitSsrBuild()) return;
2150
2167
  if (isSvelteKitServerModule(id)) return;
2151
- if (id.includes(ENTRY_BOOTSTRAP_QUERY)) return;
2168
+ if (hasEntryBootstrapParam(id)) return;
2152
2169
  if (normalizeModuleId(id).endsWith(".html")) return;
2153
2170
  if (skipTransformIds.has(resolveProjectId(id))) return;
2154
2171
  const transformCtx = this;
@@ -2176,7 +2193,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2176
2193
  return mapCodeToCodeWithSourcemap(code.replace("vueApp.mount(vueAppRootContainer);", `${injection}vueApp.mount(vueAppRootContainer);`));
2177
2194
  }
2178
2195
  const isHydrationEntryFallback = inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs.existsSync(htmlFilePath)) && !clientInjected && !id.includes("node_modules") && (id.startsWith("\0") || /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id)) && /hydrateRoot|createRoot|ReactDOM\.render/.test(code);
2179
- const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs.existsSync(htmlFilePath)) && !clientInjected && !id.includes("node_modules/.vite") && /(?:^|\/)nuxt\/dist\/app\/entry\.async\.js(?:\?|$)/.test(id) && code.includes("entry();");
2196
+ const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs.existsSync(htmlFilePath)) && !clientInjected && !hasEntryBootstrapParam(id) && !id.includes("node_modules/.vite") && /(?:^|\/)nuxt\/dist\/app\/entry\.async\.js(?:\?|$)/.test(id) && code.includes("entry();");
2180
2197
  if (injectEntry() && entryFiles.some((file) => resolveProjectId(id) === file) || _command === "serve" && inject === "html" && !isVinext && !clientInjected && !id.startsWith("\0") && !id.includes("node_modules") && /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id) || isHydrationEntryFallback || isNuxtClientEntryFallback) {
2181
2198
  clientInjected = true;
2182
2199
  if (!waitsForInit || _command === "serve" && inject === "entry" && isHydrationEntryFallback) return mapCodeToCodeWithSourcemap(`import ${JSON.stringify(getEntryPath())};\n` + code);
package/lib/index.mjs CHANGED
@@ -860,12 +860,25 @@ function getNamedExportsViaRegex(source, filePath, visited) {
860
860
  const names = /* @__PURE__ */ new Set();
861
861
  visited = visited || /* @__PURE__ */ new Set();
862
862
  if (filePath) visited.add(filePath);
863
- const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
863
+ const declRegex = new RegExp(`export\\s+(?:async\\s+)?(?:function(?:\\*\\s*|\\s+\\*?\\s*)|const\\s+|let\\s+|var\\s+|class\\s+|enum\\s+|namespace\\s+)(${JS_IDENTIFIER_PATTERN})`, "gu");
864
864
  let match;
865
865
  while ((match = declRegex.exec(source)) !== null) {
866
866
  const name = match[1];
867
867
  if (isValidEsmExportName(name)) names.add(name);
868
868
  }
869
+ const destructureRegex = /export\s+(?:const|let|var)\s+(\{[^}]*\}|\[[^\]]*\])\s*=/g;
870
+ const bindingNameRegex = new RegExp(`^(${JS_IDENTIFIER_PATTERN})`, "u");
871
+ while ((match = destructureRegex.exec(source)) !== null) {
872
+ const inner = match[1].slice(1, -1);
873
+ for (const part of inner.split(",")) {
874
+ let token = part.split("=")[0].trim();
875
+ if (token.startsWith("...")) token = token.slice(3).trim();
876
+ if (!token) continue;
877
+ if (token.includes(":")) token = token.slice(token.indexOf(":") + 1).trim();
878
+ const bindingMatch = token.match(bindingNameRegex);
879
+ if (bindingMatch && isValidEsmExportName(bindingMatch[1])) names.add(bindingMatch[1]);
880
+ }
881
+ }
869
882
  const listRegex = /export\s*\{([^}]+)\}/g;
870
883
  const typeOnlySpecifierRegex = new RegExp(`^type\\s+${JS_IDENTIFIER_PATTERN}(?:\\s+as\\s+${JS_IDENTIFIER_PATTERN})?$`, "u");
871
884
  const exportSpecifierRegex = new RegExp(`(?:\\S+\\s+as\\s+)?(${JS_IDENTIFIER_PATTERN})$`, "u");
@@ -1820,7 +1833,8 @@ function patchHashEntryFileNames(config, entryName, fileName) {
1820
1833
  }
1821
1834
  const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClientInjected, skipTransformFor = [] }) => {
1822
1835
  const DEV_HTML_PROXY_PREFIX = "virtual:mf-html-entry-proxy?";
1823
- const ENTRY_BOOTSTRAP_QUERY = "?mf-entry-bootstrap";
1836
+ const ENTRY_BOOTSTRAP_PARAM = "mf-entry-bootstrap";
1837
+ const ENTRY_BOOTSTRAP_QUERY = `?${ENTRY_BOOTSTRAP_PARAM}`;
1824
1838
  const waitsForInit = entryName === "hostInit";
1825
1839
  const getEntryPath = () => typeof entryPath === "function" ? entryPath() : entryPath;
1826
1840
  let devEntryPath = "";
@@ -1838,6 +1852,9 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
1838
1852
  function isSvelteKitServerModule(id) {
1839
1853
  return hasPackageDependency("@sveltejs/kit") && (id.includes(".svelte-kit/generated/") || id.includes("/@sveltejs/kit/src/runtime/server/"));
1840
1854
  }
1855
+ function hasEntryBootstrapParam(id) {
1856
+ return id.includes(ENTRY_BOOTSTRAP_PARAM) || decodeURIComponent(id).includes(ENTRY_BOOTSTRAP_PARAM);
1857
+ }
1841
1858
  function rewriteSvelteKitInlineStart(html, initPath) {
1842
1859
  return html.replace(/<script>([\s\S]*?)<\/script>/gi, (scriptTag, body) => {
1843
1860
  if (!body.includes("kit.start(app, element);") || !body.includes("Promise.all([")) return scriptTag;
@@ -2147,7 +2164,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2147
2164
  transform(code, id) {
2148
2165
  if (skipSvelteKitSsrBuild()) return;
2149
2166
  if (isSvelteKitServerModule(id)) return;
2150
- if (id.includes(ENTRY_BOOTSTRAP_QUERY)) return;
2167
+ if (hasEntryBootstrapParam(id)) return;
2151
2168
  if (normalizeModuleId(id).endsWith(".html")) return;
2152
2169
  if (skipTransformIds.has(resolveProjectId(id))) return;
2153
2170
  const transformCtx = this;
@@ -2175,7 +2192,7 @@ const addEntry = ({ entryName, entryPath, fileName, inject = "entry", forceClien
2175
2192
  return mapCodeToCodeWithSourcemap(code.replace("vueApp.mount(vueAppRootContainer);", `${injection}vueApp.mount(vueAppRootContainer);`));
2176
2193
  }
2177
2194
  const isHydrationEntryFallback = inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !id.includes("node_modules") && (id.startsWith("\0") || /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id)) && /hydrateRoot|createRoot|ReactDOM\.render/.test(code);
2178
- const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !id.includes("node_modules/.vite") && /(?:^|\/)nuxt\/dist\/app\/entry\.async\.js(?:\?|$)/.test(id) && code.includes("entry();");
2195
+ const isNuxtClientEntryFallback = _command === "serve" && inject === "entry" && entryFiles.length === 0 && (!htmlFilePath || !fs$1.existsSync(htmlFilePath)) && !clientInjected && !hasEntryBootstrapParam(id) && !id.includes("node_modules/.vite") && /(?:^|\/)nuxt\/dist\/app\/entry\.async\.js(?:\?|$)/.test(id) && code.includes("entry();");
2179
2196
  if (injectEntry() && entryFiles.some((file) => resolveProjectId(id) === file) || _command === "serve" && inject === "html" && !isVinext && !clientInjected && !id.startsWith("\0") && !id.includes("node_modules") && /\.(js|ts|mjs|vue|jsx|tsx)(\?|$)/.test(id) || isHydrationEntryFallback || isNuxtClientEntryFallback) {
2180
2197
  clientInjected = true;
2181
2198
  if (!waitsForInit || _command === "serve" && inject === "entry" && isHydrationEntryFallback) return mapCodeToCodeWithSourcemap(`import ${JSON.stringify(getEntryPath())};\n` + code);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.16.3",
3
+ "version": "1.16.4",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",
@@ -80,7 +80,7 @@
80
80
  "@module-federation/dts-plugin": "2.5.1",
81
81
  "@module-federation/runtime": "2.5.1",
82
82
  "@module-federation/sdk": "2.5.1",
83
- "es-module-lexer": "2.0.0",
83
+ "es-module-lexer": "2.1.0",
84
84
  "estree-walker": "3.0.3",
85
85
  "pathe": "2.0.3"
86
86
  },