Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure paths exist before trying to watch them #17

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/hotwire/spark/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Engine < ::Rails::Engine
config.hotwire.spark = ActiveSupport::OrderedOptions.new
config.hotwire.spark.merge! \
enabled: Rails.env.development?,
css_paths: File.directory?("app/assets/builds") ? %w[ app/assets/builds ] : %w[ app/assets/stylesheets ],
css_paths: %w[ app/assets/builds app/assets/stylesheets ],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we can't get rid of this to avoid the duplicated signal problem mentioned here #11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see.
Reverted this change.

html_paths: %w[ app/controllers app/helpers app/models app/views ],
stimulus_paths: %w[ app/javascript/controllers ]

Expand Down
8 changes: 7 additions & 1 deletion lib/hotwire/spark/file_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def expand_path(path)
end

def paths
@callbacks_by_path.keys
ensure_paths_present @callbacks_by_path.keys
end

def ensure_paths_present(paths)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind calling this only_existing_paths. This is an in-house convention, but we usually use ensure to name methods that may raise or take other action, not those that purely return values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Makes sense! That's a better name.

paths.select do |path|
path.exist?
end
end

def process_changed_files(changed_files)
Expand Down