spring 3.0.0 → 4.1.3

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
2
  SHA256:
3
- metadata.gz: b33b73bbbedd5ed08ff1c6de6d040faaf347cfae0b6cc41c5378a834f0cefc87
4
- data.tar.gz: 6e9c1f79634653bbf9875e6786a5e5d1df38d13d2f0b47fff129ff7a804a663c
3
+ metadata.gz: 1aaab82742a464eba8cafc32761c1f8509c661d3eae8816c7ce37402b1e454ba
4
+ data.tar.gz: dca019edd6550c1ce7d514da586df59a3c3838d1f36d113e9870cdf44052a655
5
5
  SHA512:
6
- metadata.gz: 1e7c861899e73bec7b1dd623d0c486b66efdb257bc388caf10034dd11095f2feffa2695e09008d1669931f4e1c8d805c70ca7e403ea76431315f583d43664e37
7
- data.tar.gz: 49587a245923eee35343818174edf141d2b687fb4b09cd9eeefe31c867848b03400cee41e98f2d5b35130d1b313c3f9b3433a557bfb5c5a20fc6fe4ae0822f7a
6
+ metadata.gz: 52b2c4a44be6f82f5c4877af16c52aacf98cf28641210dde453439e7e2d9ded480bc7ceb1e58465d30e8992b1bd88a8b591246bcfc66708c722fd5692c7c98a6
7
+ data.tar.gz: abb5569bb5d37f570003ba7784f181afd0598249cddc3c1519e2df63368b8db3a540119c8fedccb599c095a2b3c07dee5df0e0a09c09c30f551ccdf7e7f45f7b
data/LICENSE.txt CHANGED
@@ -1,3 +1,4 @@
1
+ Copyright (c) 2017-2021 Rafael Mendonça França
1
2
  Copyright (c) 2012-2017 Jon Leighton
2
3
 
3
4
  MIT License
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Spring
2
2
 
3
- [![Build Status](https://travis-ci.org/rails/spring.svg?branch=master)](https://travis-ci.org/rails/spring)
4
- [![Gem Version](https://badge.fury.io/rb/spring.svg)](http://badge.fury.io/rb/spring)
3
+ [![Build Status](https://github.com/rails/spring/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rails/spring/actions/workflows/ci.yml?branch=main)
4
+ [![Gem Version](https://badge.fury.io/rb/spring.svg)](https://badge.fury.io/rb/spring)
5
5
 
6
6
  Spring is a Rails application preloader. It speeds up development by
7
- keeping your application running in the background so you don't need to
7
+ keeping your application running in the background, so you don't need to
8
8
  boot it every time you run a test, rake task or migration.
9
9
 
10
10
  ## Features
@@ -16,9 +16,9 @@ boot it every time you run a test, rake task or migration.
16
16
 
17
17
  ## Compatibility
18
18
 
19
- * Ruby versions: MRI 2.5, MRI 2.6
20
- * Rails versions: 5.2, 6.0 (Spring is installed by default when you do
21
- `rails new` to generate your application)
19
+ * Ruby versions: MRI 2.7, MRI 3.0, MRI 3.1, MRI 3.2
20
+ * Rails versions: 6.0, 6.1, 7.0
21
+ * Bundler v2.1+
22
22
 
23
23
  Spring makes extensive use of `Process.fork`, so won't be able to
24
24
  provide a speed up on platforms which don't support forking (Windows, JRuby).
@@ -50,13 +50,14 @@ code into relevant existing executables. The snippet looks like this:
50
50
  ``` ruby
51
51
  begin
52
52
  load File.expand_path('../spring', __FILE__)
53
- rescue LoadError
53
+ rescue LoadError => e
54
+ raise unless e.message.include?('spring')
54
55
  end
55
56
  ```
56
57
 
57
58
  On platforms where Spring is installed and supported, this snippet
58
59
  hooks Spring into the execution of commands. In other cases, the snippet
59
- will just be silently ignored and the lines after it will be executed as
60
+ will just be silently ignored, and the lines after it will be executed as
60
61
  normal.
61
62
 
62
63
  If you don't want to prefix every command you type with `bin/`, you
@@ -70,11 +71,14 @@ Rails directory.
70
71
  Spring reloads application code, and therefore needs the application to have
71
72
  reloading enabled.
72
73
 
73
- Please, make sure `config.cache_classes` is `false` in the environments that
74
+ Ensure that `config.enable_reloading` is `true` in the environments that
74
75
  Spring manages. That setting is typically configured in
75
- `config/environments/*.rb`. In particular, make sure it is `false` for the
76
+ `config/environments/*.rb`. In particular, make sure it is `true` for the
76
77
  `test` environment.
77
78
 
79
+ Note: in versions of Rails before 7.1, the setting is called `cache_classes`,
80
+ and it needs to be `false` for Spring to work.
81
+
78
82
  ### Usage
79
83
 
80
84
  For this walkthrough I've generated a new Rails application, and run
@@ -178,7 +182,7 @@ Spring is running:
178
182
  ```
179
183
 
180
184
  There's no need to "shut down" Spring. This will happen automatically
181
- when you close your terminal. However if you do want to do a manual shut
185
+ when you close your terminal. However, if you do want to do a manual shut
182
186
  down, use the `stop` command:
183
187
 
184
188
  ```
@@ -198,12 +202,13 @@ To remove Spring:
198
202
  ### Deployment
199
203
 
200
204
  You must not install Spring on your production environment. To prevent it from
201
- being installed, provide the `--without development test` argument to the
205
+ being installed, run the `bundle config set without 'development test'` before
202
206
  `bundle install` command which is used to install gems on your production
203
207
  machines:
204
208
 
205
209
  ```
206
- $ bundle install --without development test
210
+ $ bundle config set without 'development test'
211
+ $ bundle install
207
212
  ```
208
213
 
209
214
  ## Commands
@@ -248,6 +253,7 @@ You can add these to your Gemfile for additional commands:
248
253
  * [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
249
254
  * [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
250
255
  * [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
256
+ * [spring-commands-standard](https://github.com/lakim/spring-commands-standard)
251
257
 
252
258
  ## Use without adding to bundle
253
259
 
@@ -370,7 +376,7 @@ application restart, you can specify them with `Spring.watch`:
370
376
  Spring.watch "config/some_config_file.yml"
371
377
  ```
372
378
 
373
- By default Spring polls the filesystem for changes once every 0.2 seconds. This
379
+ By default, Spring polls the filesystem for changes once every 0.2 seconds. This
374
380
  method requires zero configuration, but if you find that it's using too
375
381
  much CPU, then you can use event-based file system listening by
376
382
  installing the
@@ -386,30 +392,38 @@ a command runs:
386
392
  Spring.quiet = true
387
393
  ```
388
394
 
395
+ You can also set the initial state of the `quiet` configuration option to true
396
+ by setting the `SPRING_QUIET` environment variable before executing Spring.
397
+ This is useful if you want to set quiet mode when invoking the Spring executable
398
+ in a subprocess, and cannot or prefer not to set it programmatically
399
+ via the `Spring.quiet` option in `~/.spring.rb` or the app's `config/spring.rb`.
400
+
389
401
  ### Environment variables
390
402
 
391
403
  The following environment variables are used by Spring:
392
404
 
393
- * `DISABLE_SPRING` - If set, Spring will be bypassed and your
405
+ * `DISABLE_SPRING` - If set, Spring will be bypassed, and your
394
406
  application will boot in a foreground process
395
407
  * `SPRING_LOG` - The path to a file which Spring will write log messages
396
408
  to.
397
409
  * `SPRING_TMP_PATH` - The directory where Spring should write its temporary
398
- files (a pidfile and a socket). By default we use the
410
+ files (a pidfile and a socket). By default, we use the
399
411
  `XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
400
412
  create a directory in that named `spring-$UID`. We don't use your
401
413
  Rails application's `tmp/` directory because that may be on a
402
414
  filesystem which doesn't support UNIX sockets.
403
415
  * `SPRING_APPLICATION_ID` - Used to identify distinct Rails
404
- applications. By default it is an MD5 hash of the current
416
+ applications. By default, it is an MD5 hash of the current
405
417
  `RUBY_VERSION`, and the path to your Rails project root.
406
418
  * `SPRING_SOCKET` - The path which should be used for the UNIX socket
407
419
  which Spring uses to communicate with the long-running Spring server
408
- process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
420
+ process. By default, this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
409
421
  * `SPRING_PIDFILE` - The path which should be used to store the pid of
410
- the long-running Spring server process. By default this is related to
422
+ the long-running Spring server process. By default, this is related to
411
423
  the socket path; if the socket path is `/foo/bar/spring.sock` the
412
424
  pidfile will be `/foo/bar/spring.pid`.
425
+ * `SPRING_QUIET` - If set, the initial state of the `Spring.quiet`
426
+ configuration option will default to `true`.
413
427
  * `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
414
428
  server when it is not already running. Defaults to `spring _[version]_
415
429
  server --background`.
@@ -1,5 +1,4 @@
1
1
  require "spring/boot"
2
- require "set"
3
2
  require "pty"
4
3
 
5
4
  module Spring
@@ -11,7 +10,8 @@ module Spring
11
10
  @original_env = original_env
12
11
  @spring_env = spring_env
13
12
  @mutex = Mutex.new
14
- @waiting = Set.new
13
+ @waiting = {}
14
+ @clients = {}
15
15
  @preloaded = false
16
16
  @state = :initialized
17
17
  @interrupt = IO.pipe
@@ -91,8 +91,8 @@ module Spring
91
91
 
92
92
  require Spring.application_root_path.join("config", "application")
93
93
 
94
- unless Rails.respond_to?(:gem_version) && Rails.gem_version >= Gem::Version.new('5.2.0')
95
- raise "Spring only supports Rails >= 5.2.0"
94
+ unless Rails.respond_to?(:gem_version) && Rails.gem_version >= Gem::Version.new('6.0.0')
95
+ raise "Spring only supports Rails >= 6.0.0"
96
96
  end
97
97
 
98
98
  Rails::Application.initializer :ensure_reloading_is_enabled, group: :all do
@@ -115,7 +115,7 @@ module Spring
115
115
  raise e unless initialized?
116
116
  ensure
117
117
  watcher.add loaded_application_features
118
- watcher.add Spring.gemfile, "#{Spring.gemfile}.lock"
118
+ watcher.add Spring.gemfile, Spring.gemfile_lock
119
119
 
120
120
  if defined?(Rails) && Rails.application
121
121
  watcher.add Rails.application.paths["config/initializers"]
@@ -127,7 +127,12 @@ module Spring
127
127
  end
128
128
 
129
129
  def eager_preload
130
- with_pty { preload }
130
+ with_pty do
131
+ # we can't see stderr and there could be issues when it's overflown
132
+ # see https://github.com/rails/spring/issues/396
133
+ STDERR.reopen("/dev/null")
134
+ preload
135
+ end
131
136
  end
132
137
 
133
138
  def run
@@ -149,10 +154,23 @@ module Spring
149
154
  log "got client"
150
155
  manager.puts
151
156
 
157
+ @clients[client] = true
158
+
152
159
  _stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
153
160
  [STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
154
161
 
155
- preload unless preloaded?
162
+ if preloaded?
163
+ client.puts(0) # preload success
164
+ else
165
+ begin
166
+ preload
167
+ client.puts(0) # preload success
168
+ rescue Exception
169
+ log "preload failed"
170
+ client.puts(1) # preload failure
171
+ raise
172
+ end
173
+ end
156
174
 
157
175
  args, env = JSON.load(client.read(client.gets.to_i)).values_at("args", "env")
158
176
  command = Spring.command(args.shift)
@@ -165,6 +183,10 @@ module Spring
165
183
  end
166
184
 
167
185
  pid = fork {
186
+ # Make sure to close other clients otherwise their graceful termination
187
+ # will be impossible due to reference from this fork.
188
+ @clients.each_key { |c| c.close if c != client }
189
+
168
190
  Process.setsid
169
191
  IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
170
192
  trap("TERM", "DEFAULT")
@@ -227,7 +249,7 @@ module Spring
227
249
  if exiting?
228
250
  # Ensure that we do not ignore subsequent termination attempts
229
251
  log "forced exit"
230
- @waiting.each { |pid| Process.kill("TERM", pid) }
252
+ @waiting.each_key { |pid| Process.kill("TERM", pid) }
231
253
  Kernel.exit
232
254
  else
233
255
  state! :terminating
@@ -280,13 +302,26 @@ module Spring
280
302
  Kernel.module_eval do
281
303
  old_raise = Kernel.method(:raise)
282
304
  remove_method :raise
283
- define_method :raise do |*args|
284
- begin
285
- old_raise.call(*args)
286
- ensure
287
- if $!
288
- lib = File.expand_path("..", __FILE__)
289
- $!.backtrace.reject! { |line| line.start_with?(lib) }
305
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.2.0')
306
+ define_method :raise do |*args, **kwargs|
307
+ begin
308
+ old_raise.call(*args, **kwargs)
309
+ ensure
310
+ if $!
311
+ lib = File.expand_path("..", __FILE__)
312
+ $!.backtrace.reject! { |line| line.start_with?(lib) } unless $!.backtrace.frozen?
313
+ end
314
+ end
315
+ end
316
+ else
317
+ define_method :raise do |*args|
318
+ begin
319
+ old_raise.call(*args)
320
+ ensure
321
+ if $!
322
+ lib = File.expand_path("..", __FILE__)
323
+ $!.backtrace.reject! { |line| line.start_with?(lib) } unless $!.backtrace.frozen?
324
+ end
290
325
  end
291
326
  end
292
327
  end
@@ -319,7 +354,7 @@ module Spring
319
354
  end
320
355
 
321
356
  def wait(pid, streams, client)
322
- @mutex.synchronize { @waiting << pid }
357
+ @mutex.synchronize { @waiting[pid] = true }
323
358
 
324
359
  # Wait in a separate thread so we can run multiple commands at once
325
360
  Spring.failsafe_thread {
@@ -1,5 +1,3 @@
1
- require 'set'
2
-
3
1
  module Spring
4
2
  module Client
5
3
  class Binstub < Command
@@ -11,41 +9,36 @@ module Spring
11
9
  # client is not invoked for whatever reason, then the Kernel.exit won't
12
10
  # happen, and so we'll fall back to the lines after this block, which
13
11
  # should cause the "unsprung" version of the command to run.
14
- LOADER = <<CODE
15
- begin
16
- load File.expand_path('../spring', __FILE__)
17
- rescue LoadError => e
18
- raise unless e.message.include?('spring')
19
- end
20
- CODE
12
+ LOADER = <<~CODE
13
+ load File.expand_path("spring", __dir__)
14
+ CODE
21
15
 
22
16
  # The defined? check ensures these lines don't execute when we load the
23
17
  # binstub from the application process. Which means that in the application
24
18
  # process we'll execute the lines which come after the LOADER block, which
25
19
  # is what we want.
26
- SPRING = <<'CODE'
27
- #!/usr/bin/env ruby
28
-
29
- # This file loads Spring without using Bundler, in order to be fast.
30
- # It gets overwritten when you run the `spring binstub` command.
31
-
32
- unless defined?(Spring)
33
- require 'rubygems'
34
- require 'bundler'
35
-
36
- lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
37
- spring = lockfile.specs.detect { |spec| spec.name == 'spring' }
38
- if spring
39
- Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
40
- gem 'spring', spring.version
41
- require 'spring/binstub'
42
- end
43
- end
44
- CODE
20
+ SPRING = <<~CODE
21
+ #!/usr/bin/env ruby
22
+
23
+ # This file loads Spring without loading other gems in the Gemfile in order to be fast.
24
+ # It gets overwritten when you run the `spring binstub` command.
25
+
26
+ if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
27
+ require "bundler"
28
+
29
+ Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
30
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
31
+ gem "spring", spring.version
32
+ require "spring/binstub"
33
+ end
34
+ end
35
+ CODE
45
36
 
46
37
  OLD_BINSTUB = %{if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?}
47
38
 
48
39
  BINSTUB_VARIATIONS = Regexp.union [
40
+ %{load File.expand_path("spring", __dir__)\n},
41
+ %{begin\n load File.expand_path('../spring', __FILE__)\nrescue LoadError => e\n raise unless e.message.include?('spring')\nend\n},
49
42
  %{begin\n load File.expand_path('../spring', __FILE__)\nrescue LoadError\nend\n},
50
43
  %{begin\n spring_bin_path = File.expand_path('../spring', __FILE__)\n load spring_bin_path\nrescue LoadError => e\n raise unless e.message.end_with? spring_bin_path, 'spring/binstub'\nend\n},
51
44
  LOADER
@@ -146,7 +139,7 @@ CODE
146
139
  @mode = :add
147
140
  @items = args.drop(1)
148
141
  .map { |name| find_commands name }
149
- .inject(Set.new, :|)
142
+ .flatten.uniq
150
143
  .map { |command| Item.new(command) }
151
144
  end
152
145
 
@@ -1,9 +1,7 @@
1
- require "set"
2
-
3
1
  module Spring
4
2
  module Client
5
3
  class Rails < Command
6
- COMMANDS = Set.new %w(console runner generate destroy test)
4
+ COMMANDS = %w(console runner generate destroy test)
7
5
 
8
6
  ALIASES = {
9
7
  "c" => "console",
@@ -22,6 +20,8 @@ module Spring
22
20
 
23
21
  if COMMANDS.include?(command_name)
24
22
  Run.call(["rails_#{command_name}", *args.drop(2)])
23
+ elsif command_name&.start_with?("db:") && !command_name.start_with?("db:system")
24
+ Run.call(["rake", *args.drop(1)])
25
25
  else
26
26
  require "spring/configuration"
27
27
  ARGV.shift
@@ -142,12 +142,17 @@ module Spring
142
142
  end
143
143
 
144
144
  def run_command(client, application)
145
- log "sending command"
146
-
147
145
  application.send_io STDOUT
148
146
  application.send_io STDERR
149
147
  application.send_io STDIN
150
148
 
149
+ log "waiting for the application to be preloaded"
150
+ preload_status = application.gets
151
+ preload_status = preload_status.chomp if preload_status
152
+ log "app preload status: #{preload_status}"
153
+ exit 1 if preload_status == "1"
154
+
155
+ log "sending command"
151
156
  send_json application, "args" => args, "env" => ENV.to_hash
152
157
 
153
158
  pid = server.gets
@@ -28,9 +28,16 @@ module Spring
28
28
  config = File.expand_path("~/.spring.rb")
29
29
  require config if File.exist?(config)
30
30
 
31
- # If the config/spring.rb contains requires for commands from other gems,
32
- # then we need to be under bundler.
33
- require "bundler/setup"
31
+ # We force the TTY so bundler doesn't show a backtrace in case gems are missing.
32
+ old_env = ENV["BUNDLER_FORCE_TTY"]
33
+ ENV["BUNDLER_FORCE_TTY"] = "true"
34
+ begin
35
+ # If the config/spring.rb contains requires for commands from other gems,
36
+ # then we need to be under bundler.
37
+ require "bundler/setup"
38
+ ensure
39
+ ENV["BUNDLER_FORCE_TTY"] = old_env
40
+ end
34
41
 
35
42
  # Auto-require any Spring extensions which are in the Gemfile
36
43
  Gem::Specification.map(&:name).grep(/^spring-/).each do |command|
@@ -2,16 +2,28 @@ require "spring/errors"
2
2
 
3
3
  module Spring
4
4
  class << self
5
- attr_accessor :application_root, :quiet
5
+ attr_accessor :application_root
6
+ attr_writer :quiet
6
7
 
7
8
  def gemfile
9
+ require "bundler"
10
+
8
11
  if /\s1.9.[0-9]/ === Bundler.ruby_scope.gsub(/[\/\s]+/,'')
9
- ENV["BUNDLE_GEMFILE"] || "Gemfile"
12
+ Pathname.new(ENV["BUNDLE_GEMFILE"] || "Gemfile").expand_path
10
13
  else
11
14
  Bundler.default_gemfile
12
15
  end
13
16
  end
14
17
 
18
+ def gemfile_lock
19
+ case gemfile.to_s
20
+ when /\bgems\.rb\z/
21
+ gemfile.sub_ext('.locked')
22
+ else
23
+ gemfile.sub_ext('.lock')
24
+ end
25
+ end
26
+
15
27
  def after_fork_callbacks
16
28
  @after_fork_callbacks ||= []
17
29
  end
@@ -41,6 +53,10 @@ module Spring
41
53
  @project_root_path ||= find_project_root(Pathname.new(File.expand_path(Dir.pwd)))
42
54
  end
43
55
 
56
+ def quiet
57
+ @quiet || ENV.key?('SPRING_QUIET')
58
+ end
59
+
44
60
  private
45
61
 
46
62
  def find_project_root(current_dir)
data/lib/spring/env.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require "pathname"
2
- require "digest/md5"
3
2
 
4
3
  require "spring/version"
5
- require "spring/sid"
6
4
  require "spring/configuration"
7
5
 
8
6
  module Spring
@@ -42,6 +40,7 @@ module Spring
42
40
  end
43
41
 
44
42
  def application_id
43
+ require "digest/md5"
45
44
  ENV["SPRING_APPLICATION_ID"] || Digest::MD5.hexdigest(RUBY_VERSION + project_root.to_s)
46
45
  end
47
46
 
data/lib/spring/json.rb CHANGED
@@ -46,11 +46,9 @@ end
46
46
 
47
47
  # See https://github.com/kr/okjson for updates.
48
48
 
49
- require 'stringio'
50
-
51
49
  # Some parts adapted from
52
- # http://golang.org/src/pkg/json/decode.go and
53
- # http://golang.org/src/pkg/utf8/utf8.go
50
+ # https://golang.org/src/pkg/json/decode.go and
51
+ # https://golang.org/src/pkg/utf8/utf8.go
54
52
  module Spring
55
53
  module OkJson
56
54
  Upstream = '43'
@@ -468,19 +466,18 @@ private
468
466
 
469
467
 
470
468
  def strenc(s)
471
- t = StringIO.new
472
- t.putc(?")
469
+ t = '"'.b
473
470
  r = 0
474
471
 
475
472
  while r < s.length
476
473
  case s[r]
477
- when ?" then t.print('\\"')
478
- when ?\\ then t.print('\\\\')
479
- when ?\b then t.print('\\b')
480
- when ?\f then t.print('\\f')
481
- when ?\n then t.print('\\n')
482
- when ?\r then t.print('\\r')
483
- when ?\t then t.print('\\t')
474
+ when ?" then t << '\\"'
475
+ when ?\\ then t << '\\\\'
476
+ when ?\b then t << '\\b'
477
+ when ?\f then t << '\\f'
478
+ when ?\n then t << '\\n'
479
+ when ?\r then t << '\\r'
480
+ when ?\t then t << '\\t'
484
481
  else
485
482
  c = s[r]
486
483
  # In ruby >= 1.9, s[r] is a codepoint, not a byte.
@@ -490,14 +487,14 @@ private
490
487
  if c.ord < Spc.ord
491
488
  c = "\\u%04x" % [c.ord]
492
489
  end
493
- t.write(c)
490
+ t << c
494
491
  rescue
495
- t.write(Ustrerr)
492
+ t << Ustrerr
496
493
  end
497
494
  elsif c < Spc
498
- t.write("\\u%04x" % c)
495
+ t << "\\u%04x" % c
499
496
  elsif Spc <= c && c <= ?~
500
- t.putc(c)
497
+ t << c
501
498
  else
502
499
  n = ucharcopy(t, s, r) # ensure valid UTF-8 output
503
500
  r += n - 1 # r is incremented below
@@ -505,8 +502,8 @@ private
505
502
  end
506
503
  r += 1
507
504
  end
508
- t.putc(?")
509
- t.string
505
+ t << '"'
506
+ t
510
507
  end
511
508
 
512
509
 
@@ -531,7 +528,7 @@ private
531
528
 
532
529
  # 1-byte, 7-bit sequence?
533
530
  if c0 < Utagx
534
- t.putc(c0)
531
+ t << c0
535
532
  return 1
536
533
  end
537
534
 
@@ -544,8 +541,8 @@ private
544
541
  # 2-byte, 11-bit sequence?
545
542
  if c0 < Utag3
546
543
  raise Utf8Error if ((c0&Umask2)<<6 | (c1&Umaskx)) <= Uchar1max
547
- t.putc(c0)
548
- t.putc(c1)
544
+ t << c0
545
+ t << c1
549
546
  return 2
550
547
  end
551
548
 
@@ -559,9 +556,9 @@ private
559
556
  if c0 < Utag4
560
557
  u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
561
558
  raise Utf8Error if u <= Uchar2max
562
- t.putc(c0)
563
- t.putc(c1)
564
- t.putc(c2)
559
+ t << c0
560
+ t << c1
561
+ t << c2
565
562
  return 3
566
563
  end
567
564
 
@@ -574,16 +571,16 @@ private
574
571
  if c0 < Utag5
575
572
  u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
576
573
  raise Utf8Error if u <= Uchar3max
577
- t.putc(c0)
578
- t.putc(c1)
579
- t.putc(c2)
580
- t.putc(c3)
574
+ t << c0
575
+ t << c1
576
+ t << c2
577
+ t << c3
581
578
  return 4
582
579
  end
583
580
 
584
581
  raise Utf8Error
585
582
  rescue Utf8Error
586
- t.write(Ustrerr)
583
+ t << Ustrerr
587
584
  return 1
588
585
  end
589
586
 
data/lib/spring/server.rb CHANGED
@@ -81,7 +81,8 @@ module Spring
81
81
  # This will cause it to be automatically killed once the session
82
82
  # ends (i.e. when the user closes their terminal).
83
83
  def set_pgid
84
- Process.setpgid(0, SID.pgid)
84
+ pgid = Process.getpgid(Process.getsid)
85
+ Process.setpgid(0, pgid)
85
86
  end
86
87
 
87
88
  # Ignore SIGINT and SIGQUIT otherwise the user typing ^C or ^\ on the command line
@@ -1,3 +1,3 @@
1
1
  module Spring
2
- VERSION = "3.0.0"
2
+ VERSION = "4.1.3"
3
3
  end
@@ -1,6 +1,4 @@
1
- require "set"
2
1
  require "pathname"
3
- require "mutex_m"
4
2
 
5
3
  module Spring
6
4
  module Watcher
@@ -10,23 +8,25 @@ module Spring
10
8
  # IO.select([watcher]) # watcher is running in background
11
9
  # watcher.stale? # => true
12
10
  class Abstract
13
- include Mutex_m
14
-
15
11
  attr_reader :files, :directories, :root, :latency
16
12
 
17
13
  def initialize(root, latency)
18
- super()
19
-
14
+ @mutex = Mutex.new
20
15
  @root = File.realpath(root)
21
16
  @latency = latency
22
- @files = Set.new
23
- @directories = Set.new
17
+ @files = {}
18
+ @directories = {}
24
19
  @stale = false
25
20
  @listeners = []
26
21
 
27
22
  @on_debug = nil
28
23
  end
29
24
 
25
+ def synchronize(&block)
26
+ # Used by some gems.
27
+ @mutex.synchronize(&block)
28
+ end
29
+
30
30
  def on_debug(&block)
31
31
  @on_debug = block
32
32
  end
@@ -60,13 +60,13 @@ module Spring
60
60
  end
61
61
  end
62
62
 
63
- synchronize {
63
+ @mutex.synchronize do
64
64
  items.each do |item|
65
65
  if item.directory?
66
- directories << item.realpath.to_s
66
+ directories[item.realpath.to_s] = true
67
67
  else
68
68
  begin
69
- files << item.realpath.to_s
69
+ files[item.realpath.to_s] = true
70
70
  rescue Errno::ENOENT
71
71
  # Race condition. Ignore symlinks whose target was removed
72
72
  # since the check above, or are deeply chained.
@@ -76,7 +76,7 @@ module Spring
76
76
  end
77
77
 
78
78
  subjects_changed
79
- }
79
+ end
80
80
  end
81
81
 
82
82
  def stale?
@@ -12,7 +12,7 @@ module Spring
12
12
  end
13
13
 
14
14
  def check_stale
15
- synchronize do
15
+ @mutex.synchronize do
16
16
  computed = compute_mtime
17
17
  if mtime < computed
18
18
  debug { "check_stale: mtime=#{mtime.inspect} < computed=#{computed.inspect}" }
@@ -91,7 +91,7 @@ module Spring
91
91
  end
92
92
 
93
93
  def expanded_files
94
- files + Dir["{#{directories.map { |d| "#{d}/**/*" }.join(",")}}"]
94
+ (files.keys + Dir["{#{directories.keys.map { |d| "#{d}/**/*" }.join(",")}}"]).uniq
95
95
  end
96
96
  end
97
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2023-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -90,7 +90,6 @@ files:
90
90
  - lib/spring/json.rb
91
91
  - lib/spring/process_title_updater.rb
92
92
  - lib/spring/server.rb
93
- - lib/spring/sid.rb
94
93
  - lib/spring/version.rb
95
94
  - lib/spring/watcher.rb
96
95
  - lib/spring/watcher/abstract.rb
@@ -98,7 +97,8 @@ files:
98
97
  homepage: https://github.com/rails/spring
99
98
  licenses:
100
99
  - MIT
101
- metadata: {}
100
+ metadata:
101
+ rubygems_mfa_required: 'true'
102
102
  post_install_message:
103
103
  rdoc_options: []
104
104
  require_paths:
@@ -107,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 2.5.0
110
+ version: 2.7.0
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
113
  - - ">="
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
116
  requirements: []
117
- rubygems_version: 3.2.22
117
+ rubygems_version: 3.3.7
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Rails application preloader
data/lib/spring/sid.rb DELETED
@@ -1,42 +0,0 @@
1
- begin
2
- # If rubygems is present, keep it out of the way when loading fiddle,
3
- # otherwise if fiddle is not installed then rubygems will load all
4
- # gemspecs in its (futile) search for fiddle, which is slow.
5
- if respond_to?(:gem_original_require, true)
6
- gem_original_require 'fiddle'
7
- else
8
- require 'fiddle'
9
- end
10
- rescue LoadError
11
- end
12
-
13
- module Spring
14
- module SID
15
- def self.fiddle_func
16
- @fiddle_func ||= Fiddle::Function.new(
17
- DL::Handle::DEFAULT['getsid'],
18
- [Fiddle::TYPE_INT],
19
- Fiddle::TYPE_INT
20
- )
21
- end
22
-
23
- def self.sid
24
- @sid ||= begin
25
- if Process.respond_to?(:getsid)
26
- # Ruby 2
27
- Process.getsid
28
- elsif defined?(Fiddle) and defined?(DL)
29
- # Ruby 1.9.3 compiled with libffi support
30
- fiddle_func.call(0)
31
- else
32
- # last resort: shell out
33
- `ps -p #{Process.pid} -o sess=`.to_i
34
- end
35
- end
36
- end
37
-
38
- def self.pgid
39
- Process.getpgid(sid)
40
- end
41
- end
42
- end