HaxeFoundation / haxelib

The Haxe library manager
https://lib.haxe.org/
MIT License
173 stars 78 forks source link

Add "state save" and "state load" commands #610

Closed j-jzk closed 11 months ago

j-jzk commented 11 months ago

This PR adds two new commands:

This manifest file (note that .hxml extension isn't mandatory here) is used to "lock" the current state of the libraries in the project. This is useful for reproducing the exact state of dependencies in a project (on a new machine or in Docker), especially when working with libraries installed from git.

The intended workflow is following:

  1. do package management operations
  2. lock the dependencies: haxelib state save haxelib-lock.hxml
  3. apply the manifest file in another environment: haxelib state load haxelib-lock.hxml

This manifest mechanism supports published haxelib versions, as well as exact git and mercurial references. haxelib dev libs are ignored (with a warning), and try to resolve to "non-dev" version for the manifest file, allowing you to work with dev libs locally without altering the pin file.

I switched to file output instead of stdout for better cross-platform support, and API consistency. "manifest" terminology comes from https://learn.microsoft.com/en-us/vcpkg/users/manifests


Original PR description below:

This PR adds a new lock command which, as in other library managers, "locks" the current state of the libraries in the project. This is useful for reproducing the exact state of dependencies in a project (on a new machine or in Docker), especially when working with libraries installed from git.

The output is in HXML (-L lib:version ...) and it is dumped to stdout instead of a file. The intended workflow is following:

  1. do package management operations
  2. lock the dependencies: haxelib lock > haxelib-lock.hxml
  3. apply the lockfile in another environment: haxelib install --skip-dependencies --always haxelib-lock.hxml

I've created this for my personal usage and providing this patch hoping it could be useful to more developers. If inappropriate, feel free to add notes/close the PR. Before merging, support for locking versions of Mercurial libs (installed using haxelib hg ...) should be added. I am not a Mercurial user myself, so help would be greatly appreciated.

kLabz commented 11 months ago

Thanks! I think this can be merged once the above points have been handled

j-jzk commented 11 months ago

Hopefully I will finish this till the end of the week.

kLabz commented 11 months ago

This PR is now ready as far as I'm concerned. Will wait a bit before merging in case someone has some argument against it.

j-jzk commented 11 months ago

Thanks for all the work :) Just sat down to work on this and saw you'd already finished it (much better than I would have).

kLabz commented 11 months ago

Hope it still matches your workflow! Changed into a file arg so that windows people don't freak out :sweat_smile:

kLabz commented 11 months ago

@Simn is it ok to merge this? Documentation will wait a bit (for a new haxelib release), and can be done on a separate PR.