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)

This commit is contained in:
Nick Darnell 2022-08-10 17:42:16 -04:00 committed by Vincent Prouillet
parent 2a445fa4dc
commit 3fde41b6e5

View File

@ -1,7 +1,8 @@
use std::fs::create_dir_all; use std::fs::create_dir_all;
use std::path::{Path, PathBuf}; 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 libs::sass_rs::{compile_file, Options, OutputStyle};
use crate::anyhow; use crate::anyhow;
@ -9,6 +10,8 @@ use errors::{bail, Result};
use utils::fs::{create_file, ensure_directory_exists}; use utils::fs::{create_file, ensure_directory_exists};
pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> { pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> {
console::info("compiling sass...");
ensure_directory_exists(output_path)?; ensure_directory_exists(output_path)?;
let sass_path = { let sass_path = {
@ -65,19 +68,23 @@ fn compile_sass_glob(
Ok(compiled_paths) 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<PathBuf> { fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {
let glob_string = format!("{}/**/*.{}", sass_path.display(), extension); let glob_string = format!("*.{}", extension);
glob(&glob_string) let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher();
.expect("Invalid glob for sass")
WalkDir::new(sass_path)
.into_iter()
.filter_entry(|e| !is_partial_scss(e))
.filter_map(|e| e.ok()) .filter_map(|e| e.ok())
.filter(|entry| { .map(|e| e.into_path())
!entry .filter(|e| glob.is_match(e))
.as_path()
.iter()
.last()
.map(|c| c.to_string_lossy().starts_with('_'))
.unwrap_or(true)
})
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }