From 9a86942cede801286825604574d6def6de2d1b31 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 00:48:39 +0200 Subject: [PATCH 1/8] write `DEBUG=*` to `tailwindcss-{pid}.log` file --- crates/oxide/src/scanner/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 5512ad000354..3fdd775b901c 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -16,10 +16,13 @@ use fxhash::{FxHashMap, FxHashSet}; use ignore::{gitignore::GitignoreBuilder, WalkBuilder}; use rayon::prelude::*; use std::collections::{BTreeMap, BTreeSet}; +use std::fs::OpenOptions; +use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::sync::{self, Arc, Mutex}; use std::time::SystemTime; use tracing::event; +use tracing_subscriber::fmt::writer::BoxMakeWriter; // @source "some/folder"; // This is auto source detection // @source "some/folder/**/*"; // This is auto source detection @@ -40,13 +43,41 @@ fn init_tracing() { return; } + let file = format!("tailwindcss-{}.log", std::process::id()); + let file = OpenOptions::new() + .create(true) + .append(true) + .open(&file) + .unwrap_or_else(|_| panic!("Failed to open {file}")); + + let file = Arc::new(Mutex::new(file)); + + let writer: BoxMakeWriter = BoxMakeWriter::new({ + let file = file.clone(); + move || Box::new(MutexWriter(file.clone())) as Box + }); + _ = tracing_subscriber::fmt() .with_max_level(tracing::Level::INFO) .with_span_events(tracing_subscriber::fmt::format::FmtSpan::ACTIVE) + .with_writer(writer) + .with_ansi(false) .compact() .try_init(); } +struct MutexWriter(Arc>); + +impl Write for MutexWriter { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.0.lock().unwrap().write(buf) + } + + fn flush(&mut self) -> io::Result<()> { + self.0.lock().unwrap().flush() + } +} + #[derive(Debug, Clone)] pub enum ChangedContent { File(PathBuf, String), From 1fe008d6de3964ace49f6bf5b3fb6f07bb7a4af1 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 00:50:20 +0200 Subject: [PATCH 2/8] log which file we are reading right now --- crates/oxide/src/scanner/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 3fdd775b901c..93bdd63bface 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -425,7 +425,10 @@ impl Scanner { fn read_changed_content(c: ChangedContent) -> Option> { let (content, extension) = match c { ChangedContent::File(file, extension) => match std::fs::read(&file) { - Ok(content) => (content, extension), + Ok(content) => { + event!(tracing::Level::INFO, "Reading {:?}", file); + (content, extension) + } Err(e) => { event!(tracing::Level::ERROR, "Failed to read file: {:?}", e); return None; From 04899f1d730de0544d42bd4c1d44de65888d6b7c Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 01:10:06 +0200 Subject: [PATCH 3/8] log the path we are traversing This log happens when we are traversing using the gitignore walker --- crates/oxide/src/scanner/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 93bdd63bface..0d93a3542e43 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -740,7 +740,11 @@ fn create_walker(sources: Sources) -> Option { match (current_time, previous_time) { (Some(current), Some(prev)) if prev == current => false, - _ => true, + _ => { + event!(tracing::Level::INFO, "Discovering {:?}", path); + + true + } } } }); From df799e56083665a853410ada13b037119c3b8bdf Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 11:34:30 +0200 Subject: [PATCH 4/8] update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65e1830eaa1f..88ee2eaafb25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Upgrade: Automatically convert candidates with arbitrary values to their utilities ([#17831](https://github.com/tailwindlabs/tailwindcss/pull/17831), [#17854](https://github.com/tailwindlabs/tailwindcss/pull/17854)) +- Write to log file when using `DEBUG=*` ([#17906](https://github.com/tailwindlabs/tailwindcss/pull/17906)) ### Fixed @@ -17,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix HAML extraction with embedded Ruby ([#17846](https://github.com/tailwindlabs/tailwindcss/pull/17846)) - Don't scan files for utilities when using `@reference` ([#17836](https://github.com/tailwindlabs/tailwindcss/pull/17836)) - Fix incorrectly replacing `_` with ` ` in arbitrary modifier shorthand `bg-red-500/(--my_opacity)` ([#17889](https://github.com/tailwindlabs/tailwindcss/pull/17889)) -- Upgrade: Bump dependendencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898)) +- Upgrade: Bump dependencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898)) ## [4.1.5] - 2025-04-30 From c9cdbc1f35443e49d88d011108ce2f526a5c5b8c Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 16:09:08 +0200 Subject: [PATCH 5/8] output where we are writing the log file --- crates/oxide/src/scanner/mod.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/oxide/src/scanner/mod.rs b/crates/oxide/src/scanner/mod.rs index 0d93a3542e43..ccdbd231dbc8 100644 --- a/crates/oxide/src/scanner/mod.rs +++ b/crates/oxide/src/scanner/mod.rs @@ -38,17 +38,38 @@ static SHOULD_TRACE: sync::LazyLock = sync::LazyLock::new( || matches!(std::env::var("DEBUG"), Ok(value) if value.eq("*") || (value.contains("tailwindcss:oxide") && !value.contains("-tailwindcss:oxide"))), ); +fn dim(input: &str) -> String { + format!("\u{001b}[2m{input}\u{001b}[22m") +} + +fn blue(input: &str) -> String { + format!("\u{001b}[34m{input}\u{001b}[39m") +} + +fn highlight(input: &str) -> String { + format!("{}{}{}", dim(&blue("`")), blue(input), dim(&blue("`"))) +} + fn init_tracing() { if !*SHOULD_TRACE { return; } - let file = format!("tailwindcss-{}.log", std::process::id()); + let file_path = format!("tailwindcss-{}.log", std::process::id()); let file = OpenOptions::new() .create(true) .append(true) - .open(&file) - .unwrap_or_else(|_| panic!("Failed to open {file}")); + .open(&file_path) + .unwrap_or_else(|_| panic!("Failed to open {file_path}")); + + let file_path = Path::new(&file_path); + let absolute_file_path = dunce::canonicalize(file_path) + .unwrap_or_else(|_| panic!("Failed to canonicalize {file_path:?}")); + eprintln!( + "{} Writing debug info to: {}\n", + dim("[DEBUG]"), + highlight(absolute_file_path.as_path().to_str().unwrap()) + ); let file = Arc::new(Mutex::new(file)); From 07f2854be846b9cb5570616bd8438e1e494c4431 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 16:09:29 +0200 Subject: [PATCH 6/8] hoist printing the CLI header This allows us to: 1. Only output the header once 2. Output a log from Oxide that will end up underneath the header --- packages/@tailwindcss-cli/src/commands/build/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index 409c398e9939..8c840c666167 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -67,6 +67,9 @@ async function handleError(fn: () => T): Promise { } export async function handle(args: Result>) { + eprintln(header()) + eprintln() + using I = new Instrumentation() DEBUG && I.start('[@tailwindcss/cli] (initial build)') @@ -87,8 +90,6 @@ export async function handle(args: Result>) { // Ensure the provided `--input` exists. if (!existsSync(args['--input'])) { - eprintln(header()) - eprintln() eprintln(`Specified input file ${highlight(relative(args['--input']))} does not exist.`) process.exit(1) } @@ -97,8 +98,6 @@ export async function handle(args: Result>) { // Check if the input and output file paths are identical, otherwise return an // error to the user. if (args['--input'] === args['--output'] && args['--input'] !== '-') { - eprintln(header()) - eprintln() eprintln( `Specified input file ${highlight(relative(args['--input']))} and output file ${highlight(relative(args['--output']))} are identical.`, ) @@ -328,8 +327,6 @@ export async function handle(args: Result>) { await write(output, args, I) let end = process.hrtime.bigint() - eprintln(header()) - eprintln() eprintln(`Done in ${formatDuration(end - start)}`) } From 2793b2ac7b5295c84a9985be5f14419c60bad9cb Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 16:11:00 +0200 Subject: [PATCH 7/8] ignore `.log` files by default --- crates/oxide/src/scanner/fixtures/ignored-extensions.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/oxide/src/scanner/fixtures/ignored-extensions.txt b/crates/oxide/src/scanner/fixtures/ignored-extensions.txt index 2b19a87c02a7..4dc099e0d8ec 100644 --- a/crates/oxide/src/scanner/fixtures/ignored-extensions.txt +++ b/crates/oxide/src/scanner/fixtures/ignored-extensions.txt @@ -3,3 +3,4 @@ lock sass scss styl +log From db8a7a27528db93f79f45714b83a25fdc3ad1062 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Wed, 7 May 2025 16:13:48 +0200 Subject: [PATCH 8/8] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88ee2eaafb25..615054562f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Don't scan files for utilities when using `@reference` ([#17836](https://github.com/tailwindlabs/tailwindcss/pull/17836)) - Fix incorrectly replacing `_` with ` ` in arbitrary modifier shorthand `bg-red-500/(--my_opacity)` ([#17889](https://github.com/tailwindlabs/tailwindcss/pull/17889)) - Upgrade: Bump dependencies in parallel and make the upgrade faster ([#17898](https://github.com/tailwindlabs/tailwindcss/pull/17898)) +- Don't scan `.log` files for classes by default ([#17906](https://github.com/tailwindlabs/tailwindcss/pull/17906)) ## [4.1.5] - 2025-04-30