MCPcopy
hub / github.com/vitejs/vite / createBenchPlugin

Function createBenchPlugin

packages/vite/scripts/benchCircularImport.ts:110–135  ·  view source on GitHub ↗
(graph: SyntheticGraph)

Source from the content-addressed store, hash-verified

108const BENCH_PREFIX = '/bench/'
109
110function createBenchPlugin(graph: SyntheticGraph) {
111 return {
112 name: 'bench-circular-import',
113
114 resolveId(id: string) {
115 if (id.startsWith(BENCH_PREFIX)) {
116 // Return a virtual module id (null-byte prefix prevents fs lookup)
117 return `\0${id}`
118 }
119 },
120
121 load(id: string) {
122 if (id.startsWith(`\0${BENCH_PREFIX}`)) {
123 const realId = id.slice(1)
124 const deps = graph.edges.get(realId)
125 if (deps) {
126 const lines = deps.map(
127 (dep, i) => `import { value as __dep_${i}__ } from "${dep}";`,
128 )
129 lines.push(`export const value = ${deps.length};`)
130 return lines.join('\n')
131 }
132 }
133 },
134 }
135}
136
137// ---------------------------------------------------------------------------
138// Benchmark runner

Callers 1

runBenchmarkFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected