@module-federation/vite 1.19.1 → 1.20.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.
@@ -136,11 +136,14 @@ async function nodeImport(id) {
136
136
  const isNodeServer = () => typeof globalThis.process?.versions?.node === "string";
137
137
  const runnerCache = /* @__PURE__ */ new Map();
138
138
  /**
139
- * Import `vite/module-runner` dynamically. Returns null on Vite < 8 where the
140
- * subpath doesn't exist. Uses a plain dynamic import (not nodeImport) so that
141
- * Vitest can intercept it with vi.mock in tests.
139
+ * Load `vite/module-runner`. Returns null on Vite < 8 where the subpath doesn't
140
+ * exist.
142
141
  */
143
142
  async function getModuleRunnerModule() {
143
+ try {
144
+ const { createRequire } = await nodeImport("module");
145
+ return createRequire(import.meta.url)("vite/module-runner");
146
+ } catch {}
144
147
  try {
145
148
  return await import("vite/module-runner");
146
149
  } catch {
@@ -213,6 +216,10 @@ function makeUrlCacheKey(url, fetchTimeoutMs, fetchMaxBytes) {
213
216
  return `${fetchTimeoutMs}::${fetchMaxBytes}::${url}`;
214
217
  }
215
218
  var SsrEntryHttpError = class extends Error {
219
+ url;
220
+ status;
221
+ statusText;
222
+ bodyPreview;
216
223
  constructor(url, status, statusText, bodyPreview) {
217
224
  super(`Failed to fetch SSR module "${url}": ${status} ${statusText}` + (bodyPreview ? `\npreview: ${bodyPreview}` : ""));
218
225
  this.url = url;
@@ -565,7 +572,7 @@ async function importTempModule(filePath, versionKey) {
565
572
  }
566
573
  let warnedVmUnavailable = false;
567
574
  async function tryVmStrategy(ssrEntry, options) {
568
- const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-Dpw20xiw.js");
575
+ const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-7HAPa-Vc.js");
569
576
  if (!await isVmStrategyAvailable()) {
570
577
  if (!warnedVmUnavailable) {
571
578
  warnedVmUnavailable = true;
@@ -1,4 +1,4 @@
1
- import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-CuZVKlRm.js";
1
+ import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-Bw423jj_.js";
2
2
  //#region src/utils/ssrVmStrategy.ts
3
3
  /**
4
4
  * vm.SourceTextModule strategy for loading remote SSR entries.
@@ -0,0 +1,21 @@
1
+ //#region src/utils/injectExternalRuntimeCorePlugin.d.ts
2
+ /**
3
+ * MF runtime plugin that publishes `@module-federation/runtime-core` on
4
+ * `globalThis._FEDERATION_RUNTIME_CORE` so remotes with `experiments.externalRuntime`
5
+ * can share the host's runtime-core instead of bundling their own copy.
6
+ *
7
+ * Mirrors `@module-federation/inject-external-runtime-core-plugin` without
8
+ * adding that package (or `runtime-tools`) as a dependency of this plugin.
9
+ */
10
+ type BeforeInitArgs = {
11
+ options: {
12
+ name: string;
13
+ };
14
+ };
15
+ declare function injectExternalRuntimeCorePlugin(): {
16
+ name: string;
17
+ version: string;
18
+ beforeInit(args: BeforeInitArgs): BeforeInitArgs;
19
+ };
20
+ //#endregion
21
+ export { injectExternalRuntimeCorePlugin as default };
@@ -0,0 +1,54 @@
1
+ import * as runtimeCore from "@module-federation/runtime/core";
2
+ //#region src/utils/injectExternalRuntimeCorePlugin.ts
3
+ /**
4
+ * MF runtime plugin that publishes `@module-federation/runtime-core` on
5
+ * `globalThis._FEDERATION_RUNTIME_CORE` so remotes with `experiments.externalRuntime`
6
+ * can share the host's runtime-core instead of bundling their own copy.
7
+ *
8
+ * Mirrors `@module-federation/inject-external-runtime-core-plugin` without
9
+ * adding that package (or `runtime-tools`) as a dependency of this plugin.
10
+ */
11
+ /** Keep in sync with the `@module-federation/runtime` dependency version. */
12
+ const PLUGIN_VERSION = "2.8.0";
13
+ function getFederationGlobal() {
14
+ const globalRef = runtimeCore.Global;
15
+ if (!globalRef || typeof globalRef !== "object") return void 0;
16
+ return globalRef;
17
+ }
18
+ /**
19
+ * Publish runtime-core as soon as this module evaluates. Vite remotes can
20
+ * import the externalRuntime shim before `beforeInit` runs; registering here
21
+ * closes that race when the host has already loaded this plugin module.
22
+ *
23
+ * Leave `_FEDERATION_RUNTIME_CORE_FROM` unset until `beforeInit` so the host
24
+ * name/version metadata is applied without a false multi-runtime warning.
25
+ */
26
+ function publishExternalRuntimeCore() {
27
+ const globalRef = getFederationGlobal();
28
+ if (!globalRef) return;
29
+ if (!globalRef._FEDERATION_RUNTIME_CORE) globalRef._FEDERATION_RUNTIME_CORE = runtimeCore;
30
+ }
31
+ publishExternalRuntimeCore();
32
+ function injectExternalRuntimeCorePlugin() {
33
+ return {
34
+ name: "inject-external-runtime-core-plugin",
35
+ version: PLUGIN_VERSION,
36
+ beforeInit(args) {
37
+ const globalRef = getFederationGlobal();
38
+ if (!globalRef) return args;
39
+ const name = args.options.name;
40
+ if (globalRef._FEDERATION_RUNTIME_CORE && globalRef._FEDERATION_RUNTIME_CORE_FROM && (globalRef._FEDERATION_RUNTIME_CORE_FROM.name !== name || globalRef._FEDERATION_RUNTIME_CORE_FROM.version !== PLUGIN_VERSION)) {
41
+ console.warn(`Detect multiple module federation runtime! Injected runtime from ${globalRef._FEDERATION_RUNTIME_CORE_FROM.name}@${globalRef._FEDERATION_RUNTIME_CORE_FROM.version} and current is ${name}@${PLUGIN_VERSION}, pleasure ensure there is only one consumer to provider runtime!`);
42
+ return args;
43
+ }
44
+ globalRef._FEDERATION_RUNTIME_CORE = runtimeCore;
45
+ globalRef._FEDERATION_RUNTIME_CORE_FROM = {
46
+ version: PLUGIN_VERSION,
47
+ name
48
+ };
49
+ return args;
50
+ }
51
+ };
52
+ }
53
+ //#endregion
54
+ export { injectExternalRuntimeCorePlugin as default };
@@ -113,10 +113,7 @@ interface SsrEntryLoaderOptions {
113
113
  }
114
114
  declare function ssrEntryLoaderPlugin(options?: SsrEntryLoaderOptions): {
115
115
  name: string;
116
- loadEntry({
117
- remoteInfo,
118
- origin
119
- }: {
116
+ loadEntry({ remoteInfo, origin }: {
120
117
  remoteInfo: RemoteInfo;
121
118
  origin?: object;
122
119
  }): Promise<{
@@ -1,2 +1,2 @@
1
- import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-CuZVKlRm.js";
1
+ import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-Bw423jj_.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.19.1",
3
+ "version": "1.20.1",
4
4
  "description": "Vite plugin for Module Federation",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -15,6 +15,10 @@
15
15
  "types": "./lib/utils/ssrEntryLoader.d.ts",
16
16
  "default": "./lib/utils/ssrEntryLoader.js"
17
17
  },
18
+ "./injectExternalRuntimeCorePlugin": {
19
+ "types": "./lib/utils/injectExternalRuntimeCorePlugin.d.ts",
20
+ "default": "./lib/utils/injectExternalRuntimeCorePlugin.js"
21
+ },
18
22
  "./package.json": "./package.json"
19
23
  },
20
24
  "engines": {
@@ -35,6 +39,9 @@
35
39
  "dev-vv": "pnpm clean && pnpm -filter 'examples-vite-vite*' run dev",
36
40
  "preview-vv": "pnpm clean && pnpm run build:shared-lib && pnpm -filter 'examples-vite-vite*' --parallel run preview",
37
41
  "preview-vv:ci": "pnpm run build:shared-lib && pnpm -filter 'examples-vite-vite*' --parallel run preview",
42
+ "preview-vv:external": "pnpm clean && pnpm run build:shared-lib && EXTERNAL_RUNTIME=1 pnpm -filter 'examples-vite-vite*' --parallel run preview",
43
+ "preview-vv:external:ci": "pnpm run build:shared-lib && EXTERNAL_RUNTIME=1 pnpm -filter 'examples-vite-vite*' --parallel run preview",
44
+ "e2e:external": "playwright test --config=playwright.external-runtime.config.ts",
38
45
  "build:shared-lib": "pnpm --filter @vite-vite/shared-lib run build",
39
46
  "typecheck": "tsc -p tsconfig.json",
40
47
  "multi-example:ci": "pnpm -filter 'multi-example-*' --parallel run start",
@@ -70,20 +77,20 @@
70
77
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
71
78
  },
72
79
  "dependencies": {
73
- "@module-federation/dts-plugin": "2.8.0",
74
- "@module-federation/runtime": "2.8.0",
75
- "@module-federation/sdk": "2.8.0"
80
+ "@module-federation/dts-plugin": "2.8.1",
81
+ "@module-federation/runtime": "2.8.1",
82
+ "@module-federation/sdk": "2.8.1"
76
83
  },
77
84
  "devDependencies": {
78
- "@playwright/test": "1.58.2",
79
- "@types/node": "25.3.3",
85
+ "@playwright/test": "1.62.0",
86
+ "@types/node": "26.1.2",
80
87
  "husky": "9.1.7",
81
88
  "mock-shared-dep": "workspace:*",
82
- "oxfmt": "0.36.0",
83
- "rollup": "4.47.1",
84
- "tsdown": "0.21.0",
85
- "typescript": "5.9.3",
86
- "vite": "8.1.0",
89
+ "oxfmt": "0.61.0",
90
+ "rollup": "4.62.3",
91
+ "tsdown": "0.22.14",
92
+ "typescript": "7.0.2",
93
+ "vite": "8.1.5",
87
94
  "vitest": "4.0.18"
88
95
  }
89
96
  }