From ffa0af22b79ecd14b4f195b8edb2c5765f8a22a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20L=C3=B6rwald?= <10850250+stefanloerwald@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:36:20 +0200 Subject: [PATCH] [deploy] fix #92: allow syntax use...with / use ... as --- Tests_WebCompiler/SassDependencyTests.cs | 19 +++++++++++++++++++ .../TestCases/Scss/dependency.scss | 2 ++ .../TestCases/Scss/use_with_override.scss | 7 +++++++ Tests_WebCompiler/WholeProgramTests.cs | 2 ++ WebCompiler/Compile/SassCompiler.cs | 10 +++++++--- WebCompiler/package.csproj | 2 +- 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 Tests_WebCompiler/SassDependencyTests.cs create mode 100644 Tests_WebCompiler/TestCases/Scss/dependency.scss create mode 100644 Tests_WebCompiler/TestCases/Scss/use_with_override.scss diff --git a/Tests_WebCompiler/SassDependencyTests.cs b/Tests_WebCompiler/SassDependencyTests.cs new file mode 100644 index 0000000..9d93f97 --- /dev/null +++ b/Tests_WebCompiler/SassDependencyTests.cs @@ -0,0 +1,19 @@ +using NUnit.Framework; +using System.IO; +using System.Linq; +using WebCompiler.Compile; +using WebCompiler.Configuration.Settings; + +namespace Tests_WebCompiler +{ + internal class SassDependencyTests + { + [Test] + public void TestUseWithOverrides() + { + var compiler = new SassCompiler(new SassSettings()); + var dependencies = compiler.GetDependencies("../../../TestCases/Scss/use_with_override.scss"); + Assert.That(dependencies.Select(Path.GetFileName), Is.EqualTo(new[] {"use_with_override.scss", "dependency.scss", "test.scss", "_variables.scss", "relative.scss", "foo.scss", "_bar.scss" })); + } + } +} diff --git a/Tests_WebCompiler/TestCases/Scss/dependency.scss b/Tests_WebCompiler/TestCases/Scss/dependency.scss new file mode 100644 index 0000000..b5d15d8 --- /dev/null +++ b/Tests_WebCompiler/TestCases/Scss/dependency.scss @@ -0,0 +1,2 @@ + +$color: 'red' !default; diff --git a/Tests_WebCompiler/TestCases/Scss/use_with_override.scss b/Tests_WebCompiler/TestCases/Scss/use_with_override.scss new file mode 100644 index 0000000..60b1a7e --- /dev/null +++ b/Tests_WebCompiler/TestCases/Scss/use_with_override.scss @@ -0,0 +1,7 @@ +@use "dependency.scss" with ( +/* Overrides */ +$color: #ff0000, ); + +@import "test.scss", "_variables.scss"; + +@use "sub/relative.scss" as *; \ No newline at end of file diff --git a/Tests_WebCompiler/WholeProgramTests.cs b/Tests_WebCompiler/WholeProgramTests.cs index a51497b..4b097ab 100644 --- a/Tests_WebCompiler/WholeProgramTests.cs +++ b/Tests_WebCompiler/WholeProgramTests.cs @@ -565,6 +565,8 @@ public void ScssFilesAndFoldersConfiguredToBeIgnoredAreIgnored() "../../../TestCases/Scss/IgnoreFolder/SubFolder/test.css", "../../../TestCases/Scss/_variables.css", "../../../TestCases/Scss/site.css", + "../../../TestCases/Scss/dependency.css", + "../../../TestCases/Scss/use_with_override.css", "../../../TestCases/Scss/test.css", "../../../TestCases/Scss/sub/_bar.css", "../../../TestCases/Scss/sub/foo.css", diff --git a/WebCompiler/Compile/SassCompiler.cs b/WebCompiler/Compile/SassCompiler.cs index 449c7a1..f3cb192 100644 --- a/WebCompiler/Compile/SassCompiler.cs +++ b/WebCompiler/Compile/SassCompiler.cs @@ -111,7 +111,7 @@ public override CompilerResult Compile(List<(string File, bool Created)> file_se } internal static readonly Regex SassDependencyRegex = new Regex(@"(?<=@(import|use|forward)(?:[\s]+))(?:(?:\(\w+\)))?\s*(?:url)?(?[^;]+)", RegexOptions.Multiline); - private List GetDependencies(string file) + public List GetDependencies(string file) { var dependencies = new HashSet { file }; var candidates = new HashSet { file }; @@ -141,11 +141,15 @@ private List GetDependencies(string file) } return dependencies.ToList(); } - + private static Regex PathWithOverrideRegex = new Regex(@"(""[^""]+"")\s+(with|as)"); private static IEnumerable GetFileInfos(FileInfo info, Match match) { var url = match.Groups["url"].Value.Replace("'", "\"").Replace("(", "").Replace(")", "").Replace(";", "").Trim(); - + var matches = PathWithOverrideRegex.Matches(url); + if (matches.Any() && matches[0].Groups.Count > 1) + { + url = matches[0].Groups[1].Value; + } foreach (var name in url.Split(new[] { "\"," }, StringSplitOptions.RemoveEmptyEntries)) { var value = name.Replace("\"", "").Replace('/', Path.DirectorySeparatorChar).Trim(); diff --git a/WebCompiler/package.csproj b/WebCompiler/package.csproj index fa29e6b..026a1cc 100644 --- a/WebCompiler/package.csproj +++ b/WebCompiler/package.csproj @@ -20,7 +20,7 @@ Excubo.WebCompiler - 3.8.26 + 3.9.0