Skip to content

Commit 6712858

Browse files
authored
allow disabling symlink warning for colocated js (#4057)
Closes #4045.
1 parent 7991e34 commit 6712858

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/phoenix_live_view/colocated_js.ex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,11 @@ defmodule Phoenix.LiveView.ColocatedJS do
398398
case Keyword.get(settings, :node_modules_path, {:fallback, "assets/node_modules"}) do
399399
{:fallback, rel_path} ->
400400
location = Path.absname(rel_path)
401-
do_symlink(location)
401+
do_symlink(location, true)
402402

403403
path when is_binary(path) ->
404404
location = Path.absname(path)
405-
do_symlink(location)
405+
do_symlink(location, false)
406406
end
407407
end
408408

@@ -414,14 +414,26 @@ defmodule Phoenix.LiveView.ColocatedJS do
414414
end
415415
end
416416

417-
defp do_symlink(node_modules_path) do
417+
defp do_symlink(node_modules_path, is_fallback) do
418418
relative_node_modules_path = relative_to_target(node_modules_path)
419419

420420
with {:error, reason} when reason != :eexist <-
421-
File.ln_s(relative_node_modules_path, Path.join(target_dir(), "node_modules")) do
422-
IO.warn(
423-
"Failed to symlink node_modules folder for Phoenix.LiveView.ColocatedJS: #{inspect(reason)}"
424-
)
421+
File.ln_s(relative_node_modules_path, Path.join(target_dir(), "node_modules")),
422+
false <- Keyword.get(global_settings(), :disable_symlink_warning, false) do
423+
disable_hint = """
424+
If you don't use colocated hooks / js or you don't need to import files from "assets/node_modules"
425+
in your hooks, you can simply disable this warning by setting
426+
427+
config :phoenix_live_view, :colocated_js,
428+
disable_symlink_warning: true
429+
"""
430+
431+
IO.warn("""
432+
Failed to symlink node_modules folder for Phoenix.LiveView.ColocatedJS: #{inspect(reason)}
433+
434+
On Windows, you can address this issue by starting your Windows terminal at least once
435+
with "Run as Administrator" and then running your Phoenix application.#{is_fallback && "\n\n" <> disable_hint}
436+
""")
425437
end
426438
end
427439

0 commit comments

Comments
 (0)