From 9de79beef563cc9eb4d5f5edbb69c0eed85efb78 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 1 Nov 2022 21:33:36 -0500 Subject: [PATCH] fix!: Switch from libsass to grass Not perfect SASS compatibility Fixes #1050 --- Cargo.lock | 182 +++++++++++++++++++++++++++++++++------ Cargo.toml | 5 +- src/cobalt_model/sass.rs | 33 +++---- 3 files changed, 170 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 93256d2e..f7bed0c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,17 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.19" @@ -104,6 +115,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "beef" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1" + [[package]] name = "bincode" version = "1.3.3" @@ -296,6 +313,7 @@ dependencies = [ "exitfailure", "failure", "file-serve", + "grass", "html-minifier", "human-panic", "ignore", @@ -314,7 +332,6 @@ dependencies = [ "regex", "relative-path", "rss", - "sass-rs", "scrawl", "serde", "serde_json", @@ -362,6 +379,12 @@ dependencies = [ "walkdir", ] +[[package]] +name = "codemap" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e769b5c8c8283982a987c6e948e540254f1058d5a74b8794914d4ef5fc2a24" + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -1021,6 +1044,32 @@ dependencies = [ "regex", ] +[[package]] +name = "grass" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5bedc3dbd71dcdd41900e1f58e4d431fa69dd67c04ae1f86ae1a0339edd849" +dependencies = [ + "beef", + "codemap", + "indexmap", + "lasso", + "num-bigint", + "num-rational", + "num-traits", + "once_cell", + "phf", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -1165,7 +1214,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -1268,6 +1317,15 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "lasso" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8647c8a01e5f7878eacb2c323c4c949fdb63773110f0686c7810769874b7e0a" +dependencies = [ + "hashbrown 0.11.2", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1569,6 +1627,18 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1710,10 +1780,48 @@ dependencies = [ ] [[package]] -name = "pkg-config" -version = "0.3.26" +name = "phf" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ac8b67553a7ca9457ce0e526948cad581819238f4a9d1ea74545851fa24f37" +dependencies = [ + "phf_macros", + "phf_shared", + "proc-macro-hack", +] + +[[package]] +name = "phf_generator" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "d43f3220d96e0080cc9ea234978ccd80d904eafb17be31bb0f76daaea6493082" +dependencies = [ + "phf_shared", + "rand", +] + +[[package]] +name = "phf_macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b706f5936eb50ed880ae3009395b43ed19db5bff2ebd459c95e7bf013a89ab86" +dependencies = [ + "phf_generator", + "phf_shared", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "phf_shared" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68318426de33640f02be62b4ae8eb1261be2efbc337b60c54d845bf4484e0d9" +dependencies = [ + "siphasher", +] [[package]] name = "plist" @@ -1729,6 +1837,12 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + [[package]] name = "proc-exit" version = "2.0.0" @@ -1834,6 +1948,36 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "rayon" version = "1.5.3" @@ -1975,28 +2119,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "sass-rs" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cabcf7c6e55053f359911187ac401409aad2dc14338cae972dec266fee486abd" -dependencies = [ - "libc", - "sass-sys", -] - -[[package]] -name = "sass-sys" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "933bca23b402377f0ab71e79732a826deffc748013746ac3314f6abc7f9fc51c" -dependencies = [ - "cc", - "libc", - "num_cpus", - "pkg-config", -] - [[package]] name = "scopeguard" version = "1.1.0" @@ -2119,6 +2241,12 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62ac7f900db32bf3fd12e0117dd3dc4da74bc52ebaac97f39668446d89694803" +[[package]] +name = "siphasher" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" + [[package]] name = "sitemap" version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index 132cfc88..7454c00e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,9 +103,8 @@ vimwiki = { version = "0.1", features = ["html"] } file-serve = { version = "0.2.1", path = "crates/file-serve", optional = true } notify = { version = "4", optional = true } -sass-rs = { version = "0.2", optional = true } - html-minifier = {version="3.0", optional = true } +grass = { version = "0.11.2", default-features = false } [dev-dependencies] trycmd = "0.14" @@ -118,7 +117,7 @@ preview_unstable = ["cobalt-config/preview_unstable"] serve = ["file-serve", "notify"] syntax-highlight = ["engarde/syntax"] -sass = ['sass-rs'] +sass = [] [profile.release] lto = "thin" diff --git a/src/cobalt_model/sass.rs b/src/cobalt_model/sass.rs index 21a8dd01..7d9b2bdb 100644 --- a/src/cobalt_model/sass.rs +++ b/src/cobalt_model/sass.rs @@ -1,8 +1,6 @@ use std::ffi; use std::path; -#[cfg(feature = "sass")] -use sass_rs; use serde::{Deserialize, Serialize}; use super::files; @@ -13,7 +11,7 @@ pub use cobalt_config::SassOutputStyle; #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] #[serde(deny_unknown_fields, default)] pub struct SassBuilder { - pub import_dir: Option, + pub import_dir: std::path::PathBuf, pub style: SassOutputStyle, } @@ -21,11 +19,7 @@ impl SassBuilder { pub fn from_config(config: cobalt_config::Sass, source: &path::Path) -> Self { Self { style: config.style, - import_dir: source - .join(config.import_dir) - .into_os_string() - .into_string() - .ok(), + import_dir: source.join(config.import_dir), } } @@ -37,7 +31,7 @@ impl SassBuilder { #[derive(Debug, PartialEq, Eq)] pub struct SassCompiler { - import_dir: Option, + import_dir: std::path::PathBuf, style: SassOutputStyle, } @@ -60,17 +54,16 @@ impl SassCompiler { file_path: &path::Path, minify: &Minify, ) -> Result<()> { - let sass_opts = sass_rs::Options { - include_paths: self.import_dir.iter().cloned().collect(), - output_style: match self.style { - SassOutputStyle::Nested => sass_rs::OutputStyle::Nested, - SassOutputStyle::Expanded => sass_rs::OutputStyle::Expanded, - SassOutputStyle::Compact => sass_rs::OutputStyle::Compact, - SassOutputStyle::Compressed => sass_rs::OutputStyle::Compressed, - }, - ..Default::default() - }; - let content = sass_rs::compile_file(file_path, sass_opts).map_err(failure::err_msg)?; + let sass_opts = grass::Options::default() + .style(match self.style { + SassOutputStyle::Nested | SassOutputStyle::Expanded => grass::OutputStyle::Expanded, + SassOutputStyle::Compact | SassOutputStyle::Compressed => { + grass::OutputStyle::Compressed + } + }) + .load_path(&self.import_dir); + let raw = std::fs::read_to_string(file_path)?; + let content = grass::from_string(raw, &sass_opts)?; let rel_src = file_path .strip_prefix(source)