diff --git a/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs b/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs index 1d1617914..f8aa264fd 100644 --- a/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs +++ b/EditorExtensions/JavaScript/Linters/JsHintCompiler.cs @@ -38,10 +38,5 @@ protected override string GetPath(string sourceFileName, string targetFileName) return parameters.FlattenParameters(); } - - protected override string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - return result; - } } } diff --git a/EditorExtensions/Misc/Bundles/BundleGenerator.cs b/EditorExtensions/Misc/Bundles/BundleGenerator.cs index 910f0d474..d6348a2b2 100644 --- a/EditorExtensions/Misc/Bundles/BundleGenerator.cs +++ b/EditorExtensions/Misc/Bundles/BundleGenerator.cs @@ -106,10 +106,9 @@ private async static Task CombineFiles(Dictionary files, source.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0 && bundle.AdjustRelativePaths) source = CssUrlNormalizer.NormalizeUrls( - tree: new CssParser().Parse(source, true), - targetFile: bundleFile, - oldBasePath: actualFile - ); + tree: new CssParser().Parse(source, true), + targetFile: bundleFile, + oldBasePath: actualFile); } else if (Path.GetExtension(file).Equals(".ts", StringComparison.OrdinalIgnoreCase)) { diff --git a/EditorExtensions/SCSS/Compilers/ScssCompiler.cs b/EditorExtensions/SCSS/Compilers/ScssCompiler.cs index 7dd949462..4dd52f561 100644 --- a/EditorExtensions/SCSS/Compilers/ScssCompiler.cs +++ b/EditorExtensions/SCSS/Compilers/ScssCompiler.cs @@ -1,13 +1,10 @@ -using System; -using System.ComponentModel.Composition; +using System.ComponentModel.Composition; using System.Globalization; using System.IO; using System.Threading.Tasks; using System.Web; -using MadsKristensen.EditorExtensions.Helpers; using MadsKristensen.EditorExtensions.RtlCss; using MadsKristensen.EditorExtensions.Settings; -using Microsoft.CSS.Core; using Microsoft.VisualStudio.Utilities; using Microsoft.Web.Editor; @@ -84,31 +81,5 @@ protected override string GetPath(string sourceFileName, string targetFileName) return parameters.FlattenParameters(); } - - protected override string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - // If the caller wants us to renormalize URLs to a different filename, do so. - if (targetFileName != null && - WESettings.Instance.Scss.AdjustRelativePaths && - result.IndexOf("url(", StringComparison.OrdinalIgnoreCase) > 0) - { - try - { - result = CssUrlNormalizer.NormalizeUrls( - tree: new CssParser().Parse(result, true), - targetFile: targetFileName, - oldBasePath: sourceFileName); - } - catch (Exception ex) - { - Logger.Log(ServiceName + ": An error occurred while normalizing generated paths in " + sourceFileName + "\r\n" + ex); - return result; - } - } - - Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - - return result; - } } } diff --git a/EditorExtensions/Settings/WESettings.cs b/EditorExtensions/Settings/WESettings.cs index c9681884a..06b94ecf2 100644 --- a/EditorExtensions/Settings/WESettings.cs +++ b/EditorExtensions/Settings/WESettings.cs @@ -604,25 +604,22 @@ void OnEnableChainCompilationChanged(EventArgs e) } } - public abstract class CssChainableCompilationSettings : ChainableCompilationSettings, IChainableCompilerSettings where T : CssChainableCompilationSettings - { - [Category("Compilation")] - [DisplayName("Adjust Relative Paths")] - [Description("Adjust relative paths in post-processing step. This option only works when \"Custom output directory\" is used.")] - [DefaultValue(true)] - public bool AdjustRelativePaths { get; set; } - } - - public sealed class LessSettings : CssChainableCompilationSettings + public sealed class LessSettings : ChainableCompilationSettings { [Category("Compilation")] [DisplayName("Strict Math")] [Description("With this option turned off, LESS will try and process all maths in your CSS.")] [DefaultValue(false)] public bool StrictMath { get; set; } + + [Category("Compilation")] + [DisplayName("Adjust Relative Paths")] + [Description("Adjust relative paths in post-processing step.")] + [DefaultValue(true)] + public bool AdjustRelativePaths { get; set; } } - public sealed class ScssSettings : CssChainableCompilationSettings + public sealed class ScssSettings : ChainableCompilationSettings { public enum OutputFormat { diff --git a/EditorExtensions/Shared/Compilers/CssCompilerBase.cs b/EditorExtensions/Shared/Compilers/CssCompilerBase.cs index 80a1510e7..0062d7d60 100644 --- a/EditorExtensions/Shared/Compilers/CssCompilerBase.cs +++ b/EditorExtensions/Shared/Compilers/CssCompilerBase.cs @@ -14,7 +14,7 @@ protected async override Task PostWritingResult(CompilerResult result) private async Task HandleRtlCss(CompilerResult result) { - string value = PostProcessResult(result.RtlResult, result.RtlTargetFileName, result.RtlSourceFileName); + string value = result.RtlResult; // Write output file if (result.RtlTargetFileName != null && (MinifyInPlace || !File.Exists(result.RtlTargetFileName) || diff --git a/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs b/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs index 13ba6053c..7f30e0c3a 100644 --- a/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs +++ b/EditorExtensions/Shared/Compilers/NodeExecutorBase.cs @@ -59,16 +59,19 @@ private async Task ProcessResult(CompilerResult result, bool onl return result; } - string resultString = PostProcessResult(result.Result, result.TargetFileName, result.SourceFileName); + if (this is ILintCompiler) + return result; + + Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - if ((this is ILintCompiler) && !onlyPreview) + if (!onlyPreview) { // Write output file if (result.TargetFileName != null && (MinifyInPlace || !File.Exists(result.TargetFileName) || - resultString != await FileHelpers.ReadAllTextRetry(result.TargetFileName))) + result.Result != await FileHelpers.ReadAllTextRetry(result.TargetFileName))) { ProjectHelpers.CheckOutFileFromSourceControl(result.TargetFileName); - await FileHelpers.WriteAllTextRetry(result.TargetFileName, resultString); + await FileHelpers.WriteAllTextRetry(result.TargetFileName, result.Result); ProjectHelpers.AddFileToProject(result.SourceFileName, result.TargetFileName); } @@ -84,7 +87,7 @@ private async Task ProcessResult(CompilerResult result, bool onl await PostWritingResult(result); } - return CompilerResult.UpdateResult(result, resultString); + return result; } public static string GetOrCreateGlobalSettings(string fileName) @@ -106,12 +109,6 @@ protected virtual Task PostWritingResult(CompilerResult result) return Task.Factory.StartNew(() => { }); } - protected virtual string PostProcessResult(string result, string targetFileName, string sourceFileName) - { - Logger.Log(ServiceName + ": " + Path.GetFileName(sourceFileName) + " compiled."); - return result; - } - protected abstract string GetPath(string sourceFileName, string targetFileName); } } diff --git a/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs b/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs index 3dadd54df..1e08094c3 100644 --- a/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs +++ b/EditorExtensions/Shared/Compilers/Result/CompilerResult.cs @@ -47,11 +47,5 @@ public static CompilerResult GenerateResult(string sourceFileName, string target { return new CompilerResult(sourceFileName, targetFileName, mapFileName, isSuccess, result, resultMap, errors, hasSkipped); } - - internal static CompilerResult UpdateResult(CompilerResult result, string resultString) - { - result.Result = resultString; - return result; - } } } diff --git a/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs b/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs index 812dacd0f..daead801c 100644 --- a/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs +++ b/EditorExtensions/Shared/Helpers/Css/CssUrlNormalizer.cs @@ -12,10 +12,11 @@ class CssUrlNormalizer : ICssSimpleTreeVisitor { readonly string targetFile, oldBaseDirectory; readonly List> replacements = new List>(); + private CssUrlNormalizer(string targetFile, string oldBasePath) { - this.targetFile = Path.GetFullPath(targetFile); - this.oldBaseDirectory = Path.GetDirectoryName(oldBasePath); + targetFile = Path.GetFullPath(targetFile); + oldBaseDirectory = Path.GetDirectoryName(oldBasePath); } ///Normalizes all URLs in a CSS parse tree to be relative to the specified directory. @@ -34,6 +35,7 @@ private CssUrlNormalizer(string targetFile, string oldBasePath) public static string NormalizeUrls(BlockItem tree, string targetFile, string oldBasePath) { var normalizer = new CssUrlNormalizer(targetFile, oldBasePath); + tree.Accept(normalizer); var retVal = new StringBuilder(tree.Text); @@ -45,6 +47,7 @@ public static string NormalizeUrls(BlockItem tree, string targetFile, string old retVal.Remove(range.Start, range.Length); retVal.Insert(range.Start, HttpUtility.UrlPathEncode(url)); } + return retVal.ToString(); } @@ -55,6 +58,7 @@ public VisitItemResult Visit(ParseItem parseItem) return VisitItemResult.Continue; var newUrl = FixPath(DecodeStringLiteral(urlItem.UrlString.Text)); + if (newUrl == null) // No change return VisitItemResult.Continue;