fsprojects / Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
https://fsprojects.github.io/Paket/
MIT License
2.02k stars 520 forks source link

Proposal: Add option to emit paket.lock as JSON #4093

Open purkhusid opened 2 years ago

purkhusid commented 2 years ago

What

Add an option to Paket that changes to format of paket.lock to JSON

Why?

The exact use case for me is to parse the paket.lock file to generate Bazel targets for each NuGet package. If the lock file would be in JSON it makes it easier for other tools to parse the lock file since JSON is supported by all programming/scripting languages.

Other use cases:

purkhusid commented 2 years ago

I'm curious if @forki thinks it's a lot of work to add a JSON format and if it would be accepted as a contribution.

forki commented 2 years ago

this was brought up multiple times. It's not really that hard to do. But there needs to be an explicit switch for this. Also you need to implement the parser as well.

baronfel commented 2 years ago

Big 👍 from me on this one, I know that having this would make efforts like @TheAngryByrd's attempted integration with Dependabot easier, for example.

baronfel commented 2 years ago

@forki we could potentially do it in a staged fashion as well, where the lock file could be the output of a command (paket show lock file --json) while keeping the existing file as the source of truth. This might help to prove out the formatting/syntax, before committing to it as the full lock file format.

ratsclub commented 2 years ago

I know that having this would make efforts like @TheAngryByrd's attempted integration with Dependabot easier

It would also make the integration with Nix way easier too!

bromanko commented 1 year ago

It would also make the integration with Nix way easier too!

Is there any existing Nix integration solution? I was just researching this and coming up short. Thinking the approach would be to parse the lock file and convert it to a derivation.

ratsclub commented 1 year ago

Is there any existing Nix integration solution?

Not that I'm aware of. Right now I use dotnet through nix shell or nix develop and install fantomas as a dotnet tool. The main problem is not the lock file (although it's bad enough to parse it) it is the fake build script, because you have to package another dotnet tool (FAKE).

Having the paket.lock as a JSON would just be a nice thing to have because you could easily build tools as dependabot and package programs with Nix.

bromanko commented 1 year ago

I spent last weekend looking into this further. It's a pretty challenging undertaking. The current Nix support for dotnet involves restoring packages and then using nuget-to-nix to produce a derivation that fetches the packages from Nuget via fetchNuget. This creates a derivation roughly equivalent to package.lock. That's then used in a dotnet publish process.

I attempted to get this workflow working with Paket. I first needed to override the passthru.fetchDeps script to be amenable for Paket by including a dotnet tool install and changing the dotnet restore command. This would produce the derivation file. That should have then allowed the normal build to work. Unfortunately, the --no-build argument for dotnet publish isn't working properly for F# 2.