Skip to content

Commit

Permalink
Merge pull request #211 from Shazwazza/add-bundle-lock
Browse files Browse the repository at this point in the history
Add bundle lock
  • Loading branch information
Shazwazza authored Oct 21, 2024
2 parents deb1406 + 4e88f3b commit d5930c9
Show file tree
Hide file tree
Showing 25 changed files with 222 additions and 167 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,3 @@ jobs:
with:
name: smidge-nuget-${{ env.GitVersion_SemVer }}
path: ${{ github.workspace }}/_NugetOutput/*.*

- name: Publish to GitHub Packages
if: ${{ success() && github.event_name == 'pull_request' }}
run: dotnet nuget push "${{ github.workspace }}/_NugetOutput/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/shazwazza/index.json"
6 changes: 2 additions & 4 deletions Nuget.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="AspNetCiDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" />
<add key="XUnitDev" value="https://www.myget.org/F/xunit/api/v3/index.json" />
</packageSources>
</configuration>
</configuration>
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>
<PropertyGroup>
<PackageProjectUrl>https://github.com/Shazwazza/Smidge</PackageProjectUrl>
Expand All @@ -23,6 +23,6 @@
<VersionPrefix>4.0.0</VersionPrefix>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;net5.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;</TargetFrameworks>
</PropertyGroup>
</Project>
10 changes: 6 additions & 4 deletions src/Smidge.Core/BundleManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using Microsoft.Extensions.Options;
using Smidge.Models;
Expand Down Expand Up @@ -202,10 +202,12 @@ public void AddToBundle(string bundleName, JavaScriptFile file)
/// <returns></returns>
public Bundle GetBundle(string bundleName)
{
Bundle collection;
if (!TryGetValue(bundleName, out collection))
if (!TryGetValue(bundleName, out Bundle collection))
{
return null;
}

return collection;
}
}
}
}
6 changes: 3 additions & 3 deletions src/Smidge.Core/CompositeFiles/DefaultUrlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public string GetUrl(string bundleName, string fileExtension, bool debug, string
var handler = _keepFileExtensions ? "~/{0}/{1}.{3}{4}{2}" : "~/{0}/{1}{2}.{3}{4}";
return _requestHelper.Content(string.Format(handler,
_options.BundleFilePath,
Uri.EscapeUriString(bundleName),
Uri.EscapeDataString(bundleName),
fileExtension,
debug ? 'd' : 'v',
cacheBusterValue));
Expand Down Expand Up @@ -167,9 +167,9 @@ private string GetCompositeUrl(string fileKey, string fileExtension, string cach
string.Format(
handler,
_options.CompositeFilePath,
Uri.EscapeUriString(fileKey),
Uri.EscapeDataString(fileKey),
fileExtension,
cacheBusterValue));
}
}
}
}
13 changes: 6 additions & 7 deletions src/Smidge.Core/Smidge.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
<Content Include="..\..\assets\logo-nuget.png" Link="logo-nuget.png" Pack="true" PackagePath="" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Smidge.InMemory/Smidge.InMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Dazinator.Extensions.FileProviders" Version="2.0.0" />
<!-- Due to a security issue we need an explicit ref https://github.com/dotnet/announcements/issues/178 -->
<PackageReference Include="System.Text.Encodings.Web" Version="5.0.1" />
<PackageReference Include="System.Text.Encodings.Web" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\assets\logo-nuget.png" Link="logo-nuget.png" Pack="true" PackagePath="" />
Expand Down
15 changes: 7 additions & 8 deletions src/Smidge.Nuglify/NuglifySourceMapController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Smidge.Cache;
using Smidge.Models;
using Smidge.Options;
Expand All @@ -19,12 +20,11 @@ public NuglifySourceMapController(ISmidgeFileSystem fileSystem, IBundleManager b
_bundleManager = bundleManager;
}

public FileResult SourceMap([FromServices] BundleRequestModel bundle)
public ActionResult SourceMap([FromServices] BundleRequestModel bundle)
{
if (!_bundleManager.TryGetValue(bundle.FileKey, out _))
if (!bundle.IsBundleFound)
{
//TODO: Throw an exception, this will result in an exception anyways
return null;
return NotFound();
}

var sourceMapFile = _fileSystem.CacheFileSystem.GetRequiredFileInfo(bundle.GetSourceMapFilePath());
Expand All @@ -43,10 +43,9 @@ public FileResult SourceMap([FromServices] BundleRequestModel bundle)
}
}

//TODO: Throw an exception, this will result in an exception anyways
return null;
return NotFound();
}


}
}
}
2 changes: 1 addition & 1 deletion src/Smidge.Nuglify/Smidge.Nuglify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nuglify" Version="1.20.2" />
<PackageReference Include="Nuglify" Version="1.21.4" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
5 changes: 5 additions & 0 deletions src/Smidge.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
RequestPath = "/smidge-static"
});
bundles
.CreateCss("notfound-map-css-bundle",
"~/Css/notFoundMap.min.css"
);
});

app.UseSmidgeNuglify();
Expand Down
1 change: 1 addition & 0 deletions src/Smidge.Web/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/foundation/5.5.2/css/foundation.min.css" />
<link rel="stylesheet" href="inline-css-bundle" />
<link rel="stylesheet" href="test-bundle-4" onload="window.alert('hello')" />
@await SmidgeHelper.CssHereAsync("notfound-map-css-bundle", debug: false)
</head>
<body>

Expand Down
2 changes: 2 additions & 0 deletions src/Smidge.Web/wwwroot/Css/notFoundMap.min.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@charset "UTF-8";
/*# sourceMappingURL=notFound.min.css.map */
6 changes: 3 additions & 3 deletions src/Smidge/Controllers/AddCompressionHeaderAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -55,7 +55,7 @@ public void OnActionExecuted(ActionExecutedContext context)
if (context.Exception != null) return;

//get the model from the items
if (context.HttpContext.Items.TryGetValue(nameof(AddCompressionHeaderAttribute), out var requestModel) && requestModel is RequestModel file)
if (context.HttpContext.Items.TryGetValue(nameof(AddCompressionHeaderAttribute), out var requestModel) && requestModel is RequestModel file && file.IsBundleFound)
{
var enableCompression = true;

Expand All @@ -72,4 +72,4 @@ public void OnActionExecuted(ActionExecutedContext context)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Smidge/Controllers/AddExpiryHeadersAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void OnActionExecuted(ActionExecutedContext context)
return;

//get the model from the items
if (!context.HttpContext.Items.TryGetValue(nameof(AddExpiryHeadersAttribute), out object fileObject) || fileObject is not RequestModel file)
if (!context.HttpContext.Items.TryGetValue(nameof(AddExpiryHeadersAttribute), out object fileObject) || fileObject is not RequestModel file || !file.IsBundleFound)
return;

var enableETag = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Smidge/Controllers/CheckNotModifiedAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Smidge.Models;
using System;
Expand Down Expand Up @@ -51,7 +51,7 @@ public void OnActionExecuted(ActionExecutedContext context)
if (context.Exception != null) return;

//get the model from the items
if (context.HttpContext.Items.TryGetValue(nameof(CheckNotModifiedAttribute), out var requestModel) && requestModel is RequestModel file)
if (context.HttpContext.Items.TryGetValue(nameof(CheckNotModifiedAttribute), out var requestModel) && requestModel is RequestModel file && file.IsBundleFound)
{
//Don't execute when the request is in Debug
if (file.Debug)
Expand All @@ -74,4 +74,4 @@ private static void ReturnNotModified(ActionExecutedContext context)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void OnActionExecuting(ActionExecutingContext context)
if (context.ActionArguments.Count == 0) return;

var firstArg = context.ActionArguments.First().Value;
if (firstArg is RequestModel file)
if (firstArg is RequestModel file && file.IsBundleFound)
{
var cacheBusterValue = file.ParsedPath.CacheBusterValue;

Expand Down
Loading

0 comments on commit d5930c9

Please sign in to comment.