Home / Function/ optimize() — tailwindcss Function Reference

optimize() — tailwindcss Function Reference

Architecture documentation for the optimize() function in sources.rs from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  c9655daf_c9e2_df3b_77c6_140d877acdda["optimize()"]
  2ba1e6a3_0391_ac7e_04d2_d5d35ad686bb["sources.rs"]
  c9655daf_c9e2_df3b_77c6_140d877acdda -->|defined in| 2ba1e6a3_0391_ac7e_04d2_d5d35ad686bb
  c5db546f_e346_57a0_52ea_68112f6161c3["public_source_entries_to_private_source_entries()"]
  c5db546f_e346_57a0_52ea_68112f6161c3 -->|calls| c9655daf_c9e2_df3b_77c6_140d877acdda
  style c9655daf_c9e2_df3b_77c6_140d877acdda 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

Frequently Asked Questions

What does optimize() do?
optimize() is a function in the tailwindcss codebase, defined in crates/oxide/src/scanner/sources.rs.
Where is optimize() defined?
optimize() is defined in crates/oxide/src/scanner/sources.rs at line 103.
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