spring 4.4.1 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c0e16193bfb18c7246f5d4fd0789f03134c2b013ae204578f2771b460fb2e86
4
- data.tar.gz: 84221a6cc9097b6c7762bbbab9ab1ed89e57c2783346807dc6c8fcc22d405bf1
3
+ metadata.gz: 56e90e978202520c21d08823b1c539949f413ea8694868caec30042ede704533
4
+ data.tar.gz: 34d0bf24260d460621ba8dfbb5be7f3750a3c3b0e4c20092878f38aa66aee1a4
5
5
  SHA512:
6
- metadata.gz: 8fbb8005a56cc2d9a24f33a0f2e5d7a3f318a5d99819402aa239f8dd13ef08f85d4409d5c2969a216bf91a46f8585b884122454c05f0dcc22068174fc72ff674
7
- data.tar.gz: 10eda5daa0ba53c15f30894df2c48942f06287e94e663a0d10972ba1f49e8aa29c6fcb52747c70ce5db98c6736d62c7f11d9d8731842fd089aeb60118ded4a31
6
+ metadata.gz: b367e099835ce1cca3769b616905ac31a3d2a3ae7271b93031ebeb5cb95711735db2f3bc952541e0609197f0dc98fe3c03b0df36210fa6645ae5ff28a83c90a6
7
+ data.tar.gz: 9c428924ba4c30c0cc5ee22e21da828b237ab686fee3d134519b16198127c3829288147b4eb056f3596c05efa46db2b7c3693f4e9a1a9c7bb362b7c020b34610
data/README.md CHANGED
@@ -334,7 +334,8 @@ server process is started, it can be used to add new top-level commands.
334
334
  Spring must know how to find your Rails application. If you have a
335
335
  normal app everything works out of the box. If you are working on a
336
336
  project with a special setup (an engine for example), you must tell
337
- Spring where your app is located:
337
+ Spring where your app is located by specifying the below code in a
338
+ `config/spring.rb` file relative to your engines root directory :
338
339
 
339
340
  ```ruby
340
341
  Spring.application_root = './test/dummy'
@@ -116,6 +116,9 @@ module Spring
116
116
 
117
117
  require Spring.application_root_path.join("config", "environment")
118
118
 
119
+ invoke_after_environment_load_callbacks
120
+ preload_framework_base_classes
121
+
119
122
  disconnect_database
120
123
 
121
124
  @preloaded = :success
@@ -142,6 +145,19 @@ module Spring
142
145
  end
143
146
  end
144
147
 
148
+ # Eagerly autoload framework base classes
149
+ FRAMEWORK_BASE_CLASSES = %w[
150
+ ActionMailer::Base
151
+ ActionController::Base
152
+ ActionController::API
153
+ ].freeze
154
+
155
+ def preload_framework_base_classes
156
+ FRAMEWORK_BASE_CLASSES.each do |const|
157
+ Object.const_get(const) if Object.const_defined?(const)
158
+ end
159
+ end
160
+
145
161
  def eager_preload
146
162
  with_pty do
147
163
  # we can't see stderr and there could be issues when it's overflown
@@ -183,7 +199,7 @@ module Spring
183
199
  client.puts(0) # preload success
184
200
  rescue Exception
185
201
  log "preload failed"
186
- client.puts(1) # preload failure
202
+ ignore_client_disconnect { client.puts(1) } # preload failure
187
203
  raise
188
204
  end
189
205
  end
@@ -244,15 +260,19 @@ module Spring
244
260
 
245
261
  wait pid, streams, client
246
262
  rescue Exception => e
247
- log "exception: #{e}"
263
+ if e.is_a?(Errno::EPIPE)
264
+ log "client disconnected (#{e.message}), ignoring command"
265
+ else
266
+ log "exception: #{e}"
267
+ end
248
268
  manager.puts unless pid
249
269
 
250
270
  if streams && !e.is_a?(SystemExit)
251
- print_exception(stderr, e)
252
- streams.each(&:close)
271
+ ignore_client_disconnect { print_exception(stderr, e) }
272
+ streams.each { |stream| ignore_client_disconnect { stream.close } }
253
273
  end
254
274
 
255
- client.puts(1) if pid
275
+ ignore_client_disconnect { client.puts(1) if pid }
256
276
  client.close
257
277
  ensure
258
278
  # Redirect STDOUT and STDERR to prevent from keeping the original FDs
@@ -300,6 +320,12 @@ module Spring
300
320
  end
301
321
  end
302
322
 
323
+ def invoke_after_environment_load_callbacks
324
+ Spring.after_environment_load_callbacks.each do |callback|
325
+ callback.call
326
+ end
327
+ end
328
+
303
329
  def loaded_application_features
304
330
  root = Spring.application_root_path.to_s
305
331
  $LOADED_FEATURES.select { |f| f.start_with?(root) }
@@ -403,6 +429,15 @@ module Spring
403
429
 
404
430
  private
405
431
 
432
+ # Tolerate Errno::EPIPE on writes to the client socket. Once the client
433
+ # disconnects, every subsequent write to it raises — that's expected
434
+ # during `serve`'s status reporting; we'd be talking to a process
435
+ # that's gone.
436
+ def ignore_client_disconnect
437
+ yield
438
+ rescue Errno::EPIPE
439
+ end
440
+
406
441
  def active_record_configured?
407
442
  defined?(ActiveRecord::Base) && ActiveRecord::Base.configurations.any?
408
443
  end
@@ -102,7 +102,7 @@ module Spring
102
102
  "RACK_ENV" => app_env,
103
103
  "SPRING_ORIGINAL_ENV" => JSON.dump(Spring::ORIGINAL_ENV),
104
104
  "SPRING_PRELOAD" => preload ? "1" : "0",
105
- "SPRING_SPAWN_ENV" => JSON.dump(spawn_env),
105
+ "SPRING_SPAWN_ENV" => JSON.dump(spawn_env.compact),
106
106
  **spawn_env,
107
107
  },
108
108
  "ruby",
@@ -26,7 +26,7 @@ module Spring
26
26
  if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
27
27
  require "bundler"
28
28
 
29
- Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
29
+ Bundler.definition.requested_specs.find { |spec| spec.name == "spring" }&.tap do |spring|
30
30
  Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
31
31
  gem "spring", spring.version
32
32
  require "spring/binstub"
@@ -254,7 +254,9 @@ module Spring
254
254
  end
255
255
 
256
256
  def spawn_env
257
- ENV.slice(*Spring.spawn_on_env)
257
+ Spring.spawn_on_env.to_h do |key|
258
+ [key, ENV[key]]
259
+ end
258
260
  end
259
261
  end
260
262
  end
@@ -35,6 +35,14 @@ module Spring
35
35
  after_fork_callbacks << block
36
36
  end
37
37
 
38
+ def after_environment_load_callbacks
39
+ @after_environment_load_callbacks ||= []
40
+ end
41
+
42
+ def after_environment_load(&block)
43
+ after_environment_load_callbacks << block
44
+ end
45
+
38
46
  def spawn_on_env
39
47
  @spawn_on_env ||= []
40
48
  end
data/lib/spring/server.rb CHANGED
@@ -74,6 +74,8 @@ module Spring
74
74
  end
75
75
  rescue SocketError => e
76
76
  raise e unless client.eof?
77
+ rescue Errno::EPIPE => e
78
+ log "client disconnected with error #{e.message}, ignoring command"
77
79
  ensure
78
80
  redirect_output
79
81
  end
@@ -1,3 +1,3 @@
1
1
  module Spring
2
- VERSION = "4.4.1"
2
+ VERSION = "4.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spring
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.1
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 4.0.3
74
+ rubygems_version: 3.6.7
75
75
  specification_version: 4
76
76
  summary: Rails application preloader
77
77
  test_files: []