Skip to content

Commit 7c2583b

Browse files
committed
Sass: Removes post-processing path normalization.
LibSass does not support relative paths resolution. Nor does ruby-sass (unless we use Compass). At present, WE tries to resolve the URLs in the post-compilation step by using one base path. This misleads in the scenarios where we have nested imports and the meaning of 'relative path' need to be twisted to justify the outcome. :) Less provides this functionality OOTB. We will have to wait for LibSass to provide this functionality; either sass/libsass#674 or sass/libsass#532 gets addressed;
1 parent 75609c5 commit 7c2583b

File tree

8 files changed

+27
-70
lines changed

8 files changed

+27
-70
lines changed

EditorExtensions/JavaScript/Linters/JsHintCompiler.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,5 @@ protected override string GetPath(string sourceFileName, string targetFileName)
3838

3939
return parameters.FlattenParameters();
4040
}
41-
42-
protected override string PostProcessResult(string result, string targetFileName, string sourceFileName)
43-
{
44-
return result;
45-
}
4641
}
4742
}

EditorExtensions/Misc/Bundles/BundleGenerator.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ private async static Task<string> CombineFiles(Dictionary<string, string> files,
106106
source.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0 &&
107107
bundle.AdjustRelativePaths)
108108
source = CssUrlNormalizer.NormalizeUrls(
109-
tree: new CssParser().Parse(source, true),
110-
targetFile: bundleFile,
111-
oldBasePath: actualFile
112-
);
109+
tree: new CssParser().Parse(source, true),
110+
targetFile: bundleFile,
111+
oldBasePath: actualFile);
113112
}
114113
else if (Path.GetExtension(file).Equals(".ts", StringComparison.OrdinalIgnoreCase))
115114
{

EditorExtensions/SCSS/Compilers/ScssCompiler.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System;
2-
using System.ComponentModel.Composition;
1+
using System.ComponentModel.Composition;
32
using System.Globalization;
43
using System.IO;
54
using System.Threading.Tasks;
65
using System.Web;
7-
using MadsKristensen.EditorExtensions.Helpers;
86
using MadsKristensen.EditorExtensions.RtlCss;
97
using MadsKristensen.EditorExtensions.Settings;
10-
using Microsoft.CSS.Core;
118
using Microsoft.VisualStudio.Utilities;
129
using Microsoft.Web.Editor;
1310

@@ -84,31 +81,5 @@ protected override string GetPath(string sourceFileName, string targetFileName)
8481

8582
return parameters.FlattenParameters();
8683
}
87-
88-
protected override string PostProcessResult(string result, string targetFileName, string sourceFileName)
89-
{
90-
// If the caller wants us to renormalize URLs to a different filename, do so.
91-
if (targetFileName != null &&
92-
WESettings.Instance.Scss.AdjustRelativePaths &&
93-
result.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0)
94-
{
95-
try
96-
{
97-
result = CssUrlNormalizer.NormalizeUrls(
98-
tree: new CssParser().Parse(result, true),
99-
targetFile: targetFileName,
100-
oldBasePath: sourceFileName);
101-
}
102-
catch (Exception ex)
103-
{
104-
Logger.Log(ServiceName + ": An error occurred while normalizing generated paths in " + sourceFileName + "\r\n" + ex);
105-
return result;
106-
}
107-
}
108-
109-
Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");
110-
111-
return result;
112-
}
11384
}
11485
}

EditorExtensions/Settings/WESettings.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -604,25 +604,22 @@ void OnEnableChainCompilationChanged(EventArgs e)
604604
}
605605
}
606606

607-
public abstract class CssChainableCompilationSettings<T> : ChainableCompilationSettings<T>, IChainableCompilerSettings where T : CssChainableCompilationSettings<T>
608-
{
609-
[Category("Compilation")]
610-
[DisplayName("Adjust Relative Paths")]
611-
[Description("Adjust relative paths in post-processing step. This option only works when \"Custom output directory\" is used.")]
612-
[DefaultValue(true)]
613-
public bool AdjustRelativePaths { get; set; }
614-
}
615-
616-
public sealed class LessSettings : CssChainableCompilationSettings<LessSettings>
607+
public sealed class LessSettings : ChainableCompilationSettings<LessSettings>
617608
{
618609
[Category("Compilation")]
619610
[DisplayName("Strict Math")]
620611
[Description("With this option turned off, LESS will try and process all maths in your CSS.")]
621612
[DefaultValue(false)]
622613
public bool StrictMath { get; set; }
614+
615+
[Category("Compilation")]
616+
[DisplayName("Adjust Relative Paths")]
617+
[Description("Adjust relative paths in post-processing step.")]
618+
[DefaultValue(true)]
619+
public bool AdjustRelativePaths { get; set; }
623620
}
624621

625-
public sealed class ScssSettings : CssChainableCompilationSettings<ScssSettings>
622+
public sealed class ScssSettings : ChainableCompilationSettings<ScssSettings>
626623
{
627624
public enum OutputFormat
628625
{

EditorExtensions/Shared/Compilers/CssCompilerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected async override Task PostWritingResult(CompilerResult result)
1414

1515
private async Task HandleRtlCss(CompilerResult result)
1616
{
17-
string value = PostProcessResult(result.RtlResult, result.RtlTargetFileName, result.RtlSourceFileName);
17+
string value = result.RtlResult;
1818

1919
// Write output file
2020
if (result.RtlTargetFileName != null && (MinifyInPlace || !File.Exists(result.RtlTargetFileName) ||

EditorExtensions/Shared/Compilers/NodeExecutorBase.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,19 @@ private async Task<CompilerResult> ProcessResult(CompilerResult result, bool onl
5959
return result;
6060
}
6161

62-
string resultString = PostProcessResult(result.Result, result.TargetFileName, result.SourceFileName);
62+
if (this is ILintCompiler)
63+
return result;
64+
65+
Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");
6366

64-
if ((this is ILintCompiler) && !onlyPreview)
67+
if (!onlyPreview)
6568
{
6669
// Write output file
6770
if (result.TargetFileName != null && (MinifyInPlace || !File.Exists(result.TargetFileName) ||
68-
resultString != await FileHelpers.ReadAllTextRetry(result.TargetFileName)))
71+
result.Result != await FileHelpers.ReadAllTextRetry(result.TargetFileName)))
6972
{
7073
ProjectHelpers.CheckOutFileFromSourceControl(result.TargetFileName);
71-
await FileHelpers.WriteAllTextRetry(result.TargetFileName, resultString);
74+
await FileHelpers.WriteAllTextRetry(result.TargetFileName, result.Result);
7275
ProjectHelpers.AddFileToProject(result.SourceFileName, result.TargetFileName);
7376
}
7477

@@ -84,7 +87,7 @@ private async Task<CompilerResult> ProcessResult(CompilerResult result, bool onl
8487
await PostWritingResult(result);
8588
}
8689

87-
return CompilerResult.UpdateResult(result, resultString);
90+
return result;
8891
}
8992

9093
public static string GetOrCreateGlobalSettings(string fileName)
@@ -106,12 +109,6 @@ protected virtual Task PostWritingResult(CompilerResult result)
106109
return Task.Factory.StartNew(() => { });
107110
}
108111

109-
protected virtual string PostProcessResult(string result, string targetFileName, string sourceFileName)
110-
{
111-
Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled.");
112-
return result;
113-
}
114-
115112
protected abstract string GetPath(string sourceFileName, string targetFileName);
116113
}
117114
}

EditorExtensions/Shared/Compilers/Result/CompilerResult.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,5 @@ public static CompilerResult GenerateResult(string sourceFileName, string target
4747
{
4848
return new CompilerResult(sourceFileName, targetFileName, mapFileName, isSuccess, result, resultMap, errors, hasSkipped);
4949
}
50-
51-
internal static CompilerResult UpdateResult(CompilerResult result, string resultString)
52-
{
53-
result.Result = resultString;
54-
return result;
55-
}
5650
}
5751
}

EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ class CssUrlNormalizer : ICssSimpleTreeVisitor
1212
{
1313
readonly string targetFile, oldBaseDirectory;
1414
readonly List<Tuple<TextRange, string>> replacements = new List<Tuple<TextRange, string>>();
15+
1516
private CssUrlNormalizer(string targetFile, string oldBasePath)
1617
{
17-
this.targetFile = Path.GetFullPath(targetFile);
18-
this.oldBaseDirectory = Path.GetDirectoryName(oldBasePath);
18+
targetFile = Path.GetFullPath(targetFile);
19+
oldBaseDirectory = Path.GetDirectoryName(oldBasePath);
1920
}
2021

2122
///<summary>Normalizes all URLs in a CSS parse tree to be relative to the specified directory.</summary>
@@ -34,6 +35,7 @@ private CssUrlNormalizer(string targetFile, string oldBasePath)
3435
public static string NormalizeUrls(BlockItem tree, string targetFile, string oldBasePath)
3536
{
3637
var normalizer = new CssUrlNormalizer(targetFile, oldBasePath);
38+
3739
tree.Accept(normalizer);
3840

3941
var retVal = new StringBuilder(tree.Text);
@@ -45,6 +47,7 @@ public static string NormalizeUrls(BlockItem tree, string targetFile, string old
4547
retVal.Remove(range.Start, range.Length);
4648
retVal.Insert(range.Start, HttpUtility.UrlPathEncode(url));
4749
}
50+
4851
return retVal.ToString();
4952
}
5053

@@ -55,6 +58,7 @@ public VisitItemResult Visit(ParseItem parseItem)
5558
return VisitItemResult.Continue;
5659

5760
var newUrl = FixPath(DecodeStringLiteral(urlItem.UrlString.Text));
61+
5862
if (newUrl == null) // No change
5963
return VisitItemResult.Continue;
6064

0 commit comments

Comments
 (0)