PageSourceSearch

https://one95.app/assets/ssrVmStrategy-CkmYR5_u-C-faKevv.js

js one95.app collected 2026-10-04 23:29:07 UTC 11,474 bytes, 318 lines download raw bytes

1import { t as __vitePreload } from "./vite-preload-helper-CJkh2MBB.js";
2import { SsrEntryHttpError, n as fetchWithTimeout, neutralizeBrowserPreloadHelpers, r as readResponseTextBounded } from "./ssrEntryLoader-JXMUfFqx.js";
3//#region ../../node_modules/.pnpm/@[email protected][email protected][email protected]_@[email protected]_sass-emb_ddff83de1567196e25740b308c9ada79/node_modules/@module-federation/vite/lib/sharedKeyMatcher-DiUzRVH1.js
4var COMMON_SHARED_SUBPATHS = {
5	react: [
6		"react/jsx-runtime",
7		"react/jsx-dev-runtime",
8		"react/compiler-runtime"
9	],
10	"react-dom": ["react-dom/client", "react-dom/profiling"],
11	"solid-js": [
12		"solid-js/web",
13		"solid-js/store",
14		"solid-js/html",
15		"solid-js/h",
16		"solid-js/jsx-runtime",
17		"solid-js/jsx-dev-runtime"
18	],
19	zustand: [
20		"zustand/vanilla",
21		"zustand/react",
22		"zustand/middleware",
23		"zustand/shallow"
24	]
25};
26var VITE_DEFAULT_ASSET_TYPES = [
27	"apng",
28	"bmp",
29	"png",
30	"jpe?g",
31	"jfif",
32	"pjpeg",
33	"pjp",
34	"gif",
35	"svg",
36	"ico",
37	"webp",
38	"avif",
39	"cur",
40	"jxl",
41	"mp4",
42	"webm",
43	"ogg",
44	"mp3",
45	"wav",
46	"flac",
47	"aac",
48	"opus",
49	"mov",
50	"m4a",
51	"vtt",
52	"woff2?",
53	"eot",
54	"ttf",
55	"otf",
56	"webmanifest",
57	"pdf",
58	"txt"
59];
60new RegExp(`\\.(${[...[
61	"css",
62	"scss",
63	"sass",
64	"less",
65	"styl",
66	"stylus"
67], ...VITE_DEFAULT_ASSET_TYPES].join("|")})(?:[?#].*)?$`, "i");
68function removeTrailingSlash(value) {
69	return value.endsWith("/") ? value.slice(0, -1) : value;
70}
71function getCommonSharedSubpaths(sharedKey) {
72	return COMMON_SHARED_SUBPATHS[removeTrailingSlash(sharedKey)] || [];
73}
74var emptySharedKeyMatcher = { find: () => void 0 };
75var sharedKeyMatcherCache = /* @__PURE__ */ new WeakMap();
76function findSharedKey(source, shared) {
77	return getSharedKeyMatcher(shared).find(source);
78}
79function pickLongestWildcardKey(wildcardKeys, source) {
80	let best;
81	for (const wildcard of wildcardKeys) {
82		if (source !== wildcard.base && !source.startsWith(`${wildcard.base}/`)) continue;
83		if (!best || wildcard.base.length > best.base.length || wildcard.base.length === best.base.length && wildcard.key.length > best.key.length) best = wildcard;
84	}
85	return best?.key;
86}
87function getSharedKeyMatcher(shared) {
88	if (!shared) return emptySharedKeyMatcher;
89	const cached = sharedKeyMatcherCache.get(shared);
90	if (cached) return cached;
91	const keys = Object.keys(shared);
92	const exactKeys = new Set(keys);
93	const commonSubpathKeys = /* @__PURE__ */ new Map();
94	const wildcardKeys = [];
95	let vueKey;
96	for (const key of keys) {
97		const keyBase = key.endsWith("/") ? key.slice(0, -1) : key;
98		const shareItem = shared[key];
99		if (!vueKey && keyBase === "vue") vueKey = key;
100		if (key.endsWith("/")) wildcardKeys.push({
101			key,
102			base: keyBase
103		});
104		if (shareItem?.shareConfig?.import !== false) {
105			for (const subpath of getCommonSharedSubpaths(keyBase)) if (!commonSubpathKeys.has(subpath)) commonSubpathKeys.set(subpath, key);
106		}
107	}
108	const sourceCache = /* @__PURE__ */ new Map();
109	const matcher = { find(source) {
110		if (sourceCache.has(source)) return sourceCache.get(source);
111		let result = exactKeys.has(source) ? source : void 0;
112		if (!result && vueKey) {
113			if (source === "vue/dist/vue.esm-bundler.js" || source === "vue/dist/vue.runtime.esm-bundler.js") result = vueKey;
114		}
115		if (!result) result = commonSubpathKeys.get(source);
116		if (!result) result = pickLongestWildcardKey(wildcardKeys, source);
117		sourceCache.set(source, result);
118		return result;
119	} };
120	sharedKeyMatcherCache.set(shared, matcher);
121	return matcher;
122}
123//#endregion
124//#region ../../node_modules/.pnpm/@[email protected][email protected][email protected]_@[email protected]_sass-emb_ddff83de1567196e25740b308c9ada79/node_modules/@module-federation/vite/lib/ssrVmStrategy-CkmYR5_u.js
125/**
126* vm.SourceTextModule strategy for loading remote SSR entries.
127*
128* Unlike the temp-file strategy (which rewrites bare shared imports to
129* host-resolved file:// paths at fetch time), this strategy evaluates the
130* remote's ESM graph with `vm.SourceTextModule` in the current context and
131* resolves bare imports through a linker, in order:
132*
133*  1. The host's federation share scope — `instance.loadShare(name)` on the
134*     global `__FEDERATION__` instances. This restores real share-scope
135*     semantics (version negotiation, loaded-first reuse) on the server.
136*  2. The build-time `resolvedShared` file map (same source as the temp-file
137*     strategy) as a fallback when no instance shares the package.
138*  3. Plain host `import(specifier)` for everything else (node builtins,
139*     packages the remote expects the host to provide).
140*
141* Requires Node with `--experimental-vm-modules`; callers must check
142* `isVmStrategyAvailable()` and fall back to the temp-file strategy when the
143* API is missing.
144*/
145var vmApiPromise;
146async function getVmApi() {
147	if (!vmApiPromise) vmApiPromise = (async () => {
148		try {
149			const vm = await __vitePreload(() => import(
150				/* @vite-ignore */
151				"vm"
152), []);
153			if (typeof vm.SourceTextModule !== "function" || typeof vm.SyntheticModule !== "function") return null;
154			return vm;
155		} catch {
156			return null;
157		}
158	})();
159	return vmApiPromise;
160}
161async function isVmStrategyAvailable() {
162	return await getVmApi() !== null;
163}
164function findVmSharedKey(specifier, shared) {
165	return findSharedKey(specifier, shared);
166}
167function getFederationInstances() {
168	return globalThis.__FEDERATION__?.__INSTANCES__ ?? [];
169}
170/**
171* Resolve a bare specifier to a module namespace: share scope first, then the
172* build-time resolvedShared file map, then plain host import.
173*/
174async function loadBareModule(specifier, options) {
175	const owner = options.federationInstance;
176	const instances = owner ? [owner] : getFederationInstances();
177	for (const instance of instances) {
178		if (typeof instance?.loadShare !== "function") continue;
179		const shared = instance.options?.shared;
180		const sharedKey = findVmSharedKey(specifier, shared);
181		const shareConfig = sharedKey ? shared?.[sharedKey] : void 0;
182		if (!shareConfig) continue;
183		if (!(Array.isArray(shareConfig.scope) ? shareConfig.scope : [shareConfig.scope ?? "default"]).includes(options.shareScopeName)) continue;
184		try {
185			const factory = await instance.loadShare(specifier);
186			if (typeof factory === "function") {
187				const shared = factory();
188				if (shared) return shared;
189			}
190		} catch {}
191	}
192	const resolvedPath = options.resolvedShared[specifier];
193	if (resolvedPath) return __vitePreload(() => import(
194		/* @vite-ignore */
195		`file://${resolvedPath}`
196), []);
197	return __vitePreload(() => import(
198		/* @vite-ignore */
199		specifier
200), []);
201}
202function createSyntheticModule(vm, specifier, namespace) {
203	const source = namespace && typeof namespace === "object" ? namespace : { default: namespace };
204	const exportNames = new Set(Object.keys(source));
205	exportNames.add("default");
206	const syntheticModule = new vm.SyntheticModule([...exportNames], () => {
207		for (const exportName of exportNames) if (exportName === "default") syntheticModule.setExport("default", source.default !== void 0 ? source.default : namespace);
208		else syntheticModule.setExport(exportName, source[exportName]);
209	}, { identifier: `mf-shared:${specifier}` });
210	return syntheticModule;
211}
212var httpModuleCache = /* @__PURE__ */ new Map();
213var namespaceCache = /* @__PURE__ */ new Map();
214var linkQueues = /* @__PURE__ */ new WeakMap();
215var contextIds = /* @__PURE__ */ new WeakMap();
216var nextContextId = 1;
217function getContextId(context) {
218	let id = contextIds.get(context);
219	if (id === void 0) {
220		id = nextContextId++;
221		contextIds.set(context, id);
222	}
223	return id;
224}
225function getVmCacheContextKey(options) {
226	return JSON.stringify([
227		getContextId(options.cacheContext),
228		options.shareScopeName,
229		Object.entries(options.resolvedShared).sort(([left], [right]) => left.localeCompare(right))
230	]);
231}
232function getBodyPreview(body) {
233	return body.slice(0, 240).replace(/\s+/g, " ").trim();
234}
235async function fetchModuleSource(url, fetchTimeoutMs, fetchMaxBytes) {
236	const res = await fetchWithTimeout(url, {}, fetchTimeoutMs);
237	const text = await readResponseTextBounded(res, fetchMaxBytes ?? 10485760, url);
238	if (!res.ok) throw new SsrEntryHttpError(url, res.status, res.statusText, getBodyPreview(text));
239	return neutralizeBrowserPreloadHelpers(text);
240}
241function isHttpUrl(value) {
242	return value.startsWith("http://") || value.startsWith("https://");
243}
244/** Resolve a specifier against the referencing module's URL; null for bare specifiers. */
245function resolveSpecifierUrl(specifier, referencerUrl) {
246	if (isHttpUrl(specifier)) return specifier;
247	if (specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/")) return new URL(specifier, referencerUrl).href;
248	return null;
249}
250function getHttpModule(vm, url, options) {
251	const cacheKey = JSON.stringify([
252		getVmCacheContextKey(options),
253		options.fetchTimeoutMs ?? 1e4,
254		options.fetchMaxBytes ?? 10485760,
255		options.versionKey,
256		url
257	]);
258	if (!httpModuleCache.has(cacheKey)) httpModuleCache.set(cacheKey, (async () => {
259		const code = await fetchModuleSource(url, options.fetchTimeoutMs, options.fetchMaxBytes);
260		return new vm.SourceTextModule(code, {
261			identifier: url,
262			initializeImportMeta(meta) {
263				meta.url = url;
264			},
265			importModuleDynamically: (specifier, referencingModule) => importDynamically(vm, specifier, referencingModule, options)
266		});
267	})().catch((error) => {
268		httpModuleCache.delete(cacheKey);
269		throw error;
270	}));
271	return httpModuleCache.get(cacheKey);
272}
273async function linkModule(vm, specifier, referencingModule, options) {
274	const url = resolveSpecifierUrl(specifier, referencingModule.identifier);
275	if (url) return getHttpModule(vm, url, options);
276	return createSyntheticModule(vm, specifier, await loadBareModule(specifier, options));
277}
278async function linkModuleGraph(module, linker, cacheContext) {
279	const current = (linkQueues.get(cacheContext) ?? Promise.resolve()).catch(() => {}).then(async () => {
280		if (module.status === "unlinked") await module.link(linker);
281	});
282	linkQueues.set(cacheContext, current);
283	try {
284		await current;
285	} finally {
286		if (linkQueues.get(cacheContext) === current) linkQueues.delete(cacheContext);
287	}
288}
289async function importDynamically(vm, specifier, referencingModule, options) {
290	const linker = (spec, referencer) => linkModule(vm, spec, referencer, options);
291	const module = await linker(specifier, referencingModule);
292	await linkModuleGraph(module, linker, options.cacheContext);
293	if (module.status === "linked") await module.evaluate();
294	return module;
295}
296/**
297* Load and evaluate a remote SSR entry as a `vm.SourceTextModule` graph and
298* return its namespace (the federation container with `init`/`get`).
299* Returns null when the vm module APIs are unavailable.
300*/
301async function loadViaVmStrategy(entryUrl, options) {
302	const vm = await getVmApi();
303	if (!vm) return null;
304	const cacheKey = `${getVmCacheContextKey(options)}::${options.versionKey}::${entryUrl}`;
305	if (!namespaceCache.has(cacheKey)) namespaceCache.set(cacheKey, (async () => {
306		const entryModule = await getHttpModule(vm, entryUrl, options);
307		const linker = (specifier, referencingModule) => linkModule(vm, specifier, referencingModule, options);
308		await linkModuleGraph(entryModule, linker, options.cacheContext);
309		if (entryModule.status === "linked") await entryModule.evaluate();
310		return entryModule.namespace;
311	})().catch((error) => {
312		namespaceCache.delete(cacheKey);
313		throw error;
314	}));
315	return namespaceCache.get(cacheKey);
316}
317//#endregion
318export { isVmStrategyAvailable, loadViaVmStrategy };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.