davedawkins / Sutil

Lightweight front-end framework for F# / Fable. No dependencies.
https://sutil.dev
MIT License
298 stars 19 forks source link

Proposition to lower FSharp.Core requirements #89

Closed MangelMaxime closed 2 months ago

MangelMaxime commented 2 months ago

Hello,

When authoring F# libraries, it is recommended to make FSharp.Core dependency as low as possible. It allows a library to reach a larger range of codebase.

Otherwise people will get warning like:

Detected package downgrade: FSharp.Core from 8.0.200 to 8.0.101. Reference the package directly from the project to select a different version.

Would it be is possible to lower FSharp.Core version to 5.0.2 or 4.7.2 depending on if you need some new feature from FSharp.Core.

You can read more about FSharp.Core management here

In general, I propose 5.0.2 because based on my experience this works fine.

davedawkins commented 2 months ago

Sure no problem at all. Can I ask what prompted this issue for you?

MangelMaxime commented 2 months ago

I was working on Fable.Form implementation for Sutil and when adding it to repository I had an issue because my requested FSharp.Core version is lower than the one from Sutil.

All libraries from Fable.Form are using FSharp.Core 5.0.2, so it forced Fable.Form.Simple.Sutil.Bulma to be the only one on 8.0.301 for example.

I can of course make that specific library depends on that version, but because Sutil.fsproj doesn't specify any version for FSharp.Core it means that it will one the one coming with your .NET installation. On one machine it can be 8.0.301, 6.0.0, 9.0.0, etc. because the machine use a different version of .NET.

davedawkins commented 2 months ago

Ok. I didn't know you used Sutil. Yes, I will make this change. I never really know what to do about those dependencies. Sometimes I feel like I'm juggling to make it all work.

MangelMaxime commented 2 months ago

I am starting to experiment with it, especially now that Fable.Form rewrite allows it to target any renderer.

A version of FuncUI (desktop app), is planned too 🚀

MangelMaxime commented 2 months ago

Regarding the dependency in this case you probably just need to set <PackageReference Include="FSharp.Core" Version="5.0.2" />.

Version 5 should be enough because it gives you access to string interpolation if you use that. FSharp.Core 6+ introduces task but this not supported by Fable yet so I am almost certain you don't use it in Sutil.

davedawkins commented 2 months ago

Adding that reference now gives this warning

/Users/david/projects/Sutil/src/App/App.fsproj : warning NU1504: Duplicate 'PackageReference' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageReference' items are: FSharp.Core 8.0.100, FSharp.Core 5.0.2.

There are definitely no other references to FSharp.Core elsewhere. I'm not sure what it means about "use Update"

Also, I get these build failures now:

> dotnet fable       src/App --run webpack --mode production

Fable 4.19.3: F# to JavaScript compiler
Minimum @fable-org/fable-library-js version (when installed from npm): 1.4.2

Thanks to the contributor! @drk-mtr
Stand with Ukraine! https://standwithukraine.com.ua/

Parsing src/App/App.fsproj...
src/App> dotnet restore App.fable-temp.csproj -p:FABLE_COMPILER=true -p:FABLE_COMPILER_4=true -p:FABLE_COMPILER_JAVASCRIPT=true
  Determining projects to restore...
/Users/david/projects/Sutil/src/Sutil/Sutil.fsproj : warning NU1504: Duplicate 'PackageReference' items found. Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior. The duplicate 'PackageReference' items are: FSharp.Core 8.0.100, FSharp.Core 5.0.2.
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605: Warning As Error: Detected package downgrade: FSharp.Core from 6.0.7 to 5.0.2. Reference the package directly from the project to select a different version. 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> Feliz.Engine.Bulma 1.0.0-beta-007 -> FSharp.Core (>= 6.0.7) 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> FSharp.Core (>= 5.0.2)
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605: Warning As Error: Detected package downgrade: FSharp.Core from 6.0.2 to 5.0.2. Reference the package directly from the project to select a different version. 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> Fable.ShadowStyles 1.0.0 -> FSharp.Core (>= 6.0.2) 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> FSharp.Core (>= 5.0.2)
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605: Warning As Error: Detected package downgrade: FSharp.Core from 8.0.100 to 5.0.2. Reference the package directly from the project to select a different version. 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> Sutil -> FSharp.Core (>= 8.0.100) 
/Users/david/projects/Sutil/src/App/App.fable-temp.csproj : error NU1605:  App.fable-temp -> FSharp.Core (>= 5.0.2)

I think I can rebuild Feliz.Engine.Bulma, but I don't know about Fable.ShadowStyles.

MangelMaxime commented 2 months ago

Ah yes sorry in you case you need to use Update.

This is because by default F# add a <PackageReference Include="FSharp.Core" Version="8.0.100" /> to any fsproj.

And you can't Include twice the same package, once it is included once it needs to be "updated". My snippet use Include because I am disabling the addition of the default line by the compiler.

davedawkins commented 2 months ago

Can you show me how to use Update to avoid that warning/error please?

davedawkins commented 2 months ago

The additional errors in that log above are about Fable.ShadowStyles and Feliz.Engine.Bulma, which is why I talked about reuilding them (with FSharp.Core dependencies that follow your guidelines above).

MangelMaxime commented 2 months ago

The additional errors in that log above are about Fable.ShadowStyles and Feliz.Engine.Bulma, which is why I talked about reuilding them (with FSharp.Core dependencies that follow your guidelines above).

Ahhhhh, sorry I didn't read the error messages thinking I knew what it was 🤦‍♂️

And that's why I moved the discussion regarding Feliz.Engine & co to the other issue.

Can you show me how to use Update to avoid that warning/error please?

You need to replace Include with Update:

<PackageReference Update="FSharp.Core" Version="8.0.101" />

But if you have others dependencies using FSharp.Core (>= 6.0.2), I don't think you will be able to rebuild them. Perhaps, there is a way to force it but I am not sure how safe it is 😅

AngelMunoz commented 2 months ago

If I followed everything as I think I did there's a newer version of the shadow styles package with the lowered down requirements for FSharp.Core https://www.nuget.org/packages/Fable.ShadowStyles/1.0.1

Feel free to let me know if that works!

@MangelMaxime regarding the maintenance of that package, there's not a lot to do there it isn't really a used package so sporadic items like these are fine for me to update if there was more demand I'd consider more maintainers.

MangelMaxime commented 2 months ago

Thank a lot @AngelMunoz 👍

davedawkins commented 2 months ago

@MangelMaxime You say:

You need to replace Include with Update:

<PackageReference Update="FSharp.Core" Version="8.0.101" />

Do you mean to say 5.0.2 there?

MangelMaxime commented 2 months ago

@davedawkins Yes, indeed <PackageReference Update="FSharp.Core" Version="5.0.2" />

If you are in doubt, you can run dotnet pack and them use NuGet.info to open your package and see the version of the dependencies requested.

davedawkins commented 2 months ago

This has worked!! I'll build a new Sutil in just a moment

The only thing bothering me right now is build.fsx, it also has dependencies:


> dotnet fsi build.fsx --target clean

/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605: Detected package downgrade: FSharp.Core from 8.0.301 to 8.0.100. Reference the package directly from the project to select a different version. 
/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605:  Project -> Fake.Core.Target 6.1.1 -> FSharp.Core (>= 8.0.301) 
/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605:  Project -> FSharp.Core (>= 8.0.100)
/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605: Detected package downgrade: FSharp.Core from 8.0.301 to 8.0.100. Reference the package directly from the project to select a different version. 
/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605:  Project -> Fake.Core.Target 6.1.1 -> FSharp.Core (>= 8.0.301) 
/Users/david/.packagemanagement/nuget/Projects/98173--900f9193-4e16-44b9-8334-d92b73eb4530/Project.fsproj : warning NU1605:  Project -> FSharp.Core (>= 8.0.100)
run clean```

Any idea how to fix that?
MangelMaxime commented 2 months ago

Perhaps, you can reference FSharp.Core in the fsi directly via #nuget: ...

Or don't use Fake, personally I don't like using it because it often caused issues to my projects.

Now days, there is Fun.Build which provides a good DSL for people who like fsx files.

Or personally, my favorite way of doing it now days, it to create real project and create a CLI tool. This way, I get a good DX + I can do anything I want because this is a real F# project so I can do complex manipulation.

You can look at the following file to get a feeling of how it looks.

If you want to go with the CLI/project approach I can look to send a PR for Sutil.

davedawkins commented 2 months ago

That's amazing. I love it :-)

MangelMaxime commented 2 months ago

Ok, I will send a PR later this week then :)

davedawkins commented 2 months ago

I've done it :-) Sorry -- I didn't see that you'd offered to do a PR! I hope you haven't started it. I'll commit and push now

davedawkins commented 2 months ago

Sutil now ships with FSharp.Core 5.0.2 in v2.0.16.