Presubmit.MixFile (presubmit v0.2.2)

Copy Markdown View Source

Reads dependency and version declarations from mix.exs and mix.lock without evaluating them.

Recognised shapes: a deps/0 function returning a list literal of {:name, ...} tuples, @version "..." or version: "...", elixirc_paths: (see elixirc_paths/2), and the standard %{"name" => {...}} lockfile map.

Summary

Functions

Dependencies declared by every mix.exs in the tree (umbrella apps included), deduplicated by name.

Package names present in every mix.lock in the tree.

Dependencies declared in mix.exs, or [] if absent or unparseable.

The paths the project at path compiles Elixir from in the :prod environment, as written in its mix.exs (relative to the project).

Package names present in mix.lock, or [] if absent.

Paths in the tree matching pattern, excluding vendored dependencies and test fixtures (a mix.exs under test/ describes a fixture project, not this one).

A pattern matching the Elixir files each project in the tree ships: the .ex files Mix compiles from the project's elixirc_paths/2, joined to the project's directory. These are the files a dependent compiles; test support and fixtures compiled only under MIX_ENV=test are not among them.

The project version from mix.exs, or nil.

Types

dep()

@type dep() :: %{name: atom(), requirement: String.t() | nil, opts: keyword()}

Functions

all_deps(tree)

@spec all_deps(Presubmit.Tree.t()) :: [dep()]

Dependencies declared by every mix.exs in the tree (umbrella apps included), deduplicated by name.

all_locked(tree)

@spec all_locked(Presubmit.Tree.t()) :: [atom()]

Package names present in every mix.lock in the tree.

deps(tree, path \\ "mix.exs")

@spec deps(Presubmit.Tree.t(), String.t()) :: [dep()]

Dependencies declared in mix.exs, or [] if absent or unparseable.

elixirc_paths(tree, path \\ "mix.exs")

@spec elixirc_paths(Presubmit.Tree.t(), String.t()) :: [String.t()]

The paths the project at path compiles Elixir from in the :prod environment, as written in its mix.exs (relative to the project).

:prod is the environment a project is compiled in when it is somebody's dependency, so these are the paths of the code the package ships: test support and fixtures that elixirc_paths(:test) adds are excluded.

mix.exs is read, not evaluated. The value of elixirc_paths: is resolved from literal lists of strings joined with ++, Mix.env(), module attributes, if over comparisons of Mix.env(), and calls to functions defined in mix.exs whose clauses match on literals or variables, optionally with ==, !=, in, and, or, or not guards. That covers the elixirc_paths(Mix.env()) helper Phoenix's generator writes and the variations on it seen in practice.

Returns [] for an umbrella root (apps_path:), which compiles nothing itself, and ["lib"], Mix's default, when elixirc_paths: is absent, when its value is beyond those shapes, or when mix.exs is missing or does not parse.

locked(tree, path \\ "mix.lock")

@spec locked(Presubmit.Tree.t(), String.t()) :: [atom()]

Package names present in mix.lock, or [] if absent.

project_files(tree, pattern)

@spec project_files(Presubmit.Tree.t(), Regex.t()) :: [String.t()]

Paths in the tree matching pattern, excluding vendored dependencies and test fixtures (a mix.exs under test/ describes a fixture project, not this one).

shipped_source(tree)

@spec shipped_source(Presubmit.Tree.t()) :: Presubmit.Pattern.t()

A pattern matching the Elixir files each project in the tree ships: the .ex files Mix compiles from the project's elixirc_paths/2, joined to the project's directory. These are the files a dependent compiles; test support and fixtures compiled only under MIX_ENV=test are not among them.

Every mix.exs that project_files/2 finds is a project, so umbrella apps and subdirectory projects each contribute their own paths. A tree with no mix.exs at all is not a Mix project; there the conventional lib/ directories at any depth stand in.

version(tree, path \\ "mix.exs")

@spec version(Presubmit.Tree.t(), String.t()) :: String.t() | nil

The project version from mix.exs, or nil.