OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.44k stars 2.4k forks source link

Document dependency version selection in ResourceManagementOptionsConfiguration class #10117

Closed MikeAlhayek closed 3 years ago

MikeAlhayek commented 3 years ago

This is now about documenting the feature, see comments. The original feature request is below.

Is your feature request related to a problem? Please describe.

In the theme layout, I want to enforce bootstrap 4.6 so I added this <script asp-name="bootstrap" version="4" at="Foot"></script> which includes bootstrap 4 as desired.

I created a module that allows me to convert a select-menu to a searchable-menu. This module depends on bootstrap and jquery to be able to function. So in the ResourceManagementOptionsConfiguration class, I defined the dependencies like this

_manifest.DefineScript("SearchableDropdown")
        .SetUrl("~/SearchableDropdowns/bootstrap-select.min.js", "~/SearchableDropdowns/bootstrap-select.js")
        .SetDependencies("jquery", "bootstrap")
        .SetVersion("1.0.0");

_manifest.DefineStyle("SearchableDropdown")
         .SetUrl("~/SearchableDropdowns/bootstrap-select.min.css", "~/SearchableDropdowns/bootstrap-select.css")
         .SetDependencies("bootstrap")
         .SetVersion("1.0.0");

Unfortunately, the SetDependencies("bootstrap") call here forces to include bootstrap 5 which will cause bootstrap 4 and 5 to be included! Obviously this is a problem!

Describe the solution you'd like

I would suggest adding a way to specify version when calling SetDependencies() method using something like this

SetDependencies("bootstrap:latest") // this would include the latest version of bootstrap and would be the default behavior aka identical to calling SetDependencies("bootstrap")
SetDependencies("bootstrap:any") // this would take any version of bootstrap that is being used "if any". If none is used, then fallback to the latest version. However, if one already include, then use it and don't include anything else. In my case it would pick up that my layout is using bootstrap 4, therefore bootstrap 5 would not be included.
SetDependencies("bootstrap:4") // this would include the latest major version of bootstrap 4
SetDependencies("bootstrap:4.6.0") // this would include bootstrap version 4.6.0

I also suggest adding a new method ResourceDefinition SetDependency(string dependency, string version = "latest") this would allow the user to define a single dependency with a version.

Describe alternatives you've considered

Not sure there is a solution in place for this problem. More info can be found in the discussion #10113

deanmarcussen commented 3 years ago

Resource versioning is already well supported, and documented

https://docs.orchardcore.net/en/latest/docs/reference/modules/Resources/#set-the-version-to-use

Piedone commented 3 years ago

That's not what's this request is about. While you can define a version for your resource, as well as request a specific version of it when including it, you can't specify a version for its dependencies (unless you not use the manifest approach but include all dependencies in all locations manually). Or am I missing something?

deanmarcussen commented 3 years ago

Unless I have misunderstood the feature request is for being able to add specific version to a dependency, like this depends_on:"foo:1.0", or the same with .SetDependencies("foo:1.0) ?

Here's another link to the docs regarding how to do this https://docs.orchardcore.net/en/latest/docs/reference/modules/Resources/#inline-definition

Piedone commented 3 years ago

SetDependencies("foo:1.0) is it, yes. Great then, didn't know about this. This should be added to the docs here so let's keep this issue for that. Would you like to contribute this small docs improvement, @CrestApps?

MikeAlhayek commented 3 years ago

@Piedone sure! @deanmarcussen is “any” and “latest” something being already supported as well? If not, how can I ensure only one bootstrap version is being included?

Piedone commented 3 years ago

Thanks! The default behavior without "latest", then.