Skip to content

Commit

Permalink
Guard Mix.Project at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Feb 27, 2024
1 parent 759a2fc commit e6078a2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/phoenix_live_reload/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ defmodule Phoenix.LiveReloader.Channel do
WebConsoleLogger.subscribe(@logs)
end

deps_paths =
for {app, path} <- Mix.Project.deps_paths(), into: %{}, do: {to_string(app), path}

config = socket.endpoint.config(:live_reload)

socket =
socket
|> assign(:patterns, config[:patterns] || [])
|> assign(:debounce, config[:debounce] || 0)
|> assign(:notify_patterns, config[:notify] || [])
|> assign(:deps_paths, deps_paths)
|> assign(:deps_paths, deps_paths())

{:ok, join_info(), socket}
else
Expand Down Expand Up @@ -133,4 +130,12 @@ defmodule Phoenix.LiveReloader.Channel do
%{}
end
end

defp deps_paths do
if Code.loaded?(Mix.Project) do
for {app, path} <- Mix.Project.deps_paths(), into: %{}, do: {to_string(app), path}
else
%{}
end
end
end

0 comments on commit e6078a2

Please sign in to comment.