diff --git a/Cargo.lock b/Cargo.lock index 791a588..bbbd542 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "aho-corasick" version = "1.1.3" @@ -32,55 +17,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "anstream" -version = "0.6.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - [[package]] name = "anstyle" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" -[[package]] -name = "anstyle-parse" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" -dependencies = [ - "anstyle", - "windows-sys", -] - [[package]] name = "anyhow" version = "1.0.83" @@ -93,21 +35,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "backtrace" -version = "0.3.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - [[package]] name = "benchmark" version = "0.0.0" @@ -143,24 +70,12 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[package]] -name = "bytes" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" - [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cc" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" - [[package]] name = "cfg-if" version = "1.0.0" @@ -201,7 +116,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", - "clap_derive", ] [[package]] @@ -210,22 +124,8 @@ version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ - "anstream", "anstyle", "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" -dependencies = [ - "heck 0.5.0", - "proc-macro2", - "quote", - "syn 2.0.61", ] [[package]] @@ -234,12 +134,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" -[[package]] -name = "colorchoice" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" - [[package]] name = "console" version = "0.15.8" @@ -358,101 +252,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" - -[[package]] -name = "futures-executor" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" - -[[package]] -name = "futures-macro" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.61", -] - -[[package]] -name = "futures-sink" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" - -[[package]] -name = "futures-task" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" - -[[package]] -name = "futures-util" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - [[package]] name = "globset" version = "0.4.14" @@ -488,12 +287,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - [[package]] name = "hermit-abi" version = "0.3.9" @@ -536,12 +329,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" - [[package]] name = "itertools" version = "0.10.5" @@ -611,22 +398,7 @@ dependencies = [ "serde", "similar-asserts", "tiny_pretty", - "toml 0.8.12", -] - -[[package]] -name = "malva_cli" -version = "0.3.1" -dependencies = [ - "anyhow", - "clap", - "futures", - "globset", - "malva", - "serde_json", - "tokio", - "toml 0.7.8", - "walkdir", + "toml", ] [[package]] @@ -635,15 +407,6 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" -[[package]] -name = "miniz_oxide" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" -dependencies = [ - "adler", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -653,25 +416,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "object" -version = "0.32.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.19.0" @@ -684,18 +428,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "plotters" version = "0.3.5" @@ -759,7 +491,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "739679d3e4fda2d82602444155efe0bfb7af0f1b9018711066b30965b849e990" dependencies = [ - "heck 0.4.1", + "heck", "quote", "syn 1.0.109", ] @@ -819,12 +551,6 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" -[[package]] -name = "rustc-demangle" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" - [[package]] name = "ryu" version = "1.0.18" @@ -911,15 +637,6 @@ dependencies = [ "similar", ] -[[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" -dependencies = [ - "autocfg", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -939,12 +656,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "syn" version = "1.0.109" @@ -983,42 +694,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "tokio" -version = "1.37.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" -dependencies = [ - "backtrace", - "bytes", - "num_cpus", - "pin-project-lite", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.61", -] - -[[package]] -name = "toml" -version = "0.7.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit 0.19.15", -] - [[package]] name = "toml" version = "0.8.12" @@ -1028,7 +703,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.12", + "toml_edit", ] [[package]] @@ -1040,19 +715,6 @@ dependencies = [ "serde", ] -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap", - "serde", - "serde_spanned", - "toml_datetime", - "winnow 0.5.40", -] - [[package]] name = "toml_edit" version = "0.22.12" @@ -1063,7 +725,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.8", + "winnow", ] [[package]] @@ -1078,12 +740,6 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "walkdir" version = "2.5.0" @@ -1240,15 +896,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winnow" -version = "0.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" -dependencies = [ - "memchr", -] - [[package]] name = "winnow" version = "0.6.8" diff --git a/Cargo.toml b/Cargo.toml index 42fc16a..b3bc1a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,6 @@ members = [ "benchmark", "dprint_plugin", "malva", - "malva_cli", "standalone_wasm", ] resolver = "2" diff --git a/malva/examples/fmt.rs b/malva/examples/fmt.rs new file mode 100644 index 0000000..78858c8 --- /dev/null +++ b/malva/examples/fmt.rs @@ -0,0 +1,22 @@ +use malva::{config::FormatOptions, detect_syntax, format_text}; +use std::{env, error::Error, fs, io}; + +fn main() -> Result<(), Box> { + let file_path = env::args().nth(1).unwrap(); + let syntax = detect_syntax(&file_path).unwrap(); + let input = fs::read_to_string(&file_path)?; + let options = match fs::read_to_string("malva.toml") { + Ok(s) => toml::from_str(&s)?, + Err(error) => { + if error.kind() == io::ErrorKind::NotFound { + FormatOptions::default() + } else { + return Err(Box::new(error)); + } + } + }; + + let formatted = format_text(&input, syntax, &options)?; + print!("{formatted}"); + Ok(()) +} diff --git a/malva_cli/Cargo.toml b/malva_cli/Cargo.toml deleted file mode 100644 index 957885a..0000000 --- a/malva_cli/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "malva_cli" -version = "0.3.1" -edition = "2021" -authors = ["Pig Fang "] -description = "CSS/SCSS/Sass/Less formatter." -repository = "https://github.com/g-plane/malva" -license = "MIT" - -[dependencies] -anyhow = "1.0" -clap = { version = "4.4", features = ["derive"] } -futures = "0.3" -globset = "0.4" -malva = { path = "../malva", features = ["config_serde"] } -serde_json = "1.0" -tokio = { version = "1.32", features = [ - "fs", - "io-std", - "io-util", - "rt-multi-thread", - "macros", -] } -toml = "0.7" -walkdir = "2.4" - -[[bin]] -name = "malva" -path = "src/main.rs" -doc = false diff --git a/malva_cli/src/config.rs b/malva_cli/src/config.rs deleted file mode 100644 index ef65a10..0000000 --- a/malva_cli/src/config.rs +++ /dev/null @@ -1,26 +0,0 @@ -use anyhow::{Error, Result}; -use malva::config::FormatOptions; -use std::path::Path; -use tokio::{fs, io}; - -pub async fn resolve_config(base_dir: &Path) -> Result { - match fs::read_to_string(base_dir.join("malva.toml")).await { - Ok(content) => return toml::from_str(&content).map_err(Error::from), - Err(error) => { - if error.kind() != io::ErrorKind::NotFound { - return Err(error.into()); - } - } - } - - match fs::read_to_string(base_dir.join("malva.json")).await { - Ok(content) => return serde_json::from_str(&content).map_err(Error::from), - Err(error) => { - if error.kind() != io::ErrorKind::NotFound { - return Err(error.into()); - } - } - } - - Ok(FormatOptions::default()) -} diff --git a/malva_cli/src/format.rs b/malva_cli/src/format.rs deleted file mode 100644 index 533b169..0000000 --- a/malva_cli/src/format.rs +++ /dev/null @@ -1,20 +0,0 @@ -use anyhow::{Error, Result}; -use malva::{config::FormatOptions, format_text, Syntax}; -use std::path::Path; - -pub fn format_file(code: String, file_path: &Path, options: &FormatOptions) -> Result { - let syntax = match file_path.extension().and_then(|s| s.to_str()) { - Some(ext) if ext.eq_ignore_ascii_case("css") => Syntax::Css, - Some(ext) if ext.eq_ignore_ascii_case("scss") => Syntax::Scss, - Some(ext) if ext.eq_ignore_ascii_case("sass") => Syntax::Sass, - Some(ext) if ext.eq_ignore_ascii_case("less") => Syntax::Less, - _ => { - return Err(anyhow::anyhow!( - "unknown file extension of file: {}", - file_path.display() - )); - } - }; - - format_text(&code, syntax, options).map_err(Error::from) -} diff --git a/malva_cli/src/main.rs b/malva_cli/src/main.rs deleted file mode 100644 index 97eec7d..0000000 --- a/malva_cli/src/main.rs +++ /dev/null @@ -1,75 +0,0 @@ -use clap::Parser; -use std::{env, path::PathBuf, sync::Arc}; -use tokio::{ - fs, - io::{self, AsyncWriteExt}, - task::spawn_blocking, -}; - -mod config; -mod format; -mod search; - -#[derive(Parser)] -#[command(version, about)] -struct Args { - /// Specify config file path. - #[arg(short, long)] - config: Option, - - /// Format then write to original files. - #[arg(short, long)] - write: bool, - - #[arg(required(true))] - files: Vec, - - /// Specify which files should be ignored. - #[arg(long)] - ignore: Vec, - - #[arg(long)] - cwd: Option, -} - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - let args = Args::parse(); - - let base_dir = args - .cwd - .or_else(|| env::current_dir().ok()) - .unwrap_or_else(|| PathBuf::from(".")); - let config = Arc::new(config::resolve_config(&base_dir).await?); - let files = search::search_files(&base_dir, &args.files, &args.ignore)?; - - let tasks = files - .into_iter() - .map(|file| async { - let file = Arc::new(file); - let config = config.clone(); - - let content = fs::read_to_string(&*file).await?; - let formatted = { - let file = file.clone(); - spawn_blocking(move || format::format_file(content, &file, &config)).await?? - }; - - if args.write { - fs::write(&*file, formatted).await?; - } else { - let mut stdout = io::stdout(); - stdout.write_all(formatted.as_bytes()).await?; - } - Ok::<_, anyhow::Error>(()) - }) - .map(|result| async { - if let Err(error) = result.await { - let mut stderr = io::stderr(); - let _ = stderr.write_all(error.to_string().as_bytes()).await; - } - }); - futures::future::join_all(tasks).await; - - Ok(()) -} diff --git a/malva_cli/src/search.rs b/malva_cli/src/search.rs deleted file mode 100644 index d60cf78..0000000 --- a/malva_cli/src/search.rs +++ /dev/null @@ -1,59 +0,0 @@ -use globset::{GlobBuilder, GlobSet, GlobSetBuilder}; -use std::{ - borrow::Cow, - path::{self, Path, PathBuf}, -}; -use walkdir::WalkDir; - -pub fn search_files( - base_dir: &PathBuf, - files: &[impl AsRef], - ignore: &[String], -) -> anyhow::Result> { - let mut ignore_pats = vec![String::from("**/node_modules/**")]; - ignore_pats.extend_from_slice(ignore); - let ignore = build_glob_set(&ignore_pats)?; - - let inputs = build_glob_set(files)?; - WalkDir::new(base_dir) - .into_iter() - .map(|entry| entry.map(|entry| entry.into_path())) - .filter(|path| { - path.as_ref() - .map(|path| { - // SAFETY: all the paths are walked from `base_dir`, - // so it should be safe to strip that prefix. - let path = path.strip_prefix(base_dir).unwrap(); - inputs.is_match(path) && !ignore.is_match(path) - }) - .unwrap_or_default() - }) - .collect::, _>>() - .map_err(anyhow::Error::from) -} - -fn build_glob_set(globs: &[impl AsRef]) -> Result { - globs - .iter() - .try_fold(GlobSetBuilder::new(), |mut globset_builder, glob_raw| { - let glob_raw = glob_raw - .as_ref() - .trim_end_matches([path::MAIN_SEPARATOR, '/']); // remove trailing path separator - let glob = if Path::new(glob_raw).is_dir() { - // `globset` can't recognize if it's a directory, - // so we do a trick here. - Cow::from(format!("{glob_raw}/**/*.{{css,scss,sass,less}}")) - } else { - Cow::from(glob_raw) - }; - // Remove the beginning "current directory" mark if existed, - // because when iterating input files, their paths won't start with that mark, - // otherwise the matching will fail. - let mut glob_builder = - GlobBuilder::new(glob.trim_start_matches("./").trim_start_matches(".\\")); - glob_builder.literal_separator(true); - globset_builder.add(glob_builder.build()?); - Ok(globset_builder) - })? - .build() -}