-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathrpc-static.ts
29 lines (25 loc) · 1.08 KB
/
rpc-static.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { QueryEnv, RpcFunctions } from '../../types'
const dataCache = new Map<string, Promise<any>>()
function fetchJson(url: string): Promise<any> {
if (!dataCache.has(url))
dataCache.set(url, fetch(url).then(r => r.json()))
return dataCache.get(url)!
}
export function createStaticRpcClient(): RpcFunctions {
async function getModuleTransformInfo(query: QueryEnv, id: string) {
const { hash } = await import('ohash')
return fetchJson(`./reports/${query.vite}-${query.env}/transforms/${hash(id)}.json`)
}
return {
getMetadata: () => fetchJson('./reports/metadata.json'),
getModulesList: query => fetchJson(`./reports/${query.vite}-${query.env}/modules.json`),
getPluginMetrics: query => fetchJson(`./reports/${query.vite}-${query.env}/metric-plugins.json`),
getModuleTransformInfo,
resolveId: (query, id) => getModuleTransformInfo(query, id).then(r => r.resolvedId),
onModuleUpdated: async () => undefined,
getServerMetrics: async () => ({}),
getWaterfallInfo: async () => ({}),
getHmrEvents: async () => [],
list: () => null!,
}
}