ModuleNode Class — vite Architecture
Architecture documentation for the ModuleNode class in mixedModuleGraph.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD 8168c2c0_6927_0878_8876_5fb50d36ade9["ModuleNode"] cd2f5017_5d73_e10a_7c43_22b962517f0c["mixedModuleGraph.ts"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|defined in| cd2f5017_5d73_e10a_7c43_22b962517f0c 9a9dc712_60c4_c65b_885b_6bcb790c15f2["constructor()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 9a9dc712_60c4_c65b_885b_6bcb790c15f2 4215d885_b0c2_bfb5_601c_d7644d0bfcd4["_get()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 4215d885_b0c2_bfb5_601c_d7644d0bfcd4 25dc6156_33ff_8ead_2cd6_bd9a7f2a14dd["_set()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 25dc6156_33ff_8ead_2cd6_bd9a7f2a14dd 09c59943_148f_165b_467c_116c858a50ca["_wrapModuleSet()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 09c59943_148f_165b_467c_116c858a50ca 22f5b773_924c_1cf6_caaf_d894ee1a4c3c["_getModuleSetUnion()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 22f5b773_924c_1cf6_caaf_d894ee1a4c3c d4008aef_0d13_178a_065a_328b730fd8ed["_getModuleInfoUnion()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| d4008aef_0d13_178a_065a_328b730fd8ed 38895d1c_4e9c_143c_aa1a_6e913443453c["_getModuleObjectUnion()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 38895d1c_4e9c_143c_aa1a_6e913443453c bc2305c0_5093_7ee3_b68e_836c4d9f6f22["url()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| bc2305c0_5093_7ee3_b68e_836c4d9f6f22 371f0c03_667b_4bf5_7980_09eb8770583d["id()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 371f0c03_667b_4bf5_7980_09eb8770583d 5e9ecea2_b073_d56d_20e9_dca17b4faa61["file()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 5e9ecea2_b073_d56d_20e9_dca17b4faa61 d73a0495_bd7f_eafd_f85d_ba3fbb0241b8["type()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| d73a0495_bd7f_eafd_f85d_ba3fbb0241b8 3a4eb9e7_275b_dbf1_64d4_0626bd567229["info()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| 3a4eb9e7_275b_dbf1_64d4_0626bd567229 eb0f9ad5_3707_ef78_b89a_2d49c2278cfd["meta()"] 8168c2c0_6927_0878_8876_5fb50d36ade9 -->|method| eb0f9ad5_3707_ef78_b89a_2d49c2278cfd
Relationship Graph
Source Code
packages/vite/src/node/server/mixedModuleGraph.ts lines 20–226
export class ModuleNode {
_moduleGraph: ModuleGraph
_clientModule: EnvironmentModuleNode | undefined
_ssrModule: EnvironmentModuleNode | undefined
constructor(
moduleGraph: ModuleGraph,
clientModule?: EnvironmentModuleNode,
ssrModule?: EnvironmentModuleNode,
) {
this._moduleGraph = moduleGraph
this._clientModule = clientModule
this._ssrModule = ssrModule
}
_get<T extends keyof EnvironmentModuleNode>(
prop: T,
): EnvironmentModuleNode[T] {
return (this._clientModule?.[prop] ?? this._ssrModule?.[prop])!
}
_set<T extends keyof EnvironmentModuleNode>(
prop: T,
value: EnvironmentModuleNode[T],
): void {
if (this._clientModule) {
this._clientModule[prop] = value
}
if (this._ssrModule) {
this._ssrModule[prop] = value
}
}
_wrapModuleSet(
prop: ModuleSetNames,
module: EnvironmentModuleNode | undefined,
): Set<ModuleNode> {
if (!module) {
return new Set()
}
return createBackwardCompatibleModuleSet(this._moduleGraph, prop, module)
}
_getModuleSetUnion(prop: 'importedModules' | 'importers'): Set<ModuleNode> {
// A good approximation to the previous logic that returned the union of
// the importedModules and importers from both the browser and server
const importedModules = new Set<ModuleNode>()
const ids = new Set<string>()
if (this._clientModule) {
for (const mod of this._clientModule[prop]) {
if (mod.id) ids.add(mod.id)
importedModules.add(
this._moduleGraph.getBackwardCompatibleModuleNode(mod),
)
}
}
if (this._ssrModule) {
for (const mod of this._ssrModule[prop]) {
if (mod.id && !ids.has(mod.id)) {
importedModules.add(
this._moduleGraph.getBackwardCompatibleModuleNode(mod),
)
}
}
}
return importedModules
}
_getModuleInfoUnion(prop: 'info'): ModuleInfo | undefined {
const _clientValue = this._clientModule?.[prop]
const _ssrValue = this._ssrModule?.[prop]
if (_clientValue == null && _ssrValue == null) return undefined
return new Proxy({} as any, {
get: (_, key: string) => {
// `meta` refers to `ModuleInfo.meta` so we refer to `this.meta` to
// handle the object union between client and ssr
if (key === 'meta') {
return this.meta || EMPTY_OBJECT
}
if (_clientValue) {
if (key in _clientValue) {
return _clientValue[key as keyof ModuleInfo]
}
}
Domain
Source
Frequently Asked Questions
What is the ModuleNode class?
ModuleNode is a class in the vite codebase, defined in packages/vite/src/node/server/mixedModuleGraph.ts.
Where is ModuleNode defined?
ModuleNode is defined in packages/vite/src/node/server/mixedModuleGraph.ts at line 20.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free