spring 2.1.1 → 4.0.0

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: 90758ca717a756e672dfeaaf8295f17fcfa38f3ea3bc8bd27093a4354d45b82f
4
- data.tar.gz: 82533f3a3e3f5dc53c3f89d3b2734557bfefcf06b5cbe714238dba64160d56a3
3
+ metadata.gz: 9f13e2a4d08faffc1b15c2f1dfe801a3b0b6a12b80d7a66a39601e74ccf3feff
4
+ data.tar.gz: 60c63476055ff6050668abfc79489f7c6fbbfc9a7b3a11ea998cb5b2ab86ef9a
5
5
  SHA512:
6
- metadata.gz: 80d8a7138fa74ad857a43671e54234da3a9b6265727f170c21905694397ebe5ec9b1102dbce3098835157e49e808cbbc52d74e1894a228ab0b25e521987cc4ca
7
- data.tar.gz: 4366760559dfa2bae19ce7478302b35ca050cd431e39241427dfb5666de3a4eb704039ccdc4b02634556041aba71cebe22a053f4553e63db9d7ecdfbb980bf66
6
+ metadata.gz: 9c467ea15cea498f05ec7e5211bb014163e37a75557d9694e03cc4d6d6e94d4b62c6edcede752e61c4ff51accf472939150c7fc01901aab94cd60d4d06c8a8b1
7
+ data.tar.gz: 6d363498591c949b3a49885c38d8694db924d9a2b24c2cc8499236d67739f4cb863eff5db114385bba8cb02bf996af48acd892cbf5e2edebe495bf3bdfffca93
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,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.4, MRI 2.5, MRI 2.6
20
- * Rails versions: 4.2, 5.0, 5.1, 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
20
+ * Rails versions: 6.0, 6.1, 7.0
22
21
 
23
22
  Spring makes extensive use of `Process.fork`, so won't be able to
24
23
  provide a speed up on platforms which don't support forking (Windows, JRuby).
@@ -50,13 +49,14 @@ code into relevant existing executables. The snippet looks like this:
50
49
  ``` ruby
51
50
  begin
52
51
  load File.expand_path('../spring', __FILE__)
53
- rescue LoadError
52
+ rescue LoadError => e
53
+ raise unless e.message.include?('spring')
54
54
  end
55
55
  ```
56
56
 
57
57
  On platforms where Spring is installed and supported, this snippet
58
58
  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
59
+ will just be silently ignored, and the lines after it will be executed as
60
60
  normal.
61
61
 
62
62
  If you don't want to prefix every command you type with `bin/`, you
@@ -65,6 +65,16 @@ automatically add `./bin` to your `PATH` when you `cd` into your application.
65
65
  Simply create an `.envrc` file with the command `PATH_add bin` in your
66
66
  Rails directory.
67
67
 
68
+ ### Enable reloading
69
+
70
+ Spring reloads application code, and therefore needs the application to have
71
+ reloading enabled.
72
+
73
+ Please, make sure `config.cache_classes` is `false` in the environments that
74
+ Spring manages. That setting is typically configured in
75
+ `config/environments/*.rb`. In particular, make sure it is `false` for the
76
+ `test` environment.
77
+
68
78
  ### Usage
69
79
 
70
80
  For this walkthrough I've generated a new Rails application, and run
@@ -168,7 +178,7 @@ Spring is running:
168
178
  ```
169
179
 
170
180
  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
181
+ when you close your terminal. However, if you do want to do a manual shut
172
182
  down, use the `stop` command:
173
183
 
174
184
  ```
@@ -188,12 +198,13 @@ To remove Spring:
188
198
  ### Deployment
189
199
 
190
200
  You must not install Spring on your production environment. To prevent it from
191
- being installed, provide the `--without development test` argument to the
201
+ being installed, run the `bundle config set without 'development test'` before
192
202
  `bundle install` command which is used to install gems on your production
193
203
  machines:
194
204
 
195
205
  ```
196
- $ bundle install --without development test
206
+ $ bundle config set without 'development test'
207
+ $ bundle install
197
208
  ```
198
209
 
199
210
  ## Commands
@@ -238,6 +249,7 @@ You can add these to your Gemfile for additional commands:
238
249
  * [spring-commands-rubocop](https://github.com/p0deje/spring-commands-rubocop)
239
250
  * [spring-commands-rackup](https://github.com/wintersolutions/spring-commands-rackup)
240
251
  * [spring-commands-rack-console](https://github.com/wintersolutions/spring-commands-rack-console)
252
+ * [spring-commands-standard](https://github.com/lakim/spring-commands-standard)
241
253
 
242
254
  ## Use without adding to bundle
243
255
 
@@ -257,12 +269,10 @@ run through Spring, set the `DISABLE_SPRING` environment variable.
257
269
 
258
270
  ## Class reloading
259
271
 
260
- Spring uses Rails' class reloading mechanism
261
- (`ActiveSupport::Dependencies`) to keep your code up to date between
262
- test runs. This is the same mechanism which allows you to see changes
263
- during development when you refresh the page. However, you may never
264
- have used this mechanism with your `test` environment before, and this
265
- can cause problems.
272
+ Spring uses Rails' class reloading mechanism to keep your code up to date
273
+ between test runs. This is the same mechanism which allows you to see changes
274
+ during development when you refresh the page. However, you may never have used
275
+ this mechanism with your `test` environment before, and this can cause problems.
266
276
 
267
277
  It's important to realise that code reloading means that the constants
268
278
  in your application are *different objects* after files have changed:
@@ -362,7 +372,7 @@ application restart, you can specify them with `Spring.watch`:
362
372
  Spring.watch "config/some_config_file.yml"
363
373
  ```
364
374
 
365
- By default Spring polls the filesystem for changes once every 0.2 seconds. This
375
+ By default, Spring polls the filesystem for changes once every 0.2 seconds. This
366
376
  method requires zero configuration, but if you find that it's using too
367
377
  much CPU, then you can use event-based file system listening by
368
378
  installing the
@@ -382,24 +392,24 @@ Spring.quiet = true
382
392
 
383
393
  The following environment variables are used by Spring:
384
394
 
385
- * `DISABLE_SPRING` - If set, Spring will be bypassed and your
395
+ * `DISABLE_SPRING` - If set, Spring will be bypassed, and your
386
396
  application will boot in a foreground process
387
397
  * `SPRING_LOG` - The path to a file which Spring will write log messages
388
398
  to.
389
399
  * `SPRING_TMP_PATH` - The directory where Spring should write its temporary
390
- files (a pidfile and a socket). By default we use the
400
+ files (a pidfile and a socket). By default, we use the
391
401
  `XDG_RUNTIME_DIR` environment variable, or else `Dir.tmpdir`, and then
392
402
  create a directory in that named `spring-$UID`. We don't use your
393
403
  Rails application's `tmp/` directory because that may be on a
394
404
  filesystem which doesn't support UNIX sockets.
395
405
  * `SPRING_APPLICATION_ID` - Used to identify distinct Rails
396
- applications. By default it is an MD5 hash of the current
406
+ applications. By default, it is an MD5 hash of the current
397
407
  `RUBY_VERSION`, and the path to your Rails project root.
398
408
  * `SPRING_SOCKET` - The path which should be used for the UNIX socket
399
409
  which Spring uses to communicate with the long-running Spring server
400
- process. By default this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
410
+ process. By default, this is `SPRING_TMP_PATH/SPRING_APPLICATION_ID`.
401
411
  * `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
412
+ the long-running Spring server process. By default, this is related to
403
413
  the socket path; if the socket path is `/foo/bar/spring.sock` the
404
414
  pidfile will be `/foo/bar/spring.pid`.
405
415
  * `SPRING_SERVER_COMMAND` - The command to run to start up the Spring
@@ -11,7 +11,8 @@ module Spring
11
11
  @original_env = original_env
12
12
  @spring_env = spring_env
13
13
  @mutex = Mutex.new
14
- @waiting = Set.new
14
+ @waiting = {}
15
+ @clients = {}
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('4.2.0')
95
- raise "Spring only supports Rails >= 4.2.0"
95
+ unless Rails.respond_to?(:gem_version) && Rails.gem_version >= Gem::Version.new('6.0.0')
96
+ raise "Spring only supports Rails >= 6.0.0"
96
97
  end
97
98
 
98
- # config/environments/test.rb will have config.cache_classes = true. However
99
- # we want it to be false so that we can reload files. This is a hack to
100
- # override the effect of config.cache_classes = true. We can then actually
101
- # set config.cache_classes = false after loading the environment.
102
- Rails::Application.initializer :initialize_dependency_mechanism, group: :all do
103
- ActiveSupport::Dependencies.mechanism = :load
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, "#{Spring.gemfile}.lock"
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] = true
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
- 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
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
- # Rails 5.1 forward-compat. AD::R is deprecated to AS::R in Rails 5.
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.each_key { |c| c.close if c != client }
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,14 +239,13 @@ 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
249
245
  if exiting?
250
246
  # Ensure that we do not ignore subsequent termination attempts
251
247
  log "forced exit"
252
- @waiting.each { |pid| Process.kill("TERM", pid) }
248
+ @waiting.each_key { |pid| Process.kill("TERM", pid) }
253
249
  Kernel.exit
254
250
  else
255
251
  state! :terminating
@@ -308,7 +304,7 @@ module Spring
308
304
  ensure
309
305
  if $!
310
306
  lib = File.expand_path("..", __FILE__)
311
- $!.backtrace.reject! { |line| line.start_with?(lib) }
307
+ $!.backtrace.reject! { |line| line.start_with?(lib) } unless $!.backtrace.frozen?
312
308
  end
313
309
  end
314
310
  end
@@ -341,7 +337,7 @@ module Spring
341
337
  end
342
338
 
343
339
  def wait(pid, streams, client)
344
- @mutex.synchronize { @waiting << pid }
340
+ @mutex.synchronize { @waiting[pid] = true }
345
341
 
346
342
  # Wait in a separate thread so we can run multiple commands at once
347
343
  Spring.failsafe_thread {
@@ -93,7 +93,7 @@ module Spring
93
93
  def start_child(preload = false)
94
94
  @child, child_socket = UNIXSocket.pair
95
95
 
96
- Bundler.with_original_env do
96
+ Bundler.with_unbundled_env do
97
97
  bundler_dir = File.expand_path("../..", $LOADED_FEATURES.grep(/bundler\/setup\.rb$/).first)
98
98
  @pid = Process.spawn(
99
99
  {
@@ -11,41 +11,36 @@ module Spring
11
11
  # client is not invoked for whatever reason, then the Kernel.exit won't
12
12
  # happen, and so we'll fall back to the lines after this block, which
13
13
  # 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
14
+ LOADER = <<~CODE
15
+ load File.expand_path("spring", __dir__)
16
+ CODE
21
17
 
22
18
  # The defined? check ensures these lines don't execute when we load the
23
19
  # binstub from the application process. Which means that in the application
24
20
  # process we'll execute the lines which come after the LOADER block, which
25
21
  # 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
22
+ SPRING = <<~CODE
23
+ #!/usr/bin/env ruby
24
+
25
+ # This file loads Spring without using loading other gems in the Gemfile, in order to be fast.
26
+ # It gets overwritten when you run the `spring binstub` command.
27
+
28
+ if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"])
29
+ require "bundler"
30
+
31
+ Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring|
32
+ Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
33
+ gem "spring", spring.version
34
+ require "spring/binstub"
35
+ end
36
+ end
37
+ CODE
45
38
 
46
39
  OLD_BINSTUB = %{if !Process.respond_to?(:fork) || Gem::Specification.find_all_by_name("spring").empty?}
47
40
 
48
41
  BINSTUB_VARIATIONS = Regexp.union [
42
+ %{load File.expand_path("spring", __dir__)\n},
43
+ %{begin\n load File.expand_path('../spring', __FILE__)\nrescue LoadError => e\n raise unless e.message.include?('spring')\nend\n},
49
44
  %{begin\n load File.expand_path('../spring', __FILE__)\nrescue LoadError\nend\n},
50
45
  %{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
46
  LOADER
@@ -146,7 +141,7 @@ CODE
146
141
  @mode = :add
147
142
  @items = args.drop(1)
148
143
  .map { |name| find_commands name }
149
- .inject(Set.new, :|)
144
+ .flatten.uniq
150
145
  .map { |command| Item.new(command) }
151
146
  end
152
147
 
@@ -3,7 +3,7 @@ require "set"
3
3
  module Spring
4
4
  module Client
5
5
  class Rails < Command
6
- COMMANDS = Set.new %w(console runner generate destroy test)
6
+ COMMANDS = %w(console runner generate destroy test)
7
7
 
8
8
  ALIASES = {
9
9
  "c" => "console",
@@ -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
@@ -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
@@ -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 = "2.1.1"
2
+ VERSION = "4.0.0"
3
3
  end
@@ -19,8 +19,8 @@ module Spring
19
19
 
20
20
  @root = File.realpath(root)
21
21
  @latency = latency
22
- @files = Set.new
23
- @directories = Set.new
22
+ @files = {}
23
+ @directories = {}
24
24
  @stale = false
25
25
  @listeners = []
26
26
 
@@ -63,10 +63,10 @@ module Spring
63
63
  synchronize {
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.
@@ -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: 2.1.1
4
+ version: 4.0.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: 2020-08-25 00:00:00.000000000 Z
11
+ date: 2021-12-10 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.4.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.0.3
117
+ rubygems_version: 3.2.32
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