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

Class PartialEnvironment

packages/vite/src/node/baseEnvironment.ts:13–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11]
12
13export class PartialEnvironment {
14 name: string
15 getTopLevelConfig(): ResolvedConfig {
16 return this._topLevelConfig
17 }
18
19 config: ResolvedConfig & ResolvedEnvironmentOptions
20
21 logger: Logger
22
23 /**
24 * @internal
25 */
26 _options: ResolvedEnvironmentOptions
27 /**
28 * @internal
29 */
30 _topLevelConfig: ResolvedConfig
31
32 constructor(
33 name: string,
34 topLevelConfig: ResolvedConfig,
35 options: ResolvedEnvironmentOptions = topLevelConfig.environments[name],
36 ) {
37 // only allow some characters so that we can use name without escaping for directory names
38 // and make users easier to access with `environments.*`
39 if (!/^[\w$]+$/.test(name)) {
40 throw new Error(
41 `Invalid environment name "${name}". Environment names must only contain alphanumeric characters and "$", "_".`,
42 )
43 }
44 this.name = name
45 this._topLevelConfig = topLevelConfig
46 this._options = options
47 this.config = new Proxy(
48 options as ResolvedConfig & ResolvedEnvironmentOptions,
49 {
50 get: (target, prop: keyof ResolvedConfig) => {
51 if (prop === 'logger') {
52 return this.logger
53 }
54 if (prop in target) {
55 return this._options[prop as keyof ResolvedEnvironmentOptions]
56 }
57 return this._topLevelConfig[prop]
58 },
59 },
60 )
61 const environment = colors.dim(`(${this.name})`)
62 const colorIndex =
63 [...this.name].reduce((acc, c) => acc + c.charCodeAt(0), 0) %
64 environmentColors.length
65 const infoColor = environmentColors[colorIndex || 0]
66 this.logger = {
67 get hasWarned() {
68 return topLevelConfig.logger.hasWarned
69 },
70 info(msg, opts) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected