Closed oleg-vinted closed 1 year ago
I am pretty sure that zeitwerk and auto-reloading changes should handle most changes. I think having this would mean spring would be constantly restarting as you make modifications to pack application code.
I am not seeing any code explicitly in our code bases that use this that monitor. @ngan do you remember if we handle this?
I could see packs/**/config/initializers
though!
It also should be possible to handle this setup automatically. I have seen that dotenv handles this:
# Watch all loaded env files with Spring
begin
require "spring/commands"
ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
Spring.watch event.payload[:env].filename if Rails.application
end
rescue LoadError, ArgumentError
# Spring is not available
end
Yeah, it does indeed do a full restart whenever something changes. I couldn't find a way to distinguish between when it's absolutely necessary to restart (a new pack is added, low-level path re-initialization is necessary), and when it's not (e.g. some file in /packs/somepack/app/models/
is changed).
Zeitwerk can handle the second case just fine, but Zeitwerk alone is not enough for the first case.
So yes, ideally, we would find a way to make Spring restart when a new pack is added, not when any change is done to packs/**/*
.
I no longer think the PR makes sense in its original form, it has too big of a drawback.
Spring restart when a new pack is added, not when any change is done to packs/*/.
You're right, this is the ideal case. Spring doesn't have that ability though since it'll watch for any change. Adding a pack is uncommon enough where I think a restart will be just fine. It's just a matter of knowing that you need to restart.
We add config, etc paths to Rails' load paths which means it'll get added to Spring's watch path automatically. Therefore, changes to config/*
in packs will get picked up for spring restart.
By default, Spring does not watch and react to changes in packs folder, leading to inconsistent state.