From ee9279bb5fd17a67ba1a2eb6c53a6870aee362cb Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Tue, 19 Nov 2024 03:14:13 +0100 Subject: [PATCH] [build] Disable gzip compression during build --- Iceshrimp.Backend/Iceshrimp.Backend.csproj | 21 +--- Iceshrimp.Build/Iceshrimp.Build.csproj | 5 + Iceshrimp.Build/Iceshrimp.Build.targets | 41 +++++++ .../RewriteStaticAssetManifestTask.cs | 111 ++---------------- Iceshrimp.Frontend/Iceshrimp.Frontend.csproj | 3 + 5 files changed, 60 insertions(+), 121 deletions(-) create mode 100644 Iceshrimp.Build/Iceshrimp.Build.targets diff --git a/Iceshrimp.Backend/Iceshrimp.Backend.csproj b/Iceshrimp.Backend/Iceshrimp.Backend.csproj index ce30aa30..0d870f4a 100644 --- a/Iceshrimp.Backend/Iceshrimp.Backend.csproj +++ b/Iceshrimp.Backend/Iceshrimp.Backend.csproj @@ -8,6 +8,7 @@ + @@ -80,24 +81,4 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/Iceshrimp.Build/Iceshrimp.Build.csproj b/Iceshrimp.Build/Iceshrimp.Build.csproj index d9d5a430..c5662af5 100644 --- a/Iceshrimp.Build/Iceshrimp.Build.csproj +++ b/Iceshrimp.Build/Iceshrimp.Build.csproj @@ -11,4 +11,9 @@ + + + + + diff --git a/Iceshrimp.Build/Iceshrimp.Build.targets b/Iceshrimp.Build/Iceshrimp.Build.targets new file mode 100644 index 00000000..5ffd5d00 --- /dev/null +++ b/Iceshrimp.Build/Iceshrimp.Build.targets @@ -0,0 +1,41 @@ + + + + + + + true + + + + + + + ; + + + + + + + ;brotli + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Iceshrimp.Build/RewriteStaticAssetManifestTask.cs b/Iceshrimp.Build/RewriteStaticAssetManifestTask.cs index ebde7aec..dfccbda7 100644 --- a/Iceshrimp.Build/RewriteStaticAssetManifestTask.cs +++ b/Iceshrimp.Build/RewriteStaticAssetManifestTask.cs @@ -1,5 +1,4 @@ -using System.Diagnostics; -using System.Text.Json; +using System.Text.Json; using System.Text.Json.Serialization; using Microsoft.Build.Framework; @@ -8,19 +7,14 @@ namespace Iceshrimp.Build.Tasks; public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task { - public static void FixupFile(string manifestPath) - { - var parsed = Parse(manifestPath); - var @fixed = Fixup(manifestPath, parsed); - Write(manifestPath, @fixed); - } - [System.ComponentModel.DataAnnotations.Required] - public required ITaskItem[] ManifestFiles { get; set; } + public required ITaskItem Manifest { get; set; } public override bool Execute() { - foreach (var item in ManifestFiles) FixupFile(item.ItemSpec); + var parsed = Parse(Manifest.ItemSpec); + var @fixed = Fixup(Manifest.ItemSpec, parsed); + Write(Manifest.ItemSpec, @fixed); return true; } @@ -54,15 +48,6 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task p => p.ResponseHeaders .FirstOrDefault(i => i.Name == "Content-Length")); - // Remove gzip-compressed versions - foreach (var endpoint in manifest.Endpoints.ToArray()) - { - if (!endpoint.Selectors.Any(p => p is { Name: "Content-Encoding", Value: "gzip" })) - continue; - - manifest.Endpoints.Remove(endpoint); - } - // Rewrite uncompressed versions to reference brotli-compressed asset instead foreach (var endpoint in manifest.Endpoints.ToArray()) { @@ -75,7 +60,7 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task endpoint.ResponseHeaders.Add(len); endpoint.AssetPath += ".br"; } - + // Remove explicit routes manifest.Endpoints.RemoveAll(p => p.Route.EndsWith(".br")); @@ -93,15 +78,9 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task // ReSharper disable once CollectionNeverUpdated.Local public List Endpoints { get; set; } = []; - - public bool IsBuildManifest() => string.Equals(ManifestType, "Build", StringComparison.OrdinalIgnoreCase); } - /// - /// The description of a static asset that was generated during the build process. - /// - [DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")] - public sealed class StaticAssetDescriptor + private sealed class StaticAssetDescriptor { private string? _route; private string? _assetFile; @@ -109,18 +88,12 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task private List _endpointProperties = []; private List _responseHeaders = []; - /// - /// The route that the asset is served from. - /// public required string Route { get => _route ?? throw new InvalidOperationException("Route is required"); set => _route = value; } - /// - /// The path to the asset file from the wwwroot folder. - /// [JsonPropertyName("AssetFile")] public required string AssetPath { @@ -128,9 +101,6 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task set => _assetFile = value; } - /// - /// A list of selectors that are used to discriminate between two or more assets with the same route. - /// [JsonPropertyName("Selectors")] public List Selectors { @@ -138,9 +108,6 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task set => _selectors = value; } - /// - /// A list of properties that are associated with the endpoint. - /// [JsonPropertyName("EndpointProperties")] public List Properties { @@ -148,87 +115,29 @@ public class RewriteStaticAssetManifest : Microsoft.Build.Utilities.Task set => _endpointProperties = value; } - /// - /// A list of headers to apply to the response when this resource is served. - /// [JsonPropertyName("ResponseHeaders")] public List ResponseHeaders { get => _responseHeaders; set => _responseHeaders = value; } - - private string GetDebuggerDisplay() - { - return $"Route: {Route} Path: {AssetPath}"; - } } - /// - /// A static asset selector. Selectors are used to discriminate between two or more assets with the same route. - /// - /// The name associated to the selector. - /// The value associated to the selector and used to match against incoming requests. - /// The static server quality associated to this selector. - [DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")] - public sealed class StaticAssetSelector(string name, string value, string quality) + private sealed class StaticAssetSelector(string name, string value) { - /// - /// The name associated to the selector. - /// public string Name { get; } = name; - - /// - /// The value associated to the selector and used to match against incoming requests. - /// public string Value { get; } = value; - - /// - /// The static asset server quality associated to this selector. Used to break ties when a request matches multiple values - /// with the same degree of specificity. - /// - public string Quality { get; } = quality; - - private string GetDebuggerDisplay() => $"Name: {Name} Value: {Value} Quality: {Quality}"; } - /// - /// A property associated with a static asset. - /// - [DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")] - public sealed class StaticAssetProperty(string name, string value) + private sealed class StaticAssetProperty(string name, string value) { - /// - /// The name of the property. - /// public string Name { get; } = name; - - /// - /// The value of the property. - /// public string Value { get; } = value; - - private string GetDebuggerDisplay() => $"Name: {Name} Value:{Value}"; } - /// - /// A response header to apply to the response when a static asset is served. - /// - /// The name of the header. - /// The value of the header. - [DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")] - public sealed class StaticAssetResponseHeader(string name, string value) + private sealed class StaticAssetResponseHeader(string name, string value) { - /// - /// The name of the header. - /// public string Name { get; } = name; - - /// - /// The value of the header. - /// public string Value { get; } = value; - - private string GetDebuggerDisplay() => $"Name: {Name} Value: {Value}"; } } \ No newline at end of file diff --git a/Iceshrimp.Frontend/Iceshrimp.Frontend.csproj b/Iceshrimp.Frontend/Iceshrimp.Frontend.csproj index c0931271..a7a32345 100644 --- a/Iceshrimp.Frontend/Iceshrimp.Frontend.csproj +++ b/Iceshrimp.Frontend/Iceshrimp.Frontend.csproj @@ -6,6 +6,9 @@ true + + + IL2008,IL2040