Commit 20c168a
authored
refactor: add EnvConfig for centralized env var management (#556)
## Summary
Phase 1+2 of env var refactoring. Introduces `EnvConfig` struct that
reads all known environment variables once at startup, enabling
testable, parallel-safe code.
## Problem
- 235 direct `std::env` calls across 7 crates, 140 are
`set_var`/`remove_var`
- `env::set_var` is `unsafe` since Rust 1.83
- Tests need `#[serial]` or `#[ignore]` due to global env mutation
- No single source of truth for supported env vars
## Changes
### New: `vite_shared::EnvConfig`
- Central struct documenting all 11 known env vars
- `EnvConfig::from_env()` — read from real environment (production)
- `EnvConfig::for_test()` — sensible defaults, zero env access
- `EnvConfig::for_test_with_home(path)` — convenience for temp dir tests
- Supports struct update syntax: `EnvConfig { is_ci: true,
..EnvConfig::for_test() }`
### Updated: `home.rs`
- New `get_vite_plus_home_with_config(&EnvConfig)` — config-based, no
env access
- Legacy `get_vite_plus_home()` preserved for backward compat
- Removed `#[ignore]` test, replaced with parallel-safe config test
### Updated: `tracing.rs`
- New `init_tracing_with_config(&EnvConfig)` — config-based
- Legacy `init_tracing()` preserved
- Extracted shared `init_tracing_inner()`
## Test Results
- `cargo test -p vite_shared`: 19 passed + 2 doc-tests ✅
- `cargo check` (full project): compiles ✅
## Next Phases
- Phase 3: Thread through `vite_install` + `vite_js_runtime`
- Phase 4: Thread through `vite_global_cli` (biggest change)
- Phase 5: Remove remaining `unsafe env::set_var`1 parent c9f414d commit 20c168a
20 files changed
Lines changed: 659 additions & 564 deletions
File tree
- crates
- vite_global_cli/src
- commands
- env
- self_update
- shim
- vite_install/src
- vite_js_runtime/src
- providers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | 115 | | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
120 | 119 | | |
121 | | - | |
122 | 120 | | |
123 | 121 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
129 | 125 | | |
130 | 126 | | |
131 | 127 | | |
| |||
142 | 138 | | |
143 | 139 | | |
144 | 140 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 141 | | |
151 | 142 | | |
152 | 143 | | |
153 | | - | |
154 | 144 | | |
155 | 145 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
161 | 149 | | |
162 | 150 | | |
163 | 151 | | |
| |||
197 | 185 | | |
198 | 186 | | |
199 | 187 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | 188 | | |
206 | 189 | | |
207 | 190 | | |
208 | | - | |
209 | 191 | | |
210 | 192 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
216 | 196 | | |
217 | 197 | | |
218 | 198 | | |
| |||
235 | 215 | | |
236 | 216 | | |
237 | 217 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | 218 | | |
244 | 219 | | |
245 | 220 | | |
246 | | - | |
247 | 221 | | |
248 | 222 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
254 | 226 | | |
255 | 227 | | |
256 | 228 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | 229 | | |
263 | 230 | | |
0 commit comments