From e2c32a66de62a103444cfd65ab8d930fd01d9dee Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Tue, 31 May 2022 09:43:45 -0400 Subject: [PATCH] load paths are local to executable, not SCSS file --- src/parse/import.rs | 12 ++++-------- tests/imports.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/parse/import.rs b/src/parse/import.rs index 68a7858..79e18c4 100644 --- a/src/parse/import.rs +++ b/src/parse/import.rs @@ -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")); diff --git a/tests/imports.rs b/tests/imports.rs index 0c5e8fc..848e37c 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -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 =