Skip to content

Commit b148d69

Browse files
author
OZAWA Sakuro
committed
Preserve comments after the shebang line
The main purpose of this is to keep magic comments work.
1 parent fb08388 commit b148d69

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Next release
2+
3+
* Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true'
4+
15
## 2.0.2
26

37
* Fix reloading when a watched directory contains a dangling symlink (#522)

lib/spring/client/binstub.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Spring
44
module Client
55
class Binstub < Command
6-
SHEBANG = /\#\!.*\n/
6+
SHEBANG = /\#\!.*\n(\#.*\n)*/
77

88
# If loading the bin/spring file works, it'll run spring which will
99
# eventually call Kernel.exit. This means that in the client process

lib/spring/test/acceptance_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,30 @@ def exec_name
260260
end
261261
end
262262

263+
test "binstub preserve magic comments" do
264+
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
265+
#!/usr/bin/env ruby
266+
# frozen_string_literal: true
267+
#
268+
# more comments
269+
require 'bundler/setup'
270+
load Gem.bin_path('rake', 'rake')
271+
RUBY
272+
273+
assert_success "bin/spring binstub rake"
274+
275+
expected = <<-RUBY.gsub(/^ /, "")
276+
#!/usr/bin/env ruby
277+
# frozen_string_literal: true
278+
#
279+
# more comments
280+
#{Spring::Client::Binstub::LOADER.strip}
281+
require 'bundler/setup'
282+
load Gem.bin_path('rake', 'rake')
283+
RUBY
284+
assert_equal expected, app.path("bin/rake").read
285+
end
286+
263287
test "binstub upgrade with old binstub" do
264288
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
265289
#!/usr/bin/env ruby

0 commit comments

Comments
 (0)