Skip to content

Commit 6437054

Browse files
committed
improvement: make Igniter.exists? support directories
1 parent ab07790 commit 6437054

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

lib/igniter.ex

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,25 @@ defmodule Igniter do
539539
path = Igniter.Util.BackwardsCompat.relative_to_cwd(path, force: true)
540540

541541
cond do
542-
path in igniter.rms ->
542+
Enum.any?(
543+
igniter.rms,
544+
&(&1 == path || subdirectory?(path, &1))
545+
) ->
543546
false
544547

545548
Rewrite.has_source?(igniter.rewrite, path) ->
546549
true
547550

551+
Enum.any?(
552+
igniter.rewrite,
553+
&(&1.path == path || subdirectory?(path, &1.path))
554+
) ->
555+
true
556+
548557
igniter.assigns[:test_mode?] ->
549-
Map.has_key?(igniter.assigns[:test_files], path)
558+
igniter.assigns[:test_files]
559+
|> Map.keys()
560+
|> Enum.any?(&(&1 == path || subdirectory?(path, &1)))
550561

551562
true ->
552563
File.exists?(path)
@@ -1973,4 +1984,21 @@ defmodule Igniter do
19731984
_ ->
19741985
:unavailable
19751986
end
1987+
1988+
defp subdirectory?(path, base_path) do
1989+
case Path.relative_to(path, base_path) do
1990+
# Same path, not a subdirectory
1991+
^base_path ->
1992+
false
1993+
1994+
relative_path ->
1995+
if String.starts_with?(relative_path, ".") || String.starts_with?(relative_path, "/") do
1996+
# It's a parent path or an absolute path, not a subdirectory
1997+
false
1998+
else
1999+
# It's a relative path within the base path
2000+
true
2001+
end
2002+
end
2003+
end
19762004
end

0 commit comments

Comments
 (0)