Skip to content

Commit

Permalink
Support the debugger by working around a bug in AjaxMin that hangs wh…
Browse files Browse the repository at this point in the history
…en debugger is attached. Issue#7 in GH. Make it clear this is the case with some messaging in the JS bundles and map files.
  • Loading branch information
benmccallum committed Jun 8, 2015
1 parent e789e14 commit 73a3ee5
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 55 deletions.
48 changes: 24 additions & 24 deletions AspNetBundling.TestWebsite/Web.config
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-AspNetBundling.TestWebsite-20150313112437.mdf;Initial Catalog=aspnet-AspNetBundling.TestWebsite-20150313112437;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-AspNetBundling.TestWebsite-20150313112437.mdf;Initial Catalog=aspnet-AspNetBundling.TestWebsite-20150313112437;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="None"/>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
<remove name="FormsAuthenticationModule"/>
</modules>
<staticContent>
<remove fileExtension=".map"/>
<mimeMap fileExtension=".map" mimeType="application/json" />
<mimeMap fileExtension=".map" mimeType="application/json"/>
</staticContent>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
<parameter value="v11.0"/>
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
</configuration>
8 changes: 0 additions & 8 deletions AspNetBundling.TestWebsite/bundles/bootstrap.map

This file was deleted.

8 changes: 0 additions & 8 deletions AspNetBundling.TestWebsite/bundles/jquery.map

This file was deleted.

8 changes: 0 additions & 8 deletions AspNetBundling.TestWebsite/bundles/modernizr.map

This file was deleted.

5 changes: 5 additions & 0 deletions AspNetBundling.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetBundling", "AspNetBun
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetBundling.TestWebsite", "AspNetBundling.TestWebsite\AspNetBundling.TestWebsite.csproj", "{451C2941-F8ED-41E5-B3A6-35838DAC54BA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".misc", ".misc", "{4E5D30FA-B329-40BA-B542-C2D12E01714A}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion AspNetBundling/AdHocBundleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public string BuildBundleContent(Bundle bundle, BundleContext context, IEnumerab
var adHocBundle = bundle as AdHocBundle;
if (adHocBundle == null)
{
throw new ArgumentException(String.Format("The AdHocBundleBuilder is only meant to be used by an AdHocBundle. This one is called from a bundle of typy '{0}'", bundle.GetType()), "bundle");
throw new ArgumentException(String.Format("The AdHocBundleBuilder is only meant to be used by an AdHocBundle. This one is called from a bundle of type '{0}'", bundle.GetType()), "bundle");
}
return adHocBundle.Content;
}
Expand Down
6 changes: 3 additions & 3 deletions AspNetBundling/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AspNetBundling")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyVersion("2.0.1.0")]
[assembly: AssemblyFileVersion("2.0.1.0")]
33 changes: 30 additions & 3 deletions AspNetBundling/ScriptWithSourceMapBundleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string BuildBundleContent(Bundle bundle, BundleContext context, IEnumerab

// Generates source map using an approach documented here: http://ajaxmin.codeplex.com/discussions/446616
var sourcePath = VirtualPathUtility.ToAbsolute(bundle.Path);
var mapVirtualPath = string.Concat(bundle.Path, ".map");
var mapVirtualPath = string.Concat(bundle.Path, "map"); // don't use .map so it's picked up by the bundle module
var mapPath = VirtualPathUtility.ToAbsolute(mapVirtualPath);

// Concatenate file contents to be minified, including the sourcemap hints
Expand Down Expand Up @@ -68,9 +68,17 @@ public string BuildBundleContent(Bundle bundle, BundleContext context, IEnumerab
contentWriter.Write(contentMinified);
}

//Write the SourceMap to another Bundle
// Write the SourceMap to another Bundle
AddContentToAdHocBundle(context, mapVirtualPath, mapBuilder.ToString());

// Note: A current bug in AjaxMin reported by @LodewijkSioen here https://ajaxmin.codeplex.com/workitem/21834,
// causes the MinifyJavascript method call to hang when debugger is attached if the following line is included.
// To avoid more harm than good, don't support source mapping in this scenario until AjaxMin fixes it's bug.
if (System.Diagnostics.Debugger.IsAttached)
{
contentBuilder.Insert(0, sourceMappingDisabledMsg + "\r\n\r\n\r\n");
}

return contentBuilder.ToString();
}
catch (Exception ex)
Expand Down Expand Up @@ -124,7 +132,13 @@ private static string GetContentConcated(BundleContext context, IEnumerable<Bund
}

// Source header line then source code
contentConcated.AppendLine("///#source 1 1 " + file.VirtualFile.VirtualPath);
// Note: A current bug in AjaxMin reported by @LodewijkSioen here https://ajaxmin.codeplex.com/workitem/21834,
// causes the MinifyJavascript method call to hang when debugger is attached if the following line is included.
// To avoid more harm than good, don't support proper source mapping in this scenario until AjaxMin fixes it's bug.
if (!System.Diagnostics.Debugger.IsAttached)
{
contentConcated.AppendLine("///#source 1 1 " + file.VirtualFile.VirtualPath);
}
contentConcated.AppendLine(contents);
}

Expand All @@ -137,13 +151,26 @@ private static void AddContentToAdHocBundle(BundleContext context, string virtua
if (mapBundle == null)
{
mapBundle = new AdHocBundle(virtualPath);
context.BundleCollection.Add(mapBundle);
}
var correctlyCastMapBundle = mapBundle as AdHocBundle;
if (correctlyCastMapBundle == null)
{
throw new InvalidOperationException(string.Format("There is a bundle on the VirtualPath '{0}' of the type '{1}' when it was expected to be of the type 'SourceMapBundle'. That Virtual Path is reserved for the SourceMaps.", virtualPath, mapBundle.GetType()));
}

// Note: A current bug in AjaxMin reported by @LodewijkSioen here https://ajaxmin.codeplex.com/workitem/21834,
// causes the MinifyJavascript method call to hang when debugger is attached if the following line is included.
// To avoid more harm than good, don't support source mapping in this scenario until AjaxMin fixes it's bug.
if (System.Diagnostics.Debugger.IsAttached)
{
correctlyCastMapBundle.SetContent(sourceMappingDisabledMsg);
return;
}

correctlyCastMapBundle.SetContent(content);
}

const string sourceMappingDisabledMsg = "/* Source mapping won't work properly right now, sorry! The debugger is attached and the following bug exists in AjaxMin: https://ajaxmin.codeplex.com/workitem/21834 */";
}
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ Bundling with SourceMap generation
.Include("MyJsFileOne.js", "MyJsFileTwo.js")
);

### Known issues:
1. A current bug in AjaxMin reported by @LodewijkSioen here https://ajaxmin.codeplex.com/workitem/21834,
causes the minification to hang when the debugger is attached and we're trying to do proper sourcemapping. As such,
to avoid more harm than good, we don't support proper source mapping in this scenario until AjaxMin fixes it's bug.


Bundling with Css Rewrite Url Tranformer fix
---------------------------------------------------------
Expand Down

0 comments on commit 73a3ee5

Please sign in to comment.