Skip to content

Commit

Permalink
Print Bundler progress to stderr when invoking CLI directly
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 30, 2024
1 parent 29c434b commit e0bdfa3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def initialize(project_path, **options)
@project_path = project_path
@branch = T.let(options[:branch], T.nilable(String))
@launcher = T.let(options[:launcher], T.nilable(T::Boolean))
patch_thor_to_print_progress_to_stderr! if @launcher

# Regular bundle paths
@gemfile = T.let(
Expand Down Expand Up @@ -400,5 +401,21 @@ def base_bundle_command(env)

"bundle"
end

sig { void }
def patch_thor_to_print_progress_to_stderr!
return unless defined?(Bundler::Thor::Shell::Basic)

Bundler::Thor::Shell::Basic.prepend(Module.new do
extend T::Sig

sig { returns(IO) }
def stdout
$stderr
end
end)

Bundler.ui.level = :info
end
end
end
1 change: 1 addition & 0 deletions project-words
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ FIXEDENCODING
Floo
fnmatch
fooo
gemname
hostedtoolcache
importmap
indexables
Expand Down
6 changes: 6 additions & 0 deletions sorbet/rbi/shims/bundler.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ module Bundler
def run; end
end
end

module Thor # rubocop:disable Style/ClassAndModuleChildren
module Shell
class Basic; end
end
end
end
25 changes: 25 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,31 @@ def test_invoke_cli_calls_bundler_directly_for_update
end
end

def test_progress_is_printed_to_stderr
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "Gemfile"), <<~GEMFILE)
source "https://rubygems.org"
gem "rdoc"
GEMFILE

Bundler.with_unbundled_env do
capture_subprocess_io do
# Run bundle install to generate the lockfile
system("bundle install")
end

stdout, stderr = capture_subprocess_io do
RubyLsp::SetupBundler.new(dir, launcher: true).setup!
end

assert_match(/Bundle complete! [\d]+ Gemfile dependencies, [\d]+ gems now installed/, stderr)
assert_empty(stdout)
end
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down

0 comments on commit e0bdfa3

Please sign in to comment.