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

Conversation

adrianthedev
Copy link
Contributor

Some apps might not have the directories that are set by default.
This PR checks if the path exists before trying to watch it.

I ran into this while trying to run it in an engine. The dummy app doesn't have the app/assets/stylesheets and app/javascript/controllers paths.
This is one example. Others might structure their application differently as well.

Note

As I am still new to contributing here, I am unfamiliar with some of the design patterns and decisions made thus far in this repo. If I broke any patterns you've established so far, let me know and I'll address that.

Copy link
Member

@jorgemanrubia jorgemanrubia left a comment

Choose a reason for hiding this comment

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

Good patch @adrianthedev. Requesting a couple of changes, but good call filtering only existing dirs 👍

@@ -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.

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.

@adrianthedev
Copy link
Contributor Author

adrianthedev commented Dec 19, 2024

Thanks for the review, Jorge 🙌
Love the work!

I was talking to Paul about some of the design decisions you took with this gem.
I live the Installer naming and design pattern. I might have to use that in the future.

@jorgemanrubia jorgemanrubia merged commit 5f03fec into basecamp:main Dec 19, 2024
@jorgemanrubia
Copy link
Member

Thanks @adrianthedev! I added that because there was more to coordinate than in a regular engine, so it's nice to have a dedicated place to orcherstate things. Also, I pushed this minor tweak to main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants