spring-watcher-listen 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 561c71a39a3fed50f39fa8342ff3433a7fd38850
4
- data.tar.gz: 6e7968fb40f74c0aa54f97f2890c925a3f8c7614
2
+ SHA256:
3
+ metadata.gz: eead46e2623bf2ec3e1183ddfa664c23ed056e8e2c7722331ecc3d926888b762
4
+ data.tar.gz: 124e38605687859f9af1c4311a6ff3343c4e05b3720ded7a5c7258b3eda80586
5
5
  SHA512:
6
- metadata.gz: 2bae5dcf527456279dc77d878a1b0d9e63ef93a182158add2acd673ba40999697adcf245af75a6b66da8a96a11a0fb82ccb980c30c164381e2658dc3ddfc1a28
7
- data.tar.gz: 3748230009113fcee8f0cdbbcaf9e06f88785c9899fbbf7e2af80b778138532784db7d1703922240316913bfda7e0e209cad219f54633b62b3d7054405a22509
6
+ metadata.gz: 5579c3c246d29215cce0fd03f46270f88a3360e7b2aacaa4ac818329f8264a2ea5de7ab99b9a622c5f8cec1ce20f0e0ffd80f704b2560d4be635628c301d176a
7
+ data.tar.gz: 5cdd6f014c586cb628906e4bbed8a425c4dc357992dea33ace3fbf2cf0e929f084b1dfff8944bcc6f98c0f35bf5d713c49bf4d19cd2a3f40f3821ccf3f834913
@@ -0,0 +1,36 @@
1
+ name: CI
2
+ on: [push, pull_request]
3
+ jobs:
4
+ tests:
5
+ runs-on: ubuntu-latest
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ ruby: [ '2.7', '3.0', '3.1', 'head' ]
10
+ rails: [ '6.0', '6.1', '7.0', 'edge' ]
11
+ exclude:
12
+ - ruby: '3.1'
13
+ rails: '6.0'
14
+ - ruby: '3.1'
15
+ rails: '6.1'
16
+
17
+ env:
18
+ RAILS_VERSION: ${{ matrix.rails }}
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: ${{ matrix.ruby }}
27
+ bundler-cache: true
28
+
29
+ - name: Run unit tests
30
+ run: bundle exec rake test:unit
31
+ timeout-minutes: 3
32
+
33
+ - name: Run acceptance tests
34
+ run: bundle exec rake test:acceptance
35
+ timeout-minutes: 10
36
+ if: ${{ matrix.rails != 'edge' && matrix.ruby != 'head' }} # Acceptance tests use `gem install rails && rails new`
data/Gemfile CHANGED
@@ -1,6 +1,13 @@
1
1
  source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
2
3
 
3
4
  # Specify your gem's dependencies in spring-watcher-listen.gemspec
4
5
  gemspec
5
6
 
6
- gem "spring", github: "rails/spring"
7
+ if ENV["RAILS_VERSION"] == "edge"
8
+ gem "activesupport", github: "rails/rails", branch: "main"
9
+ elsif ENV["RAILS_VERSION"]
10
+ gem "activesupport", "~> #{ENV["RAILS_VERSION"]}.0"
11
+ end
12
+
13
+ gem "spring", github: "rails/spring", branch: "main"
data/README.md CHANGED
@@ -1,15 +1,23 @@
1
1
  # Listen watcher for Spring
2
2
 
3
- [![Build Status](https://travis-ci.org/jonleighton/spring-watcher-listen.png?branch=master)](https://travis-ci.org/jonleighton/spring-watcher-listen)
3
+ [![Build Status](https://app.travis-ci.com/rails/spring-watcher-listen.svg?branch=master)](https://app.travis-ci.com/github/rails/spring-watcher-listen)
4
4
  [![Gem Version](https://badge.fury.io/rb/spring-watcher-listen.png)](http://badge.fury.io/rb/spring-watcher-listen)
5
5
 
6
6
  This gem makes [Spring](https://github.com/rails/spring) watch the
7
7
  filesystem for changes using [Listen](https://github.com/guard/listen)
8
8
  rather than by polling the filesystem.
9
9
 
10
- Currently only Listen 1 is supported. However there is [an
11
- effort](https://github.com/jonleighton/spring-watcher-listen/issues/1)
12
- to implement Listen 2 support.
10
+ On larger projects this means spring will be more responsive, more accurate and use less cpu on local filesystems.
11
+
12
+ (NFS, shared VM folders and user file systems will still need polling)
13
+
14
+ Listen 2.7 and higher and 3.0 are supported.
15
+ If you rely on Listen 1 you can use v1.0.0 of this gem.
16
+
17
+ ## Environment variables
18
+
19
+ * `DISABLE_SPRING_WATCHER_LISTEN` - If set, this disables the loading of this gem. This can be useful for projects where
20
+ some configurations do not support inotify (e.g. Docker on M1 Macs).
13
21
 
14
22
  ## Installation
15
23
 
data/Rakefile CHANGED
@@ -1,10 +1,21 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.test_files = FileList["test/*_test.rb"]
7
- t.verbose = true
4
+ namespace :test do
5
+ Rake::TestTask.new(:unit) do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList["test/unit_test.rb"]
8
+ t.verbose = true
9
+ end
10
+
11
+ Rake::TestTask.new(:acceptance) do |t|
12
+ t.libs << "test"
13
+ t.test_files = FileList["test/acceptance_test.rb"]
14
+ t.verbose = true
15
+ end
8
16
  end
9
17
 
18
+ desc 'Run tests'
19
+ task test: ['test:unit', 'test:acceptance']
20
+
10
21
  task default: :test
@@ -1,3 +1,5 @@
1
+ return if ENV['DISABLE_SPRING_WATCHER_LISTEN']
2
+
1
3
  require "spring/watcher"
2
4
  require "spring/watcher/abstract"
3
5
 
@@ -21,11 +23,16 @@ module Spring
21
23
 
22
24
  attr_reader :listener
23
25
 
26
+ def initialize(*)
27
+ super
28
+ @listener = nil
29
+ end
30
+
24
31
  def start
25
- unless @listener
26
- @listener = ::Listen.to(*base_directories, latency: latency, &method(:changed))
27
- @listener.start
28
- end
32
+ return if @listener
33
+
34
+ @listener = ::Listen.to(*base_directories, latency: latency, &method(:changed))
35
+ @listener.start
29
36
  end
30
37
 
31
38
  def stop
@@ -35,6 +42,10 @@ module Spring
35
42
  end
36
43
  end
37
44
 
45
+ def running?
46
+ @listener && @listener.processing?
47
+ end
48
+
38
49
  def subjects_changed
39
50
  return unless @listener
40
51
  return unless @listener.respond_to?(:directories)
@@ -43,7 +54,7 @@ module Spring
43
54
  end
44
55
 
45
56
  def watching?(file)
46
- files.include?(file) || file.start_with?(*directories)
57
+ files.include?(file) || file.start_with?(*directories.keys)
47
58
  end
48
59
 
49
60
  def changed(modified, added, removed)
@@ -54,10 +65,18 @@ module Spring
54
65
  end
55
66
  end
56
67
 
68
+ def mark_stale
69
+ super
70
+
71
+ # May be called from listen thread which won't be happy
72
+ # about stopping itself, so stop from another thread.
73
+ Thread.new { stop }.join
74
+ end
75
+
57
76
  def base_directories
58
77
  ([root] +
59
- files.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
60
- directories.reject { |d| d.start_with? "#{root}/" }
78
+ files.keys.reject { |f| f.start_with? "#{root}/" }.map { |f| File.expand_path("#{f}/..") } +
79
+ directories.keys.reject { |d| d.start_with? "#{root}/" }
61
80
  ).uniq.map { |path| Pathname.new(path) }
62
81
  end
63
82
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "spring-watcher-listen"
5
- spec.version = "2.0.0"
5
+ spec.version = "2.1.0"
6
6
  spec.authors = ["Jon Leighton"]
7
7
  spec.email = ["j@jonathanleighton.com"]
8
8
  spec.summary = %q{Makes spring watch files using the listen gem.}
@@ -14,10 +14,10 @@ Gem::Specification.new do |spec|
14
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
15
  spec.require_paths = ["lib"]
16
16
 
17
- spec.add_development_dependency "bundler", "~> 1.6"
17
+ spec.add_development_dependency "bundler", "~> 2.0"
18
18
  spec.add_development_dependency "rake"
19
19
  spec.add_development_dependency "activesupport"
20
20
 
21
- spec.add_dependency "spring", "~> 1.2"
21
+ spec.add_dependency "spring", ">= 4"
22
22
  spec.add_dependency "listen", ">= 2.7", '< 4.0'
23
23
  end
data/test/helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
2
 
3
3
  require "bundler/setup"
4
- require "spring/test"
4
+ require File.dirname(Gem::Specification.find_by_name("spring").loaded_from) + "/test/support/test"
5
5
  require "minitest/autorun"
6
6
 
7
7
  if defined?(Celluloid)
data/test/unit_test.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "helper"
2
- require "spring/test/watcher_test"
3
2
  require "spring/watcher/listen"
4
3
 
5
4
  class ListenWatcherTest < Spring::Test::WatcherTest
@@ -7,6 +6,9 @@ class ListenWatcherTest < Spring::Test::WatcherTest
7
6
  Spring::Watcher::Listen
8
7
  end
9
8
 
9
+ # this test, as currently written, can only run against polling implementations
10
+ undef :test_add_directory_with_dangling_symlink
11
+
10
12
  setup do
11
13
  Celluloid.boot if defined?(Celluloid)
12
14
  end
@@ -27,8 +29,8 @@ class ListenWatcherTest < Spring::Test::WatcherTest
27
29
  dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) }
28
30
  assert_equal dirs, watcher.base_directories.sort
29
31
  ensure
30
- FileUtils.rmdir other_dir_1
31
- FileUtils.rmdir other_dir_2
32
+ FileUtils.rm_rf other_dir_1
33
+ FileUtils.rm_rf other_dir_2
32
34
  end
33
35
  end
34
36
 
@@ -49,8 +51,26 @@ class ListenWatcherTest < Spring::Test::WatcherTest
49
51
  dirs = [dir, other_dir_1, other_dir_2].sort.map { |path| Pathname.new(path) }
50
52
  assert_equal dirs, watcher.base_directories.sort
51
53
  ensure
52
- FileUtils.rmdir other_dir_1
53
- FileUtils.rmdir other_dir_2
54
+ FileUtils.rm_rf other_dir_1
55
+ FileUtils.rm_rf other_dir_2
54
56
  end
55
57
  end
58
+
59
+ test "stops listening when already stale" do
60
+ # Track when we're marked as stale.
61
+ on_stale_count = 0
62
+ watcher.on_stale { on_stale_count += 1 }
63
+
64
+ # Add a file to watch and start listening.
65
+ file = "#{@dir}/omg"
66
+ touch file, Time.now - 2.seconds
67
+ watcher.add file
68
+ watcher.start
69
+ assert watcher.running?
70
+
71
+ # Touch bumps mtime and marks as stale which stops listener.
72
+ touch file, Time.now - 1.second
73
+ Timeout.timeout(1) { sleep 0.1 while watcher.running? }
74
+ assert_equal 1, on_stale_count
75
+ end
56
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring-watcher-listen
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-27 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: spring
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.2'
61
+ version: '4'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.2'
68
+ version: '4'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: listen
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -93,8 +93,8 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
+ - ".github/workflows/ci.yml"
96
97
  - ".gitignore"
97
- - ".travis.yml"
98
98
  - Gemfile
99
99
  - LICENSE.txt
100
100
  - README.md
@@ -123,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.4.2
126
+ rubygems_version: 3.3.7
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: Makes spring watch files using the listen gem.
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2