spring 2.1.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -0
- data/README.md +33 -22
- data/lib/spring/application.rb +30 -34
- data/lib/spring/client/rails.rb +2 -0
- data/lib/spring/client/run.rb +7 -2
- data/lib/spring/configuration.rb +12 -1
- data/lib/spring/env.rb +2 -3
- data/lib/spring/json.rb +2 -2
- data/lib/spring/server.rb +2 -1
- data/lib/spring/version.rb +1 -1
- metadata +4 -5
- data/lib/spring/sid.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b47e67e59d8908152f467132052eca96c6b9e7df23e60f8a2c7a55f5861e954
|
4
|
+
data.tar.gz: 378c8a4a9dd44c41b7d77145f28f6010d3175fafdeec5e7ce049d0ec2e8babda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4d529c07b78b42af5783adcc43a9a0195e81d6a061ce6409598bb6316b64660c38e74c959773a81152390913cf25b982f8b5c5bafa674da9d6394bb29fd8490
|
7
|
+
data.tar.gz: bf4009a207501a0ce88b0f1ce4983c9eb035461f41f31e329a4cd842b63efec2f2f6adc3ff25fa23e5b46e8296a2e245ddebda51fed3237eb3758cbe3e73d463
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Spring
|
2
2
|
|
3
|
-
[![Build Status](https://
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/spring.svg)](
|
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,8 +16,8 @@ boot it every time you run a test, rake task or migration.
|
|
16
16
|
|
17
17
|
## Compatibility
|
18
18
|
|
19
|
-
* Ruby versions: MRI 2.
|
20
|
-
* Rails versions:
|
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
21
|
`rails new` to generate your application)
|
22
22
|
|
23
23
|
Spring makes extensive use of `Process.fork`, so won't be able to
|
@@ -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
|
@@ -65,6 +66,16 @@ automatically add `./bin` to your `PATH` when you `cd` into your application.
|
|
65
66
|
Simply create an `.envrc` file with the command `PATH_add bin` in your
|
66
67
|
Rails directory.
|
67
68
|
|
69
|
+
### Enable reloading
|
70
|
+
|
71
|
+
Spring reloads application code, and therefore needs the application to have
|
72
|
+
reloading enabled.
|
73
|
+
|
74
|
+
Please, make sure `config.cache_classes` is `false` in the environments that
|
75
|
+
Spring manages. That setting is typically configured in
|
76
|
+
`config/environments/*.rb`. In particular, make sure it is `false` for the
|
77
|
+
`test` environment.
|
78
|
+
|
68
79
|
### Usage
|
69
80
|
|
70
81
|
For this walkthrough I've generated a new Rails application, and run
|
@@ -168,7 +179,7 @@ Spring is running:
|
|
168
179
|
```
|
169
180
|
|
170
181
|
There's no need to "shut down" Spring. This will happen automatically
|
171
|
-
when you close your terminal. However if you do want to do a manual shut
|
182
|
+
when you close your terminal. However, if you do want to do a manual shut
|
172
183
|
down, use the `stop` command:
|
173
184
|
|
174
185
|
```
|
@@ -188,12 +199,13 @@ To remove Spring:
|
|
188
199
|
### Deployment
|
189
200
|
|
190
201
|
You must not install Spring on your production environment. To prevent it from
|
191
|
-
being installed,
|
202
|
+
being installed, run the `bundle config set without 'development test'` before
|
192
203
|
`bundle install` command which is used to install gems on your production
|
193
204
|
machines:
|
194
205
|
|
195
206
|
```
|
196
|
-
$ bundle
|
207
|
+
$ bundle config set without 'development test'
|
208
|
+
$ bundle install
|
197
209
|
```
|
198
210
|
|
199
211
|
## Commands
|
@@ -238,6 +250,7 @@ You can add these to your Gemfile for additional commands:
|
|
238
250
|
* [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
|
239
251
|
* [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
|
240
252
|
* [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
|
253
|
+
* [spring-commands-standard](https://github.com/lakim/spring-commands-standard)
|
241
254
|
|
242
255
|
## Use without adding to bundle
|
243
256
|
|
@@ -257,12 +270,10 @@ run through Spring, set the `DISABLE_SPRING` environment variable.
|
|
257
270
|
|
258
271
|
## Class reloading
|
259
272
|
|
260
|
-
Spring uses Rails' class reloading mechanism
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
have used this mechanism with your `test` environment before, and this
|
265
|
-
can cause problems.
|
273
|
+
Spring uses Rails' class reloading mechanism to keep your code up to date
|
274
|
+
between test runs. This is the same mechanism which allows you to see changes
|
275
|
+
during development when you refresh the page. However, you may never have used
|
276
|
+
this mechanism with your `test` environment before, and this can cause problems.
|
266
277
|
|
267
278
|
It's important to realise that code reloading means that the constants
|
268
279
|
in your application are *different objects* after files have changed:
|
@@ -362,7 +373,7 @@ application restart, you can specify them with `Spring.watch`:
|
|
362
373
|
Spring.watch "config/some_config_file.yml"
|
363
374
|
```
|
364
375
|
|
365
|
-
By default Spring polls the filesystem for changes once every 0.2 seconds. This
|
376
|
+
By default, Spring polls the filesystem for changes once every 0.2 seconds. This
|
366
377
|
method requires zero configuration, but if you find that it's using too
|
367
378
|
much CPU, then you can use event-based file system listening by
|
368
379
|
installing the
|
@@ -382,24 +393,24 @@ Spring.quiet = true
|
|
382
393
|
|
383
394
|
The following environment variables are used by Spring:
|
384
395
|
|
385
|
-
* `DISABLE_SPRING` - If set, Spring will be bypassed and your
|
396
|
+
* `DISABLE_SPRING` - If set, Spring will be bypassed, and your
|
386
397
|
application will boot in a foreground process
|
387
398
|
* `SPRING_LOG` - The path to a file which Spring will write log messages
|
388
399
|
to.
|
389
400
|
* `SPRING_TMP_PATH` - The directory where Spring should write its temporary
|
390
|
-
files (a pidfile and a socket). By default we use the
|
401
|
+
files (a pidfile and a socket). By default, we use the
|
391
402
|
`XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
|
392
403
|
create a directory in that named `spring-$UID`. We don't use your
|
393
404
|
Rails application's `tmp/` directory because that may be on a
|
394
405
|
filesystem which doesn't support UNIX sockets.
|
395
406
|
* `SPRING_APPLICATION_ID` - Used to identify distinct Rails
|
396
|
-
applications. By default it is an MD5 hash of the current
|
407
|
+
applications. By default, it is an MD5 hash of the current
|
397
408
|
`RUBY_VERSION`, and the path to your Rails project root.
|
398
409
|
* `SPRING_SOCKET` - The path which should be used for the UNIX socket
|
399
410
|
which Spring uses to communicate with the long-running Spring server
|
400
|
-
process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
|
411
|
+
process. By default, this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
|
401
412
|
* `SPRING_PIDFILE` - The path which should be used to store the pid of
|
402
|
-
the long-running Spring server process. By default this is related to
|
413
|
+
the long-running Spring server process. By default, this is related to
|
403
414
|
the socket path; if the socket path is `/foo/bar/spring.sock` the
|
404
415
|
pidfile will be `/foo/bar/spring.pid`.
|
405
416
|
* `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
|
data/lib/spring/application.rb
CHANGED
@@ -12,6 +12,7 @@ module Spring
|
|
12
12
|
@spring_env = spring_env
|
13
13
|
@mutex = Mutex.new
|
14
14
|
@waiting = Set.new
|
15
|
+
@clients = Set.new
|
15
16
|
@preloaded = false
|
16
17
|
@state = :initialized
|
17
18
|
@interrupt = IO.pipe
|
@@ -91,23 +92,21 @@ module Spring
|
|
91
92
|
|
92
93
|
require Spring.application_root_path.join("config", "application")
|
93
94
|
|
94
|
-
unless Rails.respond_to?(:gem_version) && Rails.gem_version >= Gem::Version.new('
|
95
|
-
raise "Spring only supports Rails >=
|
95
|
+
unless Rails.respond_to?(:gem_version) && Rails.gem_version >= Gem::Version.new('5.2.0')
|
96
|
+
raise "Spring only supports Rails >= 5.2.0"
|
96
97
|
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
99
|
+
Rails::Application.initializer :ensure_reloading_is_enabled, group: :all do
|
100
|
+
if Rails.application.config.cache_classes
|
101
|
+
raise <<-MSG.strip_heredoc
|
102
|
+
Spring reloads, and therefore needs the application to have reloading enabled.
|
103
|
+
Please, set config.cache_classes to false in config/environments/#{Rails.env}.rb.
|
104
|
+
MSG
|
105
|
+
end
|
104
106
|
end
|
105
107
|
|
106
108
|
require Spring.application_root_path.join("config", "environment")
|
107
109
|
|
108
|
-
@original_cache_classes = Rails.application.config.cache_classes
|
109
|
-
Rails.application.config.cache_classes = false
|
110
|
-
|
111
110
|
disconnect_database
|
112
111
|
|
113
112
|
@preloaded = :success
|
@@ -117,7 +116,7 @@ module Spring
|
|
117
116
|
raise e unless initialized?
|
118
117
|
ensure
|
119
118
|
watcher.add loaded_application_features
|
120
|
-
watcher.add Spring.gemfile,
|
119
|
+
watcher.add Spring.gemfile, Spring.gemfile_lock
|
121
120
|
|
122
121
|
if defined?(Rails) && Rails.application
|
123
122
|
watcher.add Rails.application.paths["config/initializers"]
|
@@ -151,10 +150,23 @@ module Spring
|
|
151
150
|
log "got client"
|
152
151
|
manager.puts
|
153
152
|
|
153
|
+
@clients << client
|
154
|
+
|
154
155
|
_stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
|
155
156
|
[STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
|
156
157
|
|
157
|
-
|
158
|
+
if preloaded?
|
159
|
+
client.puts(0) # preload success
|
160
|
+
else
|
161
|
+
begin
|
162
|
+
preload
|
163
|
+
client.puts(0) # preload success
|
164
|
+
rescue Exception
|
165
|
+
log "preload failed"
|
166
|
+
client.puts(1) # preload failure
|
167
|
+
raise
|
168
|
+
end
|
169
|
+
end
|
158
170
|
|
159
171
|
args, env = JSON.load(client.read(client.gets.to_i)).values_at("args", "env")
|
160
172
|
command = Spring.command(args.shift)
|
@@ -163,21 +175,14 @@ module Spring
|
|
163
175
|
setup command
|
164
176
|
|
165
177
|
if Rails.application.reloaders.any?(&:updated?)
|
166
|
-
|
167
|
-
if defined? ActiveSupport::Reloader
|
168
|
-
Rails.application.reloader.reload!
|
169
|
-
else
|
170
|
-
ActionDispatch::Reloader.cleanup!
|
171
|
-
ActionDispatch::Reloader.prepare!
|
172
|
-
end
|
178
|
+
Rails.application.reloader.reload!
|
173
179
|
end
|
174
180
|
|
175
|
-
# Ensure we boot the process in the directory the command was called from,
|
176
|
-
# not from the directory Spring started in
|
177
|
-
original_dir = Dir.pwd
|
178
|
-
Dir.chdir(env['PWD'] || original_dir)
|
179
|
-
|
180
181
|
pid = fork {
|
182
|
+
# Make sure to close other clients otherwise their graceful termination
|
183
|
+
# will be impossible due to reference from this fork.
|
184
|
+
@clients.select { |c| c != client }.each(&:close)
|
185
|
+
|
181
186
|
Process.setsid
|
182
187
|
IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
|
183
188
|
trap("TERM", "DEFAULT")
|
@@ -203,14 +208,6 @@ module Spring
|
|
203
208
|
# Load in the current env vars, except those which *were* changed when Spring started
|
204
209
|
env.each { |k, v| ENV[k] ||= v }
|
205
210
|
|
206
|
-
# requiring is faster, so if config.cache_classes was true in
|
207
|
-
# the environment's config file, then we can respect that from
|
208
|
-
# here on as we no longer need constant reloading.
|
209
|
-
if @original_cache_classes
|
210
|
-
ActiveSupport::Dependencies.mechanism = :require
|
211
|
-
Rails.application.config.cache_classes = true
|
212
|
-
end
|
213
|
-
|
214
211
|
connect_database
|
215
212
|
srand
|
216
213
|
|
@@ -242,7 +239,6 @@ module Spring
|
|
242
239
|
# (i.e. to prevent `spring rake -T | grep db` from hanging forever),
|
243
240
|
# even when exception is raised before forking (i.e. preloading).
|
244
241
|
reset_streams
|
245
|
-
Dir.chdir(original_dir)
|
246
242
|
end
|
247
243
|
|
248
244
|
def terminate
|
data/lib/spring/client/rails.rb
CHANGED
data/lib/spring/client/run.rb
CHANGED
@@ -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
|
data/lib/spring/configuration.rb
CHANGED
@@ -5,13 +5,24 @@ module Spring
|
|
5
5
|
attr_accessor :application_root, :quiet
|
6
6
|
|
7
7
|
def gemfile
|
8
|
+
require "bundler"
|
9
|
+
|
8
10
|
if /\s1.9.[0-9]/ === Bundler.ruby_scope.gsub(/[\/\s]+/,'')
|
9
|
-
ENV["BUNDLE_GEMFILE"] || "Gemfile"
|
11
|
+
Pathname.new(ENV["BUNDLE_GEMFILE"] || "Gemfile").expand_path
|
10
12
|
else
|
11
13
|
Bundler.default_gemfile
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
17
|
+
def gemfile_lock
|
18
|
+
case gemfile.to_s
|
19
|
+
when /\bgems\.rb\z/
|
20
|
+
gemfile.sub_ext('.locked')
|
21
|
+
else
|
22
|
+
gemfile.sub_ext('.lock')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
def after_fork_callbacks
|
16
27
|
@after_fork_callbacks ||= []
|
17
28
|
end
|
data/lib/spring/env.rb
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
require "pathname"
|
2
|
-
require "fileutils"
|
3
2
|
require "digest/md5"
|
4
|
-
require "tmpdir"
|
5
3
|
|
6
4
|
require "spring/version"
|
7
|
-
require "spring/sid"
|
8
5
|
require "spring/configuration"
|
9
6
|
|
10
7
|
module Spring
|
@@ -33,10 +30,12 @@ module Spring
|
|
33
30
|
end
|
34
31
|
|
35
32
|
def tmp_path
|
33
|
+
require "tmpdir"
|
36
34
|
path = Pathname.new(
|
37
35
|
ENV["SPRING_TMP_PATH"] ||
|
38
36
|
File.join(ENV['XDG_RUNTIME_DIR'] || Dir.tmpdir, "spring-#{Process.uid}")
|
39
37
|
)
|
38
|
+
require "fileutils"
|
40
39
|
FileUtils.mkdir_p(path) unless path.exist?
|
41
40
|
path
|
42
41
|
end
|
data/lib/spring/json.rb
CHANGED
@@ -49,8 +49,8 @@ end
|
|
49
49
|
require 'stringio'
|
50
50
|
|
51
51
|
# Some parts adapted from
|
52
|
-
#
|
53
|
-
#
|
52
|
+
# https://golang.org/src/pkg/json/decode.go and
|
53
|
+
# https://golang.org/src/pkg/utf8/utf8.go
|
54
54
|
module Spring
|
55
55
|
module OkJson
|
56
56
|
Upstream = '43'
|
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.
|
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
|
data/lib/spring/version.rb
CHANGED
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:
|
4
|
+
version: 3.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:
|
11
|
+
date: 2021-11-23 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
|
@@ -107,14 +106,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
106
|
requirements:
|
108
107
|
- - ">="
|
109
108
|
- !ruby/object:Gem::Version
|
110
|
-
version: 2.
|
109
|
+
version: 2.5.0
|
111
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
111
|
requirements:
|
113
112
|
- - ">="
|
114
113
|
- !ruby/object:Gem::Version
|
115
114
|
version: '0'
|
116
115
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
116
|
+
rubygems_version: 3.2.22
|
118
117
|
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
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
|