VirtualTimeGenServer.Doctor (GenServerVirtualTime v1.1.0)

Copy Markdown View Source

Turns a project's module references into the dependency lines it is missing.

The library is published as a family of packages that share one version, and a module keeps its name when it moves to another package. So the fix for a missing module is a line in mix.exs, not a change to the code — and this module works out which line.

mix virtual_time.doctor drives it; the parts are pure so they can be specified directly.

Summary

Types

A reference the project has to act on: either a module that lives in a package the project does not have, or a call that was removed and has a replacement.

Functions

Reports what a project has to change, given its references and a way to ask whether a module is available in the current build.

The report as a project maintainer reads it.

The dependencies a project has to add, one per package, in report order.

Types

finding()

@type finding() ::
  %{
    kind: :missing_package,
    module: String.t(),
    function: String.t() | nil,
    file: Path.t(),
    line: pos_integer(),
    package: VirtualTimeGenServer.Packages.package(),
    dependency: String.t()
  }
  | %{
      kind: :removed_api,
      module: String.t(),
      function: String.t() | nil,
      file: Path.t(),
      line: pos_integer(),
      replacement: String.t()
    }

A reference the project has to act on: either a module that lives in a package the project does not have, or a call that was removed and has a replacement.

Functions

diagnose(references, available?)

Reports what a project has to change, given its references and a way to ask whether a module is available in the current build.

A module that is available is not a finding: the doctor only speaks about problems. Availability — not the declared dependencies — is what it checks, so a package that arrives indirectly is not reported either.

format(findings)

@spec format([finding()]) :: String.t()

The report as a project maintainer reads it.

missing_dependencies(findings)

@spec missing_dependencies([finding()]) :: [String.t()]

The dependencies a project has to add, one per package, in report order.