From 57ab84a6e9351c1587724a8e48ca2d2417eb2082 Mon Sep 17 00:00:00 2001 From: mdameer Date: Sat, 6 Jul 2024 16:31:00 +0300 Subject: [PATCH 1/6] Fix non-debug version loaded for certain static resources when debug mode is enabled --- .../RequireSettings.cs | 8 ++++---- .../OrchardCore.ResourceManagement/ResourceManager.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index ea43b8f3278..c0e58a0e10a 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -258,8 +258,8 @@ public RequireSettings CombinePosition(RequireSettings dependent) return this; } - public RequireSettings New() => - new() + public RequireSettings New(ResourceManagementOptions options) => + new(options) { Name = Name, Type = Type, @@ -267,8 +267,8 @@ public RequireSettings New() => Position = Position }; - public RequireSettings NewAndCombine(RequireSettings other) => - New().Combine(other); + public RequireSettings NewAndCombine(ResourceManagementOptions options, RequireSettings other) => + New(options).Combine(other); public RequireSettings Combine(RequireSettings other) { diff --git a/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs b/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs index 3ed69e5090e..0684047928c 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs @@ -396,7 +396,7 @@ private void ExpandDependenciesImplementation( // and Foo's required location is Head, so too should Bar's location, similarly, if Foo is First positioned, // Bar dependency should be too. This behavior only applies to the dependencies. - var dependencySettings = ((RequireSettings)allResources[resource])?.New() ?? new RequireSettings(_options, resource); + var dependencySettings = ((RequireSettings)allResources[resource])?.New(_options) ?? new RequireSettings(_options, resource); dependencySettings = isTopLevel ? dependencySettings.Combine(settings) : dependencySettings.AtLocation(settings.Location); dependencySettings = dependencySettings.CombinePosition(settings); From e396b15f56555f667a358c70a14a53ba71237b04 Mon Sep 17 00:00:00 2001 From: mdameer Date: Sat, 6 Jul 2024 16:45:47 +0300 Subject: [PATCH 2/6] Handle resource management options when null --- .../RequireSettings.cs | 12 ++++++++---- .../ResourceManager.cs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index c0e58a0e10a..53bb10593f5 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -7,6 +7,8 @@ namespace OrchardCore.ResourceManagement { public class RequireSettings { + private readonly ResourceManagementOptions _options; + private Dictionary _attributes; public string BasePath { get; set; } @@ -36,6 +38,8 @@ public RequireSettings() public RequireSettings(ResourceManagementOptions options) { + _options = options; + CdnMode = options.UseCdn; DebugMode = options.DebugMode; Culture = options.Culture; @@ -258,8 +262,8 @@ public RequireSettings CombinePosition(RequireSettings dependent) return this; } - public RequireSettings New(ResourceManagementOptions options) => - new(options) + public RequireSettings New() => + _options != null ? new(_options) : new() { Name = Name, Type = Type, @@ -267,8 +271,8 @@ public RequireSettings New(ResourceManagementOptions options) => Position = Position }; - public RequireSettings NewAndCombine(ResourceManagementOptions options, RequireSettings other) => - New(options).Combine(other); + public RequireSettings NewAndCombine(RequireSettings other) => + New().Combine(other); public RequireSettings Combine(RequireSettings other) { diff --git a/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs b/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs index 0684047928c..3ed69e5090e 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement/ResourceManager.cs @@ -396,7 +396,7 @@ private void ExpandDependenciesImplementation( // and Foo's required location is Head, so too should Bar's location, similarly, if Foo is First positioned, // Bar dependency should be too. This behavior only applies to the dependencies. - var dependencySettings = ((RequireSettings)allResources[resource])?.New(_options) ?? new RequireSettings(_options, resource); + var dependencySettings = ((RequireSettings)allResources[resource])?.New() ?? new RequireSettings(_options, resource); dependencySettings = isTopLevel ? dependencySettings.Combine(settings) : dependencySettings.AtLocation(settings.Location); dependencySettings = dependencySettings.CombinePosition(settings); From 12854e3bd464d73dd74e435d29adff0dc02d8609 Mon Sep 17 00:00:00 2001 From: mdameer Date: Sun, 7 Jul 2024 02:23:08 +0300 Subject: [PATCH 3/6] Fix new RequireSettings creation --- .../RequireSettings.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index 53bb10593f5..3d80940af90 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -262,14 +262,17 @@ public RequireSettings CombinePosition(RequireSettings dependent) return this; } - public RequireSettings New() => - _options != null ? new(_options) : new() - { - Name = Name, - Type = Type, - Location = Location, - Position = Position - }; + public RequireSettings New() + { + var settings = _options != null ? new RequireSettings(_options) : new RequireSettings(); + + settings.Name = Name; + settings.Type = Type; + settings.Location = Location; + settings.Position = Position; + + return settings; + } public RequireSettings NewAndCombine(RequireSettings other) => New().Combine(other); From 6ae5bf696de7cedbe2e9b328baf2157a1bb94646 Mon Sep 17 00:00:00 2001 From: mdameer Date: Sun, 7 Jul 2024 02:41:55 +0300 Subject: [PATCH 4/6] Simplify RequireSettings initialization --- .../RequireSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index 3d80940af90..7131c56b39d 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -264,7 +264,7 @@ public RequireSettings CombinePosition(RequireSettings dependent) public RequireSettings New() { - var settings = _options != null ? new RequireSettings(_options) : new RequireSettings(); + RequireSettings settings = _options != null ? new(_options) : new(); settings.Name = Name; settings.Type = Type; From 8543cb58540d62d936f31b0d3ca797562d7118d9 Mon Sep 17 00:00:00 2001 From: Mohammad Dameer Date: Sun, 7 Jul 2024 17:24:45 +0300 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Hisham Bin Ateya --- .../RequireSettings.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index 7131c56b39d..368d9d0c1cd 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -39,7 +39,6 @@ public RequireSettings() public RequireSettings(ResourceManagementOptions options) { _options = options; - CdnMode = options.UseCdn; DebugMode = options.DebugMode; Culture = options.Culture; @@ -264,8 +263,9 @@ public RequireSettings CombinePosition(RequireSettings dependent) public RequireSettings New() { - RequireSettings settings = _options != null ? new(_options) : new(); - + RequireSettings settings = _options != null + ? new(_options) + : new(); settings.Name = Name; settings.Type = Type; settings.Location = Location; From 6be5c4ed2096cabbc0e383bf2b3b2e12604705a5 Mon Sep 17 00:00:00 2001 From: mdameer Date: Sun, 7 Jul 2024 17:26:09 +0300 Subject: [PATCH 6/6] Formatting --- .../RequireSettings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs index 368d9d0c1cd..8542a0ea570 100644 --- a/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs +++ b/src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/RequireSettings.cs @@ -266,6 +266,7 @@ public RequireSettings New() RequireSettings settings = _options != null ? new(_options) : new(); + settings.Name = Name; settings.Type = Type; settings.Location = Location;