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

Function doTransform

packages/vite/src/node/server/transformRequest.ts:150–207  ·  view source on GitHub ↗
(
  environment: DevEnvironment,
  url: string,
  options: TransformOptionsInternal,
  timestamp: number,
)

Source from the content-addressed store, hash-verified

148}
149
150async function doTransform(
151 environment: DevEnvironment,
152 url: string,
153 options: TransformOptionsInternal,
154 timestamp: number,
155) {
156 const { pluginContainer } = environment
157
158 let module = await environment.moduleGraph.getModuleByUrl(url)
159 if (module) {
160 // try use cache from url
161 const cached = await getCachedTransformResult(
162 environment,
163 url,
164 module,
165 timestamp,
166 )
167 if (cached) return cached
168 }
169
170 const resolved = module
171 ? undefined
172 : ((await pluginContainer.resolveId(url, undefined)) ?? undefined)
173
174 // resolve
175 const id = module?.id ?? resolved?.id ?? url
176
177 module ??= environment.moduleGraph.getModuleById(id)
178 if (module) {
179 // if a different url maps to an existing loaded id, make sure we relate this url to the id
180 await environment.moduleGraph._ensureEntryFromUrl(url, undefined, resolved)
181 // try use cache from id
182 const cached = await getCachedTransformResult(
183 environment,
184 url,
185 module,
186 timestamp,
187 )
188 if (cached) return cached
189 }
190
191 const result = loadAndTransform(
192 environment,
193 id,
194 url,
195 options,
196 timestamp,
197 module,
198 resolved,
199 )
200
201 const { depsOptimizer } = environment
202 if (!depsOptimizer?.isOptimizedDepFile(id)) {
203 environment._registerRequestProcessing(id, () => result)
204 }
205
206 return result
207}

Callers 1

transformRequestFunction · 0.85

Calls 7

getCachedTransformResultFunction · 0.85
loadAndTransformFunction · 0.85
_ensureEntryFromUrlMethod · 0.80
getModuleByUrlMethod · 0.45
resolveIdMethod · 0.45
getModuleByIdMethod · 0.45

Tested by

no test coverage detected