directRequest() — vite Function Reference
Architecture documentation for the directRequest() function in runner.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 2299eb48_afeb_b0e8_8b25_f24d005c00d4["directRequest()"] 1d3ff778_7ac6_0038_640f_997e968c3c8f["ModuleRunner"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|defined in| 1d3ff778_7ac6_0038_640f_997e968c3c8f 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e["cachedRequest()"] 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|calls| 2299eb48_afeb_b0e8_8b25_f24d005c00d4 1ca5cbd8_3591_8042_7bb5_fed80a4ac932["cachedModule()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| 1ca5cbd8_3591_8042_7bb5_fed80a4ac932 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e["cachedRequest()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e c112c314_3799_38c3_1ecc_d56fb8562692["runExternalModule()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| c112c314_3799_38c3_1ecc_d56fb8562692 10b9dea8_362c_1af2_93be_afa4dd9aed9e["cleanUrl()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| 10b9dea8_362c_1af2_93be_afa4dd9aed9e b4ab10d7_7a96_e400_2c45_786b44953214["posixPathToFileHref()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| b4ab10d7_7a96_e400_2c45_786b44953214 68cc8eb1_65b1_d39b_493d_786828281dad["exportAll()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| 68cc8eb1_65b1_d39b_493d_786828281dad b7db8dad_5087_15c0_4295_7bd1de779635["runInlinedModule()"] 2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| b7db8dad_5087_15c0_4295_7bd1de779635 style 2299eb48_afeb_b0e8_8b25_f24d005c00d4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/vite/src/module-runner/runner.ts lines 329–428
protected async directRequest(
url: string,
mod: EvaluatedModuleNode,
_callstack: string[],
): Promise<any> {
const fetchResult = mod.meta!
const moduleId = fetchResult.id
const callstack = [..._callstack, moduleId]
const request = async (dep: string, metadata?: SSRImportMetadata) => {
const importer = ('file' in fetchResult && fetchResult.file) || moduleId
const depMod = await this.cachedModule(dep, importer)
depMod.importers.add(moduleId)
mod.imports.add(depMod.id)
return this.cachedRequest(dep, depMod, callstack, metadata)
}
const dynamicRequest = async (dep: string) => {
// it's possible to provide an object with toString() method inside import()
dep = String(dep)
if (dep[0] === '.') {
dep = posixResolve(posixDirname(url), dep)
}
return request(dep, { isDynamicImport: true })
}
if ('externalize' in fetchResult) {
const { externalize } = fetchResult
this.debug?.('[module runner] externalizing', externalize)
const exports = await this.evaluator.runExternalModule(externalize)
mod.exports = exports
return exports
}
const { code, file } = fetchResult
if (code == null) {
const importer = callstack[callstack.length - 2]
throw new Error(
`[module runner] Failed to load "${url}"${
importer ? ` imported from ${importer}` : ''
}`,
)
}
const createImportMeta =
this.options.createImportMeta ?? createDefaultImportMeta
const modulePath = cleanUrl(file || moduleId)
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
const href = posixPathToFileHref(modulePath)
const meta = await createImportMeta(modulePath)
const exports = Object.create(null)
Object.defineProperty(exports, Symbol.toStringTag, {
value: 'Module',
enumerable: false,
configurable: false,
})
mod.exports = exports
let hotContext: ViteHotContext | undefined
if (this.hmrClient) {
Object.defineProperty(meta, 'hot', {
enumerable: true,
get: () => {
if (!this.hmrClient) {
throw new Error(`[module runner] HMR client was closed.`)
}
this.debug?.('[module runner] creating hmr context for', mod.url)
hotContext ||= new HMRContext(this.hmrClient, mod.url)
return hotContext
},
set: (value) => {
hotContext = value
},
})
}
const context: ModuleRunnerContext = {
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does directRequest() do?
directRequest() is a function in the vite codebase, defined in packages/vite/src/module-runner/runner.ts.
Where is directRequest() defined?
directRequest() is defined in packages/vite/src/module-runner/runner.ts at line 329.
What does directRequest() call?
directRequest() calls 7 function(s): cachedModule, cachedRequest, cleanUrl, exportAll, posixPathToFileHref, runExternalModule, runInlinedModule.
What calls directRequest()?
directRequest() is called by 1 function(s): cachedRequest.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free