spring 1.2.0 → 4.7.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.
Files changed (53) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +3 -2
  3. data/README.md +148 -42
  4. data/bin/spring +2 -1
  5. data/lib/spring/application/boot.rb +11 -4
  6. data/lib/spring/application.rb +178 -50
  7. data/lib/spring/application_manager.rb +17 -9
  8. data/lib/spring/boot.rb +2 -0
  9. data/lib/spring/client/binstub.rb +44 -45
  10. data/lib/spring/client/help.rb +1 -1
  11. data/lib/spring/client/rails.rb +6 -5
  12. data/lib/spring/client/run.rb +187 -41
  13. data/lib/spring/client/server.rb +18 -0
  14. data/lib/spring/client/status.rb +2 -2
  15. data/lib/spring/client/stop.rb +7 -22
  16. data/lib/spring/client.rb +11 -1
  17. data/lib/spring/command_wrapper.rb +0 -4
  18. data/lib/spring/commands/rails.rb +21 -0
  19. data/lib/spring/commands.rb +11 -4
  20. data/lib/spring/configuration.rb +49 -2
  21. data/lib/spring/env.rb +43 -12
  22. data/lib/spring/errors.rb +1 -1
  23. data/lib/spring/failsafe_thread.rb +14 -0
  24. data/lib/spring/json.rb +30 -33
  25. data/lib/spring/process_title_updater.rb +2 -2
  26. data/lib/spring/server.rb +45 -13
  27. data/lib/spring/version.rb +1 -1
  28. data/lib/spring/watcher/abstract.rb +44 -13
  29. data/lib/spring/watcher/polling.rb +48 -11
  30. data/lib/spring/watcher.rb +1 -1
  31. metadata +14 -71
  32. data/.gitignore +0 -19
  33. data/.travis.yml +0 -11
  34. data/CHANGELOG.md +0 -188
  35. data/CONTRIBUTING.md +0 -52
  36. data/Gemfile +0 -4
  37. data/Rakefile +0 -21
  38. data/lib/spring/sid.rb +0 -42
  39. data/lib/spring/test/acceptance_test.rb +0 -333
  40. data/lib/spring/test/application.rb +0 -217
  41. data/lib/spring/test/application_generator.rb +0 -121
  42. data/lib/spring/test/rails_version.rb +0 -40
  43. data/lib/spring/test/watcher_test.rb +0 -167
  44. data/lib/spring/test.rb +0 -15
  45. data/spring.gemspec +0 -23
  46. data/test/acceptance_test.rb +0 -4
  47. data/test/apps/.gitignore +0 -3
  48. data/test/helper.rb +0 -7
  49. data/test/unit/client/help_test.rb +0 -60
  50. data/test/unit/client/version_test.rb +0 -14
  51. data/test/unit/commands_test.rb +0 -59
  52. data/test/unit/process_title_updater_test.rb +0 -24
  53. data/test/unit/watcher_test.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0bae3c5f77134086e25e77df5d700895438e16ba
4
- data.tar.gz: 882c5139fed3fe573bb75136e683ca8ee3744069
2
+ SHA256:
3
+ metadata.gz: a37d78748e084596d151cde2918d30799c8dfe9e10e029920ece9e9eee8118ad
4
+ data.tar.gz: c47e0897d3938b7350245854672812436505379cc498638c3eca9e2d52537fe6
5
5
  SHA512:
6
- metadata.gz: c5d7a1655a09f56c5663024af741c3c58fe9542418603a59dddb0c19ee24203a1527911a4626f6a5eedd5daf5b6e19b1107582fdc2c7528563af1878034cf1a7
7
- data.tar.gz: d143cad1d9b6f15440d80aa300b566a4fa19c0c90deada7fa627e3b230f9199ed56eae911c0005fa2ff83814bf3e66190777a42e0bb4cf5ee6d997df9d06b297
6
+ metadata.gz: cda176e1dd4d22cabb680cb85c4fd562c256f8fb3dc04f9064fc61f910cfb384f044f63bee74a424501505b62f80e0746f6c05bddf327c6be0150f12cc678a3f
7
+ data.tar.gz: e8b1675241b3fc42c52eabb9e2f501d4abae16c35ae3e3d19080de332f3d28b258b7245c127264326871f09c35c333a3b71fcfb8fbbfecdc87648a72e1328c14
data/LICENSE.txt CHANGED
@@ -1,4 +1,5 @@
1
- Copyright (c) 2012 Jon Leighton
1
+ Copyright (c) 2017-2021 Rafael Mendonça França
2
+ Copyright (c) 2012-2017 Jon Leighton
2
3
 
3
4
  MIT License
4
5
 
@@ -19,4 +20,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
20
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
21
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
22
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Spring
2
2
 
3
- [![Build Status](https://travis-ci.org/rails/spring.png?branch=master)](https://travis-ci.org/rails/spring)
4
- [![Gem Version](https://badge.fury.io/rb/spring.png)](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,8 +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 1.9.3, MRI 2.0, MRI 2.1
20
- * Rails versions: 3.2, 4.0 (in Rails 4.1 and up Spring is included by default)
19
+ * Ruby versions: MRI 3.1+
20
+ * Rails versions: 7.1+
21
+ * Bundler v2.1+
21
22
 
22
23
  Spring makes extensive use of `Process.fork`, so won't be able to
23
24
  provide a speed up on platforms which don't support forking (Windows, JRuby).
@@ -26,14 +27,14 @@ provide a speed up on platforms which don't support forking (Windows, JRuby).
26
27
 
27
28
  ### Setup
28
29
 
29
- Add spring to your Gemfile:
30
+ Add Spring to your Gemfile:
30
31
 
31
32
  ``` ruby
32
33
  gem "spring", group: :development
33
34
  ```
34
35
 
35
36
  (Note: using `gem "spring", git: "..."` *won't* work and is not a
36
- supported way of using spring.)
37
+ supported way of using Spring.)
37
38
 
38
39
  It's recommended to 'springify' the executables in your `bin/`
39
40
  directory:
@@ -48,31 +49,71 @@ code into relevant existing executables. The snippet looks like this:
48
49
 
49
50
  ``` ruby
50
51
  begin
51
- load File.expand_path("../spring", __FILE__)
52
- rescue LoadError
52
+ load File.expand_path('../spring', __FILE__)
53
+ rescue LoadError => e
54
+ raise unless e.message.include?('spring')
53
55
  end
54
56
  ```
55
57
 
56
- On platforms where spring is installed and supported, this snippet
57
- hooks spring into the execution of commands. In other cases, the snippet
58
- will just be silently ignored and the lines after it will be executed as
58
+ On platforms where Spring is installed and supported, this snippet
59
+ hooks Spring into the execution of commands. In other cases, the snippet
60
+ will just be silently ignored, and the lines after it will be executed as
59
61
  normal.
60
62
 
61
63
  If you don't want to prefix every command you type with `bin/`, you
62
- can [use direnv](https://github.com/zimbatm/direnv#the-stdlib) to
64
+ can [use direnv](https://github.com/direnv/direnv#the-stdlib) to
63
65
  automatically add `./bin` to your `PATH` when you `cd` into your application.
64
66
  Simply create an `.envrc` file with the command `PATH_add bin` in your
65
67
  Rails directory.
66
68
 
69
+ ### Enable reloading
70
+
71
+ Spring reloads application code, and therefore needs the application to have
72
+ reloading enabled.
73
+
74
+ Ensure that `config.enable_reloading` is `true` in the environments that
75
+ Spring manages. That setting is typically configured in
76
+ `config/environments/*.rb`. In particular, make sure it is `true` for the
77
+ `test` environment.
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
+
82
+ #### Running Spring with reloading disabled (advanced, risky)
83
+
84
+ If you know what you are doing, and if every reloadable resource is configured
85
+ to materialize *lazily in the forked child*, not in the Spring server process,
86
+ then you can decide to run Spring without Rail's in-process reloaders.
87
+
88
+ To opt into this, set in `config/spring.rb`:
89
+
90
+ ```ruby
91
+ Spring.dangerously_allow_disabling_reloading = true
92
+ ```
93
+
94
+ If you set this, you should make sure that you are NOT pre-loading reloadable
95
+ resource in the Spring server. One approach is to add boot-time assertions at
96
+ the end of `Spring.after_environment_load`, e.g.:
97
+
98
+ ```ruby
99
+ Spring.after_environment_load do
100
+ raise "routes were drawn at boot" if Rails.application.routes_reloader.loaded
101
+ raise "i18n locales where loaded at boot" unless I18n.backend.instance_variable_get(:@translations).nil?
102
+ end
103
+ ```
104
+
105
+ When unsure, leave this disabled.
106
+
67
107
  ### Usage
68
108
 
69
109
  For this walkthrough I've generated a new Rails application, and run
70
- `rails generate scaffold posts name:string`.
110
+ `rails generate scaffold post name:string`.
71
111
 
72
112
  Let's run a test:
73
113
 
74
114
  ```
75
- $ time bin/rake test test/functional/posts_controller_test.rb
115
+ $ time bin/rake test test/controllers/posts_controller_test.rb
116
+ Running via Spring preloader in process 2734
76
117
  Run options:
77
118
 
78
119
  # Running tests:
@@ -88,7 +129,7 @@ user 0m0.281s
88
129
  sys 0m0.066s
89
130
  ```
90
131
 
91
- That wasn't particularly fast because it was the first run, so spring
132
+ That wasn't particularly fast because it was the first run, so Spring
92
133
  had to boot the application. It's now running:
93
134
 
94
135
  ```
@@ -102,7 +143,8 @@ Spring is running:
102
143
  The next run is faster:
103
144
 
104
145
  ```
105
- $ time bin/rake test test/functional/posts_controller_test.rb
146
+ $ time bin/rake test test/controllers/posts_controller_test.rb
147
+ Running via Spring preloader in process 8352
106
148
  Run options:
107
149
 
108
150
  # Running tests:
@@ -147,6 +189,7 @@ environment gets booted up:
147
189
 
148
190
  ```
149
191
  $ bin/rake routes
192
+ Running via Spring preloader in process 2363
150
193
  posts GET /posts(.:format) posts#index
151
194
  POST /posts(.:format) posts#create
152
195
  new_post GET /posts/new(.:format) posts#new
@@ -163,8 +206,8 @@ Spring is running:
163
206
  26707 spring app | spring-demo-app | started 2 secs ago | development mode
164
207
  ```
165
208
 
166
- There's no need to "shut down" spring. This will happen automatically
167
- when you close your terminal. However if you do want to do a manual shut
209
+ There's no need to "shut down" Spring. This will happen automatically
210
+ when you close your terminal. However, if you do want to do a manual shut
168
211
  down, use the `stop` command:
169
212
 
170
213
  ```
@@ -172,9 +215,11 @@ $ bin/spring stop
172
215
  Spring stopped.
173
216
  ```
174
217
 
218
+ From within your code, you can check whether Spring is active with `if defined?(Spring)`.
219
+
175
220
  ### Removal
176
221
 
177
- To remove spring:
222
+ To remove Spring:
178
223
 
179
224
  * 'Unspring' your bin/ executables: `bin/spring binstub --remove --all`
180
225
  * Remove spring from your Gemfile
@@ -182,12 +227,13 @@ To remove spring:
182
227
  ### Deployment
183
228
 
184
229
  You must not install Spring on your production environment. To prevent it from
185
- being installed, provide the `--without development test` argument to the
230
+ being installed, run the `bundle config set without 'development test'` before
186
231
  `bundle install` command which is used to install gems on your production
187
232
  machines:
188
233
 
189
234
  ```
190
- $ bundle install --without development test
235
+ $ bundle config set without 'development test'
236
+ $ bundle install
191
237
  ```
192
238
 
193
239
  ## Commands
@@ -212,14 +258,13 @@ Spring::Commands::Rake.environment_matchers[:default] = "development"
212
258
  ### `rails console`, `rails generate`, `rails runner`
213
259
 
214
260
  These execute the rails command you already know and love. If you run
215
- a different sub command (e.g. `rails server`) then spring will automatically
261
+ a different sub command (e.g. `rails server`) then Spring will automatically
216
262
  pass it through to the underlying `rails` executable (without the
217
263
  speed-up).
218
264
 
219
265
  ### Additional commands
220
266
 
221
- You can add these to your Gemfile for additional commands (run `spring stop` afterwards
222
- to pick up the changes):
267
+ You can add these to your Gemfile for additional commands:
223
268
 
224
269
  * [spring-commands-rspec](https://github.com/jonleighton/spring-commands-rspec)
225
270
  * [spring-commands-cucumber](https://github.com/jonleighton/spring-commands-cucumber)
@@ -227,16 +272,22 @@ to pick up the changes):
227
272
  * [spring-commands-testunit](https://github.com/jonleighton/spring-commands-testunit) - useful for
228
273
  running `Test::Unit` tests on Rails 3, since only Rails 4 allows you
229
274
  to use `rake test path/to/test` to run a particular test/directory.
275
+ * [spring-commands-parallel-tests](https://github.com/DocSpring/spring-commands-parallel-tests) - Adds the `parallel_*` commands from [`parallel_tests`](https://github.com/grosser/parallel_tests).
230
276
  * [spring-commands-teaspoon](https://github.com/alejandrobabio/spring-commands-teaspoon.git)
277
+ * [spring-commands-m](https://github.com/gabrieljoelc/spring-commands-m.git)
278
+ * [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
279
+ * [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
280
+ * [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
281
+ * [spring-commands-standard](https://github.com/lakim/spring-commands-standard)
231
282
 
232
283
  ## Use without adding to bundle
233
284
 
234
- If you don't want spring-related code checked into your source
235
- repository, it's possible to use spring without adding to your Gemfile.
236
- However, using spring binstubs without adding spring to the Gemfile is not
285
+ If you don't want Spring-related code checked into your source
286
+ repository, it's possible to use Spring without adding to your Gemfile.
287
+ However, using Spring binstubs without adding Spring to the Gemfile is not
237
288
  supported.
238
289
 
239
- To use spring like this, do a `gem install spring` and then prefix
290
+ To use Spring like this, do a `gem install spring` and then prefix
240
291
  commands with `spring`. For example, rather than running `bin/rake -T`,
241
292
  you'd run `spring rake -T`.
242
293
 
@@ -247,12 +298,10 @@ run through Spring, set the `DISABLE_SPRING` environment variable.
247
298
 
248
299
  ## Class reloading
249
300
 
250
- Spring uses Rails' class reloading mechanism
251
- (`ActiveSupport::Dependencies`) to keep your code up to date between
252
- test runs. This is the same mechanism which allows you to see changes
253
- during development when you refresh the page. However, you may never
254
- have used this mechanism with your `test` environment before, and this
255
- can cause problems.
301
+ Spring uses Rails' class reloading mechanism to keep your code up to date
302
+ between test runs. This is the same mechanism which allows you to see changes
303
+ during development when you refresh the page. However, you may never have used
304
+ this mechanism with your `test` environment before, and this can cause problems.
256
305
 
257
306
  It's important to realise that code reloading means that the constants
258
307
  in your application are *different objects* after files have changed:
@@ -286,6 +335,13 @@ false
286
335
  So to avoid this problem, don't save off references to application
287
336
  constants in your initialization code.
288
337
 
338
+ ## Using Spring with a containerized development environment
339
+
340
+ As of Spring 1.7, there is some support for doing this. See [this
341
+ example
342
+ repository](https://github.com/jonleighton/spring-docker-example) for
343
+ information about how to do it with [Docker](https://www.docker.com/).
344
+
289
345
  ## Configuration
290
346
 
291
347
  Spring will read `~/.spring.rb` and `config/spring.rb` for custom
@@ -295,12 +351,16 @@ settings. Note that `~/.spring.rb` is loaded *before* bundler, but
295
351
  projects without having to be added to the project's Gemfile, require
296
352
  them in your `~/.spring.rb`.
297
353
 
354
+ `config/spring_client.rb` is also loaded before bundler and before a
355
+ server process is started, it can be used to add new top-level commands.
356
+
298
357
  ### Application root
299
358
 
300
359
  Spring must know how to find your Rails application. If you have a
301
360
  normal app everything works out of the box. If you are working on a
302
361
  project with a special setup (an engine for example), you must tell
303
- Spring where your app is located:
362
+ Spring where your app is located by specifying the below code in a
363
+ `config/spring.rb` file relative to your engines root directory :
304
364
 
305
365
  ```ruby
306
366
  Spring.application_root = './test/dummy'
@@ -342,20 +402,66 @@ application restart, you can specify them with `Spring.watch`:
342
402
  Spring.watch "config/some_config_file.yml"
343
403
  ```
344
404
 
345
- By default Spring polls the filesystem for changes once every 0.2 seconds. This
405
+ By default, Spring polls the filesystem for changes once every 0.2 seconds. This
346
406
  method requires zero configuration, but if you find that it's using too
347
407
  much CPU, then you can use event-based file system listening by
348
408
  installing the
349
409
  [spring-watcher-listen](https://github.com/jonleighton/spring-watcher-listen)
350
410
  gem.
351
411
 
412
+ ### Quiet output
413
+
414
+ To disable the "Running via Spring preloader" message which is shown each time
415
+ a command runs:
416
+
417
+ ``` ruby
418
+ Spring.quiet = true
419
+ ```
420
+
421
+ You can also set the initial state of the `quiet` configuration option to true
422
+ by setting the `SPRING_QUIET` environment variable before executing Spring.
423
+ This is useful if you want to set quiet mode when invoking the Spring executable
424
+ in a subprocess, and cannot or prefer not to set it programmatically
425
+ via the `Spring.quiet` option in `~/.spring.rb` or the app's `config/spring.rb`.
426
+
427
+ ### Environment variables
428
+
429
+ The following environment variables are used by Spring:
430
+
431
+ * `DISABLE_SPRING` - If set, Spring will be bypassed, and your
432
+ application will boot in a foreground process
433
+ * `SPRING_LOG` - The path to a file which Spring will write log messages
434
+ to.
435
+ * `SPRING_TMP_PATH` - The directory where Spring should write its temporary
436
+ files (a pidfile and a socket). By default, we use the
437
+ `XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
438
+ create a directory in that named `spring-$UID`. We don't use your
439
+ Rails application's `tmp/` directory because that may be on a
440
+ filesystem which doesn't support UNIX sockets.
441
+ * `SPRING_APPLICATION_ID` - Used to identify distinct Rails
442
+ applications. By default, it is an MD5 hash of the current
443
+ `RUBY_VERSION`, and the path to your Rails project root.
444
+ * `SPRING_SOCKET` - The path which should be used for the UNIX socket
445
+ which Spring uses to communicate with the long-running Spring server
446
+ process. By default, this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
447
+ * `SPRING_PIDFILE` - The path which should be used to store the pid of
448
+ the long-running Spring server process. By default, this is related to
449
+ the socket path; if the socket path is `/foo/bar/spring.sock` the
450
+ pidfile will be `/foo/bar/spring.pid`.
451
+ * `SPRING_QUIET` - If set, the initial state of the `Spring.quiet`
452
+ configuration option will default to `true`.
453
+ * `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
454
+ server when it is not already running. Defaults to `spring _[version]_
455
+ server --background`.
456
+
352
457
  ## Troubleshooting
353
458
 
354
- If you want to get more information about what spring is doing, you can
355
- specify a log file with the `SPRING_LOG` environment variable:
459
+ If you want to get more information about what Spring is doing, you can
460
+ run Spring explicitly in a separate terminal:
356
461
 
357
462
  ```
358
- spring stop # if spring is already running
359
- export SPRING_LOG=/tmp/spring.log
360
- spring rake -T
463
+ $ spring server
361
464
  ```
465
+
466
+ Logging output will be printed to stdout. You can also send log output
467
+ to a file with the `SPRING_LOG` environment variable.
data/bin/spring CHANGED
@@ -43,6 +43,7 @@ if defined?(Gem)
43
43
  end
44
44
  end
45
45
 
46
- $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
46
+ lib = File.expand_path("../../lib", __FILE__)
47
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib) # enable local development
47
48
  require 'spring/client'
48
49
  Spring::Client.run(ARGV)
@@ -5,14 +5,21 @@ require "spring/application"
5
5
 
6
6
  app = Spring::Application.new(
7
7
  UNIXSocket.for_fd(3),
8
- Spring::JSON.load(ENV.delete("SPRING_ORIGINAL_ENV").dup)
8
+ Spring::JSON.load(ENV.delete("SPRING_ORIGINAL_ENV").dup),
9
+ Spring::Env.new(log_file: IO.for_fd(4))
9
10
  )
10
11
 
11
12
  Signal.trap("TERM") { app.terminate }
12
13
 
13
- Spring::ProcessTitleUpdater.run { |distance|
14
- "spring app | #{app.app_name} | started #{distance} ago | #{app.app_env} mode"
15
- }
14
+ Spring::ProcessTitleUpdater.run do |distance|
15
+ attributes = [
16
+ app.app_name,
17
+ "started #{distance} ago",
18
+ "#{app.app_env} mode",
19
+ app.spawn_env,
20
+ ].compact
21
+ "spring app | #{attributes.join(" | ")}"
22
+ end
16
23
 
17
24
  app.eager_preload if ENV.delete("SPRING_PRELOAD") == "1"
18
25
  app.run