Skip to content

Commit fc8d7cc

Browse files
authored
Add Jason dependency for Elixir <= 1.17 (#90)
Fixes #81
1 parent 8ec4827 commit fc8d7cc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/phoenix/sync/sandbox/producer.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ if Phoenix.Sync.sandbox_enabled?() do
1313
alias Electric.Replication.LogOffset
1414
alias Electric.Replication.ShapeLogCollector
1515

16+
@json if(Code.ensure_loaded?(JSON), do: JSON, else: Jason)
17+
1618
def child_spec(opts) do
1719
{:ok, stack_id} = Keyword.fetch(opts, :stack_id)
1820

@@ -164,11 +166,11 @@ if Phoenix.Sync.sandbox_enabled?() do
164166
type.to_iso8601(datetime)
165167
end
166168

167-
defp dump(map, _type) when is_map(map), do: JSON.encode!(map)
169+
defp dump(map, _type) when is_map(map), do: @json.encode!(map)
168170

169171
defp dump(list, type) when is_list(list) do
170172
if encode_list_json?(type) do
171-
JSON.encode!(list)
173+
@json.encode!(list)
172174
else
173175
encode_array(list, type)
174176
end

mix.exs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule Phoenix.Sync.MixProject do
4444
{:ecto_sql, "~> 3.10", optional: true},
4545
{:electric, "~> 1.1.2", optional: true},
4646
{:electric_client, "~> 0.7"}
47-
] ++ deps_for_env(Mix.env())
47+
] ++ deps_for_env(Mix.env()) ++ json_deps()
4848
end
4949

5050
defp deps_for_env(:test) do
@@ -68,6 +68,16 @@ defmodule Phoenix.Sync.MixProject do
6868
[]
6969
end
7070

71+
defp json_deps do
72+
if Code.ensure_loaded?(JSON) do
73+
# elixir >= 1.18
74+
[]
75+
else
76+
# elixir <= 1.17
77+
[{:jason, "~> 1.0"}]
78+
end
79+
end
80+
7181
defp aliases do
7282
[
7383
"test.all": ["test", "test.as_a_dep", "test.apps"],

0 commit comments

Comments
 (0)