Skip to content

Commit 96417c8

Browse files
authored
add debug_attributes to igniter upgrader (#3905)
1 parent f491d40 commit 96417c8

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

lib/phoenix_live_view/igniter/upgrade_to_1_1.ex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if Code.ensure_loaded?(Igniter) do
2929
end)
3030
|> maybe_update_reloadable_compilers()
3131
|> maybe_update_esbuild_config()
32+
|> maybe_update_debug_config()
3233
end
3334

3435
defp maybe_update_reloadable_compilers(igniter) do
@@ -242,5 +243,33 @@ if Code.ensure_loaded?(Igniter) do
242243
end
243244
)
244245
end
246+
247+
defp maybe_update_debug_config(igniter) do
248+
if Igniter.Project.Config.configures_key?(
249+
igniter,
250+
"dev.exs",
251+
:phoenix_live_view,
252+
:debug_heex_annotations
253+
) do
254+
if Igniter.Project.Config.configures_key?(
255+
igniter,
256+
"dev.exs",
257+
:phoenix_live_view,
258+
:debug_attributes
259+
) do
260+
igniter
261+
else
262+
Igniter.Project.Config.configure(
263+
igniter,
264+
"dev.exs",
265+
:phoenix_live_view,
266+
:debug_attributes,
267+
true
268+
)
269+
end
270+
else
271+
igniter
272+
end
273+
end
245274
end
246275
end

test/phoenix_live_view/igniter/upgrade_to_1_1_test.exs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,45 @@ defmodule Phoenix.LiveView.Igniter.UpgradeTo1_1Test do
393393
end
394394
end
395395

396+
describe "debug_attributes" do
397+
test "adds debug_attributes when debug_heex_annotations is already set" do
398+
test_project(
399+
app_name: :my_app,
400+
files: %{
401+
"config/dev.exs" => """
402+
import Config
403+
404+
config :phoenix_live_view,
405+
enable_expensive_runtime_checks: true,
406+
debug_heex_annotations: true
407+
"""
408+
}
409+
)
410+
|> run_upgrade()
411+
|> assert_has_patch("config/dev.exs", """
412+
- | debug_heex_annotations: true
413+
+ | debug_heex_annotations: true,
414+
+ | debug_attributes: true
415+
""")
416+
end
417+
418+
test "does not add debug_attributes when debug_heex_annotations is not set" do
419+
test_project(
420+
app_name: :my_app,
421+
files: %{
422+
"config/dev.exs" => """
423+
import Config
424+
425+
config :phoenix_live_view,
426+
enable_expensive_runtime_checks: true
427+
"""
428+
}
429+
)
430+
|> run_upgrade()
431+
|> assert_unchanged("config/dev.exs")
432+
end
433+
end
434+
396435
describe "full upgrade scenario" do
397436
test "performs complete upgrade for a Phoenix project" do
398437
full_project()
@@ -409,6 +448,11 @@ defmodule Phoenix.LiveView.Igniter.UpgradeTo1_1Test do
409448
- | reloadable_compilers: [:elixir, :app]
410449
+ | reloadable_compilers: [:phoenix_live_view, :elixir, :app]
411450
""")
451+
|> assert_has_patch("config/dev.exs", """
452+
- | debug_heex_annotations: true
453+
+ | debug_heex_annotations: true,
454+
+ | debug_attributes: true
455+
""")
412456
|> assert_has_patch("config/config.exs", """
413457
- | args: ~w(js/app.js --bundle --outdir=../priv/static/assets),
414458
+ | args: ~w(js/app.js --bundle --outdir=../priv/static/assets --alias:@=.),
@@ -464,6 +508,10 @@ defmodule Phoenix.LiveView.Igniter.UpgradeTo1_1Test do
464508
config :my_app, MyAppWeb.Endpoint,
465509
http: [port: 4000],
466510
reloadable_compilers: [:elixir, :app]
511+
512+
config :phoenix_live_view,
513+
enable_expensive_runtime_checks: true,
514+
debug_heex_annotations: true
467515
"""
468516
}
469517
)

0 commit comments

Comments
 (0)