@module-federation/vite 1.16.4 → 1.16.5
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 +21 -8
- package/lib/{index.d.cts → index.d.ts} +9 -1
- package/lib/{index.mjs → index.js} +141 -67
- package/lib/{packageUtils-Bbc6r6__.mjs → packageUtils-CxYRnFwy.js} +16 -8
- package/lib/{pluginDts-DDx4TPN8.mjs → pluginDts-Bgdw5ODE.js} +2 -2
- package/lib/utils/{ssrEntryLoader.mjs → ssrEntryLoader.js} +3 -3
- package/package.json +12 -20
- package/lib/index.cjs +0 -5381
- package/lib/index.d.mts +0 -167
- package/lib/packageUtils-se-UDhCa.cjs +0 -367
- package/lib/pluginDts-7EoFboCu.cjs +0 -311
- package/lib/utils/ssrEntryLoader.cjs +0 -301
- package/lib/utils/ssrEntryLoader.d.cts +0 -65
- /package/lib/utils/{ssrEntryLoader.d.mts → ssrEntryLoader.d.ts} +0 -0
package/lib/index.d.mts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { moduleFederationPlugin } from "@module-federation/sdk";
|
|
2
|
-
import { ShareStrategy } from "@module-federation/runtime/types";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/normalizeModuleFederationOptions.d.ts
|
|
5
|
-
interface RemoteObjectConfig {
|
|
6
|
-
type?: string;
|
|
7
|
-
name: string;
|
|
8
|
-
internalName?: string;
|
|
9
|
-
entry: string;
|
|
10
|
-
entryGlobalName?: string;
|
|
11
|
-
shareScope?: string;
|
|
12
|
-
}
|
|
13
|
-
interface PluginManifestOptions {
|
|
14
|
-
filePath?: string;
|
|
15
|
-
disableAssetsAnalyze?: boolean;
|
|
16
|
-
fileName?: string;
|
|
17
|
-
}
|
|
18
|
-
type ModuleFederationOptions = {
|
|
19
|
-
exposes?: Record<string, string | {
|
|
20
|
-
import: string;
|
|
21
|
-
}> | undefined;
|
|
22
|
-
filename?: string;
|
|
23
|
-
library?: any;
|
|
24
|
-
name: string;
|
|
25
|
-
remotes?: Record<string, string | RemoteObjectConfig> | undefined;
|
|
26
|
-
runtime?: any;
|
|
27
|
-
shareScope?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Override the public path used for remote entries
|
|
30
|
-
* Defaults to Vite's base config or "auto" if base is empty
|
|
31
|
-
*/
|
|
32
|
-
publicPath?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Controls whether all CSS assets from the bundle should be added to every exposed module.
|
|
35
|
-
* When false (default), the plugin will not process any CSS assets.
|
|
36
|
-
* When true, all CSS assets are bundled into every exposed module.
|
|
37
|
-
*/
|
|
38
|
-
bundleAllCSS?: boolean;
|
|
39
|
-
shared?: string[] | Record<string, string | {
|
|
40
|
-
name?: string;
|
|
41
|
-
version?: string;
|
|
42
|
-
shareScope?: string;
|
|
43
|
-
singleton?: boolean;
|
|
44
|
-
requiredVersion?: string;
|
|
45
|
-
strictVersion?: boolean;
|
|
46
|
-
import?: moduleFederationPlugin.SharedConfig['import'];
|
|
47
|
-
}> | undefined;
|
|
48
|
-
runtimePlugins?: Array<string | [string, Record<string, unknown>]>;
|
|
49
|
-
getPublicPath?: string;
|
|
50
|
-
implementation?: string;
|
|
51
|
-
manifest?: PluginManifestOptions | boolean;
|
|
52
|
-
dev?: boolean | PluginDevOptions;
|
|
53
|
-
dts?: boolean | PluginDtsOptions;
|
|
54
|
-
shareStrategy?: ShareStrategy;
|
|
55
|
-
ignoreOrigin?: boolean;
|
|
56
|
-
virtualModuleDir?: string;
|
|
57
|
-
hostInitInjectLocation?: HostInitInjectLocationOptions;
|
|
58
|
-
/**
|
|
59
|
-
* Timeout for parsing modules in seconds.
|
|
60
|
-
* Defaults to 10 seconds.
|
|
61
|
-
*/
|
|
62
|
-
moduleParseTimeout?: number;
|
|
63
|
-
/**
|
|
64
|
-
* Idle timeout for parsing modules in seconds. When set, the timeout resets
|
|
65
|
-
* on every parsed module and only fires when there has been no module activity
|
|
66
|
-
* for the configured duration. Prefer this over `moduleParseTimeout` for large
|
|
67
|
-
* codebases where the total build time may exceed the fixed timeout.
|
|
68
|
-
*/
|
|
69
|
-
moduleParseIdleTimeout?: number;
|
|
70
|
-
/**
|
|
71
|
-
* Allows generate additional remoteEntry file for "var" host environment
|
|
72
|
-
*/
|
|
73
|
-
varFilename?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Target environment for the build to enable effective tree-shaking.
|
|
76
|
-
*
|
|
77
|
-
* @see https://module-federation.io/configure/experiments#target
|
|
78
|
-
* @default 'web' (or 'node' if build.ssr is enabled)
|
|
79
|
-
*/
|
|
80
|
-
target?: 'web' | 'node';
|
|
81
|
-
/**
|
|
82
|
-
* Additional packages to mark as external in the SSR remote entry build.
|
|
83
|
-
* Shared packages and MF runtime packages are always external. Use this to
|
|
84
|
-
* add any other Node-only packages that should not be bundled into the SSR entry.
|
|
85
|
-
*/
|
|
86
|
-
ssrExternals?: string[];
|
|
87
|
-
};
|
|
88
|
-
type HostInitInjectLocationOptions = 'entry' | 'html';
|
|
89
|
-
interface PluginDevOptions {
|
|
90
|
-
disableLiveReload?: boolean;
|
|
91
|
-
disableHotTypesReload?: boolean;
|
|
92
|
-
disableDynamicRemoteTypeHints?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Controls cross-federation HMR for remote modules.
|
|
95
|
-
*
|
|
96
|
-
* - `false` / `undefined` — HMR disabled (default).
|
|
97
|
-
* - `true` — HMR enabled with auto-detected strategy. When a framework
|
|
98
|
-
* plugin with cross-federation HMR support is detected, broadcast/relay
|
|
99
|
-
* is suppressed and the framework's native HMR handles updates:
|
|
100
|
-
* - React (`@vitejs/plugin-react` / `@vitejs/plugin-react-swc`) — the
|
|
101
|
-
* plugin serves a `/@react-refresh` proxy on remotes that delegates
|
|
102
|
-
* to the host's `RefreshRuntime`, unifying the component registry.
|
|
103
|
-
* - Vue (`@vitejs/plugin-vue` / `@vitejs/plugin-vue-jsx`) — the plugin
|
|
104
|
-
* injects a `__VUE_HMR_RUNTIME__` guard into the host page so the
|
|
105
|
-
* first-loaded (host) Vue runtime is pinned and remote-loaded Vue
|
|
106
|
-
* copies cannot overwrite it.
|
|
107
|
-
* For any host, the plugin also injects a script that clears the
|
|
108
|
-
* federation `moduleCache` on `vite:beforeUpdate` so subsequent
|
|
109
|
-
* `loadRemote()` calls return the freshly patched module.
|
|
110
|
-
* Other frameworks fall back to full page reloads.
|
|
111
|
-
* - `'full-reload'` — HMR enabled, always use full page reloads even when
|
|
112
|
-
* a framework with native cross-federation HMR is detected.
|
|
113
|
-
*/
|
|
114
|
-
remoteHmr?: boolean | 'full-reload';
|
|
115
|
-
}
|
|
116
|
-
interface RemoteTypeUrl {
|
|
117
|
-
alias?: string;
|
|
118
|
-
api: string;
|
|
119
|
-
zip: string;
|
|
120
|
-
}
|
|
121
|
-
interface RemoteTypeUrls {
|
|
122
|
-
[remoteName: string]: RemoteTypeUrl;
|
|
123
|
-
}
|
|
124
|
-
interface PluginDtsOptions {
|
|
125
|
-
generateTypes?: boolean | DtsRemoteOptions;
|
|
126
|
-
consumeTypes?: boolean | DtsHostOptions;
|
|
127
|
-
tsConfigPath?: string;
|
|
128
|
-
extraOptions?: Record<string, unknown>;
|
|
129
|
-
implementation?: string;
|
|
130
|
-
cwd?: string;
|
|
131
|
-
displayErrorInTerminal?: boolean;
|
|
132
|
-
}
|
|
133
|
-
interface DtsRemoteOptions {
|
|
134
|
-
tsConfigPath?: string;
|
|
135
|
-
typesFolder?: string;
|
|
136
|
-
compiledTypesFolder?: string;
|
|
137
|
-
deleteTypesFolder?: boolean;
|
|
138
|
-
additionalFilesToCompile?: string[];
|
|
139
|
-
compilerInstance?: 'tsc' | 'vue-tsc' | 'tspc' | string;
|
|
140
|
-
compileInChildProcess?: boolean;
|
|
141
|
-
generateAPITypes?: boolean;
|
|
142
|
-
extractThirdParty?: boolean | {
|
|
143
|
-
exclude?: Array<string | RegExp>;
|
|
144
|
-
};
|
|
145
|
-
extractRemoteTypes?: boolean;
|
|
146
|
-
abortOnError?: boolean;
|
|
147
|
-
deleteTsConfig?: boolean;
|
|
148
|
-
}
|
|
149
|
-
interface DtsHostOptions {
|
|
150
|
-
typesFolder?: string;
|
|
151
|
-
abortOnError?: boolean;
|
|
152
|
-
remoteTypesFolder?: string;
|
|
153
|
-
deleteTypesFolder?: boolean;
|
|
154
|
-
maxRetries?: number;
|
|
155
|
-
consumeAPITypes?: boolean;
|
|
156
|
-
runtimePkgs?: string[];
|
|
157
|
-
remoteTypeUrls?: (() => Promise<RemoteTypeUrls>) | RemoteTypeUrls;
|
|
158
|
-
timeout?: number;
|
|
159
|
-
family?: 0 | 4 | 6;
|
|
160
|
-
typesOnBuild?: boolean;
|
|
161
|
-
}
|
|
162
|
-
//#endregion
|
|
163
|
-
//#region src/index.d.ts
|
|
164
|
-
declare function federation(mfUserOptions: ModuleFederationOptions): any[];
|
|
165
|
-
declare function createModuleFederationConfig<T extends ModuleFederationOptions>(options: T): T;
|
|
166
|
-
//#endregion
|
|
167
|
-
export { type ModuleFederationOptions, type PluginManifestOptions, createModuleFederationConfig, federation };
|
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
//#endregion
|
|
23
|
-
let fs = require("fs");
|
|
24
|
-
let module$1 = require("module");
|
|
25
|
-
let pathe = require("pathe");
|
|
26
|
-
pathe = __toESM(pathe);
|
|
27
|
-
//#region src/utils/logger.ts
|
|
28
|
-
const MODULE_FEDERATION_LOG_PREFIX = "[Module Federation]";
|
|
29
|
-
function formatModuleFederationMessage(message) {
|
|
30
|
-
return `${MODULE_FEDERATION_LOG_PREFIX} ${message}`;
|
|
31
|
-
}
|
|
32
|
-
function createModuleFederationError(message) {
|
|
33
|
-
return new Error(formatModuleFederationMessage(message));
|
|
34
|
-
}
|
|
35
|
-
function toConsoleArgs(message, rest = []) {
|
|
36
|
-
if (typeof message === "string") return [formatModuleFederationMessage(message), ...rest];
|
|
37
|
-
if (message === void 0) return [MODULE_FEDERATION_LOG_PREFIX, ...rest];
|
|
38
|
-
return [
|
|
39
|
-
MODULE_FEDERATION_LOG_PREFIX,
|
|
40
|
-
message,
|
|
41
|
-
...rest
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
const moduleFederationConsole = {
|
|
45
|
-
log(message, ...rest) {
|
|
46
|
-
console.log(...toConsoleArgs(message, rest));
|
|
47
|
-
},
|
|
48
|
-
warn(message, ...rest) {
|
|
49
|
-
console.warn(...toConsoleArgs(message, rest));
|
|
50
|
-
},
|
|
51
|
-
error(message, ...rest) {
|
|
52
|
-
console.error(...toConsoleArgs(message, rest));
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
moduleFederationConsole.log;
|
|
56
|
-
const mfWarn = moduleFederationConsole.warn;
|
|
57
|
-
const mfError = moduleFederationConsole.error;
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/utils/packageUtils.ts
|
|
60
|
-
const dependencyPresenceCache = /* @__PURE__ */ new Map();
|
|
61
|
-
let packageDetectionCwd;
|
|
62
|
-
function getDependencyCacheKey(cwd, dependencyName) {
|
|
63
|
-
return `${cwd}:${dependencyName}`;
|
|
64
|
-
}
|
|
65
|
-
function setPackageDetectionCwd(cwd) {
|
|
66
|
-
packageDetectionCwd = cwd;
|
|
67
|
-
}
|
|
68
|
-
function getPackageDetectionCwd() {
|
|
69
|
-
return packageDetectionCwd || process.cwd();
|
|
70
|
-
}
|
|
71
|
-
const DEFAULT_EXPORT_CONDITIONS = [
|
|
72
|
-
"browser",
|
|
73
|
-
"import",
|
|
74
|
-
"module",
|
|
75
|
-
"default",
|
|
76
|
-
"require"
|
|
77
|
-
];
|
|
78
|
-
function resolveExportsEntry(exportsField, conditions = DEFAULT_EXPORT_CONDITIONS) {
|
|
79
|
-
if (typeof exportsField === "string") return exportsField;
|
|
80
|
-
if (!exportsField || typeof exportsField !== "object") return void 0;
|
|
81
|
-
const record = exportsField;
|
|
82
|
-
const rootExport = record["."];
|
|
83
|
-
if (rootExport) return resolveExportsEntry(rootExport);
|
|
84
|
-
for (const condition of conditions) {
|
|
85
|
-
const target = resolveExportsEntry(record[condition], conditions);
|
|
86
|
-
if (target) return target;
|
|
87
|
-
}
|
|
88
|
-
for (const target of Object.values(record)) {
|
|
89
|
-
const resolved = resolveExportsEntry(target, conditions);
|
|
90
|
-
if (resolved) return resolved;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function getPackageExportsTarget(pkg, packageName, exportsField) {
|
|
94
|
-
if (typeof exportsField === "string") return pkg === packageName ? exportsField : void 0;
|
|
95
|
-
if (!exportsField || typeof exportsField !== "object") return void 0;
|
|
96
|
-
const record = exportsField;
|
|
97
|
-
const subpath = pkg === packageName ? "." : `.${pkg.slice(packageName.length)}`;
|
|
98
|
-
if (subpath !== ".") return record[subpath];
|
|
99
|
-
return record["."] ?? (!Object.keys(record).some((key) => key.startsWith(".")) ? record : void 0);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Escaping rules:
|
|
103
|
-
* Convert using the format __${mapping}__, where _ and $ are not allowed in npm package names but can be used in variable names.
|
|
104
|
-
* @ => 1
|
|
105
|
-
* / => 2
|
|
106
|
-
* - => 3
|
|
107
|
-
* . => 4
|
|
108
|
-
*/
|
|
109
|
-
/**
|
|
110
|
-
* Encodes a package name into a valid file name.
|
|
111
|
-
* @param {string} name - The package name, e.g., "@scope/xx-xx.xx".
|
|
112
|
-
* @returns {string} - The encoded file name.
|
|
113
|
-
*/
|
|
114
|
-
function packageNameEncode(name) {
|
|
115
|
-
if (typeof name !== "string") throw createModuleFederationError("A string package name is required");
|
|
116
|
-
return name.replace(/@/g, "_mf_0_").replace(/\//g, "_mf_1_").replace(/-/g, "_mf_2_").replace(/\./g, "_mf_3_");
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Decodes an encoded file name back to the original package name.
|
|
120
|
-
* @param {string} encoded - The encoded file name, e.g., "_mf_0_scope_mf_1_xx_mf_2_xx_mf_3_xx".
|
|
121
|
-
* @returns {string} - The decoded package name.
|
|
122
|
-
*/
|
|
123
|
-
function packageNameDecode(encoded) {
|
|
124
|
-
if (typeof encoded !== "string") throw createModuleFederationError("A string encoded file name is required");
|
|
125
|
-
return encoded.replace(/_mf_0_/g, "@").replace(/_mf_1_/g, "/").replace(/_mf_2_/g, "-").replace(/_mf_3_/g, ".");
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Removes any subpath from an npm package specifier and returns the package name only.
|
|
129
|
-
* @param {string} packageString - The package specifier, e.g., "@scope/pkg/runtime" or "react/jsx-runtime".
|
|
130
|
-
* @returns {string} - The base npm package name.
|
|
131
|
-
*/
|
|
132
|
-
function getPackageName(packageString) {
|
|
133
|
-
const match = packageString.match(/^(?:@[^/]+\/)?[^/]+/);
|
|
134
|
-
return match ? match[0] : packageString;
|
|
135
|
-
}
|
|
136
|
-
function getPackageNameFromNodeModulePath(source) {
|
|
137
|
-
const normalized = source.replace(/\\/g, "/");
|
|
138
|
-
const nodeModulesIndex = normalized.lastIndexOf("/node_modules/");
|
|
139
|
-
if (nodeModulesIndex < 0) return;
|
|
140
|
-
const parts = normalized.slice(nodeModulesIndex + 14).split("/");
|
|
141
|
-
if (!parts[0]) return;
|
|
142
|
-
if (parts[0].startsWith("@")) return parts[1] ? `${parts[0]}/${parts[1]}` : void 0;
|
|
143
|
-
return parts[0];
|
|
144
|
-
}
|
|
145
|
-
function getSharedCacheKey(pkg, shareItem) {
|
|
146
|
-
return shareItem.shareConfig.singleton || !shareItem.version ? pkg : `${pkg}@${shareItem.version}`;
|
|
147
|
-
}
|
|
148
|
-
function getInstalledPackageJson(pkg, opts) {
|
|
149
|
-
const cwd = opts?.cwd || getPackageDetectionCwd();
|
|
150
|
-
const packageName = opts?.packageName || getPackageName(pkg);
|
|
151
|
-
const tryReadPackageJson = (packageJsonPath) => {
|
|
152
|
-
if (!(0, fs.existsSync)(packageJsonPath)) return void 0;
|
|
153
|
-
try {
|
|
154
|
-
return {
|
|
155
|
-
path: packageJsonPath,
|
|
156
|
-
dir: pathe.default.dirname(packageJsonPath),
|
|
157
|
-
packageJson: JSON.parse((0, fs.readFileSync)(packageJsonPath, "utf-8"))
|
|
158
|
-
};
|
|
159
|
-
} catch {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
const findPackageInPnpmStore = (startDir) => {
|
|
164
|
-
let currentDir = startDir;
|
|
165
|
-
const rootDir = pathe.default.parse(currentDir).root;
|
|
166
|
-
while (true) {
|
|
167
|
-
const pnpmStoreDir = pathe.default.join(currentDir, "node_modules", ".pnpm");
|
|
168
|
-
if ((0, fs.existsSync)(pnpmStoreDir)) try {
|
|
169
|
-
for (const entry of (0, fs.readdirSync)(pnpmStoreDir, { withFileTypes: true })) {
|
|
170
|
-
if (!entry.isDirectory()) continue;
|
|
171
|
-
const candidate = tryReadPackageJson(pathe.default.join(pnpmStoreDir, entry.name, "node_modules", packageName, "package.json"));
|
|
172
|
-
if (candidate?.packageJson.name === packageName) return candidate;
|
|
173
|
-
}
|
|
174
|
-
} catch {}
|
|
175
|
-
if (currentDir === rootDir) break;
|
|
176
|
-
currentDir = pathe.default.dirname(currentDir);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
try {
|
|
180
|
-
const projectRequire = (0, module$1.createRequire)(new URL(`file://${pathe.default.join(cwd, "package.json")}`));
|
|
181
|
-
let resolvedPath;
|
|
182
|
-
if (opts?.fromResolvedEntry) resolvedPath = opts.fromResolvedEntry;
|
|
183
|
-
else try {
|
|
184
|
-
resolvedPath = projectRequire.resolve(pkg);
|
|
185
|
-
} catch {
|
|
186
|
-
resolvedPath = projectRequire.resolve(packageName);
|
|
187
|
-
}
|
|
188
|
-
let currentDir = pathe.default.dirname(resolvedPath);
|
|
189
|
-
const rootDir = pathe.default.parse(currentDir).root;
|
|
190
|
-
while (true) {
|
|
191
|
-
const packageJsonPath = pathe.default.join(currentDir, "package.json");
|
|
192
|
-
if ((0, fs.existsSync)(packageJsonPath)) {
|
|
193
|
-
const packageJsonContent = (0, fs.readFileSync)(packageJsonPath, "utf-8");
|
|
194
|
-
try {
|
|
195
|
-
const packageJson = JSON.parse(packageJsonContent);
|
|
196
|
-
if (packageJson.name === packageName) return {
|
|
197
|
-
path: packageJsonPath,
|
|
198
|
-
dir: currentDir,
|
|
199
|
-
packageJson
|
|
200
|
-
};
|
|
201
|
-
} catch (error) {
|
|
202
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (currentDir === rootDir) break;
|
|
206
|
-
currentDir = pathe.default.dirname(currentDir);
|
|
207
|
-
}
|
|
208
|
-
} catch {
|
|
209
|
-
let currentDir = cwd;
|
|
210
|
-
const rootDir = pathe.default.parse(currentDir).root;
|
|
211
|
-
while (true) {
|
|
212
|
-
const directCandidate = tryReadPackageJson(pathe.default.join(currentDir, "node_modules", packageName, "package.json"));
|
|
213
|
-
if (directCandidate?.packageJson.name === packageName) return directCandidate;
|
|
214
|
-
if (currentDir === rootDir) break;
|
|
215
|
-
currentDir = pathe.default.dirname(currentDir);
|
|
216
|
-
}
|
|
217
|
-
return findPackageInPnpmStore(cwd);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
function getInstalledPackageEntry(pkg, opts) {
|
|
221
|
-
const installed = getInstalledPackageJson(pkg, opts);
|
|
222
|
-
if (!installed) return void 0;
|
|
223
|
-
const cwd = opts?.cwd || getPackageDetectionCwd();
|
|
224
|
-
const packageName = opts?.packageName || getPackageName(pkg);
|
|
225
|
-
if (pkg !== packageName && opts?.resolveSubpathWithRequire !== false) try {
|
|
226
|
-
return (0, module$1.createRequire)(new URL(`file://${pathe.default.join(cwd, "package.json")}`)).resolve(pkg);
|
|
227
|
-
} catch {}
|
|
228
|
-
const packageJson = installed.packageJson;
|
|
229
|
-
const explicitEntry = resolveExportsEntry(getPackageExportsTarget(pkg, packageName, packageJson.exports), opts?.conditions) || (typeof packageJson.module === "string" ? packageJson.module : void 0) || (typeof packageJson.main === "string" ? packageJson.main : void 0) || "index.js";
|
|
230
|
-
return pathe.default.join(installed.dir, explicitEntry);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Detect whether the current runtime is Vite 8+ by checking for a Vite version flag
|
|
234
|
-
* on the plugin hook context, with Rolldown metadata kept as a compatibility fallback.
|
|
235
|
-
*/
|
|
236
|
-
function getIsRolldown(ctx) {
|
|
237
|
-
const viteVersion = ctx?.meta?.viteVersion;
|
|
238
|
-
const viteMajor = Number(String(viteVersion ?? "").split(".")[0]);
|
|
239
|
-
return Number.isFinite(viteMajor) && viteMajor >= 8 || !!ctx?.meta?.rolldownVersion;
|
|
240
|
-
}
|
|
241
|
-
/** Walk up from Vite `config.root` (Nuxt may point at `.nuxt` cache dirs). */
|
|
242
|
-
function isNuxtProjectRoot(root) {
|
|
243
|
-
let dir = root;
|
|
244
|
-
for (let i = 0; i < 8; i++) {
|
|
245
|
-
if (hasPackageDependency("nuxt", dir) || hasPackageDependency("nuxt-nightly", dir)) return true;
|
|
246
|
-
const parent = pathe.default.dirname(dir);
|
|
247
|
-
if (parent === dir) break;
|
|
248
|
-
dir = parent;
|
|
249
|
-
}
|
|
250
|
-
return false;
|
|
251
|
-
}
|
|
252
|
-
function hasPackageDependency(dependencyName, cwd = packageDetectionCwd || process.cwd()) {
|
|
253
|
-
const cacheKey = getDependencyCacheKey(cwd, dependencyName);
|
|
254
|
-
const cached = dependencyPresenceCache.get(cacheKey);
|
|
255
|
-
if (cached !== void 0) return cached;
|
|
256
|
-
try {
|
|
257
|
-
const packageJson = JSON.parse((0, fs.readFileSync)(pathe.default.join(cwd, "package.json"), "utf8"));
|
|
258
|
-
const hasDependency = [
|
|
259
|
-
packageJson.dependencies,
|
|
260
|
-
packageJson.devDependencies,
|
|
261
|
-
packageJson.peerDependencies,
|
|
262
|
-
packageJson.optionalDependencies
|
|
263
|
-
].some((deps) => !!deps?.[dependencyName]);
|
|
264
|
-
dependencyPresenceCache.set(cacheKey, hasDependency);
|
|
265
|
-
return hasDependency;
|
|
266
|
-
} catch {
|
|
267
|
-
dependencyPresenceCache.set(cacheKey, false);
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
//#endregion
|
|
272
|
-
Object.defineProperty(exports, "__toESM", {
|
|
273
|
-
enumerable: true,
|
|
274
|
-
get: function() {
|
|
275
|
-
return __toESM;
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
Object.defineProperty(exports, "createModuleFederationError", {
|
|
279
|
-
enumerable: true,
|
|
280
|
-
get: function() {
|
|
281
|
-
return createModuleFederationError;
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
Object.defineProperty(exports, "getInstalledPackageEntry", {
|
|
285
|
-
enumerable: true,
|
|
286
|
-
get: function() {
|
|
287
|
-
return getInstalledPackageEntry;
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
Object.defineProperty(exports, "getInstalledPackageJson", {
|
|
291
|
-
enumerable: true,
|
|
292
|
-
get: function() {
|
|
293
|
-
return getInstalledPackageJson;
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
Object.defineProperty(exports, "getIsRolldown", {
|
|
297
|
-
enumerable: true,
|
|
298
|
-
get: function() {
|
|
299
|
-
return getIsRolldown;
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
Object.defineProperty(exports, "getPackageDetectionCwd", {
|
|
303
|
-
enumerable: true,
|
|
304
|
-
get: function() {
|
|
305
|
-
return getPackageDetectionCwd;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
Object.defineProperty(exports, "getPackageName", {
|
|
309
|
-
enumerable: true,
|
|
310
|
-
get: function() {
|
|
311
|
-
return getPackageName;
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
Object.defineProperty(exports, "getPackageNameFromNodeModulePath", {
|
|
315
|
-
enumerable: true,
|
|
316
|
-
get: function() {
|
|
317
|
-
return getPackageNameFromNodeModulePath;
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
Object.defineProperty(exports, "getSharedCacheKey", {
|
|
321
|
-
enumerable: true,
|
|
322
|
-
get: function() {
|
|
323
|
-
return getSharedCacheKey;
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
Object.defineProperty(exports, "hasPackageDependency", {
|
|
327
|
-
enumerable: true,
|
|
328
|
-
get: function() {
|
|
329
|
-
return hasPackageDependency;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
Object.defineProperty(exports, "isNuxtProjectRoot", {
|
|
333
|
-
enumerable: true,
|
|
334
|
-
get: function() {
|
|
335
|
-
return isNuxtProjectRoot;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
Object.defineProperty(exports, "mfError", {
|
|
339
|
-
enumerable: true,
|
|
340
|
-
get: function() {
|
|
341
|
-
return mfError;
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
Object.defineProperty(exports, "mfWarn", {
|
|
345
|
-
enumerable: true,
|
|
346
|
-
get: function() {
|
|
347
|
-
return mfWarn;
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
Object.defineProperty(exports, "packageNameDecode", {
|
|
351
|
-
enumerable: true,
|
|
352
|
-
get: function() {
|
|
353
|
-
return packageNameDecode;
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
Object.defineProperty(exports, "packageNameEncode", {
|
|
357
|
-
enumerable: true,
|
|
358
|
-
get: function() {
|
|
359
|
-
return packageNameEncode;
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
Object.defineProperty(exports, "setPackageDetectionCwd", {
|
|
363
|
-
enumerable: true,
|
|
364
|
-
get: function() {
|
|
365
|
-
return setPackageDetectionCwd;
|
|
366
|
-
}
|
|
367
|
-
});
|