About Private Packages

It seems to me that the Elm compiler could enable extensions for package repositories without doing much work at all itself.

From my investigations of how 0.19 works, there are three things the compiler needs:

  1. Get a JSON representation of all known package and their versions. This currently comes from https://package.elm-lang.org/all-packages

  2. Get a JSON representation of packages that have been published since the last locally known package. This currently comes from, e.g. https://package.elm-lang.org/all-packages/since/6800

  3. Download version <x.y.z> of package <owner>/<package>. This currently comes from tag <x.y.z> of github.com/<owner>/<package>.git

Information for 1 and 2 is stored in ~/.elm/0.19.0/package/versions.dat.

The source code is stored in ~/.elm/0.19.0/package/<owner>/<package>/<x.y.z>, and compiled versions of that source are stored in the files cached.dat, ifaces.dat, and objs.dat.

The relevant parts of elm.json look like:

"dependencies": {
    "elm/core": "1.0.0 <= v < 2.0.0",
    "elm/json": "1.0.0 <= v < 2.0.0",
    "elm-community/list-extra": "8.0.0 <= v < 9.0.0"

This could be extended by putting a prefix on the <owner>/<package> strings:

"dependencies": {
    "elm/core": "1.0.0 <= v < 2.0.0",
    "elm/json": "1.0.0 <= v < 2.0.0",
    "elm-community/list-extra": "8.0.0 <= v < 9.0.0",
    "elm-gitlab:spisemisu/elm-utf8": "1.0.0 <= v < 2.0.0"

This denotes that there is an executable named elm-gitlab in the user’s PATH, and it can be called three ways, to perform the three functions needed by the package system:

  1. elm-gitlab all-packages
  2. elm-gitlab all-packages --since 6800
  3. elm-gitlab fetch spisemisu/elm-utf8 --version 1.0.1 --output ~/.elm/0.19.0/elm-gitlab/package/spisemisu/elm-utf8/1.0.1

Suitably-named subdirectories of ~/.elm could be used to store the downloads and compiler output for packages from each extension executable.

This is pretty minimal work in the compiler, and allows a wide range of extension types, including pretty much all other repository systems, and local files.

4 Likes