PartialEnvironment Class — vite Architecture
Architecture documentation for the PartialEnvironment class in baseEnvironment.ts from the vite codebase.
Entity Profile
Dependency Diagram
graph TD dc928824_33f2_0b61_b231_90d8800b77a5["PartialEnvironment"] 84057c57_14eb_2f16_cd5c_1899e8da6db0["baseEnvironment.ts"] dc928824_33f2_0b61_b231_90d8800b77a5 -->|defined in| 84057c57_14eb_2f16_cd5c_1899e8da6db0 b1f5b07b_f692_69cd_1795_627055928bb7["getTopLevelConfig()"] dc928824_33f2_0b61_b231_90d8800b77a5 -->|method| b1f5b07b_f692_69cd_1795_627055928bb7 fc780328_0dd4_ca48_1adb_4d931698bd4f["constructor()"] dc928824_33f2_0b61_b231_90d8800b77a5 -->|method| fc780328_0dd4_ca48_1adb_4d931698bd4f
Relationship Graph
Source Code
packages/vite/src/node/baseEnvironment.ts lines 13–102
export class PartialEnvironment {
name: string
getTopLevelConfig(): ResolvedConfig {
return this._topLevelConfig
}
config: ResolvedConfig & ResolvedEnvironmentOptions
logger: Logger
/**
* @internal
*/
_options: ResolvedEnvironmentOptions
/**
* @internal
*/
_topLevelConfig: ResolvedConfig
constructor(
name: string,
topLevelConfig: ResolvedConfig,
options: ResolvedEnvironmentOptions = topLevelConfig.environments[name],
) {
// only allow some characters so that we can use name without escaping for directory names
// and make users easier to access with `environments.*`
if (!/^[\w$]+$/.test(name)) {
throw new Error(
`Invalid environment name "${name}". Environment names must only contain alphanumeric characters and "$", "_".`,
)
}
this.name = name
this._topLevelConfig = topLevelConfig
this._options = options
this.config = new Proxy(
options as ResolvedConfig & ResolvedEnvironmentOptions,
{
get: (target, prop: keyof ResolvedConfig) => {
if (prop === 'logger') {
return this.logger
}
if (prop in target) {
return this._options[prop as keyof ResolvedEnvironmentOptions]
}
return this._topLevelConfig[prop]
},
},
)
const environment = colors.dim(`(${this.name})`)
const colorIndex =
[...this.name].reduce((acc, c) => acc + c.charCodeAt(0), 0) %
environmentColors.length
const infoColor = environmentColors[colorIndex || 0]
this.logger = {
get hasWarned() {
return topLevelConfig.logger.hasWarned
},
info(msg, opts) {
return topLevelConfig.logger.info(msg, {
...opts,
environment: infoColor(environment),
})
},
warn(msg, opts) {
return topLevelConfig.logger.warn(msg, {
...opts,
environment: colors.yellow(environment),
})
},
warnOnce(msg, opts) {
return topLevelConfig.logger.warnOnce(msg, {
...opts,
environment: colors.yellow(environment),
})
},
error(msg, opts) {
return topLevelConfig.logger.error(msg, {
...opts,
environment: colors.red(environment),
})
},
Domain
Defined In
Source
Frequently Asked Questions
What is the PartialEnvironment class?
PartialEnvironment is a class in the vite codebase, defined in packages/vite/src/node/baseEnvironment.ts.
Where is PartialEnvironment defined?
PartialEnvironment is defined in packages/vite/src/node/baseEnvironment.ts at line 13.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free