From 3fde41b6e5794403d4fad40d590c3d636e531fe5 Mon Sep 17 00:00:00 2001 From: Nick Darnell Date: Wed, 10 Aug 2022 17:42:16 -0400 Subject: [PATCH] The Glob library does not work correctly on windows. This changes the approach to use the normal WalkDir crate, and the Globset crate instead to find the filter. This new code correctly compiles sass files across platforms now. (#1950) --- components/site/src/sass.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/components/site/src/sass.rs b/components/site/src/sass.rs index ab6bb556..23423bd6 100644 --- a/components/site/src/sass.rs +++ b/components/site/src/sass.rs @@ -1,7 +1,8 @@ use std::fs::create_dir_all; use std::path::{Path, PathBuf}; -use libs::glob::glob; +use libs::walkdir::{WalkDir, DirEntry}; +use libs::globset::{Glob}; use libs::sass_rs::{compile_file, Options, OutputStyle}; use crate::anyhow; @@ -9,6 +10,8 @@ use errors::{bail, Result}; use utils::fs::{create_file, ensure_directory_exists}; pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> { + console::info("compiling sass..."); + ensure_directory_exists(output_path)?; let sass_path = { @@ -65,19 +68,23 @@ fn compile_sass_glob( Ok(compiled_paths) } +fn is_partial_scss(entry: &DirEntry) -> bool { + entry.file_name() + .to_str() + .map(|s| s.starts_with("_")) + .unwrap_or(false) +} + fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec { - let glob_string = format!("{}/**/*.{}", sass_path.display(), extension); - glob(&glob_string) - .expect("Invalid glob for sass") + let glob_string = format!("*.{}", extension); + let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher(); + + WalkDir::new(sass_path) + .into_iter() + .filter_entry(|e| !is_partial_scss(e)) .filter_map(|e| e.ok()) - .filter(|entry| { - !entry - .as_path() - .iter() - .last() - .map(|c| c.to_string_lossy().starts_with('_')) - .unwrap_or(true) - }) + .map(|e| e.into_path()) + .filter(|e| glob.is_match(e)) .collect::>() }