load paths are local to executable, not SCSS file

This commit is contained in:
Connor Skees 2022-05-31 09:43:45 -04:00
parent 93ad5caa39
commit e2c32a66de
2 changed files with 27 additions and 8 deletions

View File

@ -64,16 +64,12 @@ impl<'a, 'b> Parser<'a, 'b> {
for path in &self.options.load_paths {
if self.options.fs.is_dir(path) {
try_path!(path.join(name).with_extension("scss"));
try_path!(path
.join(&path_buf)
.with_file_name(name)
.join(format!("_{}", name.to_str().unwrap()))
.with_extension("scss"));
try_path!(path
.join(&path_buf)
.with_file_name(format!("_{}", name.to_str().unwrap()))
.with_extension("scss"));
try_path!(path.join(&path_buf).join("index.scss"));
try_path!(path.join(&path_buf).join("_index.scss"));
try_path!(path.join("index.scss"));
try_path!(path.join("_index.scss"));
} else {
try_path!(path.to_path_buf());
try_path!(path.with_file_name(name).with_extension("scss"));

View File

@ -94,6 +94,29 @@ fn comma_separated_import_order_css() {
);
}
#[test]
fn basic_load_path() {
tempfile!(
"basic_load_path__a.scss",
"@import \"basic_load_path__b\";\na {\n color: $a;\n}",
dir = "dir-basic_load_path__a"
);
tempfile!(
"basic_load_path__b.scss",
"$a: red;",
dir = "dir-basic_load_path__b"
);
assert_eq!(
"a {\n color: red;\n}\n",
grass::from_path(
"dir-basic_load_path__a/basic_load_path__a.scss",
&grass::Options::default().load_path(std::path::Path::new("dir-basic_load_path__b"))
)
.unwrap()
);
}
#[test]
fn comma_separated_import_trailing() {
let input =