DEV: Print a warning and restart server when editing non-autoloaded files (PR #13037)

This commit adds a listener on (almost) all .rb files in the repository. When a change occurs, it checks whether Zeitwerk is responsible for autoloading the file. If not, a warning will be printed to the console to remind the developer to restart the server. Optionally, you can pass the AUTO_RESTART=1 environment variable to automatically trigger a server restart on every non-autoloading change.

GitHub

This seems quite cool.

Minor but this can be moved into the conditional which is the only place this is used.

Are we able to listen to events only when the contents of the file have changed? Right now, the warning is being triggered even when I save without making any changes.

The title of this pull request changed from “DEV: Print a warning when editing non-autoloaded files” to "DEV: Print a warning and restart server when editing non-autoloaded files

Unfortunately not easily - the Listen gem notifies us about changes (via various OS-specific hooks), and then gives us the filenames. ‘changes’ in this case includes changes to the file metadata (e.g. modified time). Technically I guess we could load every file into memory and check for diffs, but I think it would make things a lot slower.

This method of ‘checking modified time’ is the same thing which Rails uses to trigger code reloads.