transformRequest() — vite Function Reference
Architecture documentation for the transformRequest() function in transformRequest.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 28d78764_00ba_3861_52d6_dc86fcde9e3a["transformRequest()"] ee4fcff9_3096_e290_234c_be9d1a2c8a4b["transformRequest.ts"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|defined in| ee4fcff9_3096_e290_234c_be9d1a2c8a4b c99812b1_1fd5_5046_98fa_678c5c80c0fb["transformRequest()"] c99812b1_1fd5_5046_98fa_678c5c80c0fb -->|calls| 28d78764_00ba_3861_52d6_dc86fcde9e3a 13770e2a_c6d8_fb1f_6562_e66de7bc1deb["transformMiddleware()"] 13770e2a_c6d8_fb1f_6562_e66de7bc1deb -->|calls| 28d78764_00ba_3861_52d6_dc86fcde9e3a 24ecf2a1_3c09_d451_76f3_9485b4e993f8["_createServer()"] 24ecf2a1_3c09_d451_76f3_9485b4e993f8 -->|calls| 28d78764_00ba_3861_52d6_dc86fcde9e3a c99812b1_1fd5_5046_98fa_678c5c80c0fb["transformRequest()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| c99812b1_1fd5_5046_98fa_678c5c80c0fb c42acd29_f3d2_c03f_de55_553d650a5fbf["throwClosedServerError()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| c42acd29_f3d2_c03f_de55_553d650a5fbf 74ee9886_2456_3964_e90e_5fc67925229d["monotonicDateNow()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| 74ee9886_2456_3964_e90e_5fc67925229d 3f57c8be_be57_4cf4_aa11_4ed077229c70["removeTimestampQuery()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| 3f57c8be_be57_4cf4_aa11_4ed077229c70 47338255_0359_1ee9_69c4_4c16cb66262e["getModuleByUrl()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| 47338255_0359_1ee9_69c4_4c16cb66262e 9bd7b32c_5b79_ac16_8541_4f64cc8ce19b["doTransform()"] 28d78764_00ba_3861_52d6_dc86fcde9e3a -->|calls| 9bd7b32c_5b79_ac16_8541_4f64cc8ce19b style 28d78764_00ba_3861_52d6_dc86fcde9e3a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/node/server/transformRequest.ts lines 77–147
export function transformRequest(
environment: DevEnvironment,
url: string,
options: TransformOptionsInternal = {},
): Promise<TransformResult | null> {
if (environment._closing && environment.config.dev.recoverable)
throwClosedServerError()
// This module may get invalidated while we are processing it. For example
// when a full page reload is needed after the re-processing of pre-bundled
// dependencies when a missing dep is discovered. We save the current time
// to compare it to the last invalidation performed to know if we should
// cache the result of the transformation or we should discard it as stale.
//
// A module can be invalidated due to:
// 1. A full reload because of pre-bundling newly discovered deps
// 2. A full reload after a config change
// 3. The file that generated the module changed
// 4. Invalidation for a virtual module
//
// For 1 and 2, a new request for this module will be issued after
// the invalidation as part of the browser reloading the page. For 3 and 4
// there may not be a new request right away because of HMR handling.
// In all cases, the next time this module is requested, it should be
// re-processed.
//
// We save the timestamp when we start processing and compare it with the
// last time this module is invalidated
const timestamp = monotonicDateNow()
url = removeTimestampQuery(url)
const pending = environment._pendingRequests.get(url)
if (pending) {
return environment.moduleGraph.getModuleByUrl(url).then((module) => {
if (!module || pending.timestamp > module.lastInvalidationTimestamp) {
// The pending request is still valid, we can safely reuse its result
return pending.request
} else {
// Request 1 for module A (pending.timestamp)
// Invalidate module A (module.lastInvalidationTimestamp)
// Request 2 for module A (timestamp)
// First request has been invalidated, abort it to clear the cache,
// then perform a new doTransform.
pending.abort()
return transformRequest(environment, url, options)
}
})
}
const request = doTransform(environment, url, options, timestamp)
// Avoid clearing the cache of future requests if aborted
let cleared = false
const clearCache = () => {
if (!cleared) {
environment._pendingRequests.delete(url)
cleared = true
}
}
// Cache the request and clear it once processing is done
environment._pendingRequests.set(url, {
request,
timestamp,
abort: clearCache,
})
return request.finally(clearCache)
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does transformRequest() do?
transformRequest() is a function in the vite codebase, defined in packages/vite/src/node/server/transformRequest.ts.
Where is transformRequest() defined?
transformRequest() is defined in packages/vite/src/node/server/transformRequest.ts at line 77.
What does transformRequest() call?
transformRequest() calls 6 function(s): doTransform, getModuleByUrl, monotonicDateNow, removeTimestampQuery, throwClosedServerError, transformRequest.
What calls transformRequest()?
transformRequest() is called by 3 function(s): _createServer, transformMiddleware, transformRequest.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free