@module-federation/vite 1.19.1 → 1.20.0
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/README.md +40 -0
- package/lib/index.d.ts +22 -1
- package/lib/index.js +884 -229
- package/lib/{pluginDts-9RTNVO8v.js → pluginDts-Dbbi4cnh.js} +15 -9
- package/lib/{ssrEntryLoader-CuZVKlRm.js → ssrEntryLoader-BUD1-3Z2.js} +7 -4
- package/lib/{ssrVmStrategy-Dpw20xiw.js → ssrVmStrategy-C_cJtu5V.js} +1 -1
- package/lib/utils/injectExternalRuntimeCorePlugin.d.ts +21 -0
- package/lib/utils/injectExternalRuntimeCorePlugin.js +54 -0
- package/lib/utils/ssrEntryLoader.js +1 -1
- package/package.json +8 -1
|
@@ -124,23 +124,29 @@ const DEFAULT_EXPORT_CONDITIONS = [
|
|
|
124
124
|
"browser",
|
|
125
125
|
"import",
|
|
126
126
|
"module",
|
|
127
|
-
"default"
|
|
128
|
-
"require"
|
|
127
|
+
"default"
|
|
129
128
|
];
|
|
130
129
|
function resolveExportsEntry(exportsField, conditions = DEFAULT_EXPORT_CONDITIONS) {
|
|
130
|
+
return resolveExportsEntryWithConditions(exportsField, new Set(conditions));
|
|
131
|
+
}
|
|
132
|
+
function resolveExportsEntryWithConditions(exportsField, conditions) {
|
|
131
133
|
if (typeof exportsField === "string") return exportsField;
|
|
132
134
|
if (!exportsField || typeof exportsField !== "object") return void 0;
|
|
135
|
+
if (Array.isArray(exportsField)) {
|
|
136
|
+
for (const target of exportsField) {
|
|
137
|
+
const resolved = resolveExportsEntryWithConditions(target, conditions);
|
|
138
|
+
if (resolved) return resolved;
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
133
142
|
const record = exportsField;
|
|
134
143
|
const rootExport = record["."];
|
|
135
|
-
if (rootExport) return
|
|
136
|
-
for (const condition of
|
|
137
|
-
|
|
144
|
+
if (rootExport) return resolveExportsEntryWithConditions(rootExport, conditions);
|
|
145
|
+
for (const [condition, value] of Object.entries(record)) {
|
|
146
|
+
if (condition !== "default" && !conditions.has(condition)) continue;
|
|
147
|
+
const target = resolveExportsEntryWithConditions(value, conditions);
|
|
138
148
|
if (target) return target;
|
|
139
149
|
}
|
|
140
|
-
for (const target of Object.values(record)) {
|
|
141
|
-
const resolved = resolveExportsEntry(target, conditions);
|
|
142
|
-
if (resolved) return resolved;
|
|
143
|
-
}
|
|
144
150
|
}
|
|
145
151
|
function substituteExportsWildcard(target, patternMatch) {
|
|
146
152
|
if (typeof target === "string") return target.split("*").join(patternMatch);
|
|
@@ -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
|
-
*
|
|
140
|
-
*
|
|
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 {
|
|
@@ -565,7 +568,7 @@ async function importTempModule(filePath, versionKey) {
|
|
|
565
568
|
}
|
|
566
569
|
let warnedVmUnavailable = false;
|
|
567
570
|
async function tryVmStrategy(ssrEntry, options) {
|
|
568
|
-
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-
|
|
571
|
+
const { loadViaVmStrategy, isVmStrategyAvailable } = await import("./ssrVmStrategy-C_cJtu5V.js");
|
|
569
572
|
if (!await isVmStrategyAvailable()) {
|
|
570
573
|
if (!warnedVmUnavailable) {
|
|
571
574
|
warnedVmUnavailable = true;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-
|
|
1
|
+
import { c as readResponseTextBounded, n as neutralizeBrowserPreloadHelpers, s as fetchWithTimeout, t as SsrEntryHttpError } from "./ssrEntryLoader-BUD1-3Z2.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 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-
|
|
1
|
+
import { i as ssrEntryLoaderPlugin, n as neutralizeBrowserPreloadHelpers, r as revalidate, t as SsrEntryHttpError } from "../ssrEntryLoader-BUD1-3Z2.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.
|
|
3
|
+
"version": "1.20.0",
|
|
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",
|