spring 3.0.0 → 3.1.1

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: 1f2e2dd87b67447e8ec1404be4f904fe1339e536dabddde397662313a7bb116d
4
+ data.tar.gz: 467c115d0fff87ded2aa4a7d761419f74ce9b45798f12568e21d97e1b261599f
5
5
  SHA512:
6
- metadata.gz: 1e7c861899e73bec7b1dd623d0c486b66efdb257bc388caf10034dd11095f2feffa2695e09008d1669931f4e1c8d805c70ca7e403ea76431315f583d43664e37
7
- data.tar.gz: 49587a245923eee35343818174edf141d2b687fb4b09cd9eeefe31c867848b03400cee41e98f2d5b35130d1b313c3f9b3433a557bfb5c5a20fc6fe4ae0822f7a
6
+ metadata.gz: 3cc3b61d71972b7150fdbf7331ce1e55d447fabecbc4ba55914ce2621a9221fbb913efa31b715f80f77ff807dba06b3f89e26454ef623d8d2bc26af6b6f442a3
7
+ data.tar.gz: b459527ad5f9301dd75b1e2f5c9d6e6418e7c019c3a0073a4c6e905b9118db5193bcad051bba88fd5f55cbf124037332ed6a940cd857e4c59d67127d02dbb951
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
@@ -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
@@ -178,7 +179,7 @@ Spring is running:
178
179
  ```
179
180
 
180
181
  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
182
+ when you close your terminal. However, if you do want to do a manual shut
182
183
  down, use the `stop` command:
183
184
 
184
185
  ```
@@ -198,12 +199,13 @@ To remove Spring:
198
199
  ### Deployment
199
200
 
200
201
  You must not install Spring on your production environment. To prevent it from
201
- being installed, provide the `--without development test` argument to the
202
+ being installed, run the `bundle config set without 'development test'` before
202
203
  `bundle install` command which is used to install gems on your production
203
204
  machines:
204
205
 
205
206
  ```
206
- $ bundle install --without development test
207
+ $ bundle config set without 'development test'
208
+ $ bundle install
207
209
  ```
208
210
 
209
211
  ## Commands
@@ -248,6 +250,7 @@ You can add these to your Gemfile for additional commands:
248
250
  * [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
249
251
  * [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
250
252
  * [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
253
+ * [spring-commands-standard](https://github.com/lakim/spring-commands-standard)
251
254
 
252
255
  ## Use without adding to bundle
253
256
 
@@ -370,7 +373,7 @@ application restart, you can specify them with `Spring.watch`:
370
373
  Spring.watch "config/some_config_file.yml"
371
374
  ```
372
375
 
373
- 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
374
377
  method requires zero configuration, but if you find that it's using too
375
378
  much CPU, then you can use event-based file system listening by
376
379
  installing the
@@ -390,24 +393,24 @@ Spring.quiet = true
390
393
 
391
394
  The following environment variables are used by Spring:
392
395
 
393
- * `DISABLE_SPRING` - If set, Spring will be bypassed and your
396
+ * `DISABLE_SPRING` - If set, Spring will be bypassed, and your
394
397
  application will boot in a foreground process
395
398
  * `SPRING_LOG` - The path to a file which Spring will write log messages
396
399
  to.
397
400
  * `SPRING_TMP_PATH` - The directory where Spring should write its temporary
398
- files (a pidfile and a socket). By default we use the
401
+ files (a pidfile and a socket). By default, we use the
399
402
  `XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
400
403
  create a directory in that named `spring-$UID`. We don't use your
401
404
  Rails application's `tmp/` directory because that may be on a
402
405
  filesystem which doesn't support UNIX sockets.
403
406
  * `SPRING_APPLICATION_ID` - Used to identify distinct Rails
404
- applications. By default it is an MD5 hash of the current
407
+ applications. By default, it is an MD5 hash of the current
405
408
  `RUBY_VERSION`, and the path to your Rails project root.
406
409
  * `SPRING_SOCKET` - The path which should be used for the UNIX socket
407
410
  which Spring uses to communicate with the long-running Spring server
408
- process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
411
+ process. By default, this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
409
412
  * `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
413
+ the long-running Spring server process. By default, this is related to
411
414
  the socket path; if the socket path is `/foo/bar/spring.sock` the
412
415
  pidfile will be `/foo/bar/spring.pid`.
413
416
  * `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
@@ -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
@@ -115,7 +116,7 @@ module Spring
115
116
  raise e unless initialized?
116
117
  ensure
117
118
  watcher.add loaded_application_features
118
- watcher.add Spring.gemfile, "#{Spring.gemfile}.lock"
119
+ watcher.add Spring.gemfile, Spring.gemfile_lock
119
120
 
120
121
  if defined?(Rails) && Rails.application
121
122
  watcher.add Rails.application.paths["config/initializers"]
@@ -149,10 +150,23 @@ module Spring
149
150
  log "got client"
150
151
  manager.puts
151
152
 
153
+ @clients << client
154
+
152
155
  _stdout, stderr, _stdin = streams = 3.times.map { client.recv_io }
153
156
  [STDOUT, STDERR, STDIN].zip(streams).each { |a, b| a.reopen(b) }
154
157
 
155
- preload unless preloaded?
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
156
170
 
157
171
  args, env = JSON.load(client.read(client.gets.to_i)).values_at("args", "env")
158
172
  command = Spring.command(args.shift)
@@ -165,6 +179,10 @@ module Spring
165
179
  end
166
180
 
167
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
+
168
186
  Process.setsid
169
187
  IGNORE_SIGNALS.each { |sig| trap(sig, "DEFAULT") }
170
188
  trap("TERM", "DEFAULT")
@@ -286,7 +304,7 @@ module Spring
286
304
  ensure
287
305
  if $!
288
306
  lib = File.expand_path("..", __FILE__)
289
- $!.backtrace.reject! { |line| line.start_with?(lib) }
307
+ $!.backtrace.reject! { |line| line.start_with?(lib) } unless $!.backtrace.frozen?
290
308
  end
291
309
  end
292
310
  end
@@ -22,6 +22,8 @@ module Spring
22
22
 
23
23
  if COMMANDS.include?(command_name)
24
24
  Run.call(["rails_#{command_name}", *args.drop(2)])
25
+ elsif command_name.start_with?("db:")
26
+ Run.call(["rake", *args.drop(1)])
25
27
  else
26
28
  require "spring/configuration"
27
29
  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
@@ -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
@@ -2,7 +2,6 @@ require "pathname"
2
2
  require "digest/md5"
3
3
 
4
4
  require "spring/version"
5
- require "spring/sid"
6
5
  require "spring/configuration"
7
6
 
8
7
  module Spring
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 = "3.1.1"
3
3
  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: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Leighton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-08 00:00:00.000000000 Z
11
+ date: 2021-11-25 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
@@ -99,7 +98,7 @@ homepage: https://github.com/rails/spring
99
98
  licenses:
100
99
  - MIT
101
100
  metadata: {}
102
- post_install_message:
101
+ post_install_message:
103
102
  rdoc_options: []
104
103
  require_paths:
105
104
  - lib
@@ -115,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
114
  version: '0'
116
115
  requirements: []
117
116
  rubygems_version: 3.2.22
118
- signing_key:
117
+ signing_key:
119
118
  specification_version: 4
120
119
  summary: Rails application preloader
121
120
  test_files: []
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