From b9d0256b953a67210baaec1fd91871f049560209 Mon Sep 17 00:00:00 2001 From: Aaron Tinio Date: Thu, 1 Oct 2020 10:33:20 +0800 Subject: [PATCH] Make :hackney an optional dependency --- README.md | 1 + lib/excoveralls/poster.ex | 15 +++++++++++++++ mix.exs | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 92a6a4a4..6081e0ad 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ end defp deps do [ {:excoveralls, "~> 0.10", only: :test}, + {:hackney, "~> 1.16", only: :test} # only required if posting to the coveralls.io service ] end ``` diff --git a/lib/excoveralls/poster.ex b/lib/excoveralls/poster.ex index fca0a6ec..f5db9076 100644 --- a/lib/excoveralls/poster.ex +++ b/lib/excoveralls/poster.ex @@ -22,6 +22,7 @@ defmodule ExCoveralls.Poster do end end +if Code.ensure_loaded?(:hackney) do defp send_file(file_name, options) do Application.ensure_all_started(:hackney) endpoint = options[:endpoint] || "https://coveralls.io" @@ -62,4 +63,18 @@ defmodule ExCoveralls.Poster do {:error, "Failed to upload the report to '#{endpoint}' (reason: #{inspect(reason)})."} end end +else + defp send_file(_, _) do + raise """ + missing :hackney dependency + + ExCoveralls requires :hackney to post to the coveralls.io service. + + Please add :hackney to your mix.exs :deps list and run: + + mix deps.get + mix deps.clean --build excoveralls + """ + end +end end diff --git a/mix.exs b/mix.exs index 877a8578..45aa12a3 100644 --- a/mix.exs +++ b/mix.exs @@ -39,7 +39,7 @@ defmodule ExCoveralls.Mixfile do def deps do [ {:jason, "~> 1.0"}, - {:hackney, "~> 1.16"}, + {:hackney, "~> 1.16", optional: true}, {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, {:meck, "~> 0.8", only: :test}, {:mock, "~> 0.3.6", only: :test}