Skip to content

Commit 3fde41b

Browse files
nickdarnellKeats
authored andcommitted
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)
1 parent 2a445fa commit 3fde41b

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

components/site/src/sass.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
use std::fs::create_dir_all;
22
use std::path::{Path, PathBuf};
33

4-
use libs::glob::glob;
4+
use libs::walkdir::{WalkDir, DirEntry};
5+
use libs::globset::{Glob};
56
use libs::sass_rs::{compile_file, Options, OutputStyle};
67

78
use crate::anyhow;
89
use errors::{bail, Result};
910
use utils::fs::{create_file, ensure_directory_exists};
1011

1112
pub fn compile_sass(base_path: &Path, output_path: &Path) -> Result<()> {
13+
console::info("compiling sass...");
14+
1215
ensure_directory_exists(output_path)?;
1316

1417
let sass_path = {
@@ -65,19 +68,23 @@ fn compile_sass_glob(
6568
Ok(compiled_paths)
6669
}
6770

71+
fn is_partial_scss(entry: &DirEntry) -> bool {
72+
entry.file_name()
73+
.to_str()
74+
.map(|s| s.starts_with("_"))
75+
.unwrap_or(false)
76+
}
77+
6878
fn get_non_partial_scss(sass_path: &Path, extension: &str) -> Vec<PathBuf> {
69-
let glob_string = format!("{}/**/*.{}", sass_path.display(), extension);
70-
glob(&glob_string)
71-
.expect("Invalid glob for sass")
79+
let glob_string = format!("*.{}", extension);
80+
let glob = Glob::new(glob_string.as_str()).expect("Invalid glob for sass").compile_matcher();
81+
82+
WalkDir::new(sass_path)
83+
.into_iter()
84+
.filter_entry(|e| !is_partial_scss(e))
7285
.filter_map(|e| e.ok())
73-
.filter(|entry| {
74-
!entry
75-
.as_path()
76-
.iter()
77-
.last()
78-
.map(|c| c.to_string_lossy().starts_with('_'))
79-
.unwrap_or(true)
80-
})
86+
.map(|e| e.into_path())
87+
.filter(|e| glob.is_match(e))
8188
.collect::<Vec<_>>()
8289
}
8390

0 commit comments

Comments
 (0)