Merge branch 'netcore/bug/minify-plugins' of https://github.com/kjac/Umbraco-CMS into kjac-netcore/bug/minify-plugins

# Conflicts:
#	src/Umbraco.Web.BackOffice/DependencyInjection/UmbracoBuilderExtensions.cs
This commit is contained in:
Shannon
2021-03-16 17:22:25 +11:00
5 changed files with 38 additions and 8 deletions

View File

@@ -135,9 +135,10 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
public override void ConfigureServices(IServiceCollection services)
{
services.AddTransient<TestUmbracoDatabaseFactoryProvider>();
IWebHostEnvironment webHostEnvironment = TestHelper.GetWebHostEnvironment();
TypeLoader typeLoader = services.AddTypeLoader(
GetType().Assembly,
TestHelper.GetWebHostEnvironment(),
webHostEnvironment,
TestHelper.GetHostingEnvironment(),
TestHelper.ConsoleLoggerFactory,
AppCaches.NoCache,
@@ -150,7 +151,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
.AddConfiguration()
.AddUmbracoCore()
.AddWebComponents()
.AddRuntimeMinifier()
.AddRuntimeMinifier(webHostEnvironment)
.AddBackOfficeCore()
.AddBackOfficeAuthentication()
.AddBackOfficeIdentity()

View File

@@ -213,7 +213,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing
builder.AddConfiguration()
.AddUmbracoCore()
.AddWebComponents()
.AddRuntimeMinifier()
.AddRuntimeMinifier(webHostEnvironment)
.AddBackOfficeAuthentication()
.AddBackOfficeIdentity()
.AddMembersIdentity()

View File

@@ -22,6 +22,7 @@ using Umbraco.Cms.Web.BackOffice.Services;
using Umbraco.Cms.Web.BackOffice.Trees;
using Umbraco.Cms.Web.Common.Authorization;
using Umbraco.Cms.Web.Common.Security;
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IWebHostEnvironment;
namespace Umbraco.Extensions
{
@@ -33,11 +34,11 @@ namespace Umbraco.Extensions
/// <summary>
/// Adds all required components to run the Umbraco back office
/// </summary>
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder) => builder
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment) => builder
.AddConfiguration()
.AddUmbracoCore()
.AddWebComponents()
.AddRuntimeMinifier()
.AddRuntimeMinifier(webHostEnvironment)
.AddBackOfficeCore()
.AddBackOfficeAuthentication()
.AddBackOfficeIdentity()

View File

@@ -12,7 +12,9 @@ using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Serilog;
using Smidge;
using Smidge.Nuglify;
@@ -217,9 +219,11 @@ namespace Umbraco.Extensions
/// <summary>
/// Add runtime minifier support for Umbraco
/// </summary>
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment)
{
builder.Services.AddSmidge(builder.Config.GetSection(Cms.Core.Constants.Configuration.ConfigRuntimeMinification));
var smidgePhysicalFileProvider = new SmidgePhysicalFileProvider(webHostEnvironment.ContentRootFileProvider, webHostEnvironment.WebRootFileProvider);
builder.Services.AddSmidge(builder.Config.GetSection(Cms.Core.Constants.Configuration.ConfigRuntimeMinification), smidgePhysicalFileProvider);
builder.Services.AddSmidgeNuglify();
return builder;
@@ -412,5 +416,29 @@ namespace Umbraco.Extensions
return new AspNetCoreHostingEnvironment(wrappedHostingSettings,wrappedWebRoutingSettings, webHostEnvironment);
}
/// <summary>
/// This file provider lets us serve physical files to Smidge for minification from both wwwroot and App_Plugins (which is outside wwwroot).
/// This file provider is NOT intended for use anywhere else, as it exposes files from the content root.
/// </summary>
private class SmidgePhysicalFileProvider : IFileProvider
{
private readonly IFileProvider _contentRootFileProvider;
private readonly IFileProvider _webRooFileProvider;
public SmidgePhysicalFileProvider(IFileProvider contentRootFileProvider, IFileProvider webRooFileProvider)
{
_contentRootFileProvider = contentRootFileProvider;
_webRooFileProvider = webRooFileProvider;
}
public IFileInfo GetFileInfo(string subpath) => subpath.InvariantStartsWith(Constants.SystemDirectories.AppPlugins)
? _contentRootFileProvider.GetFileInfo(subpath)
: _webRooFileProvider.GetFileInfo(subpath);
public IDirectoryContents GetDirectoryContents(string subpath) => throw new NotSupportedException();
public IChangeToken Watch(string filter) => throw new NotSupportedException();
}
}
}

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Cms.Web.UI.NetCore
{
#pragma warning disable IDE0022 // Use expression body for methods
services.AddUmbraco(_env, _config)
.AddBackOffice()
.AddBackOffice(_env)
.AddWebsite()
.AddComposers()
.Build();