Skip to content

Commit

Permalink
[deploy] fix #92: allow syntax use...with / use ... as
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanloerwald committed Jul 4, 2024
1 parent f024b74 commit ffa0af2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
19 changes: 19 additions & 0 deletions Tests_WebCompiler/SassDependencyTests.cs
Original file line number Diff line number Diff line change
@@ -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" }));
}
}
}
2 changes: 2 additions & 0 deletions Tests_WebCompiler/TestCases/Scss/dependency.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

$color: 'red' !default;
7 changes: 7 additions & 0 deletions Tests_WebCompiler/TestCases/Scss/use_with_override.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use "dependency.scss" with (
/* Overrides */
$color: #ff0000, );

@import "test.scss", "_variables.scss";

@use "sub/relative.scss" as *;
2 changes: 2 additions & 0 deletions Tests_WebCompiler/WholeProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions WebCompiler/Compile/SassCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?(?<url>[^;]+)", RegexOptions.Multiline);
private List<string> GetDependencies(string file)
public List<string> GetDependencies(string file)
{
var dependencies = new HashSet<string> { file };
var candidates = new HashSet<string> { file };
Expand Down Expand Up @@ -141,11 +141,15 @@ private List<string> GetDependencies(string file)
}
return dependencies.ToList();
}

private static Regex PathWithOverrideRegex = new Regex(@"(""[^""]+"")\s+(with|as)");
private static IEnumerable<string> 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();
Expand Down
2 changes: 1 addition & 1 deletion WebCompiler/package.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!--PackageId, Version-->
<PropertyGroup>
<PackageId>Excubo.WebCompiler</PackageId>
<VersionPrefix>3.8.26</VersionPrefix>
<VersionPrefix>3.9.0</VersionPrefix>
<!--<VersionSuffix>preview.1</VersionSuffix>-->
</PropertyGroup>
<!--Self Include-->
Expand Down

0 comments on commit ffa0af2

Please sign in to comment.