Adds better support for app_plugins loading assets in a safer way and without having to pass refs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -94,10 +94,15 @@ namespace Umbraco.Cms.Infrastructure.WebAssets
|
||||
private string[] GetScriptsForBackOfficeExtensions(IEnumerable<string> propertyEditorScripts)
|
||||
{
|
||||
var scripts = new HashSet<string>();
|
||||
foreach (var script in _parser.Manifest.Scripts)
|
||||
foreach (string script in _parser.Manifest.Scripts)
|
||||
{
|
||||
scripts.Add(script);
|
||||
foreach (var script in propertyEditorScripts)
|
||||
}
|
||||
|
||||
foreach (string script in propertyEditorScripts)
|
||||
{
|
||||
scripts.Add(script);
|
||||
}
|
||||
|
||||
return scripts.ToArray();
|
||||
}
|
||||
@@ -120,10 +125,15 @@ namespace Umbraco.Cms.Infrastructure.WebAssets
|
||||
{
|
||||
var stylesheets = new HashSet<string>();
|
||||
|
||||
foreach (var script in _parser.Manifest.Stylesheets)
|
||||
foreach (string script in _parser.Manifest.Stylesheets)
|
||||
{
|
||||
stylesheets.Add(script);
|
||||
foreach (var stylesheet in propertyEditorStyles)
|
||||
}
|
||||
|
||||
foreach (string stylesheet in propertyEditorStyles)
|
||||
{
|
||||
stylesheets.Add(stylesheet);
|
||||
}
|
||||
|
||||
return stylesheets.ToArray();
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
|
||||
.AddConfiguration()
|
||||
.AddUmbracoCore()
|
||||
.AddWebComponents()
|
||||
.AddRuntimeMinifier(webHostEnvironment)
|
||||
.AddRuntimeMinifier()
|
||||
.AddBackOfficeCore()
|
||||
.AddBackOfficeAuthentication()
|
||||
.AddBackOfficeIdentity()
|
||||
|
||||
@@ -212,7 +212,7 @@ namespace Umbraco.Cms.Tests.Integration.Testing
|
||||
builder.AddConfiguration()
|
||||
.AddUmbracoCore()
|
||||
.AddWebComponents()
|
||||
.AddRuntimeMinifier(webHostEnvironment)
|
||||
.AddRuntimeMinifier()
|
||||
.AddBackOfficeAuthentication()
|
||||
.AddBackOfficeIdentity()
|
||||
.AddMembersIdentity()
|
||||
|
||||
@@ -35,11 +35,11 @@ namespace Umbraco.Extensions
|
||||
/// <summary>
|
||||
/// Adds all required components to run the Umbraco back office
|
||||
/// </summary>
|
||||
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment) => builder
|
||||
public static IUmbracoBuilder AddBackOffice(this IUmbracoBuilder builder) => builder
|
||||
.AddConfiguration()
|
||||
.AddUmbracoCore()
|
||||
.AddWebComponents()
|
||||
.AddRuntimeMinifier(webHostEnvironment)
|
||||
.AddRuntimeMinifier()
|
||||
.AddBackOfficeCore()
|
||||
.AddBackOfficeAuthentication()
|
||||
.AddBackOfficeIdentity()
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Dazinator.Extensions.FileProviders.GlobPatternFilter;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -219,9 +220,21 @@ namespace Umbraco.Extensions
|
||||
/// <summary>
|
||||
/// Add runtime minifier support for Umbraco
|
||||
/// </summary>
|
||||
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder, IWebHostEnvironment webHostEnvironment)
|
||||
public static IUmbracoBuilder AddRuntimeMinifier(this IUmbracoBuilder builder)
|
||||
{
|
||||
var smidgePhysicalFileProvider = new SmidgePhysicalFileProvider(webHostEnvironment.ContentRootFileProvider, webHostEnvironment.WebRootFileProvider);
|
||||
// Add custom ISmidgeFileProvider to include the additional App_Plugins location
|
||||
// to load assets from.
|
||||
builder.Services.AddSingleton<ISmidgeFileProvider>(f =>
|
||||
{
|
||||
IWebHostEnvironment hostEnv = f.GetRequiredService<IWebHostEnvironment>();
|
||||
|
||||
return new SmidgeFileProvider(
|
||||
hostEnv.WebRootFileProvider,
|
||||
new GlobPatternFilterFileProvider(
|
||||
hostEnv.ContentRootFileProvider,
|
||||
// only include js or css files within App_Plugins
|
||||
new[] { "App_Plugins/**/*.js", "App_Plugins/**/*.css" }));
|
||||
});
|
||||
builder.Services.AddSmidge(builder.Config.GetSection(Constants.Configuration.ConfigRuntimeMinification));
|
||||
builder.Services.AddSmidgeNuglify();
|
||||
|
||||
@@ -416,28 +429,5 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
@@ -33,6 +33,8 @@
|
||||
<PackageReference Include="Smidge" Version="4.0.0-beta.*" />
|
||||
<PackageReference Include="Smidge.Nuglify" Version="4.0.0-beta.*" />
|
||||
<PackageReference Include="Smidge.InMemory" Version="4.0.0-beta.*" />
|
||||
<PackageReference Include="Smidge.InMemory" Version="4.0.0-beta.*" />
|
||||
<PackageReference Include="Dazinator.Extensions.FileProviders" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -8,20 +7,18 @@ namespace Umbraco.Cms.Web.UI.NetCore
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
=> CreateHostBuilder(args)
|
||||
{
|
||||
CreateHostBuilder(args)
|
||||
.Build()
|
||||
.Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
#if DEBUG
|
||||
.ConfigureAppConfiguration(config
|
||||
=> config.AddJsonFile(
|
||||
"appsettings.Local.json",
|
||||
optional: true,
|
||||
reloadOnChange: true))
|
||||
#endif
|
||||
.ConfigureLogging(x => x.ClearProviders())
|
||||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
|
||||
.ConfigureLogging(x =>
|
||||
{
|
||||
x.ClearProviders();
|
||||
})
|
||||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Cms.Web.UI.NetCore
|
||||
{
|
||||
#pragma warning disable IDE0022 // Use expression body for methods
|
||||
services.AddUmbraco(_env, _config)
|
||||
.AddBackOffice(_env)
|
||||
.AddBackOffice()
|
||||
.AddBackOfficeExternalLogins(logins =>
|
||||
{
|
||||
var loginProviderOptions = new BackOfficeExternalLoginProviderOptions(
|
||||
|
||||
Reference in New Issue
Block a user