Packages

A tool to audit Erlang & Elixir dependencies, to make sure your Gleam ✨ projects really sparkle!

Retired package: Security issue - Vulnerability warnings were never emitted due to an inverted advisory filter. Upgrade to 3.3.1 or 4.0.0-rc2+.

Current section

Files

Jump to
go_over src go_over@hex@hex.erl
Raw

src/go_over@hex@hex.erl

-module(go_over@hex@hex).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/go_over/hex/hex.gleam").
-export([decode_latest_stable_version_and_licenses/1, get_hex_info/3]).
-export_type([hex_info/0, hex_warning_source/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-type hex_info() :: {hex_info, gleam@option:option(binary()), list(binary())}.
-type hex_warning_source() :: {rejected_license, binary()} |
{outdated, binary()}.
-file("src/go_over/hex/hex.gleam", 22).
?DOC(false).
-spec pull_hex_info(go_over@hex@puller:puller(), go_over@packages:package()) -> nil.
pull_hex_info(Puller, Pkg) ->
go_over@util@print:progress(
<<<<"Checking latest version: "/utf8, (erlang:element(2, Pkg))/binary>>/binary,
" From hex.pm"/utf8>>
),
Pkg_path = go_over@hex@core:hex_info_path(Pkg),
Pkg_path_fail = go_over@hex@core:pkg_pull_error(Pkg, Pkg_path),
_ = simplifile_erl:delete(Pkg_path),
_pipe = simplifile:create_directory_all(Pkg_path),
gxyz@cli:hard_fail_with_msg(_pipe, Pkg_path_fail),
Resp = go_over@hex@core:do_pull_hex(
Puller,
Pkg,
go_over@hex@core:package_url(Pkg)
),
_pipe@1 = Pkg,
_pipe@2 = go_over@hex@core:hex_info_filename(_pipe@1),
_pipe@3 = simplifile:write(_pipe@2, Resp),
gxyz@cli:hard_fail_with_msg(_pipe@3, Pkg_path_fail).
-file("src/go_over/hex/hex.gleam", 39).
?DOC(false).
-spec decode_latest_stable_version_and_licenses(binary()) -> {ok, hex_info()} |
{error, gleam@json:decode_error()}.
decode_latest_stable_version_and_licenses(Data) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"latest_stable_version"/utf8>>,
gleam@dynamic@decode:optional(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Latest_stable_version) ->
gleam@dynamic@decode:subfield(
[<<"meta"/utf8>>, <<"licenses"/utf8>>],
gleam@dynamic@decode:list(
{decoder, fun gleam@dynamic@decode:decode_string/1}
),
fun(Licenses) ->
gleam@dynamic@decode:success(
{hex_info, Latest_stable_version, Licenses}
)
end
)
end
)
end,
gleam@json:parse(Data, Decoder).
-file("src/go_over/hex/hex.gleam", 57).
?DOC(false).
-spec pull(go_over@hex@puller:puller(), go_over@packages:package()) -> hex_info().
pull(Puller, Pkg) ->
_pipe = Pkg,
_pipe@1 = go_over@hex@core:hex_info_path(_pipe),
go_over@util@cache:pull_if_not_cached(
_pipe@1,
3600,
gxyz@function:freeze2(fun pull_hex_info/2, Puller, Pkg),
<<(erlang:element(2, Pkg))/binary, ": latest stable version"/utf8>>
),
Cached_file_name = go_over@hex@core:hex_info_filename(Pkg),
Resp = begin
_pipe@2 = Cached_file_name,
_pipe@3 = simplifile:read(_pipe@2),
gxyz@cli:hard_fail_with_msg(
_pipe@3,
<<"failed to read "/utf8, Cached_file_name/binary>>
)
end,
gxyz@cli:hard_fail_with_msg(
decode_latest_stable_version_and_licenses(Resp),
<<"failed to parse "/utf8, Cached_file_name/binary>>
).
-file("src/go_over/hex/hex.gleam", 79).
?DOC(false).
-spec check_outdated(binary(), go_over@packages:package(), binary()) -> gleam@option:option(binary()).
check_outdated(Latest_version, Pkg, Cached_file_name) ->
Latest_semver = begin
_pipe = gleamsver:parse(Latest_version),
gxyz@cli:hard_fail_with_msg(
_pipe,
<<"failed to parse: "/utf8, Cached_file_name/binary>>
)
end,
case gleamsver:compare(Latest_semver, erlang:element(3, Pkg)) of
gt ->
{some, Latest_version};
_ ->
none
end.
-file("src/go_over/hex/hex.gleam", 99).
?DOC(false).
-spec get_hex_info(
go_over@hex@puller:puller(),
go_over@packages:package(),
list(binary())
) -> list(hex_warning_source()).
get_hex_info(Puller, Pkg, Allowed_licenses) ->
Info = pull(Puller, Pkg),
Cached_file_name = go_over@hex@core:hex_info_filename(Pkg),
Outdated = begin
_pipe = erlang:element(2, Info),
_pipe@1 = gleam@option:map(
_pipe,
fun(_capture) -> check_outdated(_capture, Pkg, Cached_file_name) end
),
_pipe@2 = gleam@option:flatten(_pipe@1),
gleam@option:map(_pipe@2, fun(Field@0) -> {outdated, Field@0} end)
end,
Rejected_licenses = begin
_pipe@3 = gxyz@list:reject_contains(
erlang:element(3, Info),
Allowed_licenses
),
gleam@list:map(_pipe@3, fun(Field@0) -> {rejected_license, Field@0} end)
end,
case Outdated of
none ->
Rejected_licenses;
{some, Outdated@1} ->
[Outdated@1 | Rejected_licenses]
end.