Skip to content

Commit 46a536e

Browse files
branchseerclaude
andcommitted
fix: write trace files to dedicated directory to avoid breaking formatters
Trace files (trace-*.json) written to the project cwd were picked up by formatters during E2E tests, causing failures due to truncated JSON. Add VITE_LOG_OUTPUT_DIR env var to write trace files to a dedicated directory. Set it in the E2E workflow to ${{ runner.temp }}/trace-artifacts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d463caf commit 46a536e

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

.github/workflows/e2e-test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,22 @@ jobs:
290290
env:
291291
VITE_LOG: debug
292292
VITE_LOG_OUTPUT: chrome-json
293+
VITE_LOG_OUTPUT_DIR: ${{ runner.temp }}/trace-artifacts
293294
run: ${{ matrix.project.command }}
294295

295296
- name: Run vite-plus commands again (cache run) in ${{ matrix.project.name }}
296297
working-directory: ${{ runner.temp }}/vite-plus-ecosystem-ci/${{ matrix.project.name }}${{ matrix.project.directory && format('/{0}', matrix.project.directory) || '' }}
297298
env:
298299
VITE_LOG: debug
299300
VITE_LOG_OUTPUT: chrome-json
301+
VITE_LOG_OUTPUT_DIR: ${{ runner.temp }}/trace-artifacts
300302
run: ${{ matrix.project.command }}
301303

302304
- name: Collect trace files
303305
if: always()
304306
shell: bash
305307
run: |
306308
mkdir -p ${{ runner.temp }}/trace-artifacts
307-
# Chrome tracing writes trace-*.json in the cwd of the process
308-
find ${{ runner.temp }}/vite-plus-ecosystem-ci/${{ matrix.project.name }} -name 'trace-*.json' -exec cp {} ${{ runner.temp }}/trace-artifacts/ \; 2>/dev/null || true
309-
# Also check the workspace root
310-
find $GITHUB_WORKSPACE -maxdepth 1 -name 'trace-*.json' -exec cp {} ${{ runner.temp }}/trace-artifacts/ \; 2>/dev/null || true
311309
ls -la ${{ runner.temp }}/trace-artifacts/ 2>/dev/null || echo "No trace files found"
312310
313311
- name: Upload trace artifacts

crates/vite_shared/src/env_vars.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub const VITE_LOG: &str = "VITE_LOG";
2121
/// Output mode for tracing (e.g. `"chrome-json"` for Chrome DevTools timeline).
2222
pub const VITE_LOG_OUTPUT: &str = "VITE_LOG_OUTPUT";
2323

24+
/// Directory for chrome-json trace files (default: current working directory).
25+
pub const VITE_LOG_OUTPUT_DIR: &str = "VITE_LOG_OUTPUT_DIR";
26+
2427
/// NPM registry URL (lowercase form, highest priority).
2528
pub const NPM_CONFIG_REGISTRY: &str = "npm_config_registry";
2629

crates/vite_shared/src/tracing.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
//! - `VITE_LOG`: Controls log filtering (e.g., `"debug"`, `"vite_task=trace"`)
55
//! - `VITE_LOG_OUTPUT`: Output format — `"chrome-json"` for Chrome DevTools timeline,
66
//! `"readable"` for pretty-printed output, or default stdout.
7+
//! - `VITE_LOG_OUTPUT_DIR`: Directory for chrome-json trace files (default: cwd).
78
8-
use std::{any::Any, sync::atomic::AtomicBool};
9+
use std::{any::Any, path::PathBuf, sync::atomic::AtomicBool};
910

1011
use tracing_chrome::ChromeLayerBuilder;
1112
use tracing_subscriber::{
@@ -48,10 +49,21 @@ pub fn init_tracing() -> Option<Box<dyn Any + Send>> {
4849

4950
match output_mode.as_str() {
5051
"chrome-json" => {
51-
let (chrome_layer, guard) = ChromeLayerBuilder::new()
52+
let mut builder = ChromeLayerBuilder::new()
5253
.trace_style(tracing_chrome::TraceStyle::Async)
53-
.include_args(true)
54-
.build();
54+
.include_args(true);
55+
// Write trace files to VITE_LOG_OUTPUT_DIR if set, to avoid
56+
// polluting the project directory (formatters may pick them up).
57+
if let Ok(dir) = std::env::var(env_vars::VITE_LOG_OUTPUT_DIR) {
58+
let dir = PathBuf::from(dir);
59+
let _ = std::fs::create_dir_all(&dir);
60+
let ts = std::time::SystemTime::now()
61+
.duration_since(std::time::UNIX_EPOCH)
62+
.map(|d| d.as_micros())
63+
.unwrap_or(0);
64+
builder = builder.file(dir.join(format!("trace-{ts}.json")));
65+
}
66+
let (chrome_layer, guard) = builder.build();
5567
tracing_subscriber::registry().with(targets).with(chrome_layer).init();
5668
Some(Box::new(guard))
5769
}

performance.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ vite-task uses Unix shared memory (`/dev/shm`) for parent-child process communic
273273

274274
## Known Issues
275275

276-
### Windows: Trace files break formatter
276+
### Trace files break formatter (fixed)
277277

278-
When `VITE_LOG_OUTPUT=chrome-json` is set, trace files (`trace-*.json`) are written to the project working directory. On Windows, `vp fmt` picks up these files and fails with "Unterminated string constant" because the trace files contain very long PATH strings.
278+
When `VITE_LOG_OUTPUT=chrome-json` is set, trace files (`trace-*.json`) were written to the project working directory. Formatters (oxfmt/prettier) pick up these files and fail with "Unterminated string constant" because trace files may contain truncated JSON (especially on Windows where PATH strings are very long).
279279

280-
**Recommendation**: Add `trace-*.json` to formatter ignore patterns, or write trace files to a dedicated directory outside the workspace.
280+
**Fix**: Set `VITE_LOG_OUTPUT_DIR` to write trace files to a dedicated directory outside the workspace.
281281

282282
### NAPI trace files empty for some projects
283283

0 commit comments

Comments
 (0)