optimize() — tailwindcss Function Reference
Architecture documentation for the optimize() function in sources.rs from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 8ca5dcda_6e18_de9e_e08b_e49a46567b4b["optimize()"] c1a91897_e0c1_9742_bda9_8acee093718c["public_source_entries_to_private_source_entries()"] c1a91897_e0c1_9742_bda9_8acee093718c -->|calls| 8ca5dcda_6e18_de9e_e08b_e49a46567b4b style 8ca5dcda_6e18_de9e_e08b_e49a46567b4b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
crates/oxide/src/scanner/sources.rs lines 103–171
pub fn optimize(&mut self) {
// Resolve base path immediately
let Ok(base) = dunce::canonicalize(&self.base) else {
event!(Level::ERROR, "Failed to resolve base: {:?}", self.base);
return;
};
self.base = base.to_string_lossy().to_string();
// No dynamic part, figure out if we are dealing with a file or a directory.
if !self.pattern.contains('*') {
let combined_path = if self.pattern.starts_with("/") {
PathBuf::from(&self.pattern)
} else {
PathBuf::from(&self.base).join(&self.pattern)
};
match dunce::canonicalize(combined_path) {
Ok(resolved_path) if resolved_path.is_dir() => {
self.base = resolved_path.to_string_lossy().to_string();
self.pattern = "**/*".to_owned();
}
Ok(resolved_path) if resolved_path.is_file() => {
self.base = resolved_path
.parent()
.unwrap()
.to_string_lossy()
.to_string();
// Ensure leading slash, otherwise it will match against all files in all folders/
self.pattern =
format!("/{}", resolved_path.file_name().unwrap().to_string_lossy());
}
_ => {}
}
return;
}
// Contains dynamic part
let (static_part, dynamic_part) = split_pattern(&self.pattern);
let base: PathBuf = self.base.clone().into();
let base = match static_part {
Some(static_part) => {
// TODO: If the base does not exist on disk, try removing the last slash and try
// again.
match dunce::canonicalize(base.join(static_part)) {
Ok(base) => base,
Err(err) => {
event!(tracing::Level::ERROR, "Failed to resolve glob: {:?}", err);
return;
}
}
}
None => base,
};
let pattern = match dynamic_part {
Some(dynamic_part) => dynamic_part,
None => {
if base.is_dir() {
"**/*".to_owned()
} else {
"".to_owned()
}
}
};
self.base = base.to_string_lossy().to_string();
self.pattern = pattern;
}
Domain
Subdomains
Source
Frequently Asked Questions
What does optimize() do?
optimize() is a function in the tailwindcss codebase.
What calls optimize()?
optimize() is called by 1 function(s): public_source_entries_to_private_source_entries.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free