public async Task Source_Map_Removed() { var js = @"!function(e,t){""function""==typeof define&&define.amd?define([],function(); //# sourceMappingURL=tmhDynamicLocale.min.js.map Testing 123 //# sourceMappingURL=https://hello.com/blah.min.js.map ; asdf asdf asd fasdf //# sourceMappingURL=../blah.min.js.map; asdf asdf asd fasdf"; var removeMaps = GetJsSourceMapProcessor(); using (var bc = BundleContext.CreateEmpty()) { var fileProcessContext = new FileProcessContext(js, new JavaScriptFile("js/test.js"), bc); await removeMaps.ProcessAsync(fileProcessContext, ctx => Task.FromResult(0)); Assert.Equal( @"!function(e,t){""function""==typeof define&&define.amd?define([],function(); //# sourceMappingURL=/js/tmhDynamicLocale.min.js.map; Testing 123 //# sourceMappingURL=https://hello.com/blah.min.js.map; asdf asdf asd fasdf //# sourceMappingURL=/blah.min.js.map; asdf asdf asd fasdf".Replace("\r\n", "\n"), fileProcessContext.FileContent.Replace("\r\n", "\n")); } }
public async Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { var result = await _nodeServices.InvokeAsync <string>( _nodeScript.Value.FileName, fileProcessContext.FileContent); fileProcessContext.Update(result); await next(fileProcessContext); }
public async Task <string> GetNuglify() { using (var bc = BundleContext.CreateEmpty()) { var fileProcessContext = new FileProcessContext(JQuery, new JavaScriptFile(), bc); await _nuglify.ProcessAsync(fileProcessContext, s => Task.FromResult(0)); return(fileProcessContext.FileContent); } }
public Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { if (fileProcessContext.WebFile.DependencyType == WebFileType.Js) { throw new InvalidOperationException("Cannot use " + nameof(NuglifyCss) + " with a js file source"); } var result = Uglify.Css(fileProcessContext.FileContent, fileProcessContext.WebFile.FilePath, _settings.CssCodeSettings); if (result.HasErrors) { //TODO: need to format this exception message nicely throw new InvalidOperationException( string.Join(",", result.Errors.Select(x => x.Message))); } fileProcessContext.Update(result.Code); return(next(fileProcessContext)); }
public Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { //Info for source mapping, see http://ajaxmin.codeplex.com/wikipage?title=SourceMaps // as an example, see http://ajaxmin.codeplex.com/SourceControl/latest#AjaxMinTask/AjaxMinManifestTask.cs under ProcessJavaScript // When a source map provider is specified, the process is: // * Create a string builder/writer to capture the output of the source map // * Create a sourcemap from the SourceMapFactory based on the provider name // * Set some V3 source map provider (the default) properties // * Call StartPackage, passing in the file path of the original file and the file path of the map (which will be appended to the end of the minified output) // * Do the minification // * Call EndPackage, and close/dispose of writers // * Get the source map result from the string builder if (fileProcessContext.WebFile.DependencyType == WebFileType.Css) { throw new InvalidOperationException("Cannot use " + nameof(NuglifyJs) + " with a css file source"); } var nuglifyJsCodeSettings = _settings.JsCodeSettings; //Its very important that we clone here because the code settings is a singleton and we are changing it (i.e. the CodeSettings class is mutable) var codeSettings = nuglifyJsCodeSettings.CodeSettings.Clone(); if (nuglifyJsCodeSettings.SourceMapType != SourceMapType.None) { var sourceMap = fileProcessContext.BundleContext.GetSourceMapFromContext(nuglifyJsCodeSettings.SourceMapType); codeSettings.SymbolsMap = sourceMap; //These are a couple of options that could be needed for V3 source maps //sourceRoot is explained here: // http://blog.teamtreehouse.com/introduction-source-maps // https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ //sourceMap.SourceRoot = //SafeHeader is used to avoid XSS and adds some custom json to the top of the file , here's what the source code says: // "if we want to add the cross-site script injection protection string" it adds this to the top ")]}'" // explained here: https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ under "Potential XSSI issues" // ** not needed for inline //sourceMap.SafeHeader = //generate a minified file path - this is really not used but is used in our inline source map like test.js --> test.min.js //var extension = Path.GetExtension(fileProcessContext.WebFile.FilePath); //var minPath = fileProcessContext.WebFile.FilePath.Substring( // 0, // fileProcessContext.WebFile.FilePath.LastIndexOf('.')) + ".min" + extension; //we then need to 'StartPackage', this will be called once per file for the same source map instance but that is ok it doesn't cause any harm var fileName = fileProcessContext.BundleContext.BundleName + fileProcessContext.BundleContext.FileExtension; sourceMap.StartPackage(fileName, fileName + ".map"); } //now do the processing var result = Uglify.Js(fileProcessContext.FileContent, fileProcessContext.WebFile.FilePath, codeSettings); if (result.HasErrors) { throw new InvalidOperationException( string.Join(",", result.Errors.Select(x => x.ToString()))); } fileProcessContext.Update(result.Code); if (nuglifyJsCodeSettings.SourceMapType != SourceMapType.None) { AddSourceMapAppenderToContext(fileProcessContext.BundleContext, nuglifyJsCodeSettings.SourceMapType); } return(next(fileProcessContext)); }
public async Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { await next(fileProcessContext); fileProcessContext.Update(fileProcessContext.FileContent + "\nFooter"); }
public async Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { await next(fileProcessContext); fileProcessContext.Update("Header\n" + fileProcessContext.FileContent); }
public async Task ProcessAsync(FileProcessContext fileProcessContext, PreProcessorDelegate next) { await next(fileProcessContext); fileProcessContext.Update("WrappedHeader\n" + fileProcessContext.FileContent + "\nWrappedFooter"); }