rubyatscale / packs-rails

packs-rails establishes and implements a set of conventions for splitting up large monoliths.
MIT License
268 stars 26 forks source link

Add spring watch #82

Closed professor closed 7 months ago

professor commented 8 months ago

When a pack moves, we want spring to update the loaded classes so that packwerk prints correct results

Screenshot 2024-02-13 at 13 40 43

Fixes #81

exterm commented 8 months ago

Very excited for this to land

exterm commented 8 months ago

One note: this doesn't seem to cover the case where an autoload path is added and none of the previously registered package.yml files is changed.

I just added an initializer to a pack and had to stop spring manually.

perryqh commented 8 months ago

One note: this doesn't seem to cover the case where an autoload path is added and none of the previously registered package.yml files is changed.

I just added an initializer to a pack and had to stop spring manually.

Thanks for the comment!

We want to clarify the expectation. Did you add a new autoload path or a new file in the autoload path?

We noticed that Spring has a limitation on only watching files it knows about when initialized. New files, including ruby files, will not cause Spring to reload.

exterm commented 8 months ago

We noticed that Spring has a limitation on only watching files it knows about when initialized. New files, including ruby files, will not cause Spring to reload.

Mmmh, was that with or without https://github.com/rails/spring-watcher-listen ? Listen, according to its documentation, can detect added files in watched directories.

Detects file modification, addition and removal.

https://github.com/guard/listen?tab=readme-ov-file#features

And here's the code in spring-watcher-listen that listens to additions: https://github.com/rails/spring-watcher-listen/blob/996d29e8f9b38fb642dd6b496ed600e941bd7de1/lib/spring/watcher/listen.rb#L62 ... I wonder if that's only for directories outside of Rails.root? Curious.

Did you add a new autoload path or a new file in the autoload path?

If I remember correctly, I added a pack with new ruby files and didn't modify any existing package.yml files. In general - why would we expect this mechanism to be able to pick up new autoload paths from newly added packages? We only respect package.yml files that were present at application startup, no?

I wonder if we could listen to additions of package.yml files... but it seems that would require a custom spring watcher, or modifications to spring-watcher-listen.

professor commented 7 months ago

Replaced by https://github.com/rubyatscale/packs-rails/pull/86

exterm commented 7 months ago

The other PR says this was closed because it "started to need more and more gem dependencies". I don't see those in the diff. Can you expand on the problem you encountered?