Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/esbuild.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ defmodule Esbuild do
|> elem(1)
end

def json_library() do
case Application.get_env(:esbuild, :json_library) do
nil ->
case Code.ensure_loaded(JSON) do
{:module, _} -> JSON
{:error, _} -> Jason
end

lib ->
lib
end
Comment on lines +192 to +201

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replicate the Phoenix implementation for now:

Suggested change
case Application.get_env(:esbuild, :json_library) do
nil ->
case Code.ensure_loaded(JSON) do
{:module, _} -> JSON
{:error, _} -> Jason
end
lib ->
lib
end
Application.get_env(:esbuild, :json_library, Jason)

That way the default remains Jason, but we may it an optional dep... hmm how bad is that actually? (That's what we ended up with in Phoenix, Jason is still the default library but the dependency is optional and we don't check it's available at runtime)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for all of that. Phoenix has to be customizable because of user structs and all not. In here, we just need any module. So we use JSON, otherwise fallback to Jason as an optional dep, or raise.

end

defp start_unique_install_worker() do
ref =
__MODULE__.Supervisor
Expand Down
2 changes: 1 addition & 1 deletion lib/esbuild/npm_registry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Esbuild.NpmRegistry do
}
} =
fetch_file!(url)
|> Jason.decode!()
|> Esbuild.json_library().decode!()

%{"sig" => signature} =
signatures
Expand Down