Skip to content

Keep magic comments work after springifying #526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Next release

* Preserve comments right after the shebang line which might include magic comments such as `frozen_string_literal: true'

## 2.0.2

* Fix reloading when a watched directory contains a dangling symlink (#522)
Expand Down
2 changes: 1 addition & 1 deletion lib/spring/client/binstub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Spring
module Client
class Binstub < Command
SHEBANG = /\#\!.*\n/
SHEBANG = /\#\!.*\n(\#.*\n)*/

# If loading the bin/spring file works, it'll run spring which will
# eventually call Kernel.exit. This means that in the client process
Expand Down
24 changes: 24 additions & 0 deletions lib/spring/test/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,30 @@ def exec_name
end
end

test "binstub preserve magic comments" do
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# more comments
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY

assert_success "bin/spring binstub rake"

expected = <<-RUBY.gsub(/^ /, "")
#!/usr/bin/env ruby
# frozen_string_literal: true
#
# more comments
#{Spring::Client::Binstub::LOADER.strip}
require 'bundler/setup'
load Gem.bin_path('rake', 'rake')
RUBY
assert_equal expected, app.path("bin/rake").read
end

test "binstub upgrade with old binstub" do
File.write(app.path("bin/rake"), <<-RUBY.strip_heredoc)
#!/usr/bin/env ruby
Expand Down