Mix hex.build exclude files?

As I want to push my very first package to hex.pm I try to create a local build to see how it works. I see that by default it adds a lot of things I would rather keep out. According to the documentation the :files key defaults to ["lib", "priv", "mix.exs", "README*", "readme*", "LICENSE*", "license*", "CHANGELOG*", "changelog*", "src"] and now my build includes

  Files:
    lib/TAGS <- I don't want to include this
    lib/border.ex
    lib/check/warning/cl_inspect.ex
    lib/check/warning/require_cl.ex
    lib/cl.ex
    lib/cltest.ex  <- I don't want to include this. I know, bad practice keeping this file here
    lib/fields.ex
    lib/label.ex
    lib/render.ex
    lib/switches.ex
    lib/template_engine.ex
    mix.exs
    README.html <- I don't want to include this
    README.md
    README.md~ <- I don't want to include this

The files I want to exclude the same as in my .gitignore. The glob patterns used in the default :files key are inclusive. The other option I see is explicitly list every file I want included. Is there any other option?

1 Like
lib/TAGS <- I don't want to include this

Then do not create it here.

lib/cltest.ex  <- I don't want to include this. I know, bad practice keeping this file here

You are aware of the problem, solve it by moving the file away…

README.html <- I don't want to include this
README.md~ <- I don't want to include this

Alter the list a bit: ["lib", "priv", "mix.exs", "README.md", "LICENSE*", "license*", "CHANGELOG*", "changelog*", "src"] (perhaps for license, changelog etc as well).

But you are right, we should be able to exclude well know temporary files or artifacts (x.erl created from x.yrl will get included by default…)

I’m not sure though if we need to suggest this at elixir-core-mailinglist (because of mix) or at hex’ issue tracker…

2 Likes

I didn’t. Spacemacs did and I don’t know how to change that behavior :confused:.

I did remove that file and did a few changes to the list. It isn’t as bad as I was expecting.

Some times coding in Elixir gives the feeling that lack of some feature is on purpose to enforce good practices.

1 Like

I think the best option is to explicitly list the files you want to include, you can be a bit more specific than the default:

files: ["README.md", "mix*", "lib/**/*.ex"]

If you’d like to take the advantage of .gitignore, you can do this: (pretty popular solution in rubygems):

{out, 0} = System.cmd("git", ["ls-files", "lib", "mix*"])
...
files: String.split(out, "\n")

but note that might still include files not appropriate for the package, so you’d need to manually filter them out.

lib/cltest.ex <- I don’t want to include this. I know, bad practice keeping this file here

You are aware of the problem, solve it by moving the file away…

Agreed. Furthermore, If this file is only used in :dev or :test env (but not :prod in which mix deps run by default), then you can put this file into a different directory and configure Mix to look for files there in given env. Same as Phoenix apps by default compile files from test/support: https://github.com/phoenixframework/phoenix/blob/v1.3.0/installer/templates/phx_single/mix.exs#L32

But you are right, we should be able to exclude well know temporary files or artifacts (x.erl created from x.yrl will get included by default…)
I’m not sure though if we need to suggest this at elixir-core-mailinglist (because of mix) or at hex’ issue tracker…

@NobbZ if you want to pursue this, please open up an issue on Hex. However, I think in most cases it would be enough to manually include only certain files, e.g.:

files: ["src/foo.erl", "src/*.yrl", "lib/**/*.ex"]
3 Likes