zwilias / elm-json

Install, upgrade and uninstall Elm dependencies
MIT License
183 stars 9 forks source link

Request ability to specify latest version of a major version of a package #18

Closed jfmengels closed 4 years ago

jfmengels commented 4 years ago

Hi!

I'd like to request the ability to install the latest version of a major release of a dependency. In other words, I'd like to be able to do elm-json install author/name@2, or the equivalent of npm install something@^2 in npm.

Request context

I am the author elm-review, which is a library and CLI, and the CLI uses elm-json under the hood (thanks a lot for this tool, by the way :heart:).

elm-review works using a configuration written in Elm, where it defines the review rules to enable. Some of which are defined in local files, and the rest are found in Elm packages, such as this one.

To avoid polluting the project's elm.json (and potentially blocking the install of their dependencies), the configuration is in the review/ directory of their project, which has a Config.elm file and an elm.json file.

When running the actual review, it in essence copies the review/ folder somewhere in elm-stuff and compiles a new application by merging the user configuration and Elm code contained and specific to the CLI, using the source-directories and the dependencies found in review/elm.json.

To help onboard the user, the CLI provides an init command, where it will create the review/ directory with an empty configuration file and an elm.json, and will install the jfmengels/elm-review package using elm-json install jfmengels/elm-review.

That last section is where my problem resides. The code contained CLI application works for/with a specific version of this package (1.0.0 <= v < 2.0.0), but when running init, it will install the latest released version, potentially 2.0.0 or later. In effect, the day I release v2.0.0, all the existing init with the CLI that supports only v1.x.x will stop working correctly.

Proposed solution

The solutions I could think of with are:

  1. Specifying in the CLI the exact version of jfmengels/elm-review that will work (ex: 1.3.4), but that makes it necessary to release a new version of the CLI every time I release the package, which is not great.

  2. Have elm-json support a syntax like elm-json install author/name@1

  3. Have the CLI fetch the contents of the package registry, find out the latest version of the package of the major release I wish to support, and install that one (basically reimplement elm-json solve I think?)

I think I will go with solution 3, but maybe solution 2 is an easy and welcome (to you) addition to elm-json.

I don't know the exact reason for elm install not supporting this option in the first place. I am guessing it is because this is quite a rare edge-case.

Let met know what you think :)

zwilias commented 4 years ago

I think this should be feasible to implement in elm-json!

When using the the install command, what essentially happens is that we take the current constraints, and add an extra constraint for the package-to-be-added. If no version is specified, this is an open constraint ("anything goes!"). If a version is specified, this becomes a very narrow constraint ("this exact version, please"). At least on the technical level, something like @2 being added as 2.0.0 <= v < 3.0.0 should be doable.

Thanks for the suggestion, I'm going to try and put some work into this tomorrow!

jfmengels commented 4 years ago

Thanks a lot for working on this @zwilias!

I understand that it was released in elm-json v0.2.4, but it is not working for me, even by trying the example given in the docs

> elm-json install elm/http@2
error: Invalid value for '<PACKAGE>...': Invalid version: 2

Could it be that the CLI args parser still doesn't allow package "names" like elm/http@2?

zwilias commented 4 years ago

Oh lord, I messed up the deploy to github by messing with tags, trying to get the RPI build working šŸ¤¦ā€ā™‚ image

I'll tag a v0.2.5, and release that once all the builds are finished!

zwilias commented 4 years ago

image

There we go šŸ˜„

jfmengels commented 4 years ago

Works great, thanks a lot! :tada: