@module-federation/vite 1.21.3 → 1.21.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.
@@ -1,5 +1,5 @@
1
1
  import { n as normalizePathForImport } from "./buildPaths-BkaQHrd2.js";
2
- import { _ as mfError, g as createModuleFederationError, l as hasPackageDependency, p as resolveImportPath } from "./dtsConstants-CScOzmdO.js";
2
+ import { _ as mfError, g as createModuleFederationError, l as hasPackageDependency, p as resolveImportPath } from "./dtsConstants-BsaLBaaK.js";
3
3
  import fs from "fs";
4
4
  import * as path$1 from "node:path";
5
5
  import os from "os";
@@ -0,0 +1,198 @@
1
+ //#region src/utils/pathNormalization.ts
2
+ const COMMON_SHARED_SUBPATHS = {
3
+ react: [
4
+ "react/jsx-runtime",
5
+ "react/jsx-dev-runtime",
6
+ "react/compiler-runtime"
7
+ ],
8
+ "react-dom": ["react-dom/client", "react-dom/profiling"],
9
+ "solid-js": [
10
+ "solid-js/web",
11
+ "solid-js/store",
12
+ "solid-js/html",
13
+ "solid-js/h",
14
+ "solid-js/jsx-runtime",
15
+ "solid-js/jsx-dev-runtime"
16
+ ],
17
+ zustand: [
18
+ "zustand/vanilla",
19
+ "zustand/react",
20
+ "zustand/middleware",
21
+ "zustand/shallow"
22
+ ]
23
+ };
24
+ const VITE_DEFAULT_ASSET_TYPES = [
25
+ "apng",
26
+ "bmp",
27
+ "png",
28
+ "jpe?g",
29
+ "jfif",
30
+ "pjpeg",
31
+ "pjp",
32
+ "gif",
33
+ "svg",
34
+ "ico",
35
+ "webp",
36
+ "avif",
37
+ "cur",
38
+ "jxl",
39
+ "mp4",
40
+ "webm",
41
+ "ogg",
42
+ "mp3",
43
+ "wav",
44
+ "flac",
45
+ "aac",
46
+ "opus",
47
+ "mov",
48
+ "m4a",
49
+ "vtt",
50
+ "woff2?",
51
+ "eot",
52
+ "ttf",
53
+ "otf",
54
+ "webmanifest",
55
+ "pdf",
56
+ "txt"
57
+ ];
58
+ const ASSET_LIKE_IMPORT_RE = new RegExp(`\\.(${[...[
59
+ "css",
60
+ "scss",
61
+ "sass",
62
+ "less",
63
+ "styl",
64
+ "stylus"
65
+ ], ...VITE_DEFAULT_ASSET_TYPES].join("|")})(?:[?#].*)?$`, "i");
66
+ function isAssetLikeImport(source) {
67
+ return ASSET_LIKE_IMPORT_RE.test(source);
68
+ }
69
+ const VITE_OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
70
+ function isViteOptimizableEntry(resolvedPath) {
71
+ return VITE_OPTIMIZABLE_ENTRY_RE.test(resolvedPath);
72
+ }
73
+ function removeTrailingSlash(value) {
74
+ return value.endsWith("/") ? value.slice(0, -1) : value;
75
+ }
76
+ function ensureTrailingSlash(value) {
77
+ return `${removeTrailingSlash(value)}/`;
78
+ }
79
+ function getBasePath(base) {
80
+ return removeTrailingSlash(base || "/");
81
+ }
82
+ function isNuxtClientBase(base) {
83
+ return getBasePath(base).endsWith("/_nuxt");
84
+ }
85
+ function normalizeNodeModulePath(source) {
86
+ const queryIndex = source.indexOf("?");
87
+ return (queryIndex === -1 ? source : source.slice(0, queryIndex)).replace(/\\/g, "/");
88
+ }
89
+ function isNodeModulePath(source) {
90
+ return source.includes("/node_modules/") || source.includes("\\node_modules\\");
91
+ }
92
+ function filterId(id) {
93
+ return typeof id === "string" && !id.includes("\0");
94
+ }
95
+ const NODE_MODULE_FILE_EXT_RE = /^\.[cm]?[jt]sx?$/i;
96
+ function matchesNodeModuleCandidate(normalized, candidate) {
97
+ const marker = `/node_modules/${candidate}`;
98
+ let from = 0;
99
+ while (from < normalized.length) {
100
+ const index = normalized.indexOf(marker, from);
101
+ if (index === -1) return false;
102
+ const after = normalized.slice(index + marker.length);
103
+ const boundary = after.search(/[?#]/);
104
+ const afterPath = boundary === -1 ? after : after.slice(0, boundary);
105
+ if (afterPath === "" || afterPath.startsWith("/") || NODE_MODULE_FILE_EXT_RE.test(afterPath)) return true;
106
+ from = index + 1;
107
+ }
108
+ return false;
109
+ }
110
+ function getMatchingNodeModuleSubpath(source, candidates) {
111
+ const normalized = normalizeNodeModulePath(source);
112
+ return [...candidates].sort((a, b) => b.length - a.length).find((candidate) => matchesNodeModuleCandidate(normalized, candidate));
113
+ }
114
+ function getCommonSharedSubpaths(sharedKey) {
115
+ return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
116
+ }
117
+ function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
118
+ return getMatchingNodeModuleSubpath(source, getCommonSharedSubpaths(removeTrailingSlash(sharedKey)));
119
+ }
120
+ /**
121
+ * Resolves the public path for remote entries
122
+ * @param options - Module Federation options
123
+ * @param viteBase - Vite's base config value
124
+ * @param originalBase - Original base config before any transformations
125
+ * @returns The resolved public path
126
+ */
127
+ function resolvePublicPath(options, viteBase, originalBase) {
128
+ if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
129
+ if (!originalBase) return "auto";
130
+ if (viteBase) {
131
+ if (viteBase === "./") return "auto";
132
+ return ensureTrailingSlash(viteBase);
133
+ }
134
+ return "auto";
135
+ }
136
+ //#endregion
137
+ //#region src/utils/sharedKeyMatcher.ts
138
+ function matchesSharedSource(source, key) {
139
+ const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
140
+ if (keyBase === "vue" && (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js")) return true;
141
+ if (key.endsWith("/")) return source === keyBase || source.startsWith(`${keyBase}/`);
142
+ if (getCommonSharedSubpaths(keyBase).includes(source)) return true;
143
+ return source === keyBase;
144
+ }
145
+ const emptySharedKeyMatcher = { find: () => void 0 };
146
+ const sharedKeyMatcherCache = /* @__PURE__ */ new WeakMap();
147
+ function invalidateSharedKeyMatcher(shared) {
148
+ sharedKeyMatcherCache.delete(shared);
149
+ }
150
+ function findSharedKey(source, shared) {
151
+ return getSharedKeyMatcher(shared).find(source);
152
+ }
153
+ function pickLongestWildcardKey(wildcardKeys, source) {
154
+ let best;
155
+ for (const wildcard of wildcardKeys) {
156
+ if (source !== wildcard.base && !source.startsWith(`${wildcard.base}/`)) continue;
157
+ if (!best || wildcard.base.length > best.base.length || wildcard.base.length === best.base.length && wildcard.key.length > best.key.length) best = wildcard;
158
+ }
159
+ return best?.key;
160
+ }
161
+ function getSharedKeyMatcher(shared) {
162
+ if (!shared) return emptySharedKeyMatcher;
163
+ const cached = sharedKeyMatcherCache.get(shared);
164
+ if (cached) return cached;
165
+ const keys = Object.keys(shared);
166
+ const exactKeys = new Set(keys);
167
+ const commonSubpathKeys = /* @__PURE__ */ new Map();
168
+ const wildcardKeys = [];
169
+ let vueKey;
170
+ for (const key of keys) {
171
+ const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
172
+ const shareItem = shared[key];
173
+ if (!vueKey && keyBase === "vue") vueKey = key;
174
+ if (key.endsWith("/")) wildcardKeys.push({
175
+ key,
176
+ base: keyBase
177
+ });
178
+ if (shareItem?.shareConfig?.import !== false) {
179
+ for (const subpath of getCommonSharedSubpaths(keyBase)) if (!commonSubpathKeys.has(subpath)) commonSubpathKeys.set(subpath, key);
180
+ }
181
+ }
182
+ const sourceCache = /* @__PURE__ */ new Map();
183
+ const matcher = { find(source) {
184
+ if (sourceCache.has(source)) return sourceCache.get(source);
185
+ let result = exactKeys.has(source) ? source : void 0;
186
+ if (!result && vueKey) {
187
+ if (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js") result = vueKey;
188
+ }
189
+ if (!result) result = commonSubpathKeys.get(source);
190
+ if (!result) result = pickLongestWildcardKey(wildcardKeys, source);
191
+ sourceCache.set(source, result);
192
+ return result;
193
+ } };
194
+ sharedKeyMatcherCache.set(shared, matcher);
195
+ return matcher;
196
+ }
197
+ //#endregion
198
+ export { filterId as a, getCommonSharedSubpaths as c, isNodeModulePath as d, isNuxtClientBase as f, resolvePublicPath as h, ensureTrailingSlash as i, getMatchingNodeModuleSubpath as l, normalizeNodeModulePath as m, invalidateSharedKeyMatcher as n, getBasePath as o, isViteOptimizableEntry as p, matchesSharedSource as r, getCommonSharedSubpathFromNodeModulePath as s, findSharedKey as t, isAssetLikeImport as u };
@@ -203,7 +203,7 @@ async function getOrCreateRunner(remoteOrigin, resolvedShared, fetchTimeoutMs, f
203
203
  headers: { "Content-Type": "application/json" },
204
204
  body: JSON.stringify(payload)
205
205
  }, fetchTimeoutMs), fetchMaxBytes, runnerEndpoint);
206
- const result = JSON.parse(text);
206
+ const result = parseRunnerInvokeResult(JSON.parse(text));
207
207
  if ("error" in result && payload.data.name === "fetchModule") {
208
208
  const sharedExternal = await resolveSharedExternal(payload.data.data[0], resolvedShared);
209
209
  if (sharedExternal) return { result: sharedExternal };
@@ -223,6 +223,31 @@ const _fs = () => nodeImport("fs");
223
223
  const _crypto = () => nodeImport("crypto");
224
224
  const _module = () => nodeImport("module");
225
225
  const _url = () => nodeImport("url");
226
+ function isPlainObject(value) {
227
+ return !!value && typeof value === "object" && !Array.isArray(value);
228
+ }
229
+ function parseManifestEntry(value) {
230
+ if (!isPlainObject(value) || typeof value.name !== "string" || value.name.length === 0) return;
231
+ return {
232
+ name: value.name,
233
+ path: typeof value.path === "string" ? value.path : "",
234
+ type: typeof value.type === "string" ? value.type : "module"
235
+ };
236
+ }
237
+ /** Network JSON is untyped until parsed. Keep the original object for version hashing. */
238
+ function parseManifest(data) {
239
+ if (!isPlainObject(data)) return null;
240
+ return data;
241
+ }
242
+ function parseRunnerInvokeResult(data) {
243
+ if (!isPlainObject(data)) return { error: { message: "Invalid runner response" } };
244
+ if ("error" in data) {
245
+ const error = data.error;
246
+ return { error: { message: isPlainObject(error) && typeof error.message === "string" ? error.message : "Unknown runner error" } };
247
+ }
248
+ if ("result" in data) return { result: data.result };
249
+ return { result: data };
250
+ }
226
251
  /**
227
252
  * Version key for a resolved SSR entry. Derived from the remote's manifest
228
253
  * content so a redeploy at the same URL produces a different key, which in
@@ -274,7 +299,7 @@ async function fetchManifest(manifestUrl, fetchTimeoutMs, fetchMaxBytes) {
274
299
  const res = await fetchWithTimeout(manifestUrl, {}, fetchTimeoutMs);
275
300
  if (!res.ok) return null;
276
301
  const text = await readResponseTextBounded(res, fetchMaxBytes, manifestUrl);
277
- return JSON.parse(text);
302
+ return parseManifest(JSON.parse(text));
278
303
  } catch (error) {
279
304
  if (isSsrFetchBodyTooLargeError(error)) throw error;
280
305
  return null;
@@ -317,13 +342,13 @@ function resolveEntryAssetUrl(entry, manifestUrl) {
317
342
  return new URL(`${entry.path || ""}${entry.name}`, base).href;
318
343
  }
319
344
  function resolveSSREntryUrl(manifest, manifestUrl) {
320
- const meta = manifest?.metaData;
321
- if (!meta?.ssrRemoteEntry?.name) return null;
345
+ const entry = parseManifestEntry(manifest.metaData?.ssrRemoteEntry);
346
+ if (!entry) return null;
322
347
  const base = manifestUrl.replace(/\/[^/]+$/, "/");
323
- const entryPath = (meta.ssrRemoteEntry.path || "") + meta.ssrRemoteEntry.name;
348
+ const entryPath = entry.path + entry.name;
324
349
  return {
325
350
  url: new URL(entryPath, base).href,
326
- type: meta.ssrRemoteEntry.type || "module",
351
+ type: entry.type,
327
352
  versionKey: computeManifestVersionKey(manifest)
328
353
  };
329
354
  }
@@ -342,8 +367,8 @@ async function headCheckSsrEntry(candidate, fetchTimeoutMs) {
342
367
  return null;
343
368
  }
344
369
  function resolveAssetBaseUrl(entryUrl, manifest, manifestUrl) {
345
- const remoteEntry = manifest?.metaData?.remoteEntry;
346
- if (remoteEntry?.name) return resolveEntryAssetUrl(remoteEntry, manifestUrl);
370
+ const remoteEntry = parseManifestEntry(manifest?.metaData?.remoteEntry);
371
+ if (remoteEntry) return resolveEntryAssetUrl(remoteEntry, manifestUrl);
347
372
  if (!isManifestEntry(entryUrl)) return entryUrl;
348
373
  return new URL("remoteEntry.js", manifestUrl.replace(/\/[^/]+$/, "/")).href;
349
374
  }
@@ -489,7 +514,7 @@ async function getSSRCacheDir() {
489
514
  if (!ssrCacheDirPromise) ssrCacheDirPromise = (async () => {
490
515
  const { join } = await _path();
491
516
  const { rmSync } = await _fs();
492
- const dir = join(process.cwd(), "node_modules", ".ssr-cache");
517
+ const dir = join(process.cwd(), "node_modules", ".ssr-cache", String(process.pid));
493
518
  process.once("exit", () => {
494
519
  try {
495
520
  rmSync(dir, {
@@ -606,7 +631,7 @@ async function importTempModule(filePath, versionKey) {
606
631
  }
607
632
  let warnedVmUnavailable = false;
608
633
  async function tryVmStrategy(ssrEntry, options) {
609
- const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-tpI6we9Q.js");
634
+ const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-D4KB-y3H.js");
610
635
  if (!await isVmStrategyAvailable()) {
611
636
  if (!warnedVmUnavailable) {
612
637
  warnedVmUnavailable = true;
@@ -1,5 +1,5 @@
1
- import { a as getCommonSharedSubpaths } from "./pathNormalization-CHct3UwV.js";
2
- import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-BMtjS_Vl.js";
1
+ import { t as findSharedKey } from "./sharedKeyMatcher-DiUzRVH1.js";
2
+ import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-CqtaiDUp.js";
3
3
  //#region src/utils/ssrVmStrategy.ts
4
4
  /**
5
5
  * vm.SourceTextModule strategy for loading remote SSR entries.
@@ -41,20 +41,7 @@ async function isVmStrategyAvailable() {
41
41
  return await getVmApi() !== null;
42
42
  }
43
43
  function findVmSharedKey(specifier, shared) {
44
- if (!shared) return;
45
- const keys = Object.keys(shared);
46
- if (Object.prototype.hasOwnProperty.call(shared, specifier)) return specifier;
47
- const vueKey = keys.find((key) => key.endsWith("/") ? key.slice(0, -1) === "vue" : key === "vue");
48
- if (vueKey && (specifier === "vue/dist/vue.esm-bundler.js" || specifier === "vue/dist/vue.runtime.esm-bundler.js")) return vueKey;
49
- const commonSubpathKey = keys.find((key) => {
50
- return getCommonSharedSubpaths(key.endsWith("/") ? key.slice(0, -1) : key).includes(specifier);
51
- });
52
- if (commonSubpathKey) return commonSubpathKey;
53
- return keys.find((key) => {
54
- if (!key.endsWith("/")) return false;
55
- const keyBase = key.slice(0, -1);
56
- return specifier === keyBase || specifier.startsWith(`${keyBase}/`);
57
- });
44
+ return findSharedKey(specifier, shared);
58
45
  }
59
46
  function getFederationInstances() {
60
47
  return globalThis.__FEDERATION__?.__INSTANCES__ ?? [];
@@ -1,2 +1,2 @@
1
- import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-BMtjS_Vl.js";
1
+ import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-CqtaiDUp.js";
2
2
  export { SsrEntryHttpError, ssrEntryLoaderPlugin as default, neutralizeBrowserPreloadHelpers, revalidate };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/vite",
3
- "version": "1.21.3",
3
+ "version": "1.21.4",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -1,115 +0,0 @@
1
- //#region src/utils/pathNormalization.ts
2
- const COMMON_SHARED_SUBPATHS = {
3
- react: [
4
- "react/jsx-runtime",
5
- "react/jsx-dev-runtime",
6
- "react/compiler-runtime"
7
- ],
8
- "react-dom": ["react-dom/client", "react-dom/profiling"],
9
- "solid-js": [
10
- "solid-js/web",
11
- "solid-js/store",
12
- "solid-js/html",
13
- "solid-js/h"
14
- ],
15
- zustand: ["zustand/vanilla", "zustand/react"]
16
- };
17
- const VITE_DEFAULT_ASSET_TYPES = [
18
- "apng",
19
- "bmp",
20
- "png",
21
- "jpe?g",
22
- "jfif",
23
- "pjpeg",
24
- "pjp",
25
- "gif",
26
- "svg",
27
- "ico",
28
- "webp",
29
- "avif",
30
- "cur",
31
- "jxl",
32
- "mp4",
33
- "webm",
34
- "ogg",
35
- "mp3",
36
- "wav",
37
- "flac",
38
- "aac",
39
- "opus",
40
- "mov",
41
- "m4a",
42
- "vtt",
43
- "woff2?",
44
- "eot",
45
- "ttf",
46
- "otf",
47
- "webmanifest",
48
- "pdf",
49
- "txt"
50
- ];
51
- const ASSET_LIKE_IMPORT_RE = new RegExp(`\\.(${[...[
52
- "css",
53
- "scss",
54
- "sass",
55
- "less",
56
- "styl",
57
- "stylus"
58
- ], ...VITE_DEFAULT_ASSET_TYPES].join("|")})(?:[?#].*)?$`, "i");
59
- function isAssetLikeImport(source) {
60
- return ASSET_LIKE_IMPORT_RE.test(source);
61
- }
62
- const VITE_OPTIMIZABLE_ENTRY_RE = /\.[cm]?[jt]s$/;
63
- function isViteOptimizableEntry(resolvedPath) {
64
- return VITE_OPTIMIZABLE_ENTRY_RE.test(resolvedPath);
65
- }
66
- function removeTrailingSlash(value) {
67
- return value.endsWith("/") ? value.slice(0, -1) : value;
68
- }
69
- function ensureTrailingSlash(value) {
70
- return `${removeTrailingSlash(value)}/`;
71
- }
72
- function getBasePath(base) {
73
- return removeTrailingSlash(base || "/");
74
- }
75
- function isNuxtClientBase(base) {
76
- return getBasePath(base).endsWith("/_nuxt");
77
- }
78
- function normalizeNodeModulePath(source) {
79
- const queryIndex = source.indexOf("?");
80
- return (queryIndex === -1 ? source : source.slice(0, queryIndex)).replace(/\\/g, "/");
81
- }
82
- function isNodeModulePath(source) {
83
- return source.includes("/node_modules/") || source.includes("\\node_modules\\");
84
- }
85
- function filterId(id) {
86
- return typeof id === "string" && !id.includes("\0");
87
- }
88
- function getMatchingNodeModuleSubpath(source, candidates) {
89
- const normalized = normalizeNodeModulePath(source);
90
- return [...candidates].sort((a, b) => b.length - a.length).find((candidate) => normalized.includes(`/node_modules/${candidate}/`) || normalized.includes(`/node_modules/${candidate}.`));
91
- }
92
- function getCommonSharedSubpaths(sharedKey) {
93
- return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
94
- }
95
- function getCommonSharedSubpathFromNodeModulePath(source, sharedKey) {
96
- return getMatchingNodeModuleSubpath(source, getCommonSharedSubpaths(removeTrailingSlash(sharedKey)));
97
- }
98
- /**
99
- * Resolves the public path for remote entries
100
- * @param options - Module Federation options
101
- * @param viteBase - Vite's base config value
102
- * @param originalBase - Original base config before any transformations
103
- * @returns The resolved public path
104
- */
105
- function resolvePublicPath(options, viteBase, originalBase) {
106
- if (options.publicPath && options.publicPath !== "auto") return options.publicPath;
107
- if (!originalBase) return "auto";
108
- if (viteBase) {
109
- if (viteBase === "./") return "auto";
110
- return ensureTrailingSlash(viteBase);
111
- }
112
- return "auto";
113
- }
114
- //#endregion
115
- export { getCommonSharedSubpaths as a, isNodeModulePath as c, normalizeNodeModulePath as d, resolvePublicPath as f, getCommonSharedSubpathFromNodeModulePath as i, isNuxtClientBase as l, filterId as n, getMatchingNodeModuleSubpath as o, getBasePath as r, isAssetLikeImport as s, ensureTrailingSlash as t, isViteOptimizableEntry as u };