From 9a4671c4c64527e1a59a88bcac24fbcc14337470 Mon Sep 17 00:00:00 2001 From: Malte Rohde Date: Mon, 29 Jul 2024 18:48:58 +0200 Subject: [PATCH] Extract version from version string after app config (#321) Closes #318 --- CHANGELOG.md | 6 ++++++ lib/chromic_pdf/pdf/chrome_runner.ex | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ba915e..6a4a11e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Fixed + +- Small fix `:chrome_version` config switch allowing to pass `Chrome x.y.z.zz` instead of just `x.y.z.zz` + ## [1.16.1] - 2024-07-25 ### Added diff --git a/lib/chromic_pdf/pdf/chrome_runner.ex b/lib/chromic_pdf/pdf/chrome_runner.ex index 2331ef7..fd9b1bd 100644 --- a/lib/chromic_pdf/pdf/chrome_runner.ex +++ b/lib/chromic_pdf/pdf/chrome_runner.ex @@ -28,13 +28,13 @@ defmodule ChromicPDF.ChromeRunner do @spec version() :: binary() def version do - with_app_config_cache(:chrome_version, &do_version/0) + :chrome_version + |> with_app_config_cache(&get_version_from_chrome/0) + |> extract_version() end - defp do_version do - output = system_cmd!(executable(), ["--version"], stderr_to_stdout: true) - [version] = Regex.run(~r/\d+\.\d+\.\d+\.\d+/, output) - version + defp get_version_from_chrome do + system_cmd!(executable(), ["--version"], stderr_to_stdout: true) rescue e -> reraise( @@ -57,6 +57,11 @@ defmodule ChromicPDF.ChromeRunner do ) end + defp extract_version(value) do + [version] = Regex.run(~r/\d+\.\d+\.\d+\.\d+/, value) + version + end + # Public for unit tests. @doc false @spec shell_command(keyword()) :: binary()