Skip to content

Commit

Permalink
The Glob library does not work correctly on windows. This changes the…
Browse files Browse the repository at this point in the history
… 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)
  • Loading branch information
nickdarnell authored and Keats committed Aug 14, 2022
1 parent 2a445fa commit 3fde41b
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions components/site/src/sass.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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;
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 = {
Expand Down Expand Up @@ -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<PathBuf> {
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::<Vec<_>>()
}

Expand Down

0 comments on commit 3fde41b

Please sign in to comment.