Repository: phoenixframework/phoenix (elixir)

Issue:
Warn on phx.gen.live if LiveView.JS is missing?
<!--
### Precheck

* For general discussions and support, use Stack Overflow or the Elixir Forum
* For proposing and discussing new features, start a thread on the Phoenix Core mailing list
* For bugs, do a quick search and make sure the bug has not yet been reported
* Ensure that this issue is related to the Phoenix library and not one of the dependencies listed in mix.exs (Ecto, Plug, etc.)
* All checked? Be nice and have fun!
-->

The latest generator relies on `Phoenix.LiveView.JS` which requires LiveView v0.17+. Without the module, running `mix phx.server` after running the generator will emit a compilation error:

```sh
== Compilation error in file lib/fiddle_web/live/live_helpers.ex ==
** (CompileError) lib/fiddle_web/live/live_helpers.ex:55: Phoenix.LiveView.JS.__struct__/1 is undefined, cannot expand struct Phoenix.LiveView.JS. Make sure the struct name is correct. If the struct name exists and is correct but it still cannot be found, you likely have cyclic module usage in your code
    lib/fiddle_web/live/live_helpers.ex:55: (module)
```

Should we check whether or not `LiveView.JS` is loaded and print a warning for the user to upgrade? They will need to update deps for LiveView and LiveDashboard:

```elixir
defp deps do
 [
    {:phoenix_live_view, "~> 0.17"},
    {:phoenix_live_dashboard", "~> 0.6"}
    # deps...
  ]
end
```


Pull request description:
Add upgrade instructions to phx.gen.live task
Closes #4642

Patch:
diff --git a/lib/mix/tasks/phx.gen.live.ex b/lib/mix/tasks/phx.gen.live.ex
index 4bf63ca47..fbb2924a0 100644
--- a/lib/mix/tasks/phx.gen.live.ex
+++ b/lib/mix/tasks/phx.gen.live.ex
@@ -219,6 +219,18 @@ defmodule Mix.Tasks.Phx.Gen.Live do
       """
     end
     if context.generate?, do: Gen.Context.print_shell_instructions(context)
+    maybe_print_upgrade_info()
+  end
+
+  defp maybe_print_upgrade_info do
+    unless Code.ensure_loaded?(Phoenix.LiveView.JS) do
+      Mix.shell().info """
+
+      You must update :phoenix_live_view to v0.17 or later and
+      :phoenix_live_dashboard to v0.6 or later to use the features
+      in this generator.
+      """
+    end
   end
 
   defp live_route_instructions(schema) do


Test patch:
diff --git a/test/mix/tasks/phx.gen.live_test.exs b/test/mix/tasks/phx.gen.live_test.exs
index 68fc6b645..f397e0b07 100644
--- a/test/mix/tasks/phx.gen.live_test.exs
+++ b/test/mix/tasks/phx.gen.live_test.exs
@@ -174,6 +174,13 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
           live "/comments/:id", CommentLive.Show, :show
           live "/comments/:id/show/edit", CommentLive.Show, :edit
       """]}
+
+      assert_receive({:mix_shell, :info, ["""
+
+      You must update :phoenix_live_view to v0.17 or later and
+      :phoenix_live_dashboard to v0.6 or later to use the features
+      in this generator.
+      """]})
     end
   end