From 3459158e64d441e4e924d5893fa9987dae0c74f5 Mon Sep 17 00:00:00 2001 From: Brian John Date: Tue, 14 Dec 2021 17:07:37 -0600 Subject: [PATCH] Disable with `DISABLE_SPRING_WATCHER_LISTEN` env var We have a project where some Engineers are running configurations that do not support `inotify`, which causes an error when this gem is loaded. We still want these Engineers to be able to use Spring in polling mode. We tried setting `require: false` in the `Gemfile` but [Spring loads the gem anyway](https://github.com/rails/spring/blob/a318a1837524ea6e39a7073af94e75131fcc95d1/lib/spring/commands.rb#L35-L46). This change introduces a new env var `DISABLE_SPRING_WATCHER_LISTEN` which, along the lines of `DISABLE_SPRING`, disables the functionality in this gem. --- README.md | 5 +++++ lib/spring/watcher/listen.rb | 2 ++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 098d539..7cb2f27 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,11 @@ On larger projects this means spring will be more responsive, more accurate and Listen 2.7 and higher and 3.0 are supported. If you rely on Listen 1 you can use v1.0.0 of this gem. +## Environment variables + +* `DISABLE_SPRING_WATCHER_LISTEN` - If set, this disables the loading of this gem. This can be useful for projects where + some configurations do not support inotify (e.g. Docker on M1 Macs). + ## Installation Stop Spring if it's already running: diff --git a/lib/spring/watcher/listen.rb b/lib/spring/watcher/listen.rb index a925540..3e14e04 100644 --- a/lib/spring/watcher/listen.rb +++ b/lib/spring/watcher/listen.rb @@ -1,3 +1,5 @@ +return if ENV['DISABLE_SPRING_WATCHER_LISTEN'] + require "spring/watcher" require "spring/watcher/abstract"